Decompiled source of Horde v1.0.1

Horde.dll

Decompiled a week ago
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]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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.0.1")]
	public class WaveBoosterPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <CapEnforcerRoutine>d__17 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public WaveBoosterPlugin <>4__this;

			private WaitForSeconds <wait>5__1;

			private object <waveStruct>5__2;

			private int <current>5__3;

			private int <target>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CapEnforcerRoutine>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<wait>5__1 = null;
				<waveStruct>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<wait>5__1 = new WaitForSeconds(1f);
					break;
				case 1:
					<>1__state = -1;
					if (!<>4__this._reflectionValid || (Object)(object)EnemyManager.Instance == (Object)null || ((Object)(object)NetworkManager.Singleton != (Object)null && !NetworkManager.Singleton.IsServer))
					{
						break;
					}
					try
					{
						<waveStruct>5__2 = _waveField.GetValue(EnemyManager.Instance);
						<current>5__3 = (int)_maxEnemiesField.GetValue(<waveStruct>5__2);
						<target>5__4 = ((!<>4__this.StopSpawnsConfig.Value) ? <>4__this.MaxEnemiesConfig.Value : 0);
						if (<current>5__3 != <target>5__4)
						{
							_maxEnemiesField.SetValue(<waveStruct>5__2, <target>5__4);
							_waveField.SetValue(EnemyManager.Instance, <waveStruct>5__2);
						}
						<waveStruct>5__2 = null;
					}
					catch
					{
					}
					break;
				}
				<>2__current = <wait>5__1;
				<>1__state = 1;
				return true;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static WaveBoosterPlugin Instance;

		public static ManualLogSource ModLogger;

		public ConfigEntry<int> MaxEnemiesConfig;

		public ConfigEntry<int> MultiplierConfig;

		public ConfigEntry<bool> ShowCounterConfig;

		public ConfigEntry<bool> StopSpawnsConfig;

		public ConfigEntry<Key> MenuKeyConfig;

		public static MethodInfo _masterSpawnMethod;

		private static FieldInfo _waveField;

		private static FieldInfo _maxEnemiesField;

		private bool _showMenu = false;

		private Rect _windowRect = new Rect(20f, 20f, 320f, 160f);

		private GUIStyle _counterStyle;

		private bool _reflectionValid = false;

		private void Awake()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			Instance = this;
			ModLogger = ((BaseUnityPlugin)this).Logger;
			MaxEnemiesConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxEnemies", 100, "");
			MultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SpawnMultiplier", 3, "");
			ShowCounterConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowCounter", true, "");
			StopSpawnsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StopSpawns", false, "");
			MenuKeyConfig = ((BaseUnityPlugin)this).Config.Bind<Key>("General", "MenuKey", (Key)94, "");
			Harmony val = new Harmony("com.coloron.horde");
			LocateReflections();
			try
			{
				val.PatchAll();
			}
			catch (Exception ex)
			{
				ModLogger.LogError((object)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;
				}
			}
			catch
			{
			}
		}

		[IteratorStateMachine(typeof(<CapEnforcerRoutine>d__17))]
		private IEnumerator CapEnforcerRoutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CapEnforcerRoutine>d__17(0)
			{
				<>4__this = this
			};
		}

		private void Update()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (Keyboard.current != null && ((ButtonControl)Keyboard.current[MenuKeyConfig.Value]).wasPressedThisFrame)
			{
				ToggleMenu();
			}
		}

		private void ToggleMenu()
		{
			_showMenu = !_showMenu;
			Cursor.visible = _showMenu;
			Cursor.lockState = (CursorLockMode)((!_showMenu) ? 1 : 0);
		}

		private void OnGUI()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (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(999, _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<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			ShowCounterConfig.Value = GUILayout.Toggle(ShowCounterConfig.Value, " Show Counter", Array.Empty<GUILayoutOption>());
			StopSpawnsConfig.Value = GUILayout.Toggle(StopSpawnsConfig.Value, " Stop All Spawns", Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			GUILayout.Label($"Spawn Multiplier: {MultiplierConfig.Value}x", Array.Empty<GUILayoutOption>());
			MultiplierConfig.Value = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)MultiplierConfig.Value, 1f, 10f, Array.Empty<GUILayoutOption>()));
			GUILayout.Space(10f);
			GUILayout.Label($"Max Enemy Cap: {MaxEnemiesConfig.Value}", Array.Empty<GUILayoutOption>());
			MaxEnemiesConfig.Value = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)MaxEnemiesConfig.Value, 1f, 500f, Array.Empty<GUILayoutOption>()));
			GUILayout.EndVertical();
			GUI.DragWindow();
		}
	}
	[HarmonyPatch]
	public class SmartMultiplierPatch
	{
		[CompilerGenerated]
		private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private MethodBase <>2__current;

			private int <>l__initialThreadId;

			MethodBase IEnumerator<MethodBase>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <TargetMethods>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (WaveBoosterPlugin._masterSpawnMethod != null)
					{
						<>2__current = WaveBoosterPlugin._masterSpawnMethod;
						<>1__state = 1;
						return true;
					}
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator()
			{
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					return this;
				}
				return new <TargetMethods>d__0(0);
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<MethodBase>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<TargetMethods>d__0))]
		private static IEnumerable<MethodBase> TargetMethods()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TargetMethods>d__0(-2);
		}

		public static void Prefix(ref int __2)
		{
			if ((Object)(object)WaveBoosterPlugin.Instance == (Object)null || ((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;
		}
	}
}