Add DisableServerAuthority to ModFlags (#78)

This commit is contained in:
js6pak authored and GitHub committed 2024-03-02 13:02:02 +01:00
1 parent 710ca79fa5
commit d82268b88a
6 files changed
+55 -4

No files matched your search

+5
View File
@@ -27,4 +27,9 @@ public enum ModFlags : ushort
/// Requires the host of the lobby to have the mod. /// Requires the host of the lobby to have the mod.
/// </summary> /// </summary>
RequireOnHost = 1 << 2, RequireOnHost = 1 << 2,
/// <summary>
/// Notifies the game server that the host has authority over game logic.
/// </summary>
DisableServerAuthority = 1 << 3,
} }
+4 -2
View File
@@ -39,7 +39,8 @@ public static class ModList
return _modByPluginType[pluginType]; return _modByPluginType[pluginType];
} }
internal static bool IsAnyModIsRequiredOnAllClients { get; private set; } internal static bool IsAnyModRequiredOnAllClients { get; private set; }
internal static bool IsAnyModDisableServerAuthority { get; private set; }
private static readonly Dictionary<uint, Mod> _modByNetId = new(); private static readonly Dictionary<uint, Mod> _modByNetId = new();
private static readonly Dictionary<Mod, uint> _netIdByMod = new(); private static readonly Dictionary<Mod, uint> _netIdByMod = new();
@@ -115,7 +116,8 @@ public static class ModList
netId++; netId++;
} }
IsAnyModIsRequiredOnAllClients = Current.Any(m => m.IsRequiredOnAllClients); IsAnyModRequiredOnAllClients = Current.Any(m => m.IsRequiredOnAllClients);
IsAnyModDisableServerAuthority = Current.Any(m => (m.Flags & ModFlags.DisableServerAuthority) != 0);
var debug = new StringBuilder("Mod list:"); var debug = new StringBuilder("Mod list:");
foreach (var mod in Current) foreach (var mod in Current)
+1 -1
View File
@@ -84,7 +84,7 @@ internal static class ClientPatches
if (innerNetClient.AmHost) if (innerNetClient.AmHost)
{ {
if (reactorClientData == null && ModList.IsAnyModIsRequiredOnAllClients) if (reactorClientData == null && ModList.IsAnyModRequiredOnAllClients)
{ {
Warning("Kicking " + clientData.PlayerName + " for not having Reactor installed"); Warning("Kicking " + clientData.PlayerName + " for not having Reactor installed");
+1 -1
View File
@@ -103,7 +103,7 @@ internal static class HttpPatches
public static void Postfix(GameStartManager __instance) public static void Postfix(GameStartManager __instance)
{ {
if (AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) return; if (AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) return;
if (ModList.IsAnyModIsRequiredOnAllClients && !IsCurrentRegionModded()) if (ModList.IsAnyModRequiredOnAllClients && !IsCurrentRegionModded())
{ {
Warning("Vanilla region, locking public toggle"); Warning("Vanilla region, locking public toggle");
@@ -0,0 +1,41 @@
using HarmonyLib;
using Reactor.Networking;
namespace Reactor.Patches.Miscellaneous;
[HarmonyPatch]
internal static class DisableServerAuthorityPatch
{
private const int DisableServerAuthorityFlag = 25;
public static bool Enabled => ModList.IsAnyModDisableServerAuthority || ReactorConfig.ForceDisableServerAuthority.Value;
[HarmonyPatch(typeof(Constants), nameof(Constants.GetBroadcastVersion))]
[HarmonyPostfix]
public static void GetBroadcastVersionPatch(ref int __result)
{
if (!Enabled) return;
if (AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) return;
Debug("Sending the DisableServerAuthority flag");
var revision = __result % 50;
if (revision < DisableServerAuthorityFlag)
{
__result += DisableServerAuthorityFlag;
}
}
[HarmonyPatch(typeof(Constants), nameof(Constants.IsVersionModded))]
[HarmonyPrefix]
public static bool IsVersionModdedPatch(ref bool __result)
{
if (Enabled)
{
__result = true;
return false;
}
return true;
}
}
+3
View File
@@ -6,7 +6,10 @@ internal static class ReactorConfig
{ {
public const string FeaturesSection = "Features"; public const string FeaturesSection = "Features";
public static ConfigEntry<bool> ForceDisableServerAuthority { get; private set; } = null!;
public static void Bind(ConfigFile config) public static void Bind(ConfigFile config)
{ {
ForceDisableServerAuthority = config.Bind(FeaturesSection, nameof(ForceDisableServerAuthority), false, "Enables the DisableServerAuthority flag even when no mods declare it");
} }
} }