using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 hordeBooster { [BepInPlugin("com.coloron.horde", "Horde", "1.1.0")] [MycoMod(/*Could not decode attribute arguments.*/)] public class WaveBoosterPlugin : BaseUnityPlugin { public static WaveBoosterPlugin Instance; public static ManualLogSource ModLogger; public ConfigEntry ModEnabledConfig; public ConfigEntry MaxEnemiesConfig; public ConfigEntry MultiplierConfig; public ConfigEntry ShowCounterConfig; public ConfigEntry StopSpawnsConfig; public ConfigEntry MenuKeyConfig; public static MethodInfo _masterSpawnMethod; private static FieldInfo _waveField; private static FieldInfo _maxEnemiesField; private bool _showMenu = false; private Rect _windowRect = new Rect(20f, 20f, 340f, 160f); private GUIStyle _counterStyle; private bool _reflectionValid = false; private void Awake() { //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Expected O, but got Unknown Instance = this; ModLogger = ((BaseUnityPlugin)this).Logger; ModEnabledConfig = ((BaseUnityPlugin)this).Config.Bind("General", "ModEnabled", true, "Master toggle"); MaxEnemiesConfig = ((BaseUnityPlugin)this).Config.Bind("General", "MaxEnemies", 0, "0 = use the game's default max enemy value"); MultiplierConfig = ((BaseUnityPlugin)this).Config.Bind("General", "SpawnMultiplier", 1, ""); ShowCounterConfig = ((BaseUnityPlugin)this).Config.Bind("General", "ShowCounter", true, ""); StopSpawnsConfig = ((BaseUnityPlugin)this).Config.Bind("General", "StopSpawns", false, ""); MenuKeyConfig = ((BaseUnityPlugin)this).Config.Bind("General", "MenuKey", (Key)94, ""); Harmony val = new Harmony("com.coloron.horde"); LocateReflections(); try { val.PatchAll(); } catch (Exception ex) { ModLogger.LogError((object)("Harmony Patching Failed: " + ex.Message)); } } private void Start() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) _counterStyle = new GUIStyle { fontSize = 25, fontStyle = (FontStyle)1 }; _counterStyle.normal.textColor = Color.red; ((MonoBehaviour)this).StartCoroutine(CapEnforcerRoutine()); } private void LocateReflections() { try { Type typeFromHandle = typeof(EnemyManager); MethodInfo[] methods = typeFromHandle.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo[] array = methods; foreach (MethodInfo methodInfo in array) { if (methodInfo.Name == "SpawnWave_Server") { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length > 4 && parameters[0].ParameterType == typeof(Vector3)) { _masterSpawnMethod = methodInfo; break; } } } _waveField = AccessTools.Field(typeFromHandle, "wave"); if (_waveField != null) { _maxEnemiesField = AccessTools.Field(_waveField.FieldType, "maxLivingEnemies"); } if (_waveField != null && _maxEnemiesField != null) { _reflectionValid = true; } else { ModLogger.LogWarning((object)"Failed to find 'wave' or 'maxLivingEnemies' on EnemyManager. Cap Enforcer is disabled."); } if (_masterSpawnMethod == null) { ModLogger.LogWarning((object)"Failed to locate 'SpawnWave_Server' method. Spawn multiplier is disabled."); } } catch (Exception arg) { ModLogger.LogError((object)$"Error executing reflection: {arg}"); } } private IEnumerator CapEnforcerRoutine() { WaitForSeconds wait = new WaitForSeconds(1f); while (true) { yield return wait; if (!ModEnabledConfig.Value || !_reflectionValid || (Object)(object)EnemyManager.Instance == (Object)null || ((Object)(object)NetworkManager.Singleton != (Object)null && !NetworkManager.Singleton.IsServer)) { continue; } try { object waveStruct = _waveField.GetValue(EnemyManager.Instance); int current; int target; if (waveStruct != null) { current = (int)_maxEnemiesField.GetValue(waveStruct); if (StopSpawnsConfig.Value) { target = 0; goto IL_0156; } if (MaxEnemiesConfig.Value != 0) { target = MaxEnemiesConfig.Value; goto IL_0156; } } goto end_IL_00b9; IL_0156: if (current != target) { _maxEnemiesField.SetValue(waveStruct, target); _waveField.SetValue(EnemyManager.Instance, waveStruct); } end_IL_00b9:; } catch (Exception ex) { Exception ex2 = ex; ModLogger.LogError((object)("Encountered error in CapEnforcerRoutine. Disabling Cap Enforcer. Error: " + ex2.Message)); _reflectionValid = false; } } } private void Update() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)EnemyManager.Instance == (Object)null) { if (_showMenu) { ToggleMenu(); } } else if (Keyboard.current == null) { ModLogger.LogWarning((object)"Keyboard.current is null - new Input System backend not active."); } else if (((ButtonControl)Keyboard.current[MenuKeyConfig.Value]).wasPressedThisFrame) { ModLogger.LogInfo((object)$"MenuKey ({MenuKeyConfig.Value}) pressed - toggling menu."); ToggleMenu(); } } private void ToggleMenu() { _showMenu = !_showMenu; Cursor.visible = _showMenu; Cursor.lockState = (CursorLockMode)(!_showMenu); } private void OnGUI() { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) if (ModEnabledConfig.Value && ShowCounterConfig.Value) { int num = (((Object)(object)EnemyManager.Instance != (Object)null) ? EnemyManager.Instance.LivingEnemies : 0); GUI.Label(new Rect((float)(Screen.width - 220), 20f, 200f, 50f), $"ENEMIES: {num}", _counterStyle); } if (_showMenu) { GUI.backgroundColor = Color.black; _windowRect = GUI.Window(92839, _windowRect, new WindowFunction(DrawWindow), "Horde Settings"); float num2 = Mathf.Clamp(((Rect)(ref _windowRect)).x, 0f, (float)Screen.width - ((Rect)(ref _windowRect)).width); float num3 = Mathf.Clamp(((Rect)(ref _windowRect)).y, 0f, (float)Screen.height - ((Rect)(ref _windowRect)).height); ((Rect)(ref _windowRect)).position = new Vector2(num2, num3); } } private void DrawWindow(int windowID) { GUILayout.BeginVertical(Array.Empty()); GUILayout.BeginHorizontal(Array.Empty()); ModEnabledConfig.Value = GUILayout.Toggle(ModEnabledConfig.Value, " Enable", Array.Empty()); GUI.enabled = ModEnabledConfig.Value; ShowCounterConfig.Value = GUILayout.Toggle(ShowCounterConfig.Value, " Counter", Array.Empty()); StopSpawnsConfig.Value = GUILayout.Toggle(StopSpawnsConfig.Value, " Stop Spawns", Array.Empty()); GUILayout.EndHorizontal(); GUILayout.Space(10f); GUILayout.Label($"Spawn Multiplier: {MultiplierConfig.Value}x", Array.Empty()); MultiplierConfig.Value = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)MultiplierConfig.Value, 1f, 10f, Array.Empty())); GUILayout.Space(10f); string text = ((MaxEnemiesConfig.Value == 0) ? "Default" : MaxEnemiesConfig.Value.ToString()); GUILayout.Label("Max Enemy Cap: " + text, Array.Empty()); MaxEnemiesConfig.Value = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)MaxEnemiesConfig.Value, 0f, 500f, Array.Empty())); GUI.enabled = true; GUILayout.EndVertical(); GUI.DragWindow(); } } [HarmonyPatch] public class SmartMultiplierPatch { private static IEnumerable TargetMethods() { if (WaveBoosterPlugin._masterSpawnMethod != null) { yield return WaveBoosterPlugin._masterSpawnMethod; } } public static void Prefix(ref int __2) { if ((Object)(object)WaveBoosterPlugin.Instance == (Object)null || !WaveBoosterPlugin.Instance.ModEnabledConfig.Value || ((Object)(object)NetworkManager.Singleton != (Object)null && !NetworkManager.Singleton.IsServer)) { return; } if (WaveBoosterPlugin.Instance.StopSpawnsConfig.Value) { __2 = 0; return; } int value = WaveBoosterPlugin.Instance.MultiplierConfig.Value; if (value > 1 && __2 > 0) { __2 *= value; } } } [HarmonyPatch(typeof(GameManager), "RemoveSyncedTransform_Rpc")] public static class SafeNetworkDespawnPatch { public static Exception Finalizer(Exception __exception) { return null; } } [HarmonyPatch(typeof(GameManager), "SendSyncedPositionsToClients_Server")] public static class SafeSyncPositionPatch { public static Exception Finalizer(Exception __exception) { return null; } } [HarmonyPatch(typeof(SoundPlayer), "OnSoundEnd")] public static class SafeSoundPatch { public static Exception Finalizer(Exception __exception) { return null; } } }