Decompiled source of ProjectileChargePatch v0.0.1

ProjectileChargePatch.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using GunChargePatch.Extensions;
using GunChargePatch.Extensions.Copied;
using HarmonyLib;
using InControl;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GunChargePatch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GunChargePatch")]
[assembly: AssemblyTitle("GunChargePatch")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GunChargePatch
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.rounds.willuwontu.gunchargepatch", "GunChargePatch", "0.0.4")]
	[BepInProcess("Rounds.exe")]
	public class GunChargePatch : BaseUnityPlugin
	{
		private const string ModId = "com.rounds.willuwontu.gunchargepatch";

		private const string ModName = "GunChargePatch";

		public const string Version = "0.0.4";

		public static GunChargePatch instance { get; private set; }

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			new Harmony("com.rounds.willuwontu.gunchargepatch").PatchAll();
		}

		private void Start()
		{
			ProjectileInit[] array = Resources.FindObjectsOfTypeAll<ProjectileInit>();
			for (int i = 0; i < array.Length; i++)
			{
				GameObject gameObject = ((Component)array[i]).gameObject;
				if (Object.op_Implicit((Object)(object)gameObject.GetComponent<ProjectileInit>()) && !Object.op_Implicit((Object)(object)gameObject.GetComponent<ChargedProjectileInit>()))
				{
					gameObject.AddComponent<ChargedProjectileInit>();
				}
			}
		}
	}
	public class ChargedProjectileInit : MonoBehaviour
	{
		private Gun[] guns;

		[PunRPC]
		internal void RPCA_InitCharge(int senderID, int nrOfProj, float dmgM, float randomSeed, float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
			((Component)this).gameObject.GetComponent<ProjectileInit>().InvokeMethod("RPCA_Init", senderID, nrOfProj, dmgM, randomSeed);
		}

		internal void OFFLINE_InitCharge(int senderID, int nrOfProj, float dmgM, float randomSeed, float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
			((Component)this).gameObject.GetComponent<ProjectileInit>().InvokeMethod("OFFLINE_Init", senderID, nrOfProj, dmgM, randomSeed);
		}

		[PunRPC]
		internal void RPCA_Init_SeparateGunCharge(int senderID, int gunID, int nrOfProj, float dmgM, float randomSeed, float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
			((Component)this).gameObject.GetComponent<ProjectileInit>().InvokeMethod("RPCA_Init_SeparateGun", senderID, gunID, nrOfProj, dmgM, randomSeed);
		}

		internal void OFFLINE_Init_SeparateGunCharge(int senderID, int gunID, int nrOfProj, float dmgM, float randomSeed, float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
			((Component)this).gameObject.GetComponent<ProjectileInit>().InvokeMethod("OFFLINE_Init_SeparateGun", senderID, gunID, nrOfProj, dmgM, randomSeed);
		}

		private Gun GetChildGunWithID(int id, GameObject player)
		{
			if (guns == null)
			{
				guns = player.GetComponentsInChildren<Gun>();
			}
			return guns[id];
		}

		private static Player GetPlayerWithActorAndPlayerIDs(int actorID, int playerID)
		{
			Player result = null;
			foreach (Player player in PlayerManager.instance.players)
			{
				if (player.data.view.ControllerActorNr == actorID && player.playerID == playerID)
				{
					result = player;
					break;
				}
			}
			return result;
		}

		[PunRPC]
		internal void RPCA_Init_noAmmoUseCharge(int senderID, int nrOfProj, float dmgM, float randomSeed, float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
			((Component)this).gameObject.GetComponent<ProjectileInit>().InvokeMethod("RPCA_Init_noAmmoUse", senderID, nrOfProj, dmgM, randomSeed);
		}

		internal void OFFLINE_Init_noAmmoUseCharge(int senderID, int nrOfProj, float dmgM, float randomSeed, float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
			((Component)this).gameObject.GetComponent<ProjectileInit>().InvokeMethod("OFFLINE_Init_noAmmoUse", senderID, nrOfProj, dmgM, randomSeed);
		}

		[PunRPC]
		public void RPCA_SetBulletCharge(float charge)
		{
			((Component)this).gameObject.GetComponent<ProjectileHit>().GetAdditionalData().charge = charge;
		}
	}
}
namespace GunChargePatch.Patches
{
	[HarmonyPatch(typeof(CardInfoDisplayer))]
	internal class CardInfoDisplayer_Patch
	{
		[HarmonyPrefix]
		[HarmonyPatch("DrawCard")]
		private static void StopChargeBreak(ref bool charge)
		{
			charge = false;
		}
	}
	[HarmonyPatch(typeof(GeneralInput))]
	internal class GeneralInput_Patch
	{
		[HarmonyPostfix]
		[HarmonyPriority(900)]
		[HarmonyPatch("Update")]
		private static void AimCorrection(GeneralInput __instance, CharacterData ___data)
		{
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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)
			//IL_00e8: 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)
			if (!Object.op_Implicit((Object)(object)___data) || !___data.view.IsMine || !Object.op_Implicit((Object)(object)___data.weaponHandler) || !Object.op_Implicit((Object)(object)___data.weaponHandler.gun) || !___data.weaponHandler.gun.useCharge)
			{
				return;
			}
			Gun gun = ___data.weaponHandler.gun;
			if (((PlayerActionSet)___data.playerActions).Device == null)
			{
				__instance.aimDirection = MainCam.instance.cam.ScreenToWorldPoint(Input.mousePosition) - ((Component)__instance).transform.position;
				__instance.aimDirection.z = 0f;
				((Vector3)(ref __instance.aimDirection)).Normalize();
				if (Optionshandler.lockMouse)
				{
					try
					{
						__instance.aimDirection = (Vector3)typeof(GeneralInput).InvokeMethod("MakeEightDirections", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[1] { __instance.aimDirection });
					}
					catch (Exception ex)
					{
						Debug.Log((object)"Error during lock mouse.");
						Debug.LogException(ex);
					}
				}
			}
			else
			{
				__instance.aimDirection.x = __instance.aimDirection.x + ((TwoAxisInputControl)___data.playerActions.Aim).X;
				__instance.aimDirection.y = __instance.aimDirection.y + ((TwoAxisInputControl)___data.playerActions.Aim).Y;
				if (Optionshandler.lockStick)
				{
					try
					{
						__instance.aimDirection = (Vector3)typeof(GeneralInput).InvokeMethod("MakeEightDirections", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[1] { __instance.aimDirection });
					}
					catch (Exception ex2)
					{
						Debug.Log((object)"Error during lock stick.");
						Debug.LogException(ex2);
					}
				}
			}
			try
			{
				if (__instance.aimDirection != Vector3.zero)
				{
					__instance.aimDirection += Vector3.up * 0.13f / Mathf.Clamp(gun.projectileSpeed * gun.currentCharge * gun.chargeSpeedTo, 1f, 100f);
				}
				if (__instance.aimDirection != Vector3.zero)
				{
					__instance.lastAimDirection = __instance.aimDirection;
				}
			}
			catch (Exception ex3)
			{
				Debug.Log((object)"Error elsewhere.");
				Debug.LogException(ex3);
			}
		}

		[HarmonyPostfix]
		[HarmonyPriority(300)]
		[HarmonyPatch("Update")]
		private static void AimCorrectionIn0G(GeneralInput __instance, CharacterData ___data)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_01d9: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)___data) || !___data.view.IsMine || !Object.op_Implicit((Object)(object)___data.weaponHandler) || !Object.op_Implicit((Object)(object)___data.weaponHandler.gun) || !___data.weaponHandler.gun.useCharge)
			{
				return;
			}
			Gun gun = ___data.weaponHandler.gun;
			if (!gun.useCharge || gun.gravity > 0f)
			{
				return;
			}
			if (((PlayerActionSet)___data.playerActions).Device == null)
			{
				__instance.aimDirection = MainCam.instance.cam.ScreenToWorldPoint(Input.mousePosition) - ((Component)__instance).transform.position;
				__instance.aimDirection.z = 0f;
				((Vector3)(ref __instance.aimDirection)).Normalize();
				if (Optionshandler.lockMouse)
				{
					__instance.aimDirection = (Vector3)typeof(GeneralInput).InvokeMethod("MakeEightDirections", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[1] { __instance.aimDirection });
				}
			}
			else
			{
				__instance.aimDirection.x = __instance.aimDirection.x + ((TwoAxisInputControl)___data.playerActions.Aim).X;
				__instance.aimDirection.y = __instance.aimDirection.y + ((TwoAxisInputControl)___data.playerActions.Aim).Y;
				if (Optionshandler.lockStick)
				{
					__instance.aimDirection = (Vector3)typeof(GeneralInput).InvokeMethod("MakeEightDirections", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[1] { __instance.aimDirection });
				}
			}
			if (__instance.aimDirection != Vector3.zero)
			{
				__instance.lastAimDirection = __instance.aimDirection;
			}
		}
	}
	[HarmonyPatch(typeof(Gun))]
	internal class GunPatchDefaultStats
	{
		[HarmonyPostfix]
		[HarmonyPatch("ResetStats")]
		private static void SetOnReset(Gun __instance)
		{
			__instance.chargeDamageMultiplier = 1f;
			__instance.chargeEvenSpreadTo = 0f;
			__instance.chargeRecoilTo = 1f;
			__instance.chargeSpeedTo = 1f;
			__instance.chargeSpreadTo = 0f;
		}

		[HarmonyPatch(typeof(Gun))]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(new Type[] { })]
		[HarmonyPostfix]
		private static void SetOnCreate(Gun __instance)
		{
			__instance.chargeDamageMultiplier = 1f;
			__instance.chargeEvenSpreadTo = 0f;
			__instance.chargeRecoilTo = 1f;
			__instance.chargeSpeedTo = 1f;
			__instance.chargeSpreadTo = 0f;
		}
	}
	[HarmonyPatch(typeof(ApplyCardStats))]
	internal class ApplyCardStatsPatchAdjustments
	{
		[HarmonyPostfix]
		[HarmonyPatch("CopyGunStats")]
		private static void SetOnReset(ApplyCardStats __instance, Gun copyFromGun, Gun copyToGun)
		{
			copyToGun.chargeRecoilTo -= copyFromGun.chargeRecoilTo;
			copyToGun.chargeRecoilTo *= copyFromGun.chargeRecoilTo;
		}
	}
	[HarmonyPatch(typeof(ApplyCardStats))]
	internal class CheckBulletsAfterGettingCards
	{
		[HarmonyPostfix]
		[HarmonyPatch("ApplyStats")]
		private static void SetOnReset(ApplyCardStats __instance)
		{
			ProjectileInit[] array = Resources.FindObjectsOfTypeAll<ProjectileInit>();
			for (int i = 0; i < array.Length; i++)
			{
				GameObject gameObject = ((Component)array[i]).gameObject;
				if (Object.op_Implicit((Object)(object)gameObject.GetComponent<ProjectileInit>()) && !Object.op_Implicit((Object)(object)gameObject.GetComponent<ChargedProjectileInit>()))
				{
					gameObject.AddComponent<ChargedProjectileInit>();
				}
			}
		}
	}
	[HarmonyPatch(typeof(Gun))]
	internal class Gun_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Attack")]
		[HarmonyPriority(0)]
		private static void ResetCharge(Gun __instance, float charge, bool __result)
		{
			if (__result)
			{
				__instance.currentCharge = 0f;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("ApplyProjectileStats")]
		[HarmonyPriority(800)]
		private static void AdjustBulletSpeed(Gun __instance, GameObject obj)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.useCharge)
			{
				ProjectileHit component = obj.GetComponent<ProjectileHit>();
				MoveTransform component2 = obj.GetComponent<MoveTransform>();
				float charge = component.GetAdditionalData().charge;
				component2.localForce *= charge * __instance.chargeSpeedTo;
				component.damage *= charge * __instance.chargeDamageMultiplier;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void ChargeWeaponCD(Gun __instance, ref float __result)
		{
			if (__instance.useCharge)
			{
				__result = 0.1f;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("DoAttacks")]
		[HarmonyPriority(300)]
		private static void SetAttacks(Gun __instance, float charge, ref int attacks)
		{
			if (__instance.useCharge)
			{
				attacks = Mathf.Clamp(Mathf.RoundToInt(charge * (float)__instance.GetAdditionalData().attacksAtFullCharge), 1, 10);
			}
		}
	}
	[HarmonyPatch]
	internal class Gun_PatchTranspiler
	{
		private static CodeInstruction[] OriginalFireBurstCode;

		private static CodeInstruction[] NewFireBurstCode;

		private static Type GetNestedIDoBlockTransitionType()
		{
			Type[] nestedTypes = typeof(Gun).GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic);
			Type result = null;
			Type[] array = nestedTypes;
			foreach (Type type in array)
			{
				if (type.Name.Contains("FireBurst"))
				{
					result = type;
					break;
				}
			}
			return result;
		}

		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(GetNestedIDoBlockTransitionType(), "MoveNext", (Type[])null, (Type[])null);
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Expected O, but got Unknown
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Expected O, but got Unknown
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Expected O, but got Unknown
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Expected O, but got Unknown
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Expected O, but got Unknown
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Expected O, but got Unknown
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Expected O, but got Unknown
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Expected O, but got Unknown
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Expected O, but got Unknown
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: Expected O, but got Unknown
			//IL_0538: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Expected O, but got Unknown
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Expected O, but got Unknown
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Expected O, but got Unknown
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Expected O, but got Unknown
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0596: Expected O, but got Unknown
			//IL_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a7: Expected O, but got Unknown
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0837: Expected O, but got Unknown
			//IL_084c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0856: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			OriginalFireBurstCode = list.ToArray();
			MethodInfo methodInfo = AccessTools.Method(typeof(GameObject), "GetComponent", (Type[])null, new Type[1] { typeof(ProjectileInit) });
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(ProjectileInit), "OFFLINE_Init", new Type[4]
			{
				typeof(int),
				typeof(int),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo2);
			MethodInfo methodInfo3 = AccessTools.Method(typeof(ProjectileInit), "OFFLINE_Init_noAmmoUse", new Type[4]
			{
				typeof(int),
				typeof(int),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo3);
			MethodInfo methodInfo4 = AccessTools.Method(typeof(ProjectileInit), "OFFLINE_Init_SeparateGun", new Type[5]
			{
				typeof(int),
				typeof(int),
				typeof(int),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo4);
			MethodInfo methodInfo5 = AccessTools.Method(typeof(GameObject), "GetComponent", (Type[])null, new Type[1] { typeof(PhotonView) });
			MethodInfo methodInfo6 = AccessTools.Method(typeof(PhotonView), "RPC", new Type[3]
			{
				typeof(string),
				typeof(RpcTarget),
				typeof(object[])
			}, (Type[])null);
			AccessTools.Field(typeof(Gun), "holdable");
			AccessTools.Field(typeof(Holdable), "holder");
			AccessTools.Field(typeof(CharacterData), "player");
			FieldInfo fieldInfo = AccessTools.Field(typeof(Gun), "player");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(Player), "playerID");
			MethodInfo methodInfo7 = AccessTools.Method(typeof(GameObject), "GetComponent", (Type[])null, new Type[1] { typeof(ChargedProjectileInit) });
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo7);
			MethodInfo methodInfo8 = AccessTools.Method(typeof(Debug), "Log", new Type[1] { typeof(object) }, (Type[])null);
			CodeInstruction item = new CodeInstruction(OpCodes.Call, (object)methodInfo8);
			new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(list[25].opcode, list[25].operand),
				new CodeInstruction(OpCodes.Conv_R4, (object)null),
				new CodeInstruction(list[293].opcode, list[293].operand),
				item
			};
			MethodInfo methodInfo9 = AccessTools.Method(typeof(ChargedProjectileInit), "OFFLINE_InitCharge", new Type[5]
			{
				typeof(int),
				typeof(int),
				typeof(float),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo9);
			MethodInfo methodInfo10 = AccessTools.Method(typeof(ChargedProjectileInit), "OFFLINE_Init_noAmmoUseCharge", new Type[5]
			{
				typeof(int),
				typeof(int),
				typeof(float),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo10);
			MethodInfo methodInfo11 = AccessTools.Method(typeof(ChargedProjectileInit), "OFFLINE_Init_SeparateGunCharge", new Type[6]
			{
				typeof(int),
				typeof(int),
				typeof(int),
				typeof(float),
				typeof(float),
				typeof(float)
			}, (Type[])null);
			new CodeInstruction(OpCodes.Callvirt, (object)methodInfo11);
			List<CodeInstruction> list2 = new List<CodeInstruction>
			{
				new CodeInstruction(list[24].opcode, list[24].operand),
				new CodeInstruction(list[25].opcode, list[25].operand),
				new CodeInstruction(OpCodes.Conv_R4, (object)null)
			};
			List<CodeInstruction> list3 = new List<CodeInstruction>();
			list3.Add(new CodeInstruction(OpCodes.Dup, (object)null));
			list3.AddRange(list2);
			list3.Add(new CodeInstruction(list[293].opcode, list[293].operand));
			list3.Add(new CodeInstruction(OpCodes.Stelem_Ref, (object)null));
			new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ldloc_1, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo),
				new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo2),
				new CodeInstruction(OpCodes.Box, (object)typeof(int)),
				new CodeInstruction(OpCodes.Stelem_Ref, (object)null)
			};
			Dictionary<string, string> dictionary = new Dictionary<string, string>
			{
				{ "RPCA_Init", "RPCA_InitCharge" },
				{ "RPCA_Init_noAmmoUse", "RPCA_Init_noAmmoUseCharge" },
				{ "RPCA_Init_SeparateGun", "RPCA_Init_SeparateGunCharge" }
			};
			for (int i = 0; i < list.Count(); i++)
			{
				if (list[i].opcode == OpCodes.Callvirt)
				{
					if ((MethodInfo)list[i].operand == methodInfo)
					{
						list[i].operand = methodInfo7;
					}
					if ((MethodInfo)list[i].operand == methodInfo2)
					{
						list[i].operand = methodInfo9;
						list.InsertRange(i, list2);
						i += list2.Count();
					}
					if ((MethodInfo)list[i].operand == methodInfo3)
					{
						list[i].operand = methodInfo10;
						list.InsertRange(i, list2);
						i += list2.Count();
					}
					if ((MethodInfo)list[i].operand == methodInfo4)
					{
						list[i].operand = methodInfo11;
						list.InsertRange(i, list2);
						i += list2.Count();
					}
				}
				if (!(list[i].opcode == OpCodes.Ldstr) || !dictionary.Keys.Contains((string)list[i].operand) || !(list[i - 1].opcode == OpCodes.Callvirt) || !((MethodInfo)list[i - 1].operand == methodInfo5))
				{
					continue;
				}
				list[i].operand = dictionary[(string)list[i].operand];
				for (; list[i].opcode != OpCodes.Newarr; i++)
				{
				}
				int index = i - 1;
				int num = 0;
				for (; !(list[i].opcode == OpCodes.Callvirt) || !((MethodInfo)list[i].operand == methodInfo6); i++)
				{
					if (list[i].opcode == OpCodes.Stelem_Ref)
					{
						num++;
					}
				}
				list.InsertRange(i, list3);
				list.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_I4_S, (object)num));
				num++;
				list[index] = new CodeInstruction(OpCodes.Ldc_I4_S, (object)num);
			}
			NewFireBurstCode = list.ToArray();
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(HealthHandler))]
	internal class HealthHandler_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Revive")]
		private static void ResetCharge(CharacterData ___data)
		{
			___data.weaponHandler.gun.currentCharge = 0f;
		}
	}
	[HarmonyPatch(typeof(WeaponHandler))]
	internal class WeaponHandler_Patch
	{
		[HarmonyPatch("Attack")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> PassCharge(IEnumerable<CodeInstruction> instructions)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			AccessTools.Field(typeof(WeaponHandler), "gun");
			FieldInfo fieldInfo = AccessTools.Field(typeof(Gun), "currentCharge");
			list2.Add(new CodeInstruction(OpCodes.Dup, (object)null));
			list2.Add(new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo));
			list2.Add(new CodeInstruction(OpCodes.Conv_R4, (object)null));
			list.RemoveAt(111);
			list.InsertRange(111, list2);
			return list.AsEnumerable();
		}

		[HarmonyPrefix]
		[HarmonyPatch("Attack")]
		private static void DefaultChargingMethod(WeaponHandler __instance, CharacterData ___data)
		{
			if (Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)___data) && Object.op_Implicit((Object)(object)__instance.gun) && __instance.gun.useCharge && ___data.input.shootIsPressed && !___data.dead && (bool)typeof(PlayerVelocity).GetField("simulated", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField).GetValue(___data.playerVel) && 0 < (int)typeof(GunAmmo).GetField("currentAmmo", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField).GetValue(((Component)__instance.gun).GetComponentInChildren<GunAmmo>()))
			{
				__instance.gun.currentCharge = Mathf.Clamp(__instance.gun.currentCharge + TimeHandler.deltaTime / __instance.gun.GetAdditionalData().chargeTime * __instance.gun.GetAdditionalData().maxCharge, 0f, __instance.gun.GetAdditionalData().maxCharge);
			}
		}
	}
}
namespace GunChargePatch.Extensions
{
	public class GunAdditionalData
	{
		public float maxCharge = 1f;

		public float chargeTime = 1f;

		public bool useDefaultChargingMethod = true;

		public int attacksAtFullCharge = 1;

		public GunAdditionalData()
		{
			maxCharge = 1f;
			chargeTime = 1f;
			useDefaultChargingMethod = true;
			attacksAtFullCharge = 1;
		}
	}
	public static class GunExtensions
	{
		private static readonly ConditionalWeakTable<Gun, GunAdditionalData> additionalData = new ConditionalWeakTable<Gun, GunAdditionalData>();

		public static GunAdditionalData GetAdditionalData(this Gun instance)
		{
			return additionalData.GetOrCreateValue(instance);
		}
	}
	[HarmonyPatch(typeof(Gun), "ResetStats")]
	internal class GunPatchResetStats
	{
		private static void Prefix(Gun __instance)
		{
			__instance.GetAdditionalData().maxCharge = 1f;
			__instance.GetAdditionalData().chargeTime = 1f;
			__instance.GetAdditionalData().useDefaultChargingMethod = true;
			__instance.GetAdditionalData().attacksAtFullCharge = 1;
		}
	}
	public static class PlayerManagerExtension
	{
		public static Player GetPlayerWithID(this PlayerManager playerManager, int playerID)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			return (Player)typeof(PlayerManager).InvokeMember("GetPlayerWithID", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, playerManager, new object[1] { playerID });
		}

		public static Player GetPlayerWithActorID(this PlayerManager playerManager, int actorID)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			return (Player)typeof(PlayerManager).InvokeMember("GetPlayerWithActorID", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, playerManager, new object[1] { actorID });
		}
	}
	internal class ProjectileHitAdditionalData
	{
		public float charge;
	}
	public static class ProjectileHitExtensions
	{
		private static readonly ConditionalWeakTable<ProjectileHit, ProjectileHitAdditionalData> additionalData = new ConditionalWeakTable<ProjectileHit, ProjectileHitAdditionalData>();

		internal static ProjectileHitAdditionalData GetAdditionalData(this ProjectileHit instance)
		{
			return additionalData.GetOrCreateValue(instance);
		}

		public static float GetBulletCharge(this ProjectileHit instance)
		{
			return instance.GetAdditionalData().charge;
		}
	}
}
namespace GunChargePatch.Extensions.Copied
{
	public static class ExtensionMethods
	{
		public static MethodInfo GetMethodInfo(Type type, string methodName)
		{
			MethodInfo methodInfo = null;
			do
			{
				methodInfo = type.GetMethod(methodName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				type = type.BaseType;
			}
			while (methodInfo == null && type != null);
			return methodInfo;
		}

		public static object InvokeMethod(this object obj, string methodName, params object[] arguments)
		{
			if (obj == null)
			{
				throw new ArgumentNullException("obj");
			}
			Type type = obj.GetType();
			MethodInfo methodInfo = GetMethodInfo(type, methodName);
			if (methodInfo == null)
			{
				throw new ArgumentOutOfRangeException("propertyName", $"Couldn't find property {methodName} in type {type.FullName}");
			}
			return methodInfo.Invoke(obj, arguments);
		}

		public static MethodInfo GetMethodInfo(Type type, string methodName, Type[] parameters)
		{
			MethodInfo methodInfo = null;
			do
			{
				methodInfo = type.GetMethod(methodName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameters, null);
				type = type.BaseType;
			}
			while (methodInfo == null && type != null);
			return methodInfo;
		}

		public static object InvokeMethod(this object obj, string methodName, Type[] argumentOrder, params object[] arguments)
		{
			if (obj == null)
			{
				throw new ArgumentNullException("obj");
			}
			Type type = obj.GetType();
			MethodInfo methodInfo = GetMethodInfo(type, methodName, argumentOrder);
			if (methodInfo == null)
			{
				throw new ArgumentOutOfRangeException("propertyName", $"Couldn't find property {methodName} in type {type.FullName}");
			}
			return methodInfo.Invoke(obj, arguments);
		}

		public static FieldInfo GetFieldInfo(Type type, string fieldName)
		{
			FieldInfo fieldInfo = null;
			do
			{
				fieldInfo = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				type = type.BaseType;
			}
			while (fieldInfo == null && type != null);
			return fieldInfo;
		}

		public static object GetFieldValue(this object obj, string fieldName)
		{
			if (obj == null)
			{
				throw new ArgumentNullException("obj");
			}
			Type type = obj.GetType();
			FieldInfo fieldInfo = GetFieldInfo(type, fieldName);
			if (fieldInfo == null)
			{
				throw new ArgumentOutOfRangeException("propertyName", $"Couldn't find property {fieldName} in type {type.FullName}");
			}
			return fieldInfo.GetValue(obj);
		}

		public static void SetFieldValue(this object obj, string fieldName, object val)
		{
			if (obj == null)
			{
				throw new ArgumentNullException("obj");
			}
			Type type = obj.GetType();
			FieldInfo fieldInfo = GetFieldInfo(type, fieldName);
			if (fieldInfo == null)
			{
				throw new ArgumentOutOfRangeException("propertyName", $"Couldn't find property {fieldName} in type {type.FullName}");
			}
			fieldInfo.SetValue(obj, val);
		}

		public static PropertyInfo GetPropertyInfo(Type type, string propertyName)
		{
			PropertyInfo propertyInfo = null;
			do
			{
				propertyInfo = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				type = type.BaseType;
			}
			while (propertyInfo == null && type != null);
			return propertyInfo;
		}

		public static object GetPropertyValue(this object obj, string propertyName)
		{
			if (obj == null)
			{
				throw new ArgumentNullException("obj");
			}
			Type type = obj.GetType();
			PropertyInfo propertyInfo = GetPropertyInfo(type, propertyName);
			if (propertyInfo == null)
			{
				throw new ArgumentOutOfRangeException("propertyName", $"Couldn't find property {propertyName} in type {type.FullName}");
			}
			return propertyInfo.GetValue(obj, null);
		}

		public static void SetPropertyValue(this object obj, string propertyName, object val)
		{
			if (obj == null)
			{
				throw new ArgumentNullException("obj");
			}
			Type type = obj.GetType();
			PropertyInfo propertyInfo = GetPropertyInfo(type, propertyName);
			if (propertyInfo == null)
			{
				throw new ArgumentOutOfRangeException("propertyName", $"Couldn't find property {propertyName} in type {type.FullName}");
			}
			propertyInfo.SetValue(obj, val, null);
		}

		public static object Cast(this Type Type, object data)
		{
			ParameterExpression parameterExpression = Expression.Parameter(typeof(object), "data");
			return Expression.Lambda(Expression.Block(Expression.Convert(Expression.Convert(parameterExpression, data.GetType()), Type)), parameterExpression).Compile().DynamicInvoke(data);
		}
	}
}