Skip to content

Commit

Permalink
Update desync stuff checker to look for mote saturation checks (#477)
Browse files Browse the repository at this point in the history
Checks to mote saturation are (generally) going to be unique to a specific player and changing game's behavior based on it may cause desyncs.
  • Loading branch information
SokyranTheDragon authored Oct 6, 2024
1 parent 796972a commit d18f40f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Source/DebugActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private class DesyncSourceSearchWindow : Window
private bool doVanilla = false;

public override bool IsDebug => true;
public override Vector2 InitialSize => new(525f, 615f);
public override Vector2 InitialSize => new(525f, 640f);
public override float Margin => 32f;

public DesyncSourceSearchWindow()
Expand Down Expand Up @@ -163,6 +163,7 @@ internal enum StuffToSearch
[NonBasic] GetHashCode,
[NonBasic] PatchedSyncMethods,
[NonBasic] LongEvents,
MoteSaturation,
}

private static readonly MethodInfo FindCurrentMap = AccessTools.DeclaredPropertyGetter(typeof(Find), nameof(Find.CurrentMap));
Expand Down Expand Up @@ -198,6 +199,16 @@ internal enum StuffToSearch
[typeof(Action), typeof(string), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool)]),
}.Where(x => x != null).ToHashSet();

// We could also add check for MoteCounter.moteCount field, but it's
// private, so it should be very unlikely that anyone is using it.
private static readonly HashSet<MethodInfo> MoteSaturationMethods = new[]
{
AccessTools.DeclaredPropertyGetter(typeof(MoteCounter), nameof(MoteCounter.MoteCount)),
AccessTools.DeclaredPropertyGetter(typeof(MoteCounter), nameof(MoteCounter.Saturation)),
AccessTools.DeclaredPropertyGetter(typeof(MoteCounter), nameof(MoteCounter.Saturated)),
AccessTools.DeclaredPropertyGetter(typeof(MoteCounter), nameof(MoteCounter.SaturatedLowPriority)),
}.Where(x => x != null).ToHashSet();

[DebugAction(CategoryName, "Unsafe stuff logger", allowedGameStates = AllowedGameStates.Entry)]
public static void OpenDesyncSourceSearchWindow() => Find.WindowStack.Add(new DesyncSourceSearchWindow());

Expand Down Expand Up @@ -391,6 +402,13 @@ public static void LogUnpatchedStuff(HashSet<StuffToSearch> selectedStuff, bool
Log.Warning("== In majority of cases, long events are completely safe. However, there are 2 potential situations that can cause issues with them. The first is asynchronous long events, and the second is long events queued during game startup. ==");
Log.Message(found.Append("\n").Join(delimiter: "\n"));
}

if (log.TryGetValue(StuffToSearch.MoteSaturation, out found) && found.Any())
{
Log.Warning("== Mote saturation checks found: ==");
Log.Warning("== Code that runs based on how saturated the motes are may cause desyncs as mote saturation may differ between players. ==");
Log.Message(found.Append("\n").Join(delimiter: "\n"));
}
}
else Log.Warning("== No unpatched RNG or potentially unsafe methods found ==");

Expand Down Expand Up @@ -518,6 +536,9 @@ internal static HashSet<StuffToSearch> FindRng(MethodBase baseMethod)
case MethodInfo method when LongEventMethods.Contains(method):
foundStuff.Add(StuffToSearch.LongEvents);
break;
case MethodInfo method when MoteSaturationMethods.Contains(method):
foundStuff.Add(StuffToSearch.MoteSaturation);
break;
}
}

Expand Down

0 comments on commit d18f40f

Please sign in to comment.