using System; using System.Threading; using HarmonyLib; internal static class ConnectionGate { private const int WaitMilliseconds = 15000; private static readonly ManualResetEventSlim Opened = new ManualResetEventSlim(false); private static int _holds; internal static void Install(Harmony harmony) { harmony.PatchAll(typeof(ConnectionGatePatch)); } internal static void Open() { Opened.Set(); } internal static void Hold() { if (Opened.IsSet) return; var count = Interlocked.Increment(ref _holds); RadicadeEacBypassPlugin.LogSource.LogWarning("[Patch] a server request arrived before the patch list finished; holding it until it does (hold #" + count + ")."); if (Opened.Wait(WaitMilliseconds)) return; RadicadeEacBypassPlugin.LogSource.LogError("[Patch] the patch list did not finish within " + (WaitMilliseconds / 1000) + "s; releasing this request and every later one so the client is not held forever."); Opened.Set(); } } [HarmonyPatch(typeof(BestHTTP.HTTPManager), "SendRequest", new[] { typeof(BestHTTP.HTTPRequest) })] internal static class ConnectionGatePatch { [HarmonyPriority(Priority.First)] internal static void Prefix() { ConnectionGate.Hold(); } }