Snapshot for release 2026.10.18.1 (internal 0b612bf)

This commit is contained in:
Tom Bohar 2026-10-18 19:44:48 -04:00
commit 605ec6f0e6
9 changed files with 318 additions and 2 deletions

View file

@ -4083,6 +4083,24 @@ internal static class ClientObjectHooks
internal static bool IsContainerInSnapshot(uint objectId) =>
TryGetPwdSnapshotInt(objectId, 6, out int capacity) && capacity > 0;
/// <summary>
/// EquipmentTracker's start: the ids the PWD snapshot shows as wielded by <paramref name="playerId"/>
/// in no container, with their location. Both fields must agree: the wielder alone stays on an
/// item after it went into a pack (2026-10-17). Off-thread safe (snapshot only).
/// </summary>
internal static void CollectWieldedFromSnapshot(uint playerId, List<(uint Id, uint Loc)> dest)
{
lock (_weeniePtrSwapLock)
{
foreach (KeyValuePair<uint, PwdEntry> kv in _pwdFront)
{
if (kv.Key == playerId) continue;
if (kv.Value.Wielder == playerId && kv.Value.Container == 0 && kv.Value.Location != 0)
dest.Add((kv.Key, kv.Value.Location));
}
}
}
/// <summary>
/// Off-thread helper for UpdateObjectInventoryHooks: writes the ids whose PWD
/// container or wielder is <paramref name="containerId"/> from the main-thread

View file

@ -0,0 +1,228 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace RynthCore.Engine.Compatibility;
/// <summary>
/// What the player wields, and where, from the server's own messages (the way Decal's object
/// database knows it, and why VTank never guesses):
/// * GameEvent 0x0023 WieldObject [item][EquipMask]: the item is wielded in that slot;
/// * GameEvent 0x0022 InventoryPutObjInContainer [item][container]..: it is in a container;
/// * GameEvent 0x019A InventoryPutObjectIn3D [item]: it was dropped.
/// (ACE: GameEventWieldItem, GameEventItemServerSaysContainId, GameEventItemServerSaysMoveItem.)
///
/// The client's own copy of these fields goes stale on this client: CurrentWieldedLocation reads 0
/// and the PWD wielder keeps naming the player after the item went into a pack (Drakkon fought
/// bare-handed and died over it, 2026-10-17/18). The tracker starts from the client's PWD snapshot
/// where its fields agree (wielder = the player and no container), then follows the messages.
/// Messages that arrive before that start are kept and applied on top of it.
///
/// The record survives an engine reload (/rc rl, a publish): every change is written to
/// %LOCALAPPDATA%\RynthCore\equip\p{pid}.txt and a new engine in the same client starts from it.
/// The client's fields are only right at login: restarted from them mid-session, the tracker had
/// the Sceptre "in hand" that the server had put into the pack minutes before (2026-10-18 12:29).
/// At logout the file is deleted, so the next login starts from the login's own records.
///
/// Thread safety: the game-event hook runs on AC's main thread, plugins ask from the pump thread;
/// everything goes through <see cref="Gate"/>.
/// </summary>
internal static class EquipmentTracker
{
private static readonly object Gate = new();
private static readonly Dictionary<uint, uint> _wielded = new(); // item -> EquipMask
private static readonly Dictionary<uint, uint> _pending = new(); // before the start: item -> EquipMask (0 = not wielded)
private static uint _playerId;
private static bool _seeded;
private static int _changes;
private static string _source = "";
private static string FilePath => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RynthCore", "equip",
$"p{Environment.ProcessId}.txt");
/// <summary>Where the current record started from ("saved", "login records", "client records mid-session").</summary>
public static string Source { get { lock (Gate) return _source; } }
// Writes the record (under Gate). A failed write only loses the carry-over across a reload.
private static void SaveLocked()
{
try
{
string path = FilePath;
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
var lines = new List<string>(_wielded.Count + 1) { $"player {_playerId:X8}" };
foreach (var kv in _wielded) lines.Add($"{kv.Key:X8} {kv.Value:X8}");
File.WriteAllLines(path, lines);
}
catch { }
}
// The saved record for this client and character, or null.
private static Dictionary<uint, uint>? LoadSaved(uint player)
{
try
{
string path = FilePath;
if (!File.Exists(path)) return null;
string[] lines = File.ReadAllLines(path);
if (lines.Length == 0 || lines[0] != $"player {player:X8}") return null;
var map = new Dictionary<uint, uint>();
for (int i = 1; i < lines.Length; i++)
{
string[] parts = lines[i].Split(' ');
if (parts.Length == 2
&& uint.TryParse(parts[0], System.Globalization.NumberStyles.HexNumber, null, out uint id)
&& uint.TryParse(parts[1], System.Globalization.NumberStyles.HexNumber, null, out uint loc))
map[id] = loc;
}
return map;
}
catch { return null; }
}
private static void DeleteSaved()
{
try { File.Delete(FilePath); } catch { }
}
/// <summary>A WieldObject for <paramref name="item"/> at <paramref name="location"/> (main thread).</summary>
public static void OnWield(uint item, uint location)
{
if (item == 0) return;
lock (Gate)
{
if (!_seeded) { _pending[item] = location; return; }
if (location == 0) _wielded.Remove(item); else _wielded[item] = location;
_changes++;
SaveLocked();
}
RynthLog.Compat($"Equipment: 0x{item:X8} wielded at 0x{location:X8} (server)");
}
/// <summary>An InventoryPutObjInContainer for <paramref name="item"/> (main thread): not wielded.</summary>
public static void OnContained(uint item, uint container)
{
if (item == 0) return;
bool was;
lock (Gate)
{
if (!_seeded) { _pending[item] = 0; return; }
was = _wielded.Remove(item);
if (was) { _changes++; SaveLocked(); }
}
if (was) RynthLog.Compat($"Equipment: 0x{item:X8} into container 0x{container:X8} (server)");
}
/// <summary>An InventoryPutObjectIn3D for <paramref name="item"/> (main thread): dropped, not wielded.</summary>
public static void OnDropped(uint item)
{
if (item == 0) return;
bool was;
lock (Gate)
{
if (!_seeded) { _pending[item] = 0; return; }
was = _wielded.Remove(item);
if (was) { _changes++; SaveLocked(); }
}
if (was) RynthLog.Compat($"Equipment: 0x{item:X8} dropped (server)");
}
/// <summary>
/// The player's wielded items into <paramref name="ids"/> / <paramref name="locations"/>. Returns the
/// count, or -1 while there is no player or no PWD snapshot to start from. Any thread.
/// </summary>
public static int Copy(Span<uint> ids, Span<uint> locations)
{
if (!EnsureStarted()) return -1;
lock (Gate)
{
int n = 0;
foreach (var kv in _wielded)
{
if (n >= ids.Length || n >= locations.Length) break;
ids[n] = kv.Key;
locations[n] = kv.Value;
n++;
}
return n;
}
}
/// <summary>Starts (or restarts, for another character) from the PWD snapshot. False until it can.</summary>
private static bool EnsureStarted()
{
if (LogoutLifecycleHooks.HasObservedLogout)
{
bool had;
lock (Gate) had = _seeded;
if (had) { Reset(); DeleteSaved(); RynthLog.Compat("Equipment: logged out - the record is dropped"); }
return false;
}
uint player = ClientHelperHooks.GetPlayerId();
if (player == 0) return false;
lock (Gate)
{
if (_seeded && player == _playerId) return true;
}
Dictionary<uint, uint>? saved = LoadSaved(player);
if (saved == null && !ClientObjectHooks.HasPwdSnapshot) return false;
var seed = new List<(uint Id, uint Loc)>();
string from;
if (saved != null)
{
foreach (var kv in saved) seed.Add((kv.Key, kv.Value));
from = "the record saved before the engine reload";
}
else
{
ClientObjectHooks.CollectWieldedFromSnapshot(player, seed);
from = LoginLifecycleHooks.HasObservedLoginComplete ? "the client's records (at login)" : "the client's records (mid-session: may be stale until items move)";
}
string list;
lock (Gate)
{
if (_seeded && player == _playerId) return true;
bool other = _seeded && player != _playerId;
_wielded.Clear();
foreach (var (id, loc) in seed) _wielded[id] = loc;
// Messages seen before the start are newer than the snapshot read, except after a
// character change (they were the last character's).
if (!other)
foreach (var kv in _pending)
{
if (kv.Value == 0) _wielded.Remove(kv.Key);
else _wielded[kv.Key] = kv.Value;
}
_pending.Clear();
_playerId = player;
_seeded = true;
_source = from;
SaveLocked();
list = _wielded.Count == 0 ? "nothing" : string.Join(", ", FormatAll());
}
RynthLog.Compat($"Equipment: started for 0x{player:X8} from {from}: {list}");
return true;
}
private static IEnumerable<string> FormatAll()
{
foreach (var kv in _wielded) yield return $"0x{kv.Key:X8}@0x{kv.Value:X}";
}
/// <summary>Forget everything (logout, teardown): the next query starts again.</summary>
public static void Reset()
{
lock (Gate)
{
_wielded.Clear();
_pending.Clear();
_seeded = false;
_playerId = 0;
}
}
/// <summary>Changes followed since the start (diagnostics).</summary>
public static int Changes { get { lock (Gate) return _changes; } }
}

View file

@ -408,10 +408,23 @@ internal static class SmartBoxHooks
// nothing cached is a candidate. Here, not on the server message stream,
// so it works with that stream off (engine.json / /rc netmsg off).
if (size >= 12)
AutoIdService.OnPutInContainer(
{
uint putItem = unchecked((uint)Marshal.ReadInt32(IntPtr.Add(data, 4)));
uint putContainer = unchecked((uint)Marshal.ReadInt32(IntPtr.Add(data, 8)));
AutoIdService.OnPutInContainer(putItem, putContainer);
EquipmentTracker.OnContained(putItem, putContainer);
}
break;
case 0x0023: // WieldObject: [item u32][EquipMask u32] (ACE GameEventWieldItem).
if (size >= 12)
EquipmentTracker.OnWield(
unchecked((uint)Marshal.ReadInt32(IntPtr.Add(data, 4))),
unchecked((uint)Marshal.ReadInt32(IntPtr.Add(data, 8))));
break;
case 0x019A: // InventoryPutObjectIn3D: [item u32] (ACE GameEventItemServerSaysMoveItem): dropped.
if (size >= 8)
EquipmentTracker.OnDropped(unchecked((uint)Marshal.ReadInt32(IntPtr.Add(data, 4))));
break;
case 0x00A0: // InventoryServerSaveFailed: [objectId u32][errorType u32] —
// the server refused an inventory change (wield, move, ...).
// Layout from UIQueueManager::ProcessNetBlobData's inline case

View file

@ -944,6 +944,12 @@ internal struct RynthCoreAPI
/// schema). Returns the UTF-8 byte length; when it is &gt;= capacity nothing was written (call
/// again with a bigger buffer). -1 on failure. Any thread. Requires API v86+.</summary>
public IntPtr GetServerStateJsonFn;
/// <summary>v87: <c>int GetWieldedItems(uint* ids, uint* locations, int max)</c>: what the player
/// wields and where (EquipMask), from the server's WieldObject / InventoryPutObjInContainer /
/// InventoryPutObjectIn3D messages, started from the client's records where they agree
/// (Compatibility/EquipmentTracker.cs). Returns the count written (at most max), or -1 while
/// there is no player or nothing to start from. Any thread. Requires API v87+.</summary>
public IntPtr GetWieldedItemsFn;
}
/// <summary>v79 <see cref="TrainingInfoNative.Flags"/> bits.</summary>
@ -1756,6 +1762,8 @@ internal unsafe delegate int GetServerInfoCallbackDelegate(byte* worldName, int
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetServerStateJsonCallbackDelegate(byte* buffer, int capacity);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetWieldedItemsCallbackDelegate(uint* ids, uint* locations, int max);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int CloseContainerCallbackDelegate(uint containerId);

View file

@ -23,5 +23,7 @@ internal static class PluginContractVersion
// craft chance, for a plugin; from SilentKelpie's build, 2026-10-15).
// v86: GetServerStateJson (the server list, active server and owning plugins for every plugin;
// server plugins declare their server in their manifest; from SilentKelpie's build).
public const uint Current = 86;
// v87: GetWieldedItems (what the player wields and where, from the server's wield / contain /
// drop messages: EquipmentTracker; the client's own fields go stale, 2026-10-18).
public const uint Current = 87;
}

View file

@ -279,6 +279,7 @@ internal static partial class PluginManager
private static ArmConfirmationCallbackDelegate? _armConfirmationCallback; // v85
private static GetLastConfirmationCallbackDelegate? _getLastConfirmationCallback; // v85
private static GetServerStateJsonCallbackDelegate? _getServerStateJsonCallback; // v86
private static GetWieldedItemsCallbackDelegate? _getWieldedItemsCallback; // v87
private static ForceResetBusyCountCallbackDelegate? _forceResetBusyCountCallback;
private static GetObjectSpellIdsCallbackDelegate? _getObjectSpellIdsCallback;
private static GetObjectSkillLevelCallbackDelegate? _getObjectSkillBuffedCallback;
@ -3135,6 +3136,7 @@ internal static partial class PluginManager
_armConfirmationCallback ??= ArmConfirmationAction;
unsafe { _getLastConfirmationCallback ??= GetLastConfirmationAction; }
unsafe { _getServerStateJsonCallback ??= GetServerStateJsonAction; }
unsafe { _getWieldedItemsCallback ??= GetWieldedItemsAction; }
_api.Version = PluginContractVersion.Current;
_api.LogFn = Marshal.GetFunctionPointerForDelegate(_logCallback);
@ -3288,6 +3290,7 @@ internal static partial class PluginManager
_api.ArmConfirmationFn = Marshal.GetFunctionPointerForDelegate(_armConfirmationCallback);
_api.GetLastConfirmationFn = Marshal.GetFunctionPointerForDelegate(_getLastConfirmationCallback);
_api.GetServerStateJsonFn = Marshal.GetFunctionPointerForDelegate(_getServerStateJsonCallback);
_api.GetWieldedItemsFn = Marshal.GetFunctionPointerForDelegate(_getWieldedItemsCallback);
RouteApiThroughLoader();
}
@ -3485,6 +3488,20 @@ internal static partial class PluginManager
/// v86: the server list as JSON (UI/Sections/ServerStateJson.cs) from the published snapshot.
/// Any thread: the snapshot is immutable and the strings are volatile reads. -1 on failure.
/// </summary>
/// <summary>v87: what the player wields (EquipmentTracker). -1 while it can't start.</summary>
private static unsafe int GetWieldedItemsAction(uint* ids, uint* locations, int max)
{
try
{
if (ids == null || locations == null || max <= 0) return -1;
return Compatibility.EquipmentTracker.Copy(new Span<uint>(ids, max), new Span<uint>(locations, max));
}
catch
{
return -1;
}
}
private static unsafe int GetServerStateJsonAction(byte* buffer, int capacity)
{
try

View file

@ -40,6 +40,9 @@ internal sealed class RynthAiSettings
public int TargetFPSBackground { get; set; } = 30;
public bool EnableAutocram { get; set; }
public bool PeaceModeWhenIdle { get; set; }
// RynthAi's Weapons Back After Heals. Nullable: an older RynthAi doesn't send it, and the
// engine then sends none back (a false would turn it off).
public bool? RearmAfterVitals { get; set; }
public bool StartMacroOnLogin { get; set; }
public bool PatrolOnLogin { get; set; }
// RynthAi's Escape Acid and Lava. Default on; an older RynthAi doesn't send it, and a missing
@ -720,6 +723,8 @@ internal static class SettingsSchema
Bool("Auto Cram", s => s.EnableAutocram, (s, v) => s.EnableAutocram = v,
"Automatically moves items from your main pack into side packs.\nNote: recently used weapons stay in the main pack."),
Bool("Peace Mode When Idle", s => s.PeaceModeWhenIdle, (s, v) => s.PeaceModeWhenIdle = v),
Bool("Weapons Back After Heals", s => s.RearmAfterVitals == true, (s, v) => s.RearmAfterVitals = v,
"After a heal, restam or remana spell with nothing to fight, put the last fight's weapons\n(main hand and off hand) back on instead of waiting for the next monster."),
Bool("Start Macro On Login", s => s.StartMacroOnLogin, (s, v) => s.StartMacroOnLogin = v,
"Automatically starts the macro when RynthAi loads."),
Bool("Patrol On Login", s => s.PatrolOnLogin, (s, v) => s.PatrolOnLogin = v,