Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 4 additions & 0 deletions lib/PATCHES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<name>_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.
29 changes: 29 additions & 0 deletions lib/Unreal.Core/Models/NetGuidCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,6 +145,9 @@ public void AddToExportGroupMap(string group, NetFieldExportGroup exportGroup)
/// </summary>
/// <param name="netguid"></param>
/// <returns><see cref="NetFieldExportGroup"/></returns>
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)
Expand Down Expand Up @@ -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
// "<name>_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;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Unreal.Core/ReplayReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
36 changes: 32 additions & 4 deletions src/ChestCounter/ReplayAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +101,7 @@ private sealed record GrantEvent(float Time, uint PlayerStateActor, int ElementI
private readonly List<GrantEvent> _grants = new();

/// <summary>Bump when the analysis changes so that existing replays are re-analyzed.</summary>
public const int CurrentVersion = 10;
public const int CurrentVersion = 13;

private static readonly bool ProbeDebug = Environment.GetEnvironmentVariable("CHESTCOUNTER_DEBUG") == "4";

Expand All @@ -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);
}
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand Down