Decompiled source of ULTRAKILL MUSTNT LIVE v0.4.2

UKML.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("UKML")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My take on the currently unreleased ULTRAKILL Must Die difficulty")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyInformationalVersion("0.4.1+b8962ecb9d7f25574e38b7dd39fc1305df8bf631")]
[assembly: AssemblyProduct("UKML")]
[assembly: AssemblyTitle("UKML")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UKML
{
	[BepInPlugin("wacfeld.ukml", "ULTRAKILL Mustn't Live", "0.4.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "wacfeld.ukml";

		public const string PLUGIN_NAME = "ULTRAKILL Mustn't Live";

		public const string PLUGIN_VERSION = "0.4.1";

		private readonly Harmony harmony = new Harmony("wacfeld.ukml");

		private static bool addressableInit;

		public static GameObject shockwave;

		public static GameObject explosion;

		public ManualLogSource Log => ((BaseUnityPlugin)this).Logger;

		public static T LoadObject<T>(string path)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!addressableInit)
			{
				Addressables.InitializeAsync().WaitForCompletion();
				addressableInit = true;
			}
			return Addressables.LoadAssetAsync<T>((object)path).WaitForCompletion();
		}

		private void LoadAll()
		{
			shockwave = LoadObject<GameObject>("Assets/Prefabs/Attacks and Projectiles/PhysicalShockwave.prefab");
			explosion = LoadObject<GameObject>("Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion.prefab");
			Console.WriteLine("loaded assets!");
		}

		private void Awake()
		{
			harmony.PatchAll();
			LoadAll();
			Log.LogInfo((object)"Loaded ULTRAKILL Mustn't Live v0.4.1");
		}
	}
	[HarmonyPatch(typeof(NewMovement))]
	[HarmonyPatch("GetHurt")]
	internal class PatchGetHurt
	{
		private static void Prefix(ref float hardDamageMultiplier)
		{
			hardDamageMultiplier = 0.5f;
		}
	}
	[HarmonyPatch(typeof(SpiderBody))]
	[HarmonyPatch("Start")]
	internal class PatchMauriceStart
	{
		private static void Postfix(ref float ___coolDownMultiplier, ref int ___maxBurst, ref EnemyIdentifier ___eid)
		{
			___coolDownMultiplier = 500f;
			___maxBurst = 5;
		}
	}
	[HarmonyPatch(typeof(SpiderBody))]
	[HarmonyPatch("Update")]
	internal class PatchMauriceUpdate
	{
		private static void Postfix(SpiderBody __instance, EnemyIdentifier ___eid, ref int ___beamsAmount, ref float ___beamProbability)
		{
			if (___eid.beenGasolined)
			{
				__instance.Enrage();
			}
			if (__instance.isEnraged)
			{
				___beamsAmount = 2;
				___beamProbability = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(SpiderBody))]
	[HarmonyPatch("BeamChargeEnd")]
	internal class PatchMauriceBeamChargeEnd
	{
		public static Dictionary<int, bool> beamParryable = new Dictionary<int, bool>();

		private static void Prefix(SpiderBody __instance)
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			if (!beamParryable.ContainsKey(instanceID))
			{
				beamParryable.Add(instanceID, value: false);
			}
			beamParryable[instanceID] = !beamParryable[instanceID];
			if (beamParryable[instanceID])
			{
				__instance.spark = MonoSingleton<DefaultReferenceManager>.Instance.parryableFlash;
			}
			else
			{
				__instance.spark = MonoSingleton<DefaultReferenceManager>.Instance.unparryableFlash;
			}
		}

		private static void Postfix(SpiderBody __instance, ref bool ___parryable, Vector3 ___predictedPlayerPos, EnemyIdentifier ___eid)
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			if (!beamParryable[instanceID])
			{
				___parryable = false;
			}
			if (((MonoBehaviour)__instance).IsInvoking("BeamFire"))
			{
				((MonoBehaviour)__instance).CancelInvoke("BeamFire");
				((MonoBehaviour)__instance).Invoke("BeamFire", 0.25f / ___eid.totalSpeedModifier);
			}
		}
	}
	[HarmonyPatch(typeof(Explosion))]
	[HarmonyPatch("Start")]
	internal class PatchExplosion
	{
		private static void Postfix(Explosion __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.enemy)
			{
				__instance.canHit = (AffectedSubjects)1;
			}
		}
	}
	[HarmonyPatch(typeof(ContinuousBeam))]
	[HarmonyPatch("Update")]
	internal class PatchSchismBeam
	{
		private static void Postfix(ContinuousBeam __instance)
		{
			if (__instance.enemy)
			{
				__instance.canHitEnemy = false;
			}
			else
			{
				__instance.canHitEnemy = true;
			}
		}
	}
	[HarmonyPatch(typeof(Projectile))]
	[HarmonyPatch("Start")]
	internal class PatchProjectileStart
	{
		private static void Postfix(Projectile __instance, ref float ___speed, ref float ___turningSpeedMultiplier)
		{
			___speed *= 2f;
			___turningSpeedMultiplier *= 2f;
		}
	}
	[HarmonyPatch(typeof(Projectile))]
	[HarmonyPatch("Collided")]
	internal class PatchCollided
	{
		private static void Prefix(Projectile __instance, ref bool ___active, Collider other)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			if (___active && (((Component)other).gameObject.CompareTag("Head") || ((Component)other).gameObject.CompareTag("Body") || ((Component)other).gameObject.CompareTag("Limb") || ((Component)other).gameObject.CompareTag("EndLimb")) && !((Component)other).gameObject.CompareTag("Armor"))
			{
				EnemyIdentifierIdentifier componentInParent = ((Component)other).gameObject.GetComponentInParent<EnemyIdentifierIdentifier>();
				EnemyIdentifier val = null;
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.eid != (Object)null)
				{
					val = componentInParent.eid;
				}
				if ((Object)(object)val != (Object)null)
				{
					__instance.safeEnemyType = val.enemyType;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("OrbSpawn")]
	internal class PatchCerbThrow
	{
		public static Dictionary<int, int> orbBounces = new Dictionary<int, int>();

		private static bool Prefix(StatueBoss __instance, Light ___orbLight, Vector3 ___projectedPlayerPos, EnemyIdentifier ___eid, ref bool ___orbGrowing, ParticleSystem ___part)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(AddressablesExtensions.ToAsset(__instance.orbProjectile), new Vector3(((Component)___orbLight).transform.position.x, ((Component)__instance).transform.position.y + 3.5f, ((Component)___orbLight).transform.position.z), Quaternion.identity);
			val.transform.LookAt(___projectedPlayerPos);
			val.GetComponent<Rigidbody>().AddForce(val.transform.forward * 20000f);
			Projectile val2 = default(Projectile);
			if (val.TryGetComponent<Projectile>(ref val2))
			{
				int instanceID = ((Object)val2).GetInstanceID();
				orbBounces.Add(instanceID, 0);
				val2.target = ___eid.target;
			}
			___orbGrowing = false;
			___orbLight.range = 0f;
			___part.Play();
			return false;
		}
	}
	[HarmonyPatch(typeof(Projectile))]
	[HarmonyPatch("FixedUpdate")]
	internal class PatchCerbProj
	{
		private static bool Prefix(Projectile __instance, Rigidbody ___rb, Vector3 ___origScale, AudioSource ___aud, ref float ___radius)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Invalid comparison between Unknown and I4
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.parried || __instance.boosted)
			{
				return true;
			}
			int instanceID = ((Object)__instance).GetInstanceID();
			if (!PatchCerbThrow.orbBounces.ContainsKey(instanceID))
			{
				return true;
			}
			if (PatchCerbThrow.orbBounces[instanceID] >= 5)
			{
				return true;
			}
			if (!__instance.hittingPlayer && !__instance.undeflectable && !__instance.decorative && __instance.speed != 0f && (int)__instance.homingType == 0)
			{
				___rb.velocity = ((Component)__instance).transform.forward * __instance.speed;
			}
			if (__instance.decorative && ((Component)__instance).transform.localScale.x < ___origScale.x)
			{
				___aud.pitch = ((Component)__instance).transform.localScale.x / ___origScale.x * 2.8f;
				((Component)__instance).transform.localScale = Vector3.Slerp(((Component)__instance).transform.localScale, ___origScale, Time.deltaTime * __instance.speed);
			}
			Vector3 velocity = ___rb.velocity;
			Vector3 normalized = ((Vector3)(ref velocity)).normalized;
			velocity = ___rb.velocity;
			RaycastHit[] array = ___rb.SweepTestAll(normalized, ((Vector3)(ref velocity)).magnitude * Time.fixedDeltaTime, (QueryTriggerInteraction)1);
			if (array == null || array.Length == 0)
			{
				return false;
			}
			Array.Sort(array, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
			for (int i = 0; i < array.Length; i++)
			{
				GameObject gameObject = ((Component)((RaycastHit)(ref array[i])).transform).gameObject;
				if ((gameObject.layer == 10 || gameObject.layer == 11) && (gameObject.gameObject.CompareTag("Head") || gameObject.gameObject.CompareTag("Body") || gameObject.gameObject.CompareTag("Limb") || gameObject.gameObject.CompareTag("EndLimb") || gameObject.gameObject.CompareTag("Enemy")))
				{
					return false;
				}
				if (LayerMaskDefaults.IsMatchingLayer(gameObject.layer, (LMD)1) || gameObject.layer == 26 || gameObject.CompareTag("Armor"))
				{
					Vector3 normal = ((RaycastHit)(ref array[i])).normal;
					velocity = ___rb.velocity;
					Vector3 val = Vector3.Reflect(((Vector3)(ref velocity)).normalized, ((RaycastHit)(ref array[i])).normal);
					velocity = ___rb.velocity;
					___rb.velocity = val * ((Vector3)(ref velocity)).magnitude;
					PatchCerbThrow.orbBounces[instanceID]++;
					GameObject val2 = Object.Instantiate<GameObject>(Plugin.shockwave, ((Component)___rb).transform.position, Quaternion.identity);
					PhysicalShockwave component = val2.GetComponent<PhysicalShockwave>();
					component.damage = 25;
					component.speed = 75f;
					component.maxSize = 100f;
					component.enemy = true;
					component.enemyType = (EnemyType)0;
					((Component)component).transform.rotation = Quaternion.FromToRotation(((Component)component).transform.rotation * Vector3.up, normal);
					Explosion[] componentsInChildren = Object.Instantiate<GameObject>(Plugin.explosion, ((Component)___rb).transform.position, Quaternion.identity).GetComponentsInChildren<Explosion>();
					Explosion[] array2 = componentsInChildren;
					foreach (Explosion val3 in array2)
					{
						val3.maxSize *= 1.5f;
						val3.damage = Mathf.RoundToInt(__instance.damage);
						val3.enemy = true;
						val3.canHit = (AffectedSubjects)1;
						val3.enemyDamageMultiplier = 0f;
					}
					MonoSingleton<StainVoxelManager>.Instance.TryIgniteAt(((Component)__instance).transform.position, 3);
					break;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Projectile))]
	[HarmonyPatch("Start")]
	internal class PatchCerbOrbStart
	{
		private static void Postfix(Projectile __instance)
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			if (PatchCerbThrow.orbBounces.ContainsKey(instanceID))
			{
				__instance.ignoreExplosions = true;
			}
		}
	}
	[HarmonyPatch(typeof(Explosion))]
	[HarmonyPatch("Collide")]
	internal class PatchExplosionOrb
	{
		private static bool Prefix(Collider other, Explosion __instance)
		{
			if (!__instance.enemy)
			{
				return true;
			}
			Projectile component = ((Component)other).GetComponent<Projectile>();
			if ((Object)(object)component != (Object)null)
			{
				int instanceID = ((Object)component).GetInstanceID();
				if (PatchCerbThrow.orbBounces.ContainsKey(instanceID))
				{
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("Update")]
	internal class PatchCerbEnrage
	{
		private static void Postfix(StatueBoss __instance)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			if (__instance.enraged)
			{
				return;
			}
			int instanceID = ((Object)__instance).GetInstanceID();
			StatueBoss[] array = (StatueBoss[])(object)Resources.FindObjectsOfTypeAll(typeof(StatueBoss));
			StatueBoss[] array2 = array;
			foreach (StatueBoss val in array2)
			{
				int instanceID2 = ((Object)val).GetInstanceID();
				if (instanceID2 != instanceID)
				{
					FieldInfo field = typeof(StatueBoss).GetField("st", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
					Statue val2 = (Statue)field.GetValue(val);
					if ((Object)(object)val2 != (Object)null && val2.health < val2.originalHealth / 2f)
					{
						__instance.EnrageDelayed();
						break;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("StompHit")]
	internal class PatchCerbStomp
	{
		private static void Postfix(GameObject ___currentStompWave, AssetReference ___stompWave, StatueBoss __instance, EnemyIdentifier ___eid)
		{
			//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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			___currentStompWave = Object.Instantiate<GameObject>(AddressablesExtensions.ToAsset(___stompWave), ((Component)__instance).transform.position, Quaternion.identity);
			PhysicalShockwave component = ___currentStompWave.GetComponent<PhysicalShockwave>();
			((Component)component).transform.rotation = ((Component)__instance).transform.rotation;
			((Component)component).transform.Rotate(Vector3.forward * 90f, (Space)1);
			component.damage = 25;
			component.speed = 75f;
			AudioSource val = default(AudioSource);
			if (((Component)component).TryGetComponent<AudioSource>(ref val))
			{
				((Behaviour)val).enabled = false;
			}
			component.damage = Mathf.RoundToInt((float)component.damage * ___eid.totalDamageModifier);
			component.maxSize = 100f;
			component.enemy = true;
			component.enemyType = (EnemyType)0;
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("Tackle")]
	internal class PatchTackle
	{
		private static void Postfix(StatueBoss __instance, ref int ___extraTackles)
		{
			if (__instance.enraged)
			{
				___extraTackles++;
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("Dash")]
	internal class PatchDash
	{
		private static void Postfix(GameObject ___currentStompWave, AssetReference ___stompWave, StatueBoss __instance, EnemyIdentifier ___eid, ref int ___extraTackles)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			float num = 45f;
			num = ((!__instance.enraged) ? ((___extraTackles == 1) ? 45f : 135f) : ((___extraTackles != 0) ? ((___extraTackles == 2) ? 45f : 135f) : 0f));
			___currentStompWave = Object.Instantiate<GameObject>(AddressablesExtensions.ToAsset(___stompWave), ((Component)__instance).transform.position, Quaternion.identity);
			PhysicalShockwave component = ___currentStompWave.GetComponent<PhysicalShockwave>();
			((Component)component).transform.rotation = ((Component)__instance).transform.rotation;
			((Component)component).transform.Rotate(Vector3.forward * num, (Space)1);
			component.damage = 25;
			component.speed = 75f;
			component.damage = Mathf.RoundToInt((float)component.damage * ___eid.totalDamageModifier);
			component.maxSize = 100f;
			component.enemy = true;
			component.enemyType = (EnemyType)0;
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("StopDash")]
	internal class PatchStopDash
	{
		private static void Postfix(StatueBoss __instance, ref float ___realSpeedModifier)
		{
			if (((MonoBehaviour)__instance).IsInvoking("DelayedTackle"))
			{
				((MonoBehaviour)__instance).CancelInvoke("DelayedTackle");
				float num = 0.25f;
				if (!__instance.enraged && Random.value > 0.75f)
				{
					num += 0.5f;
				}
				((MonoBehaviour)__instance).Invoke("DelayedTackle", num / ___realSpeedModifier);
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("Update")]
	internal class PatchCerbCooldown
	{
		private static void Postfix(StatueBoss __instance)
		{
			int num = ((!__instance.enraged) ? 1 : 3);
			for (int i = 0; i < num; i++)
			{
				if (__instance.attackCheckCooldown > 0f)
				{
					__instance.attackCheckCooldown = Mathf.MoveTowards(__instance.attackCheckCooldown, 0f, Time.deltaTime);
				}
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss))]
	[HarmonyPatch("SetSpeed")]
	internal class PatchCerbAnim
	{
		private static void Postfix(StatueBoss __instance, Animator ___anim)
		{
			if (__instance.enraged)
			{
				___anim.speed *= 1.5f;
			}
			else
			{
				___anim.speed *= 1.2f;
			}
		}
	}
}