using 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.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.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("NoWeedRespawn")] [assembly: AssemblyTitle("NoWeedRespawn")] [assembly: AssemblyVersion("1.0.0.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 OutdoorSession { internal static bool OutdoorCleared; internal static bool AnyDestroyedThisMoon; internal static readonly HashSet DestroyedIndices = new HashSet(); internal static void Reset() { OutdoorCleared = false; AnyDestroyedThisMoon = false; DestroyedIndices.Clear(); 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 (OutdoorSession.OutdoorCleared) { Plugin.VLog("Skipped GenerateMold (OutdoorCleared)."); return false; } if (!OutdoorSession.AnyDestroyedThisMoon) { return true; } OutdoorHelpers.MaybeMarkCleared(__instance); if (OutdoorSession.OutdoorCleared) { 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(); } } 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."); } } } } [BepInPlugin("com.benhough.lethal.NoWeedRespawn", "NoWeedRespawn", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string ModGuid = "com.benhough.lethal.NoWeedRespawn"; public const string ModName = "NoWeedRespawn"; public const string ModVersion = "1.0.0"; internal static ManualLogSource Log { get; private set; } internal static ConfigEntry Enabled { get; private set; } internal static ConfigEntry BlockIndoorRespawn { get; private set; } internal static ConfigEntry BlockOutdoorRespawn { get; private set; } internal static ConfigEntry VerboseLogging { get; private set; } internal static bool IndoorActive { get { if (Enabled.Value) { return BlockIndoorRespawn.Value; } return false; } } internal static bool OutdoorActive { get { if (Enabled.Value) { return BlockOutdoorRespawn.Value; } return false; } } 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("General", "Enabled", true, "Master toggle. When false, all patches no-op."); BlockIndoorRespawn = ((BaseUnityPlugin)this).Config.Bind("General", "BlockIndoorRespawn", true, "Keep indoor cadaver/weed tiles eradicated after they are fully cleared."); BlockOutdoorRespawn = ((BaseUnityPlugin)this).Config.Bind("General", "BlockOutdoorRespawn", true, "Prevent outdoor vain shroud / mold from regenerating after clears this moon."); VerboseLogging = ((BaseUnityPlugin)this).Config.Bind("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.0 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.0"; } }