Skip to content

Commit

Permalink
Merge pull request #55 from miniduikboot/fix/region-info-feedback-loop
Browse files Browse the repository at this point in the history
Improve regionInfo.json writing logic
  • Loading branch information
js6pak authored May 30, 2022
2 parents fcc8056 + cb799e8 commit 2b98a21
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Reactor/Patches/RegionInfoWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,25 @@ public void Dispose()
[HarmonyPatch(typeof(FileIO), nameof(FileIO.WriteAllText))]
private static class WritePatch
{
public static void Prefix(string path)
public static bool Prefix(string path, string contents)
{
// Among Us' region loading code unfortunately contains a call
// to SaveServers, which will write out the region file. This
// will lead to a positive feedback loop when detecting writes,
// which is undesireable. So we check if the write makes a
// change to the file on disk and if it would write the same
// file again, stop AU from actually writing it.
if (ServerManager.Instance && path == ServerManager.Instance.serverInfoFileJson)
{
PluginSingleton<ReactorPlugin>.Instance.RegionInfoWatcher.IgnoreNext = true;
var currentContents = FileIO.ReadAllText(path);
var continueWrite = currentContents != contents;
Logger<ReactorPlugin>.Debug($"Continue serverInfoFile write? {continueWrite}");
// If we will write, ignore the next change action from the observer.
PluginSingleton<ReactorPlugin>.Instance.RegionInfoWatcher.IgnoreNext = continueWrite;
return continueWrite;
}

return true;
}
}
}
Expand Down

0 comments on commit 2b98a21

Please sign in to comment.