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 e2b3150..7c1b36d 100644 --- a/lib/PATCHES.md +++ b/lib/PATCHES.md @@ -15,3 +15,7 @@ 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. +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 ffa59ef..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; @@ -138,6 +145,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 +210,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..dc22cbf 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 = 13; 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); } @@ -371,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)) { @@ -653,12 +675,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) {