From 70155fe8a6fdf443a6699f4fc25e6642b249d933 Mon Sep 17 00:00:00 2001 From: js6pak Date: Fri, 18 Feb 2022 22:38:35 +0100 Subject: [PATCH] Don't reload regionInfo.json when the game saves it --- Reactor/Patches/RegionInfoWatcher.cs | 21 +++++++++++++++++++++ Reactor/ReactorPlugin.cs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Reactor/Patches/RegionInfoWatcher.cs b/Reactor/Patches/RegionInfoWatcher.cs index ac349cd..8d346d6 100644 --- a/Reactor/Patches/RegionInfoWatcher.cs +++ b/Reactor/Patches/RegionInfoWatcher.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using HarmonyLib; using Reactor.Extensions; using UnityEngine; using Object = UnityEngine.Object; @@ -10,6 +11,8 @@ internal class RegionInfoWatcher : IDisposable { private FileSystemWatcher Watcher { get; } + public bool IgnoreNext { get; set; } + internal RegionInfoWatcher() { Watcher = new FileSystemWatcher( @@ -21,6 +24,12 @@ internal RegionInfoWatcher() { if (new FileInfo(e.Name).Length > 0) { + if (IgnoreNext) + { + IgnoreNext = false; + return; + } + Dispatcher.Instance.Enqueue(() => { ServerManager.Instance.LoadServers(); @@ -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.Instance.RegionInfoWatcher.IgnoreNext = true; + } + } + } } } diff --git a/Reactor/ReactorPlugin.cs b/Reactor/ReactorPlugin.cs index 74234fc..d1ebcaa 100644 --- a/Reactor/ReactorPlugin.cs +++ b/Reactor/ReactorPlugin.cs @@ -25,7 +25,7 @@ public partial class ReactorPlugin : BasePlugin public ConfigEntry? AllowVanillaServers { get; private set; } - private RegionInfoWatcher RegionInfoWatcher { get; } = new RegionInfoWatcher(); + internal RegionInfoWatcher RegionInfoWatcher { get; } = new RegionInfoWatcher(); public ReactorPlugin() {