Decompiled source of HackerX v1.0.0

HackerX.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using BepInEx;
using DM;
using HarmonyLib;
using InControl;
using Landfall.MonoBatch;
using Landfall.TABC;
using Landfall.TABS;
using Landfall.TABS.AI;
using Landfall.TABS.AI.Components;
using Landfall.TABS.AI.Components.Tags;
using Landfall.TABS.AI.Systems;
using Landfall.TABS.GameMode;
using Landfall.TABS.GameState;
using Landfall.TABS.Services;
using Landfall.TABS.UI.BattleUI;
using Landfall.TABS.UnitPlacement;
using Landfall.TABS.WinConditions;
using Landfall.TABS_Input;
using TFBGames;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[BepInPlugin("HackerX.InvulnerableUnit", "HackerX", "1.0.0")]
public sealed class HackerXMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Unit), "Awake")]
	[HarmonyPriority(800)]
	private static class UnitAwakePatch
	{
		private static void Postfix(Unit __instance)
		{
			if (Active && !((Object)(object)__instance == (Object)null) && (Object)(object)__instance.unitBlueprint == (Object)(object)Blueprint)
			{
				AttachProtection(__instance);
			}
		}
	}

	private static class HackerXPatches
	{
		[HarmonyPatch]
		[HarmonyPriority(800)]
		private static class SpawnPatch
		{
			private static MethodBase TargetMethod()
			{
				return (from m in typeof(UnitBlueprint).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where m.Name == "Spawn"
					where m.GetParameters().Length == 9
					where m.GetParameters()[3].ParameterType == typeof(Unit).MakeByRefType()
					select m).Single();
			}

			private static bool Prefix(UnitBlueprint __instance, Vector3 posistion, Team team, ref Unit __3)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || !BattleActive || !IsBattleState())
				{
					return true;
				}
				if (!HackerXPermanentRegistry.ShouldBlock(__instance, team, posistion))
				{
					return true;
				}
				__3 = null;
				return false;
			}

			private static void Postfix(UnitBlueprint __instance, ref Unit __3)
			{
				if (!Active || (Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Blueprint || (Object)(object)__3 == (Object)null)
				{
					return;
				}
				Unit val = FindProtectedUnit();
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)__3)
				{
					InternalDestroy = true;
					try
					{
						Object.Destroy((Object)(object)((Component)__3).gameObject);
					}
					catch
					{
					}
					finally
					{
						InternalDestroy = false;
					}
					__3 = val;
				}
				else
				{
					AttachProtection(__3);
				}
			}
		}

		[HarmonyPatch]
		[HarmonyPriority(800)]
		private static class SpawnSimplePatch
		{
			private static MethodBase TargetMethod()
			{
				return (from m in typeof(UnitBlueprint).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where m.Name == "Spawn"
					where m.GetParameters().Length == 5
					where m.GetParameters()[0].ParameterType == typeof(Vector3)
					where m.GetParameters()[1].ParameterType == typeof(Quaternion)
					where m.GetParameters()[2].ParameterType == typeof(Team)
					select m).Single();
			}

			private static bool Prefix(UnitBlueprint __instance, Vector3 posistion, Team team, ref GameObject[] __result)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || !BattleActive || !IsBattleState())
				{
					return true;
				}
				if (!HackerXPermanentRegistry.ShouldBlock(__instance, team, posistion))
				{
					return true;
				}
				__result = Array.Empty<GameObject>();
				return false;
			}

			private static void Postfix(UnitBlueprint __instance, GameObject[] __result)
			{
				if (!Active || (Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Blueprint || __result == null)
				{
					return;
				}
				foreach (GameObject val in __result)
				{
					if (!((Object)(object)val == (Object)null))
					{
						Unit componentInChildren = val.GetComponentInChildren<Unit>(true);
						if ((Object)(object)componentInChildren != (Object)null)
						{
							AttachProtection(componentInChildren);
							break;
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(UnitPlacementBrush), "PlaceUnitInternal")]
		[HarmonyPriority(800)]
		private static class PlaceUnitInternalPatch
		{
			private static bool Prefix(UnitBlueprint blueprint)
			{
				if (!Active || (Object)(object)blueprint == (Object)null || (Object)(object)blueprint != (Object)(object)Blueprint)
				{
					return true;
				}
				return (Object)(object)FindProtectedUnit() == (Object)null;
			}
		}

		[HarmonyPatch(typeof(BrushBehaviourBase), "Place")]
		[HarmonyPriority(800)]
		private static class BrushPlacePatch
		{
			private static bool Prefix(UnitBlueprint unit)
			{
				if (!Active || (Object)(object)unit == (Object)null || (Object)(object)unit != (Object)(object)Blueprint)
				{
					return true;
				}
				return (Object)(object)FindProtectedUnit() == (Object)null;
			}
		}

		[HarmonyPatch(typeof(TeamSystem), "RemoveEntity")]
		[HarmonyPriority(800)]
		private static class TeamRemovePatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(HealthHandler), "Update")]
		[HarmonyPriority(800)]
		private static class HealthUpdatePatch
		{
			private static void Protect(Unit u)
			{
				if (!((Object)(object)u == (Object)null) && Object.op_Implicit((Object)(object)u) && !((Object)(object)u.data == (Object)null))
				{
					HackerXGuard component = ((Component)u).GetComponent<HackerXGuard>();
					if ((Object)(object)component != (Object)null)
					{
						component.PreventVoidDeath(u);
					}
					if (u.data.maxHealth < 1000000f)
					{
						u.data.maxHealth = 1000000f;
					}
					if (u.data.health < u.data.maxHealth)
					{
						u.data.health = u.data.maxHealth;
					}
					if (u.data.Dead)
					{
						u.data.Dead = false;
					}
				}
			}

			private static void Prefix(HealthHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
					if (Verify(componentInParent))
					{
						Protect(componentInParent);
					}
				}
			}

			private static void Postfix(HealthHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
					if (Verify(componentInParent))
					{
						Protect(componentInParent);
					}
				}
			}
		}

		[HarmonyPatch(typeof(HealthHandler), "Update")]
		[HarmonyPriority(800)]
		private static class PermanentDeathHealthUpdatePatch
		{
			private static void Postfix(HealthHandler __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (HackerXGuard.IsPermanentDeathMarked(componentInParent))
				{
					try
					{
						__instance.willBeRewived = false;
					}
					catch
					{
					}
					if ((Object)(object)componentInParent.data != (Object)null)
					{
						componentInParent.data.hasBeenRevived = true;
						componentInParent.data.health = 0f;
						componentInParent.data.Dead = true;
					}
				}
			}
		}

		[HarmonyPatch(typeof(DataHandler), "TouchGround")]
		[HarmonyPriority(800)]
		private static class TouchGroundPatch
		{
			private static void Postfix(DataHandler __instance)
			{
				Unit val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (Active && Verify(val))
				{
					HackerXGuard component = ((Component)val).GetComponent<HackerXGuard>();
					if ((Object)(object)component != (Object)null)
					{
						component.RememberGroundedPosition();
					}
				}
			}
		}

		[HarmonyPatch(typeof(BaseGameMode), "UpdateForEnterExitBattle")]
		[HarmonyPriority(0)]
		private static class TabBattleExitPatch
		{
			private static void Postfix(BaseGameMode __instance, PlayerActions playerActions)
			{
				if (!Active || __instance == null || playerActions == null)
				{
					return;
				}
				try
				{
					if (((OneAxisInputControl)playerActions.m_enterExitBattle).WasReleased && !IsBattleState())
					{
						BattleActive = false;
						HackerXPermanentRegistry.Clear();
					}
				}
				catch
				{
				}
			}
		}

		[HarmonyPatch(typeof(BaseGameMode), "OnEnterBattleState")]
		[HarmonyPriority(800)]
		private static class BattleEnterPatch
		{
			private static void Postfix()
			{
				if (Active)
				{
					BattleActive = true;
					OnBattleStarted();
					HackerXGuard.InstallProtectedCollisionShield();
				}
			}
		}

		[HarmonyPatch(typeof(GameStateManager), "EnterBattleState")]
		[HarmonyPriority(800)]
		private static class GameStateBattlePatch
		{
			private static void Postfix()
			{
				if (Active)
				{
					BattleActive = true;
					HackerXPermanentRegistry.Clear();
				}
			}
		}

		[HarmonyPatch(typeof(GameStateManager), "EnterPlacementState")]
		[HarmonyPriority(800)]
		private static class GameStatePlacementPatch
		{
			private static bool Prefix()
			{
				CleanupPlacementState();
				return true;
			}
		}

		private static class VictoryControlPatch
		{
			private static bool Prefix()
			{
				return !BattleControlProtected();
			}
		}

		private static class MatchOverSetterPatch
		{
			private static bool Prefix(ref bool __0)
			{
				if (BattleControlProtected())
				{
					__0 = false;
					return false;
				}
				return true;
			}
		}

		private static class BattleEndObservationPatch
		{
			private static void Postfix()
			{
				if (Active && !IsBattleState())
				{
					BattleActive = false;
					HackerXPermanentRegistry.Clear();
				}
			}
		}

		private static class TimeStatePatch
		{
			private static bool Prefix()
			{
				return !BattleControlProtected();
			}
		}

		private static class UnitStartPatch
		{
			private static void Postfix(Unit __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null) && (Object)(object)__instance.unitBlueprint == (Object)(object)Blueprint)
				{
					AttachProtection(__instance);
				}
			}
		}

		private static class BlueprintSetValuesPatch
		{
			private static bool Prefix(UnitBlueprint __instance)
			{
				return (Object)(object)__instance != (Object)(object)HackerXAccess.GetBlueprint();
			}
		}

		private static class BlueprintUnitBasePatch
		{
			private static void Prefix(UnitBlueprint __instance, ref GameObject __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint() && (Object)(object)ProtectedUnitBase != (Object)null)
				{
					__0 = ProtectedUnitBase;
				}
			}
		}

		private static class BlueprintFistPatch
		{
			private static void Prefix(UnitBlueprint __instance, ref GameObject __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint() && (Object)(object)ProtectedFistRef != (Object)null)
				{
					__0 = ProtectedFistRef;
				}
			}
		}

		private static class BlueprintWeaponPatch
		{
			private static void Prefix(UnitBlueprint __instance, ref GameObject __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint())
				{
					__0 = null;
				}
			}
		}

		private static class BlueprintPropsPatch
		{
			private static void Prefix(UnitBlueprint __instance, ref GameObject[] __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint())
				{
					__0 = null;
				}
			}
		}

		private static class BlueprintProjectilePatch
		{
			private static void Prefix(UnitBlueprint __instance, ref ProjectileEntity __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint())
				{
					__0 = null;
				}
			}
		}

		private static class BlueprintBoolPatch
		{
			private static void Prefix(UnitBlueprint __instance, ref bool __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint())
				{
					__0 = true;
				}
			}
		}

		private static class BlueprintIntPatch
		{
			private static void Prefix(UnitBlueprint __instance, ref int __0)
			{
				if ((Object)(object)__instance == (Object)(object)HackerXAccess.GetBlueprint())
				{
					__0 = ModId;
				}
			}
		}

		[HarmonyPatch(typeof(NetworkUnitsManager), "OnUnitDied")]
		[HarmonyPriority(800)]
		private static class NetworkDiedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(NetworkUnitsManager), "OnNetworkUnitDetached")]
		[HarmonyPriority(800)]
		private static class NetworkDetachedPatch
		{
			private static bool Prefix(NetworkUnit networkUnit)
			{
				if (!Active || (Object)(object)networkUnit == (Object)null)
				{
					return true;
				}
				return !Verify(networkUnit.Unit);
			}
		}

		private static class NetworkDestroyedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		private static class NetworkRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		private static class NetworkDestroyAllPatch
		{
			private static bool Prefix()
			{
				return !BattleControlProtected();
			}
		}

		private static class NetworkRemoveErrorPatch
		{
			private static bool Prefix()
			{
				return !BattleControlProtected();
			}
		}

		[HarmonyPatch(typeof(DataHandler), "BatchedUpdate")]
		[HarmonyPriority(800)]
		private static class DataBatchedUpdatePatch
		{
			private static void Apply(DataHandler data)
			{
				if (!((Object)(object)data == (Object)null) && !data.Dead)
				{
					if (data.canFall)
					{
						data.canFall = false;
					}
					if (data.fallTime != -1f)
					{
						data.fallTime = -1f;
					}
					if (data.ragdollControl != 1f)
					{
						data.ragdollControl = 1f;
					}
					if (data.muscleControl != 1f)
					{
						data.muscleControl = 1f;
					}
					if (data.maxHealth < 1000000f)
					{
						data.maxHealth = 1000000f;
					}
					if (data.health < data.maxHealth)
					{
						data.health = data.maxHealth;
					}
				}
			}

			private static void Prefix(DataHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null) && Verify(((Component)__instance).GetComponentInParent<Unit>()))
				{
					Apply(__instance);
				}
			}

			private static void Postfix(DataHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null) && Verify(((Component)__instance).GetComponentInParent<Unit>()))
				{
					Apply(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(DataHandler), "BatchedFixedUpdate")]
		[HarmonyPriority(800)]
		private static class DataBatchedFixedUpdatePatch
		{
			private static void Apply(DataHandler data)
			{
				if (!((Object)(object)data == (Object)null) && !data.Dead)
				{
					if (data.canFall)
					{
						data.canFall = false;
					}
					if (data.fallTime != -1f)
					{
						data.fallTime = -1f;
					}
					if (data.ragdollControl != 1f)
					{
						data.ragdollControl = 1f;
					}
					if (data.muscleControl != 1f)
					{
						data.muscleControl = 1f;
					}
				}
			}

			private static void Prefix(DataHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null) && Verify(((Component)__instance).GetComponentInParent<Unit>()))
				{
					Apply(__instance);
				}
			}

			private static void Postfix(DataHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null) && Verify(((Component)__instance).GetComponentInParent<Unit>()))
				{
					Apply(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(DataHandler), "TouchGround")]
		private static class GroundCheckerCollisionPatch
		{
			private static void Postfix(GroundChecker __instance, Collision collision)
			{
				//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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance == (Object)null || collision == null || (Object)(object)collision.collider == (Object)null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!Active || !Verify(componentInParent) || (Object)(object)componentInParent.data == (Object)null || componentInParent.data.Dead)
				{
					return;
				}
				ContactPoint contact = collision.GetContact(0);
				if (!(Vector3.Angle(((ContactPoint)(ref contact)).normal, Vector3.up) > 80f))
				{
					componentInParent.data.TouchGround(((ContactPoint)(ref contact)).point, ((ContactPoint)(ref contact)).normal, collision.rigidbody);
					HackerXGuard component = ((Component)componentInParent).GetComponent<HackerXGuard>();
					if ((Object)(object)component != (Object)null)
					{
						component.RememberGroundedPosition();
					}
				}
			}
		}

		[HarmonyPatch(typeof(Balance), "Fall")]
		[HarmonyPriority(800)]
		private static class BalanceFallPatch
		{
			private static bool Prefix(Balance __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!Verify(componentInParent))
				{
					return true;
				}
				DataHandler data = componentInParent.data;
				if ((Object)(object)data != (Object)null && !data.Dead)
				{
					data.canFall = false;
					data.fallTime = -1f;
					data.ragdollControl = 1f;
					data.muscleControl = 1f;
					data.cantFallForSeconds = Mathf.Max(data.cantFallForSeconds, 0.18f);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(MonoBatchService), "OnFixedUpdate")]
		[HarmonyPriority(0)]
		private static class MonoBatchFixedUpdatePatch
		{
			private static void Postfix()
			{
				if (Active)
				{
					HackerXGuard.StabilizeProtectedPhysics();
				}
			}
		}

		[HarmonyPatch(typeof(StunEffect), "DoEffect")]
		[HarmonyPriority(800)]
		private static class StunDoEffectPatch
		{
			private static bool Prefix(StunEffect __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !Verify(((Component)__instance).GetComponentInParent<Unit>());
			}
		}

		[HarmonyPatch(typeof(GravityField), "OnTriggerEnter")]
		[HarmonyPriority(800)]
		private static class GravityFieldEnterPatch
		{
			private static bool Prefix(GravityField __instance, Collider other)
			{
				if (!Active || (Object)(object)other == (Object)null)
				{
					return true;
				}
				return !Verify(((Component)other).GetComponentInParent<Unit>());
			}
		}

		[HarmonyPatch(typeof(GravityField), "OnTriggerExit")]
		[HarmonyPriority(800)]
		private static class GravityFieldExitPatch
		{
			private static bool Prefix(GravityField __instance, Collider other)
			{
				if (!Active || (Object)(object)other == (Object)null)
				{
					return true;
				}
				return !Verify(((Component)other).GetComponentInParent<Unit>());
			}
		}

		[HarmonyPatch(typeof(WeaponHandler), "Start")]
		[HarmonyPriority(800)]
		private static class WeaponStartPatch
		{
			private static void Postfix(WeaponHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
					if (Verify(componentInParent))
					{
						HackerXGuard.EnsureNativeFists(componentInParent);
						HackerXGuard.InstallProtectedCollisionShield();
					}
				}
			}
		}

		[HarmonyPatch(typeof(WeaponHandler), "UseHands")]
		[HarmonyPriority(800)]
		private static class UseHandsPatch
		{
			private static void Postfix(WeaponHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
					if (Verify(componentInParent))
					{
						HackerXGuard.TuneNativeFists(componentInParent);
						HackerXGuard.InstallProtectedCollisionShield();
					}
				}
			}
		}

		[HarmonyPatch(typeof(WeaponHandler), "BatchedUpdate")]
		[HarmonyPriority(800)]
		private static class WeaponUpdatePatch
		{
			private static void Postfix(WeaponHandler __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
					if (Verify(componentInParent))
					{
						HackerXGuard.EnsureNativeFists(componentInParent);
					}
				}
			}
		}

		[HarmonyPatch(typeof(MeleeWeapon), "Attack")]
		[HarmonyPriority(800)]
		private static class MeleeAttackPatch
		{
			private static void Postfix(MeleeWeapon __instance)
			{
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || (Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).GetComponent<HackerXFistMarker>() == (Object)null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!Verify(componentInParent))
				{
					return;
				}
				HackerXGuard component = ((Component)componentInParent).GetComponent<HackerXGuard>();
				if (!((Object)(object)component == (Object)null))
				{
					component.BraceAfterPunch();
					Unit internalTarget = component.GetInternalTarget();
					if (!((Object)(object)internalTarget == (Object)null) && !((Object)(object)internalTarget == (Object)(object)componentInParent) && !((Object)(object)internalTarget.data == (Object)null) && !internalTarget.data.Dead && internalTarget.Team != componentInParent.Team)
					{
						HackerXGuard.ReturnTargetToEssentialForm(internalTarget);
						HackerXGuard.KillPermanently(internalTarget, componentInParent);
					}
				}
			}
		}

		[HarmonyPatch(typeof(CollisionWeapon), "OnCollisionEnter")]
		[HarmonyPriority(800)]
		private static class HackerCollisionEnterPatch
		{
			private static void Prefix(CollisionWeapon __instance, Collision collision)
			{
				if (!Active || (Object)(object)__instance == (Object)null || collision == null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!((Object)(object)componentInParent == (Object)null) && Verify(componentInParent))
				{
					Collider collider = collision.collider;
					if ((Object)(object)collider != (Object)null)
					{
						HackerXGuard.IgnoreColliderPairIfNonTerrain(componentInParent, collider);
					}
				}
			}
		}

		[HarmonyPatch(typeof(CollisionWeapon), "OnCollisionStay")]
		[HarmonyPriority(800)]
		private static class HackerCollisionStayPatch
		{
			private static void Prefix(CollisionWeapon __instance, Collision collision)
			{
				if (!Active || (Object)(object)__instance == (Object)null || collision == null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!((Object)(object)componentInParent == (Object)null) && Verify(componentInParent))
				{
					Collider collider = collision.collider;
					if ((Object)(object)collider != (Object)null)
					{
						HackerXGuard.IgnoreColliderPairIfNonTerrain(componentInParent, collider);
					}
				}
			}
		}

		[HarmonyPatch(typeof(ProjectileHit), "Hit")]
		[HarmonyPriority(800)]
		private static class HackerProjectileContactPatch
		{
			private static void Prefix(ProjectileHit __instance, RaycastHit sentHit)
			{
				if (Active && !((Object)(object)__instance == (Object)null) && !((Object)(object)((RaycastHit)(ref sentHit)).collider == (Object)null))
				{
					Unit val = HackerXGuard.FindProtectedForCollision();
					if (!((Object)(object)val == (Object)null))
					{
						HackerXGuard.IgnoreColliderPairIfNonTerrain(val, ((RaycastHit)(ref sentHit)).collider);
					}
				}
			}
		}

		[HarmonyPatch(typeof(CollisionWeapon), "OnCollisionEnter")]
		[HarmonyPriority(800)]
		private static class FistCollisionPatch
		{
			private static void Postfix(CollisionWeapon __instance, Collision collision)
			{
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: 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_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: 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_023a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0207: Unknown result type (might be due to invalid IL or missing references)
				//IL_020e: Unknown result type (might be due to invalid IL or missing references)
				//IL_021b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0220: Unknown result type (might be due to invalid IL or missing references)
				//IL_0222: Unknown result type (might be due to invalid IL or missing references)
				//IL_022c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || (Object)(object)__instance == (Object)null || collision == null || (Object)(object)((Component)__instance).GetComponent<HackerXFistMarker>() == (Object)null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!Verify(componentInParent))
				{
					return;
				}
				Unit val = (((Object)(object)collision.rigidbody != (Object)null) ? ((Component)collision.rigidbody).GetComponentInParent<Unit>() : (((Object)(object)collision.collider != (Object)null) ? ((Component)collision.collider).GetComponentInParent<Unit>() : null));
				if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)componentInParent || (Object)(object)val.data == (Object)null || val.data.Dead || val.Team == componentInParent.Team)
				{
					return;
				}
				HackerXGuard component = ((Component)componentInParent).GetComponent<HackerXGuard>();
				if ((Object)(object)component != (Object)null)
				{
					component.BraceAfterPunch();
				}
				HackerXGuard.ReturnTargetToEssentialForm(val);
				HackerXGuard.KillPermanently(val, componentInParent);
				ContactPoint contact = collision.GetContact(0);
				Vector3 val2 = ((Component)val).transform.root.position - ((Component)componentInParent).transform.root.position;
				Vector3 val3;
				if (((Vector3)(ref val2)).sqrMagnitude < 0.001f)
				{
					val3 = ((ContactPoint)(ref contact)).normal;
					val2 = ((((Vector3)(ref val3)).sqrMagnitude > 0.001f) ? (-((ContactPoint)(ref contact)).normal) : ((Component)componentInParent).transform.forward);
				}
				((Vector3)(ref val2)).Normalize();
				Rigidbody val4 = (((Object)(object)val.data.mainRig != (Object)null) ? val.data.mainRig : collision.rigidbody);
				if ((Object)(object)val4 != (Object)null)
				{
					float num = ((Component)val).transform.root.position.y - ((Component)componentInParent).transform.root.position.y;
					val3 = Vector3.ProjectOnPlane(val2, Vector3.up);
					Vector3 val5 = ((Vector3)(ref val3)).normalized;
					if (((Vector3)(ref val5)).sqrMagnitude < 0.001f)
					{
						val5 = ((Component)componentInParent).transform.forward;
					}
					val5 += Vector3.up * Mathf.Clamp(num * 0.22f, -0.35f, 0.35f);
					((Vector3)(ref val5)).Normalize();
					val4.AddForce(val5 * 1800f, (ForceMode)1);
					val4.AddTorque(Vector3.Cross(Vector3.up, val5) * 350f, (ForceMode)1);
				}
				HackerXGuard.DeformTarget(val, ((ContactPoint)(ref contact)).point, 0.22f, 0.32f);
			}
		}

		[HarmonyPatch(typeof(ProjectileHit), "Hit")]
		[HarmonyPriority(800)]
		private static class ProjectileHitPatch
		{
			private static bool Prefix(ProjectileHit __instance, ref RaycastHit sentHit)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				Unit val = (((Object)(object)((RaycastHit)(ref sentHit)).transform != (Object)null) ? ((Component)((RaycastHit)(ref sentHit)).transform.root).GetComponent<Unit>() : null);
				if ((Object)(object)val != (Object)null && Verify(val))
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ProjectileHit), "Start")]
		[HarmonyPriority(800)]
		private static class ProjectileStartPatch
		{
			private static void Postfix(ProjectileHit __instance)
			{
				GameObject val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).gameObject : null);
				HackerXGuard.IgnoreProjectileCollisions(val);
				if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<HackerXGuidedRagdollProjectile>() != (Object)null)
				{
					HackerXGuard.SuppressNativeProjectileVisual(val);
				}
			}
		}

		[HarmonyPatch(typeof(ProjectileHit), "Reset")]
		[HarmonyPriority(800)]
		private static class ProjectileResetPatch
		{
			private static void Postfix(ProjectileHit __instance)
			{
				GameObject val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).gameObject : null);
				HackerXGuard.IgnoreProjectileCollisions(val);
				if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<HackerXGuidedRagdollProjectile>() != (Object)null)
				{
					HackerXGuard.SuppressNativeProjectileVisual(val);
				}
			}
		}

		[HarmonyPatch(typeof(PooledProjectile), "Reset")]
		[HarmonyPriority(800)]
		private static class PooledProjectileResetPatch
		{
			private static void Postfix(PooledProjectile __instance)
			{
				GameObject val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).gameObject : null);
				HackerXGuard.IgnoreProjectileCollisions(val);
				if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<HackerXGuidedRagdollProjectile>() != (Object)null)
				{
					HackerXGuard.SuppressNativeProjectileVisual(val);
				}
			}
		}

		[HarmonyPatch(typeof(Projectile), "OnEnable")]
		[HarmonyPriority(800)]
		private static class NetworkProjectileEnablePatch
		{
			private static void Postfix(Projectile __instance)
			{
				GameObject val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).gameObject : null);
				HackerXGuard.IgnoreProjectileCollisions(val);
				if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<HackerXGuidedRagdollProjectile>() != (Object)null)
				{
					HackerXGuard.SuppressNativeProjectileVisual(val);
				}
			}
		}

		private static class NativeRangedProjectilePatch
		{
			private static void SimplePostfix(GameObject __result)
			{
				if (Active)
				{
					_ = (Object)(object)__result == (Object)null;
				}
			}

			private static void GameObjectPostfix(GameObject __result, GameObject prefab, Vector3 position, Quaternion rotation, Unit unit, byte weaponIndex, Vector3 spawnDirection, Vector3 directionToTarget, Rigidbody targetRigidbody, Vector3 shootPositionForward, bool isSpawnedFromPrefabId, byte? randomSeed)
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				if (Active && !((Object)(object)__result == (Object)null) && !((Object)(object)unit == (Object)null) && Verify(unit))
				{
					Vector3 spawnDirection2 = ((((Vector3)(ref directionToTarget)).sqrMagnitude > 0.001f) ? directionToTarget : ((((Vector3)(ref spawnDirection)).sqrMagnitude > 0.001f) ? spawnDirection : shootPositionForward));
					HackerXGuard.InitializeNativeGuidedProjectile(__result, unit, targetRigidbody, spawnDirection2, shootPositionForward);
				}
			}

			private static void IndexPostfix(Projectile __result, int prefabIndex, Vector3 position, Quaternion rotation, Unit unit, byte weaponIndex, Vector3 spawnDirection, Vector3 directionToTarget, Rigidbody targetRigidbody, Vector3 shootPositionForward, byte? randomSeed)
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				if (Active && !((Object)(object)__result == (Object)null) && !((Object)(object)unit == (Object)null) && Verify(unit))
				{
					Vector3 spawnDirection2 = ((((Vector3)(ref directionToTarget)).sqrMagnitude > 0.001f) ? directionToTarget : ((((Vector3)(ref spawnDirection)).sqrMagnitude > 0.001f) ? spawnDirection : shootPositionForward));
					HackerXGuard.InitializeNativeGuidedProjectile(((Component)__result).gameObject, unit, targetRigidbody, spawnDirection2, shootPositionForward);
				}
			}
		}

		[HarmonyPatch(typeof(RangeWeapon), "Attack")]
		[HarmonyPriority(800)]
		private static class RangeWeaponAttackPatch
		{
			private static void Prefix(RangeWeapon __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (Verify(componentInParent))
				{
					EnsureNativeRagdollProjectilePrefab();
					if ((Object)(object)NativeProjectilePrefab != (Object)null)
					{
						__instance.ObjectToSpawn = NativeProjectilePrefab;
					}
					__instance.allowedToFire = true;
					((Weapon)__instance).connectedData = componentInParent.data;
					((Weapon)__instance).callAttackEffects = false;
				}
			}
		}

		[HarmonyPatch(typeof(UnitAPI), "SetAttackTarget")]
		[HarmonyPriority(800)]
		private static class AttackTargetRedirectPatch
		{
			private static void Prefix(UnitAPI __instance, ref float3 targetPos, ref Rigidbody mainRig, ref DataHandler unitData, ref TargetData targetData, ref bool canSeeTarget)
			{
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0181: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_0186: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				Unit val = (((Object)(object)mainRig != (Object)null) ? ((Component)mainRig).GetComponentInParent<Unit>() : null);
				if (Verify(componentInParent))
				{
					if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)componentInParent && val.Team != componentInParent.Team && (Object)(object)val.data != (Object)null && !val.data.Dead)
					{
						HackerXGuard.SetInternalTarget(componentInParent, val, new Vector3(targetPos.x, targetPos.y, targetPos.z));
					}
					else if ((Object)(object)unitData != (Object)null)
					{
						Unit componentInParent2 = ((Component)unitData).GetComponentInParent<Unit>();
						if ((Object)(object)componentInParent2 != (Object)null && (Object)(object)componentInParent2 != (Object)(object)componentInParent && componentInParent2.Team != componentInParent.Team && (Object)(object)componentInParent2.data != (Object)null && !componentInParent2.data.Dead)
						{
							HackerXGuard.SetInternalTarget(componentInParent, componentInParent2, new Vector3(targetPos.x, targetPos.y, targetPos.z));
						}
					}
				}
				if (!((Object)(object)mainRig == (Object)null) && !Verify(componentInParent) && (Object)(object)val != (Object)null && Verify(val))
				{
					DataHandler val2 = (((Object)(object)componentInParent != (Object)null) ? componentInParent.data : null);
					if ((Object)(object)componentInParent != (Object)null && componentInParent != val && (Object)(object)val2 != (Object)null)
					{
						mainRig = val2.mainRig;
						unitData = val2;
						targetPos = float3.op_Implicit(((Object)(object)val2.torso != (Object)null) ? val2.torso.position : ((Component)componentInParent).transform.position);
						targetData.DistanceToTarget = 0f;
						targetData.TargetInAttackRange = 1;
						targetData.TargetInPreferredRange = 1;
						canSeeTarget = true;
					}
				}
			}
		}

		[HarmonyPatch(typeof(WeaponHandler), "Attack")]
		[HarmonyPriority(800)]
		private static class WeaponAttackPatch
		{
			private static bool Prefix(WeaponHandler __instance, ref Vector3 position, ref Rigidbody targetRig, ref Vector3 forceDirection, ref ForceWeapon forceWeapon)
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_014f: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!Verify(componentInParent))
				{
					return true;
				}
				HackerXGuard component = ((Component)componentInParent).GetComponent<HackerXGuard>();
				Unit val = (((Object)(object)component != (Object)null) ? component.GetInternalTarget() : null);
				if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)componentInParent || val.Team == componentInParent.Team || (Object)(object)val.data == (Object)null || val.data.Dead)
				{
					return true;
				}
				HackerXGuard.EnsureNativeFists(componentInParent);
				HackerXGuard.EnsureNativeLauncher(componentInParent);
				targetRig = val.data.mainRig;
				position = (((Object)(object)val.data.torso != (Object)null) ? val.data.torso.position : ((Component)val).transform.position);
				Vector3 val2 = position - ((Component)componentInParent).transform.root.position;
				if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
				{
					val2 = ((Component)componentInParent).transform.forward;
				}
				forceDirection = ((Vector3)(ref val2)).normalized;
				Weapon leftWeapon = __instance.leftWeapon;
				MeleeWeapon val3 = (MeleeWeapon)(object)((leftWeapon is MeleeWeapon) ? leftWeapon : null);
				Weapon rightWeapon = __instance.rightWeapon;
				RangeWeapon val4 = (RangeWeapon)(object)((rightWeapon is RangeWeapon) ? rightWeapon : null);
				bool flag = false;
				if ((Object)(object)val3 != (Object)null)
				{
					((Weapon)val3).connectedData = componentInParent.data;
					((Weapon)val3).internalCounter = 0f;
					((Weapon)val3).Attack(position, targetRig, forceDirection, false);
					flag = true;
				}
				if ((Object)(object)val4 != (Object)null)
				{
					((Weapon)val4).connectedData = componentInParent.data;
					val4.allowedToFire = true;
					((Weapon)val4).internalCounter = 0f;
					EnsureNativeRagdollProjectilePrefab();
					if ((Object)(object)NativeRagdollProjectilePrefab != (Object)null)
					{
						val4.ObjectToSpawn = NativeRagdollProjectilePrefab;
					}
					((Weapon)val4).Attack(position, targetRig, forceDirection, false);
					flag = true;
				}
				if (flag && (Object)(object)component != (Object)null)
				{
					component.MarkNativeAttack();
				}
				return !flag;
			}
		}

		[HarmonyPatch(typeof(FindEnemyTargetSystem), "OnUpdate")]
		[HarmonyPriority(800)]
		private static class FindEnemyTargetPatch
		{
			private static void Postfix(FindEnemyTargetSystem __instance)
			{
				RedirectEcsTargets(__instance);
			}
		}

		[HarmonyPatch(typeof(UnitECSToMonoSyncSystem), "OnUpdate")]
		[HarmonyPriority(800)]
		private static class EcsTargetSyncPatch
		{
			private static void Postfix(UnitECSToMonoSyncSystem __instance)
			{
				RedirectEcsTargets(__instance);
			}
		}

		[HarmonyPatch(typeof(Damagable), "TakeDamage")]
		[HarmonyPriority(800)]
		private static class BaseDamagePatch
		{
			private static bool Prefix(Damagable __instance)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(HealthHandler), "SetInvulnerable")]
		[HarmonyPriority(800)]
		private static class InvulnerabilityPatch
		{
			private static bool Prefix(HealthHandler __instance, bool invulnerable)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (!Active || !Verify(unit))
				{
					return true;
				}
				FieldInfo field = typeof(HealthHandler).GetField("isInvulnerable", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					field.SetValue(__instance, true);
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(HealthHandlerClient), "TakeDamage")]
		[HarmonyPriority(800)]
		private static class ClientDamagePatch
		{
			private static bool Prefix(HealthHandlerClient __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !Verify(((Component)__instance).GetComponentInParent<Unit>());
			}
		}

		[HarmonyPatch(typeof(MonoBehaviour), "StartCoroutine")]
		[HarmonyPriority(800)]
		private static class StartCoroutinePatch
		{
			private static bool Prefix(MonoBehaviour __instance, ref Coroutine __result)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				if (!HackerXGuard.IsPermanentDeathMarked(((Component)__instance).GetComponentInParent<Unit>()))
				{
					return true;
				}
				__result = null;
				return false;
			}
		}

		[HarmonyPatch(typeof(ReviveStick), "Update")]
		[HarmonyPriority(800)]
		private static class ReviveStickUpdatePatch
		{
			private static bool Prefix(ReviveStick __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !HackerXGuard.IsPermanentDeathMarked(((Component)__instance).GetComponentInChildren<Unit>(true));
			}
		}

		[HarmonyPatch(typeof(ReviveStick), "ReviveAfterTime")]
		[HarmonyPriority(800)]
		private static class ReviveAfterTimePatch
		{
			private static bool Prefix(ReviveStick __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !HackerXGuard.IsPermanentDeathMarked(((Component)__instance).GetComponentInChildren<Unit>(true));
			}
		}

		private static class ReviveHealthPatch
		{
			private static void Postfix(ReviveStick __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInChildren = ((Component)__instance).GetComponentInChildren<Unit>(true);
					if (!HackerXGuard.IsPermanentDeathMarked(componentInChildren) && Verify(componentInChildren) && !((Object)(object)componentInChildren.data == (Object)null))
					{
						componentInChildren.data.maxHealth = Mathf.Max(componentInChildren.data.maxHealth, 1000000f);
						componentInChildren.data.health = componentInChildren.data.maxHealth;
						componentInChildren.data.Dead = false;
					}
				}
			}
		}

		[HarmonyPatch(typeof(UnitCombinations), "UpdateUnit")]
		[HarmonyPriority(800)]
		private static class CombinationHealthPatch
		{
			private static void Postfix(Unit unit)
			{
				if (Active && Verify(unit) && !((Object)(object)unit.data == (Object)null))
				{
					unit.data.maxHealth = Mathf.Max(unit.data.maxHealth, 1000000f);
					unit.data.health = unit.data.maxHealth;
				}
			}
		}

		[HarmonyPatch(typeof(CastleFightHouse), "DoUpgrades")]
		[HarmonyPriority(800)]
		private static class CastleHealthPatch
		{
			private static void Postfix(Unit unit)
			{
				if (Active && Verify(unit) && !((Object)(object)unit.data == (Object)null))
				{
					unit.data.maxHealth = Mathf.Max(unit.data.maxHealth, 1000000f);
					unit.data.health = unit.data.maxHealth;
				}
			}
		}

		[HarmonyPatch(typeof(CopySelf), "DoEffect")]
		[HarmonyPriority(800)]
		private static class CopySelfHealthPatch
		{
			private static void Postfix(CopySelf __instance)
			{
				if (Active && !((Object)(object)__instance == (Object)null))
				{
					Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
					if (Verify(componentInParent) && !((Object)(object)componentInParent.data == (Object)null))
					{
						componentInParent.data.maxHealth = Mathf.Max(componentInParent.data.maxHealth, 1000000f);
						componentInParent.data.health = componentInParent.data.maxHealth;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Unit), "UnfreezeBody")]
		[HarmonyPriority(800)]
		private static class UnfreezeBodyPatch
		{
			private static void Postfix(Unit __instance)
			{
				if (!Active || (Object)(object)__instance == (Object)null || !Verify(__instance))
				{
					return;
				}
				RigidbodyHolder componentInChildren = ((Component)__instance).GetComponentInChildren<RigidbodyHolder>();
				if ((Object)(object)componentInChildren == (Object)null)
				{
					return;
				}
				Rigidbody[] allRigs = componentInChildren.AllRigs;
				for (int i = 0; i < allRigs.Length; i++)
				{
					if ((Object)(object)allRigs[i] != (Object)null)
					{
						allRigs[i].constraints = (RigidbodyConstraints)0;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Unit), "DestroyUnit")]
		[HarmonyPriority(800)]
		private static class DestroyUnitPatch
		{
			private static bool Prefix(Unit __instance)
			{
				if (Active)
				{
					return !Verify(__instance);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(HealthHandler), "TakeDamage")]
		[HarmonyPriority(800)]
		private static class DamagePatch
		{
			private static bool Prefix(HealthHandler __instance)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch]
		[HarmonyPriority(800)]
		private static class DiePatch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				return from m in typeof(HealthHandler).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where m.Name == "Die"
					select m;
			}

			private static bool Prefix(HealthHandler __instance)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(800)]
		private static class DeadPatch
		{
			private static bool Prefix(DataHandler __instance, bool __0)
			{
				if (!Active || !__0 || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !Verify(((Component)__instance).GetComponentInParent<Unit>());
			}
		}

		[HarmonyPatch(typeof(UnitPlacementBrush), "RemoveUnitInternal")]
		[HarmonyPriority(800)]
		private static class RemoveUnitPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(BaseGameMode), "OnUnitDied")]
		[HarmonyPriority(800)]
		private static class BaseDiedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(LocalMultiplayerGameMode), "OnUnitDied")]
		[HarmonyPriority(800)]
		private static class LocalDiedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(MainMenuGameMode), "OnUnitDied")]
		[HarmonyPriority(800)]
		private static class MenuDiedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(UnitCreatorGameMode), "OnUnitDied")]
		[HarmonyPriority(800)]
		private static class CreatorDiedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch]
		[HarmonyPriority(800)]
		private static class CharacterItemEquipPatch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				return from m in typeof(CharacterItem).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where m.Name == "Equip"
					select m;
			}

			private static bool Prefix(CharacterItem __instance)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CharacterItem), "Remove")]
		[HarmonyPriority(800)]
		private static class CharacterItemRemovePatch
		{
			private static bool Prefix()
			{
				return true;
			}
		}

		[HarmonyPatch(typeof(CharacterItem), "SetVisibility")]
		[HarmonyPriority(800)]
		private static class CharacterItemVisibilityPatch
		{
			private static bool Prefix(CharacterItem __instance, ref bool __0)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (!Active || !Verify(unit))
				{
					return true;
				}
				__0 = false;
				return true;
			}
		}

		[HarmonyPatch(typeof(EyeSpawner), "SetEyesActive")]
		[HarmonyPriority(800)]
		private static class EyesActivePatch
		{
			private static bool Prefix(EyeSpawner __instance)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (!Active || !Verify(unit))
				{
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(EyeSpawner), "SetEyesVisable")]
		[HarmonyPriority(800)]
		private static class EyesVisiblePatch
		{
			private static bool Prefix(EyeSpawner __instance)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (!Active || !Verify(unit))
				{
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(WeaponHandler), "SetWeapon")]
		[HarmonyPriority(800)]
		private static class SetWeaponPatch
		{
			private static bool Prefix(WeaponHandler __instance, Weapon weapon)
			{
				Unit unit = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponentInParent<Unit>() : null);
				if (!Active || !Verify(unit))
				{
					return true;
				}
				if ((Object)(object)weapon == (Object)null)
				{
					return true;
				}
				bool num = (Object)(object)((Component)weapon).GetComponentInParent<HandRight>() != (Object)null;
				bool flag = (Object)(object)((Component)weapon).GetComponentInParent<HandLeft>() != (Object)null;
				return num || flag;
			}
		}

		[HarmonyPatch(typeof(BaseGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class RemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CampaignGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class CampaignRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(LocalMultiplayerGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class LocalRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(MainMenuGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class MenuRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(OnlineMultiplayerGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class OnlineRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(SandboxGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class SandboxRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(UnitCreatorGameMode), "OnUnitRemoved")]
		[HarmonyPriority(800)]
		private static class CreatorRemovedPatch
		{
			private static bool Prefix(Unit unit)
			{
				if (Active)
				{
					return !Verify(unit);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Unit), "InitializeUnit")]
		[HarmonyPriority(800)]
		private static class InitUnitPatch
		{
			private static bool Prefix(Unit __instance)
			{
				if (Active && HackerXGuard.IsPermanentDeathMarked(__instance))
				{
					return false;
				}
				if (Active && Verify(__instance) && (Object)(object)Blueprint != (Object)null)
				{
					__instance.unitBlueprint = Blueprint;
				}
				if (Active && Verify(__instance))
				{
					HackerXGuard hackerXGuard = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<HackerXGuard>() : null);
					if ((Object)(object)hackerXGuard != (Object)null)
					{
						hackerXGuard.InstallCollisionShield();
					}
				}
				return true;
			}
		}

		private static void RedirectEcsTargets(object system)
		{
			//IL_005d: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			if (!Active || system == null)
			{
				return;
			}
			int frameCount = Time.frameCount;
			if (frameCount == EcsRedirectFrame || frameCount % 12 != 0)
			{
				return;
			}
			EcsRedirectFrame = frameCount;
			Unit val = FindProtectedUnit();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			GameObjectEntity component = ((Component)val).GetComponent<GameObjectEntity>();
			if ((Object)(object)component == (Object)null || component.EntityManager == null || !component.EntityManager.IsCreated)
			{
				return;
			}
			Entity entity = component.Entity;
			EntityManager entityManager = component.EntityManager;
			try
			{
				MethodInfo method = typeof(ComponentSystemBase).GetMethod("GetComponentGroup", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[1] { typeof(ComponentType[]) }, null);
				if (method == null)
				{
					return;
				}
				object? obj = method.Invoke(system, new object[1] { new ComponentType[1] { ComponentType.Create<HasTargetTag>() } });
				ComponentGroup val2 = (ComponentGroup)((obj is ComponentGroup) ? obj : null);
				if (val2 == null)
				{
					return;
				}
				EntityArray entityArray = val2.GetEntityArray();
				ComponentDataArray<HasTargetTag> componentDataArray = val2.GetComponentDataArray<HasTargetTag>();
				for (int i = 0; i < ((EntityArray)(ref entityArray)).Length; i++)
				{
					if (!(componentDataArray[i].Target != entity))
					{
						HasTargetTag val3 = componentDataArray[i];
						val3.Target = ((EntityArray)(ref entityArray))[i];
						if (entityManager.Exists(((EntityArray)(ref entityArray))[i]) && entityManager.HasComponent<HasTargetTag>(((EntityArray)(ref entityArray))[i]))
						{
							entityManager.SetComponentData<HasTargetTag>(((EntityArray)(ref entityArray))[i], val3);
						}
					}
				}
			}
			catch
			{
			}
		}
	}

	private static class HackerXUnityPatches
	{
		[HarmonyPatch(typeof(Object), "Destroy", new Type[] { typeof(Object) })]
		[HarmonyPriority(800)]
		private static class DestroyPatch
		{
			private static bool Prefix(Object obj)
			{
				if (!Active || InternalDestroy)
				{
					return true;
				}
				return !HackerXGuard.IsCriticalObject(obj);
			}
		}

		[HarmonyPatch(typeof(Object), "Destroy", new Type[]
		{
			typeof(Object),
			typeof(float)
		})]
		[HarmonyPriority(800)]
		private static class DestroyDelayPatch
		{
			private static bool Prefix(Object obj)
			{
				if (!Active || InternalDestroy)
				{
					return true;
				}
				return !HackerXGuard.IsCriticalObject(obj);
			}
		}

		[HarmonyPatch(typeof(Object), "DestroyImmediate", new Type[] { typeof(Object) })]
		[HarmonyPriority(800)]
		private static class DestroyImmediatePatch
		{
			private static bool Prefix(Object obj)
			{
				if (!Active || InternalDestroy)
				{
					return true;
				}
				return !HackerXGuard.IsCriticalObject(obj);
			}
		}

		[HarmonyPatch(typeof(GameObject), "SetActive")]
		[HarmonyPriority(800)]
		private static class SetActivePatch
		{
			private static bool Prefix(GameObject __instance, bool value)
			{
				if (!Active || value || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				if ((Object)(object)__instance.GetComponentInParent<CharacterItem>() != (Object)null || (Object)(object)__instance.GetComponentInParent<EyeSpawner>() != (Object)null)
				{
					return true;
				}
				return !HackerXGuard.IsCriticalObject((Object)(object)__instance);
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(800)]
		private static class ScalePatch
		{
			private static bool Prefix(Transform __instance)
			{
				if (!Active || InternalTransformMutation || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !HackerXGuard.IsRootTransform(__instance);
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(800)]
		private static class MeshPatch
		{
			private static bool Prefix(MeshFilter __instance)
			{
				if (Active)
				{
					return (Object)(object)GetGuard((Object)(object)__instance) == (Object)null;
				}
				return true;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(800)]
		private static class SkinnedMeshPatch
		{
			private static bool Prefix(SkinnedMeshRenderer __instance)
			{
				if (Active)
				{
					return (Object)(object)GetGuard((Object)(object)__instance) == (Object)null;
				}
				return true;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(800)]
		private static class RendererEnabledPatch
		{
			private static bool Prefix(Renderer __instance, bool value)
			{
				if (!Active)
				{
					return true;
				}
				if ((Object)(object)GetGuard((Object)(object)__instance) == (Object)null)
				{
					return true;
				}
				if (HackerXGuard.IsAppearanceObject((Object)(object)__instance))
				{
					return true;
				}
				return value;
			}
		}

		[HarmonyPatch(typeof(Transform), "SetParent", new Type[] { typeof(Transform) })]
		[HarmonyPriority(800)]
		private static class BehaviourEnabledPatch
		{
			private static bool Prefix(Behaviour __instance, bool value)
			{
				if (!Active || value)
				{
					return true;
				}
				return !HackerXGuard.IsCriticalObject((Object)(object)__instance);
			}
		}

		private static class ColliderEnabledPatch
		{
			private static bool Prefix(Collider __instance, bool value)
			{
				if (!Active || value)
				{
					return true;
				}
				return !HackerXGuard.IsCriticalObject((Object)(object)__instance);
			}
		}

		private static class MeshSharedPatch
		{
			private static bool Prefix(Object __instance)
			{
				if (Active)
				{
					return (Object)(object)GetGuard(__instance) == (Object)null;
				}
				return true;
			}
		}

		private static class RendererMaterialPatch
		{
			private static bool Prefix(Renderer __instance)
			{
				if (Active)
				{
					return (Object)(object)GetGuard((Object)(object)__instance) == (Object)null;
				}
				return true;
			}
		}

		private static class RendererMaterialsPatch
		{
			private static bool Prefix(Renderer __instance)
			{
				if (Active)
				{
					return (Object)(object)GetGuard((Object)(object)__instance) == (Object)null;
				}
				return true;
			}
		}

		private static class RigidbodyMassPatch
		{
			private static bool Prefix(Rigidbody __instance, ref float value)
			{
				if (!Active || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				Unit componentInParent = ((Component)__instance).GetComponentInParent<Unit>();
				if (!Verify(componentInParent))
				{
					return true;
				}
				HackerXGuard component = ((Component)componentInParent).GetComponent<HackerXGuard>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				value = component.GetProtectedMass(__instance, value);
				return true;
			}
		}

		private static class UnitSetMassMultiplierPatch
		{
			private static bool Prefix(Unit __instance, float massMultiplier)
			{
				if (!Active || (Object)(object)__instance == (Object)null || massMultiplier == 1f)
				{
					return true;
				}
				return !Verify(__instance);
			}
		}

		private static class RigidbodyHolderStartPatch
		{
			private static void Prefix(RigidbodyHolder __instance, ref float __state)
			{
				__state = 1f;
				if (Active && !((Object)(object)__instance == (Object)null) && Verify(((Component)__instance).GetComponentInParent<Unit>()))
				{
					__state = __instance.massMultiplier;
					__instance.massMultiplier = 1f;
				}
			}

			private static void Postfix(RigidbodyHolder __instance, float __state)
			{
				if (!((Object)(object)__instance == (Object)null) && __state != 1f && Verify(((Component)__instance).GetComponentInParent<Unit>()))
				{
					__instance.massMultiplier = __state;
				}
			}
		}

		private static class RendererForceOffPatch
		{
			private static bool Prefix(Renderer __instance, bool value)
			{
				if (!Active || (Object)(object)GetGuard((Object)(object)__instance) == (Object)null)
				{
					return true;
				}
				if (HackerXGuard.IsAppearanceObject((Object)(object)__instance))
				{
					return true;
				}
				return !value;
			}
		}

		private static class SetParentPatch
		{
			private static bool Prefix(Transform __instance, Transform __0)
			{
				if (!Active || InternalTransformMutation || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				if (!HackerXGuard.IsProtectedHierarchyTransform(__instance))
				{
					return true;
				}
				if ((Object)(object)__0 != (Object)null && HackerXGuard.IsProtectedHierarchyTransform(__0))
				{
					return true;
				}
				return false;
			}
		}

		private static class DetachChildrenPatch
		{
			private static bool Prefix(Transform __instance)
			{
				if (!Active || InternalTransformMutation || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				return !HackerXGuard.IsProtectedHierarchyTransform(__instance);
			}
		}

		private static class SetParentTwoPatch
		{
			private static bool Prefix(Transform __instance, Transform __0, bool __1)
			{
				if (!Active || InternalTransformMutation || (Object)(object)__instance == (Object)null)
				{
					return true;
				}
				if (!HackerXGuard.IsRootTransform(__instance))
				{
					return true;
				}
				if ((Object)(object)__0 == (Object)null)
				{
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(800)]
		private static class GameObjectNamePatch
		{
			private static bool Prefix(GameObject __instance, string __0)
			{
				if (!Active)
				{
					return true;
				}
				HackerXGuard guard = GetGuard((Object)(object)__instance);
				if ((Object)(object)guard == (Object)null)
				{
					return true;
				}
				Unit component = ((Component)guard).GetComponent<Unit>();
				if ((Object)(object)component == (Object)null || (Object)(object)__instance != (Object)(object)((Component)component).gameObject)
				{
					return true;
				}
				return __0 == "HackerX";
			}
		}
	}

	private const string HarmonyId = "HackerX.InvulnerableUnit.Harmony";

	private const string UnitName = "HackerX";

	private const string FactionName = "HackerX";

	private static readonly Dictionary<int, HackerXGuard> Guards = new Dictionary<int, HackerXGuard>();

	private static Harmony Harmony;

	private static UnitBlueprint Blueprint;

	private static GameObject ProtectedUnitBase;

	private static GameObject ProtectedFistRef;

	private static Faction Faction;

	private static DatabaseID UnitGuid;

	private static DatabaseID FactionGuid;

	private static byte[] SecurityKey;

	private static int ModId;

	private static bool Active;

	private static bool BattleActive;

	private static bool InternalDestroy;

	internal static bool InternalTransformMutation;

	private static bool HooksInstalled;

	private static bool MainMenuBindingsCleared;

	private static Unit CachedProtectedUnit;

	internal static GameObject NativeProjectilePrefab;

	internal static GameObject NativeRagdollProjectilePrefab;

	internal static HackerXMod Instance;

	internal static int EcsRedirectFrame = -1;

	private static readonly BindingFlags PatchFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	private void Awake()
	{
		Instance = this;
		SecurityKey = new byte[32];
		using (RNGCryptoServiceProvider rNGCryptoServiceProvider = new RNGCryptoServiceProvider())
		{
			rNGCryptoServiceProvider.GetBytes(SecurityKey);
		}
		ModId = BuildModId(SecurityKey);
		SceneManager.sceneLoaded += OnSceneLoaded;
		SceneManager.sceneUnloaded += OnSceneUnloaded;
		EnableProtection();
		if (IsGameSceneLoaded())
		{
			RefreshSceneBindings();
		}
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
		SceneManager.sceneUnloaded -= OnSceneUnloaded;
		DisableProtection();
		Instance = null;
	}

	private void Update()
	{
		if (!Active)
		{
			return;
		}
		if (IsGameSceneLoaded())
		{
			if (MainMenuBindingsCleared)
			{
				MainMenuBindingsCleared = false;
				EnsureContent();
				RefreshSceneBindings();
			}
			if (!IsBattleState())
			{
				if (BattleActive)
				{
					HackerXPermanentRegistry.Clear();
				}
				BattleActive = false;
			}
		}
		else
		{
			BattleActive = false;
		}
	}

	internal static bool IsGameSceneLoaded()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		Scene sceneByName = SceneManager.GetSceneByName("GameScene");
		if (((Scene)(ref sceneByName)).IsValid())
		{
			return ((Scene)(ref sceneByName)).isLoaded;
		}
		return false;
	}

	private static bool IsMainMenuLoaded()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		Scene sceneByName = SceneManager.GetSceneByName("MainMenu");
		if (((Scene)(ref sceneByName)).IsValid())
		{
			return ((Scene)(ref sceneByName)).isLoaded;
		}
		return false;
	}

	private static void CleanupPlacementState()
	{
		if (!Active)
		{
			return;
		}
		BattleActive = false;
		HackerXPermanentRegistry.Clear();
		Unit[] array = Object.FindObjectsOfType<Unit>().Where(Verify).ToArray();
		foreach (Unit val in array)
		{
			if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			HackerXGuard component = ((Component)val).GetComponent<HackerXGuard>();
			if ((Object)(object)component != (Object)null)
			{
				component.ResetBattleReferences();
			}
			InternalDestroy = true;
			try
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			catch
			{
			}
			finally
			{
				InternalDestroy = false;
			}
		}
		Guards.Clear();
		CachedProtectedUnit = null;
	}

	private static bool BattleControlProtected()
	{
		if (!Active || InternalDestroy)
		{
			return false;
		}
		if (!BattleActive && !IsBattleState())
		{
			return false;
		}
		return (Object)(object)FindProtectedUnit() != (Object)null;
	}

	private static bool IsBattleState()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Invalid comparison between Unknown and I4
		try
		{
			GameStateManager service = ServiceLocator.GetService<GameStateManager>();
			return service != null && (int)service.GameState == 1;
		}
		catch
		{
			return false;
		}
	}

	internal static bool IsBattleActiveNow()
	{
		if (!BattleActive)
		{
			return IsBattleState();
		}
		return true;
	}

	private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (((Scene)(ref scene)).name == "MainMenu")
		{
			MainMenuBindingsCleared = true;
			BattleActive = false;
			HackerXPermanentRegistry.Clear();
			Guards.Clear();
			CachedProtectedUnit = null;
			Unit[] array = Object.FindObjectsOfType<Unit>();
			foreach (Unit val in array)
			{
				if ((Object)(object)val != (Object)null && Verify(val))
				{
					try
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
					catch
					{
					}
				}
			}
		}
		else if (((Scene)(ref scene)).name == "GameScene")
		{
			EnsureContent();
			BattleActive = IsBattleState();
			RefreshSceneBindings();
			if (BattleActive)
			{
				OnBattleStarted();
			}
		}
	}

	private static void OnSceneUnloaded(Scene scene)
	{
		if (((Scene)(ref scene)).name == "MainMenu")
		{
			MainMenuBindingsCleared = true;
			BattleActive = false;
			HackerXPermanentRegistry.Clear();
		}
	}

	private static void RefreshSceneBindings()
	{
		if (!Active || !IsGameSceneLoaded())
		{
			return;
		}
		EnsureContent();
		Unit[] array = Object.FindObjectsOfType<Unit>();
		foreach (Unit val in array)
		{
			if (!((Object)(object)val == (Object)null) && Object.op_Implicit((Object)(object)val) && (Object)(object)val.unitBlueprint == (Object)(object)Blueprint)
			{
				AttachProtection(val);
			}
		}
		PruneDuplicateUnits();
	}

	private static void OnBattleStarted()
	{
		if (Active && IsGameSceneLoaded())
		{
			EnsureContent();
			RefreshSceneBindings();
		}
	}

	private static void EnableProtection()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		if (!Active || !HooksInstalled)
		{
			Active = true;
			EnsureContent();
			if (Harmony == null)
			{
				Harmony = new Harmony("HackerX.InvulnerableUnit.Harmony");
			}
			if (!HooksInstalled)
			{
				SetupOriginalMethodTrampolines();
				ApplyPatches();
				HooksInstalled = true;
			}
		}
	}

	private static void DisableProtection()
	{
		try
		{
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
		catch
		{
		}
		Harmony = null;
		HooksInstalled = false;
		Active = false;
		BattleActive = false;
		HackerXGuard[] array = Guards.Values.ToArray();
		foreach (HackerXGuard hackerXGuard in array)
		{
			if ((Object)(object)hackerXGuard != (Object)null)
			{
				Object.Destroy((Object)(object)hackerXGuard);
			}
		}
		Guards.Clear();
	}

	private static void ClearPrivateRiders(UnitBlueprint blueprint)
	{
		if ((Object)(object)blueprint == (Object)null)
		{
			return;
		}
		try
		{
			FieldInfo field = typeof(UnitBlueprint).GetField("Riders", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(blueprint, null);
			}
			FieldInfo field2 = typeof(UnitBlueprint).GetField("m_hasCustomRider", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field2 != null)
			{
				field2.SetValue(blueprint, false);
			}
		}
		catch
		{
		}
	}

	private static int BuildModId(byte[] key)
	{
		using SHA256 sHA = SHA256.Create();
		int val = BitConverter.ToInt32(sHA.ComputeHash(key), 0) & 0x7FFFFFFF;
		return Math.Max(1000, val);
	}

	private static string KeyHex()
	{
		return BitConverter.ToString(SecurityKey).Replace("-", "");
	}

	internal static bool IsActiveFast()
	{
		return Active;
	}

	internal static UnitBlueprint GetBlueprintFast()
	{
		return Blueprint;
	}

	internal static GameObject GetProtectedFistFast()
	{
		return ProtectedFistRef;
	}

	internal static void RegisterGuardFast(Unit unit, HackerXGuard guard)
	{
		if (!((Object)(object)unit == (Object)null) && !((Object)(object)guard == (Object)null))
		{
			Guards[((Object)unit).GetInstanceID()] = guard;
		}
	}

	internal static bool Verify(Unit unit)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)unit == (Object)null || !Object.op_Implicit((Object)(object)unit))
		{
			return false;
		}
		HackerXGuard component = ((Component)unit).GetComponent<HackerXGuard>();
		if ((Object)(object)component != (Object)null)
		{
			return component.IsValid(SecurityKey, UnitGuid, KeyHex());
		}
		return false;
	}

	private static HackerXGuard GetGuard(Object obj)
	{
		Component val = (Component)(object)((obj is Component) ? obj : null);
		if ((Object)(object)val != (Object)null)
		{
			HackerXGuard component = val.GetComponent<HackerXGuard>();
			if ((Object)(object)component != (Object)null)
			{
				return component;
			}
			Unit componentInParent = val.GetComponentInParent<Unit>();
			if ((Object)(object)componentInParent != (Object)null && Verify(componentInParent))
			{
				return ((Component)componentInParent).GetComponent<HackerXGuard>();
			}
		}
		GameObject val2 = (GameObject)(object)((obj is GameObject) ? obj : null);
		if ((Object)(object)val2 != (Object)null)
		{
			HackerXGuard component2 = val2.GetComponent<HackerXGuard>();
			if ((Object)(object)component2 != (Object)null)
			{
				return component2;
			}
			Unit componentInParent2 = val2.GetComponentInParent<Unit>();
			if ((Object)(object)componentInParent2 != (Object)null && Verify(componentInParent2))
			{
				return ((Component)componentInParent2).GetComponent<HackerXGuard>();
			}
		}
		return null;
	}

	private static void EnsureContent()
	{
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: 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_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Expected O, but got Unknown
		//IL_008f: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		ContentDatabase val = ContentDatabase.Instance();
		if ((Object)(object)Blueprint == (Object)null)
		{
			UnitBlueprint val2 = val.GetAllUnitBlueprints().FirstOrDefault((Func<UnitBlueprint, bool>)((UnitBlueprint x) => (Object)(object)x != (Object)null && (Object)(object)x.UnitBase != (Object)null && (Object)(object)x.fistRef != (Object)null && (Object)(object)x.Mount == (Object)null));
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = val.GetAllUnitBlueprints().FirstOrDefault((Func<UnitBlueprint, bool>)((UnitBlueprint x) => (Object)(object)x != (Object)null && (Object)(object)x.UnitBase != (Object)null));
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			Blueprint = new UnitBlueprint(val2);
			UnitGuid = DatabaseID.NewID(ModId);
			Blueprint.Entity.GUID = UnitGuid;
			Blueprint.Entity.Name = "HackerX";
			Blueprint.RightWeapon = null;
			Blueprint.LeftWeapon = null;
			Blueprint.holdinigWithTwoHands = false;
			Blueprint.SetCustomUnit(ModId, KeyHex());
			Blueprint.RightWeaponData = null;
			Blueprint.LeftWeaponData = null;
			Blueprint.m_props = null;
			Blueprint.m_propData = null;
			Blueprint.Mount = null;
			Blueprint.objectsToSpawnAsChildren = null;
			Blueprint.fistRef = val2.fistRef;
			ProtectedUnitBase = Blueprint.UnitBase;
			ProtectedFistRef = Blueprint.fistRef;
			Blueprint.SetNoCustomRider();
			ClearPrivateRiders(Blueprint);
			Blueprint.sizeMultiplier = 1f;
			Blueprint.minSizeRandom = 1f;
			Blueprint.maxSizeRandom = 1f;
			Blueprint.forceNoRandomSize = true;
			val.AddUserUnitBlueprint(Blueprint);
		}
		if ((Object)(object)Faction == (Object)null)
		{
			Faction = val.GetFactionByName("HackerX");
			if ((Object)(object)Faction == (Object)null)
			{
				Faction = ScriptableObject.CreateInstance<Faction>();
				FactionGuid = DatabaseID.NewID();
				Faction.Init(FactionGuid);
				Faction.Entity.Name = "HackerX";
				Faction.modID = 0;
				Faction.IsCustom = true;
				Faction.m_displayFaction = true;
				Faction.index = 999;
				Faction.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { Blueprint };
				FactionColorAndIcon(val, Faction);
				val.AddUserFaction(Faction);
			}
			else
			{
				FactionGuid = Faction.Entity.GUID;
				Faction.modID = 0;
				Faction.IsCustom = true;
				Faction.m_displayFaction = true;
				Faction.index = 999;
				Faction.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { Blueprint };
				FactionColorAndIcon(val, Faction);
				if ((Object)(object)val.GetFaction(FactionGuid) == (Object)null)
				{
					val.AddUserFaction(Faction);
				}
			}
		}
		if ((Object)(object)Blueprint != (Object)null && (Object)(object)val.GetUnitBlueprint(UnitGuid) == (Object)null)
		{
			val.AddUserUnitBlueprint(Blueprint);
		}
		if ((Object)(object)Faction != (Object)null && (Object)(object)val.GetFaction(FactionGuid) == (Object)null)
		{
			Faction.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { Blueprint };
			Faction.modID = 0;
			Faction.IsCustom = true;
			Faction.m_displayFaction = true;
			Faction.index = 999;
			FactionColorAndIcon(val, Faction);
			val.AddUserFaction(Faction);
		}
		EnsureNativeProjectilePrefab(val);
		EnsureNativeRagdollProjectilePrefab();
	}

	private static void EnsureNativeProjectilePrefab(ContentDatabase db)
	{
		if ((Object)(object)NativeProjectilePrefab != (Object)null)
		{
			return;
		}
		try
		{
			IEnumerable<GameObject> allProjectiles = db.GetAllProjectiles();
			NativeProjectilePrefab = allProjectiles.FirstOrDefault((Func<GameObject, bool>)((GameObject go) => (Object)(object)go != (Object)null && (Object)(object)go.GetComponent<Projectile>() != (Object)null && (Object)(object)go.GetComponent<ProjectileHit>() != (Object)null && ((Object)(object)go.GetComponent<PooledProjectile>() != (Object)null || (Object)(object)go.GetComponent<MoveTransform>() != (Object)null)));
			if ((Object)(object)NativeProjectilePrefab == (Object)null)
			{
				NativeProjectilePrefab = allProjectiles.FirstOrDefault((Func<GameObject, bool>)((GameObject go) => (Object)(object)go != (Object)null && (Object)(object)go.GetComponent<Projectile>() != (Object)null && (Object)(object)go.GetComponent<ProjectileHit>() != (Object)null));
			}
		}
		catch
		{
		}
	}

	internal static void EnsureNativeRagdollProjectilePrefab()
	{
		if (!((Object)(object)NativeProjectilePrefab == (Object)null))
		{
			NativeRagdollProjectilePrefab = NativeProjectilePrefab;
		}
	}

	private static void FactionColorAndIcon(ContentDatabase db, Faction faction)
	{
		if ((Object)(object)faction == (Object)null || db == null)
		{
			return;
		}
		try
		{
			Faction val = db.GetAllFactions().FirstOrDefault((Func<Faction, bool>)((Faction x) => (Object)(object)x != (Object)null && (Object)(object)x != (Object)(object)faction && (Object)(object)x.FactionIcon != (Object)null));
			if ((Object)(object)val != (Object)null)
			{
				faction.FactionIcon = val.FactionIcon;
				faction.CustomFactionColor = val.CustomFactionColor;
			}
			else
			{
				faction.CustomFactionColor = db.GetCustomFactionColorDatabase().CustomFacionColors[0];
			}
		}
		catch
		{
		}
	}

	private static Unit FindProtectedUnitsSingle()
	{
		if (!Active)
		{
			return null;
		}
		if ((Object)(object)CachedProtectedUnit != (Object)null && Object.op_Implicit((Object)(object)CachedProtectedUnit))
		{
			return CachedProtectedUnit;
		}
		Unit[] array = Object.FindObjectsOfType<Unit>();
		foreach (Unit val in array)
		{
			if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val) && Verify(val))
			{
				CachedProtectedUnit = val;
				return val;
			}
		}
		return null;
	}

	private static Unit[] FindProtectedUnits()
	{
		Unit val = FindProtectedUnitsSingle();
		if (!((Object)(object)val != (Object)null))
		{
			return Array.Empty<Unit>();
		}
		return (Unit[])(object)new Unit[1] { val };
	}

	internal static Unit FindProtectedUnit()
	{
		return FindProtectedUnitsSingle();
	}

	internal static Unit GetCachedProtectedUnit()
	{
		if (!((Object)(object)CachedProtectedUnit != (Object)null) || !Object.op_Implicit((Object)(object)CachedProtectedUnit))
		{
			return FindProtectedUnitsSingle();
		}
		return CachedProtectedUnit;
	}

	private static void PruneDuplicateUnits()
	{
		Unit[] array = FindProtectedUnits();
		if (array.Length <= 1)
		{
			return;
		}
		for (int i = 1; i < array.Length; i++)
		{
			Unit val = array[i];
			if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			InternalDestroy = true;
			try
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			catch
			{
			}
			finally
			{
				InternalDestroy = false;
			}
			Guards.Remove(((Object)val).GetInstanceID());
			if ((Object)(object)CachedProtectedUnit == (Object)(object)val)
			{
				CachedProtectedUnit = null;
			}
		}
	}

	private static void AttachProtection(Unit unit)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)unit == (Object)null) && Object.op_Implicit((Object)(object)unit))
		{
			HackerXGuard hackerXGuard = ((Component)unit).GetComponent<HackerXGuard>();
			if ((Object)(object)hackerXGuard == (Object)null)
			{
				hackerXGuard = ((Component)unit).gameObject.AddComponent<HackerXGuard>();
			}
			hackerXGuard.Configure(SecurityKey, UnitGuid, FactionGuid, KeyHex(), "HackerX");
			hackerXGuard.ApplyAppearance();
			Guards[((Object)unit).GetInstanceID()] = hackerXGuard;
			CachedProtectedUnit = unit;
			hackerXGuard.Refresh();
			hackerXGuard.InstallCollisionShield();
		}
	}

	private static MethodInfo PatchHandler(Type type, Type nestedType, string handlerName)
	{
		if (type == null || nestedType == null)
		{
			return null;
		}
		return nestedType.GetMethod(handlerName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
	}

	private static int PatchNamed(Type targetType, string methodName, MethodInfo prefix = null, MethodInfo postfix = null)
	{
		if (Harmony == null || targetType == null)
		{
			return 0;
		}
		int num = 0;
		MethodBase[] array;
		try
		{
			array = (from m in targetType.GetMethods(PatchFlags | BindingFlags.DeclaredOnly)
				where m.Name == methodName
				select m).Cast<MethodBase>().ToArray();
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("HackerX patch discovery failed for " + targetType.FullName + "." + methodName + ": " + ex.Message));
			return 0;
		}
		MethodBase[] array2 = array;
		for (int num2 = 0; num2 < array2.Length; num2++)
		{
			if (PatchOne(array2[num2], prefix, postfix))
			{
				num++;
			}
		}
		return num;
	}

	private static int PatchSetter(Type targetType, string propertyName, MethodInfo prefix)
	{
		if (Harmony == null || targetType == null)
		{
			return 0;
		}
		try
		{
			PropertyInfo property = targetType.GetProperty(propertyName, PatchFlags);
			MethodInfo methodInfo = ((property != null) ? property.GetSetMethod(nonPublic: true) : null);
			return (methodInfo != null && PatchOne(methodInfo, prefix, null)) ? 1 : 0;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("HackerX setter patch failed for " + targetType.FullName + "." + propertyName + ": " + ex.Message));
			return 0;
		}
	}

	private static int PatchTimeServiceStateHooks()
	{
		if (Harmony == null)
		{
			return 0;
		}
		MethodInfo methodInfo = Handler("HackerXPatches", "TimeStatePatch", "Prefix");
		if (methodInfo == null)
		{
			return 0;
		}
		int num = 0;
		try
		{
			MethodInfo[] methods = typeof(TimeService).GetMethods(PatchFlags | BindingFlags.DeclaredOnly);
			foreach (MethodInfo methodInfo2 in methods)
			{
				if (!(methodInfo2.Name != "SetState") && PatchOne(methodInfo2, methodInfo, null))
				{
					num++;
				}
			}
		}
		catch
		{
		}
		return num;
	}

	private static bool PatchOne(MethodBase original, MethodInfo prefix, MethodInfo postfix)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		if (Harmony == null || original == null)
		{
			return false;
		}
		try
		{
			HarmonyMethod val = ((!(prefix != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(prefix, 800, (string[])null, (string[])null, (bool?)null));
			HarmonyMethod val2 = ((!(postfix != null)) ? ((HarmonyMethod)null) : new HarmonyMethod(postfix, 800, (string[])null, (string[])null, (bool?)null));
			Harmony.Patch(original, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("HackerX skipped patch " + original.DeclaringType?.ToString() + "." + original.Name + ": " + ex.Message));
			return false;
		}
	}

	private static MethodInfo Handler(string groupName, string patchName, string methodName)
	{
		try
		{
			Type nestedType = typeof(HackerXMod).GetNestedType(groupName, BindingFlags.Public | BindingFlags.NonPublic);
			Type type = ((nestedType != null) ? nestedType.GetNestedType(patchName, BindingFlags.Public | BindingFlags.NonPublic) : null);
			return (type != null) ? type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) : null;
		}
		catch
		{
			return null;
		}
	}

	private static void SetupOriginalMethodTrampolines()
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		if (Harmony == null)
		{
			return;
		}
		try
		{
			MethodBase method = typeof(Object).GetMethod("Destroy", PatchFlags, null, new Type[1] { typeof(Object) }, null);
			MethodInfo method2 = typeof(HackerXOriginalMethods).GetMethod("DestroyOriginal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (method != null && method2 != null)
			{
				Harmony.CreateReversePatcher(method, new HarmonyMethod(method2)).Patch((HarmonyReversePatchType)0);
			}
			MethodBase method3 = typeof(Object).GetMethod("DestroyImmediate", PatchFlags, null, new Type[1] { typeof(Object) }, null);
			MethodInfo method4 = typeof(HackerXOriginalMethods).GetMethod("DestroyImmediateOriginal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (method3 != null && method4 != null)
			{
				Harmony.CreateReversePatcher(method3, new HarmonyMethod(method4)).Patch((HarmonyReversePatchType)0);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("HackerX original-method trampoline setup failed: " + ex.Message));
		}
	}

	private static void ApplyPatches()
	{
		if (Harmony != null)
		{
			int num = 0;
			num += PatchSetter(typeof(Transform), "localScale", Handler("HackerXUnityPatches", "ScalePatch", "Prefix"));
			num += PatchNamed(typeof(Object), "Destroy", Handler("HackerXUnityPatches", "DestroyPatch", "Prefix"));
			num += PatchNamed(typeof(Object), "DestroyImmediate", Handler("HackerXUnityPatches", "DestroyImmediatePatch", "Prefix"));
			num += PatchNamed(typeof(Object), "DestroyObject", Handler("HackerXUnityPatches", "DestroyPatch", "Prefix"));
			num += PatchNamed(typeof(GameObject), "SetActive", Handler("HackerXUnityPatches", "SetActivePatch", "Prefix"));
			num += PatchSetter(typeof(GameObject), "name", Handler("HackerXUnityPatches", "GameObjectNamePatch", "Prefix"));
			num += PatchNamed(typeof(Transform), "SetParent", Handler("HackerXUnityPatches", "SetParentPatch", "Prefix"));
			num += PatchNamed(typeof(Transform), "DetachChildren", Handler("HackerXUnityPatches", "DetachChildrenPatch", "Prefix"));
			MethodBase method = typeof(Transform).GetMethod("SetParent", PatchFlags, null, new Type[2]
			{
				typeof(Transform),
				typeof(bool)
			}, null);
			if (method != null)
			{
				PatchOne(method, Handler("HackerXUnityPatches", "SetParentTwoPatch", "Prefix"), null);
			}
			num += PatchSetter(typeof(Behaviour), "enabled", Handler("HackerXUnityPatches", "BehaviourEnabledPatch", "Prefix"));
			num += PatchSetter(typeof(Collider), "enabled", Handler("HackerXUnityPatches", "ColliderEnabledPatch", "Prefix"));
			num += PatchSetter(typeof(MeshFilter), "sharedMesh", Handler("HackerXUnityPatches", "MeshSharedPatch", "Prefix"));
			num += PatchSetter(typeof(MeshFilter), "mesh", Handler("HackerXUnityPatches", "MeshSharedPatch", "Prefix"));
			num += PatchSetter(typeof(SkinnedMeshRenderer), "sharedMesh", Handler("HackerXUnityPatches", "SkinnedMeshPatch", "Prefix"));
			num += PatchSetter(typeof(Renderer), "sharedMaterial", Handler("HackerXUnityPatches", "RendererMaterialPatch", "Prefix"));
			num += PatchSetter(typeof(Renderer), "sharedMaterials", Handler("HackerXUnityPatches", "RendererMaterialsPatch", "Prefix"));
			num += PatchSetter(typeof(Renderer), "forceRenderingOff", Handler("HackerXUnityPatches", "RendererForceOffPatch", "Prefix"));
			num += PatchSetter(typeof(Renderer), "enabled", Handler("HackerXUnityPatches", "RendererEnabledPatch", "Prefix"));
			num += PatchSetter(typeof(Rigidbody), "mass", Handler("HackerXUnityPatches", "RigidbodyMassPatch", "Prefix"));
			num += PatchNamed(typeof(Unit), "SetMassMultiplier", Handler("HackerXUnityPatches", "UnitSetMassMultiplierPatch", "Prefix"));
			num += PatchNamed(typeof(RigidbodyHolder), "Start", Handler("HackerXUnityPatches", "RigidbodyHolderStartPatch", "Prefix"), Handler("HackerXUnityPatches", "RigidbodyHolderStartPatch", "Postfix"));
			num += PatchNamed(typeof(Unit), "DestroyUnit", Handler("HackerXPatches", "DestroyUnitPatch", "Prefix"));
			num += PatchNamed(typeof(Unit), "UnfreezeBody", null, Handler("HackerXPatches", "UnfreezeBodyPatch", "Postfix"));
			num += PatchNamed(typeof(Unit), "InitializeUnit", Handler("HackerXPatches", "InitUnitPatch", "Prefix"));
			num += PatchNamed(typeof(Unit), "Start", null, Handler("HackerXPatches", "UnitStartPatch", "Postfix"));
			MethodInfo method2 = typeof(UnitAwakePatch).GetMethod("Postfix", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			num += PatchNamed(typeof(Unit), "Awake", null, method2);
			num += PatchNamed(typeof(HealthHandler), "TakeDamage", Handler("HackerXPatches", "DamagePatch", "Prefix"));
			num += PatchNamed(typeof(Damagable), "TakeDamage", Handler("HackerXPatches", "BaseDamagePatch", "Prefix"));
			num += PatchNamed(typeof(HealthHandler), "SetInvulnerable", Handler("HackerXPatches", "InvulnerabilityPatch", "Prefix"));
			num += PatchNamed(typeof(HealthHandlerClient), "TakeDamage", Handler("HackerXPatches", "ClientDamagePatch", "Prefix"));
			num += PatchNamed(typeof(ReviveStick), "Update", Handler("HackerXPatches", "ReviveStickUpdatePatch", "Prefix"), Handler("HackerXPatches", "ReviveHealthPatch", "Postfix"));
			num += PatchNamed(typeof(ReviveStick), "ReviveAfterTime", Handler("HackerXPatches", "ReviveAfterTimePatch", "Prefix"));
			num += PatchNamed(typeof(MonoBehaviour), "StartCoroutine", Handler("HackerXPatches", "StartCoroutinePatch", "Prefix"));
			num += PatchNamed(typeof(UnitCombinations), "UpdateUnit", null, Handler("HackerXPatches", "CombinationHealthPatch", "Postfix"));
			num += PatchNamed(typeof(CastleFightHouse), "DoUpgrades", null, Handler("HackerXPatches", "CastleHealthPatch", "Postfix"));
			num += PatchNamed(typeof(CopySelf), "DoEffect", null, Handler("HackerXPatches", "CopySelfHealthPatch", "Postfix"));
			num += PatchNamed(typeof(HealthHandler), "Die", Handler("HackerXPatches", "DiePatch", "Prefix"));
			num += PatchSetter(typeof(DataHandler), "Dead", Handler("HackerXPatches", "DeadPatch", "Prefix"));
			num += PatchNamed(typeof(UnitPlacementBrush), "RemoveUnitInternal", Handler("HackerXPatches", "RemoveUnitPatch", "Prefix"));
			num += PatchNamed(typeof(UnitPlacementBrush), "PlaceUnitInternal", Handler("HackerXPatches", "PlaceUnitInternalPatch", "Prefix"));
			num += PatchNamed(typeof(BrushBehaviourBase), "Place", Handler("HackerXPatches", "BrushPlacePatch", "Prefix"));
			num += PatchNamed(typeof(TeamSystem), "RemoveEntity", Handler("HackerXPatches", "TeamRemovePatch", "Prefix"));
			num += PatchNamed(typeof(HealthHandler), "Update", Handler("HackerXPatches", "HealthUpdatePatch", "Prefix"));
			num += PatchNamed(typeof(DataHandler), "BatchedUpdate", null, Handler("HackerXPatches", "DataBatchedUpdatePatch", "Postfix"));
			num += PatchNamed(typeof(DataHandler), "BatchedFixedUpdate", Handler("HackerXPatches", "DataBatchedFixedUpdatePatch", "Prefix"), Handler("HackerXPatches", "DataBatchedFixedUpdatePatch", "Postfix"));
			num += PatchNamed(typeof(GroundChecker), "OnCollisionEnter", null, Handler("HackerXPatches", "GroundCheckerCollisionPatch", "Postfix"));
			num += PatchNamed(typeof(GroundChecker), "OnCollisionStay", null, Handler("HackerXPatches", "GroundCheckerCollisionPatch", "Postfix"));
			num += PatchNamed(typeof(Balance), "Fall", Handler("HackerXPatches", "BalanceFallPatch", "Prefix"));
			num += PatchNamed(typeof(StunEffect), "DoEffect", Handler("HackerXPatches", "StunDoEffectPatch", "Prefix"));
			num += PatchNamed(typeof(GravityField), "OnTriggerEnter", Handler("HackerXPatches", "GravityFieldEnterPatch", "Prefix"));
			num += PatchNamed(typeof(GravityField), "OnTriggerExit", Handler("HackerXPatches", "GravityFieldExitPatch", "Prefix"));
			num += PatchNamed(typeof(WeaponHandler), "Start", null, Handler("HackerXPatches", "WeaponStartPatch", "Postfix"));
			num += PatchNamed(typeof(WeaponHandler), "UseHands", null, Handler("HackerXPatches", "UseHandsPatch", "Postfix"));
			num += PatchNamed(typeof(CollisionWeapon), "OnCollisionEnter", Handler("HackerXPatches", "HackerCollisionEnterPatch", "Prefix"), Handler("HackerXPatches", "FistCollisionPatch", "Postfix"));
			num += PatchNamed(typeof(CollisionWeapon), "OnCollisionStay", Handler("HackerXPatches", "HackerCollisionStayPatch", "Prefix"));
			num += PatchNamed(typeof(MeleeWeapon), "Attack", null, Handler("HackerXPatches", "MeleeAttackPatch", "Postfix"));
			num += PatchNamed(typeof(ProjectileHit), "Hit", Handler("HackerXPatches", "ProjectileHitPatch", "Prefix"));
			MethodInfo methodInfo = typeof(ProjectilesSpawnManager).GetMethods(PatchFlags | BindingFlags.DeclaredOnly).FirstOrDefault((MethodInfo m) => m.Name == "SpawnProjectile" && m.ReturnType == typeof(GameObject) && m.GetParameters().Length == 3 && m.GetParameters()[0].ParameterType == typeof(GameObject) && m.GetParameters()[1].ParameterType == typeof(Vector3) && m.GetParameters()[2].ParameterType == typeof(Quaternion));
			MethodInfo methodInfo2 = typeof(ProjectilesSpawnManager).GetMethods(PatchFlags | BindingFlags.DeclaredOnly).FirstOrDefault((MethodInfo m) => m.Name == "SpawnProjectile" && m.ReturnType == typeof(GameObject) && m.GetParameters().Length == 12 && m.GetParameters()[0].ParameterType == typeof(GameObject) && m.GetParameters()[3].ParameterType == typeof(