Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of NoWeedRespawn v1.0.1
NoWeedRespawn.dll
Decompiled a month agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("NoWeedRespawn")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1")] [assembly: AssemblyProduct("NoWeedRespawn")] [assembly: AssemblyTitle("NoWeedRespawn")] [assembly: AssemblyVersion("1.0.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace NoWeedRespawn { internal static class HostModGate { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnMessage; public static Action<ulong> <1>__OnClientConnected; } public const string MessageName = "MrGlim.NoWeedRespawn"; private const byte OpHostHello = 0; private const byte OpClientSyncRequest = 1; private static bool _registered; private static bool _clientConnectedHooked; private static bool _requestedSync; private static bool _clientHostEnabled; private static bool _clientBlockIndoor = true; private static bool _clientBlockOutdoor = true; private static bool _clientOutdoorCleared; public static bool HostHasMod { get { EnsureRegistered(); NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null) { return true; } if (singleton.IsServer || singleton.IsHost) { if (Plugin.Enabled != null) { return Plugin.Enabled.Value; } return false; } return _clientHostEnabled; } } public static bool FeaturesActive => HostHasMod; public static bool IndoorActive { get { if (!FeaturesActive) { return false; } NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.IsServer || singleton.IsHost) { if (Plugin.BlockIndoorRespawn != null) { return Plugin.BlockIndoorRespawn.Value; } return false; } return _clientBlockIndoor; } } public static bool OutdoorActive { get { if (!FeaturesActive) { return false; } NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.IsServer || singleton.IsHost) { if (Plugin.BlockOutdoorRespawn != null) { return Plugin.BlockOutdoorRespawn.Value; } return false; } return _clientBlockOutdoor; } } public static bool OutdoorClearedSynced { get { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.IsServer || singleton.IsHost) { return OutdoorSession.OutdoorCleared; } return _clientOutdoorCleared; } } public static void OnSessionReset() { _clientOutdoorCleared = false; } public static void Reset() { _registered = false; _clientConnectedHooked = false; _requestedSync = false; _clientHostEnabled = false; _clientBlockIndoor = true; _clientBlockOutdoor = true; _clientOutdoorCleared = false; } public static void EnsureRegistered() { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null) { _registered = false; _clientConnectedHooked = false; return; } if (!_registered) { CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager; object obj = <>O.<0>__OnMessage; if (obj == null) { HandleNamedMessageDelegate val = OnMessage; <>O.<0>__OnMessage = val; obj = (object)val; } customMessagingManager.RegisterNamedMessageHandler("MrGlim.NoWeedRespawn", (HandleNamedMessageDelegate)obj); _registered = true; Plugin.Log.LogInfo((object)"MrGlim.NoWeedRespawn net handler registered."); } if (singleton.IsServer && !_clientConnectedHooked) { singleton.OnClientConnectedCallback += OnClientConnected; _clientConnectedHooked = true; } if (!singleton.IsServer && singleton.IsConnectedClient && !_requestedSync) { _requestedSync = true; RequestSync(); } } public static void BroadcastState() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) EnsureRegistered(); NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsServer) { bool flag = Plugin.Enabled != null && Plugin.Enabled.Value; bool flag2 = Plugin.BlockIndoorRespawn != null && Plugin.BlockIndoorRespawn.Value; bool flag3 = Plugin.BlockOutdoorRespawn != null && Plugin.BlockOutdoorRespawn.Value; bool outdoorCleared = OutdoorSession.OutdoorCleared; FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1); byte b = 0; ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag3, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref outdoorCleared, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessageToAll("MrGlim.NoWeedRespawn", val, (NetworkDelivery)2); ((FastBufferWriter)(ref val)).Dispose(); } } private static void OnClientConnected(ulong clientId) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsServer && clientId != singleton.LocalClientId) { SendHello(clientId); } } private static void RequestSync() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && !singleton.IsServer) { FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1); byte b = 1; ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessage("MrGlim.NoWeedRespawn", 0uL, val, (NetworkDelivery)2); ((FastBufferWriter)(ref val)).Dispose(); } } private static void SendHello(ulong clientId) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsServer) { bool flag = Plugin.Enabled != null && Plugin.Enabled.Value; bool flag2 = Plugin.BlockIndoorRespawn != null && Plugin.BlockIndoorRespawn.Value; bool flag3 = Plugin.BlockOutdoorRespawn != null && Plugin.BlockOutdoorRespawn.Value; bool outdoorCleared = OutdoorSession.OutdoorCleared; FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1); byte b = 0; ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag3, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref outdoorCleared, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessage("MrGlim.NoWeedRespawn", clientId, val, (NetworkDelivery)2); ((FastBufferWriter)(ref val)).Dispose(); } } private static void OnMessage(ulong sender, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) byte b = default(byte); ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives)); NetworkManager singleton = NetworkManager.Singleton; switch (b) { case 1: if ((Object)(object)singleton != (Object)null && singleton.IsServer) { SendHello(sender); } break; case 0: { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); bool flag2 = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives)); bool flag3 = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag3, default(ForPrimitives)); bool flag4 = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag4, default(ForPrimitives)); if ((Object)(object)singleton != (Object)null && !singleton.IsServer) { _clientHostEnabled = flag; _clientBlockIndoor = flag2; _clientBlockOutdoor = flag3; _clientOutdoorCleared = flag4; if (flag4) { OutdoorSession.OutdoorCleared = true; } Plugin.Log.LogInfo((object)$"Host hello: enabled={flag} indoor={flag2} outdoor={flag3} cleared={flag4}"); } break; } } } } [HarmonyPatch(typeof(GameNetworkManager), "Disconnect")] internal static class HostModGateDisconnectPatch { public static void Prefix() { HostModGate.Reset(); Plugin.Log.LogInfo((object)"NoWeedRespawn gate reset on disconnect."); } } internal static class OutdoorSession { internal static bool OutdoorCleared; internal static bool AnyDestroyedThisMoon; internal static readonly HashSet<int> DestroyedIndices = new HashSet<int>(); internal static void Reset() { OutdoorCleared = false; AnyDestroyedThisMoon = false; DestroyedIndices.Clear(); HostModGate.OnSessionReset(); Plugin.VLog("Outdoor session flags reset."); } } internal static class IndoorHelpers { internal static bool IsServer(NetworkBehaviour nb) { if ((Object)(object)nb != (Object)null && nb.IsServer) { return true; } NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null) { return singleton.IsServer; } return false; } internal static void ForceEradicateEmptyTiles(CadaverGrowthAI growth) { if (Plugin.IndoorActive && !((Object)(object)growth == (Object)null) && IsServer((NetworkBehaviour)(object)growth) && growth.GrowthTiles != null) { for (int i = 0; i < growth.GrowthTiles.Count; i++) { TryForceEradicateTile(growth.GrowthTiles[i], i); } } } internal static void TryForceEradicateTile(TileWithGrowth? tile, int tileIndex) { if (tile != null && tile.plantsInTile <= 0 && (tile.plantPositions == null || tile.plantPositions.Count <= 0)) { if (!tile.eradicated) { tile.eradicated = true; tile.eradicatedAtTime = Time.realtimeSinceStartup; Plugin.VLog($"Forced eradicated on empty tile={tileIndex}"); } else if (tile.eradicatedAtTime <= 0f) { tile.eradicatedAtTime = Time.realtimeSinceStartup; } } } } [HarmonyPatch(typeof(CadaverGrowthAI), "SyncRemoveEradicationFromTileRpc")] internal static class SyncRemoveEradicationPatch { [HarmonyPrefix] private static bool Prefix(int tileIndex) { if (!Plugin.IndoorActive) { return true; } Plugin.VLog($"Blocked SyncRemoveEradicationFromTileRpc tile={tileIndex}"); return false; } } [HarmonyPatch(typeof(CadaverGrowthAI), "SyncSpawnPlantRpc")] internal static class SyncSpawnPlantPatch { [HarmonyPrefix] private static bool Prefix(CadaverGrowthAI __instance, int tileIndex) { if (!Plugin.IndoorActive) { return true; } if (__instance?.GrowthTiles == null) { return true; } if (tileIndex < 0 || tileIndex >= __instance.GrowthTiles.Count) { return true; } TileWithGrowth val = __instance.GrowthTiles[tileIndex]; if (val != null && val.eradicated) { Plugin.VLog($"Blocked SyncSpawnPlantRpc on eradicated tile={tileIndex}"); return false; } return true; } } [HarmonyPatch(typeof(CadaverGrowthAI), "DestroyPlantAtPosition")] internal static class DestroyPlantAtPositionPatch { [HarmonyPostfix] private static void Postfix(CadaverGrowthAI __instance) { IndoorHelpers.ForceEradicateEmptyTiles(__instance); } } [HarmonyPatch(typeof(CadaverGrowthAI), "RemoveWeedFromTile")] internal static class RemoveWeedFromTilePatch { [HarmonyPostfix] private static void Postfix(CadaverGrowthAI __instance, int tileIndex) { if (Plugin.IndoorActive && !((Object)(object)__instance == (Object)null) && IndoorHelpers.IsServer((NetworkBehaviour)(object)__instance) && __instance.GrowthTiles != null && tileIndex >= 0 && tileIndex < __instance.GrowthTiles.Count) { IndoorHelpers.TryForceEradicateTile(__instance.GrowthTiles[tileIndex], tileIndex); } } } [HarmonyPatch(typeof(MoldSpreadManager), "AddToDestroyedMoldList")] internal static class AddToDestroyedMoldListPatch { [HarmonyPostfix] private static void Postfix(MoldSpreadManager __instance, int index) { if (Plugin.OutdoorActive && !((Object)(object)__instance == (Object)null)) { OutdoorSession.AnyDestroyedThisMoon = true; OutdoorSession.DestroyedIndices.Add(index); OutdoorHelpers.MaybeMarkCleared(__instance); Plugin.VLog($"AddToDestroyedMoldList index={index} cleared={OutdoorSession.OutdoorCleared}"); } } } [HarmonyPatch(typeof(MoldSpreadManager), "DestroyMoldAtIndex")] internal static class DestroyMoldAtIndexPatch { [HarmonyPostfix] private static void Postfix(MoldSpreadManager __instance, bool __result) { if (Plugin.OutdoorActive && !((Object)(object)__instance == (Object)null) && __result) { OutdoorSession.AnyDestroyedThisMoon = true; OutdoorHelpers.MaybeMarkCleared(__instance); } } } [HarmonyPatch(typeof(MoldSpreadManager), "DestroyMoldAtPosition")] internal static class DestroyMoldAtPositionPatch { [HarmonyPostfix] private static void Postfix(MoldSpreadManager __instance) { if (Plugin.OutdoorActive && !((Object)(object)__instance == (Object)null)) { OutdoorSession.AnyDestroyedThisMoon = true; OutdoorHelpers.MaybeMarkCleared(__instance); } } } [HarmonyPatch(typeof(MoldSpreadManager), "GenerateMold")] internal static class GenerateMoldPatch { [HarmonyPrefix] private static bool Prefix(MoldSpreadManager __instance) { if (!Plugin.OutdoorActive) { return true; } if (HostModGate.OutdoorClearedSynced) { Plugin.VLog("Skipped GenerateMold (OutdoorCleared)."); return false; } if (!OutdoorSession.AnyDestroyedThisMoon) { return true; } OutdoorHelpers.MaybeMarkCleared(__instance); if (HostModGate.OutdoorClearedSynced) { Plugin.VLog("Skipped GenerateMold (no living weeds after destroy)."); return false; } return true; } } [HarmonyPatch(typeof(MoldSpreadManager), "ResetMoldData")] internal static class ResetMoldDataPatch { [HarmonyPostfix] private static void Postfix() { OutdoorSession.Reset(); } } [HarmonyPatch(typeof(StartOfRound), "ResetMoldStates")] internal static class ResetMoldStatesPatch { [HarmonyPostfix] private static void Postfix() { OutdoorSession.Reset(); } } [HarmonyPatch(typeof(StartOfRound), "StartGame")] internal static class StartGamePatch { [HarmonyPostfix] private static void Postfix() { OutdoorSession.Reset(); HostModGate.EnsureRegistered(); } } [HarmonyPatch(typeof(StartOfRound), "Start")] internal static class HostModGateStartPatch { private static void Postfix() { HostModGate.EnsureRegistered(); } } internal static class OutdoorHelpers { internal static void MaybeMarkCleared(MoldSpreadManager msm) { if (!((Object)(object)msm == (Object)null) && !OutdoorSession.OutdoorCleared && OutdoorSession.AnyDestroyedThisMoon) { bool flag = msm.generatedMold == null || msm.generatedMold.Count == 0; bool flag2 = false; try { flag2 = !msm.GetWeeds(); } catch { } if (flag || flag2) { OutdoorSession.OutdoorCleared = true; Plugin.Log.LogInfo((object)"Outdoor mold fully cleared for this moon; further GenerateMold blocked."); HostModGate.BroadcastState(); } } } } [BepInPlugin("com.benhough.lethal.NoWeedRespawn", "NoWeedRespawn", "1.0.1")] public class Plugin : BaseUnityPlugin { public const string ModGuid = "com.benhough.lethal.NoWeedRespawn"; public const string ModName = "NoWeedRespawn"; public const string ModVersion = "1.0.1"; internal static ManualLogSource Log { get; private set; } internal static ConfigEntry<bool> Enabled { get; private set; } internal static ConfigEntry<bool> BlockIndoorRespawn { get; private set; } internal static ConfigEntry<bool> BlockOutdoorRespawn { get; private set; } internal static ConfigEntry<bool> VerboseLogging { get; private set; } internal static bool IndoorActive => HostModGate.IndoorActive; internal static bool OutdoorActive => HostModGate.OutdoorActive; private void Awake() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle. When false, all patches no-op."); BlockIndoorRespawn = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BlockIndoorRespawn", true, "Keep indoor cadaver/weed tiles eradicated after they are fully cleared."); BlockOutdoorRespawn = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BlockOutdoorRespawn", true, "Prevent outdoor vain shroud / mold from regenerating after clears this moon."); VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "VerboseLogging", false, "Log patch hits (eradication keep, spawn blocks, GenerateMold skips)."); new Harmony("com.benhough.lethal.NoWeedRespawn").PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"NoWeedRespawn v1.0.1 loaded. Host should run this for networked growth RPCs."); } internal static void VLog(string message) { if (VerboseLogging.Value) { Log.LogInfo((object)message); } } } internal static class PluginInfo { public const string PLUGIN_GUID = "com.benhough.lethal.NoWeedRespawn"; public const string PLUGIN_NAME = "NoWeedRespawn"; public const string PLUGIN_VERSION = "1.0.1"; } }