Decompiled source of Rocket Parry v1.0.0

Mod rocket.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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: AssemblyCompany("Mod rocket")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Mod rocket")]
[assembly: AssemblyTitle("Mod rocket")]
[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 RocketParryAndCoinFix
{
	[BepInPlugin("com.custom.rocketparry", "Rocket Parry & Coin Ignore", "1.0.9")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("com.custom.rocketparry");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Rocket Parry & Coin Ignore 1.0.9 loaded!");
		}
	}
	public static class ParriedRocketsTracker
	{
		public const string StyleIdRocketParry = "custom.rocketparry.direct";

		public const string StyleNameRocketParry = "ПРЯМОЙ НАВОДКОЙ";

		public const string StyleIdShieldBreak = "custom.rocketparry.gunnerstunned";

		public const string StyleNameShieldBreak = "НАВОДЧИК КОНТУЖЕН";

		public static readonly HashSet<int> ParriedRocketIds = new HashSet<int>();

		public static readonly HashSet<int> AwardedDirectHitIds = new HashSet<int>();

		public static readonly HashSet<int> HookHoldRocketIds = new HashSet<int>();

		public static readonly Dictionary<int, float> SavedRocketSpeeds = new Dictionary<int, float>();

		public static bool SuppressGuardBreak = false;

		public static void AwardGreenStyle(string styleId, string upperTitle, int points, EnemyIdentifier eid = null)
		{
			if (!((Object)(object)MonoSingleton<StyleHUD>.Instance == (Object)null))
			{
				Dictionary<string, string> value = Traverse.Create((object)MonoSingleton<StyleHUD>.Instance).Field("idNameDict").GetValue<Dictionary<string, string>>();
				if (value != null)
				{
					value[styleId] = "<color=#00FF00>" + upperTitle.ToUpper() + "</color>";
				}
				MonoSingleton<StyleHUD>.Instance.AddPoints(points, styleId, (GameObject)null, eid, -1, "", "");
			}
		}
	}
	[HarmonyPatch(typeof(StyleHUD))]
	public static class StyleHudPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("AddPoints")]
		public static bool AddPointsPrefix(string pointID)
		{
			if (ParriedRocketsTracker.SuppressGuardBreak && pointID == "ultrakill.guardbreak")
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Punch))]
	public static class PunchRocketParryPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("ActiveFrame")]
		public static void ActiveFramePostfix(Punch __instance, bool firstFrame)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (firstFrame && (int)__instance.type == 0 && !__instance.parriedSomething)
			{
				NewMovement instance = MonoSingleton<NewMovement>.Instance;
				if ((Object)(object)instance != (Object)null && (Object)(object)instance.ridingRocket != (Object)null)
				{
					bool __result = false;
					TryParryProjectilePrefix(__instance, ((Component)instance.ridingRocket).transform, canProjectileBoost: true, ref __result);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("TryParryProjectile")]
		public static bool TryParryProjectilePrefix(Punch __instance, Transform target, bool canProjectileBoost, ref bool __result)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: 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_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: 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)
			if ((int)__instance.type != 0 || (Object)(object)target == (Object)null)
			{
				return true;
			}
			Grenade val = ((Component)target).GetComponent<Grenade>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)target).GetComponentInParent<Grenade>();
			}
			if ((Object)(object)val == (Object)null || !val.rocket)
			{
				return true;
			}
			int instanceID = ((Object)val).GetInstanceID();
			if (ParriedRocketsTracker.ParriedRocketIds.Contains(instanceID))
			{
				return true;
			}
			bool playerRiding = val.playerRiding;
			bool flag = val.hooked || ParriedRocketsTracker.HookHoldRocketIds.Contains(instanceID);
			if (!val.enemy && !canProjectileBoost && !flag && !val.frozen && !playerRiding)
			{
				return true;
			}
			if (playerRiding)
			{
				val.PlayerRideEnd();
				if ((Object)(object)MonoSingleton<NewMovement>.Instance != (Object)null && (Object)(object)MonoSingleton<NewMovement>.Instance.rb != (Object)null)
				{
					Vector3 velocity = MonoSingleton<NewMovement>.Instance.rb.velocity;
					MonoSingleton<NewMovement>.Instance.rb.velocity = new Vector3(velocity.x, Mathf.Max(velocity.y, 14f), velocity.z);
				}
			}
			if (flag && (Object)(object)MonoSingleton<HookArm>.Instance != (Object)null)
			{
				MonoSingleton<HookArm>.Instance.Cancel();
			}
			val.hooked = false;
			ParriedRocketsTracker.HookHoldRocketIds.Remove(instanceID);
			ParriedRocketsTracker.ParriedRocketIds.Add(instanceID);
			Traverse.Create((object)__instance).Field("alreadyBoostedProjectile").SetValue((object)true);
			if (ParriedRocketsTracker.SavedRocketSpeeds.TryGetValue(instanceID, out var value) && value > 0f)
			{
				val.rocketSpeed = value;
				ParriedRocketsTracker.SavedRocketSpeeds.Remove(instanceID);
			}
			if (val.rocketSpeed <= 0f)
			{
				val.rocketSpeed = 60f;
			}
			Vector3 parryLookTarget = Punch.GetParryLookTarget();
			Vector3 val2;
			if (playerRiding && (Object)(object)MonoSingleton<CameraController>.Instance != (Object)null)
			{
				Vector3 defaultPos = MonoSingleton<CameraController>.Instance.GetDefaultPos();
				val2 = parryLookTarget - defaultPos;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				((Component)val).transform.position = defaultPos + normalized * 1.3f;
			}
			val2 = parryLookTarget - ((Component)val).transform.position;
			Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
			((Component)val).transform.forward = normalized2;
			if (val.enemy)
			{
				val.enemy = false;
				val.ignoreEnemyType.Clear();
				__instance.Parry(false, (EnemyIdentifier)null, "");
			}
			else
			{
				__instance.anim.Play("Hook", 0, 0.065f);
				MonoSingleton<TimeController>.Instance.ParryFlash();
			}
			Grenade obj = val;
			obj.rocketSpeed *= 1.5f;
			if ((Object)(object)val.rb != (Object)null)
			{
				val.rb.isKinematic = false;
				val.rb.detectCollisions = true;
				val.rb.velocity = normalized2 * val.rocketSpeed;
			}
			val.levelledUp = true;
			GameObject value2 = Traverse.Create((object)val).Field("levelUpEffect").GetValue<GameObject>();
			if ((Object)(object)value2 != (Object)null)
			{
				value2.SetActive(true);
			}
			__instance.hitSomething = true;
			__instance.parriedSomething = true;
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Grenade))]
	public static class GrenadePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("FixedUpdate")]
		public static void FixedUpdatePostfix(Grenade __instance)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.rocket || (Object)(object)__instance.rb == (Object)null || __instance.playerRiding)
			{
				return;
			}
			int instanceID = ((Object)__instance).GetInstanceID();
			if (ParriedRocketsTracker.HookHoldRocketIds.Contains(instanceID))
			{
				__instance.rb.isKinematic = false;
				__instance.rb.velocity = Vector3.zero;
				return;
			}
			bool flag = ParriedRocketsTracker.ParriedRocketIds.Contains(instanceID);
			if (__instance.frozen && flag)
			{
				__instance.rb.isKinematic = false;
				__instance.rb.velocity = ((Component)__instance).transform.forward * __instance.rocketSpeed;
			}
			if (!flag)
			{
				return;
			}
			Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, 0.85f, 16384, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				if (!((Object)(object)array[i] == (Object)null))
				{
					Grenade val = ((Component)array[i]).GetComponent<Grenade>() ?? ((Component)array[i]).GetComponentInParent<Grenade>();
					if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)__instance && val.rocket)
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
						__instance.Explode(true, false, true, 1.3f, true, (GameObject)null, false);
						break;
					}
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Explode")]
		public static bool ExplodePrefix(Grenade __instance, ref bool harmless, ref bool super, bool ultrabooster, bool fup)
		{
			if (!__instance.rocket)
			{
				return true;
			}
			int instanceID = ((Object)__instance).GetInstanceID();
			if (fup && !ParriedRocketsTracker.ParriedRocketIds.Contains(instanceID) && !ParriedRocketsTracker.HookHoldRocketIds.Contains(instanceID))
			{
				ParriedRocketsTracker.HookHoldRocketIds.Add(instanceID);
				ParriedRocketsTracker.SavedRocketSpeeds[instanceID] = ((__instance.rocketSpeed > 0f) ? __instance.rocketSpeed : 60f);
				if ((Object)(object)MonoSingleton<HookArm>.Instance != (Object)null)
				{
					MonoSingleton<HookArm>.Instance.Cancel();
				}
				__instance.hooked = false;
				((MonoBehaviour)__instance).StartCoroutine(HoldRocketForParryRoutine(__instance));
				return false;
			}
			if (ParriedRocketsTracker.ParriedRocketIds.Contains(instanceID) && !ultrabooster)
			{
				harmless = false;
				super = true;
			}
			return true;
		}

		private static IEnumerator HoldRocketForParryRoutine(Grenade grenade)
		{
			if ((Object)(object)grenade.rb != (Object)null)
			{
				grenade.rb.isKinematic = false;
				grenade.rb.velocity = Vector3.zero;
			}
			if ((Object)(object)MonoSingleton<CameraController>.Instance != (Object)null)
			{
				Transform cam = ((Component)MonoSingleton<CameraController>.Instance).transform;
				((Component)grenade).transform.position = cam.position + cam.forward * 1.4f;
			}
			yield return (object)new WaitForSeconds(0.4f);
			if (!((Object)(object)grenade != (Object)null))
			{
				yield break;
			}
			int rocketId = ((Object)grenade).GetInstanceID();
			if (!ParriedRocketsTracker.ParriedRocketIds.Contains(rocketId))
			{
				ParriedRocketsTracker.HookHoldRocketIds.Remove(rocketId);
				if (ParriedRocketsTracker.SavedRocketSpeeds.TryGetValue(rocketId, out var savedSpeed) && savedSpeed > 0f)
				{
					grenade.rocketSpeed = savedSpeed;
					ParriedRocketsTracker.SavedRocketSpeeds.Remove(rocketId);
				}
				grenade.Explode(false, false, false, 1f, false, (GameObject)null, false);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Collision", new Type[]
		{
			typeof(Collider),
			typeof(Vector3)
		})]
		public static bool CollisionPrefix(Grenade __instance, Collider other)
		{
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Invalid comparison between Unknown and I4
			if (!__instance.rocket || (Object)(object)other == (Object)null)
			{
				return true;
			}
			int instanceID = ((Object)__instance).GetInstanceID();
			if (ParriedRocketsTracker.HookHoldRocketIds.Contains(instanceID))
			{
				return false;
			}
			if (((Component)other).CompareTag("Coin") || (Object)(object)((Component)other).GetComponent<Coin>() != (Object)null)
			{
				Coin component = ((Component)other).GetComponent<Coin>();
				if ((Object)(object)component == (Object)null || !component.doubled)
				{
					CapsuleCollider value = Traverse.Create((object)__instance).Field("col").GetValue<CapsuleCollider>();
					if ((Object)(object)value != (Object)null)
					{
						Physics.IgnoreCollision((Collider)(object)value, other, true);
					}
					return false;
				}
			}
			if (ParriedRocketsTracker.ParriedRocketIds.Contains(instanceID))
			{
				EnemyIdentifier val = null;
				EnemyIdentifierIdentifier val2 = (Object.op_Implicit((Object)(object)other.attachedRigidbody) ? ((Component)other.attachedRigidbody).GetComponent<EnemyIdentifierIdentifier>() : ((Component)other).GetComponent<EnemyIdentifierIdentifier>());
				val = ((!((Object)(object)val2 != (Object)null) || !((Object)(object)val2.eid != (Object)null)) ? ((Component)other).GetComponentInParent<EnemyIdentifier>() : val2.eid);
				if ((Object)(object)val != (Object)null && !val.dead)
				{
					if (!ParriedRocketsTracker.AwardedDirectHitIds.Contains(instanceID))
					{
						ParriedRocketsTracker.AwardedDirectHitIds.Add(instanceID);
						ParriedRocketsTracker.AwardGreenStyle("custom.rocketparry.direct", "ПРЯМОЙ НАВОДКОЙ", 100, val);
					}
					if ((int)val.enemyType == 33)
					{
						Gutterman component2 = ((Component)val).GetComponent<Gutterman>();
						if ((Object)(object)component2 != (Object)null)
						{
							Traverse val3 = Traverse.Create((object)component2);
							if (val3.Field("hasShield").GetValue<bool>())
							{
								ParriedRocketsTracker.SuppressGuardBreak = true;
								try
								{
									val3.Method("ShieldBreak", new object[2] { true, true }).GetValue();
								}
								finally
								{
									ParriedRocketsTracker.SuppressGuardBreak = false;
								}
								ParriedRocketsTracker.AwardGreenStyle("custom.rocketparry.gunnerstunned", "НАВОДЧИК КОНТУЖЕН", 250, val);
							}
						}
					}
				}
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnDestroy")]
		public static void OnDestroyPostfix(Grenade __instance)
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			ParriedRocketsTracker.ParriedRocketIds.Remove(instanceID);
			ParriedRocketsTracker.AwardedDirectHitIds.Remove(instanceID);
			ParriedRocketsTracker.HookHoldRocketIds.Remove(instanceID);
			ParriedRocketsTracker.SavedRocketSpeeds.Remove(instanceID);
		}
	}
}