Decompiled source of ModifyMonsterSpawner v1.0.0

staller.ModifyMonsterSpawner.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("staller.ModifyMonsterSpawner")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ModifyMonsterSpawner")]
[assembly: AssemblyTitle("staller.ModifyMonsterSpawner")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.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]
	[Microsoft.CodeAnalysis.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]
	[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;
		}
	}
}
internal class ModifySpawnerConfig
{
	private static ConfigEntry<int> _spawnModify;

	private static ConfigEntry<float> _spawnDuration;

	public static int SpawnModify
	{
		get
		{
			return _spawnModify.Value;
		}
		set
		{
			_spawnModify.Value = value;
		}
	}

	public static float SpawnDuration
	{
		get
		{
			return _spawnDuration.Value;
		}
		set
		{
			_spawnDuration.Value = value;
		}
	}

	internal static void Bind(ConfigFile config)
	{
		_spawnModify = config.Bind<int>("General", "Spawn Modify", 3, "Modifier of monster spawning quantity");
		_spawnDuration = config.Bind<float>("General", "Spawn Duration", 2.5f, "The gap between the first and second wave sleeper");
	}
}
namespace ModifyMonsterSpawner
{
	[ContentWarningPlugin("staller.ModifyMonsterSpawner", "1.0.0", false)]
	[BepInPlugin("staller.ModifyMonsterSpawner", "ModifyMonsterSpawner", "1.0.0")]
	public class ModifyMonsterSpawner : BaseUnityPlugin
	{
		public static ModifyMonsterSpawner Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			ModifySpawnerConfig.Bind(((BaseUnityPlugin)this).Config);
			Patch();
			Logger.LogInfo((object)"staller.ModifyMonsterSpawner v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("staller.ModifyMonsterSpawner");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "staller.ModifyMonsterSpawner";

		public const string PLUGIN_NAME = "ModifyMonsterSpawner";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ModifyMonsterSpawner.Patches
{
	[HarmonyPatch(typeof(RoundSpawner))]
	public class MonsterSpawnerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void RoundSpawnerStartPatch(RoundSpawner __instance)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			int spawnModify = ModifySpawnerConfig.SpawnModify;
			float spawnDuration = ModifySpawnerConfig.SpawnDuration;
			Debug.Log((object)$"Modify: {spawnModify}");
			FieldInfo field = typeof(RoundSpawner).GetField("testFirstWaveSize", BindingFlags.Instance | BindingFlags.Public);
			if (field != null)
			{
				Vector2 val = (Vector2)field.GetValue(__instance);
				field.SetValue(__instance, (object)new Vector2(val.x * (float)spawnModify, val.y * (float)spawnModify));
				Debug.Log((object)$"Modified first wave size: {val} -> {(object)(Vector2)field.GetValue(__instance)}");
			}
			else
			{
				Debug.LogError((object)"Failed to find testFirstWaveSize field.");
			}
			FieldInfo field2 = typeof(RoundSpawner).GetField("testBudget", BindingFlags.Instance | BindingFlags.Public);
			if (field2 != null)
			{
				int num = (int)field2.GetValue(__instance);
				field2.SetValue(__instance, num * spawnModify);
				Debug.Log((object)$"Modified spawn budget: {num} -> {num * spawnModify}");
			}
			else
			{
				Debug.LogError((object)"Failed to find testBudget field.");
			}
			FieldInfo field3 = typeof(RoundSpawner).GetField("testMinMaxSecondWaveWaitTime", BindingFlags.Instance | BindingFlags.Public);
			if (field3 != null)
			{
				Vector2 val2 = (Vector2)field3.GetValue(__instance);
				field3.SetValue(__instance, (object)new Vector2(val2.x / spawnDuration, val2.y / spawnDuration));
				Debug.Log((object)$"Modified second wave wait time: {val2} -> {(object)(Vector2)field3.GetValue(__instance)}");
			}
			else
			{
				Debug.LogError((object)"Failed to find testMinMaxSecondWaveWaitTime field.");
			}
			MethodInfo method = typeof(RoundSpawner).GetMethod("SpawnSecondRun", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method != null)
			{
				int budgetForSpawn = (int)field2.GetValue(__instance);
				FieldInfo field4 = typeof(RoundSpawner).GetField("testBiggestPurchase", BindingFlags.Instance | BindingFlags.Public);
				if (field4 != null)
				{
					int biggestPurchase = (int)field4.GetValue(__instance);
					float waitTime = spawnDuration;
					((MonoBehaviour)__instance).StartCoroutine(DelayedSecondWaveSpawn(__instance, method, waitTime, budgetForSpawn, biggestPurchase));
				}
				else
				{
					Debug.LogError((object)"Failed to find testBiggestPurchase field.");
				}
			}
			else
			{
				Debug.LogError((object)"Failed to find SpawnSecondRun method.");
			}
		}

		private static IEnumerator DelayedSecondWaveSpawn(RoundSpawner instance, MethodInfo spawnSecondRunMethod, float waitTime, int budgetForSpawn, int biggestPurchase)
		{
			yield return (object)new WaitForSeconds(1f);
			try
			{
				spawnSecondRunMethod.Invoke(instance, new object[3] { waitTime, budgetForSpawn, biggestPurchase });
				Debug.Log((object)"Spawned second wave with modified settings.");
			}
			catch (Exception ex)
			{
				Debug.LogError((object)$"Error invoking SpawnSecondRun: {ex}");
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}