From db05821a3769110f194eb145ac2d104382a65a9c Mon Sep 17 00:00:00 2001 From: koiseka Date: Sun, 8 Nov 2026 16:51:19 -0800 Subject: [PATCH 1/3] Fix missed treasures and chests - Golden chest variants (BGA_DelilahTreasureHuntAnimatedChest_*): read as TreasureHuntChest so the prize id is kept. - Treasure grants on FortAbilitySystemComponentAthena: the reader hands the raw ActivatableAbilities payload to RawProbe instead of the generic NetDelta decoding, and the analyzer accepts that component. - Buried chests: the grant comes when digging completes, ~2.4s before the chest reports searched; allow up to +4s for buried chests only. - Map chests with numbered names (Tiered_Chest_Athena47_UAID_..., *__): matched to the exact _C class instead of failing. - Analyzer version 11 so replays on disk are analyzed again. Co-Authored-By: Claude Opus 5.5 --- lib/PATCHES.md | 2 ++ lib/Unreal.Core/Models/NetGuidCache.cs | 22 ++++++++++++++++++++++ lib/Unreal.Core/ReplayReader.cs | 8 ++++++++ src/ChestCounter/ReplayAnalyzer.cs | 23 ++++++++++++++++++++--- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/PATCHES.md b/lib/PATCHES.md index e2b3150..41144cf 100644 --- a/lib/PATCHES.md +++ b/lib/PATCHES.md @@ -15,3 +15,5 @@ Changes for ChestCounter: 9. `Unreal.Core/BitReader.cs`: `SetTempEnd` always saves the current end, even on overflow. Otherwise the next `RestoreTempEnd` restored a stale end, reading went backwards and the parser looped until the 3-minute timeout ("analysis took too long"). 10. `Unreal.Core/ReplayReader.cs` + `BinaryReader.cs`: reading a replay **still being written**. `ReadReplayChunks` stops at the last complete chunk (`IsPartialReplay`, `BinaryReader.Length`), and an encrypted replay flagged "live" is accepted when its key is present. 11. `Unreal.Core/ReplayReader.cs`: in a "live" replay, an event or data chunk that cannot be decrypted is skipped, or stops the reading, instead of failing the analysis. Note: during the match, Fortnite leaves the encryption key at zero in the header and only writes the real key at the end. The data of a match in progress therefore cannot be read (`ReplayHeaderProbe.KeyMissing`). +12. `Unreal.Core/Models/NetGuidCache.cs`: level placed actors whose instance name is not their class name (`Tiered_Chest_Athena47_UAID_...`, `Tiered_Chest_Athena5_6e02a0a859c897db_11`) are matched to the exact `_C` class after stripping the UAID / instance hash and the number suffix. Before, these chests were never decoded ("Failed group") and were not counted. +13. `Unreal.Core/ReplayReader.cs`: a ClassNetCache custom delta property that `RawProbe` asks for (`FortAbilitySystemComponentAthena_ClassNetCache.ActivatableAbilities`) is handed over raw instead of being decoded as `GrantedAbility`, whose generic NetDelta decoding gives garbage indices. Without it the treasure handler grants were never read on players with the `FortAbilitySystemComponentAthena` class. diff --git a/lib/Unreal.Core/Models/NetGuidCache.cs b/lib/Unreal.Core/Models/NetGuidCache.cs index ffa59ef..707100d 100644 --- a/lib/Unreal.Core/Models/NetGuidCache.cs +++ b/lib/Unreal.Core/Models/NetGuidCache.cs @@ -138,6 +138,9 @@ public void AddToExportGroupMap(string group, NetFieldExportGroup exportGroup) /// /// /// + private static readonly System.Text.RegularExpressions.Regex StaticInstanceSuffix = + new(@"(_UAID_.*|_[0-9a-f]{16}_\d+)$", System.Text.RegularExpressions.RegexOptions.Compiled); + public NetFieldExportGroup? GetNetFieldExportGroup(uint? netguid) { if (!netguid.HasValue) @@ -200,6 +203,25 @@ public void AddToExportGroupMap(string group, NetFieldExportGroup exportGroup) } } + // ChestCounter patch: level placed actors whose instance name is not their class name, e.g. + // "Tiered_Chest_Athena47_UAID_387C..._1632776713" or "Tiered_Chest_Athena5_6e02a0a859c897db_11" (class + // Tiered_Chest_Athena_C). Strip the UAID / instance hash part and the number suffix and accept only an exact + // "_C" class, so a wrong layout is never used. + var baseName = StaticInstanceSuffix.Replace(path.RemoveAllPathPrefixes(), "").CleanPathSuffix(); + if (baseName.Length > 0) + { + var className = baseName + "_C"; + foreach (var groupPathKvp in NetFieldExportGroupMap) + { + if (_cleanedPaths.TryGetValue(groupPathKvp.Value.PathNameIndex, out var groupPathFixed) && groupPathFixed == className) + { + NetFieldExportGroupMapPathFixed[netguid.Value] = groupPathKvp.Value; + _archTypeToExportGroup[netguid.Value] = groupPathKvp.Value; + return groupPathKvp.Value; + } + } + } + _failedPaths.Add(path); return null; } diff --git a/lib/Unreal.Core/ReplayReader.cs b/lib/Unreal.Core/ReplayReader.cs index 7ecc1d4..3c9534d 100644 --- a/lib/Unreal.Core/ReplayReader.cs +++ b/lib/Unreal.Core/ReplayReader.cs @@ -1499,6 +1499,14 @@ public virtual bool ReceivedReplicatorBunch(DataBunch bunch, FBitArchive archive } else { + // ChestCounter patch: when RawProbe asks for this field, give it the raw FastArray payload + // instead of the generic NetDelta decoding (wrong for ActivatableAbilities: garbage indices). + if (RawProbe.Matches(classNetCache.PathName + "." + fieldCache.Name)) + { + ProbeField(bunch.ChIndex, classNetCache.PathName, fieldCache.Name, archive); + continue; + } + var group = _netGuidCache.GetNetFieldExportGroup(classNetProperty.PathName); if (group is null || !_netFieldParser.WillReadType(group.PathName)) { diff --git a/src/ChestCounter/ReplayAnalyzer.cs b/src/ChestCounter/ReplayAnalyzer.cs index 7ef57de..22c13db 100644 --- a/src/ChestCounter/ReplayAnalyzer.cs +++ b/src/ChestCounter/ReplayAnalyzer.cs @@ -52,6 +52,14 @@ static ReplayAnalyzer() } var last = path[(path.LastIndexOf('/') + 1)..]; + + // Variants of the golden treasure chest animation (e.g. BGA_DelilahTreasureHuntAnimatedChest_Rare) carry the + // prize id too: map them onto TreasureHuntChest, not GenericContainer (their name contains "Chest"). + if (last.StartsWith("BGA_DelilahTreasureHuntAnimatedChest", StringComparison.Ordinal)) + { + return "/DelilahTreasureHuntGameplay/Gameplay/Actors/BGA_DelilahTreasureHuntAnimatedChest.BGA_DelilahTreasureHuntAnimatedChest_C"; + } + if (last.StartsWith("B_", StringComparison.Ordinal) && TreasureActor.IsMatch(last)) { return GenericWeapon.GroupPath; @@ -93,7 +101,7 @@ private sealed record GrantEvent(float Time, uint PlayerStateActor, int ElementI private readonly List _grants = new(); /// Bump when the analysis changes so that existing replays are re-analyzed. - public const int CurrentVersion = 10; + public const int CurrentVersion = 11; private static readonly bool ProbeDebug = Environment.GetEnvironmentVariable("CHESTCOUNTER_DEBUG") == "4"; @@ -112,7 +120,10 @@ private sealed record GrantEvent(float Time, uint PlayerStateActor, int ElementI RawProbe.Filter = path => path.Contains("FortAbilitySystemComponent", StringComparison.Ordinal) || debugFilter?.IsMatch(path) == true; RawProbe.Sink = (channel, group, field, data, bits) => { - if (group.EndsWith("AbilitySystemComponent_ClassNetCache", StringComparison.Ordinal) && _treasureHandlerGuids.Count > 0) + // FortAbilitySystemComponent_ClassNetCache (unnamed fields) or FortAbilitySystemComponentAthena_ClassNetCache + // (named "ActivatableAbilities", handed over raw by the reader instead of its generic NetDelta decoding). + if (group.Contains("AbilitySystemComponent", StringComparison.Ordinal) && group.EndsWith("_ClassNetCache", StringComparison.Ordinal) + && field is "?" or "ActivatableAbilities" && _treasureHandlerGuids.Count > 0) { ReadAbilityGrants(channel, data, bits); } @@ -653,12 +664,18 @@ string NameOfPawn(uint pawn) => { var h = handlerTimes[hi]; var nextHandler = hi + 1 < handlerTimes.Count ? handlerTimes[hi + 1] : float.MaxValue; + // Buried chests grant the prize when the dig completes, ~2.5s before the chest reports "searched": allow + // up to +4s for them only. var closest = _searches - .Where(x => x.Time >= h - 3 && x.Time <= h + 2) + .Where(x => x.Time >= h - 3 && (x.Time <= h + 2 || (x.Time <= h + 4 && ChestKinds.Classify(x.Label) == ChestKinds.Buried))) .OrderBy(x => Math.Abs(x.Time - h)) .FirstOrDefault(); var mine = closest != null && closest.SearcherPawn is uint cp && targetPawns.Contains(cp); var golden = finds.FirstOrDefault(f => f.FromGoldenChest && f.ObtainedAtSeconds is float g && Math.Abs(g - h) <= 5); + if (Environment.GetEnvironmentVariable("CHESTCOUNTER_DEBUG") == "1") + { + Console.Error.WriteLine($"DBG decide {h,7:F1}s {(golden != null ? "GOLDEN" : mine ? "MINE" : closest != null ? "OTHER" : "NO-SEARCH")} closest={(closest == null ? "-" : $"{closest.Time:F1}s {closest.Label}")}"); + } if (mine && golden == null) { From 4a3170bec07e6036b6432285b9f3fdc8fb0fa837 Mon Sep 17 00:00:00 2001 From: koiseka Date: Sun, 8 Nov 2026 18:32:54 -0800 Subject: [PATCH 2/3] Count chests that are reset and opened again A chest can go back to "not searched" during a match and be opened again, by anyone. ChestCounter counted each chest key only once, so the second opening (often the recording player's, after a teammate's) was dropped. - BaseContainer.bAlreadySearched is bool?, so an update that does not carry it is no longer read as "not searched". - An explicit bAlreadySearched=false on a chest that is not destroyed clears it from the counted set (and its last searcher), so the next opening counts. - Analyzer version 12 so replays on disk are analyzed again. Co-Authored-By: Claude Opus 5.5 --- .../Models/NetFieldExports/Items/BaseContainer.cs | 2 +- lib/PATCHES.md | 1 + src/ChestCounter/ReplayAnalyzer.cs | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/FortniteReplayReader/Models/NetFieldExports/Items/BaseContainer.cs b/lib/FortniteReplayReader/Models/NetFieldExports/Items/BaseContainer.cs index 0053dd0..003098e 100644 --- a/lib/FortniteReplayReader/Models/NetFieldExports/Items/BaseContainer.cs +++ b/lib/FortniteReplayReader/Models/NetFieldExports/Items/BaseContainer.cs @@ -56,7 +56,7 @@ public abstract class BaseContainer : INetFieldExportGroup public uint? SearchingPawn { get; set; } [NetFieldExport("bAlreadySearched", RepLayoutCmdType.PropertyBool)] - public bool bAlreadySearched { get; set; } + public bool? bAlreadySearched { get; set; } [NetFieldExport("BounceNormal", RepLayoutCmdType.PropertyVector)] public FVector BounceNormal { get; set; } diff --git a/lib/PATCHES.md b/lib/PATCHES.md index 41144cf..3ecbff9 100644 --- a/lib/PATCHES.md +++ b/lib/PATCHES.md @@ -17,3 +17,4 @@ Changes for ChestCounter: 11. `Unreal.Core/ReplayReader.cs`: in a "live" replay, an event or data chunk that cannot be decrypted is skipped, or stops the reading, instead of failing the analysis. Note: during the match, Fortnite leaves the encryption key at zero in the header and only writes the real key at the end. The data of a match in progress therefore cannot be read (`ReplayHeaderProbe.KeyMissing`). 12. `Unreal.Core/Models/NetGuidCache.cs`: level placed actors whose instance name is not their class name (`Tiered_Chest_Athena47_UAID_...`, `Tiered_Chest_Athena5_6e02a0a859c897db_11`) are matched to the exact `_C` class after stripping the UAID / instance hash and the number suffix. Before, these chests were never decoded ("Failed group") and were not counted. 13. `Unreal.Core/ReplayReader.cs`: a ClassNetCache custom delta property that `RawProbe` asks for (`FortAbilitySystemComponentAthena_ClassNetCache.ActivatableAbilities`) is handed over raw instead of being decoded as `GrantedAbility`, whose generic NetDelta decoding gives garbage indices. Without it the treasure handler grants were never read on players with the `FortAbilitySystemComponentAthena` class. +14. `FortniteReplayReader/Models/NetFieldExports/Items/BaseContainer.cs`: `bAlreadySearched` is `bool?`, so an update that does not carry it (null) is no longer read as "not searched". ChestCounter uses the explicit `false` to see that a chest was reset and can be opened (and counted) again. diff --git a/src/ChestCounter/ReplayAnalyzer.cs b/src/ChestCounter/ReplayAnalyzer.cs index 22c13db..7968557 100644 --- a/src/ChestCounter/ReplayAnalyzer.cs +++ b/src/ChestCounter/ReplayAnalyzer.cs @@ -101,7 +101,7 @@ private sealed record GrantEvent(float Time, uint PlayerStateActor, int ElementI private readonly List _grants = new(); /// Bump when the analysis changes so that existing replays are re-analyzed. - public const int CurrentVersion = 11; + public const int CurrentVersion = 12; private static readonly bool ProbeDebug = Environment.GetEnvironmentVariable("CHESTCOUNTER_DEBUG") == "4"; @@ -382,7 +382,18 @@ protected override void OnExportRead(uint channelIndex, INetFieldExportGroup? ex } var containerKey = _channelKey.GetValueOrDefault(channelIndex, $"ch:{channelIndex}"); - if (container.bAlreadySearched) + // A chest can be reset (searched -> not searched) and opened again later, by anyone: only an explicit + // "not searched" clears it, so the next opening is counted too. + if (container.bAlreadySearched == false && !container.bDestroyed && _searched.Remove(containerKey)) + { + _lastSearcher.Remove(channelIndex); + if (Environment.GetEnvironmentVariable("CHESTCOUNTER_DEBUG") == "1") + { + Console.Error.WriteLine($"DBG reset {Now,7:F1}s {_channelLabel.GetValueOrDefault(channelIndex, "?")} {containerKey}"); + } + } + + if (container.bAlreadySearched == true) { if (_searched.Add(containerKey)) { From c50caff4bcd9d87c2f2cc4f42f67d1bc21ef5183 Mon Sep 17 00:00:00 2001 From: koiseka Date: Sun, 8 Nov 2026 18:58:55 -0800 Subject: [PATCH 3/3] Retry actors whose export group arrived after them NetGuidCache remembered a path that found no export group as failed for the whole replay. An actor sent a moment before its class's export group (in practice: rare chests in view at the start of the match, before the first rare chest is fully sent) was then never decoded, and every later update of it, including being opened, was dropped. - Adding a new export group clears the failed paths so they are tried again. - Analyzer version 13 so replays on disk are analyzed again. Co-Authored-By: Claude Opus 5.5 --- lib/PATCHES.md | 1 + lib/Unreal.Core/Models/NetGuidCache.cs | 7 +++++++ src/ChestCounter/ReplayAnalyzer.cs | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/PATCHES.md b/lib/PATCHES.md index 3ecbff9..7c1b36d 100644 --- a/lib/PATCHES.md +++ b/lib/PATCHES.md @@ -18,3 +18,4 @@ Changes for ChestCounter: 12. `Unreal.Core/Models/NetGuidCache.cs`: level placed actors whose instance name is not their class name (`Tiered_Chest_Athena47_UAID_...`, `Tiered_Chest_Athena5_6e02a0a859c897db_11`) are matched to the exact `_C` class after stripping the UAID / instance hash and the number suffix. Before, these chests were never decoded ("Failed group") and were not counted. 13. `Unreal.Core/ReplayReader.cs`: a ClassNetCache custom delta property that `RawProbe` asks for (`FortAbilitySystemComponentAthena_ClassNetCache.ActivatableAbilities`) is handed over raw instead of being decoded as `GrantedAbility`, whose generic NetDelta decoding gives garbage indices. Without it the treasure handler grants were never read on players with the `FortAbilitySystemComponentAthena` class. 14. `FortniteReplayReader/Models/NetFieldExports/Items/BaseContainer.cs`: `bAlreadySearched` is `bool?`, so an update that does not carry it (null) is no longer read as "not searched". ChestCounter uses the explicit `false` to see that a chest was reset and can be opened (and counted) again. +15. `Unreal.Core/Models/NetGuidCache.cs`: a path that found no export group was remembered as failed for the whole replay. An actor sent a moment before its class's export group (e.g. a rare chest in view before the first rare chest is fully sent) was then never decoded, and its later updates (opened...) were lost. Adding a new export group clears that list so those paths are tried again. diff --git a/lib/Unreal.Core/Models/NetGuidCache.cs b/lib/Unreal.Core/Models/NetGuidCache.cs index 707100d..2655eb6 100644 --- a/lib/Unreal.Core/Models/NetGuidCache.cs +++ b/lib/Unreal.Core/Models/NetGuidCache.cs @@ -87,6 +87,13 @@ public void AddToExportGroupMap(string group, NetFieldExportGroup exportGroup) exportGroup.PathName = exportGroup.PathName.RemoveAllPathPrefixes(); } + // ChestCounter patch: an actor whose export group arrives a moment after the actor itself was cached as + // "failed" for good, and every later update of it was dropped. A new group may resolve those paths: retry them. + if (!NetFieldExportGroupMap.ContainsKey(group)) + { + _failedPaths.Clear(); + } + NetFieldExportGroupMap[group] = exportGroup; NetFieldExportGroupIndexToGroup[exportGroup.PathNameIndex] = group; _netFieldExportGroupFromIndex[exportGroup.PathNameIndex] = exportGroup; diff --git a/src/ChestCounter/ReplayAnalyzer.cs b/src/ChestCounter/ReplayAnalyzer.cs index 7968557..dc22cbf 100644 --- a/src/ChestCounter/ReplayAnalyzer.cs +++ b/src/ChestCounter/ReplayAnalyzer.cs @@ -101,7 +101,7 @@ private sealed record GrantEvent(float Time, uint PlayerStateActor, int ElementI private readonly List _grants = new(); /// Bump when the analysis changes so that existing replays are re-analyzed. - public const int CurrentVersion = 12; + public const int CurrentVersion = 13; private static readonly bool ProbeDebug = Environment.GetEnvironmentVariable("CHESTCOUNTER_DEBUG") == "4";