From 924645891999ccb0cb8a5d97968d5c3948f1c737 Mon Sep 17 00:00:00 2001 From: js6pak Date: Thu, 27 Oct 2022 11:41:41 +0200 Subject: [PATCH] Kick for not having reactor only when necessary --- Reactor/Networking/ModList.cs | 4 ++++ Reactor/Networking/Patches/ClientPatches.cs | 4 ++-- Reactor/Networking/Patches/HttpPatches.cs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Reactor/Networking/ModList.cs b/Reactor/Networking/ModList.cs index 89d0ad0..3db6e36 100644 --- a/Reactor/Networking/ModList.cs +++ b/Reactor/Networking/ModList.cs @@ -39,6 +39,8 @@ public static class ModList return _modByPluginType[pluginType]; } + internal static bool IsAnyModIsRequiredOnAllClients { get; private set; } + private static readonly Dictionary _modByNetId = new(); private static readonly Dictionary _netIdByMod = new(); @@ -113,6 +115,8 @@ public static class ModList netId++; } + IsAnyModIsRequiredOnAllClients = Current.Any(m => m.IsRequiredOnAllClients); + var debug = new StringBuilder("Mod list:"); foreach (var mod in Current) { diff --git a/Reactor/Networking/Patches/ClientPatches.cs b/Reactor/Networking/Patches/ClientPatches.cs index b6d4a50..1dcdfe8 100644 --- a/Reactor/Networking/Patches/ClientPatches.cs +++ b/Reactor/Networking/Patches/ClientPatches.cs @@ -84,7 +84,7 @@ internal static class ClientPatches if (innerNetClient.AmHost) { - if (reactorClientData == null) + if (reactorClientData == null && ModList.IsAnyModIsRequiredOnAllClients) { Warning("Kicking " + clientData.PlayerName + " for not having Reactor installed"); @@ -100,7 +100,7 @@ internal static class ClientPatches return false; } - if (!Mod.Validate(reactorClientData.Mods, ModList.Current, out var reason)) + if (!Mod.Validate(reactorClientData?.Mods ?? Array.Empty(), ModList.Current, out var reason)) { innerNetClient.KickWithReason(clientData.Id, reason); __result = false; diff --git a/Reactor/Networking/Patches/HttpPatches.cs b/Reactor/Networking/Patches/HttpPatches.cs index a24bcec..0900f1f 100644 --- a/Reactor/Networking/Patches/HttpPatches.cs +++ b/Reactor/Networking/Patches/HttpPatches.cs @@ -103,7 +103,7 @@ internal static class HttpPatches public static void Postfix(GameStartManager __instance) { if (AmongUsClient.Instance.GameMode != GameModes.OnlineGame) return; - if (ModList.Current.Any(m => m.IsRequiredOnAllClients) && !IsCurrentRegionModded()) + if (ModList.IsAnyModIsRequiredOnAllClients && !IsCurrentRegionModded()) { Warning("Vanilla region, locking public toggle");