Decompiled source of Cursed Voodoo v1.0.0

VoodooNerf.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VoodooNerf")]
[assembly: AssemblyTitle("VoodooNerf")]
[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;
		}
	}
}
namespace VoodooNerf
{
	[BepInPlugin("Omniscye.VoodooNerf", "VoodooNerf", "1.0")]
	public class VoodooNerf : BaseUnityPlugin
	{
		internal static VoodooNerf Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}
namespace Empress.Repo.VoodooKillPatch
{
	[BepInPlugin("empress.repo.voodookillpatch", "Voodoo Kill Patch", "1.0.4")]
	[BepInProcess("REPO.exe")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "empress.repo.voodookillpatch";

		public const string PluginName = "Voodoo Kill Patch";

		public const string PluginVersion = "1.0.4";

		internal static ManualLogSource LogSrc;

		private Harmony _harmony;

		private bool _patched;

		internal static Type VoodooType;

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			LogSrc = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("empress.repo.voodookillpatch");
			TryPatch();
			AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
		}

		private void OnDestroy()
		{
			try
			{
				AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
		}

		private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs e)
		{
			if (_patched)
			{
				return;
			}
			try
			{
				string a = e.LoadedAssembly?.GetName()?.Name;
				if (string.Equals(a, "WesleysEnemies", StringComparison.Ordinal))
				{
					LogSrc.LogInfo((object)"Detected WesleysEnemies assembly load; attempting patch...");
					TryPatch();
				}
			}
			catch (Exception arg)
			{
				LogSrc.LogError((object)$"OnAssemblyLoad handler errored: {arg}");
			}
		}

		private void TryPatch()
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Expected O, but got Unknown
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Expected O, but got Unknown
			if (_patched)
			{
				return;
			}
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(delegate(Assembly a)
			{
				try
				{
					return a.GetName().Name.Equals("WesleysEnemies", StringComparison.Ordinal);
				}
				catch
				{
					return false;
				}
			});
			if (assembly == null)
			{
				LogSrc.LogInfo((object)"WesleysEnemies not loaded yet. Waiting...");
				return;
			}
			VoodooType = assembly.GetType("WesleysEnemies.AI.Voodoo", throwOnError: false) ?? assembly.GetType("WesleysEnemies.Voodoo", throwOnError: false) ?? assembly.GetTypes().FirstOrDefault((Type t) => t.Name == "Voodoo");
			if (VoodooType == null)
			{
				LogSrc.LogWarning((object)"Type 'Voodoo' not found in WesleysEnemies; nothing to patch.");
				return;
			}
			MethodInfo method = VoodooType.GetMethod("OnHurt", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method != null)
			{
				_harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(Patches).GetMethod("Voodoo_OnHurt_Prefix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				LogSrc.LogWarning((object)"Method Voodoo.OnHurt() not found; kill-fix may be incomplete.");
			}
			MethodInfo method2 = VoodooType.GetMethod("OnSpawn", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method2 != null)
			{
				_harmony.Patch((MethodBase)method2, (HarmonyMethod)null, new HarmonyMethod(typeof(Patches).GetMethod("Voodoo_OnSpawn_Postfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			Type typeFromHandle = typeof(EnemyHealth);
			MethodInfo method3 = typeFromHandle.GetMethod("Hurt", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
			{
				typeof(int),
				typeof(Vector3)
			}, null);
			if (method3 != null)
			{
				_harmony.Patch((MethodBase)method3, (HarmonyMethod)null, new HarmonyMethod(typeof(Patches).GetMethod("EnemyHealth_Hurt_Postfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo method4 = typeFromHandle.GetMethod("DeathImpulseRPC", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method4 != null)
			{
				_harmony.Patch((MethodBase)method4, (HarmonyMethod)null, new HarmonyMethod(typeof(Patches).GetMethod("EnemyHealth_DeathImpulse_Postfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			Type type = (from a in AppDomain.CurrentDomain.GetAssemblies()
				select a.GetType("EnemyRigidbody", throwOnError: false)).FirstOrDefault((Type t) => t != null);
			if (type != null)
			{
				MethodInfo method5 = type.GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method5 != null)
				{
					_harmony.Patch((MethodBase)method5, new HarmonyMethod(typeof(Patches).GetMethod("EnemyRigidbody_FixedUpdate_Prefix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			Type type2 = (from a in AppDomain.CurrentDomain.GetAssemblies()
				select a.GetType("EnemyDirector", throwOnError: false)).FirstOrDefault((Type t) => t != null);
			if (type2 != null)
			{
				MethodInfo method6 = type2.GetMethod("SetInvestigate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
				{
					typeof(Vector3),
					typeof(float),
					typeof(bool)
				}, null);
				if (method6 != null)
				{
					_harmony.Patch((MethodBase)method6, new HarmonyMethod(typeof(Patches).GetMethod("EnemyDirector_SetInvestigate_Prefix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			_patched = true;
			LogSrc.LogInfo((object)"Patched WesleysEnemies.Voodoo.OnHurt() – Voodoo can now be killed normally.");
		}

		internal static void SafeQuarantine(GameObject go)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)go == (Object)null)
				{
					return;
				}
				Behaviour[] componentsInChildren = go.GetComponentsInChildren<Behaviour>(true);
				foreach (Behaviour val in componentsInChildren)
				{
					try
					{
						val.enabled = false;
					}
					catch
					{
					}
				}
				Collider[] componentsInChildren2 = go.GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren2)
				{
					try
					{
						val2.enabled = false;
					}
					catch
					{
					}
				}
				Rigidbody[] componentsInChildren3 = go.GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody val3 in componentsInChildren3)
				{
					try
					{
						val3.isKinematic = true;
						val3.velocity = Vector3.zero;
						val3.angularVelocity = Vector3.zero;
						val3.Sleep();
					}
					catch
					{
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logSrc = LogSrc;
				if (logSrc != null)
				{
					logSrc.LogWarning((object)("SafeQuarantine failed: " + ex.Message));
				}
			}
		}
	}
	public static class Patches
	{
		public static bool Voodoo_OnHurt_Prefix(object __instance)
		{
			return false;
		}

		public static void Voodoo_OnSpawn_Postfix(object __instance)
		{
			try
			{
				object? obj = __instance.GetType().GetField("_enemyHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(__instance);
				EnemyHealth val = (EnemyHealth)((obj is EnemyHealth) ? obj : null);
				if ((Object)(object)val != (Object)null)
				{
					if (val.health <= 0)
					{
						val.health = 100;
					}
					if (val.healthCurrent <= 0 || val.healthCurrent > val.health)
					{
						val.healthCurrent = val.health;
					}
					ManualLogSource logSrc = Plugin.LogSrc;
					if (logSrc != null)
					{
						logSrc.LogInfo((object)$"Voodoo OnSpawn: normalized health to {val.healthCurrent}.");
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logSrc2 = Plugin.LogSrc;
				if (logSrc2 != null)
				{
					logSrc2.LogWarning((object)("Voodoo_OnSpawn_Postfix failed: " + ex.Message));
				}
			}
		}

		public static void EnemyHealth_Hurt_Postfix(EnemyHealth __instance, int _damage, Vector3 _hurtDirection)
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Type voodooType = Plugin.VoodooType;
				if (voodooType == null)
				{
					return;
				}
				Component component = ((Component)__instance).gameObject.GetComponent(voodooType);
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				ManualLogSource logSrc = Plugin.LogSrc;
				if (logSrc != null)
				{
					logSrc.LogInfo((object)$"Voodoo took {_damage} damage. HP now {__instance.healthCurrent}/{__instance.health}.");
				}
				if (__instance.healthCurrent > 0)
				{
					return;
				}
				FieldInfo field = typeof(EnemyHealth).GetField("dead", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				bool flag = false;
				if (field != null && field.GetValue(__instance) is bool flag2)
				{
					flag = flag2;
				}
				if (!flag)
				{
					MethodInfo method = typeof(EnemyHealth).GetMethod("Death", BindingFlags.Instance | BindingFlags.NonPublic);
					if (method != null)
					{
						ManualLogSource logSrc2 = Plugin.LogSrc;
						if (logSrc2 != null)
						{
							logSrc2.LogInfo((object)"Voodoo at <=0 HP but not dead. Forcing Death().");
						}
						method.Invoke(__instance, new object[1] { _hurtDirection });
					}
				}
				Plugin.SafeQuarantine(((Component)__instance).gameObject);
				Object.Destroy((Object)(object)((Component)__instance).gameObject, 0.25f);
			}
			catch (Exception ex)
			{
				ManualLogSource logSrc3 = Plugin.LogSrc;
				if (logSrc3 != null)
				{
					logSrc3.LogWarning((object)("EnemyHealth_Hurt_Postfix failed: " + ex.Message));
				}
			}
		}

		public static void EnemyHealth_DeathImpulse_Postfix(EnemyHealth __instance)
		{
			try
			{
				Type voodooType = Plugin.VoodooType;
				if (voodooType == null)
				{
					return;
				}
				Component component = ((Component)__instance).gameObject.GetComponent(voodooType);
				if (!((Object)(object)component == (Object)null))
				{
					ManualLogSource logSrc = Plugin.LogSrc;
					if (logSrc != null)
					{
						logSrc.LogInfo((object)"Voodoo confirmed dead via DeathImpulse. Destroying GameObject.");
					}
					Plugin.SafeQuarantine(((Component)__instance).gameObject);
					Object.Destroy((Object)(object)((Component)__instance).gameObject);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logSrc2 = Plugin.LogSrc;
				if (logSrc2 != null)
				{
					logSrc2.LogWarning((object)("EnemyHealth_DeathImpulse_Postfix failed: " + ex.Message));
				}
			}
		}

		public static bool EnemyRigidbody_FixedUpdate_Prefix(object __instance)
		{
			try
			{
				Component val = (Component)((__instance is Component) ? __instance : null);
				if (val != null)
				{
					EnemyHealth component = val.GetComponent<EnemyHealth>();
					if ((Object)(object)component != (Object)null && component.healthCurrent <= 0)
					{
						return false;
					}
				}
			}
			catch
			{
			}
			return true;
		}

		public static bool EnemyDirector_SetInvestigate_Prefix(object __instance, Vector3 position, float radius, bool pathfindOnly)
		{
			try
			{
				Component val = (Component)((__instance is Component) ? __instance : null);
				if (val != null)
				{
					EnemyHealth componentInParent = val.GetComponentInParent<EnemyHealth>();
					if ((Object)(object)componentInParent != (Object)null && componentInParent.healthCurrent <= 0)
					{
						return false;
					}
				}
			}
			catch
			{
			}
			return true;
		}
	}
}