Decompiled source of Receiver 2 Modding Kit v1.5.0

Receiver2ModdingKit.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using FMOD;
using FMOD.Studio;
using FMODUnity;
using HarmonyLib;
using ImGuiNET;
using Mono.Cecil;
using MonoMod.Utils.Cil;
using Receiver2;
using Receiver2ModdingKit.CustomSounds;
using Receiver2ModdingKit.Editor;
using Receiver2ModdingKit.Gamemodes;
using Receiver2ModdingKit.Helpers;
using Receiver2ModdingKit.ModInstaller;
using Receiver2ModdingKit.Thunderstore;
using Rewired;
using RewiredConsts;
using SimpleJSON;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Wolfire;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Receiver2ModdingKit
{
	internal class EditorInput
	{
		public static bool GetKeyDown(KeyCode key)
		{
			return false;
		}

		public static bool GetKeyUp(KeyCode key)
		{
			return false;
		}

		public static bool GetKey(KeyCode key)
		{
			return false;
		}

		public static Vector3 GetMousePos()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.zero;
		}

		public static Ray MouseRay()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return default(Ray);
		}
	}
	public static class Extensions
	{
		internal static JSONObject current_gun_data;

		internal static bool lah_force_bullet_display;

		internal static Queue<Tuple<PoseSpring, float>> pose_spring_overrides = new Queue<Tuple<PoseSpring, float>>();

		internal static bool unlock_cursor;

		internal static bool confine_cursor;

		internal static bool freeze_camera_rotation;

		internal static Type konType = null;

		public static Harmony getConsoleColorHarmonyInstance;

		public static Harmony logEventArgsToStringHarmonyInstance;

		public static ConsoleColor BackgroundColor
		{
			get
			{
				return (ConsoleColor)(konType?.GetProperty("BackgroundColor").GetMethod.Invoke(null, null));
			}
			set
			{
				konType?.GetProperty("BackgroundColor").SetMethod.Invoke(null, new object[1] { value });
			}
		}

		public static ShellCasingScript GetBullet(this LocalAimHandler lah, Preset cartridge_dimension)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected I4, but got Unknown
			return lah.GetBullet((Preset[])(object)new Preset[1] { (Preset)(int)cartridge_dimension });
		}

		public static ShellCasingScript GetBullet(this LocalAimHandler lah, uint cartridge_dimension)
		{
			return lah.GetBullet((Preset[])(object)new Preset[1] { (Preset)cartridge_dimension });
		}

		public static ShellCasingScript GetBullet(this LocalAimHandler lah, Preset[] cartridge_dimensions)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			if ((Object)(object)lah == (Object)null)
			{
				Debug.LogError((object)"(Extension) LocalAimHandler.GetBullet(): This LocalAimHandler instance is null");
				return null;
			}
			if (cartridge_dimensions == null)
			{
				Debug.LogError((object)"(Extension) LocalAimHandler.GetBullet(): You have to provide a CartridgeSpec array");
				return null;
			}
			object obj = ReflectionManager.LAH_Get_Last_Bullet.Invoke(lah, new object[1] { cartridge_dimensions });
			if (obj == null)
			{
				return null;
			}
			return (ShellCasingScript)ReflectionManager.LAH_BulletInventory_item.GetValue(obj);
		}

		public static ShellCasingScript GetBullet(this LocalAimHandler lah, uint[] cartridge_dimensions)
		{
			return lah.GetBullet(cartridge_dimensions.Cast<Preset>().ToArray());
		}

		public static void ShowBullets(this LocalAimHandler lah, bool show_bullets)
		{
			lah_force_bullet_display = show_bullets;
		}

		public static void ForceCursorUnlock(bool unlock, bool confine)
		{
			unlock_cursor = unlock;
			confine_cursor = confine;
		}

		public static void ShakeBullets(this LocalAimHandler lah)
		{
			if ((Object)(object)lah != (Object)null)
			{
				ReflectionManager.LAH_bullet_shake_time.SetValue(lah, Time.time);
			}
		}

		public static float GetSpringState(this LocalAimHandler lah, PoseSpring spring)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)lah == (Object)null)
			{
				Debug.LogError((object)"(Extension) LocalAimHandler.GetSpringState(): This LocalAimHandler instance is null");
				return 0f;
			}
			return ((Spring)ReflectionManager.LAH_pose_springs[spring].GetValue(lah)).state;
		}

		public static void OverrideSpringState(this LocalAimHandler lah, PoseSpring spring, float amount)
		{
			pose_spring_overrides.Enqueue(new Tuple<PoseSpring, float>(spring, amount));
		}

		public static bool TryGetChild(this DirectoryInfo dir, string child_directory_name, out DirectoryInfo child_directory)
		{
			string path = Path.Combine(dir.FullName, child_directory_name);
			child_directory = new DirectoryInfo(path);
			return Directory.Exists(path);
		}

		public static void Disable(this ActiveItem active_item)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			active_item.item_type = (Type)6;
		}

		public static void SetItemSpawn(this ActiveItem active_item, InventoryItem item, JSONObject persistentData = null)
		{
			active_item.SetItemSpawn(((Object)(object)item != (Object)null) ? item.InternalName : "", persistentData);
		}

		public static void SetItemSpawn(this ActiveItem active_item, string item_internal_name, JSONObject persistentData = null)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			active_item.item_type = (Type)11;
			active_item.internal_name = item_internal_name;
			if ((JSONNode)(object)persistentData != (object)null)
			{
				active_item.persistent_data = persistentData;
			}
		}

		public static bool AddItemsToSpawnList(this ReceiverCoreScript core_script, params InventoryItem[] items)
		{
			if (ModLoader.rcs_prefab_list_locked)
			{
				ModLoader.prefab_list_queue.AddRange(items);
				return false;
			}
			core_script.generic_prefabs = core_script.generic_prefabs.Concat(items).ToArray();
			return true;
		}

		public static JSONObject GetCheckpointData(this ReceiverCoreScript core_script)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return (JSONObject)(((object)current_gun_data) ?? ((object)new JSONObject()));
		}

		public static void RemovePersistentListeners(this UnityEventBase unity_event)
		{
			if (unity_event.GetPersistentEventCount() != 0)
			{
				object value = ReflectionManager.UEB_persistent_calls.GetValue(unity_event);
				ReflectionManager.PCG_Clear.Invoke(value, new object[0]);
			}
		}

		public static void MoveTo(this FileInfo source_file, string destination_file, bool overwrite)
		{
			if (overwrite && File.Exists(destination_file))
			{
				File.Delete(destination_file);
			}
			source_file.MoveTo(destination_file);
		}

		public static BepInPlugin GetBepInAttribute(this BaseUnityPlugin plugin)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			return (BepInPlugin)Attribute.GetCustomAttribute(((object)plugin).GetType(), typeof(BepInPlugin));
		}

		public static bool TryFindObjectOfType<T>(out T result) where T : Object
		{
			return (Object)(object)(result = Object.FindObjectOfType<T>()) != (Object)null;
		}

		public static bool TryFindObjectsOfType<T>(out T[] result) where T : Object
		{
			return (result = Object.FindObjectsOfType<T>()) != null;
		}

		public static List<CodeInstruction> ToCodeInstructions(this MethodInfo methodInfo, Dictionary<CodeInstruction, CodeInstruction> replaceInstructionWith = null)
		{
			List<CodeInstruction> originalInstructions = PatchProcessor.GetOriginalInstructions((MethodBase)methodInfo, (ILGenerator)null);
			if (replaceInstructionWith != null)
			{
				for (int i = 0; i < originalInstructions.Count; i++)
				{
					if (replaceInstructionWith.TryGetValue(originalInstructions[i], out var value))
					{
						originalInstructions[i] = value;
					}
				}
			}
			return originalInstructions;
		}

		public static List<CodeInstruction> ToCodeInstructionsClipLast(this MethodInfo methodInfo, out List<Label> extractedLabels, Dictionary<CodeInstruction, CodeInstruction> replaceInstructionWith = null)
		{
			List<CodeInstruction> originalInstructions = PatchProcessor.GetOriginalInstructions((MethodBase)methodInfo, (ILGenerator)null);
			if (replaceInstructionWith != null)
			{
				for (int i = 0; i < originalInstructions.Count; i++)
				{
					if (replaceInstructionWith.TryGetValue(originalInstructions[i], out var value))
					{
						originalInstructions[i] = value;
					}
				}
			}
			extractedLabels = CodeInstructionExtensions.ExtractLabels(originalInstructions.Last());
			originalInstructions.Remove(originalInstructions.Last());
			return originalInstructions;
		}

		public static void LogWithCustomLevelName(this ManualLogSource logger, object data, string levelName)
		{
			logEventArgsToStringHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.LogEventArgsToStringPatch), (string)null);
			HarmonyManager.LogEventArgsToStringPatch.levelName = levelName;
			logger.Log((LogLevel)696969, data);
			logEventArgsToStringHarmonyInstance.UnpatchSelf();
		}

		public static void LogWithCustomLevelNameAndColor(this ManualLogSource logger, object data, string levelName, ConsoleColor color)
		{
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logEventArgsToStringHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.LogEventArgsToStringPatch), (string)null);
			HarmonyManager.LogEventArgsToStringPatch.levelName = levelName;
			logger.Log((LogLevel)696969, data);
			logEventArgsToStringHarmonyInstance.UnpatchSelf();
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogWithColor(this ManualLogSource logger, LogLevel logLevel, object data, ConsoleColor color)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.Log(logLevel, data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogDebugWithColor(this ManualLogSource logger, object data, ConsoleColor color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (getConsoleColorHarmonyInstance == null)
			{
				getConsoleColorHarmonyInstance = new Harmony("GetConsoleColor");
			}
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.LogDebug(data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogErrorWithColor(this ManualLogSource logger, object data, ConsoleColor color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (getConsoleColorHarmonyInstance == null)
			{
				getConsoleColorHarmonyInstance = new Harmony("GetConsoleColor");
			}
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.LogError(data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogFatalWithColor(this ManualLogSource logger, object data, ConsoleColor color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (getConsoleColorHarmonyInstance == null)
			{
				getConsoleColorHarmonyInstance = new Harmony("GetConsoleColor");
			}
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.LogFatal(data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogInfoWithColor(this ManualLogSource logger, object data, ConsoleColor color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (getConsoleColorHarmonyInstance == null)
			{
				getConsoleColorHarmonyInstance = new Harmony("GetConsoleColor");
			}
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.LogInfo(data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogMessageWithColor(this ManualLogSource logger, object data, ConsoleColor color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (getConsoleColorHarmonyInstance == null)
			{
				getConsoleColorHarmonyInstance = new Harmony("GetConsoleColor");
			}
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.LogMessage(data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}

		public static void LogWarningWithColor(this ManualLogSource logger, object data, ConsoleColor color)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (getConsoleColorHarmonyInstance == null)
			{
				getConsoleColorHarmonyInstance = new Harmony("GetConsoleColor");
			}
			getConsoleColorHarmonyInstance = Harmony.CreateAndPatchAll(typeof(HarmonyManager.GetConsoleColorPatch), (string)null);
			HarmonyManager.GetConsoleColorPatch.consoleColor = color;
			logger.LogWarning(data);
			getConsoleColorHarmonyInstance.UnpatchSelf();
		}
	}
	public static class HarmonyManager
	{
		internal static class HarmonyInstances
		{
			public static Harmony Core;

			public static Harmony Transpilers;

			public static Harmony DebugPatches;

			public static Harmony Thunderstore;

			public static Harmony CustomSounds;

			public static Harmony ModHelpEntry;

			public static Harmony ModGameMode;
		}

		private static class Transpilers
		{
			private static GameModeMusicSpec current_working_music_spec;

			[HarmonyPatch(typeof(GunScript), "Update")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> GunScriptTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Expected O, but got Unknown
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Expected O, but got Unknown
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Expected O, but got Unknown
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(GunScript), "gun_model"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)).Advance().InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0, (object)null))
					.InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModGunScript), "UpdateModGun", (Type[])null, (Type[])null)))
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(GunScript), "UpdateSlide")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> GunScriptSlideTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(GunScript), "AccelFromChangeAndTime", (Type[])null, (Type[])null), (string)null)).SetOperandAndAdvance(AccessTools.Method(typeof(ModGunScript), "CalculateSlideAcceleration", (Type[])null, (Type[])null)).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(GunScript), "AccelFromChangeAndTime", (Type[])null, (Type[])null), (string)null))
					.SetOperandAndAdvance(AccessTools.Method(typeof(ModGunScript), "CalculateSlideAccelerationTime", (Type[])null, (Type[])null))
					.RemoveInstructions(2)
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(RuntimeTileLevelGenerator), "PopulateItems")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> PopulateItemsTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(GunScript), "gun_type"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null)).SetOperandAndAdvance(AccessTools.Field(typeof(GunScript), "magazine_root_types")).InsertAndAdvance(new CodeInstruction(OpCodes.Ldlen, (object)null))
					.SetOpcodeAndAdvance(OpCodes.Ldc_I4_0)
					.SetOpcodeAndAdvance(OpCodes.Bne_Un_S)
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(LocalAimHandler), "HandleGunControls")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> LAHGunControlsTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Expected O, but got Unknown
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Expected O, but got Unknown
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Expected O, but got Unknown
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(GunScript), "gun_model"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_5, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)).Advance().SetOperandAndAdvance(AccessTools.Field(typeof(GunScript), "slide_lock_is_safety"))
					.SetOpcodeAndAdvance(OpCodes.Ldc_I4_1)
					.MatchForward(false, new CodeMatch((OpCode?)OpCodes.Leave, (object)null, (string)null))
					.Advance()
					.Insert(new CodeInstruction(OpCodes.Nop, (object)null))
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(LocalAimHandler), "UpdateLooseBulletDisplay")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> LAHBulletDisplayTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Expected O, but got Unknown
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Expected O, but got Unknown
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Expected O, but got Unknown
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Expected O, but got Unknown
				SmartCodeMatcher smartCodeMatcher = new SmartCodeMatcher(instructions).MatchForward(true, new CodeMatch((OpCode?)OpCodes.Ldnull, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Object), "op_Equality", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Brtrue, (object)null, (string)null));
				if (smartCodeMatcher.IsValid)
				{
					CodeInstruction instruction = smartCodeMatcher.Instruction;
					smartCodeMatcher.Start().MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(LocalAimHandler), "get_IsHoldingMagazine", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)).InsertAndAdvance(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Extensions), "lah_force_bullet_display")))
						.Insert(instruction);
				}
				return smartCodeMatcher.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(LocalAimHandler), "HandleGunControls")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> LAHHandleGunControlsTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Expected O, but got Unknown
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Expected O, but got Unknown
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Expected O, but got Unknown
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Expected O, but got Unknown
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Expected O, but got Unknown
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Expected O, but got Unknown
				//IL_014a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Expected O, but got Unknown
				//IL_0186: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Expected O, but got Unknown
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a4: Expected O, but got Unknown
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Expected O, but got Unknown
				//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e8: Expected O, but got Unknown
				//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Expected O, but got Unknown
				SmartCodeMatcher smartCodeMatcher = new SmartCodeMatcher(instructions, generator).MatchForward(true, new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(GunScript), "mag_seated_wrong"), (string)null)).MatchBack(true, new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null)).Advance()
					.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_1, (object)null), new CodeInstruction(OpCodes.Isinst, (object)typeof(ModGunScript)))
					.Insert(OpCodes.Call, (object)AccessTools.Method(typeof(Vector3), "op_Multiply", new Type[2]
					{
						typeof(Vector3),
						typeof(float)
					}, (Type[])null))
					.CreateBranch(OpCodes.Brfalse_S, (CodeInstruction[])(object)new CodeInstruction[2]
					{
						new CodeInstruction(OpCodes.Ldarg_1, (object)null),
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModGunScript), "GetMagSmackStrength", (Type[])null, (Type[])null))
					}, (CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Ldc_R4, (object)1f)
					});
				LocalBuilder localBuilder = generator.DeclareLocal(typeof(Vector3));
				smartCodeMatcher.Advance().InsertAndAdvance(new CodeInstruction(OpCodes.Stloc, (object)localBuilder.LocalIndex), new CodeInstruction(OpCodes.Ldloca, (object)localBuilder.LocalIndex), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Time), "get_time", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(Vector3), "z")), new CodeInstruction(OpCodes.Ldloc, (object)localBuilder.LocalIndex));
				return smartCodeMatcher.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(LocalAimHandler), "Update")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> LAHUpdateXRayTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Expected O, but got Unknown
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Expected O, but got Unknown
				return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(LocalAimHandler), "inspect_x_ray_timer"), (string)null)
				}).Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Time), "get_timeScale", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Div, (object)null)
				})
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(MagazineScript), "UpdateRoundPositions")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> MagazineFollowerTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(true, new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)).Advance(-1).RemoveInstruction()
					.MatchForward(false, new CodeMatch((OpCode?)OpCodes.Sub, (object)null, (string)null))
					.RemoveInstruction()
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(MenuManagerScript), "Update")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> ModGameModeSupressMenu(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Expected O, but got Unknown
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Expected O, but got Unknown
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Cursor), "set_visible", (Type[])null, (Type[])null), (string)null)).SetInstruction(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(ModGameModeManager), "DisplayGameModeMenu"))).Advance(2)
					.SetInstruction(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(ModGameModeManager), "DisplayGameModeMenu")))
					.Advance()
					.Insert(new CodeInstruction(OpCodes.Ldc_I4_0, (object)null), new CodeInstruction(OpCodes.Ceq, (object)null))
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(MusicScript), "Update")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> ModGameModeMusic(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Expected O, but got Unknown
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Expected O, but got Unknown
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Expected O, but got Unknown
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Expected O, but got Unknown
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Expected O, but got Unknown
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Expected O, but got Unknown
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_014a: Expected O, but got Unknown
				//IL_0165: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Expected O, but got Unknown
				//IL_0179: Unknown result type (might be due to invalid IL or missing references)
				//IL_017f: Expected O, but got Unknown
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Expected O, but got Unknown
				//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b7: Expected O, but got Unknown
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Expected O, but got Unknown
				//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Expected O, but got Unknown
				//IL_0227: Unknown result type (might be due to invalid IL or missing references)
				//IL_022d: Expected O, but got Unknown
				//IL_024a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Expected O, but got Unknown
				//IL_026b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0271: Expected O, but got Unknown
				//IL_0279: Unknown result type (might be due to invalid IL or missing references)
				//IL_027f: Expected O, but got Unknown
				//IL_029a: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: Expected O, but got Unknown
				//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c1: Expected O, but got Unknown
				//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e2: Expected O, but got Unknown
				//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f0: Expected O, but got Unknown
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0312: Expected O, but got Unknown
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0334: Expected O, but got Unknown
				//IL_0350: Unknown result type (might be due to invalid IL or missing references)
				//IL_0356: Expected O, but got Unknown
				//IL_035f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0365: Expected O, but got Unknown
				//IL_0381: Unknown result type (might be due to invalid IL or missing references)
				//IL_0387: Expected O, but got Unknown
				//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a9: Expected O, but got Unknown
				//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_03cb: Expected O, but got Unknown
				//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03da: Expected O, but got Unknown
				//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fc: Expected O, but got Unknown
				//IL_0418: Unknown result type (might be due to invalid IL or missing references)
				//IL_041e: Expected O, but got Unknown
				//IL_043a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0440: Expected O, but got Unknown
				//IL_0449: Unknown result type (might be due to invalid IL or missing references)
				//IL_044f: Expected O, but got Unknown
				//IL_0461: Unknown result type (might be due to invalid IL or missing references)
				//IL_0467: Expected O, but got Unknown
				//IL_0483: Unknown result type (might be due to invalid IL or missing references)
				//IL_0489: Expected O, but got Unknown
				SmartCodeMatcher smartCodeMatcher = new SmartCodeMatcher(instructions, generator);
				smartCodeMatcher.MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)1f, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "main_menu"), (string)null));
				smartCodeMatcher.Advance().RemoveInstructions(2).Advance(-1);
				smartCodeMatcher.SetAndAdvance(OpCodes.Ldloc_0, null).InsertAndAdvance(new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(ReceiverCoreScript), "game_mode")), new CodeInstruction(OpCodes.Ldnull, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Object), "op_Inequality", (Type[])null, (Type[])null)));
				smartCodeMatcher.CreateBranch(OpCodes.Brfalse, (CodeInstruction[])(object)new CodeInstruction[4]
				{
					new CodeInstruction(OpCodes.Ldloc_0, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(ReceiverCoreScript), "game_mode")),
					new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameModeBase), "GetGameMode", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(ModGameModeBase), "ModGameMode"))
				}, (CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldc_R4, (object)1f),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "main_menu"))
				});
				smartCodeMatcher.MatchBack(false, new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null));
				CodeInstruction val = new CodeInstruction(smartCodeMatcher.Instruction);
				val.opcode = OpCodes.Bne_Un;
				smartCodeMatcher.Advance(5);
				smartCodeMatcher.InsertAndAdvance(val, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModGameModeManager), "get_CurrentGameMode", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(ModGameModeBase), "GetMusicParams", (Type[])null, (Type[])null)), new CodeInstruction(OpCodes.Stsfld, (object)AccessTools.Field(typeof(Transpilers), "current_working_music_spec")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Transpilers), "current_working_music_spec")), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameModeMusicSpec), "target_global_gain")), new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "target_global_gain")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Transpilers), "current_working_music_spec")), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameModeMusicSpec), "gain_recover_delay")), new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "gain_recover_delay")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Transpilers), "current_working_music_spec")), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameModeMusicSpec), "danger")), new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "danger")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Transpilers), "current_working_music_spec")), new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameModeMusicSpec), "mystical")), new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "mystical")), new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldc_R4, (object)0f), new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(MusicScript), "main_menu")));
				return smartCodeMatcher.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(ReceiverCoreScript), "LoadCheckpoint")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> ModGameModeLoad(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Stloc_3, (object)null, (string)null)).InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModGameModeManager), "ChooseGameModeFromJSON", (Type[])null, (Type[])null))).InstructionEnumeration();
			}

			[HarmonyPatch(typeof(ReceiverCoreScript), "TriggerCheckpoint")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> ModGameModeSave(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Expected O, but got Unknown
				SmartCodeMatcher smartCodeMatcher = new SmartCodeMatcher(instructions);
				smartCodeMatcher.MatchForward(true, new CodeMatch((OpCode?)OpCodes.Constrained, (object)typeof(GameMode), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null));
				smartCodeMatcher.Advance();
				smartCodeMatcher.InsertAndAdvance(OpCodes.Pop);
				smartCodeMatcher.Insert(OpCodes.Call, (object)AccessTools.Method(typeof(ModGameModeManager), "GetGameModeName", (Type[])null, (Type[])null));
				return smartCodeMatcher.InstructionEnumeration();
			}
		}

		private static class DebugTranspilers
		{
			[HarmonyPatch(typeof(MenuManagerScript), "UpdateDeveloperMenu")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> DevMenuTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Expected O, but got Unknown
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Expected O, but got Unknown
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Expected O, but got Unknown
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Expected O, but got Unknown
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0172: Expected O, but got Unknown
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Expected O, but got Unknown
				//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Expected O, but got Unknown
				//IL_0227: Unknown result type (might be due to invalid IL or missing references)
				//IL_022d: Expected O, but got Unknown
				//IL_0255: Unknown result type (might be due to invalid IL or missing references)
				//IL_025b: Expected O, but got Unknown
				SmartCodeMatcher smartCodeMatcher = new SmartCodeMatcher(instructions, generator);
				return smartCodeMatcher.MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"Subtitles", (string)null)).SetAndAdvance(OpCodes.Ldstr, "Tapes Unlock Debug").InsertAndAdvance(new CodeInstruction(OpCodes.Ldstr, (object)""))
					.InsertAndAdvance(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(ModTapeManager), "tapes_debug_window_open")))
					.InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "MenuItem", new Type[3]
					{
						typeof(string),
						typeof(string),
						typeof(bool)
					}, (Type[])null)))
					.InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModTapeManager), "SwitchMenuVisible", (Type[])null, (Type[])null)))
					.Insert(new CodeInstruction(OpCodes.Ldstr, (object)"Subtitles"))
					.Advance(-1)
					.InsertBranch(OpCodes.Brfalse, smartCodeMatcher.Pos + 1)
					.MatchForward(false, new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "EndMainMenuBar", (Type[])null, (Type[])null), (string)null))
					.SetAndAdvance(OpCodes.Ldstr, "Modding")
					.InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "BeginMenu", new Type[1] { typeof(string) }, (Type[])null)))
					.Insert(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "EndMainMenuBar", (Type[])null, (Type[])null)))
					.InsertBranchAndAdvance(OpCodes.Brfalse, smartCodeMatcher.Pos)
					.InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModInfoAsset), "DisplayImGuiControls", (Type[])null, (Type[])null)))
					.InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "EndMenu", (Type[])null, (Type[])null)))
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(AudioManager), "Update")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> AudioDebugMenuTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(ImGui), "End", (Type[])null, (Type[])null), (string)null)).InsertAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ModAudioManager), "DrawImGUIDebug", (Type[])null, (Type[])null))).InstructionEnumeration();
			}
		}

		private static class R2ModManPatches
		{
			[HarmonyPatch(typeof(Locale), "GetTapeSubtitle", new Type[]
			{
				typeof(string),
				typeof(LocaleID)
			})]
			[HarmonyPostfix]
			public static void PatchLocaleSubtitles(string tape_id, LocaleID locale_id, ref TapeSubtitles __result)
			{
				ModTapeManager.TryReplaceSubtitles(tape_id, ref __result);
			}

			[HarmonyPatch(typeof(ReceiverCoreScript), "Awake")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> R2MMCoreTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(false, new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(ReceiverCoreScript), "LoadPersistentData", (Type[])null, (Type[])null), (string)null)).Insert(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Receiver2ModdingKit.Thunderstore.Thunderstore), "InstallGuns", (Type[])null, (Type[])null))).InstructionEnumeration();
			}

			[HarmonyPatch(typeof(TapeManager), "OnEnable")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> R2MMTapesTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Expected O, but got Unknown
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Expected O, but got Unknown
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(true, new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(TapeManager), "tape_prefabs_all"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(List<GameObject>), "get_Count", (Type[])null, (Type[])null), (string)null)).InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0, (object)null)).Insert(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Receiver2ModdingKit.Thunderstore.Thunderstore), "InstallTapes", (Type[])null, (Type[])null)))
					.InstructionEnumeration();
			}

			[HarmonyPatch(typeof(ModulePrefabsList), "OnEnable")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> R2MMTilesTranspiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Expected O, but got Unknown
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Expected O, but got Unknown
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Expected O, but got Unknown
				return new SmartCodeMatcher(instructions).MatchForward(true, new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldlen, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Conv_I4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Blt, (object)null, (string)null)).Advance(2).InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0, (object)null))
					.Insert(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Receiver2ModdingKit.Thunderstore.Thunderstore), "InstallTiles", (Type[])null, (Type[])null)))
					.InstructionEnumeration();
			}
		}

		internal static class GetConsoleColorPatch
		{
			internal static ConsoleColor consoleColor;

			[HarmonyPatch(typeof(LogLevelExtensions), "GetConsoleColor")]
			[HarmonyPostfix]
			internal static void ChangeGetColorResult(ref ConsoleColor __result)
			{
				__result = consoleColor;
			}
		}

		internal static class LogEventArgsToStringPatch
		{
			internal static string levelName;

			[HarmonyPatch(typeof(LogEventArgs), "ToString")]
			[HarmonyPostfix]
			internal static void ChangeLogEventArgsLevel(LogEventArgs __instance, ref string __result)
			{
				__result = $"[{levelName,-7}:{__instance.Source.SourceName,10}] {__instance.Data}";
			}
		}

		private static void DisplayInstructions(CodeMatcher code_matcher, int breadth)
		{
			DisplayInstructions(code_matcher, breadth, (Action<string>)Debug.LogError);
		}

		private static void DisplayInstructions(CodeMatcher code_matcher, int breadth, Action<string> logger)
		{
			int num = Mathf.Max(code_matcher.Pos - breadth, 0);
			int num2 = Mathf.Min(code_matcher.Pos + breadth + 1, code_matcher.Length - 1);
			for (int i = num; i < code_matcher.Pos; i++)
			{
				logger(((object)code_matcher.InstructionAt(i - code_matcher.Pos)).ToString());
			}
			logger(string.Concat(code_matcher.Instruction, " <"));
			for (int j = code_matcher.Pos + 1; j < num2; j++)
			{
				logger(((object)code_matcher.InstructionAt(j - code_matcher.Pos)).ToString());
			}
		}

		[HarmonyPatch(typeof(GunScript), "CanHolster")]
		[HarmonyPrefix]
		private static bool PatchGunHolster(GunScript __instance, ref bool __result)
		{
			if (__instance is ModGunScript modGunScript)
			{
				__result = modGunScript.CanHolster();
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(MenuManagerScript), "Update")]
		[HarmonyPostfix]
		private static void ForceCursorState()
		{
			if (Extensions.unlock_cursor)
			{
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)(Extensions.confine_cursor ? 2 : 0);
			}
		}

		[HarmonyPatch(typeof(MagazineScript), "UpdateRoundPositions")]
		[HarmonyPostfix]
		private static void PatchMagazineRoundPositions(ref MagazineScript __instance)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			if (__instance is DoubleStackMagazine)
			{
				for (int i = 0; i < __instance.NumRounds(); i++)
				{
					ShellCasingScript val = __instance.rounds[i];
					bool flag = i % 2 == 0 == (__instance.rounds.Count % 2 == 0) != __instance.round_position_params.mirror_double_stack;
					((Component)val).transform.localPosition = new Vector3((Vector3.right * ((Component)val).GetComponent<BoxCollider>().size.x * __instance.round_position_params.param_e * (float)((!flag) ? 1 : (-1))).x, ((Component)val).transform.localPosition.y, ((Component)val).transform.localPosition.z);
				}
				if (__instance.extracting)
				{
					ShellCasingScript val2 = __instance.rounds[0];
					float num = Mathf.InverseLerp(Vector3.Dot(((Component)((InventoryItem)__instance).slot).transform.Find("barrel/point_round_entering").position, ((Component)__instance).transform.forward), Vector3.Dot(__instance.round_top.position, ((Component)__instance).transform.forward), Vector3.Dot(((Component)((InventoryItem)__instance).slot).transform.Find("slide/point_chambered_round").position, ((Component)__instance).transform.forward));
					bool flag2 = __instance.rounds.Count % 2 == 0 != __instance.round_position_params.mirror_double_stack;
					((Component)val2).transform.localPosition = new Vector3((((Component)val2).transform.right * ((Component)val2).GetComponent<BoxCollider>().size.x * __instance.round_position_params.param_e * (float)((!flag2) ? 1 : (-1))).x * num, ((Component)val2).transform.localPosition.y, ((Component)val2).transform.localPosition.z);
				}
			}
		}

		[HarmonyPatch(typeof(MagazineScript), "Awake")]
		[HarmonyPostfix]
		private static void UpdateSpringOnAwake(MagazineScript __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance.spring))
			{
				__instance.spring.UpdateScale();
			}
		}

		[HarmonyPatch(typeof(TapesMenuScript), "OnLoad")]
		[HarmonyPrefix]
		private static void PatchTapeMenuLoad()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if ((int)ReceiverCoreScript.Instance().game_mode.GetGameMode() == 3)
			{
				ModTapeManager.PrepareTapesForCompound();
			}
			else
			{
				ModTapeManager.PrepareTapesForGame();
			}
		}

		[HarmonyPatch(typeof(TapesMenuScript), "CreateMenuEntries")]
		[HarmonyPrefix]
		private static void PrePatchTapeCreateMenuEntries(ref TapesMenuScript __instance)
		{
			ModTapeManager.Init();
			GameObject ecsPrefab = Object.Instantiate<GameObject>(GameObject.Find("ReceiverCore/Menus/Overlay Menu Canvas/Aspect Ratio Fitter/New Pause Menu/Backdrop1/Sub-Menu Layout Group/New Tape Menu/Entries Layout/ScrollableContent Variant/Viewport/Content/Standard/Invalid"));
			__instance.ecsPrefab = ecsPrefab;
		}

		[HarmonyPatch(typeof(TapesMenuScript), "CreateMenuEntries")]
		[HarmonyPostfix]
		private static void PostPatchTapeCreateMenuEntries(TapesMenuScript __instance)
		{
			ModTapeManager.CreateModTapes(__instance);
		}

		[HarmonyPatch(typeof(CartridgeSpec), "SetFromPreset")]
		[HarmonyPrefix]
		private static bool PatchSetCartridge(Preset preset, ref CartridgeSpec __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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 (ModShellCasingScript.mod_cartridges.ContainsKey(preset))
			{
				__instance = ModShellCasingScript.mod_cartridges[preset];
				return false;
			}
			return true;
		}

		public static void PrintMethodIL(Type type, string name, bool original = false)
		{
			PrintMethodIL(AccessTools.Method(type, name, (Type[])null, (Type[])null), original);
		}

		public static void PrintMethodIL(MethodInfo method, bool original = false)
		{
			List<CodeInstruction> list = (original ? PatchProcessor.GetOriginalInstructions((MethodBase)method, (ILGenerator)null) : PatchProcessor.GetCurrentInstructions((MethodBase)method, int.MaxValue, (ILGenerator)null));
			int count = list.Count;
			for (int i = 0; i < count; i++)
			{
				Debug.Log((object)list[i]);
			}
		}

		[HarmonyPatch(typeof(ReceiverCoreScript), "Awake")]
		[HarmonyPostfix]
		private static void PatchCoreAwake(List<GameObject> ___gun_prefabs_all)
		{
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Expected O, but got Unknown
			foreach (GameObject item in ___gun_prefabs_all)
			{
				ModGunScript component = item.GetComponent<ModGunScript>();
				if ((Object)(object)component != (Object)null)
				{
					try
					{
						ModLoader.LoadGun(component);
					}
					catch (Exception ex)
					{
						Debug.LogError((object)("Error happened when loading gun " + ((InventoryItem)component).InternalName));
						Debug.LogError((object)ex);
					}
				}
			}
			ModLoader.Finish();
			ReceiverCoreScript.Instance().player_prefab.GetComponent<PlayerScript>().main_camera_prefab.GetComponent<Camera>().nearClipPlane = 0.02f;
			string[] files = Directory.GetFiles(Path.Combine(Application.persistentDataPath, "Tapes"), "*.srt", SearchOption.AllDirectories);
			for (int i = 0; i < files.Length; i++)
			{
				FileInfo fileInfo = new FileInfo(files[i]);
				ModTapeManager.RegisterSubtitles(fileInfo.Name.Replace(".srt", ""), fileInfo);
			}
			try
			{
				ModdingKitConfig.Initialize();
			}
			catch
			{
				Debug.LogError((object)"An error accured when trying to create settings for the Modding Kit");
			}
			foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
			{
				BankList[] array = allLoadedAssetBundle.LoadAllAssets<BankList>();
				if (array != null)
				{
					ModAudioManager.LoadBanksFromLists(array);
				}
			}
			foreach (TapeContent modTape in ReceiverCoreScript.Instance().tape_loadout_asset.GetModTapes())
			{
				LocaleTapeMenuEntry val = new LocaleTapeMenuEntry();
				val.name = "Invalid";
				val.id_string = modTape.tape_id_string;
				val.title = modTape.title;
				val.description = modTape.text;
				Locale.active_locale_tape_menu_entries_string.Add(modTape.tape_id_string, val);
			}
			Delegate[] invocationList = ModdingKitEvents.ExecuteOnStartup.GetInvocationList();
			foreach (Delegate @delegate in invocationList)
			{
				try
				{
					@delegate.DynamicInvoke();
				}
				catch (Exception ex2)
				{
					Debug.LogError((object)("Failed invoking startup event for method " + @delegate.Method.Name + ";\nDumping stack trace:"));
					Debug.LogError((object)ex2);
				}
			}
		}

		[HarmonyPatch(typeof(ShellCasingScript), "CollisionSound")]
		[HarmonyPrefix]
		private static bool PatchCollisionSound(BallisticMaterial material, ref ShellCasingScript __instance)
		{
			//IL_004e: 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)
			//IL_0054: 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_00a8: Expected I4, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			if (((InventoryItem)__instance).physics_collided || !(__instance is ModShellCasingScript))
			{
				return true;
			}
			ModShellCasingScript modShellCasingScript = (ModShellCasingScript)(object)__instance;
			((InventoryItem)modShellCasingScript).physics_collided = true;
			if (!((ShellCasingScript)modShellCasingScript).IsSpent())
			{
				AudioManager.PlayOneShot3D(modShellCasingScript.sound_bullet_fall_hard, ((Component)modShellCasingScript).transform.position, 1f, 1f);
				return false;
			}
			MaterialLabel material_label = material.material_label;
			switch (material_label - 1)
			{
			case 0:
			case 1:
			case 2:
			case 4:
			case 5:
			case 7:
			case 13:
			case 14:
			case 18:
				AudioManager.PlayOneShot3D(modShellCasingScript.sound_shell_casing_impact_hard, ((Component)modShellCasingScript).transform.position, 1f, 1f);
				break;
			case 3:
			case 6:
			case 8:
			case 9:
			case 10:
			case 11:
			case 12:
				AudioManager.PlayOneShot3D(modShellCasingScript.sound_shell_casing_impact_soft, ((Component)modShellCasingScript).transform.position, 1f, 1f);
				break;
			}
			return false;
		}

		[HarmonyPatch(typeof(MagazineScript), "Awake")]
		[HarmonyPrefix]
		private static void PatchMagazineAwake(MagazineScript __instance)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			SpringCompressInstance[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<SpringCompressInstance>();
			foreach (SpringCompressInstance val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogError((object)("Null spring in magazine \"" + ((InventoryItem)__instance).InternalName + "\""));
				}
				else if (!(((Vector3)(ref val.orig_center)).magnitude > 0f))
				{
					val.orig_center = (((Component)val).transform.InverseTransformPoint(val.new_top.position) + ((Component)val).transform.InverseTransformPoint(val.new_bottom.position)) / 2f;
					val.orig_dist = Vector3.Distance(val.new_top.position, val.new_bottom.position);
				}
			}
		}

		[HarmonyPatch(typeof(RuntimeTileLevelGenerator), "SpawnMagazine")]
		[HarmonyPostfix]
		private static void PatchSpawnMagazine(ref ActiveItem __result)
		{
			if (!ModdingKitEvents.ItemSpawnHandlers.ContainsKey(ReceiverCoreScript.Instance().CurrentLoadout.gun_internal_name))
			{
				return;
			}
			foreach (ModdingKitEvents.OnItemSpawn item in ModdingKitEvents.ItemSpawnHandlers[ReceiverCoreScript.Instance().CurrentLoadout.gun_internal_name])
			{
				try
				{
					if (item(ref __result))
					{
						break;
					}
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("Failed invoking item spawn event method " + item.Method.Name + " for gun " + ReceiverCoreScript.Instance().CurrentLoadout.gun_internal_name + ";\nDumping stack trace:"));
					Debug.LogError((object)ex);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerLoadout), "Deserialize")]
		[HarmonyPrefix]
		private static void PatchDeserializeLoadout(JSONNode jn_root)
		{
			if (jn_root.HasKey("gun_persistent_data"))
			{
				Extensions.current_gun_data = jn_root["gun_persistent_data"].AsObject;
			}
		}

		[HarmonyPatch(typeof(PlayerLoadout), "Serialize")]
		[HarmonyPostfix]
		private static void PatchSerializeLoadout(ref JSONObject __result)
		{
			GunScript val = default(GunScript);
			if ((Object)(object)LocalAimHandler.player_instance != (Object)null && LocalAimHandler.player_instance.TryGetGun(ref val) && val is ModGunScript)
			{
				((JSONNode)__result)["gun_persistent_data"] = (JSONNode)(object)(val as ModGunScript).EncodeJSON((JSONNode)(object)((StorableMonoBehaviour)val).GetPersistentData());
			}
		}

		[HarmonyPatch(typeof(PlayerLoadout), "Reserialize")]
		[HarmonyPostfix]
		private static void PatchReserializeLoadout()
		{
			Extensions.current_gun_data = null;
		}

		[HarmonyPatch(typeof(ReceiverCoreScript), "SpawnGun")]
		[HarmonyPostfix]
		private static void PatchSpawnGun(ref GunScript __result)
		{
			if (!((Object)(object)__result == (Object)null) && __result is ModGunScript && (__result as ModGunScript).OwnData((JSONNode)(object)Extensions.current_gun_data))
			{
				((StorableMonoBehaviour)__result).SetPersistentData((__result as ModGunScript).DecodeJSON((JSONNode)(object)Extensions.current_gun_data));
			}
		}

		[HarmonyPatch(typeof(SettingsMenuScript), "OnKeybindsClick")]
		[HarmonyPostfix]
		private static void PatchOpenKeybinds()
		{
			GunScript val = default(GunScript);
			if (!((Object)(object)LocalAimHandler.player_instance == (Object)null) && LocalAimHandler.player_instance.TryGetGun(ref val))
			{
				KeybindsManager.SetKeybindsActive(val.weapon_group_name);
			}
		}

		[HarmonyPatch(typeof(RankingProgressionGameMode), "EvaluateNextLoadout")]
		[HarmonyPrefix]
		private static void PatchEvaluateLoadout(ref HashSet<string> ___campaign_loadouts)
		{
			string[] loadout_names = ReceiverCoreScript.Instance().weapon_loadout_asset.GetAllLoadoutNames();
			___campaign_loadouts.RemoveWhere((string loadout_name) => !loadout_names.Contains(loadout_name));
		}

		[HarmonyPatch(typeof(ReceiverCoreScript), "GetWorldGenerationConfigurationFromName")]
		[HarmonyPostfix]
		private static void PatchGetWCG(ref WorldGenerationConfiguration __result)
		{
			if (__result != null)
			{
				string[] loadout_names = ReceiverCoreScript.Instance().weapon_loadout_asset.GetAllLoadoutNames();
				__result.loadouts.RemoveAll(delegate(LoadoutValue loadout)
				{
					string name = loadout.name;
					return !loadout_names.Contains(name);
				});
			}
		}

		[HarmonyPatch(typeof(RankingProgressionCampaign), "LoadFile")]
		[HarmonyPostfix]
		private static void PatchLoadCampaign(string filename)
		{
			JSONNode val = ReceiverCoreScript.LoadJSONFile(filename);
			if (val.HasKey("use_modded_guns") && val["use_modded_guns"].AsBool && !ModdedGunsCampaignManager.modded_guns_campaigns.Contains(filename))
			{
				ModdedGunsCampaignManager.modded_guns_campaigns.Add(filename);
			}
		}

		[HarmonyPatch(typeof(WorldGenerationConfiguration), "Deserialize")]
		[HarmonyPostfix]
		private static void PatchLoadWCG(ref WorldGenerationConfiguration __result)
		{
			//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_0104: Expected O, but got Unknown
			GameModeBase game_mode = ReceiverCoreScript.Instance().game_mode;
			if (!((Object)(object)game_mode != (Object)null) || !(game_mode is RankingProgressionGameMode))
			{
				return;
			}
			string item = AccessTools.Field(typeof(RankingProgressionGameMode), "campaign_path").GetValue(game_mode) as string;
			if (!ModdedGunsCampaignManager.modded_guns_campaigns.Contains(item))
			{
				return;
			}
			string[] loadout_names = ReceiverCoreScript.Instance().weapon_loadout_asset.GetAllLoadoutNames();
			__result.loadouts.RemoveAll((LoadoutValue loadout) => !loadout_names.Contains(loadout.name));
			string[] array = loadout_names;
			foreach (string loadout_name in array)
			{
				if (!ReceiverCoreScript.Instance().weapon_loadout_asset.GetLoadoutPrefab(loadout_name).gun_internal_name.StartsWith("wolfire") && !__result.loadouts.Any((LoadoutValue loadout_value) => loadout_value.name == loadout_name))
				{
					__result.loadouts.Add(new LoadoutValue
					{
						name = loadout_name
					});
				}
			}
		}

		[HarmonyPatch(typeof(LocalAimHandler), "StepRecoil")]
		[HarmonyPostfix]
		private static void PatchStepRecoil()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0045: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Hand[] hands = LocalAimHandler.player_instance.hands;
			foreach (Hand val in hands)
			{
				if ((int)val.state == 1)
				{
					ModGunScript modGunScript = val.slot.contents[0] as ModGunScript;
					if ((Object)(object)modGunScript != (Object)null)
					{
						Vector3 value = val.recoil_events.Last();
						Vector2 stepRecoilMultiplier = modGunScript.GetStepRecoilMultiplier();
						value.x *= stepRecoilMultiplier.x;
						value.y *= stepRecoilMultiplier.y;
						val.recoil_events[val.recoil_events.Count - 1] = value;
					}
				}
			}
		}

		[HarmonyPatch(typeof(LocalAimHandler), "HandleGunControls")]
		[HarmonyPostfix]
		private static void PatchHandleSprings()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			LocalAimHandler obj = default(LocalAimHandler);
			if (LocalAimHandler.TryGetInstance(ref obj))
			{
				while (Extensions.pose_spring_overrides.Count > 0)
				{
					Tuple<PoseSpring, float> tuple = Extensions.pose_spring_overrides.Dequeue();
					((Spring)ReflectionManager.LAH_pose_springs[tuple.Item1].GetValue(obj)).target_state = tuple.Item2;
				}
			}
		}

		internal static void UnpatchAll()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			FieldInfo[] fields = typeof(HarmonyInstances).GetFields();
			for (int i = 0; i < fields.Length; i++)
			{
				Harmony val = (Harmony)fields[i].GetValue(null);
				if (val != null)
				{
					val.UnpatchSelf();
				}
			}
		}

		private static IEnumerator FixLegacySounds()
		{
			yield return null;
			foreach (MethodBase patchedMethod in HarmonyInstances.CustomSounds.GetPatchedMethods())
			{
				Patches patchInfo = Harmony.GetPatchInfo(patchedMethod);
				if (patchInfo.Owners.Count != 1)
				{
					HarmonyInstances.CustomSounds.Unpatch(patchedMethod, (HarmonyPatchType)1, patchInfo.Owners.First((string ownerID) => ownerID != HarmonyInstances.CustomSounds.Id));
					continue;
				}
				break;
			}
		}

		private static IEnumerator WaitForModel10ToSpawn()
		{
			GunScript[] array = Object.FindObjectsOfType<GunScript>();
			for (int i = 0; i < array.Length; i++)
			{
				if ((int)array[i].gun_model == 2)
				{
					Object.Instantiate<GunScript>(ReceiverCoreScript.Instance().GetGunPrefab(ReceiverCoreScript.Instance().CurrentLoadout.gun_internal_name), ((Component)array[i]).transform.position, ((Component)array[i]).transform.rotation);
					((Component)array[i]).gameObject.SetActive(false);
					break;
				}
			}
			yield break;
		}

		internal static void Initialize()
		{
			HarmonyInstances.Core = Harmony.CreateAndPatchAll(typeof(HarmonyManager), (string)null);
			HarmonyInstances.Transpilers = Harmony.CreateAndPatchAll(typeof(Transpilers), (string)null);
			HarmonyInstances.ModHelpEntry = Harmony.CreateAndPatchAll(typeof(ModHelpEntryManager), (string)null);
			HarmonyInstances.CustomSounds = Harmony.CreateAndPatchAll(typeof(ModAudioPatches), (string)null);
			HarmonyInstances.ModGameMode = Harmony.CreateAndPatchAll(typeof(ModGameModeManager), (string)null);
			if (Receiver2ModdingKit.Thunderstore.Thunderstore.LaunchedWithR2ModMan)
			{
				HarmonyInstances.Thunderstore = Harmony.CreateAndPatchAll(typeof(R2ModManPatches), (string)null);
			}
			((MonoBehaviour)ModdingKitCorePlugin.instance).StartCoroutine(FixLegacySounds());
		}
	}
	public class Keybind
	{
		public interface KeyMapping
		{
			int GetKey();

			bool IsRedirect();
		}

		public class KeyboardKey : KeyMapping
		{
			private KeyCode key;

			public KeyboardKey(KeyCode key)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				this.key = key;
			}

			public int GetKey()
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected I4, but got Unknown
				return (int)key;
			}

			public bool IsRedirect()
			{
				return false;
			}
		}

		public class KeyRedirect : KeyMapping
		{
			private int action_id;

			public KeyRedirect(int action_id)
			{
				this.action_id = action_id;
			}

			public int GetKey()
			{
				return action_id;
			}

			public bool IsRedirect()
			{
				return true;
			}
		}

		public string name;

		public string gun_name = "";

		public KeyMapping key;

		public int fallback_action_id;

		public Keybind(string keybind_menu_name, int fallback_action_id, KeyMapping default_value = null)
		{
			name = keybind_menu_name;
			this.fallback_action_id = fallback_action_id;
			key = default_value;
		}

		public string GetLongName()
		{
			return gun_name + "::" + name;
		}
	}
	public class KeybindContainer
	{
		public string gun_name;

		public GameObject category_object;

		public ModKeybindComponent[] keybind_components;

		public bool active { get; private set; }

		public void SetActive(bool active)
		{
			this.active = active;
			category_object.SetActive(active);
			ModKeybindComponent[] array = keybind_components;
			for (int i = 0; i < array.Length; i++)
			{
				((Component)array[i]).gameObject.SetActive(active);
			}
		}
	}
	internal static class KeybindsManager
	{
		internal static GameObject keybinds_menu_banner = null;

		internal static GameObject keybinds_menu_space = null;

		internal static List<KeybindContainer> custom_keybinds = new List<KeybindContainer>();

		private static Dictionary<string, int> m_rewired_actions = null;

		internal static Dictionary<string, int> rewired_actions
		{
			get
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: 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: Invalid comparison between Unknown and I4
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				if (m_rewired_actions == null)
				{
					m_rewired_actions = new Dictionary<string, int> { { "None", -1 } };
					FieldInfo[] fields = typeof(Action).GetFields(BindingFlags.Static | BindingFlags.Public);
					for (int i = 0; i < fields.Length; i++)
					{
						int num = (int)fields[i].GetValue(null);
						LocaleUIString val = ControllerBindingScript.RewiredActionToButtonLabel(num, (Pole)0);
						if ((int)val != 151)
						{
							m_rewired_actions.Add(Locale.GetUIString(val), num);
						}
					}
				}
				return m_rewired_actions;
			}
		}

		public static bool IsKeybindRegistered(string weapon_group_name)
		{
			return custom_keybinds.Any((KeybindContainer keybind) => keybind.gun_name == weapon_group_name);
		}

		public static KeybindContainer GetKeybinds(string weapon_group_name)
		{
			return custom_keybinds.First((KeybindContainer keybind) => keybind.gun_name == weapon_group_name);
		}

		public static bool TryGetKeybinds(string weapon_group_name, out KeybindContainer keybind_container)
		{
			foreach (KeybindContainer custom_keybind in custom_keybinds)
			{
				if (custom_keybind.gun_name == weapon_group_name)
				{
					keybind_container = custom_keybind;
					return true;
				}
			}
			keybind_container = null;
			return false;
		}

		public static void DeactivateAllKeybinds()
		{
			if ((Object)(object)keybinds_menu_banner != (Object)null)
			{
				keybinds_menu_banner.SetActive(false);
			}
			if ((Object)(object)keybinds_menu_space != (Object)null)
			{
				keybinds_menu_space.SetActive(false);
			}
			foreach (KeybindContainer custom_keybind in custom_keybinds)
			{
				custom_keybind.SetActive(active: false);
			}
		}

		public static void SetKeybindsActive(string weapon_group_name)
		{
			bool active = false;
			foreach (KeybindContainer custom_keybind in custom_keybinds)
			{
				if (custom_keybind.gun_name == weapon_group_name)
				{
					custom_keybind.SetActive(active: true);
					active = true;
				}
				else
				{
					custom_keybind.SetActive(active: false);
				}
			}
			if ((Object)(object)keybinds_menu_banner != (Object)null)
			{
				keybinds_menu_banner.SetActive(active);
			}
			if ((Object)(object)keybinds_menu_space != (Object)null)
			{
				keybinds_menu_space.SetActive(active);
			}
		}
	}
	public class ModKeybindComponent : MonoBehaviour
	{
		public Keybind keybind;

		public Button keyboard_binding;

		public TextMeshProUGUI keyboard_binding_text;

		public DropdownComponent redirect_binding;

		public Button clear_button;

		private IEnumerator PickKeyCoroutine()
		{
			SettingsMenuManager.ShowKeyBindDialog(((Object)this).name);
			while (!Input.GetKeyDown((KeyCode)27))
			{
				foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
				{
					KeyCode val = value;
					if (Input.GetKeyDown(val))
					{
						redirect_binding.Select(0);
						keybind.key = new Keybind.KeyboardKey(val);
						((TMP_Text)keyboard_binding_text).text = ((object)(KeyCode)(ref val)).ToString();
						SettingsMenuManager.HideKeyBindDialog();
						ModdingKitConfig.UpdateKeybindValue(keybind);
						yield break;
					}
				}
				yield return null;
			}
			SettingsMenuManager.HideKeyBindDialog();
		}

		public void Awake()
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			if (keybind.key.IsRedirect())
			{
				for (int i = 0; i < redirect_binding.dropdown.options.Count; i++)
				{
					string text = redirect_binding.dropdown.options[i].text;
					if (KeybindsManager.rewired_actions[text] == keybind.key.GetKey())
					{
						string key = KeybindsManager.rewired_actions.Keys.ElementAt(i);
						keybind.key = new Keybind.KeyRedirect(KeybindsManager.rewired_actions[key]);
						((TMP_Text)keyboard_binding_text).text = "";
						break;
					}
				}
			}
			else
			{
				TextMeshProUGUI obj = keyboard_binding_text;
				KeyCode val = (KeyCode)keybind.key.GetKey();
				((TMP_Text)obj).text = ((object)(KeyCode)(ref val)).ToString();
			}
			((UnityEvent)keyboard_binding.onClick).AddListener((UnityAction)delegate
			{
				((MonoBehaviour)ModdingKitCorePlugin.instance).StartCoroutine(PickKeyCoroutine());
			});
			((UnityEvent<int>)(object)redirect_binding.OnChange).AddListener((UnityAction<int>)delegate(int index)
			{
				string key2 = KeybindsManager.rewired_actions.Keys.ElementAt(index);
				keybind.key = new Keybind.KeyRedirect(KeybindsManager.rewired_actions[key2]);
				((TMP_Text)keyboard_binding_text).text = "";
				ModdingKitConfig.UpdateKeybindValue(keybind);
			});
			((UnityEvent)clear_button.onClick).AddListener((UnityAction)delegate
			{
				((TMP_Text)keyboard_binding_text).text = "";
				redirect_binding.Select(0);
				keybind.key = new Keybind.KeyRedirect(-1);
				ModdingKitConfig.UpdateKeybindValue(keybind);
			});
		}
	}
	public class Metadata<T> : Component
	{
		public string Name { get; private set; }

		public T Value { get; private set; }

		public void Set(T value)
		{
			Set(Name, value);
		}

		public void Set(string name, T value)
		{
			Name = name;
			Value = value;
		}
	}
	public static class MetadataExtensions
	{
		public static Metadata<T> AddMeta<T>(this GameObject gobj, string name, T value)
		{
			Metadata<T>[] components = gobj.GetComponents<Metadata<T>>();
			foreach (Metadata<T> metadata in components)
			{
				if (metadata.Name == name)
				{
					metadata.Set(value);
					return metadata;
				}
			}
			Metadata<T> metadata2 = gobj.AddComponent<Metadata<T>>();
			metadata2.Set(name, value);
			return metadata2;
		}

		public static Metadata<T> SetMeta<T>(this GameObject gobj, string name, T value)
		{
			Metadata<T>[] components = gobj.GetComponents<Metadata<T>>();
			foreach (Metadata<T> metadata in components)
			{
				if (metadata.Name == name)
				{
					metadata.Set(value);
					return metadata;
				}
			}
			return gobj.AddMeta(name, value);
		}

		public static Metadata<T> SetMeta<T>(this Component comp, string name, T value)
		{
			Metadata<T>[] components = comp.GetComponents<Metadata<T>>();
			foreach (Metadata<T> metadata in components)
			{
				if (metadata.Name == name)
				{
					metadata.Set(value);
					return metadata;
				}
			}
			return comp.gameObject.AddMeta(name, value);
		}

		public static T GetMeta<T>(this GameObject gobj, string name)
		{
			Metadata<T>[] components = gobj.GetComponents<Metadata<T>>();
			foreach (Metadata<T> metadata in components)
			{
				if (metadata.Name == name)
				{
					return metadata.Value;
				}
			}
			return default(T);
		}

		public static T GetMeta<T>(this Component comp, string name)
		{
			Metadata<T>[] components = comp.GetComponents<Metadata<T>>();
			foreach (Metadata<T> metadata in components)
			{
				if (metadata.Name == name)
				{
					return metadata.Value;
				}
			}
			return default(T);
		}
	}
	[RequireComponent(typeof(InventorySlot), typeof(LevelItem))]
	public abstract class ModGunScript : GunScript, ISerializationCallbackReceiver
	{
		[Serializable]
		public class ModLocaleTactics
		{
			public string title;

			[TextArea]
			public string description;

			public LocaleTactics GetLocaleTactics(GunScript gun)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				return new LocaleTactics
				{
					gun_internal_name = gun.weapon_group_name,
					title = (Utility.IsNullOrWhiteSpace(title) ? ((InventoryItem)gun).InternalName : title),
					text = description
				};
			}
		}

		[Tooltip("All objects in the prefab should have the same activation status, most desirably they should be deactivated")]
		public GameObject muzzle_flash_prefab;

		public bool visible_in_spawnmenu = true;

		public bool spawns_in_dreaming = true;

		public float magazine_shake_strength_multiplier = 1f;

		public float slide_return_time = 0.04f;

		public ModHelpEntry help_entry;

		public ModLocaleTactics locale_tactics;

		[SerializeField]
		[HideInInspector]
		private bool help_entry_generate;

		[SerializeField]
		[HideInInspector]
		private string help_entry_name;

		[SerializeField]
		[HideInInspector]
		private Sprite help_entry_info_sprite;

		[SerializeField]
		[HideInInspector]
		private string help_entry_title;

		[SerializeField]
		[HideInInspector]
		private string help_entry_description;

		[SerializeField]
		[HideInInspector]
		private string locale_tactics_title;

		[SerializeField]
		[HideInInspector]
		private string locale_tactics_description;

		[Tooltip("List of custom audio events used by the gun, created via RMB -> Create -> Receiver 2 Modding -> Custom Sounds List")]
		public CustomSoundsList audio;

		protected bool _disconnector_needs_reset
		{
			get
			{
				return ReflectionManager.GS_disconnector_needs_reset.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_disconnector_needs_reset.Invoke((GunScript)(object)this) = value;
			}
		}

		protected float _hammer_halfcocked
		{
			get
			{
				return ReflectionManager.GS_hammer_halfcocked.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_hammer_halfcocked.Invoke((GunScript)(object)this) = value;
			}
		}

		protected float _hammer_cocked_val
		{
			get
			{
				return ReflectionManager.GS_hammer_cocked_val.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_hammer_cocked_val.Invoke((GunScript)(object)this) = value;
			}
		}

		protected int _hammer_state
		{
			get
			{
				return ReflectionManager.GS_hammer_state.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_hammer_state.Invoke((GunScript)(object)this) = value;
			}
		}

		protected bool _slide_stop_locked
		{
			get
			{
				return ReflectionManager.GS_slide_stop_locked.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_slide_stop_locked.Invoke((GunScript)(object)this) = value;
			}
		}

		protected LinearMover _select_fire
		{
			get
			{
				return ReflectionManager.GS_select_fire.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_select_fire.Invoke((GunScript)(object)this) = value;
			}
		}

		protected float _yoke_open
		{
			get
			{
				return ReflectionManager.GS_yoke_open.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_yoke_open.Invoke((GunScript)(object)this) = value;
			}
		}

		protected int _current_firing_mode_index
		{
			get
			{
				return ReflectionManager.GS_current_firing_mode_index.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_current_firing_mode_index.Invoke((GunScript)(object)this) = value;
			}
		}

		protected LinearMover _firing_pin
		{
			get
			{
				return ReflectionManager.GS_firing_pin.Invoke((GunScript)(object)this);
			}
			set
			{
				ReflectionManager.GS_firing_pin.Invoke((GunScript)(object)this) = value;
			}
		}

		public PlayerInput player_input { get; protected set; }

		public KeybindContainer keybinds { get; protected set; }

		internal static void UpdateModGun(GunScript gun)
		{
			if (gun is ModGunScript)
			{
				try
				{
					((ModGunScript)(object)gun).UpdateGun();
				}
				catch (Exception ex)
				{
					Debug.LogError((object)$"Catched exception during {((InventoryItem)gun).InternalName}'s UpdateGun");
					Debug.LogException(ex);
				}
			}
		}

		protected static float InterpCurve(in float[] curve, float time)
		{
			if (curve == null || curve.Length < 2)
			{
				Debug.LogError((object)"ModGunScript.InterpCurve(): curve parameter must contain at least 2 elements");
				return 0f;
			}
			if (time <= curve[0])
			{
				return curve[1];
			}
			if (time >= curve[curve.Length - 2])
			{
				return curve[curve.Length - 1];
			}
			for (int i = 0; i < curve.Length - 2; i += 2)
			{
				if (time <= curve[i + 2])
				{
					float num = Mathf.InverseLerp(curve[i], curve[i + 2], time);
					return Mathf.Lerp(curve[i + 1], curve[i + 3], num);
				}
			}
			return curve[1];
		}

		protected void TryFireBullet(float dry_fire_volume = 1f)
		{
			if (Object.op_Implicit((Object)(object)base.round_in_chamber) && !base.round_in_chamber.IsSpent() && ((SimpleMover)base.slide).amount == 0f)
			{
				((GunScript)this).FireBullet(base.round_in_chamber);
				return;
			}
			base.recoil_transfer_x -= Random.Range(15f, 30f);
			base.recoil_transfer_y += Random.Range(-20f, 20f);
			base.dry_fired = true;
			ReceiverEvents.TriggerEvent((ReceiverEventTypeInt)13, (!((Object)(object)base.round_in_chamber != (Object)null)) ? 1 : 2);
			AudioManager.PlayOneShotAttached(base.sound_dry_fire, ((Component)this).gameObject, dry_fire_volume);
		}

		protected void TryFireBullet(float dry_fire_volume, Action<ShellCasingScript> on_fire)
		{
			if (Object.op_Implicit((Object)(object)base.round_in_chamber) && !base.round_in_chamber.IsSpent() && ((SimpleMover)base.slide).amount == 0f)
			{
				on_fire(base.round_in_chamber);
				return;
			}
			base.recoil_transfer_x -= Random.Range(15f, 30f);
			base.recoil_transfer_y += Random.Range(-20f, 20f);
			base.dry_fired = true;
			ReceiverEvents.TriggerEvent((ReceiverEventTypeInt)13, (!((Object)(object)base.round_in_chamber != (Object)null)) ? 1 : 2);
			AudioManager.PlayOneShotAttached(base.sound_dry_fire, ((Component)this).gameObject, dry_fire_volume);
		}

		protected void UpdateAnimatedComponents()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			AnimatedMover[] animated_components = base.animated_components;
			foreach (AnimatedMover val in animated_components)
			{
				((GunScript)this).ApplyTransform(val.anim_path, val.mover.amount, val.component);
			}
		}

		protected void SetArmorPiercing(bool armor_piercing)
		{
			if (armor_piercing != base.armor_piercing)
			{
				base.armor_piercing = armor_piercing;
				TurretArmor[] array = Object.FindObjectsOfType<TurretArmor>();
				for (int i = 0; i < array.Length; i++)
				{
					((Component)array[i]).SendMessage("UpdateMaterial", (object)this);
				}
			}
		}

		protected void Awake()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00ed: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			player_input = new PlayerInput((GunScript)(object)this);
			using (new TransformDebugScope())
			{
				try
				{
					((GunScript)this).Awake();
				}
				catch (NullReferenceException ex)
				{
					Debug.LogError((object)$"Catched exception during {((InventoryItem)this).InternalName}'s Awake");
					if (!string.IsNullOrEmpty(TransformDebugScope.last_target))
					{
						Debug.LogError((object)("You seem to be missing the " + TransformDebugScope.last_target + " transform."));
					}
					else
					{
						Debug.LogError((object)"Carefully check if you've assigned all the fields properly and if there aren't any missing references");
					}
					Debug.LogError((object)ex);
				}
			}
			UpdatedSpring[] update_springs = base.update_springs;
			foreach (UpdatedSpring val in update_springs)
			{
				if ((Object)(object)val.spring == (Object)null)
				{
					Debug.LogError((object)("Null spring in gun \"" + ((InventoryItem)this).InternalName + "\""));
					continue;
				}
				val.spring.orig_center = (((Component)val.spring).transform.InverseTransformPoint(val.spring.new_top.position) + ((Component)val.spring).transform.InverseTransformPoint(val.spring.new_bottom.position)) / 2f;
				val.spring.orig_dist = Vector3.Distance(val.spring.new_top.position, val.spring.new_bottom.position);
			}
			if ((Object)(object)audio != (Object)null)
			{
				audio.SetGun(this);
				ModdingKitConfig.AddConfigEventListener(delegate(object sender, SettingChangedEventArgs args)
				{
					if (args.ChangedSetting.Definition.Key == "Use Custom Sounds")
					{
						audio.SetSoundEvents();
					}
				});
				audio.SetSoundEvents();
			}
			GameObject object_prefab = muzzle_flash_prefab;
			bool flag = true;
			if ((Object)(object)object_prefab == (Object)null)
			{
				object_prefab = base.pooled_muzzle_flash.object_prefab;
			}
			if ((Object)(object)object_prefab != (Object)null && ObjectPool.pools != null)
			{
				ObjectPool val2 = ObjectPool.pools["MuzzleFlashPool"];
				Dictionary<string, int> dictionary = ReflectionManager.OP_pool_map.GetValue(val2) as Dictionary<string, int>;
				GameObject val3;
				if (dictionary.ContainsKey(((InventoryItem)this).InternalName + "_muzzle_flash"))
				{
					val3 = val2.pooled_prefab_parameters[dictionary[((InventoryItem)this).InternalName + "_muzzle_flash"]].pool_object;
				}
				else
				{
					val2.AddPrefab(object_prefab);
					val3 = new GameObject(((InventoryItem)this).InternalName + "_muzzle_flash");
					val3.transform.parent = ((Component)val2).transform;
					Object.Instantiate<GameObject>(object_prefab, val3.transform);
					int num = dictionary.Values.Max() + 1;
					if (num >= val2.pooled_prefab_parameters.Count)
					{
						Object.Destroy((Object)(object)val3);
						flag = false;
					}
					else
					{
						dictionary.Add(((Object)val3).name, num);
						val2.pooled_prefab_parameters[num].ClaimPool(val3);
					}
				}
				if (flag)
				{
					base.pooled_muzzle_flash.pool_prefab = ((Component)val2).gameObject;
					base.pooled_muzzle_flash.object_prefab = val3;
					base.pooled_muzzle_flash.object_prefab_name = ((Object)val3).name;
				}
			}
			try
			{
				AwakeGun();
			}
			catch (Exception ex2)
			{
				Debug.LogError((object)$"Catched exception during {((InventoryItem)this).InternalName}'s AwakeGun");
				Debug.LogException(ex2);
			}
		}

		protected void Update()
		{
			using (new TransformDebugScope())
			{
				try
				{
					EarlyUpdateGun();
				}
				catch (Exception ex)
				{
					Debug.LogError((object)$"Catched exception during {((InventoryItem)this).InternalName}'s EarlyUpdateGun");
					Debug.LogException(ex);
				}
				try
				{
					((GunScript)this).Update();
					UpdateAnimatedComponents();
					if (Object.op_Implicit((Object)(object)((SimpleMover)base.safety).transform))
					{
						((SimpleMover)base.safety).UpdateDisplay();
					}
				}
				catch (NullReferenceException ex2)
				{
					Debug.LogError((object)$"Catched exception during {((InventoryItem)this).InternalName}'s Update");
					if (!string.IsNullOrEmpty(TransformDebugScope.last_target))
					{
						Debug.LogError((object)("You seem to be missing the " + TransformDebugScope.last_target + " transform."));
					}
					else
					{
						Debug.LogError((object)"Carefully check if you've assigned all the fields properly and if there aren't any missing references");
					}
					Debug.LogError((object)ex2);
				}
				try
				{
					LateUpdateGun();
				}
				catch (Exception ex3)
				{
					Debug.LogError((object)$"Catched exception during {((InventoryItem)this).InternalName}'s LateUpdateGun");
					Debug.LogException(ex3);
				}
			}
		}

		public void BaseInitializeGun()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.spawn_info_sprite == (Object)null)
			{
				Debug.LogError((object)("Gun " + ((InventoryItem)this).InternalName + " doesn't have a spawn_info_sprite assigned, it may cause problems later"));
				base.spawn_info_sprite = Sprite.Create(Texture2D.blackTexture, Rect.zero, Vector2.zero);
			}
			keybinds = SettingsMenuManager.GenerateKeybindMenu(this);
			try
			{
				InitializeGun();
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error accured while initializing gun " + ((InventoryItem)this).InternalName + ":"));
				Debug.LogException(ex);
			}
		}

		public override void OnChangeInventorySlot(InventorySlot old_slot, InventorySlot new_slot, Hand from_hand, Hand to_hand)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			((GunScript)this).OnChangeInventorySlot(old_slot, new_slot, from_hand, to_hand);
			if ((Object)(object)new_slot != (Object)null && (Object)(object)old_slot != (Object)null)
			{
				if ((int)new_slot.type == 2)
				{
					OnHolster();
				}
				else if ((int)new_slot.type == 1)
				{
					OnUnholster();
				}
			}
		}

		public virtual void InitializeGun()
		{
		}

		public virtual void AwakeGun()
		{
		}

		public virtual ModHelpEntry GetGunHelpEntry()
		{
			if (help_entry == null || !help_entry.generate)
			{
				return null;
			}
			return help_entry;
		}

		[Obsolete("This method makes gun loading unnecessarily complicated, use ModShellCasingScript instead")]
		public virtual CartridgeSpec GetCustomCartridgeSpec()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			CartridgeSpec result = default(CartridgeSpec);
			((CartridgeSpec)(ref result)).SetFromPreset((Preset)0);
			return result;
		}

		public virtual LocaleTactics GetGunTactics()
		{
			return locale_tactics.GetLocaleTactics((GunScript)(object)this);
		}

		public virtual float GetTotalMass()
		{
			return -1f;
		}

		[HarmonyPatch(typeof(GunScript), "GetTotalMass")]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		public float GetDefaultTotalMass()
		{
			return 0f;
		}

		[HarmonyPatch(typeof(GunScript), "GetTotalMass")]
		[HarmonyPrefix]
		public static bool PatchGetTotalMass(GunScript __instance, ref float __result)
		{
			__result = __instance.GetTotalMass();
			return __result < 0f;
		}

		public virtual float GetMagSmackStrength()
		{
			return magazine_shake_strength_multiplier;
		}

		public virtual Vector2 GetStepRecoilMultiplier()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(1f / base.mass, 1f / base.mass);
		}

		public virtual bool CanHolster()
		{
			if ((Object)(object)base.magazine_instance_in_gun != (Object)null)
			{
				return ((SimpleMover)base.magazine).amount == 0f;
			}
			return true;
		}

		public virtual void OnHolster()
		{
		}

		public virtual void OnUnholster()
		{
		}

		public abstract void UpdateGun();

		public virtual void EarlyUpdateGun()
		{
		}

		public virtual void LateUpdateGun()
		{
		}

		public virtual float GetSlideReturnTime()
		{
			return slide_return_time;
		}

		public static float CalculateSlideAcceleration(GunScript __instance, float change, float time)