diff --git a/README.md b/README.md index 0b2bd1f..c8c1161 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ works with. The maintainers publish the releases of the mods in this repository. | [gm-commands](mods/gm-commands/) | the development and testing chat commands: teleport, items, monsters, experience, test hits, protocol probes | | [globalchat](mods/globalchat/) | talk to other LocalExile players through the LocalExile global chat server | | [waypoint-tools](mods/waypoint-tools/) | lets Waypoint's tools reach the game without the client control bridge: the item crafter gives its items through it | +| [equipmentfusion](mods/equipmentfusion/) | automatic attributes and defences from non-weapon native skin transfers; donor gems and skills excluded; requires the companion server update | | [backpack](mods/backpack/) | an optional native 20-slot extra backpack for every class, with safe recovery after disable | | [petloot](mods/petloot/) | optional pet pickup with per-character filters, minimum stacks, pause/resume and configurable 2x pet speed | | [zoom](mods/zoom/) | a wider view in normal play: the camera stands further back, the mouse wheel reaches it, `/zoom` sets how far | diff --git a/mods.json b/mods.json index 89582f9..ecdd5a2 100644 --- a/mods.json +++ b/mods.json @@ -2,6 +2,7 @@ "version": 1, "mods": [ { "id": "backpack", "name": "Extra Backpack", "description": "An optional native 20-slot extra backpack for every character class.", "author": "zj1022", "version": "1.0.3", "compatibleClientVersions": ["0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "script", "path": "mods/backpack", "depends": [], "settings": false }, + { "id": "equipmentfusion", "name": "Equipment Fusion", "description": "Adds non-weapon skin-transfer donor attributes and defences automatically; requires the companion native skin-transfer server update.", "author": "JJ ouyang", "version": "2.0.2", "compatibleClientVersions": ["0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/equipmentfusion", "depends": ["Game"], "settings": false }, { "id": "fastcampaign", "name": "Fast Campaign", "description": "A faster campaign: 5x kill experience, +50% movement speed, and /fast lists the commands that skip ahead.", "author": "LocalExile", "version": "1.1.4", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/fastcampaign", "depends": [], "settings": true }, { "id": "globalchat", "name": "Global Chat", "description": "Talk to other LocalExile players: global, trade and whisper chat go through the LocalExile global chat server.", "author": "JetStream", "version": "1.1.4", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/globalchat", "depends": [], "settings": true }, { "id": "gm-commands", "name": "GM Commands", "description": "The development and testing chat commands: teleport, items, monsters, experience, quest flags, test hits and protocol probes.", "author": "LocalExile", "version": "1.5.0", "compatibleClientVersions": ["0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/gm-commands", "depends": ["Game"], "settings": false }, diff --git a/mods/equipmentfusion/EquipmentFusionMod.cs b/mods/equipmentfusion/EquipmentFusionMod.cs new file mode 100644 index 0000000..5708033 --- /dev/null +++ b/mods/equipmentfusion/EquipmentFusionMod.cs @@ -0,0 +1,105 @@ +using System.Runtime.CompilerServices; +using GameServer.Core.Protocol.Instance; +using GameServer.Modding; +using static Game; + +namespace LocalExile.Mods.EquipmentFusion; + +/// Native skin transfers retain the items; this optional provider contributes only their non-weapon stats. +public sealed class EquipmentFusionMod : IMod, IDisposable +{ + ConditionalWeakTable _sources = new(); + sealed class Cached + { + public readonly Lock Gate = new(); + public (byte Row, InventoryItem Item)[] Hosts = []; + public IReadOnlyList<(byte Row, InventoryItem Item)> Sources = []; + } + readonly ConditionalWeakTable _views = new(); + readonly Lock _cacheGate = new(); + int _disposed; + static readonly HashSet Slots = [1, 4, 5, 6, 7, 8, 9, 10, 102]; + static readonly HashSet Classes = ["Body Armour", "Helmet", "Amulet", "Ring", "Gloves", "Boots", "Belt"]; + + public void Load(IModContext mod) => GameEvents.ItemStatSources.Add(mod.Manifest.Id, Sources); + + public IReadOnlyList<(byte Row, InventoryItem Item)> Sources(ClientState conn, + IReadOnlyList<(byte Row, InventoryItem Item)> native) + { + if (Volatile.Read(ref _disposed) != 0) return Array.Empty<(byte, InventoryItem)>(); + if (!_views.TryGetValue(conn, out var view)) + lock (_cacheGate) + { + if (Volatile.Read(ref _disposed) != 0) return Array.Empty<(byte, InventoryItem)>(); + if (!_views.TryGetValue(conn, out view)) _views.Add(conn, view = new Cached()); + } + var cache = (Cached)view; + lock (cache.Gate) + { + if (Volatile.Read(ref _disposed) != 0) + { + _views.Remove(conn); + return Array.Empty<(byte, InventoryItem)>(); + } + bool same = cache.Hosts.Length == native.Count; + for (int i = 0; same && i < native.Count; i++) + same = cache.Hosts[i].Row == native[i].Row && ReferenceEquals(cache.Hosts[i].Item, native[i].Item); + if (same) return cache.Sources; + cache.Sources = BuildSources(conn, native); + cache.Hosts = [.. native]; + return cache.Sources; + } + } + + IReadOnlyList<(byte Row, InventoryItem Item)> BuildSources(ClientState conn, + IReadOnlyList<(byte Row, InventoryItem Item)> native) + { + var catalog = ItemsFor(conn); + var result = new List<(byte Row, InventoryItem Item)>(); + foreach (var (row, target) in native) + { + if (!Slots.Contains(row) || target.Item.SkinTransferSource is not { } donor + || donor.SkinTransferSource is not null || target.Id >= 0x80000000u + || catalog.ByHash(target.Item.TypeHash) is not { } a || catalog.ByHash(donor.TypeHash) is not { } b + || !Classes.Contains(a.Class) || a.Class != b.Class) continue; + if (!_sources.TryGetValue(target, out var projected)) + lock (_cacheGate) + if (!_sources.TryGetValue(target, out projected)) + { + projected = new(0x80000000u | target.Id, 0, 0, Project(donor, catalog.Mods)); + _sources.Add(target, projected); + } + result.Add((row, projected)); + } + return result; + } + + /// Only the calculation view changes. The native donor, including its sockets and all modifiers, is kept intact. + public static Item Project(Item donor, ModCatalog mods) + { + var projected = new ItemMod[donor.Mods.Count]; + for (int i = 0; i < projected.Length; i++) + { + var mod = donor.Mods[i]; + if (mods.ByHash(mod.Hash) is not { } row) { projected[i] = mod; continue; } + var values = new int[mod.Values.Count]; + for (int index = 0; index < values.Length; index++) + values[index] = index < row.Stats.Count && SkillExecution(row.Stats[index].Id) ? 0 : mod.Values[index]; + projected[i] = mod with { Values = values }; + } + return donor with { Sockets = Array.Empty(), Links = null, Mods = projected }; + } + + // Skill grants are never enumerated from ItemStatSources. These numeric execution controls also stay out of global stats. + static bool SkillExecution(string id) => id.Contains("trigger", StringComparison.OrdinalIgnoreCase) + || id.Contains("cast_on_", StringComparison.OrdinalIgnoreCase) + || id.Contains("cast_when_", StringComparison.OrdinalIgnoreCase) + || id.Contains("granted_skill", StringComparison.OrdinalIgnoreCase) + || id.Contains("grants_skill", StringComparison.OrdinalIgnoreCase); + + public void Dispose() + { + if (Interlocked.Exchange(ref _disposed, 1) != 0) return; + lock (_cacheGate) { _views.Clear(); _sources.Clear(); } + } +} diff --git a/mods/equipmentfusion/README.md b/mods/equipmentfusion/README.md new file mode 100644 index 0000000..88c20f9 --- /dev/null +++ b/mods/equipmentfusion/README.md @@ -0,0 +1,49 @@ +# Equipment Fusion + +![Equipment Fusion](icon.png) + +Author: **JJ ouyang**. + +When enabled, equipment with a native skin transfer automatically gains the donor's numerical attributes and local +defences. Each item retains its own modifiers, quality, sockets and gems. Use the game's skin-transfer picker and +reclaim action; the GM tool only installs the mod, changes its switch and shows its actual load status. + +Choose the single **Skin Transfer**, rather than a similarly named pack, in the native microtransaction stash. +The 3.29 client requires the donor's sockets to be empty before its picker accepts the donor; remove its gems first. +The mod does not bypass that client restriction. Saved donors containing gems still retain them on reclaim, and those +gems never supply stats, requirements or skills while the item is a donor. + +## Scope + +- Body armour, helmets, gloves, boots, belts, amulets and rings contribute. Both weapon hands and the stored weapon sets + are excluded, including shields and quivers. +- Global numerical modifiers use the server's existing item-stat rules and requirement qualification. Local armour, + evasion, energy shield and ward are calculated on each item before the completed values are combined. +- Donor socketed gems, granted skills and triggered skills never enter the player's skill-source collections. Numeric + trigger controls are removed from the calculation view. Ordinary numerical modifiers in the same row are retained. +- Reclaim returns the original donor with all of its properties and gems. Disabling or uninstalling the mod removes + its extra contribution on the next equipment/stat refresh. Native binding, storage and reclaim remain available. +- Existing skin transfers start contributing when the mod is enabled. No additional selection or mod chat command is needed. + +## Required server update + +This is a dependency draft. It requires the companion LocalExile native skin-transfer implementation and the general +`GameEvents.ItemStatSources` interface. **An unmodified LocalExile 0.5.2-beta release does not support this mod.** +The manifest's 0.5.2-beta is the repository-required provisional review baseline, not a release compatibility claim. +The maintainer must set the first release containing the prerequisite before merging or publishing. + +Build with `dotnet build mods/equipmentfusion/equipmentfusion.csproj -p:LocalExileRoot=`. +Install the output in `Mods/Binaries/equipmentfusion/` of that matching server. It starts disabled. + +## Controls + +No added commands or tunable settings. Use Waypoint or the GM tool, or the official `/mod`, `/mod_enable equipmentfusion`, +`/mod_disable equipmentfusion` and `/mod_reload equipmentfusion` commands. Native actions remain the way to bind and reclaim. + +## Icon + +Reuses the original 256 by 256 Equipment Fusion artwork, made from the author's game screenshots and gameplay description. + +## Validation + +See the accompanying change description for the tested server revision, automated checks and native-client acceptance. diff --git a/mods/equipmentfusion/equipmentfusion.csproj b/mods/equipmentfusion/equipmentfusion.csproj new file mode 100644 index 0000000..31ce8f9 --- /dev/null +++ b/mods/equipmentfusion/equipmentfusion.csproj @@ -0,0 +1,5 @@ + + + + + diff --git a/mods/equipmentfusion/icon.png b/mods/equipmentfusion/icon.png new file mode 100644 index 0000000..b3401c3 Binary files /dev/null and b/mods/equipmentfusion/icon.png differ diff --git a/mods/equipmentfusion/mod.json b/mods/equipmentfusion/mod.json new file mode 100644 index 0000000..1712696 --- /dev/null +++ b/mods/equipmentfusion/mod.json @@ -0,0 +1,12 @@ +{ + "id": "equipmentfusion", + "name": "Equipment Fusion", + "description": "Adds non-weapon skin-transfer donor attributes and defences automatically; requires the companion native skin-transfer server update.", + "author": "JJ ouyang", + "version": "2.0.2", + "compatibleClientVersions": ["0.5.2-beta"], + "kind": "feature", + "depends": ["Game"], + "enabled": false, + "requiredServerApis": ["Item.SkinTransferSource", "GameEvents.ItemStatSources"] +}