Skip to content

Commit

Permalink
Don't reload regionInfo.json when the game saves it
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Feb 18, 2022
1 parent 89a8ada commit 70155fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Reactor/Patches/RegionInfoWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using HarmonyLib;
using Reactor.Extensions;
using UnityEngine;
using Object = UnityEngine.Object;
Expand All @@ -10,6 +11,8 @@ internal class RegionInfoWatcher : IDisposable
{
private FileSystemWatcher Watcher { get; }

public bool IgnoreNext { get; set; }

internal RegionInfoWatcher()
{
Watcher = new FileSystemWatcher(
Expand All @@ -21,6 +24,12 @@ internal RegionInfoWatcher()
{
if (new FileInfo(e.Name).Length > 0)
{
if (IgnoreNext)
{
IgnoreNext = false;
return;
}

Dispatcher.Instance.Enqueue(() =>
{
ServerManager.Instance.LoadServers();
Expand All @@ -44,5 +53,17 @@ public void Dispose()
{
Watcher.Dispose();
}

[HarmonyPatch(typeof(FileIO), nameof(FileIO.WriteAllText))]
private static class WritePatch
{
public static void Prefix(string path)
{
if (ServerManager.Instance && path == ServerManager.Instance.serverInfoFileJson)
{
PluginSingleton<ReactorPlugin>.Instance.RegionInfoWatcher.IgnoreNext = true;
}
}
}
}
}
2 changes: 1 addition & 1 deletion Reactor/ReactorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class ReactorPlugin : BasePlugin

public ConfigEntry<bool>? AllowVanillaServers { get; private set; }

private RegionInfoWatcher RegionInfoWatcher { get; } = new RegionInfoWatcher();
internal RegionInfoWatcher RegionInfoWatcher { get; } = new RegionInfoWatcher();

public ReactorPlugin()
{
Expand Down

0 comments on commit 70155fe

Please sign in to comment.