Snapshot for release 2026.10.23.1 (internal 7581cff)

This commit is contained in:
Tom Bohar 2026-10-23 16:34:02 -04:00
commit 92f28bd243
73 changed files with 12203 additions and 308 deletions

View file

@ -0,0 +1,42 @@
using System;
namespace RynthCore.Plugin.RynthDefective.Items;
/// <summary>
/// One thing the character carries or wears, as the client reports it. A plain data holder: the
/// reader (HostInventory) fills it, everything else (slot matching, item kinds, the weapon picker)
/// works on it without the host, so it can be tested offline.
/// </summary>
internal sealed class CarriedItem
{
public uint Id;
public string Name = string.Empty;
public uint Wcid;
/// <summary>MaterialType (int 131): "Silver" in "Silver Wand"; 0 = none / unknown.</summary>
public int Material;
/// <summary>ItemType flags (the client's TryGetItemType).</summary>
public uint ItemType;
/// <summary>PublicWeenieDesc bitfield (healer, food ...); 0 when the engine can't read it.</summary>
public uint Bitfield;
/// <summary>Stack size (at least 1) and the largest stack (1 = not stackable).</summary>
public int Stack = 1, MaxStack = 1;
/// <summary>Uses left / most uses (Structure 92 / MaxStructure 91): kits, essences; MaxUses 0 = none.</summary>
public int Uses, MaxUses;
/// <summary>ValidLocations (int 9): the EquipMask slots it can go into; 0 = it can't be worn or wielded.</summary>
public int ValidLocations;
/// <summary>The slot it is wielded in now (0 = in a pack).</summary>
public int WieldedLocation;
/// <summary>CombatUse (int 51): 1 melee, 2 missile, 3 ammo, 4 shield, 5 two-handed.</summary>
public int CombatUse;
/// <summary>DamageType (int 45) and UiEffects (int 18): the element of a caster.</summary>
public int DamageType, UiEffects;
/// <summary>Icon, underlay and overlay texture ids (0x06......), 0 = none.</summary>
public uint Icon, Underlay, Overlay;
public bool Wielded => WieldedLocation != 0;
/// <summary>The name with the material in front ("Silver Wand"), as the character sees it in the game.</summary>
public string FullName => ItemNames.Full(Name, Material);
public override string ToString() => $"0x{Id:X8} {FullName}";
}

View file

@ -0,0 +1,169 @@
using System;
using System.Collections.Generic;
using RynthCore.PluginSdk;
namespace RynthCore.Plugin.RynthDefective.Items;
/// <summary>
/// Reads what the character carries and wears from the client into <see cref="CarriedItem"/>s.
/// Plugin pump thread only. Everything comes from what the client already has (the engine's
/// object snapshot and its property caches); nothing is sent to the server.
/// GetContainerContents(player) returns the main pack's items, the side packs and the worn and
/// wielded items; each side pack's items come from GetContainerContents(pack). What an item IS
/// (name, wcid, material, kind, picture) is kept per object id once read; what changes (stack,
/// uses left, whether it is in hand) is read every time.
/// </summary>
internal sealed class HostInventory
{
// STypeInt
private const uint StackSize = 12, MaxStackSize = 11, ValidLocations = 9, CurrentWieldedLocation = 10, UiEffects = 18,
DamageType = 45, CombatUse = 51, MaterialType = 131, Structure = 92, MaxStructure = 91;
// STypeDID
private const uint DidIcon = 8, DidIconOverlay = 50, DidIconUnderlay = 52;
private const int MaxContents = 1024;
private const int MaxNesting = 3;
private const uint ItemTypeContainer = 0x200;
/// <summary>A caster whose damage type has not arrived (it comes with an identify) is read again after this.</summary>
private const long RecheckMs = 15_000;
private sealed class Static
{
public string Name = string.Empty;
public uint Wcid;
public int Material;
public uint ItemType, Bitfield;
public int MaxStack = 1, MaxUses, ValidLocations, CombatUse, DamageType, UiEffects;
public uint Icon, Underlay, Overlay;
public bool IsContainer;
public long ReadMs;
}
private readonly Dictionary<uint, Static> _static = new();
private readonly uint[] _contents = new uint[MaxContents];
public void Reset() => _static.Clear();
/// <summary>Everything carried and worn; empty when the character or its inventory isn't readable yet.</summary>
public List<CarriedItem> Read(RynthCoreHost host, long nowMs)
{
var items = new List<CarriedItem>();
if (!host.HasGetPlayerId || !host.HasGetContainerContents) return items;
uint player = host.GetPlayerId();
if (player == 0) return items;
ScanInto(host, player, player, items, 0, nowMs);
return items;
}
private void ScanInto(RynthCoreHost host, uint container, uint player, List<CarriedItem> items, int depth, long nowMs)
{
int n = host.GetContainerContents(container, _contents);
if (n <= 0) return;
uint[] ids = new uint[n];
Array.Copy(_contents, ids, n);
var packs = new List<uint>();
foreach (uint id in ids)
{
if (id == 0) continue;
Ownership(host, id, out uint c, out uint w, out uint loc);
bool worn = w == player && w != 0;
if (!worn && c != container && c != 0) continue; // moved away since the engine's snapshot
CarriedItem? it = ReadItem(host, id, nowMs, out Static? st);
if (it == null) continue;
if (worn)
{
if (loc == 0 && host.TryGetObjectIntProperty(id, CurrentWieldedLocation, out int l)) loc = unchecked((uint)l);
it.WieldedLocation = loc == 0 ? 1 : unchecked((int)loc); // worn but the slot unreadable: still "in hand"
}
else if (st!.IsContainer && depth < MaxNesting)
{
packs.Add(id);
continue; // a pack is not something to use or wield
}
items.Add(it);
}
foreach (uint pack in packs)
ScanInto(host, pack, player, items, depth + 1, nowMs);
}
/// <summary>One item as the client has it now (null if it has no name yet or is gone).</summary>
public CarriedItem? ReadOne(RynthCoreHost host, uint id, long nowMs)
{
uint player = host.HasGetPlayerId ? host.GetPlayerId() : 0;
CarriedItem? it = ReadItem(host, id, nowMs, out _);
if (it == null) return null;
Ownership(host, id, out _, out uint w, out uint loc);
if (w != 0 && w == player)
{
if (loc == 0 && host.TryGetObjectIntProperty(id, CurrentWieldedLocation, out int l)) loc = unchecked((uint)l);
it.WieldedLocation = loc == 0 ? 1 : unchecked((int)loc);
}
return it;
}
private CarriedItem? ReadItem(RynthCoreHost host, uint id, long nowMs, out Static? st)
{
st = null;
if (!_static.TryGetValue(id, out st) || Stale(st, nowMs))
{
st = ReadStatic(host, id, nowMs);
if (st == null) return null;
_static[id] = st;
}
var it = new CarriedItem
{
Id = id,
Name = st.Name,
Wcid = st.Wcid,
Material = st.Material,
ItemType = st.ItemType,
Bitfield = st.Bitfield,
MaxStack = st.MaxStack,
MaxUses = st.MaxUses,
ValidLocations = st.ValidLocations,
CombatUse = st.CombatUse,
DamageType = st.DamageType,
UiEffects = st.UiEffects,
Icon = st.Icon,
Underlay = st.Underlay,
Overlay = st.Overlay,
};
if (host.TryGetObjectIntProperty(id, StackSize, out int stack) && stack > 0) it.Stack = stack;
if (st.MaxUses > 0 && host.TryGetObjectIntProperty(id, Structure, out int uses)) it.Uses = Math.Max(0, uses);
return it;
}
private static bool Stale(Static st, long nowMs) =>
(st.ItemType & ItemKinds.TypeCaster) != 0 && st.DamageType == 0 && nowMs - st.ReadMs >= RecheckMs;
private static Static? ReadStatic(RynthCoreHost host, uint id, long nowMs)
{
if (!host.TryGetObjectName(id, out string name) || string.IsNullOrWhiteSpace(name)) return null;
var st = new Static { Name = name.Trim(), ReadMs = nowMs };
if (host.TryGetItemType(id, out uint type)) st.ItemType = type;
st.IsContainer = (st.ItemType & ItemTypeContainer) != 0;
if (host.HasGetObjectWcid && host.TryGetObjectWcid(id, out uint wcid)) st.Wcid = wcid;
if (host.HasGetObjectBitfield && host.TryGetObjectBitfield(id, out uint bf)) st.Bitfield = bf;
if (host.TryGetObjectIntProperty(id, MaterialType, out int material)) st.Material = Math.Max(0, material);
if (host.TryGetObjectIntProperty(id, MaxStackSize, out int maxStack)) st.MaxStack = Math.Max(1, maxStack);
if (host.TryGetObjectIntProperty(id, MaxStructure, out int maxUses) && maxUses > 0) st.MaxUses = maxUses;
if (host.TryGetObjectIntProperty(id, ValidLocations, out int valid)) st.ValidLocations = valid;
if (host.TryGetObjectIntProperty(id, CombatUse, out int use)) st.CombatUse = use;
if (host.TryGetObjectIntProperty(id, DamageType, out int dt)) st.DamageType = dt;
if (host.TryGetObjectIntProperty(id, UiEffects, out int fx)) st.UiEffects = fx;
if (host.HasGetObjectDataIdProperty)
{
if (host.TryGetObjectDataIdProperty(id, DidIcon, out uint icon)) st.Icon = icon;
if (host.TryGetObjectDataIdProperty(id, DidIconUnderlay, out uint under)) st.Underlay = under;
if (host.TryGetObjectDataIdProperty(id, DidIconOverlay, out uint over)) st.Overlay = over;
}
return st;
}
private static void Ownership(RynthCoreHost host, uint id, out uint container, out uint wielder, out uint location)
{
container = wielder = location = 0;
if (host.HasGetObjectOwnershipInfo && host.TryGetObjectOwnershipInfo(id, out container, out wielder, out location)) return;
if (host.HasGetObjectWielderInfo && host.TryGetObjectWielderInfo(id, out uint w, out uint loc)) { wielder = w; location = loc; }
}
}

View file

@ -0,0 +1,145 @@
using System;
namespace RynthCore.Plugin.RynthDefective.Items;
/// <summary>What an item is, as far as using it goes.</summary>
internal enum ItemKind
{
/// <summary>Anything used by itself: potions, scrolls, food, gems, summons ...</summary>
Other,
/// <summary>A healing or stamina kit: used on yourself.</summary>
Kit,
Melee,
Missile,
/// <summary>A wand, staff or orb that casts war magic (any element but Nether).</summary>
WarWand,
/// <summary>A caster of Nether: void magic.</summary>
VoidWand,
Shield,
Armor,
Jewelry,
Ammo,
}
/// <summary>What pressing an item's slot does with it.</summary>
internal enum UseAction
{
/// <summary>UseObject: double-clicking it (potions, scrolls, food).</summary>
Use,
/// <summary>UseObjectOn(item, you): healing and stamina kits.</summary>
UseOnSelf,
/// <summary>UseObjectOn(item, the selected target).</summary>
UseOnSelected,
/// <summary>Wield or wear it (UseObject: the client's double-click takes what is in the way off).</summary>
Equip,
}
/// <summary>The weapon picker's groups, in the order they are listed.</summary>
internal enum WeaponGroup { Melee, Missile, WarMagic, VoidMagic, Shield, Ammo }
internal static class ItemKinds
{
// ItemType flags
public const uint TypeMelee = 0x1, TypeArmor = 0x2, TypeClothing = 0x4, TypeJewelry = 0x8, TypeMissile = 0x100, TypeCaster = 0x8000;
// PublicWeenieDesc bitfield: the healer bit
public const uint BitfieldHealer = 0x10000;
// EquipMask slots
public const int ShieldSlot = 0x00200000, AmmoSlot = 0x00800000;
// CombatUse values
public const int CombatUseAmmo = 3, CombatUseShield = 4;
// DamageType / UiEffects bits of Nether
public const int DamageNether = 0x400, EffectNether = 0x1000;
public static ItemKind Classify(CarriedItem it)
{
bool equippable = it.ValidLocations != 0;
if (!equippable)
{
if ((it.Bitfield & BitfieldHealer) != 0) return ItemKind.Kit;
// The engine couldn't read the bitfield: RynthAi's own test for the kits it uses.
if (it.Bitfield == 0 && it.Name.EndsWith(" Kit", StringComparison.OrdinalIgnoreCase)) return ItemKind.Kit;
return ItemKind.Other;
}
bool weaponClass = (it.ItemType & (TypeMelee | TypeMissile | TypeCaster)) != 0 || IsWandName(it.Name);
if (it.CombatUse == CombatUseAmmo || (it.ValidLocations & AmmoSlot) != 0) return ItemKind.Ammo;
if (it.CombatUse == CombatUseShield || (!weaponClass && (it.ValidLocations & ShieldSlot) != 0)) return ItemKind.Shield;
if ((it.ItemType & TypeCaster) != 0 || (weaponClass && (it.ItemType & (TypeMelee | TypeMissile)) == 0))
return IsNether(it) ? ItemKind.VoidWand : ItemKind.WarWand;
if ((it.ItemType & TypeMissile) != 0) return ItemKind.Missile;
if ((it.ItemType & TypeMelee) != 0) return ItemKind.Melee;
if ((it.ItemType & TypeJewelry) != 0) return ItemKind.Jewelry;
return ItemKind.Armor; // armor, clothing and anything else that is worn
}
/// <summary>What a slot does with the item when the player has set nothing else.</summary>
public static UseAction DefaultAction(ItemKind kind) => kind switch
{
ItemKind.Kit => UseAction.UseOnSelf,
ItemKind.Other => UseAction.Use,
_ => UseAction.Equip,
};
public static bool IsWeapon(ItemKind k) => k is ItemKind.Melee or ItemKind.Missile or ItemKind.WarWand or ItemKind.VoidWand;
/// <summary>The picker group of a kind, or null when the picker doesn't list it.</summary>
public static WeaponGroup? GroupOf(ItemKind k) => k switch
{
ItemKind.Melee => WeaponGroup.Melee,
ItemKind.Missile => WeaponGroup.Missile,
ItemKind.WarWand => WeaponGroup.WarMagic,
ItemKind.VoidWand => WeaponGroup.VoidMagic,
ItemKind.Shield => WeaponGroup.Shield,
ItemKind.Ammo => WeaponGroup.Ammo,
_ => null,
};
public static string Label(WeaponGroup g) => g switch
{
WeaponGroup.Melee => "Melee",
WeaponGroup.Missile => "Missile",
WeaponGroup.WarMagic => "War Magic",
WeaponGroup.VoidMagic => "Void Magic",
WeaponGroup.Shield => "Shields",
_ => "Ammunition",
};
/// <summary>A caster whose element is Nether (the damage type, the icon's glow, or the name).</summary>
public static bool IsNether(CarriedItem it) =>
(it.DamageType & DamageNether) != 0
|| (it.DamageType == 0 && (it.UiEffects & EffectNether) != 0)
|| (it.DamageType == 0 && it.UiEffects == 0 && HasWord(it.Name, "Nether", "Void"));
/// <summary>The element a caster is named or glows for, for the picker's second column ("" = none known).</summary>
public static string Element(CarriedItem it)
{
if ((it.DamageType & 0x400) != 0) return "Nether";
if ((it.DamageType & 0x10) != 0) return "Fire";
if ((it.DamageType & 0x08) != 0) return "Cold";
if ((it.DamageType & 0x40) != 0) return "Lightning";
if ((it.DamageType & 0x20) != 0) return "Acid";
int fx = it.UiEffects;
if ((fx & 0x1000) != 0) return "Nether";
if ((fx & 0x0020) != 0) return "Fire";
if ((fx & 0x0080) != 0) return "Cold";
if ((fx & 0x0040) != 0) return "Lightning";
if ((fx & 0x0100) != 0) return "Acid";
if ((fx & 0x0400) != 0) return "Slash";
if ((fx & 0x0800) != 0) return "Pierce";
if ((fx & 0x0200) != 0) return "Bludgeon";
return string.Empty;
}
public static bool IsWandName(string? name) => HasWord(name, "Orb", "Staff", "Wand", "Scepter", "Sceptre", "Baton", "Crozier");
private static bool HasWord(string? name, params string[] words)
{
if (string.IsNullOrEmpty(name)) return false;
foreach (string w in words)
if (name.IndexOf(w, StringComparison.OrdinalIgnoreCase) >= 0) return true;
return false;
}
/// <summary>A launcher needs ammunition in hand; a thrown weapon (a stack of darts) does not.</summary>
public static bool NeedsAmmo(CarriedItem it) => it.MaxStack <= 1;
}

View file

@ -0,0 +1,33 @@
using System;
namespace RynthCore.Plugin.RynthDefective.Items;
/// <summary>Display names: a weapon's material in front of the base name the client reports.</summary>
internal static class ItemNames
{
/// <summary>ACE's MaterialType names, index = the id (0 = none).</summary>
private static readonly string[] Materials =
{
"", "Ceramic", "Porcelain", "Cloth", "Linen", "Satin", "Silk", "Velvet", "Wool", "Gem",
"Agate", "Amber", "Amethyst", "Aquamarine", "Azurite", "Black Garnet", "Black Opal", "Bloodstone", "Carnelian", "Citrine",
"Diamond", "Emerald", "Fire Opal", "Green Garnet", "Green Jade", "Hematite", "Imperial Topaz", "Jet", "Lapis Lazuli", "Lavender Jade",
"Malachite", "Moonstone", "Onyx", "Opal", "Peridot", "Red Garnet", "Red Jade", "Rose Quartz", "Ruby", "Sapphire",
"Smokey Quartz", "Sunstone", "Tiger Eye", "Tourmaline", "Turquoise", "White Jade", "White Quartz", "White Sapphire", "Yellow Garnet", "Yellow Topaz",
"Zircon", "Ivory", "Leather", "Armoredillo Hide", "Gromnie Hide", "Reed Shark Hide", "Metal", "Brass", "Bronze", "Copper",
"Gold", "Iron", "Pyreal", "Silver", "Steel", "Stone", "Alabaster", "Granite", "Marble", "Obsidian",
"Sandstone", "Serpentine", "Wood", "Ebony", "Mahogany", "Oak", "Pine", "Teak",
};
public static string Material(int id) => id > 0 && id < Materials.Length ? Materials[id] : string.Empty;
/// <summary>"Silver Wand": the material in front, unless the name already starts with it.</summary>
public static string Full(string? baseName, int material)
{
string name = (baseName ?? string.Empty).Trim();
string mat = Material(material);
if (mat.Length == 0 || name.Length == 0) return name;
if (name.StartsWith(mat + " ", StringComparison.OrdinalIgnoreCase) || name.Equals(mat, StringComparison.OrdinalIgnoreCase))
return name;
return mat + " " + name;
}
}