From 316527227f1e6f5c79572e17ab0705007988193e Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Mon, 12 Oct 2026 16:20:31 -0700 Subject: [PATCH] Hold corpse opens and automatic world uses while the salvage panel is pending A corpse use sent between the salvage UST use and the salvage execute is swallowed by the client, and the corpse loop then waits for an open that never comes. - SalvageManager.PanelPending: the UST was used and the execute is not sent yet (main cycle and the combine sweep). - Corpse open waits while it is true, with the claim's timeout clock stopped, and logs the wait once. - UseAudit.WorldUseHold: automatic door/corpse uses are held (logged HELD, return false) while RynthAi says so; uses the player asks for are never held. Cleared by Reset; RynthAi wires it at init and clears it at shutdown. - Test: LootPacingTests (panel pending 20 s: no corpse use, claim kept, auto world use held; after the execute the corpse opens). Co-Authored-By: Claude Opus 5.5 (1M context) --- .../CorpseOpenController.cs | 15 ++ .../Loot/SalvageManager.cs | 12 ++ .../RynthAiPlugin.Pacing.cs | 8 + .../RynthCore.Plugin.RynthAi/RynthAiPlugin.cs | 2 + Plugins/Shared/UseAudit.cs | 18 ++ Tools/RynthCore.RynthAiHostTests/Program.cs | 1 + .../Tests/LootPacingTests.cs | 176 ++++++++++++++++++ 7 files changed, 232 insertions(+) create mode 100644 Tools/RynthCore.RynthAiHostTests/Tests/LootPacingTests.cs diff --git a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs index f2049d8..50a021f 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs @@ -695,6 +695,20 @@ public sealed partial class RynthAiPlugin FreezeCorpseTimeout(now); return; } + // The salvage panel is opening (UST used, execute not sent yet): the client would swallow + // the use (SalvageManager.PanelPending). Wait, with the claim's timeout clock stopped (this + // sits before the freeze reset below so the frozen age carries across held ticks). + if (_salvageManager?.PanelPending == true) + { + FreezeCorpseTimeout(now); + if (!_openHeldBySalvageLogged) + { + _openHeldBySalvageLogged = true; + LootDiag($"[RynthAi] Corpse loot: open of 0x{(uint)_targetCorpseId:X8} waits for the salvage panel (UST used, salvage not sent yet)."); + } + return; + } + _openHeldBySalvageLogged = false; _corpseHoldFrozenAge = -1; // One server action at a time (2026-10-06, ActionPacer): no open while the server is still @@ -761,6 +775,7 @@ public sealed partial class RynthAiPlugin } private long _corpseOpenBusyWaitSince; + private bool _openHeldBySalvageLogged; // Peace before the open: one request per claimed corpse, only with no monster within // LootStarveCloseYards (the same test that gives looting its turn while combat still has a diff --git a/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs index 3b6c076..0650daf 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs @@ -196,6 +196,18 @@ public sealed class SalvageManager /// Returns true while a salvage operation is in flight. public bool IsBusy => _phase != Phase.Idle || _queue.Count > 0; + /// + /// True from the UST use until the salvage execute has gone out (a batch or a bag combine). + /// Meanwhile the client swallows a door or corpse use: no Use packet, no busy count, and the + /// open waited out its 5 s limit (in one log, 6 of 6 corpse opens sent 0-155 ms after the UST + /// use were lost; 4 of 4 sent after the execute were answered). Narrower than IsBusy, which + /// also covers a queued batch whose panel isn't open yet. + /// + public bool PanelPending => + _phase is Phase.OpeningPanel or Phase.AddingItems or Phase.ReadyToExecute + || (_phase == Phase.CombiningSalvage + && _combinePhase is CombinePhase.OpeningPanel or CombinePhase.AddingBags or CombinePhase.Salvaging); + /// /// Looting sent the pickup of an item whose rule says Salvage. Tracks it without queueing: /// the sweep queues it once it is in the pack, even if the pickup confirm never comes. diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.Pacing.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.Pacing.cs index fd7c8bf..a095161 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.Pacing.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.Pacing.cs @@ -13,6 +13,14 @@ namespace RynthCore.Plugin.RynthAi; // ============================================================================ public sealed partial class RynthAiPlugin { + /// + /// UseAudit.WorldUseHold: an automatic door or corpse use waits while the salvage panel is + /// between the Ust use and the salvage send. A world use in that window is swallowed by the + /// client, and the corpse loop then sat waiting for an open that never came. + /// + private string? SalvagePanelHold() => + _salvageManager?.PanelPending == true ? "the salvage panel is opening; the use waits for the salvage to go out" : null; + /// UseAudit.AfterSend: a use or use-on went out - record it as the action the server is answering. private static void RecordUseForPacing(RynthCoreHost host, UseAudit.SentUse use) { diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs index dba556c..a78b5c3 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs @@ -186,6 +186,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase RynthCore.Plugin.Shared.ActionPacer.Reset(); RynthCore.Plugin.Shared.ActionPacer.Enabled = true; RynthCore.Plugin.Shared.UseAudit.AfterSend = RecordUseForPacing; + RynthCore.Plugin.Shared.UseAudit.WorldUseHold = SalvagePanelHold; _objectCache = new WorldObjectCache(Host); // must exist before CreateObject events fire during login // Items we use (or use something on) get re-identified before a meta reads them. // ObjectUsed is a static event and Shutdown never unsubscribes: when the engine @@ -234,6 +235,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase // Don't let the static audit hold this instance once it's gone (a reused module). RynthCore.Plugin.Shared.UseAudit.MacroOn = static () => false; RynthCore.Plugin.Shared.UseAudit.AfterSend = null; + RynthCore.Plugin.Shared.UseAudit.WorldUseHold = null; RynthCore.Plugin.Shared.ActionPacer.Enabled = false; RynthCore.Plugin.Shared.ActionPacer.Forget("shutdown"); diff --git a/Plugins/Shared/UseAudit.cs b/Plugins/Shared/UseAudit.cs index 605bbd4..fbb1206 100644 --- a/Plugins/Shared/UseAudit.cs +++ b/Plugins/Shared/UseAudit.cs @@ -84,6 +84,7 @@ internal static class UseAudit _worldUseSentMs = 0; _worldUseSeqAtSend = 0; AfterSend = null; + WorldUseHold = null; } } @@ -96,6 +97,16 @@ internal static class UseAudit Write(host, objectId, subsystem, $"BLOCKED 0x{objectId:X8} {what} macro=off auto - {why} (with the macro off nothing opens a door or corpse unless you ask)", force: true); return false; } + if (kind == UseKind.Auto && doorOrCorpse) + { + string? hold = null; + try { hold = WorldUseHold?.Invoke(); } catch { hold = null; } + if (!string.IsNullOrEmpty(hold)) + { + Write(host, objectId, subsystem, $"HELD 0x{objectId:X8} {what} auto - {why} ({hold})", force: false); + return false; + } + } Write(host, objectId, subsystem, $"0x{objectId:X8} {what} macro={MacroText} {KindText(kind)} - {why}", force: false); int seqBefore = 0; bool track = TrackWorldUses && doorOrCorpse; @@ -124,6 +135,13 @@ internal static class UseAudit /// public static Action? AfterSend; + /// + /// Asked before an automatic door or corpse use: a reason to hold it back (nothing is sent, the + /// call returns false), or null/empty to send. RynthAi holds them while the salvage panel opens + /// (the client swallows the use then). A use the player asked for is never held. Cleared by Reset. + /// + public static Func? WorldUseHold; + // ── A door or corpse use the server hasn't answered yet (2026-10-06) ────────── // The server walks/turns the character to a used door or corpse, and any movement packet // from the client cancels that (ACE: a MoveToState stops the move-to chain, and a combat diff --git a/Tools/RynthCore.RynthAiHostTests/Program.cs b/Tools/RynthCore.RynthAiHostTests/Program.cs index 40ffc78..b7f2550 100644 --- a/Tools/RynthCore.RynthAiHostTests/Program.cs +++ b/Tools/RynthCore.RynthAiHostTests/Program.cs @@ -99,6 +99,7 @@ internal static class Program CastNoDamageTests.Register(runner); ManaReserveTests.Register(runner); DamageRowsTests.Register(runner); + LootPacingTests.Register(runner); return runner.Run("RynthAi host tests", args.Length > 0 ? args[0] : null); } } diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/LootPacingTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/LootPacingTests.cs new file mode 100644 index 0000000..4f079b7 --- /dev/null +++ b/Tools/RynthCore.RynthAiHostTests/Tests/LootPacingTests.cs @@ -0,0 +1,176 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using RynthCore.Loot; +using RynthCore.Plugin.RynthAi; +using RynthCore.Plugin.RynthAi.LegacyUi; +using RynthCore.Plugin.RynthAi.Loot; +using RynthCore.Plugin.Shared; +using RynthCore.PluginCore; +using RynthCore.PluginSdk; +using RynthCore.RynthAiHostTests.Fakes; +using RynthCore.RynthAiTests.Harness; + +namespace RynthCore.RynthAiHostTests.Tests; + +// Loot findings: +// H. A corpse use sent between the salvage UST use and the salvage execute is swallowed by the +// client (the salvage panel open wins), and the corpse loop then waits for an open that never +// comes. Corpse opens (and every automatic door/corpse use, via UseAudit.WorldUseHold) wait +// while the salvage panel is pending; the corpse claim's timeout is not charged meanwhile. +internal static class LootPacingTests +{ + private const uint Player = 0x50000E01; + private const uint CorpseA = 0x80069ACE; + private const uint CorpseB = 0x80073023; + private const uint Ust = 0x80000E11; + private const uint Junk = 0x80000E12; + private const uint UstWcid = 20646; + private const uint ItemTypeContainer = 0x200, ItemTypeArmor = 0x2; + private const uint LongDescKey = 16; + private const string Me = "Drakkon"; + private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public; + private static (uint Cell, float X, float Y, float Z) Me0 => (0x6347028Au, 100f, 100f, 0f); + + public static void Register(Runner r) + { + r.Add("salvage/loot: no corpse open (or auto door/corpse use) while the salvage panel is pending; the claim is kept and opened after the execute", CorpseOpenWaitsForSalvagePanel); + } + + private static void World() + { + FakeHost.Reset(); + FakeHost.SalvageCalls = true; // UseObject + MoveItemExternal + salvage panel + FakeHost.WeaponCalls = true; + FakeHost.ServerGates = true; + FakeHost.LastUseDoneCalls = true; + FakeHost.StopCalls = true; + FakeHost.Names[Player] = Me; + FakeHost.Positions[Player] = Me0; + FakeHost.PlayerPose = Me0; + foreach ((uint id, float dx) in new[] { (CorpseA, 1.0f), (CorpseB, 1.5f) }) + { + FakeHost.Names[id] = "Corpse of Olthoi Swarm Worker"; + FakeHost.ItemTypes[id] = ItemTypeContainer; + FakeHost.Strings[(id, LongDescKey)] = $"Killed by {Me}."; + FakeHost.NotAttackable.Add(id); + FakeHost.Positions[id] = (Me0.Cell, Me0.X + dx, Me0.Y, Me0.Z); + } + FakeHost.Names[Ust] = "Salvaging Ust"; + FakeHost.Wcids[Ust] = UstWcid; + FakeHost.Names[Junk] = "Iron Breastplate"; + FakeHost.ItemTypes[Junk] = ItemTypeArmor; + FakeHost.Ints[(Junk, 131)] = 64; // MaterialType + } + + private sealed class Bot + { + public readonly RynthAiPlugin P = new(); + public readonly LegacyUiSettings S = new() + { + IsMacroRunning = true, + EnableLooting = true, + EnableCombat = false, + LootOwnership = 0, + LootContentSettleMs = 0, + LootEmptyCorpseMs = 0, + StopLootingWhenPackFull = false, + EnableCombineSalvage = false, + SalvageOpenDelayFirstMs = 400, SalvageOpenDelayFastMs = 50, + SalvageAddDelayFirstMs = 600, SalvageAddDelayFastMs = 50, + SalvageSalvageDelayMs = 50, + SalvageResultDelayFirstMs = 1000, SalvageResultDelayFastMs = 250, + }; + public readonly WorldObjectCache Cache; + + public Bot(RynthCoreHost host) + { + typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi }); + var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer)); + typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, S); + Set("_dashboard", dash); + Cache = new WorldObjectCache(host); + Cache.SetPlayerId(Player); + Set("_objectCache", Cache); + Set("_playerId", Player); + Cache.OnCreateObject(CorpseA); + Cache.OnCreateObject(CorpseB); + _ = Cache[unchecked((int)Ust)]; // filed as the indexer does (FakeHost.MakeCache) + _ = Cache[unchecked((int)Junk)]; + Cache.Tick(); + + string profile = Path.Combine(Program.TempRoot, "loot-pacing-test.json"); + var p = new LootProfile { Name = "nothing" }; + p.Save(profile); + S.CurrentLootPath = profile; + } + + public void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(P, v); + public T Get(string f) => (T)typeof(RynthAiPlugin).GetField(f, Any)!.GetValue(P)!; + public object? Call(string m, params object[] a) => typeof(RynthAiPlugin).GetMethod(m, Any)!.Invoke(P, a); + public void Tick() + { + Set("_activity", BotActivity.Looting); + Call("TickCorpseOpening"); + } + } + + private static int CorpseUses() => FakeHost.Uses.Count(u => u == CorpseA || u == CorpseB); + + private static void CorpseOpenWaitsForSalvagePanel() + { + World(); + var host = FakeHost.Create(Player); + var bot = new Bot(host); + long now = 60_000_000; + var savedClock = RynthAiPlugin.CorpseClock; + RynthAiPlugin.CorpseClock = () => now; + try + { + UseAudit.Reset("RynthAi", () => true); + // As RynthAiPlugin's init wires it. + UseAudit.WorldUseHold = (Func)Delegate.CreateDelegate(typeof(Func), bot.P, + typeof(RynthAiPlugin).GetMethod("SalvagePanelHold", Any)!); + + var mgr = new SalvageManager(host, bot.S, bot.Cache) { Clock = () => now }; + bot.Set("_salvageManager", mgr); + FakeHost.OnSalvageExecute = added => + { + foreach (uint id in added) { FakeHost.Names.Remove(id); bot.Cache.OnDeleteObject(id); } + }; + mgr.EnqueueItem(Junk); + + // The salvage cycle starts: UST used, panel not executed yet. + for (int i = 0; i < 200 && !FakeHost.Uses.Contains(Ust); i++) { now += 50; mgr.OnTick(0); } + Check.True(FakeHost.Uses.Contains(Ust), "the UST is used"); + FakeHost.UseDone(0); // the server answers the UST use (the panel opens) + Check.True(mgr.PanelPending, "the salvage panel is pending (UST used, no execute yet)"); + + // 20 s with the panel pending (longer than the 12 s claim timeout): looting ticks on. + for (int i = 0; i < 200; i++) { bot.Tick(); now += 100; } + Check.Eq(CorpseUses(), 0, "no corpse use while the salvage panel is pending"); + Check.Eq(bot.Get("_targetCorpseId"), unchecked((int)CorpseA), "the claim is kept, not abandoned on timeout"); + Check.Eq(FakeHost.Logs.Count(l => l.Contains("waits for the salvage panel")), 1, "the wait is logged once"); + + // Any other automatic door/corpse use is held too (nav doors, the use check's probes). + Check.False(host.UseFor(CorpseB, "Nav", "test: an automatic world use"), "an automatic world use is held"); + Check.Eq(CorpseUses(), 0, "and not sent"); + Check.True(FakeHost.Logs.Any(l => l.Contains("HELD 0x80073023")), "the hold is logged"); + + // The panel executes; the corpse opens on the next looting tick. + for (int i = 0; i < 200 && FakeHost.SalvageExecutes.Count == 0; i++) { now += 50; mgr.OnTick(0); } + Check.Eq(FakeHost.SalvageExecutes.Count, 1, "the salvage goes out"); + Check.False(mgr.PanelPending, "the panel is no longer pending once the execute is sent"); + for (int i = 0; i < 5 && CorpseUses() == 0; i++) { bot.Tick(); now += 100; } + Check.Eq(CorpseUses(), 1, "the corpse is opened after the execute"); + Check.True(FakeHost.Uses.Contains(CorpseA), "the claimed corpse"); + } + finally + { + RynthAiPlugin.CorpseClock = savedClock; + UseAudit.Reset("?", null); + } + } +}