Decompiled source of Oops All Maurices v1.1.0

OopsAllMaurices.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OopsAllMaurices")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OopsAllMaurices")]
[assembly: AssemblyTitle("OopsAllMaurices")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OopsAllMaurices
{
	[BepInPlugin("com.yourname.oopsallmaurices", "Oops All Maurices", "1.0.4")]
	public class MainPlugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Oops All Maurices mod loaded!");
			Harmony val = new Harmony("com.yourname.oopsallmaurices");
			val.PatchAll();
			SceneManager.sceneLoaded += delegate
			{
				EnemyReplacerPatch.ClearCache();
			};
		}
	}
	[HarmonyPatch(typeof(EnemyIdentifier), "Start")]
	public class EnemyReplacerPatch
	{
		private static bool isReplacing;

		private static GameObject cachedMauricePrefab;

		public static void ClearCache()
		{
			cachedMauricePrefab = null;
		}

		private static void Postfix(EnemyIdentifier __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			if (isReplacing || (Object)(object)__instance == (Object)null || (int)__instance.enemyType == 4)
			{
				return;
			}
			if ((Object)(object)cachedMauricePrefab == (Object)null)
			{
				cachedMauricePrefab = FindMauricePrefab();
			}
			if (!((Object)(object)cachedMauricePrefab != (Object)null))
			{
				return;
			}
			isReplacing = true;
			Transform transform = ((Component)__instance).transform;
			Vector3 position = transform.position;
			Quaternion rotation = transform.rotation;
			Transform parent = transform.parent;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(position, Vector3.up, ref val, 6f))
			{
				position.y = ((RaycastHit)(ref val)).point.y - 3f;
			}
			GameObject val2 = Object.Instantiate<GameObject>(cachedMauricePrefab, position, rotation, parent);
			EnemyIdentifier component = val2.GetComponent<EnemyIdentifier>();
			if ((Object)(object)component != (Object)null)
			{
				if (__instance.onDeath != null)
				{
					component.onDeath = __instance.onDeath;
				}
				UpdateWaveTrackers(((Component)__instance).gameObject, val2);
			}
			Object.Destroy((Object)(object)((Component)__instance).gameObject);
			isReplacing = false;
		}

		private static void UpdateWaveTrackers(GameObject oldTarget, GameObject newTarget)
		{
			ActivateNextWave[] array = Object.FindObjectsOfType<ActivateNextWave>();
			ActivateNextWave[] array2 = array;
			foreach (ActivateNextWave val in array2)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				FieldInfo[] fields = typeof(ActivateNextWave).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo[] array3 = fields;
				foreach (FieldInfo fieldInfo in array3)
				{
					object value = fieldInfo.GetValue(val);
					if (value == null || !(value is IList list))
					{
						continue;
					}
					for (int k = 0; k < list.Count; k++)
					{
						object obj = list[k];
						if (obj == null)
						{
							continue;
						}
						GameObject val2 = (GameObject)((obj is GameObject) ? obj : null);
						if (val2 != null && (Object)(object)val2 == (Object)(object)oldTarget)
						{
							list[k] = newTarget;
							continue;
						}
						EnemyIdentifier val3 = (EnemyIdentifier)((obj is EnemyIdentifier) ? obj : null);
						if (val3 != null && (Object)(object)((Component)val3).gameObject == (Object)(object)oldTarget)
						{
							list[k] = newTarget.GetComponent<EnemyIdentifier>();
						}
					}
				}
			}
		}

		private static GameObject FindMauricePrefab()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Invalid comparison between Unknown and I4
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			EnemyIdentifier[] array = Object.FindObjectsOfType<EnemyIdentifier>();
			EnemyIdentifier[] array2 = array;
			Scene scene;
			foreach (EnemyIdentifier val in array2)
			{
				if ((Object)(object)val != (Object)null && (int)val.enemyType == 4 && (Object)(object)((Component)val).gameObject != (Object)null)
				{
					scene = ((Component)val).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						return ((Component)val).gameObject;
					}
				}
			}
			EnemyIdentifier[] array3 = Resources.FindObjectsOfTypeAll<EnemyIdentifier>();
			EnemyIdentifier[] array4 = array3;
			foreach (EnemyIdentifier val2 in array4)
			{
				if ((Object)(object)val2 != (Object)null && (int)val2.enemyType == 4 && (Object)(object)((Component)val2).gameObject != (Object)null)
				{
					scene = ((Component)val2).gameObject.scene;
					if (!((Scene)(ref scene)).IsValid())
					{
						return ((Component)val2).gameObject;
					}
				}
			}
			return null;
		}
	}
}