mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
Add DisableServerAuthority to ModFlags (#78)
This commit is contained in:
1 parent
710ca79fa5
commit
d82268b88a
6 files changed
+55
-4
No files matched your search
@@ -27,4 +27,9 @@ public enum ModFlags : ushort
|
||||
/// Requires the host of the lobby to have the mod.
|
||||
/// </summary>
|
||||
RequireOnHost = 1 << 2,
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the game server that the host has authority over game logic.
|
||||
/// </summary>
|
||||
DisableServerAuthority = 1 << 3,
|
||||
}
|
||||
@@ -39,7 +39,8 @@ public static class ModList
|
||||
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<Mod, uint> _netIdByMod = new();
|
||||
@@ -115,7 +116,8 @@ public static class ModList
|
||||
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:");
|
||||
foreach (var mod in Current)
|
||||
|
||||
@@ -84,7 +84,7 @@ internal static class ClientPatches
|
||||
|
||||
if (innerNetClient.AmHost)
|
||||
{
|
||||
if (reactorClientData == null && ModList.IsAnyModIsRequiredOnAllClients)
|
||||
if (reactorClientData == null && ModList.IsAnyModRequiredOnAllClients)
|
||||
{
|
||||
Warning("Kicking " + clientData.PlayerName + " for not having Reactor installed");
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ internal static class HttpPatches
|
||||
public static void Postfix(GameStartManager __instance)
|
||||
{
|
||||
if (AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) return;
|
||||
if (ModList.IsAnyModIsRequiredOnAllClients && !IsCurrentRegionModded())
|
||||
if (ModList.IsAnyModRequiredOnAllClients && !IsCurrentRegionModded())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,10 @@ internal static class ReactorConfig
|
||||
{
|
||||
public const string FeaturesSection = "Features";
|
||||
|
||||
public static ConfigEntry<bool> ForceDisableServerAuthority { get; private set; } = null!;
|
||||
|
||||
public static void Bind(ConfigFile config)
|
||||
{
|
||||
ForceDisableServerAuthority = config.Bind(FeaturesSection, nameof(ForceDisableServerAuthority), false, "Enables the DisableServerAuthority flag even when no mods declare it");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user