Decompiled source of TNHFramework v0.1.5

patchers/OldTweakerDisabler.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Logging;
using Mono.Cecil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OldTweakerDisabler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OldTweakerDisabler")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("86ca37de-2467-4dad-991f-25a8cb18f841")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OldTweakerDisabler;

public static class Entrypoint
{
	private static readonly ManualLogSource Logger = Logger.CreateLogSource("Deliter");

	public static IEnumerable<string> TargetDLLs => Enumerable.Empty<string>();

	public static void Patch(AssemblyDefinition asm)
	{
		Logger.LogWarning((object)("No DLLs should be patched, but the patch method was called. Assembly: " + (object)asm));
	}

	public static void Initialize()
	{
		string[] directories = Directory.GetDirectories(Paths.PluginPath);
		string[] array = directories;
		foreach (string text in array)
		{
			Logger.LogInfo((object)("Found directory " + text));
			if (text.Contains("devyndamonster-TakeAndHoldTweaker") && File.Exists(Path.Combine(text, "TakeAndHoldTweaker.deli")))
			{
				File.Move(Path.Combine(text, "TakeAndHoldTweaker.deli"), Path.Combine(text, "TakeAndHoldTweaker.deli.bak"));
				Logger.LogInfo((object)"Disabled old Take & Hold Tweaker install. Re-enable it via reinstalling or renaming the DLL. Will break compatibility with TNH Tweaker 1.8.");
			}
		}
	}
}

plugins/TNHTweaker/TNHFramework.dll

Decompiled 2 months 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.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Deli;
using Deli.Immediate;
using Deli.Setup;
using Deli.VFS;
using FistVR;
using HarmonyLib;
using MagazinePatcher;
using Microsoft.CodeAnalysis;
using OtherLoader;
using Stratum;
using Stratum.Extensions;
using TNHFramework.ObjectTemplates;
using TNHFramework.ObjectTemplates.V1;
using TNHFramework.Patches;
using TNHFramework.Utilities;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Valve.Newtonsoft.Json;
using Valve.Newtonsoft.Json.Converters;
using YamlDotNet.Core;
using YamlDotNet.Serialization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TakeAndHoldTweaker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TakeAndHoldTweaker")]
[assembly: AssemblyCopyright("Copyright ©  2020")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("13103263-bab2-4450-ae68-23c78eb493b2")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TNHFramework
{
	public static class AsyncLoadMonitor
	{
		public static List<AnvilCallback<AssetBundle>> CallbackList = new List<AnvilCallback<AssetBundle>>();

		public static float GetProgress()
		{
			if (CallbackList.Count == 0)
			{
				return 1f;
			}
			float num = 0f;
			for (int i = 0; i < CallbackList.Count; i++)
			{
				if (((AnvilCallbackBase)CallbackList[i]).IsCompleted)
				{
					CallbackList.RemoveAt(i);
					i--;
				}
				else
				{
					num += ((AnvilCallbackBase)CallbackList[i]).Progress;
				}
			}
			return num / (float)CallbackList.Count;
		}
	}
	public class SosigLinkLootWrapper : MonoBehaviour
	{
		public TNH_Manager M;

		public global::TNHFramework.ObjectTemplates.CustomCharacter character;

		public global::TNHFramework.ObjectTemplates.EquipmentGroup group;

		public bool dontDrop = false;

		public bool shouldDropOnCleanup;

		private void OnDestroy()
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			if (dontDrop)
			{
				return;
			}
			TNHFrameworkLogger.Log("Lootable link was destroyed!", TNHFrameworkLogger.LogType.TNH);
			List<global::TNHFramework.ObjectTemplates.EquipmentGroup> spawnedEquipmentGroups = group.GetSpawnedEquipmentGroups();
			string text = null;
			int num = 0;
			string text2 = default(string);
			foreach (global::TNHFramework.ObjectTemplates.EquipmentGroup item in spawnedEquipmentGroups)
			{
				for (int i = 0; i < item.ItemsToSpawn; i++)
				{
					if (item.IsCompatibleMagazine)
					{
						FVRObject ammoContainerForEquipped = FirearmUtils.GetAmmoContainerForEquipped(item.MinAmmoCapacity, item.MaxAmmoCapacity, character.GlobalObjectBlacklist, character.GetMagazineBlacklist());
						if ((Object)(object)ammoContainerForEquipped != (Object)null)
						{
							text = ammoContainerForEquipped.ItemID;
						}
						else
						{
							TNHFrameworkLogger.Log("Spawning nothing since group was compatible magazines, and could not find a compatible magazine for player", TNHFrameworkLogger.LogType.TNH);
						}
					}
					else
					{
						List<string> objects = item.GetObjects();
						if (objects.Count == 0)
						{
							TNHFrameworkLogger.Log("Spawning nothing since group was empty", TNHFrameworkLogger.LogType.TNH);
						}
						else
						{
							text = objects.GetRandom();
						}
					}
					if (!Utility.IsNullOrWhiteSpace(text))
					{
						if (LoadedTemplateManager.LoadedVaultFiles.ContainsKey(text))
						{
							TNHFrameworkLogger.Log("Spawning vault file " + text, TNHFrameworkLogger.LogType.TNH);
							Transform transform = ((Component)this).transform;
							transform.position = ((Component)this).transform.position + Vector3.up * 0.1f * (float)num;
							VaultSystem.SpawnVaultFile(LoadedTemplateManager.LoadedVaultFiles[text], transform, true, false, false, ref text2, Vector3.zero, (ReturnObjectListDelegate)null, false);
						}
						else if (LoadedTemplateManager.LoadedLegacyVaultFiles.ContainsKey(text))
						{
							TNHFrameworkLogger.Log("Spawning legacy vault file " + text, TNHFrameworkLogger.LogType.TNH);
							AnvilManager.Run(TNHFrameworkUtils.SpawnFirearm(LoadedTemplateManager.LoadedLegacyVaultFiles[text], ((Component)this).transform.position + Vector3.up * 0.1f * (float)num, ((Component)this).transform.rotation, M));
						}
						else
						{
							TNHFrameworkLogger.Log("Spawning item " + text, TNHFrameworkLogger.LogType.TNH);
							GameObject val = Object.Instantiate<GameObject>(((AnvilAsset)IM.OD[text]).GetGameObject(), ((Component)this).transform.position + Vector3.up * 0.1f * (float)num, ((Component)this).transform.rotation);
							M.AddObjectToTrackedList(val);
						}
						num++;
					}
				}
			}
		}
	}
	public class DebugPatches
	{
		[HarmonyPatch(typeof(TNH_Manager), "Start")]
		[HarmonyPrefix]
		public static bool AddPointDebugText(TNH_Manager __instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			foreach (TNH_HoldPoint holdPoint in __instance.HoldPoints)
			{
				TNHFrameworkLogger.Log("Adding text!", TNHFrameworkLogger.LogType.TNH);
				GameObject val = new GameObject("Canvas");
				val.transform.rotation = Quaternion.LookRotation(Vector3.right);
				val.transform.position = holdPoint.SpawnPoint_SystemNode.position + Vector3.up * 0.2f;
				Canvas val2 = val.AddComponent<Canvas>();
				RectTransform component = ((Component)val2).GetComponent<RectTransform>();
				val2.renderMode = (RenderMode)2;
				component.sizeDelta = new Vector2(1f, 1f);
				GameObject val3 = new GameObject("Text");
				val3.transform.SetParent(val.transform);
				val3.transform.rotation = val.transform.rotation;
				val3.transform.localPosition = Vector3.zero;
				val3.AddComponent<CanvasRenderer>();
				Text val4 = val3.AddComponent<Text>();
				Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
				val4.text = "Hold " + __instance.HoldPoints.IndexOf(holdPoint);
				val4.alignment = (TextAnchor)4;
				val4.fontSize = 32;
				val3.transform.localScale = new Vector3(0.0015f, 0.0015f, 0.0015f);
				val4.font = font;
				val4.horizontalOverflow = (HorizontalWrapMode)1;
			}
			return true;
		}
	}
	public class SosigLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			IFileHandle val = (IFileHandle)(object)((handle is IFileHandle) ? handle : null);
			if (val == null)
			{
				throw new ArgumentException("Could not load sosig! Make sure you're pointing to a sosig template json file in the manifest");
			}
			try
			{
				string text = ((Stage)stage).ImmediateReaders.Get<string>().Invoke(val);
				JsonSerializerSettings val2 = new JsonSerializerSettings
				{
					NullValueHandling = (NullValueHandling)1
				};
				SosigTemplate sosigTemplate = JsonConvert.DeserializeObject<SosigTemplate>(text, val2);
				TNHFrameworkLogger.Log("Sosig loaded successfuly : " + sosigTemplate.DisplayName, TNHFrameworkLogger.LogType.General);
				LoadedTemplateManager.AddSosigTemplate(sosigTemplate);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for sosig file! Caused Error: " + ex.ToString());
			}
		}
	}
	public class CharacterLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			IDirectoryHandle val = (IDirectoryHandle)(object)((handle is IDirectoryHandle) ? handle : null);
			if (val == null)
			{
				throw new ArgumentException("Could not load character! Character should point to a folder holding the character.json and thumb.png");
			}
			try
			{
				global::TNHFramework.ObjectTemplates.V1.CustomCharacter customCharacter = null;
				Sprite val2 = null;
				foreach (IFileHandle file in ExtIDirectoryHandle.GetFiles(val))
				{
					if (((IHandle)file).Path.EndsWith("character.json"))
					{
						string text = ((Stage)stage).ImmediateReaders.Get<string>().Invoke(file);
						JsonSerializerSettings val3 = new JsonSerializerSettings
						{
							NullValueHandling = (NullValueHandling)1
						};
						customCharacter = JsonConvert.DeserializeObject<global::TNHFramework.ObjectTemplates.V1.CustomCharacter>(text, val3);
					}
					else if (((IHandle)file).Path.EndsWith("thumb.png"))
					{
						val2 = TNHFrameworkUtils.LoadSprite(file);
					}
				}
				if (customCharacter == null)
				{
					TNHFrameworkLogger.LogError("Failed to load custom character! No character.json file found");
					return;
				}
				if ((Object)(object)val2 == (Object)null)
				{
					TNHFrameworkLogger.LogError("Failed to load custom character! No thumb.png file found");
					return;
				}
				foreach (IFileHandle file2 in ExtIDirectoryHandle.GetFiles(val))
				{
					foreach (global::TNHFramework.ObjectTemplates.V1.EquipmentPool equipmentPool in customCharacter.EquipmentPools)
					{
						if (((IHandle)file2).Path.Split(new char[1] { '/' }).Last() == equipmentPool.IconName)
						{
							equipmentPool.GetPoolEntry().TableDef.Icon = TNHFrameworkUtils.LoadSprite(file2);
						}
					}
				}
				TNHFrameworkLogger.Log("Character loaded successfuly : " + customCharacter.DisplayName, TNHFrameworkLogger.LogType.General);
				LoadedTemplateManager.AddCharacterTemplate(new global::TNHFramework.ObjectTemplates.CustomCharacter(customCharacter), val2);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for character! Caused Error: " + ex.ToString());
			}
		}
	}
	public class VaultFileLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			IFileHandle val = (IFileHandle)(object)((handle is IFileHandle) ? handle : null);
			if (val == null)
			{
				throw new ArgumentException("Could not load vault file! Make sure you're pointing to a vault json file in the manifest");
			}
			try
			{
				string text = ((Stage)stage).ImmediateReaders.Get<string>().Invoke(val);
				JsonSerializerSettings val2 = new JsonSerializerSettings
				{
					NullValueHandling = (NullValueHandling)1
				};
				SavedGunSerializable savedGunSerializable = JsonConvert.DeserializeObject<SavedGunSerializable>(text, val2);
				TNHFrameworkLogger.Log("Vault file loaded successfuly : " + savedGunSerializable.FileName, TNHFrameworkLogger.LogType.General);
				LoadedTemplateManager.AddVaultFile(savedGunSerializable);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for vault file! Caused Error: " + ex.ToString());
			}
		}
	}
	public static class TNHMenuInitializer
	{
		public static bool TNHInitialized;

		public static bool MagazineCacheFailed;

		public static List<TNH_CharacterDef> SavedCharacters;

		public static IEnumerator InitializeTNHMenuAsync(string path, Text progressText, Text itemsText, SceneLoader hotdog, List<CharacterCategory> Categories, TNH_CharacterDatabase CharDatabase, TNH_UIManager instance, bool outputFiles)
		{
			((Component)hotdog).gameObject.SetActive(false);
			bool isOtherLoaderLoaded;
			try
			{
				PokeOtherloader();
				isOtherLoaderLoaded = true;
			}
			catch
			{
				isOtherLoaderLoaded = false;
				TNHFrameworkLogger.LogWarning("OtherLoader not found. If you are using OtherLoader, please ensure you have version 0.1.6 or later!");
			}
			float itemLoadProgress;
			do
			{
				yield return null;
				itemLoadProgress = AsyncLoadMonitor.GetProgress();
				if (isOtherLoaderLoaded)
				{
					itemLoadProgress = Mathf.Min(itemLoadProgress, GetOtherLoaderProgress());
					itemsText.text = GetLoadingItems();
				}
				progressText.text = $"LOADING ITEMS : {itemLoadProgress * 100f:0.0}%";
			}
			while (itemLoadProgress < 1f);
			bool isMagPatcherLoaded;
			try
			{
				PokeMagPatcher();
				isMagPatcherLoaded = true;
				TNHFrameworkLogger.LogWarning("MagazinePatcher is detected.");
			}
			catch
			{
				isMagPatcherLoaded = false;
				TNHFrameworkLogger.LogWarning("MagazinePatcher not found.");
			}
			if (isMagPatcherLoaded)
			{
				float cachingProgress;
				do
				{
					yield return null;
					cachingProgress = PokeMagPatcher();
					itemsText.text = GetMagPatcherCacheLog();
					progressText.text = $"CACHING ITEMS : {cachingProgress * 100f:0.0}%";
				}
				while (cachingProgress < 1f);
			}
			else if (TNHFramework.InternalMagPatcher.Value)
			{
				TNHFrameworkLogger.Log($"[{DateTime.Now:HH:mm:ss}] Internal Mag Patcher started!", TNHFrameworkLogger.LogType.General);
				InternalMagPatcher();
				TNHFrameworkLogger.Log($"[{DateTime.Now:HH:mm:ss}] Internal Mag Patcher finished!", TNHFrameworkLogger.LogType.General);
			}
			LoadTNHTemplates(CharDatabase);
			SavedCharacters = CharDatabase.Characters;
			if (outputFiles)
			{
				CreateTNHFiles(path);
			}
			RefreshTNHUI(instance, Categories, CharDatabase);
			itemsText.text = "";
			progressText.text = "";
			((Component)hotdog).gameObject.SetActive(true);
			TNHInitialized = true;
		}

		public static void InternalMagPatcher()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Invalid comparison between Unknown and I4
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Invalid comparison between Unknown and I4
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Invalid comparison between Unknown and I4
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Invalid comparison between Unknown and I4
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Invalid comparison between Unknown and I4
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Invalid comparison between Unknown and I4
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			List<FVRObject> list = new List<FVRObject>();
			foreach (KeyValuePair<string, FVRObject> item in IM.OD)
			{
				if ((int)item.Value.Category == 1)
				{
					list.Add(item.Value);
				}
				else if ((int)item.Value.Category == 4)
				{
					if (!TNHFramework.CartridgeDictionary.ContainsKey(item.Value.RoundType))
					{
						TNHFramework.CartridgeDictionary.Add(item.Value.RoundType, new List<FVRObject>());
					}
					TNHFramework.CartridgeDictionary[item.Value.RoundType].Add(item.Value);
				}
				else if ((int)item.Value.Category == 2)
				{
					if (!TNHFramework.MagazineDictionary.ContainsKey(item.Value.MagazineType))
					{
						TNHFramework.MagazineDictionary.Add(item.Value.MagazineType, new List<FVRObject>());
					}
					TNHFramework.MagazineDictionary[item.Value.MagazineType].Add(item.Value);
				}
				else if ((int)item.Value.Category == 3)
				{
					if (!TNHFramework.StripperDictionary.ContainsKey(item.Value.ClipType))
					{
						TNHFramework.StripperDictionary.Add(item.Value.ClipType, new List<FVRObject>());
					}
					TNHFramework.StripperDictionary[item.Value.ClipType].Add(item.Value);
				}
				else if ((int)item.Value.Category == 6)
				{
					if (!TNHFramework.SpeedloaderDictionary.ContainsKey(item.Value.RoundType))
					{
						TNHFramework.SpeedloaderDictionary.Add(item.Value.RoundType, new List<FVRObject>());
					}
					if (item.Value.ItemID == "Speedloader12gauge_5Shot")
					{
						item.Value.MagazineCapacity = 5;
					}
					TNHFramework.SpeedloaderDictionary[item.Value.RoundType].Add(item.Value);
				}
			}
			foreach (FVRObject item2 in list)
			{
				FVRFireArm val = null;
				FireArmClipType clipType = item2.ClipType;
				FireArmRoundType roundType = item2.RoundType;
				FireArmMagazineType magazineType = item2.MagazineType;
				int num = item2.MagazineCapacity;
				if (!ValidFireArm(roundType, clipType, magazineType, 0))
				{
					if (!item2.IsModContent && (int)item2.TagFirearmAction == 8 && item2.TagFirearmFeedOption.Contains((OTagFirearmFeedOption)1))
					{
						continue;
					}
					TNHFrameworkLogger.Log($"Loading firearm {item2.DisplayName} [Mod = {item2.IsModContent}]", TNHFrameworkLogger.LogType.General);
					GameObject gameObject = ((AnvilAsset)item2).GetGameObject();
					if ((Object)(object)gameObject != (Object)null)
					{
						val = gameObject.GetComponent<FVRFireArm>();
					}
					if ((Object)(object)val != (Object)null)
					{
						roundType = val.RoundType;
						magazineType = val.MagazineType;
						clipType = val.ClipType;
					}
				}
				if (!ValidFireArm(roundType, clipType, magazineType, num))
				{
					TNHFrameworkLogger.Log("Firearm " + item2.DisplayName + " skipped!", TNHFrameworkLogger.LogType.General);
					continue;
				}
				if ((item2.CompatibleSingleRounds == null || item2.CompatibleSingleRounds.Count == 0) && TNHFramework.CartridgeDictionary.ContainsKey(roundType))
				{
					TNHFrameworkLogger.Log($"Giving firearm {item2.DisplayName} new rounds of type {roundType}", TNHFrameworkLogger.LogType.General);
					item2.CompatibleSingleRounds = TNHFramework.CartridgeDictionary[roundType];
				}
				if ((item2.CompatibleMagazines == null || item2.CompatibleMagazines.Count == 0) && TNHFramework.MagazineDictionary.ContainsKey(magazineType) && (int)magazineType > 0)
				{
					TNHFrameworkLogger.Log($"Giving firearm {item2.DisplayName} new magazines of type {magazineType}", TNHFrameworkLogger.LogType.General);
					item2.CompatibleMagazines = TNHFramework.MagazineDictionary[magazineType];
				}
				if ((item2.CompatibleClips == null || item2.CompatibleClips.Count == 0) && TNHFramework.StripperDictionary.ContainsKey(clipType) && (int)clipType > 0)
				{
					TNHFrameworkLogger.Log($"Giving firearm {item2.DisplayName} new clips of type {clipType}", TNHFrameworkLogger.LogType.General);
					item2.CompatibleClips = TNHFramework.StripperDictionary[clipType];
				}
				if ((item2.CompatibleSpeedLoaders != null && item2.CompatibleSpeedLoaders.Count != 0) || (int)item2.TagFirearmAction != 3)
				{
					continue;
				}
				if ((Object)(object)val == (Object)null)
				{
					GameObject gameObject2 = ((AnvilAsset)item2).GetGameObject();
					if ((Object)(object)gameObject2 != (Object)null)
					{
						val = gameObject2.GetComponent<FVRFireArm>();
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					roundType = val.RoundType;
					Revolver component = ((Component)val).gameObject.GetComponent<Revolver>();
					if ((Object)(object)component != (Object)null)
					{
						num = component.Chambers.Length;
					}
				}
				if (!TNHFramework.SpeedloaderDictionary.ContainsKey(roundType))
				{
					continue;
				}
				foreach (FVRObject item3 in TNHFramework.SpeedloaderDictionary[roundType])
				{
					if (item3.MagazineCapacity == num)
					{
						TNHFrameworkLogger.Log($"Giving firearm {item2.DisplayName} new speedloader of type {roundType}", TNHFrameworkLogger.LogType.General);
						item2.CompatibleSpeedLoaders.Add(item3);
					}
				}
			}
		}

		public static bool ValidFireArm(FireArmRoundType roundType, FireArmClipType clipType, FireArmMagazineType magazineType, int magazineCapacity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			return (int)roundType != 0 || (int)magazineType != 0 || magazineCapacity != 0 || (int)clipType > 0;
		}

		public static void PokeOtherloader()
		{
			LoaderStatus.GetLoaderProgress();
			List<string> loadingItems = LoaderStatus.LoadingItems;
		}

		public static float PokeMagPatcher()
		{
			return PatcherStatus.PatcherProgress;
		}

		public static string GetMagPatcherCacheLog()
		{
			return PatcherStatus.CacheLog;
		}

		public static float GetOtherLoaderProgress()
		{
			return LoaderStatus.GetLoaderProgress();
		}

		public static string GetLoadingItems()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			List<string> loadingItems = LoaderStatus.LoadingItems;
			for (int i = 0; i < loadingItems.Count; i++)
			{
				string text = ColorUtility.ToHtmlStringRGBA(new Color(0.5f, 0.5f, 0.5f, Mathf.Clamp(((float)loadingItems.Count - (float)i) / (float)loadingItems.Count, 0f, 1f)));
				loadingItems[i] = "<color=#" + text + ">Loading Assets (" + loadingItems[i] + ")</color>";
			}
			loadingItems.Reverse();
			return string.Join("\n", loadingItems.ToArray());
		}

		public static void LoadTNHTemplates(TNH_CharacterDatabase CharDatabase)
		{
			TNHFrameworkLogger.Log("Performing TNH Initialization", TNHFrameworkLogger.LogType.General);
			TNHFrameworkLogger.Log("Adding default sosigs to template dictionary", TNHFrameworkLogger.LogType.General);
			LoadDefaultSosigs();
			TNHFrameworkLogger.Log("Adding default characters to template dictionary", TNHFrameworkLogger.LogType.General);
			LoadDefaultCharacters(CharDatabase.Characters);
			LoadedTemplateManager.DefaultIconSprites = TNHFrameworkUtils.GetAllIcons(LoadedTemplateManager.DefaultCharacters);
			TNHFrameworkLogger.Log("Delayed Init of default characters", TNHFrameworkLogger.LogType.General);
			InitCharacters(LoadedTemplateManager.DefaultCharacters, isCustom: false);
			TNHFrameworkLogger.Log("Delayed Init of custom characters", TNHFrameworkLogger.LogType.General);
			InitCharacters(LoadedTemplateManager.CustomCharacters, isCustom: true);
			TNHFrameworkLogger.Log("Delayed Init of custom sosigs", TNHFrameworkLogger.LogType.General);
			InitSosigs(LoadedTemplateManager.CustomSosigs);
		}

		public static void CreateTNHFiles(string path)
		{
			TNHFrameworkLogger.Log("Creating character creation files", TNHFrameworkLogger.LogType.General);
			TNHFrameworkUtils.CreateDefaultSosigTemplateFiles(LoadedTemplateManager.DefaultSosigs, path);
			TNHFrameworkUtils.CreateDefaultCharacterFiles(LoadedTemplateManager.DefaultCharacters, path);
			TNHFrameworkUtils.CreateIconIDFile(path, LoadedTemplateManager.DefaultIconSprites.Keys.ToList());
			TNHFrameworkUtils.CreateObjectIDFile(path);
			TNHFrameworkUtils.CreateSosigIDFile(path);
			TNHFrameworkUtils.CreateJsonVaultFiles(path);
			TNHFrameworkUtils.CreateGeneratedTables(path);
			TNHFrameworkUtils.CreatePopulatedCharacterTemplate(path);
		}

		private static void LoadDefaultSosigs()
		{
			foreach (SosigEnemyTemplate value in ManagerSingleton<IM>.Instance.odicSosigObjsByID.Values)
			{
				LoadedTemplateManager.AddSosigTemplate(value);
			}
		}

		private static void LoadDefaultCharacters(List<TNH_CharacterDef> characters)
		{
			foreach (TNH_CharacterDef character in characters)
			{
				LoadedTemplateManager.AddCharacterTemplate(character);
			}
		}

		private static void InitCharacters(List<global::TNHFramework.ObjectTemplates.CustomCharacter> characters, bool isCustom)
		{
			for (int i = 0; i < characters.Count; i++)
			{
				global::TNHFramework.ObjectTemplates.CustomCharacter customCharacter = characters[i];
				try
				{
					customCharacter.DelayedInit(isCustom);
				}
				catch (Exception ex)
				{
					TNHFrameworkLogger.LogError("Failed to load character: " + customCharacter.DisplayName + ". Error Output:\n" + ex.ToString());
					characters.RemoveAt(i);
					LoadedTemplateManager.LoadedCharactersDict.Remove(customCharacter.GetCharacter());
					i--;
				}
			}
		}

		private static void InitSosigs(List<SosigTemplate> sosigs)
		{
			for (int i = 0; i < sosigs.Count; i++)
			{
				SosigTemplate sosigTemplate = sosigs[i];
				try
				{
					sosigTemplate.DelayedInit();
				}
				catch (Exception ex)
				{
					TNHFrameworkLogger.LogError("Failed to load sosig: " + sosigTemplate.DisplayName + ". Error Output:\n" + ex.ToString());
					for (int j = 0; j < LoadedTemplateManager.LoadedCharactersDict.Values.Count; j++)
					{
						KeyValuePair<TNH_CharacterDef, global::TNHFramework.ObjectTemplates.CustomCharacter> keyValuePair = LoadedTemplateManager.LoadedCharactersDict.ToList()[j];
						if (keyValuePair.Value.CharacterUsesSosig(sosigTemplate.SosigEnemyID))
						{
							TNHFrameworkLogger.LogError("Removing character that used removed sosig: " + keyValuePair.Value.DisplayName);
							LoadedTemplateManager.LoadedCharactersDict.Remove(keyValuePair.Key);
							j--;
						}
					}
				}
			}
		}

		public static void RefreshTNHUI(TNH_UIManager instance, List<CharacterCategory> Categories, TNH_CharacterDatabase CharDatabase)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected I4, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected I4, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			TNHFrameworkLogger.Log("Refreshing TNH UI", TNHFrameworkLogger.LogType.General);
			foreach (TNH_CharacterDef key in LoadedTemplateManager.LoadedCharactersDict.Keys)
			{
				bool flag = false;
				foreach (CharacterCategory Category in Categories)
				{
					if (Category.CategoryName == LoadedTemplateManager.LoadedCharactersDict[key].CategoryData.Name)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					Categories.Insert(LoadedTemplateManager.LoadedCharactersDict[key].CategoryData.Priority, new CharacterCategory
					{
						CategoryName = LoadedTemplateManager.LoadedCharactersDict[key].CategoryData.Name,
						Characters = new List<TNH_Char>()
					});
				}
				if (!Categories[(int)key.Group].Characters.Contains(key.CharacterID))
				{
					Categories[(int)key.Group].Characters.Add(key.CharacterID);
					CharDatabase.Characters.Add(key);
				}
			}
			Traverse val = Traverse.Create((object)instance);
			int num = (int)val.Field("m_selectedCategory").GetValue();
			int selectedButton = (int)val.Field("m_selectedCharacter").GetValue();
			val.Method("SetSelectedCategory", new object[1] { num }).GetValue();
			instance.OBS_CharCategory.SetSelectedButton(selectedButton);
		}
	}
	public static class LoadedTemplateManager
	{
		public static Dictionary<TNH_CharacterDef, global::TNHFramework.ObjectTemplates.CustomCharacter> LoadedCharactersDict = new Dictionary<TNH_CharacterDef, global::TNHFramework.ObjectTemplates.CustomCharacter>();

		public static Dictionary<SosigEnemyTemplate, SosigTemplate> LoadedSosigsDict = new Dictionary<SosigEnemyTemplate, SosigTemplate>();

		public static Dictionary<PoolEntry, global::TNHFramework.ObjectTemplates.EquipmentPool> EquipmentPoolDictionary = new Dictionary<PoolEntry, global::TNHFramework.ObjectTemplates.EquipmentPool>();

		public static Dictionary<string, VaultFile> LoadedVaultFiles = new Dictionary<string, VaultFile>();

		public static Dictionary<string, SavedGunSerializable> LoadedLegacyVaultFiles = new Dictionary<string, SavedGunSerializable>();

		public static List<global::TNHFramework.ObjectTemplates.CustomCharacter> CustomCharacters = new List<global::TNHFramework.ObjectTemplates.CustomCharacter>();

		public static List<global::TNHFramework.ObjectTemplates.CustomCharacter> DefaultCharacters = new List<global::TNHFramework.ObjectTemplates.CustomCharacter>();

		public static List<SosigTemplate> CustomSosigs = new List<SosigTemplate>();

		public static List<SosigEnemyTemplate> DefaultSosigs = new List<SosigEnemyTemplate>();

		public static Dictionary<string, int> SosigIDDict = new Dictionary<string, int>();

		public static int NewSosigID = 30000;

		public static int NewCharacterID = 1000;

		public static Dictionary<string, Sprite> DefaultIconSprites = new Dictionary<string, Sprite>();

		public static void AddSosigTemplate(SosigTemplate template)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			template.Validate();
			SosigEnemyTemplate sosigEnemyTemplate = template.GetSosigEnemyTemplate();
			if (!SosigIDDict.ContainsKey(template.SosigEnemyID))
			{
				SosigIDDict.Add(template.SosigEnemyID, NewSosigID);
				NewSosigID++;
				sosigEnemyTemplate.SosigEnemyID = (SosigEnemyID)SosigIDDict[template.SosigEnemyID];
				CustomSosigs.Add(template);
				LoadedSosigsDict.Add(sosigEnemyTemplate, template);
				TNHFrameworkLogger.Log("Sosig added successfuly : " + template.DisplayName, TNHFrameworkLogger.LogType.Character);
			}
			else
			{
				TNHFrameworkLogger.LogError("Loaded sosig had same SosigEnemyID as another sosig -- SosigEnemyID : " + template.SosigEnemyID);
			}
		}

		public static void AddSosigTemplate(SosigEnemyTemplate realTemplate)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected I4, but got Unknown
			SosigTemplate sosigTemplate = new SosigTemplate(realTemplate);
			if (!SosigIDDict.ContainsKey(sosigTemplate.SosigEnemyID))
			{
				SosigIDDict.Add(sosigTemplate.SosigEnemyID, (int)realTemplate.SosigEnemyID);
				DefaultSosigs.Add(realTemplate);
				LoadedSosigsDict.Add(realTemplate, sosigTemplate);
				TNHFrameworkLogger.Log("Sosig added successfuly : " + sosigTemplate.DisplayName, TNHFrameworkLogger.LogType.Character);
			}
			else
			{
				TNHFrameworkLogger.LogError("Loaded sosig had same SosigEnemyID as another sosig -- SosigEnemyID : " + sosigTemplate.SosigEnemyID);
			}
		}

		public static void AddCharacterTemplate(global::TNHFramework.ObjectTemplates.CustomCharacter template, Sprite thumbnail)
		{
			template.Validate();
			CustomCharacters.Add(template);
			LoadedCharactersDict.Add(template.GetCharacter(NewCharacterID, thumbnail), template);
			foreach (global::TNHFramework.ObjectTemplates.EquipmentPool equipmentPool in template.EquipmentPools)
			{
				EquipmentPoolDictionary.Add(equipmentPool.GetPoolEntry(), equipmentPool);
			}
			NewCharacterID++;
			TNHFrameworkLogger.Log("Character added successfuly : " + template.DisplayName, TNHFrameworkLogger.LogType.Character);
		}

		public static void AddCharacterTemplate(TNH_CharacterDef realTemplate)
		{
			global::TNHFramework.ObjectTemplates.CustomCharacter customCharacter = new global::TNHFramework.ObjectTemplates.CustomCharacter(realTemplate);
			DefaultCharacters.Add(customCharacter);
			LoadedCharactersDict.Add(realTemplate, customCharacter);
			foreach (global::TNHFramework.ObjectTemplates.EquipmentPool equipmentPool in customCharacter.EquipmentPools)
			{
				if (!EquipmentPoolDictionary.ContainsKey(equipmentPool.GetPoolEntry()))
				{
					EquipmentPoolDictionary.Add(equipmentPool.GetPoolEntry(), equipmentPool);
				}
			}
			TNHFrameworkLogger.Log("Character added successfuly : " + realTemplate.DisplayName, TNHFrameworkLogger.LogType.Character);
		}

		public static void AddVaultFile(VaultFile template)
		{
			if (!LoadedVaultFiles.ContainsKey(template.FileName))
			{
				LoadedVaultFiles.Add(template.FileName, template);
			}
		}

		public static void AddVaultFile(SavedGunSerializable template)
		{
			template.Validate();
			if (!LoadedLegacyVaultFiles.ContainsKey(template.FileName))
			{
				LoadedLegacyVaultFiles.Add(template.FileName, template);
			}
		}
	}
	public enum PanelType
	{
		MagDuplicator,
		Recycler,
		AmmoReloader,
		MagUpgrader,
		AddFullAuto,
		AmmoPurchase,
		FireRateUp,
		FireRateDown,
		MagPurchase
	}
	public class MagazinePanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public Dictionary<string, MagazineBlacklistEntry> blacklist;

		public int DupeCost = 2;

		public int UpgradeCost = 3;

		public int PurchaseCost = 2;

		private int numTokensSelected = 0;

		public static Sprite background;

		private TNH_ObjectConstructorIcon DupeIcon;

		private TNH_ObjectConstructorIcon UpgradeIcon;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		private Text priceText_0;

		private Text priceText_1;

		private Text priceText_2;

		private FVRPhysicalObject selectedObject = null;

		private FVRFireArmMagazine detectedMag = null;

		private Speedloader detectedSpeedLoader = null;

		private FVRObject purchaseMag = null;

		private FVRObject upgradeMag = null;

		private Collider[] colBuffer = (Collider[])(object)new Collider[50];

		public void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			original = ((Component)this).gameObject.GetComponent<TNH_MagDuplicator>();
			if ((Object)(object)original == (Object)null)
			{
				TNHFrameworkLogger.LogError("Mag Upgrader failed, original Mag Duplicator was null!");
			}
			((Behaviour)original).enabled = false;
			blacklist = LoadedTemplateManager.LoadedCharactersDict[original.M.C].GetMagazineBlacklist();
			InitPanel();
			UpdateIcons();
			GM.TNH_Manager.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

		private void OnDestroy()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if ((Object)(object)original.M != (Object)null)
			{
				original.M.TokenCountChangeEvent -= new TokenCountChange(UpdateTokenDisplay);
			}
		}

		private void InitPanel()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)");
			Text component = ((Component)val).gameObject.GetComponent<Text>();
			component.text = "-- Mag Dupe / Upgrade / Buy --";
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val3 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val4 = val3.Find("Icon_0");
			val4.localPosition = new Vector3(-270f, -200f, 0f);
			Transform val5 = val3.Find("Icon_1");
			val5.localPosition = new Vector3(0f, -200f, 0f);
			Transform transform = Object.Instantiate<GameObject>(((Component)val5).gameObject, val3).transform;
			transform.localPosition = new Vector3(275f, -200f, 0f);
			Transform val6 = ((Component)original).transform.Find("PointableButton_0");
			val6.position = val4.position;
			Transform val7 = ((Component)original).transform.Find("PointableButton_1");
			val7.position = val5.position;
			Transform transform2 = Object.Instantiate<GameObject>(((Component)val7).gameObject, val7.parent).transform;
			transform2.position = transform.position;
			Image component2 = ((Component)val2).gameObject.GetComponent<Image>();
			component2.sprite = background;
			DupeIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			UpgradeIcon = ((Component)val5).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			PurchaseIcon = ((Component)transform).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component3 = ((Component)val6).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				DupeMagButton();
			});
			Button component4 = ((Component)val7).gameObject.GetComponent<Button>();
			component4.onClick = new ButtonClickedEvent();
			((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
			{
				UpgradeMagButton();
			});
			Button component5 = ((Component)transform2).gameObject.GetComponent<Button>();
			component5.onClick = new ButtonClickedEvent();
			((UnityEvent)component5.onClick).AddListener((UnityAction)delegate
			{
				PurchaseMagButton();
			});
			priceText_0 = AddPriceText(val4, new Vector3(-235f, 155f, 0f));
			priceText_1 = AddPriceText(val5, new Vector3(40f, 155f, 0f));
			priceText_2 = AddPriceText(transform, new Vector3(355f, 150f, 0f));
			priceText_2.alignment = (TextAnchor)3;
			priceText_0.text = "x" + DupeCost;
			priceText_1.text = "x" + UpgradeCost;
			priceText_2.text = "x" + PurchaseCost;
		}

		private Text AddPriceText(Transform iconTransform, Vector3 localPosition)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0092: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PriceCanvas");
			val.transform.SetParent(iconTransform.parent);
			val.transform.rotation = iconTransform.rotation;
			val.transform.localPosition = localPosition;
			Canvas val2 = val.AddComponent<Canvas>();
			RectTransform component = ((Component)val2).GetComponent<RectTransform>();
			val2.renderMode = (RenderMode)2;
			component.sizeDelta = new Vector2(1f, 1f);
			GameObject val3 = new GameObject("Text");
			val3.transform.SetParent(val.transform);
			val3.transform.rotation = val.transform.rotation;
			val3.transform.localPosition = Vector3.zero;
			val3.AddComponent<CanvasRenderer>();
			Text val4 = val3.AddComponent<Text>();
			Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
			val4.text = "x?";
			val4.alignment = (TextAnchor)4;
			val4.fontSize = 30;
			val4.fontStyle = (FontStyle)1;
			val3.transform.localScale = new Vector3(0.0015f, 0.0015f, 0.0015f);
			val4.font = font;
			val4.horizontalOverflow = (HorizontalWrapMode)1;
			return val4;
		}

		private void DupeMagButton()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)(object)detectedMag == (Object)null && (Object)(object)detectedSpeedLoader == (Object)null) || original.M.GetNumTokens() < DupeCost)
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(DupeCost);
			if ((Object)(object)detectedMag != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Duplicated " + ((FVRPhysicalObject)detectedMag).ObjectWrapper.DisplayName);
				FirearmUtils.SpawnDuplicateMagazine(original.M, detectedMag, original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
			}
			else
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Duplicated " + ((FVRPhysicalObject)detectedSpeedLoader).ObjectWrapper.DisplayName);
				FirearmUtils.SpawnDuplicateSpeedloader(original.M, detectedSpeedLoader, original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
			}
			ClearSelection();
			UpdateIcons();
		}

		private void UpgradeMagButton()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)upgradeMag == (Object)null || original.M.GetNumTokens() < UpgradeCost)
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(UpgradeCost);
			TNHFramework.HoldActions[original.M.m_level].Add("Upgraded " + ((FVRPhysicalObject)detectedMag).ObjectWrapper.DisplayName + " To " + upgradeMag.DisplayName);
			Object.Destroy((Object)(object)((FVRInteractiveObject)detectedMag).GameObject);
			Object.Instantiate<GameObject>(((AnvilAsset)upgradeMag).GetGameObject(), original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
			ClearSelection();
			UpdateIcons();
		}

		private void PurchaseMagButton()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)purchaseMag == (Object)null || original.M.GetNumTokens() < PurchaseCost)
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(PurchaseCost);
			TNHFramework.HoldActions[original.M.m_level].Add("Purchased " + purchaseMag.DisplayName);
			Object.Instantiate<GameObject>(((AnvilAsset)purchaseMag).GetGameObject(), original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
			ClearSelection();
			UpdateIcons();
		}

		private void Update()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (Vector3.Distance(original.ScanningVolume.position, ((Component)GM.CurrentPlayerBody.Head).transform.position) < 2f)
			{
				Scan();
				UpdateIcons();
			}
			else
			{
				ClearSelection();
			}
		}

		private void ClearSelection()
		{
			detectedMag = null;
			detectedSpeedLoader = null;
			purchaseMag = null;
			upgradeMag = null;
			selectedObject = null;
			TG_Bounds placementBoundsRenderer = original.PlacementBoundsRenderer;
			if (placementBoundsRenderer != null)
			{
				((Component)placementBoundsRenderer).gameObject.SetActive(false);
			}
		}

		private void Scan()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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)
			global::TNHFramework.ObjectTemplates.CustomCharacter customCharacter = LoadedTemplateManager.LoadedCharactersDict[original.M.C];
			if ((Object)(object)selectedObject != (Object)null)
			{
				Bounds val = default(Bounds);
				((Bounds)(ref val))..ctor(((Component)selectedObject).transform.position, new Vector3(0.01f, 0.01f, 0.01f));
				Collider[] componentsInChildren = ((Component)((Component)selectedObject).transform).GetComponentsInChildren<Collider>();
				Collider[] array = componentsInChildren;
				foreach (Collider val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && val2.isTrigger)
					{
						((Bounds)(ref val)).Encapsulate(val2.bounds);
					}
				}
				Vector3 position = selectedObject.RootRigidbody.position;
				Vector3 val3 = ((Bounds)(ref val)).center - ((Component)selectedObject).transform.position;
				if ((Object)(object)original.PlacementBoundsRenderer == (Object)null)
				{
					GameObject val4 = Object.Instantiate<GameObject>(original.PlacementBoundsPrefab, position, Quaternion.identity);
					original.PlacementBoundsRenderer = val4.GetComponent<TG_Bounds>();
				}
				((Component)original.PlacementBoundsRenderer).gameObject.SetActive(true);
				original.PlacementBoundsRenderer.PoseAndRescale(position + val3, ((Bounds)(ref val)).extents * 2f, original.EmitterPoint.position);
				Bounds val5 = default(Bounds);
				((Bounds)(ref val5))..ctor(original.ScanningVolume.position, new Vector3(0.001f, 0.001f, 0.001f));
				((Bounds)(ref val5)).Encapsulate(original.ScanningVolume.TransformPoint(new Vector3(0.5f, 0.5f, 0.5f)));
				((Bounds)(ref val5)).Encapsulate(original.ScanningVolume.TransformPoint(new Vector3(-0.5f, -0.5f, -0.5f)));
				if (!((Bounds)(ref val)).Intersects(val5))
				{
					ClearSelection();
				}
			}
			if (!((Object)(object)selectedObject == (Object)null))
			{
				return;
			}
			int num = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, LayerMask.op_Implicit(original.ScanningLM), (QueryTriggerInteraction)2);
			detectedMag = null;
			detectedSpeedLoader = null;
			purchaseMag = null;
			upgradeMag = null;
			for (int j = 0; j < num; j++)
			{
				if (!((Object)(object)colBuffer[j].attachedRigidbody != (Object)null))
				{
					continue;
				}
				FVRFireArm component = ((Component)colBuffer[j]).GetComponent<FVRFireArm>();
				if ((Object)(object)purchaseMag == (Object)null && (Object)(object)component != (Object)null && !((FVRInteractiveObject)component).IsHeld && (Object)(object)((FVRPhysicalObject)component).QuickbeltSlot == (Object)null)
				{
					MagazineBlacklistEntry magazineBlacklistEntry = (blacklist.ContainsKey(((FVRPhysicalObject)component).ObjectWrapper.ItemID) ? blacklist[((FVRPhysicalObject)component).ObjectWrapper.ItemID] : null);
					List<FVRObject> compatibleMagazines = FirearmUtils.GetCompatibleMagazines(((FVRPhysicalObject)component).ObjectWrapper, -1, -1, smallestIfEmpty: false, customCharacter.GlobalObjectBlacklist, magazineBlacklistEntry);
					if (compatibleMagazines.Count > 0)
					{
						purchaseMag = FirearmUtils.GetSmallestCapacityMagazine(compatibleMagazines, customCharacter.GlobalObjectBlacklist, magazineBlacklistEntry);
						selectedObject = (FVRPhysicalObject)(object)component;
					}
				}
				FVRFireArmMagazine component2 = ((Component)colBuffer[j].attachedRigidbody).GetComponent<FVRFireArmMagazine>();
				if ((Object)(object)component2 != (Object)null && (Object)(object)component2.FireArm == (Object)null && !((FVRInteractiveObject)component2).IsHeld && (Object)(object)((FVRPhysicalObject)component2).QuickbeltSlot == (Object)null && !component2.IsIntegrated)
				{
					detectedMag = component2;
					selectedObject = (FVRPhysicalObject)(object)component2;
				}
				Speedloader component3 = ((Component)colBuffer[j].attachedRigidbody).GetComponent<Speedloader>();
				if ((Object)(object)component3 != (Object)null && !((FVRInteractiveObject)component3).IsHeld && (Object)(object)((FVRPhysicalObject)component3).QuickbeltSlot == (Object)null && component3.IsPretendingToBeAMagazine)
				{
					detectedSpeedLoader = component3;
					selectedObject = (FVRPhysicalObject)(object)component3;
				}
				if ((Object)(object)purchaseMag != (Object)null && ((Object)(object)detectedMag != (Object)null || (Object)(object)detectedSpeedLoader != (Object)null))
				{
					break;
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0023: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			global::TNHFramework.ObjectTemplates.CustomCharacter customCharacter = LoadedTemplateManager.LoadedCharactersDict[original.M.C];
			DupeIcon.State = (IconState)2;
			UpgradeIcon.State = (IconState)2;
			PurchaseIcon.State = (IconState)2;
			int numTokens = GM.TNH_Manager.GetNumTokens();
			numTokensSelected = 0;
			if ((Object)(object)detectedMag != (Object)null || (Object)(object)detectedSpeedLoader != (Object)null)
			{
				DupeIcon.State = (IconState)1;
				if (numTokens >= DupeCost)
				{
					numTokensSelected = DupeCost;
				}
			}
			if ((Object)(object)purchaseMag != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
				if (numTokens >= PurchaseCost)
				{
					numTokensSelected = PurchaseCost;
				}
			}
			if ((Object)(object)detectedMag != (Object)null)
			{
				upgradeMag = FirearmUtils.GetNextHighestCapacityMagazine(((FVRPhysicalObject)detectedMag).ObjectWrapper);
				if ((Object)(object)upgradeMag != (Object)null)
				{
					UpgradeIcon.State = (IconState)1;
					if (numTokens >= UpgradeCost)
					{
						numTokensSelected = UpgradeCost;
					}
				}
			}
			DupeIcon.UpdateIconDisplay();
			UpgradeIcon.UpdateIconDisplay();
			PurchaseIcon.UpdateIconDisplay();
			UpdateTokenDisplay(numTokens);
		}

		private void UpdateTokenDisplay(int numTokens)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.TokenList.Count; i++)
			{
				if (i < numTokens)
				{
					if (i < numTokens - numTokensSelected)
					{
						((Graphic)original.TokenList[i]).color = original.Token_Unselected;
					}
					else
					{
						((Graphic)original.TokenList[i]).color = original.Token_Selected;
					}
				}
				else
				{
					((Graphic)original.TokenList[i]).color = original.Token_Empty;
				}
			}
		}
	}
	public class AmmoPurchasePanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public Dictionary<string, MagazineBlacklistEntry> blacklist;

		public int PanelCost = 1;

		private int numTokensSelected = 0;

		public static Sprite background;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		private FVRPhysicalObject selectedObject = null;

		private FVRFireArm detectedFirearm = null;

		private Collider[] colBuffer = (Collider[])(object)new Collider[50];

		public void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			original = ((Component)this).gameObject.GetComponent<TNH_MagDuplicator>();
			if ((Object)(object)original == (Object)null)
			{
				TNHFrameworkLogger.LogError("Ammo Purchaser failed, original mag duplicator was null!");
			}
			((Behaviour)original).enabled = false;
			InitPanel();
			UpdateIcons();
			GM.TNH_Manager.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

		private void OnDestroy()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if ((Object)(object)original.M != (Object)null)
			{
				original.M.TokenCountChangeEvent -= new TokenCountChange(UpdateTokenDisplay);
			}
		}

		private void InitPanel()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)");
			Text component = ((Component)val).gameObject.GetComponent<Text>();
			component.text = "-- Ammo Purchaser --";
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val3 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val4 = val3.Find("Icon_0");
			val4.localPosition = new Vector3(0f, -290f, 0f);
			Transform val5 = val3.Find("Icon_1");
			Object.Destroy((Object)(object)((Component)val5).gameObject);
			Transform val6 = ((Component)original).transform.Find("PointableButton_0");
			val6.position = val4.position;
			Transform val7 = ((Component)original).transform.Find("PointableButton_1");
			Object.Destroy((Object)(object)((Component)val7).gameObject);
			Image component2 = ((Component)val2).gameObject.GetComponent<Image>();
			component2.sprite = background;
			PurchaseIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component3 = ((Component)val6).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				PurchaseAmmoButton();
			});
		}

		public void PurchaseAmmoButton()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)detectedFirearm == (Object)null || original.M.GetNumTokens() < PanelCost)
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(PanelCost);
			OTagFirearmRoundPower roundPower = AM.GetRoundPower(detectedFirearm.RoundType);
			int roundsToSpawn = GetRoundsToSpawn(roundPower);
			TNHFrameworkLogger.Log("Compatible rounds count for " + ((FVRPhysicalObject)detectedFirearm).ObjectWrapper.ItemID + ": " + IM.OD[((FVRPhysicalObject)detectedFirearm).ObjectWrapper.ItemID].CompatibleSingleRounds.Count, TNHFrameworkLogger.LogType.General);
			global::TNHFramework.ObjectTemplates.CustomCharacter customCharacter = LoadedTemplateManager.LoadedCharactersDict[original.M.C];
			MagazineBlacklistEntry magazineBlacklistEntry = null;
			if (customCharacter.GetMagazineBlacklist().ContainsKey(((FVRPhysicalObject)detectedFirearm).ObjectWrapper.ItemID))
			{
				magazineBlacklistEntry = customCharacter.GetMagazineBlacklist()[((FVRPhysicalObject)detectedFirearm).ObjectWrapper.ItemID];
			}
			FVRObject random = FirearmUtils.GetCompatibleRounds(((FVRPhysicalObject)detectedFirearm).ObjectWrapper, customCharacter.ValidAmmoEras, customCharacter.ValidAmmoSets, customCharacter.GlobalAmmoBlacklist, customCharacter.GlobalObjectBlacklist, magazineBlacklistEntry).GetRandom();
			AnvilManager.Run(SpawnRounds(original.M, random, roundsToSpawn));
			ClearSelection();
			UpdateIcons();
		}

		public IEnumerator SpawnRounds(TNH_Manager M, FVRObject bullet, int count)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((AnvilAsset)bullet).GetGameObject();
			return TNHFrameworkUtils.InstantiateMultiple(M, gameObject, original.Spawnpoint_Mag.position, count);
		}

		public int GetRoundsToSpawn(OTagFirearmRoundPower roundPower)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Invalid comparison between Unknown and I4
			if ((int)roundPower == 3)
			{
				return 18;
			}
			if ((int)roundPower == 2)
			{
				return 30;
			}
			if ((int)roundPower == 1)
			{
				return 30;
			}
			if ((int)roundPower == 4)
			{
				return 20;
			}
			if ((int)roundPower == 5)
			{
				return 16;
			}
			if ((int)roundPower == 8)
			{
				return 16;
			}
			if ((int)roundPower == 6)
			{
				return 6;
			}
			if ((int)roundPower == 7)
			{
				return 3;
			}
			return 10;
		}

		private void Update()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (Vector3.Distance(original.ScanningVolume.position, ((Component)GM.CurrentPlayerBody.Head).transform.position) < 2f)
			{
				Scan();
				UpdateIcons();
			}
			else
			{
				ClearSelection();
			}
		}

		private void ClearSelection()
		{
			detectedFirearm = null;
			selectedObject = null;
			TG_Bounds placementBoundsRenderer = original.PlacementBoundsRenderer;
			if (placementBoundsRenderer != null)
			{
				((Component)placementBoundsRenderer).gameObject.SetActive(false);
			}
		}

		private void Scan()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)selectedObject != (Object)null)
			{
				Bounds val = default(Bounds);
				((Bounds)(ref val))..ctor(((Component)selectedObject).transform.position, new Vector3(0.01f, 0.01f, 0.01f));
				Collider[] componentsInChildren = ((Component)((Component)selectedObject).transform).GetComponentsInChildren<Collider>();
				Collider[] array = componentsInChildren;
				foreach (Collider val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && val2.isTrigger)
					{
						((Bounds)(ref val)).Encapsulate(val2.bounds);
					}
				}
				Vector3 position = selectedObject.RootRigidbody.position;
				Vector3 val3 = ((Bounds)(ref val)).center - ((Component)selectedObject).transform.position;
				if ((Object)(object)original.PlacementBoundsRenderer == (Object)null)
				{
					GameObject val4 = Object.Instantiate<GameObject>(original.PlacementBoundsPrefab, position, Quaternion.identity);
					original.PlacementBoundsRenderer = val4.GetComponent<TG_Bounds>();
				}
				((Component)original.PlacementBoundsRenderer).gameObject.SetActive(true);
				original.PlacementBoundsRenderer.PoseAndRescale(position + val3, ((Bounds)(ref val)).extents * 2f, original.EmitterPoint.position);
				Bounds val5 = default(Bounds);
				((Bounds)(ref val5))..ctor(original.ScanningVolume.position, new Vector3(0.001f, 0.001f, 0.001f));
				((Bounds)(ref val5)).Encapsulate(original.ScanningVolume.TransformPoint(new Vector3(0.5f, 0.5f, 0.5f)));
				((Bounds)(ref val5)).Encapsulate(original.ScanningVolume.TransformPoint(new Vector3(-0.5f, -0.5f, -0.5f)));
				if (!((Bounds)(ref val)).Intersects(val5))
				{
					ClearSelection();
				}
			}
			if (!((Object)(object)selectedObject == (Object)null))
			{
				return;
			}
			int num = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, LayerMask.op_Implicit(original.ScanningLM), (QueryTriggerInteraction)2);
			detectedFirearm = null;
			for (int j = 0; j < num; j++)
			{
				if ((Object)(object)colBuffer[j].attachedRigidbody != (Object)null)
				{
					FVRFireArm component = ((Component)colBuffer[j].attachedRigidbody).GetComponent<FVRFireArm>();
					if ((Object)(object)component != (Object)null && !((FVRInteractiveObject)component).IsHeld && (Object)(object)((FVRPhysicalObject)component).QuickbeltSlot == (Object)null)
					{
						detectedFirearm = component;
						selectedObject = (FVRPhysicalObject)(object)component;
						break;
					}
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			PurchaseIcon.State = (IconState)2;
			int numTokens = GM.TNH_Manager.GetNumTokens();
			numTokensSelected = 0;
			if ((Object)(object)detectedFirearm != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
				if (numTokens >= PanelCost)
				{
					numTokensSelected = PanelCost;
				}
			}
			PurchaseIcon.UpdateIconDisplay();
			UpdateTokenDisplay(numTokens);
		}

		private void UpdateTokenDisplay(int numTokens)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.TokenList.Count; i++)
			{
				if (i < numTokens)
				{
					if (i < numTokens - numTokensSelected)
					{
						((Graphic)original.TokenList[i]).color = original.Token_Unselected;
					}
					else
					{
						((Graphic)original.TokenList[i]).color = original.Token_Selected;
					}
				}
				else
				{
					((Graphic)original.TokenList[i]).color = original.Token_Empty;
				}
			}
		}
	}
	public class FullAutoPanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public int PanelCost = 4;

		private int numTokensSelected = 0;

		public static Sprite background;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		private FVRPhysicalObject selectedObject = null;

		public Handgun detectedHandgun = null;

		public ClosedBoltWeapon detectedClosedBolt = null;

		public OpenBoltReceiver detectedOpenBolt = null;

		private Collider[] colBuffer = (Collider[])(object)new Collider[50];

		public void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			original = ((Component)this).gameObject.GetComponent<TNH_MagDuplicator>();
			if ((Object)(object)original == (Object)null)
			{
				TNHFrameworkLogger.LogError("Full Auto Enabler failed, original Mag Duplicator was null!");
			}
			((Behaviour)original).enabled = false;
			InitPanel();
			UpdateIcons();
			GM.TNH_Manager.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

		private void OnDestroy()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if ((Object)(object)original.M != (Object)null)
			{
				original.M.TokenCountChangeEvent -= new TokenCountChange(UpdateTokenDisplay);
			}
		}

		private void InitPanel()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)");
			Text component = ((Component)val).gameObject.GetComponent<Text>();
			component.text = "-- Full Auto Upgrader --";
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val3 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val4 = val3.Find("Icon_0");
			val4.localPosition = new Vector3(0f, -290f, 0f);
			Transform val5 = val3.Find("Icon_1");
			Object.Destroy((Object)(object)((Component)val5).gameObject);
			Transform val6 = ((Component)original).transform.Find("PointableButton_0");
			val6.position = val4.position;
			Transform val7 = ((Component)original).transform.Find("PointableButton_1");
			Object.Destroy((Object)(object)((Component)val7).gameObject);
			Image component2 = ((Component)val2).gameObject.GetComponent<Image>();
			component2.sprite = background;
			PurchaseIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component3 = ((Component)val6).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				AddFullAutoButton();
			});
		}

		public void AddFullAutoButton()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)(object)detectedHandgun == (Object)null && (Object)(object)detectedClosedBolt == (Object)null && (Object)(object)detectedOpenBolt == (Object)null) || PanelCost > original.M.GetNumTokens())
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(PanelCost);
			if ((Object)(object)detectedHandgun != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Added Full-Auto To " + ((FVRPhysicalObject)detectedHandgun).ObjectWrapper.DisplayName);
				AddFullAutoToHandgun(detectedHandgun);
				ClearSelection();
			}
			else if ((Object)(object)detectedClosedBolt != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Added Full-Auto To " + ((FVRPhysicalObject)detectedClosedBolt).ObjectWrapper.DisplayName);
				AddFullAutoToClosedBolt(detectedClosedBolt);
				ClearSelection();
			}
			else if ((Object)(object)detectedOpenBolt != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Added Full-Auto To " + ((FVRPhysicalObject)detectedOpenBolt).ObjectWrapper.DisplayName);
				AddFullAutoToOpenBolt(detectedOpenBolt);
				ClearSelection();
			}
		}

		private void AddFullAutoToHandgun(Handgun gun)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			FireSelectorMode val = new FireSelectorMode();
			val.SelectorPosition = 0f;
			val.ModeType = (FireSelectorModeType)2;
			if (gun.FireSelectorModes != null)
			{
				FireSelectorMode[] fireSelectorModes = gun.FireSelectorModes;
				foreach (FireSelectorMode val2 in fireSelectorModes)
				{
					Debug.Log((object)val2.ModeType);
				}
			}
			if (gun.FireSelectorModes == null || gun.FireSelectorModes.Length == 0)
			{
				FireSelectorMode val3 = new FireSelectorMode();
				val3.SelectorPosition = 0f;
				val3.ModeType = (FireSelectorModeType)1;
				gun.FireSelectorModes = (FireSelectorMode[])(object)new FireSelectorMode[2] { val3, val };
			}
			else
			{
				List<FireSelectorMode> list = new List<FireSelectorMode>(gun.FireSelectorModes) { val };
				gun.FireSelectorModes = list.ToArray();
			}
			if (!gun.HasFireSelector)
			{
				gun.HasFireSelector = true;
				if (gun.HasSafety)
				{
					gun.FireSelectorAxis = gun.SafetyAxis;
					gun.FireSelectorInterpStyle = gun.Safety_Interp;
					gun.FireSelector = gun.Safety;
				}
				else if ((Object)(object)gun.FireSelector == (Object)null)
				{
					gun.FireSelector = Object.Instantiate<GameObject>(new GameObject(), ((FVRInteractiveObject)gun).GameObject.transform).transform;
				}
			}
			if (gun.HasSafety)
			{
				((FVRFireArm)gun).AudioClipSet.FireSelector = ((FVRFireArm)gun).AudioClipSet.Safety;
				gun.HasSafety = false;
			}
		}

		private void AddFullAutoToClosedBolt(ClosedBoltWeapon gun)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: 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)
			//IL_0039: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			FireSelectorMode val = new FireSelectorMode();
			val.ModeType = (FireSelectorModeType)3;
			val.SelectorPosition = 0f;
			if (gun.FireSelector_Modes == null || gun.FireSelector_Modes.Length == 0)
			{
				FireSelectorMode val2 = new FireSelectorMode();
				val2.ModeType = (FireSelectorModeType)1;
				val2.SelectorPosition = 0f;
				gun.FireSelector_Modes = (FireSelectorMode[])(object)new FireSelectorMode[2] { val2, val };
			}
			else
			{
				List<FireSelectorMode> list = new List<FireSelectorMode>(gun.FireSelector_Modes) { val };
				gun.FireSelector_Modes = list.ToArray();
			}
		}

		private void AddFullAutoToOpenBolt(OpenBoltReceiver gun)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: 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)
			//IL_0039: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			FireSelectorMode val = new FireSelectorMode();
			val.ModeType = (FireSelectorModeType)2;
			val.SelectorPosition = 0f;
			if (gun.FireSelector_Modes == null || gun.FireSelector_Modes.Length == 0)
			{
				FireSelectorMode val2 = new FireSelectorMode();
				val2.ModeType = (FireSelectorModeType)1;
				val2.SelectorPosition = 0f;
				gun.FireSelector_Modes = (FireSelectorMode[])(object)new FireSelectorMode[2] { val2, val };
			}
			else
			{
				List<FireSelectorMode> list = new List<FireSelectorMode>(gun.FireSelector_Modes) { val };
				gun.FireSelector_Modes = list.ToArray();
			}
		}

		private void Update()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (Vector3.Distance(original.ScanningVolume.position, ((Component)GM.CurrentPlayerBody.Head).transform.position) < 2f)
			{
				Scan();
				UpdateIcons();
			}
			else
			{
				ClearSelection();
			}
		}

		private void ClearSelection()
		{
			detectedHandgun = null;
			detectedClosedBolt = null;
			detectedOpenBolt = null;
			selectedObject = null;
			TG_Bounds placementBoundsRenderer = original.PlacementBoundsRenderer;
			if (placementBoundsRenderer != null)
			{
				((Component)placementBoundsRenderer).gameObject.SetActive(false);
			}
		}

		private void Scan()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)selectedObject != (Object)null)
			{
				Bounds val = default(Bounds);
				((Bounds)(ref val))..ctor(((Component)selectedObject).transform.position, new Vector3(0.01f, 0.01f, 0.01f));
				Collider[] componentsInChildren = ((Component)((Component)selectedObject).transform).GetComponentsInChildren<Collider>();
				Collider[] array = componentsInChildren;
				foreach (Collider val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && val2.isTrigger)
					{
						((Bounds)(ref val)).Encapsulate(val2.bounds);
					}
				}
				Vector3 position = selectedObject.RootRigidbody.position;
				Vector3 val3 = ((Bounds)(ref val)).center - ((Component)selectedObject).transform.position;
				if ((Object)(object)original.PlacementBoundsRenderer == (Object)null)
				{
					GameObject val4 = Object.Instantiate<GameObject>(original.PlacementBoundsPrefab, position, Quaternion.identity);
					original.PlacementBoundsRenderer = val4.GetComponent<TG_Bounds>();
				}
				((Component)original.PlacementBoundsRenderer).gameObject.SetActive(true);
				original.PlacementBoundsRenderer.PoseAndRescale(position + val3, ((Bounds)(ref val)).extents * 2f, original.EmitterPoint.position);
				Bounds val5 = default(Bounds);
				((Bounds)(ref val5))..ctor(original.ScanningVolume.position, new Vector3(0.001f, 0.001f, 0.001f));
				((Bounds)(ref val5)).Encapsulate(original.ScanningVolume.TransformPoint(new Vector3(0.5f, 0.5f, 0.5f)));
				((Bounds)(ref val5)).Encapsulate(original.ScanningVolume.TransformPoint(new Vector3(-0.5f, -0.5f, -0.5f)));
				if (!((Bounds)(ref val)).Intersects(val5))
				{
					ClearSelection();
				}
			}
			if (!((Object)(object)selectedObject == (Object)null))
			{
				return;
			}
			detectedHandgun = null;
			detectedClosedBolt = null;
			detectedOpenBolt = null;
			int num = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, LayerMask.op_Implicit(original.ScanningLM), (QueryTriggerInteraction)2);
			for (int j = 0; j < num; j++)
			{
				if ((Object)(object)colBuffer[j].attachedRigidbody != (Object)null)
				{
					Handgun component = ((Component)colBuffer[j].attachedRigidbody).GetComponent<Handgun>();
					if ((Object)(object)component != (Object)null && (component.FireSelectorModes == null || !component.FireSelectorModes.Any((FireSelectorMode o) => (int)o.ModeType == 2)))
					{
						detectedHandgun = component;
						selectedObject = (FVRPhysicalObject)(object)component;
						break;
					}
					ClosedBoltWeapon component2 = ((Component)colBuffer[j].attachedRigidbody).GetComponent<ClosedBoltWeapon>();
					if ((Object)(object)component2 != (Object)null && (component2.FireSelector_Modes == null || !component2.FireSelector_Modes.Any((FireSelectorMode o) => (int)o.ModeType == 3)))
					{
						detectedClosedBolt = component2;
						selectedObject = (FVRPhysicalObject)(object)component2;
						break;
					}
					OpenBoltReceiver component3 = ((Component)colBuffer[j].attachedRigidbody).GetComponent<OpenBoltReceiver>();
					if ((Object)(object)component3 != (Object)null && (component3.FireSelector_Modes == null || !component3.FireSelector_Modes.Any((FireSelectorMode o) => (int)o.ModeType == 2)))
					{
						detectedOpenBolt = component3;
						selectedObject = (FVRPhysicalObject)(object)component3;
						break;
					}
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0008: 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)
			PurchaseIcon.State = (IconState)2;
			int numTokens = GM.TNH_Manager.GetNumTokens();
			numTokensSelected = 0;
			if ((Object)(object)detectedHandgun != (Object)null || (Object)(object)detectedClosedBolt != (Object)null || (Object)(object)detectedOpenBolt != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
				if (numTokens >= PanelCost)
				{
					numTokensSelected = PanelCost;
				}
			}
			PurchaseIcon.UpdateIconDisplay();
			UpdateTokenDisplay(numTokens);
		}

		private void UpdateTokenDisplay(int numTokens)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.TokenList.Count; i++)
			{
				if (i < numTokens)
				{
					if (i < numTokens - numTokensSelected)
					{
						((Graphic)original.TokenList[i]).color = original.Token_Unselected;
					}
					else
					{
						((Graphic)original.TokenList[i]).color = original.Token_Selected;
					}
				}
				else
				{
					((Graphic)original.TokenList[i]).color = original.Token_Empty;
				}
			}
		}
	}
	public class FireRatePanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public static Sprite background;

		public static Sprite plusSprite;

		public static Sprite minusSprite;

		private TNH_ObjectConstructorIcon PlusIcon;

		private TNH_ObjectConstructorIcon MinusIcon;

		private FVRPhysicalObject selectedObject = null;

		public Handgun detectedHandgun = null;

		public ClosedBoltWeapon detectedClosedBolt = null;

		public OpenBoltReceiver detectedOpenBolt = null;

		private int PanelCost = 1;

		private int numTokensSelected = 0;

		private Collider[] colBuffer = (Collider[])(object)new Collider[50];

		private float fireRateMultiplier = 1.5f;

		public void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			original = ((Component)this).gameObject.GetComponent<TNH_MagDuplicator>();
			if ((Object)(object)original == (Object)null)
			{
				TNHFrameworkLogger.LogError("Fire Rate Modifier failed, original Mag Duplicator was null!");
			}
			((Behaviour)original).enabled = false;
			InitPanel();
			UpdateIcons();
			GM.TNH_Manager.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

		private void OnDestroy()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if ((Object)(object)original.M != (Object)null)
			{
				original.M.TokenCountChangeEvent -= new TokenCountChange(UpdateTokenDisplay);
			}
		}

		public void InitPanel()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)");
			Text component = ((Component)val).gameObject.GetComponent<Text>();
			component.text = "-- Fire Rate Up / Down --";
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val3 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val4 = val3.Find("Icon_0");
			val4.localPosition = new Vector3(-165f, -290f, 0f);
			Transform val5 = val3.Find("Icon_1");
			val5.localPosition = new Vector3(165f, -290f, 0f);
			Transform val6 = ((Component)original).transform.Find("PointableButton_0");
			val6.position = val4.position;
			Transform val7 = ((Component)original).transform.Find("PointableButton_1");
			val7.position = val5.position;
			Image component2 = ((Component)val2).gameObject.GetComponent<Image>();
			component2.sprite = background;
			MinusIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			PlusIcon = ((Component)val5).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			MinusIcon.Sprite_Accept = minusSprite;
			PlusIcon.Sprite_Accept = plusSprite;
			Button component3 = ((Component)val6).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				DecreaseFireRateButton();
			});
			Button component4 = ((Component)val7).gameObject.GetComponent<Button>();
			component4.onClick = new ButtonClickedEvent();
			((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
			{
				IncreaseFireRateButton();
			});
		}

		public void IncreaseFireRateButton()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)(object)detectedHandgun == (Object)null && (Object)(object)detectedClosedBolt == (Object)null && (Object)(object)detectedOpenBolt == (Object)null) || PanelCost > original.M.GetNumTokens())
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(PanelCost);
			IncreaseFireRate();
			ClearSelection();
		}

		public void DecreaseFireRateButton()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)(object)detectedHandgun == (Object)null && (Object)(object)detectedClosedBolt == (Object)null && (Object)(object)detectedOpenBolt == (Object)null) || PanelCost > original.M.GetNumTokens())
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Spawn, ((Component)this).transform.position);
			original.M.SubtractTokens(PanelCost);
			DecreaseFireRate();
			ClearSelection();
		}

		public void IncreaseFireRate()
		{
			if ((Object)(object)detectedHandgun != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Increased Fire-Rate For " + ((FVRPhysicalObject)detectedHandgun).ObjectWrapper.DisplayName);
				HandgunSlide slide = detectedHandgun.Slide;
				slide.SpringStiffness *= fireRateMultiplier;
				HandgunSlide slide2 = detectedHandgun.Slide;
				slide2.Speed_Rearward *= fireRateMultiplier;
				HandgunSlide slide3 = detectedHandgun.Slide;
				slide3.Speed_Forward *= fireRateMultiplier;
			}
			else if ((Object)(object)detectedClosedBolt != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Increased Fire-Rate For " + ((FVRPhysicalObject)detectedClosedBolt).ObjectWrapper.DisplayName);
				ClosedBolt bolt = detectedClosedBolt.Bolt;
				bolt.SpringStiffness *= fireRateMultiplier;
				ClosedBolt bolt2 = detectedClosedBolt.Bolt;
				bolt2.Speed_Forward *= fireRateMultiplier;
				ClosedBolt bolt3 = detectedClosedBolt.Bolt;
				bolt3.Speed_Rearward *= fireRateMultiplier;
			}
			else
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Increased Fire-Rate For " + ((FVRPhysicalObject)detectedOpenBolt).ObjectWrapper.DisplayName);
				OpenBoltReceiverBolt bolt4 = detectedOpenBolt.Bolt;
				bolt4.BoltSpringStiffness *= fireRateMultiplier;
				OpenBoltReceiverBolt bolt5 = detectedOpenBolt.Bolt;
				bolt5.BoltSpeed_Forward *= fireRateMultiplier;
				OpenBoltReceiverBolt bolt6 = detectedOpenBolt.Bolt;
				bolt6.BoltSpeed_Rearward *= fireRateMultiplier;
			}
		}

		public void DecreaseFireRate()
		{
			if ((Object)(object)detectedHandgun != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Decreased Fire-Rate For " + ((FVRPhysicalObject)detectedHandgun).ObjectWrapper.DisplayName);
				HandgunSlide slide = detectedHandgun.Slide;
				slide.SpringStiffness *= 1f / fireRateMultiplier;
				HandgunSlide slide2 = detectedHandgun.Slide;
				slide2.Speed_Rearward *= 1f / fireRateMultiplier;
				HandgunSlide slide3 = detectedHandgun.Slide;
				slide3.Speed_Forward *= 1f / fireRateMultiplier;
			}
			else if ((Object)(object)detectedClosedBolt != (Object)null)
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Decreased Fire-Rate For " + ((FVRPhysicalObject)detectedClosedBolt).ObjectWrapper.DisplayName);
				ClosedBolt bolt = detectedClosedBolt.Bolt;
				bolt.SpringStiffness *= 1f / fireRateMultiplier;
				ClosedBolt bolt2 = detectedClosedBolt.Bolt;
				bolt2.Speed_Rearward *= 1f / fireRateMultiplier;
				ClosedBolt bolt3 = detectedClosedBolt.Bolt;
				bolt3.Speed_Forward *= 1f / fireRateMultiplier;
			}
			else
			{
				TNHFramework.HoldActions[original.M.m_level].Add("Decreased Fire-Rate For " + ((FVRPhysicalObject)detectedOpenBolt).ObjectWrapper.DisplayName);
				OpenBoltReceiverBolt bolt4 = detectedOpenBolt.Bolt;
				bolt4.BoltSpringStiffness *= 1f / fireRateMultiplier;
				OpenBoltReceiverBolt bolt5 = detectedOpenBolt.Bolt;
				bolt5.BoltSpeed_F