Decompiled source of TNHFramework v0.120.3

patchers/OldTweakerDisabler.dll

Decompiled 2 weeks 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.IgnoreSymbolStoreSequencePoints)]
[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 TweakerDisabler;

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);
		foreach (string text in directories)
		{
			Logger.LogInfo((object)("Found directory " + text));
			if (text.Contains("devyndamonster-TakeAndHoldTweaker"))
			{
				ModifyTNHTweakerFiles(text);
				break;
			}
		}
	}

	public static void ModifyTNHTweakerFiles(string dir)
	{
		string text = Path.Combine(dir, "TakeAndHoldTweaker.deli");
		string text2 = Path.Combine(dir, "TakeAndHoldTweaker.deli.bak");
		string text3 = Path.Combine(dir, "TakeAndHoldTweaker.deli.old");
		string text4 = Path.Combine(dir, "TakeAndHoldTweaker.deli.bak.old");
		if (File.Exists(text2))
		{
			if (File.Exists(text))
			{
				File.Delete(text2);
			}
			else
			{
				File.Move(text2, text);
			}
		}
		if (File.Exists(text4))
		{
			if (File.Exists(text3))
			{
				File.Delete(text4);
			}
			else
			{
				File.Move(text4, text3);
			}
		}
		if (File.Exists(text))
		{
			File.Copy(text, text3, overwrite: true);
			File.Delete(text);
			Logger.LogInfo((object)"Disabled old TakeAndHoldTweaker install. To re-enable it, you must disable TNHFramework, and then disable and enable TakeAndHoldFramework");
		}
	}
}

plugins/TNHTweaker/TNHFramework.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Deli;
using Deli.Immediate;
using Deli.Setup;
using Deli.VFS;
using FistVR;
using FistVR.Ugc;
using HarmonyLib;
using MagazinePatcher;
using Microsoft.CodeAnalysis;
using OtherLoader;
using Stratum;
using Stratum.Extensions;
using TNHFramework.ObjectTemplates;
using TNHFramework.Patches;
using TNHFramework.Utilities;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Valve.Newtonsoft.Json;
using Valve.Newtonsoft.Json.Converters;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[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.120.3.0")]
[assembly: AssemblyVersion("0.120.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

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

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

		public CustomCharacter character;

		public EquipmentGroup group;

		public bool dontDrop;

		public bool shouldDropOnCleanup;

		private void OnDestroy()
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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<EquipmentGroup> spawnedEquipmentGroups = group.GetSpawnedEquipmentGroups();
			string text = null;
			VaultFile val = null;
			int num = 0;
			string text2 = default(string);
			foreach (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)
						{
							TNHFrameworkLogger.Log("Spawning nothing since group was compatible magazines, and could not find a compatible magazine for player", TNHFrameworkLogger.LogType.TNH);
						}
						else
						{
							text = ammoContainerForEquipped.ItemID;
						}
					}
					else if (item.UsesVaultFiles())
					{
						val = item.GetRandomVaultFile();
					}
					else
					{
						text = item.GetRandomObject();
					}
					if (Utility.IsNullOrWhiteSpace(text) && val == null)
					{
						continue;
					}
					if (val != null || LoadedTemplateManager.LoadedVaultFiles.ContainsKey(text))
					{
						if (val == null)
						{
							val = LoadedTemplateManager.LoadedVaultFiles[text];
						}
						TNHFrameworkLogger.Log("Spawning vault file " + (text ?? val.FileName), TNHFrameworkLogger.LogType.TNH);
						GameObject val2 = new GameObject("SosigDropMarker");
						val2.transform.position = ((Component)this).transform.position + Vector3.up * 0.1f * (float)(num + 1);
						val2.transform.rotation = Quaternion.identity;
						val2.transform.localScale = ((Component)this).transform.localScale;
						ReturnObjectListDelegate val3 = (ReturnObjectListDelegate)delegate(List<FVRPhysicalObject> objs)
						{
							TNHFrameworkUtils.TrackVaultObjects(M, objs);
						};
						VaultSystem.SpawnVaultFile(val, val2.transform, true, false, false, ref text2, Vector3.zero, val3, false, -1);
						M.AddObjectToTrackedList(val2);
					}
					else if (LoadedTemplateManager.LoadedLegacyVaultFiles.ContainsKey(text) && LoadedTemplateManager.LoadedLegacyVaultFiles[text] != null)
					{
						TNHFrameworkLogger.Log("Spawning legacy vault file " + text, TNHFrameworkLogger.LogType.TNH);
						AnvilManager.Run(TNHFrameworkUtils.SpawnLegacyVaultFile(LoadedTemplateManager.LoadedLegacyVaultFiles[text], ((Component)this).transform.position + Vector3.up * 0.1f * (float)(num + 1), Quaternion.identity, M, addForce: true));
					}
					else if ((Object)(object)IM.OD[text] != (Object)null)
					{
						TNHFrameworkLogger.Log("Spawning item " + text, TNHFrameworkLogger.LogType.TNH);
						AnvilManager.Run(TNHFrameworkUtils.SpawnItemRoutine(M, ((Component)this).transform.position + Vector3.up * 0.1f * (float)(num + 1), Quaternion.identity, IM.OD[text], addForce: true));
					}
					num++;
					if (TNHFramework.SosigItemDropVibrate.Value)
					{
						for (int num2 = 0; num2 < 2; num2++)
						{
							FVRViveHand obj = GM.CurrentMovementManager.Hands[num2];
							obj.Buzz(obj.Buzzer.Buzz_GunShot);
						}
					}
				}
			}
		}

		private void OnApplicationQuit()
		{
			dontDrop = true;
		}
	}
	public class DebugPatches
	{
		[HarmonyPatch(typeof(TNH_Manager), "Start")]
		[HarmonyPrefix]
		public static void AddPointDebugText(TNH_Manager __instance)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0055: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00c1: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0150: 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 obj = val.AddComponent<Canvas>();
				RectTransform component = ((Component)obj).GetComponent<RectTransform>();
				obj.renderMode = (RenderMode)2;
				component.sizeDelta = new Vector2(1f, 1f);
				GameObject val2 = new GameObject("Text");
				val2.transform.SetParent(val.transform);
				val2.transform.rotation = val.transform.rotation;
				val2.transform.localPosition = Vector3.zero;
				val2.AddComponent<CanvasRenderer>();
				Text obj2 = val2.AddComponent<Text>();
				Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
				obj2.text = "Hold " + __instance.HoldPoints.IndexOf(holdPoint);
				obj2.alignment = (TextAnchor)4;
				obj2.fontSize = 32;
				val2.transform.localScale = new Vector3(0.0015f, 0.0015f, 0.0015f);
				obj2.font = font;
				obj2.horizontalOverflow = (HorizontalWrapMode)1;
			}
		}
	}
	public class SosigLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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 successfully : " + 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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
			{
				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<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;
				}
				TNH_CharacterDef character = customCharacter.GetCharacter(val2);
				foreach (IFileHandle file2 in ExtIDirectoryHandle.GetFiles(val))
				{
					for (int i = 0; i < customCharacter.EquipmentPools.Count; i++)
					{
						EquipmentPool equipmentPool = customCharacter.EquipmentPools[i];
						if (((IHandle)file2).Path.Split(new char[1] { '/' }).Last() == equipmentPool.IconName)
						{
							equipmentPool.GetPoolEntry(character.UgcId, i, "EquipmentPool").TableDef.Icon = TNHFrameworkUtils.LoadSprite(file2);
						}
					}
				}
				LoadedTemplateManager.AddCharacterTemplate(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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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 successfully : " + 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 IEnumerator InitializeTNHMenuAsync(string path, Text progressText, Text itemsText, TNH_LevelLoader hotdog, TNH_CharacterDatabase CharDatabase, TNH_UIManager instance, bool outputFiles)
		{
			if (hotdog != null)
			{
				((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 num;
			do
			{
				yield return null;
				num = AsyncLoadMonitor.GetProgress();
				if (isOtherLoaderLoaded)
				{
					num = Mathf.Min(num, GetOtherLoaderProgress());
					itemsText.text = GetLoadingItems();
				}
				progressText.text = $"LOADING ITEMS : {num * 100f:0.0}%";
			}
			while (num <= 0f);
			bool flag;
			try
			{
				PokeMagPatcher();
				flag = true;
				TNHFrameworkLogger.LogWarning("MagazinePatcher is detected.");
			}
			catch
			{
				flag = false;
				TNHFrameworkLogger.LogWarning("MagazinePatcher not found.");
			}
			if (flag)
			{
				float num2;
				do
				{
					yield return null;
					num2 = PokeMagPatcher();
					itemsText.text = GetMagPatcherCacheLog();
					progressText.text = $"CACHING ITEMS : {num2 * 100f:0.0}%";
				}
				while (num2 <= 0f);
			}
			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);
			}
			if (TNHFramework.FixModAttachmentTags.Value)
			{
				TNHFrameworkUtils.FixModAttachmentTags();
			}
			LoadTNHTemplates(UgcManager.GetAllItems<TNH_CharacterDef>().ToList());
			if (outputFiles)
			{
				CreateTNHFiles(path);
			}
			TNHInitialized = true;
			UIManagerPatches.RefreshTNHUI(instance);
			itemsText.text = "";
			progressText.text = "";
			if (hotdog != null)
			{
				((Component)hotdog).gameObject.SetActive(true);
			}
		}

		public static void PokeOtherloader()
		{
			LoaderStatus.GetLoaderProgress();
			_ = LoaderStatus.LoadingItems;
		}

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

		public static string GetLoadingItems()
		{
			//IL_003a: 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 float PokeMagPatcher()
		{
			return PatcherStatus.PatcherProgress;
		}

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

		public static void InternalMagPatcher()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Invalid comparison between Unknown and I4
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Invalid comparison between Unknown and I4
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Invalid comparison between Unknown and I4
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: 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_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Invalid comparison between Unknown and I4
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Invalid comparison between Unknown and I4
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: 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 ((!IM.CompatMags.ContainsKey(magazineType) || !IM.CompatMags[magazineType].Any()) && TNHFramework.MagazineDictionary.ContainsKey(magazineType) && (int)magazineType != 0)
				{
					TNHFrameworkLogger.Log($"Giving IM.CompatMags new magazines of type {magazineType}", TNHFrameworkLogger.LogType.General);
					IM.CompatMags.Add(magazineType, TNHFramework.MagazineDictionary[magazineType]);
				}
				if ((item2.CompatibleSingleRounds == null || !item2.CompatibleSingleRounds.Any()) && 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.Any()) && 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.Any()) && 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.Any()) || (int)item2.TagFirearmAction != 3) && !(item2.ItemID == "GrappleGun"))
				{
					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 (item2.ItemID == "GrappleGun")
					{
						num = 2;
					}
				}
				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_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			if ((int)roundType == 0 && (int)magazineType == 0 && magazineCapacity == 0)
			{
				return (int)clipType > 0;
			}
			return true;
		}

		public static void LoadTNHTemplates(List<TNH_CharacterDef> characters)
		{
			TNHFrameworkLogger.Log("Performing TNH Initialization", TNHFrameworkLogger.LogType.General);
			TNHFrameworkLogger.Log("Adding default sosigs to template dictionary", TNHFrameworkLogger.LogType.General);
			LoadDefaultSosigs();
			TNHFrameworkLogger.Log("Adding Steam Workshop sosigs to template dictionary", TNHFrameworkLogger.LogType.General);
			LoadWorkshopSosigs(characters);
			TNHFrameworkLogger.Log("Adding default characters to template dictionary", TNHFrameworkLogger.LogType.General);
			LoadDefaultCharacters(characters);
			LoadedTemplateManager.DefaultIconSprites = GetAllIcons(LoadedTemplateManager.DefaultCharacters);
			TNHFrameworkLogger.Log("Delayed Init of default characters", TNHFrameworkLogger.LogType.General);
			InitCharacters(LoadedTemplateManager.DefaultCharacters);
			TNHFrameworkLogger.Log("Delayed Init of custom characters", TNHFrameworkLogger.LogType.General);
			InitCharacters(LoadedTemplateManager.CustomCharacters);
			TNHFrameworkLogger.Log("Delayed Init of custom sosigs", TNHFrameworkLogger.LogType.General);
			InitSosigs(LoadedTemplateManager.CustomSosigs);
		}

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

		private static void LoadWorkshopSosigs(List<TNH_CharacterDef> characters)
		{
			foreach (TNH_CharacterDef character in characters)
			{
				List<TNH_Progression> list = new List<TNH_Progression>();
				if (character.Progressions != null)
				{
					list.AddRange(character.Progressions);
				}
				if (character.Progressions_Endless != null)
				{
					list.AddRange(character.Progressions_Endless);
				}
				HashSet<SosigEnemyTemplate> hashSet = new HashSet<SosigEnemyTemplate>();
				foreach (TNH_Progression item in list)
				{
					if (item.Levels == null)
					{
						continue;
					}
					foreach (Level level in item.Levels)
					{
						TNH_TakeChallenge takeChallenge = level.TakeChallenge;
						if ((Object)(object)((takeChallenge != null) ? takeChallenge.OverrideGID : null) != (Object)null)
						{
							hashSet.Add(level.TakeChallenge.OverrideGID);
						}
						TNH_TakeChallenge supplyChallenge = level.SupplyChallenge;
						if ((Object)(object)((supplyChallenge != null) ? supplyChallenge.OverrideGID : null) != (Object)null)
						{
							hashSet.Add(level.SupplyChallenge.OverrideGID);
						}
						if (level.HoldChallenge?.Phases != null)
						{
							foreach (Phase phase in level.HoldChallenge.Phases)
							{
								if ((Object)(object)phase.OverrideEType != (Object)null)
								{
									hashSet.Add(phase.OverrideEType);
								}
								if ((Object)(object)phase.OverrideLType != (Object)null)
								{
									hashSet.Add(phase.OverrideLType);
								}
							}
						}
						if (level.PatrolChallenge?.Patrols == null)
						{
							continue;
						}
						foreach (Patrol patrol in level.PatrolChallenge.Patrols)
						{
							if ((Object)(object)patrol.OverrideEType != (Object)null)
							{
								hashSet.Add(patrol.OverrideEType);
							}
							if ((Object)(object)patrol.OverrideLType != (Object)null)
							{
								hashSet.Add(patrol.OverrideLType);
							}
						}
					}
				}
				foreach (SosigEnemyTemplate item2 in hashSet)
				{
					LoadedTemplateManager.AddSosigTemplate(item2, workshop: true);
				}
			}
		}

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

		public unsafe static Dictionary<string, Sprite> GetAllIcons(List<CustomCharacter> characters)
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Sprite> dictionary = new Dictionary<string, Sprite>();
			foreach (CustomCharacter character in characters)
			{
				foreach (PoolEntry entry in character.GetCharacter().EquipmentPool.Entries)
				{
					if ((Object)(object)entry.TableDef.Icon != (Object)null && !dictionary.ContainsKey(((Object)entry.TableDef.Icon).name))
					{
						TNHFrameworkLogger.Log("Icon found (" + ((Object)entry.TableDef.Icon).name + ")", TNHFrameworkLogger.LogType.Character);
						dictionary.Add(((Object)entry.TableDef.Icon).name, entry.TableDef.Icon);
					}
				}
			}
			foreach (IconEnumPair item in IM.ObjectTableIcons.IconsByEnum)
			{
				ObjectTableDefIconType iconType = item.IconType;
				if (!dictionary.ContainsKey(((object)(*(ObjectTableDefIconType*)(&iconType))/*cast due to .constrained prefix*/).ToString()))
				{
					iconType = item.IconType;
					TNHFrameworkLogger.Log("Icon found (" + ((object)(*(ObjectTableDefIconType*)(&iconType))/*cast due to .constrained prefix*/).ToString() + ")", TNHFrameworkLogger.LogType.Character);
					iconType = item.IconType;
					dictionary.Add(((object)(*(ObjectTableDefIconType*)(&iconType))/*cast due to .constrained prefix*/).ToString(), item.Icon);
				}
			}
			return dictionary;
		}

		private static void InitCharacters(List<CustomCharacter> characters)
		{
			for (int num = characters.Count - 1; num >= 0; num--)
			{
				CustomCharacter character = characters[num];
				try
				{
					character.DelayedInit();
				}
				catch (Exception ex)
				{
					TNHFrameworkLogger.LogError("Failed to load character: " + character.DisplayName + ". Error Output:\n" + ex.ToString());
					characters.RemoveAt(num);
					CharacterTemplate value = LoadedTemplateManager.LoadedCharacterDict.Single((KeyValuePair<string, CharacterTemplate> o) => o.Value.Custom == character).Value;
					LoadedTemplateManager.LoadedCharacterDict.Remove(value.Def.UgcId);
				}
			}
		}

		private static void InitSosigs(List<SosigTemplate> sosigs)
		{
			for (int i = 0; i < sosigs.Count; i++)
			{
				SosigTemplate sosig = sosigs[i];
				try
				{
					sosig.DelayedInit();
				}
				catch (Exception ex)
				{
					TNHFrameworkLogger.LogError("Failed to load sosig: " + sosig.DisplayName + ". Error Output:\n" + ex.ToString());
					KeyValuePair<string, CharacterTemplate>[] array = LoadedTemplateManager.LoadedCharacterDict.Where((KeyValuePair<string, CharacterTemplate> o) => o.Value.Custom.CharacterUsesSosig(sosig.SosigEnemyID)).ToArray();
					for (int num = 0; num < array.Length; num++)
					{
						KeyValuePair<string, CharacterTemplate> keyValuePair = array[num];
						TNHFrameworkLogger.LogError("Removing character that used removed sosig: " + keyValuePair.Value.Custom.DisplayName);
						LoadedTemplateManager.LoadedCharacterDict.Remove(keyValuePair.Key);
					}
				}
			}
		}

		public static void CreateTNHFiles(string path)
		{
			TNHFrameworkLogger.Log("Creating character creation files", TNHFrameworkLogger.LogType.General);
			CreateSosigTemplateFiles(LoadedTemplateManager.DefaultSosigs, path);
			CreateSosigTemplateFiles(LoadedTemplateManager.CustomSosigs, path);
			CreateCharacterFiles(LoadedTemplateManager.DefaultCharacters, path, isCustom: false);
			CreateCharacterFiles(LoadedTemplateManager.CustomCharacters, path, isCustom: true);
			CreateIconIDFile(path, LoadedTemplateManager.DefaultIconSprites.Keys.ToList());
			CreateObjectIDFile(path);
			CreateSosigIDFile(path);
			CreateJsonVaultFiles(path);
			CreateGeneratedTables(path);
			CreatePopulatedCharacterTemplate(path);
		}

		public static string CleanFilename(string filename)
		{
			return Regex.Replace(filename, "(<|>|:|\"|/|\\\\|\\||\\?|\\*)", "");
		}

		public static void CreateSosigTemplateFiles(List<SosigEnemyTemplate> sosigs, string path)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			try
			{
				TNHFrameworkLogger.Log("Creating default sosig template files", TNHFrameworkLogger.LogType.File);
				path = Path.Combine(path, "DefaultSosigTemplates");
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				foreach (SosigEnemyTemplate sosig in sosigs)
				{
					string path2 = Path.Combine(path, CleanFilename(((object)Unsafe.As<SosigEnemyID, SosigEnemyID>(ref sosig.SosigEnemyID)/*cast due to .constrained prefix*/).ToString() + ".json"));
					if (File.Exists(path2))
					{
						File.Delete(path2);
					}
					using StreamWriter streamWriter = File.CreateText(path2);
					string value = JsonConvert.SerializeObject((object)new SosigTemplate(sosig), (Formatting)1, (JsonConverter[])(object)new JsonConverter[1] { (JsonConverter)new StringEnumConverter() });
					streamWriter.WriteLine(value);
					streamWriter.Close();
				}
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public static void CreateSosigTemplateFiles(List<SosigTemplate> sosigs, string path)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			try
			{
				TNHFrameworkLogger.Log("Creating custom sosig template files", TNHFrameworkLogger.LogType.File);
				path = Path.Combine(path, "CustomSosigTemplates");
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				foreach (SosigTemplate sosig in sosigs)
				{
					string path2 = Path.Combine(path, CleanFilename(sosig.SosigEnemyID + ".json"));
					if (File.Exists(path2))
					{
						File.Delete(path2);
					}
					using StreamWriter streamWriter = File.CreateText(path2);
					string value = JsonConvert.SerializeObject((object)sosig, (Formatting)1, (JsonConverter[])(object)new JsonConverter[1] { (JsonConverter)new StringEnumConverter() });
					streamWriter.WriteLine(value);
					streamWriter.Close();
				}
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public static void CreateCharacterFiles(List<CustomCharacter> characters, string path, bool isCustom)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			try
			{
				TNHFrameworkLogger.Log("Creating " + (isCustom ? "custom" : "default") + " character template files", TNHFrameworkLogger.LogType.File);
				path = Path.Combine(path, isCustom ? "CustomCharacters" : "DefaultCharacters");
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				foreach (CustomCharacter character in characters)
				{
					string path2 = Path.Combine(path, CleanFilename(character.DisplayName + ".json"));
					if (File.Exists(path2))
					{
						File.Delete(path2);
					}
					using StreamWriter streamWriter = File.CreateText(path2);
					string value = JsonConvert.SerializeObject((object)character, (Formatting)1, (JsonConverter[])(object)new JsonConverter[1] { (JsonConverter)new StringEnumConverter() });
					streamWriter.WriteLine(value);
					streamWriter.Close();
				}
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public static void CreateIconIDFile(string path, List<string> icons)
		{
			try
			{
				string path2 = Path.Combine(path, "IconIDs.txt");
				if (File.Exists(path2))
				{
					File.Delete(path2);
				}
				using StreamWriter streamWriter = File.CreateText(path2);
				streamWriter.WriteLine("#Available Icons for equipment pools");
				foreach (string icon in icons)
				{
					streamWriter.WriteLine(icon);
				}
				streamWriter.Close();
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public unsafe static void CreateObjectIDFile(string path)
		{
			try
			{
				string path2 = Path.Combine(path, "ObjectIDs.csv");
				if (File.Exists(path2))
				{
					File.Delete(path2);
				}
				using StreamWriter streamWriter = File.CreateText(path2);
				streamWriter.WriteLine("DisplayName,ObjectID,Mod Content,Category,Era,Set,Country of Origin,Attachment Feature,Firearm Action,Firearm Feed Option,Firing Modes,Firearm Mounts,Attachment Mount,Round Power,Round Type,Size,Melee Handedness,Melee Style,Powerup Type,Thrown Damage Type,Thrown Type");
				foreach (FVRObject value in IM.OD.Values)
				{
					streamWriter.WriteLine(value.DisplayName.Replace(",", ".") + "," + value.ItemID.Replace(",", ".") + "," + value.IsModContent + "," + ((object)Unsafe.As<ObjectCategory, ObjectCategory>(ref value.Category)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagEra, OTagEra>(ref value.TagEra)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagSet, OTagSet>(ref value.TagSet)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagFirearmCountryOfOrigin, OTagFirearmCountryOfOrigin>(ref value.TagFirearmCountryOfOrigin)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagAttachmentFeature, OTagAttachmentFeature>(ref value.TagAttachmentFeature)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagFirearmAction, OTagFirearmAction>(ref value.TagFirearmAction)/*cast due to .constrained prefix*/).ToString() + "," + string.Join("+", value.TagFirearmFeedOption.Select((OTagFirearmFeedOption o) => ((object)(*(OTagFirearmFeedOption*)(&o))/*cast due to .constrained prefix*/).ToString()).ToArray()) + "," + string.Join("+", value.TagFirearmFiringModes.Select((OTagFirearmFiringMode o) => ((object)(*(OTagFirearmFiringMode*)(&o))/*cast due to .constrained prefix*/).ToString()).ToArray()) + "," + string.Join("+", value.TagFirearmMounts.Select((OTagFirearmMount o) => ((object)(*(OTagFirearmMount*)(&o))/*cast due to .constrained prefix*/).ToString()).ToArray()) + "," + ((object)Unsafe.As<OTagFirearmMount, OTagFirearmMount>(ref value.TagAttachmentMount)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagFirearmRoundPower, OTagFirearmRoundPower>(ref value.TagFirearmRoundPower)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<FireArmRoundType, FireArmRoundType>(ref value.RoundType)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagFirearmSize, OTagFirearmSize>(ref value.TagFirearmSize)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagMeleeHandedness, OTagMeleeHandedness>(ref value.TagMeleeHandedness)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagMeleeStyle, OTagMeleeStyle>(ref value.TagMeleeStyle)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagPowerupType, OTagPowerupType>(ref value.TagPowerupType)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagThrownDamageType, OTagThrownDamageType>(ref value.TagThrownDamageType)/*cast due to .constrained prefix*/).ToString() + "," + ((object)Unsafe.As<OTagThrownType, OTagThrownType>(ref value.TagThrownType)/*cast due to .constrained prefix*/).ToString());
				}
				streamWriter.Close();
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public static void CreateSosigIDFile(string path)
		{
			try
			{
				string path2 = Path.Combine(path, "SosigIDs.txt");
				if (File.Exists(path2))
				{
					File.Delete(path2);
				}
				using StreamWriter streamWriter = File.CreateText(path2);
				streamWriter.WriteLine("#Available Sosig IDs for spawning");
				List<string> list = LoadedTemplateManager.SosigIDDict.Keys.ToList();
				list.Sort();
				foreach (string item in list)
				{
					streamWriter.WriteLine(item);
				}
				streamWriter.Close();
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public static void CreateJsonVaultFiles(string path)
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			try
			{
				TNHFrameworkLogger.Log("Creating JSON vault files", TNHFrameworkLogger.LogType.File);
				path = Path.Combine(path, "VaultFiles");
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				string[] files = ES2.GetFiles(string.Empty, "*.txt");
				List<SavedGunSerializable> list = new List<SavedGunSerializable>();
				string[] array = files;
				foreach (string text in array)
				{
					try
					{
						if (text.Contains("DONTREMOVETHISPARTOFFILENAMEV02a") && ES2.Exists(text))
						{
							ES2Reader val = ES2Reader.Create(text);
							try
							{
								SavedGun gun = val.Read<SavedGun>("SavedGun");
								list.Add(new SavedGunSerializable(gun));
							}
							finally
							{
								((IDisposable)val)?.Dispose();
							}
						}
					}
					catch
					{
						TNHFrameworkLogger.LogWarning("Vault File " + text + " could not be loaded");
					}
				}
				foreach (SavedGunSerializable item in list)
				{
					string path2 = Path.Combine(path, CleanFilename(item.FileName + ".json"));
					if (File.Exists(path2))
					{
						File.Delete(path2);
					}
					using StreamWriter streamWriter = File.CreateText(path2);
					string value = JsonConvert.SerializeObject((object)item, (Formatting)1, (JsonConverter[])(object)new JsonConverter[1] { (JsonConverter)new StringEnumConverter() });
					streamWriter.WriteLine(value);
					streamWriter.Close();
				}
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}

		public static void CreateGeneratedTables(string path)
		{
			try
			{
				path = Path.Combine(path, "GeneratedEquipmentPools");
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}
				foreach (CustomCharacter item in LoadedTemplateManager.LoadedCharacterDict.Select((KeyValuePair<string, CharacterTemplate> o) => o.Value.Custom))
				{
					using StreamWriter streamWriter = File.CreateText(Path.Combine(path, CleanFilename(item.DisplayName + ".txt")));
					streamWriter.WriteLine("Primary Starting Weapon");
					if (item.PrimaryWeapon != null)
					{
						streamWriter.WriteLine(item.PrimaryWeapon.ToString());
					}
					streamWriter.WriteLine("\n\nSecondary Starting Weapon");
					if (item.SecondaryWeapon != null)
					{
						streamWriter.WriteLine(item.SecondaryWeapon.ToString());
					}
					streamWriter.WriteLine("\n\nTertiary Starting Weapon");
					if (item.TertiaryWeapon != null)
					{
						streamWriter.WriteLine(item.TertiaryWeapon.ToString());
					}
					streamWriter.WriteLine("\n\nPrimary Starting Item");
					if (item.PrimaryItem != null)
					{
						streamWriter.WriteLine(item.PrimaryItem.ToString());
					}
					streamWriter.WriteLine("\n\nSecondary Starting Item");
					if (item.SecondaryItem != null)
					{
						streamWriter.WriteLine(item.SecondaryItem.ToString());
					}
					streamWriter.WriteLine("\n\nTertiary Starting Item");
					if (item.TertiaryItem != null)
					{
						streamWriter.WriteLine(item.TertiaryItem.ToString());
					}
					streamWriter.WriteLine("\n\nStarting Shield");
					if (item.Shield != null)
					{
						streamWriter.WriteLine(item.Shield.ToString());
					}
					foreach (EquipmentPool equipmentPool in item.EquipmentPools)
					{
						streamWriter.WriteLine("\n\n" + equipmentPool.ToString());
					}
					streamWriter.Close();
				}
			}
			catch
			{
			}
		}

		public static void CreatePopulatedCharacterTemplate(string path)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			try
			{
				TNHFrameworkLogger.Log("Creating populated character template file", TNHFrameworkLogger.LogType.File);
				path = Path.Combine(path, "PopulatedCharacterTemplate.json");
				if (!File.Exists(path))
				{
					File.Delete(path);
				}
				using StreamWriter streamWriter = File.CreateText(path);
				string value = JsonConvert.SerializeObject((object)new CustomCharacter(), (Formatting)1, (JsonConverter[])(object)new JsonConverter[1] { (JsonConverter)new StringEnumConverter() });
				streamWriter.WriteLine(value);
				streamWriter.Close();
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError(ex.ToString());
			}
		}
	}
	public class CharacterTemplate(TNH_CharacterDef def, CustomCharacter custom)
	{
		public TNH_CharacterDef Def = def;

		public CustomCharacter Custom = custom;
	}
	public static class LoadedTemplateManager
	{
		public static CustomCharacter CurrentCharacter;

		public static Level CurrentLevel;

		public static Dictionary<string, CharacterTemplate> LoadedCharacterDict = new Dictionary<string, CharacterTemplate>();

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

		public static Dictionary<PoolEntry, EquipmentPool> EquipmentPoolDictionary = new Dictionary<PoolEntry, EquipmentPool>();

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

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

		public static List<CustomCharacter> CustomCharacters = new List<CustomCharacter>();

		public static List<CustomCharacter> DefaultCharacters = new List<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 Dictionary<string, Sprite> DefaultIconSprites = new Dictionary<string, Sprite>();

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

		public static void AddSosigTemplate(SosigEnemyTemplate realTemplate, bool workshop)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected I4, but got Unknown
			SosigTemplate sosigTemplate = new SosigTemplate(realTemplate);
			if (DefaultSosigs.Contains(realTemplate) || LoadedSosigsDict.ContainsKey(realTemplate))
			{
				TNHFrameworkLogger.LogError("Loaded sosig already added : " + realTemplate.UgcId);
				return;
			}
			if (workshop || (int)realTemplate.SosigEnemyID == -1)
			{
				if (SosigIDDict.ContainsKey(realTemplate.UgcId))
				{
					TNHFrameworkLogger.LogError("Loaded sosig had same SosigEnemyID as another sosig -- SosigEnemyID : " + realTemplate.UgcId);
					return;
				}
				SosigIDDict.Add(realTemplate.UgcId, NewSosigID);
				NewSosigID++;
				TNHFrameworkLogger.Log("Sosig added successfully : " + realTemplate.UgcId, TNHFrameworkLogger.LogType.Character);
			}
			else
			{
				if (SosigIDDict.ContainsKey(sosigTemplate.SosigEnemyID))
				{
					TNHFrameworkLogger.LogError("Loaded sosig had same SosigEnemyID as another sosig -- SosigEnemyID : " + sosigTemplate.SosigEnemyID);
					return;
				}
				SosigIDDict.Add(sosigTemplate.SosigEnemyID, (int)realTemplate.SosigEnemyID);
				TNHFrameworkLogger.Log("Sosig added successfully : " + sosigTemplate.DisplayName, TNHFrameworkLogger.LogType.Character);
			}
			DefaultSosigs.Add(realTemplate);
			LoadedSosigsDict.Add(realTemplate, sosigTemplate);
		}

		public static void AddCharacterTemplate(CustomCharacter template, Sprite thumbnail)
		{
			template.isCustom = true;
			template.TableID = "TNHF_" + template.TableID;
			TNH_CharacterDef character = template.GetCharacter(thumbnail);
			if (LoadedCharacterDict.ContainsKey(character.UgcId))
			{
				TNHFrameworkLogger.Log("Character already exists (" + character.UgcId + " [" + template.TableID + "]) : " + template.DisplayName, TNHFrameworkLogger.LogType.General);
				return;
			}
			CustomCharacters.Add(template);
			LoadedCharacterDict.Add(character.UgcId, new CharacterTemplate(character, template));
			for (int i = 0; i < template.EquipmentPools.Count; i++)
			{
				EquipmentPoolDictionary.Add(template.EquipmentPools[i].GetPoolEntry(character.UgcId, i, "EquipmentPool"), template.EquipmentPools[i]);
			}
			TNHFrameworkLogger.Log("Character added successfully (" + character.UgcId + " [" + template.TableID + "]) : " + template.DisplayName, TNHFrameworkLogger.LogType.General);
		}

		public static void AddCharacterTemplate(TNH_CharacterDef charDef)
		{
			if (LoadedCharacterDict.ContainsKey(charDef.UgcId))
			{
				TNHFrameworkLogger.Log("Character already exists (" + charDef.UgcId + " [" + charDef.TableID + "]) : " + charDef.DisplayName, TNHFrameworkLogger.LogType.General);
				return;
			}
			CustomCharacter customCharacter = new CustomCharacter(charDef);
			DefaultCharacters.Add(customCharacter);
			LoadedCharacterDict.Add(charDef.UgcId, new CharacterTemplate(charDef, customCharacter));
			for (int i = 0; i < customCharacter.EquipmentPools.Count; i++)
			{
				PoolEntry poolEntry = customCharacter.EquipmentPools[i].GetPoolEntry(charDef.UgcId, i, "EquipmentPool");
				if (!EquipmentPoolDictionary.ContainsKey(poolEntry))
				{
					EquipmentPoolDictionary.Add(poolEntry, customCharacter.EquipmentPools[i]);
				}
			}
			TNHFrameworkLogger.Log("Character added successfully (" + charDef.UgcId + " [" + charDef.TableID + "]) : " + charDef.DisplayName, TNHFrameworkLogger.LogType.General);
		}

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

		public static void AddVaultFile(SavedGunSerializable template)
		{
			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;

		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;

		private FVRFireArmMagazine detectedMag;

		private Speedloader detectedSpeedLoader;

		private FVRObject purchaseMag;

		private FVRObject upgradeMag;

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

		private readonly MethodInfo miUpdateIconDisplay = typeof(TNH_ObjectConstructorIcon).GetMethod("UpdateIconDisplay", BindingFlags.Instance | BindingFlags.NonPublic);

		public void Awake()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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.CurrentCharacter.GetMagazineBlacklist();
			InitPanel();
			UpdateIcons();
			original.M.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

		private void OnDestroy()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: 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_01c8: Expected O, but got Unknown
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			((Component)((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)")).gameObject.GetComponent<Text>().text = "-- Mag Dupe / Upgrade / Buy --";
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Capacity").localPosition = new Vector3(0f, -30f, 0f);
			Transform val3 = val2.Find("Icon_0");
			val3.localPosition = new Vector3(-270f, -200f, 0f);
			Transform val4 = val2.Find("Icon_1");
			val4.localPosition = new Vector3(0f, -200f, 0f);
			Transform transform = Object.Instantiate<GameObject>(((Component)val4).gameObject, val2).transform;
			transform.localPosition = new Vector3(275f, -200f, 0f);
			Transform obj = ((Component)original).transform.Find("PointableButton_0");
			obj.position = val3.position;
			Transform val5 = ((Component)original).transform.Find("PointableButton_1");
			val5.position = val4.position;
			Transform transform2 = Object.Instantiate<GameObject>(((Component)val5).gameObject, val5.parent).transform;
			transform2.position = transform.position;
			((Component)val).gameObject.GetComponent<Image>().sprite = background;
			DupeIcon = ((Component)val3).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			UpgradeIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			PurchaseIcon = ((Component)transform).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component = ((Component)obj).gameObject.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(new UnityAction(DupeMagButton));
			Button component2 = ((Component)val5).gameObject.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			((UnityEvent)component2.onClick).AddListener(new UnityAction(UpgradeMagButton));
			Button component3 = ((Component)transform2).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener(new UnityAction(PurchaseMagButton));
			priceText_0 = AddPriceText(val3, new Vector3(-235f, 155f, 0f));
			priceText_1 = AddPriceText(val4, 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;
			original.CapacityText.text = string.Empty;
		}

		private Text AddPriceText(Transform iconTransform, Vector3 localPosition)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0023: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_0100: 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 obj = val.AddComponent<Canvas>();
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			obj.renderMode = (RenderMode)2;
			component.sizeDelta = new Vector2(1f, 1f);
			GameObject val2 = new GameObject("Text");
			val2.transform.SetParent(val.transform);
			val2.transform.rotation = val.transform.rotation;
			val2.transform.localPosition = Vector3.zero;
			val2.AddComponent<CanvasRenderer>();
			Text obj2 = val2.AddComponent<Text>();
			Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
			obj2.text = "x?";
			obj2.alignment = (TextAnchor)4;
			obj2.fontSize = 30;
			obj2.fontStyle = (FontStyle)1;
			val2.transform.localScale = new Vector3(0.0015f, 0.0015f, 0.0015f);
			obj2.font = font;
			obj2.horizontalOverflow = (HorizontalWrapMode)1;
			return obj2;
		}

		private void DupeMagButton()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_00c1: 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)
			{
				FirearmUtils.SpawnDuplicateMagazine(original.M, detectedMag, original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
			}
			else
			{
				FirearmUtils.SpawnDuplicateSpeedloader(original.M, detectedSpeedLoader, original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
			}
			ClearSelection();
			UpdateIcons();
		}

		private void UpgradeMagButton()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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);
			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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			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);
			Object.Instantiate<GameObject>(((AnvilAsset)purchaseMag).GetGameObject(), original.Spawnpoint_Mag.position, original.Spawnpoint_Mag.rotation);
		}

		private void Update()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0024: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			CustomCharacter currentCharacter = LoadedTemplateManager.CurrentCharacter;
			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>();
				foreach (Collider val2 in componentsInChildren)
				{
					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)
			{
				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, currentCharacter.GlobalObjectBlacklist, magazineBlacklistEntry);
						if (compatibleMagazines.Any())
						{
							purchaseMag = FirearmUtils.GetSmallestCapacityMagazine(compatibleMagazines, currentCharacter.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;
					}
				}
			}
			SetCostBasedOnMag();
		}

		private void SetCostBasedOnMag()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)detectedMag == (Object)null && (Object)(object)detectedSpeedLoader == (Object)null)
			{
				DupeIcon.State = (IconState)2;
				DupeCost = 0;
			}
			else
			{
				DupeIcon.State = (IconState)1;
				DupeCost = 2;
			}
			CustomCharacter currentCharacter = LoadedTemplateManager.CurrentCharacter;
			original.CapacityText.text = string.Empty;
			if ((Object)(object)detectedMag != (Object)null)
			{
				FVRObject nextHighestCapacityMagazine = FirearmUtils.GetNextHighestCapacityMagazine(((FVRPhysicalObject)detectedMag).ObjectWrapper, currentCharacter.GlobalObjectBlacklist);
				if ((Object)(object)nextHighestCapacityMagazine != (Object)null)
				{
					original.CapacityText.text = detectedMag.m_capacity + " -> " + nextHighestCapacityMagazine.MagazineCapacity;
					UpgradeIcon.State = (IconState)1;
					((object)original).GetType().GetField("m_hasUpgradeableMags", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(original, true);
				}
				else
				{
					UpgradeIcon.State = (IconState)2;
					((object)original).GetType().GetField("m_hasUpgradeableMags", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(original, false);
				}
			}
			else
			{
				UpgradeIcon.State = (IconState)2;
				((object)original).GetType().GetField("m_hasUpgradeableMags", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(original, false);
			}
			UpdateTokenDisplay(original.M.GetNumTokens());
		}

		private void UpdateIcons()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			CustomCharacter currentCharacter = LoadedTemplateManager.CurrentCharacter;
			DupeIcon.State = (IconState)2;
			UpgradeIcon.State = (IconState)2;
			PurchaseIcon.State = (IconState)2;
			int numTokens = original.M.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, currentCharacter.GlobalObjectBlacklist);
				if ((Object)(object)upgradeMag != (Object)null)
				{
					UpgradeIcon.State = (IconState)1;
					if (numTokens >= UpgradeCost)
					{
						numTokensSelected = UpgradeCost;
					}
				}
			}
			miUpdateIconDisplay.Invoke(DupeIcon, new object[0]);
			miUpdateIconDisplay.Invoke(UpgradeIcon, new object[0]);
			miUpdateIconDisplay.Invoke(PurchaseIcon, new object[0]);
			UpdateTokenDisplay(numTokens);
		}

		private void UpdateTokenDisplay(int numTokens)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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;

		public static Sprite background;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		private FVRPhysicalObject selectedObject;

		private FVRFireArm detectedFirearm;

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

		private readonly MethodInfo miUpdateIconDisplay = typeof(TNH_ObjectConstructorIcon).GetMethod("UpdateIconDisplay", BindingFlags.Instance | BindingFlags.NonPublic);

		public void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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();
			original.M.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

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

		private void InitPanel()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			((Component)((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)")).gameObject.GetComponent<Text>().text = "-- Ammo Purchaser --";
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform obj = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val2 = obj.Find("Icon_0");
			val2.localPosition = new Vector3(0f, -290f, 0f);
			Object.Destroy((Object)(object)((Component)obj.Find("Icon_1")).gameObject);
			Transform obj2 = ((Component)original).transform.Find("PointableButton_0");
			obj2.position = val2.position;
			Object.Destroy((Object)(object)((Component)((Component)original).transform.Find("PointableButton_1")).gameObject);
			((Component)val).gameObject.GetComponent<Image>().sprite = background;
			PurchaseIcon = ((Component)val2).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component = ((Component)obj2).gameObject.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(new UnityAction(PurchaseAmmoButton));
			original.CapacityText.text = string.Empty;
		}

		public void PurchaseAmmoButton()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)detectedFirearm == (Object)null || original.M.GetNumTokens() < PanelCost)
			{
				SM.PlayCoreSound((FVRPooledAudioType)20, original.AudEvent_Fail, ((Component)this).transform.position);
				return;
			}
			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);
			CustomCharacter currentCharacter = LoadedTemplateManager.CurrentCharacter;
			MagazineBlacklistEntry magazineBlacklistEntry = null;
			if (currentCharacter.GetMagazineBlacklist().ContainsKey(((FVRPhysicalObject)detectedFirearm).ObjectWrapper.ItemID))
			{
				magazineBlacklistEntry = currentCharacter.GetMagazineBlacklist()[((FVRPhysicalObject)detectedFirearm).ObjectWrapper.ItemID];
			}
			FVRObject random = FirearmUtils.GetCompatibleRounds(((FVRPhysicalObject)detectedFirearm).ObjectWrapper, currentCharacter.ValidAmmoEras, currentCharacter.ValidAmmoSets, currentCharacter.GlobalAmmoBlacklist, currentCharacter.GlobalObjectBlacklist, magazineBlacklistEntry).GetRandom();
			if ((Object)(object)random == (Object)null)
			{
				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);
			AnvilManager.Run(SpawnRounds(original.M, random, roundsToSpawn));
			ClearSelection();
			UpdateIcons();
		}

		public IEnumerator SpawnRounds(TNH_Manager M, FVRObject bullet, int count)
		{
			//IL_0014: 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_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected I4, but got Unknown
			return (int)roundPower switch
			{
				0 => 10, 
				1 => 30, 
				2 => 30, 
				3 => 18, 
				4 => 20, 
				5 => 16, 
				6 => 6, 
				7 => 3, 
				8 => 16, 
				9 => 10, 
				_ => 10, 
			};
		}

		private void Update()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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)
			//IL_00ac: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			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>();
				foreach (Collider val2 in componentsInChildren)
				{
					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_0007: 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)
			PurchaseIcon.State = (IconState)2;
			int numTokens = original.M.GetNumTokens();
			numTokensSelected = 0;
			if ((Object)(object)detectedFirearm != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
				if (numTokens >= PanelCost)
				{
					numTokensSelected = PanelCost;
				}
			}
			miUpdateIconDisplay.Invoke(PurchaseIcon, new object[0]);
			UpdateTokenDisplay(numTokens);
		}

		private void UpdateTokenDisplay(int numTokens)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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;

		public static Sprite background;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		private FVRPhysicalObject selectedObject;

		public Handgun detectedHandgun;

		public ClosedBoltWeapon detectedClosedBolt;

		public OpenBoltReceiver detectedOpenBolt;

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

		private readonly MethodInfo miUpdateIconDisplay = typeof(TNH_ObjectConstructorIcon).GetMethod("UpdateIconDisplay", BindingFlags.Instance | BindingFlags.NonPublic);

		public void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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();
			original.M.TokenCountChangeEvent += new TokenCountChange(UpdateTokenDisplay);
		}

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

		private void InitPanel()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			((Component)((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/AmmoReloaderTitle (3)")).gameObject.GetComponent<Text>().text = "-- Full Auto Upgrader --";
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform obj = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val2 = obj.Find("Icon_0");
			val2.localPosition = new Vector3(0f, -290f, 0f);
			Object.Destroy((Object)(object)((Component)obj.Find("Icon_1")).gameObject);
			Transform obj2 = ((Component)original).transform.Find("PointableButton_0");
			obj2.position = val2.position;
			Object.Destroy((Object)(object)((Component)((Component)original).transform.Find("PointableButton_1")).gameObject);
			((Component)val).gameObject.GetComponent<Image>().sprite = background;
			PurchaseIcon = ((Component)val2).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component = ((Component)obj2).gameObject.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(new UnityAction(AddFullAutoButton));
			original.CapacityText.text = string.Empty;
		}

		public void AddFullAutoButton()
		{
			//IL_0074: 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)
			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)
			{
				AddFullAutoToHandgun(detectedHandgun);
				ClearSelection();
			}
			else if ((Object)(object)detectedClosedBolt != (Object)null)
			{
				AddFullAutoToClosedBolt(detectedClosedBolt);
				ClearSelection();
			}
			else if ((Object)(object)detectedOpenBolt != (Object)null)
			{
				AddFullAutoToOpenBolt(detectedOpenBolt);
				ClearSelection();
			}
		}

		private void AddFullAutoToHandgun(Handgun gun)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			FireSelectorMode val = new FireSelectorMode
			{
				SelectorPosition = 0f,
				ModeType = (FireSelectorModeType)2
			};
			if (gun.FireSelectorModes != null)
			{
				FireSelectorMode[] fireSelectorModes = gun.FireSelectorModes;
				for (int i = 0; i < fireSelectorModes.Length; i++)
				{
					Debug.Log((object)fireSelectorModes[i].ModeType);
				}
			}
			if (gun.FireSelectorModes == null || gun.FireSelectorModes.Length == 0)
			{
				FireSelectorMode val2 = new FireSelectorMode
				{
					SelectorPosition = 0f,
					ModeType = (FireSelectorModeType)1
				};
				gun.FireSelectorModes = (FireSelectorMode[])(object)new FireSelectorMode[2] { val2, 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_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing