Decompiled source of TNHFramework v0.1.4

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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OldTweakerDisabler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OldTweakerDisabler")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("86ca37de-2467-4dad-991f-25a8cb18f841")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OldTweakerDisabler;

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

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

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

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

plugins/TNHTweaker/TNHFramework.dll

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

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

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

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

		public bool dontDrop = false;

		public bool shouldDropOnCleanup;

		private void OnDestroy()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			if (dontDrop)
			{
				return;
			}
			TNHFrameworkLogger.Log("Lootable link was destroyed!", TNHFrameworkLogger.LogType.TNH);
			List<global::TNHFramework.ObjectTemplates.EquipmentGroup> spawnedEquipmentGroups = group.GetSpawnedEquipmentGroups();
			int num = 0;
			string text = default(string);
			foreach (global::TNHFramework.ObjectTemplates.EquipmentGroup item in spawnedEquipmentGroups)
			{
				for (int i = 0; i < item.ItemsToSpawn; i++)
				{
					string key;
					if (item.IsCompatibleMagazine)
					{
						FVRObject ammoContainerForEquipped = FirearmUtils.GetAmmoContainerForEquipped(item.MinAmmoCapacity, item.MaxAmmoCapacity);
						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);
							return;
						}
						key = ammoContainerForEquipped.ItemID;
					}
					else
					{
						key = item.GetObjects().GetRandom();
					}
					if (LoadedTemplateManager.LoadedVaultFiles.ContainsKey(key))
					{
						Transform transform = ((Component)this).transform;
						transform.position = ((Component)this).transform.position + Vector3.up * 0.1f * (float)num;
						VaultSystem.SpawnVaultFile(LoadedTemplateManager.LoadedVaultFiles[key], transform, true, false, false, ref text, Vector3.zero, (ReturnObjectListDelegate)null, false);
					}
					else if (LoadedTemplateManager.LoadedLegacyVaultFiles.ContainsKey(key))
					{
						AnvilManager.Run(TNHFrameworkUtils.SpawnFirearm(LoadedTemplateManager.LoadedLegacyVaultFiles[key], ((Component)this).transform.position + Vector3.up * 0.1f * (float)num, ((Component)this).transform.rotation));
					}
					else
					{
						Object.Instantiate<GameObject>(((AnvilAsset)IM.OD[key]).GetGameObject(), ((Component)this).transform.position + Vector3.up * 0.1f * (float)num, ((Component)this).transform.rotation);
					}
					num++;
				}
			}
		}
	}
	public class DebugPatches
	{
		[HarmonyPatch(typeof(TNH_Manager), "Start")]
		[HarmonyPrefix]
		public static bool AddPointDebugText(TNH_Manager __instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			foreach (TNH_HoldPoint holdPoint in __instance.HoldPoints)
			{
				TNHFrameworkLogger.Log("Adding text!", TNHFrameworkLogger.LogType.TNH);
				GameObject val = new GameObject("Canvas");
				val.transform.rotation = Quaternion.LookRotation(Vector3.right);
				val.transform.position = holdPoint.SpawnPoint_SystemNode.position + Vector3.up * 0.2f;
				Canvas val2 = val.AddComponent<Canvas>();
				RectTransform component = ((Component)val2).GetComponent<RectTransform>();
				val2.renderMode = (RenderMode)2;
				component.sizeDelta = new Vector2(1f, 1f);
				GameObject val3 = new GameObject("Text");
				val3.transform.SetParent(val.transform);
				val3.transform.rotation = val.transform.rotation;
				val3.transform.localPosition = Vector3.zero;
				val3.AddComponent<CanvasRenderer>();
				Text val4 = val3.AddComponent<Text>();
				Font font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
				val4.text = "Hold " + __instance.HoldPoints.IndexOf(holdPoint);
				val4.alignment = (TextAnchor)4;
				val4.fontSize = 32;
				val3.transform.localScale = new Vector3(0.0015f, 0.0015f, 0.0015f);
				val4.font = font;
				val4.horizontalOverflow = (HorizontalWrapMode)1;
			}
			return true;
		}
	}
	public class SosigLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			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
			{
				SosigTemplate sosigTemplate = ((Stage)stage).ImmediateReaders.Get<JToken>().Invoke(val).ToObject<SosigTemplate>();
				TNHFrameworkLogger.Log("Sosig loaded successfuly : " + sosigTemplate.DisplayName, TNHFrameworkLogger.LogType.File);
				LoadedTemplateManager.AddSosigTemplate(sosigTemplate);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for sosig file! Caused Error: " + ex.ToString());
			}
		}
	}
	public class CharacterLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			IDirectoryHandle val = (IDirectoryHandle)(object)((handle is IDirectoryHandle) ? handle : null);
			if (val == null)
			{
				throw new ArgumentException("Could not load character! Character should point to a folder holding the character.json and thumb.png");
			}
			try
			{
				global::TNHFramework.ObjectTemplates.V1.CustomCharacter customCharacter = null;
				Sprite val2 = null;
				foreach (IFileHandle file in ExtIDirectoryHandle.GetFiles(val))
				{
					if (((IHandle)file).Path.EndsWith("character.json"))
					{
						string text = ((Stage)stage).ImmediateReaders.Get<string>().Invoke(file);
						JsonSerializerSettings val3 = new JsonSerializerSettings
						{
							NullValueHandling = (NullValueHandling)1
						};
						customCharacter = JsonConvert.DeserializeObject<global::TNHFramework.ObjectTemplates.V1.CustomCharacter>(text, val3);
					}
					else if (((IHandle)file).Path.EndsWith("thumb.png"))
					{
						val2 = TNHFrameworkUtils.LoadSprite(file);
					}
				}
				if (customCharacter == null)
				{
					TNHFrameworkLogger.LogError("Failed to load custom character! No character.json file found");
					return;
				}
				if ((Object)(object)val2 == (Object)null)
				{
					TNHFrameworkLogger.LogError("Failed to load custom character! No thumb.png file found");
					return;
				}
				foreach (IFileHandle file2 in ExtIDirectoryHandle.GetFiles(val))
				{
					foreach (global::TNHFramework.ObjectTemplates.V1.EquipmentPool equipmentPool in customCharacter.EquipmentPools)
					{
						if (((IHandle)file2).Path.Split(new char[1] { '/' }).Last() == equipmentPool.IconName)
						{
							equipmentPool.GetPoolEntry().TableDef.Icon = TNHFrameworkUtils.LoadSprite(file2);
						}
					}
				}
				TNHFrameworkLogger.Log("Character loaded successfuly : " + customCharacter.DisplayName, TNHFrameworkLogger.LogType.File);
				LoadedTemplateManager.AddCharacterTemplate(new global::TNHFramework.ObjectTemplates.CustomCharacter(customCharacter), val2);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for character! Caused Error: " + ex.ToString());
			}
		}
	}
	public class VaultFileLoaderDeli
	{
		public void LoadAsset(SetupStage stage, Mod mod, IHandle handle)
		{
			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
			{
				SavedGunSerializable savedGunSerializable = ((Stage)stage).ImmediateReaders.Get<JToken>().Invoke(val).ToObject<SavedGunSerializable>();
				TNHFrameworkLogger.Log("Vault file loaded successfuly : " + savedGunSerializable.FileName, TNHFrameworkLogger.LogType.File);
				TNHFrameworkLogger.Log("Vault file loaded successfuly : " + savedGunSerializable.FileName, TNHFrameworkLogger.LogType.File);
				LoadedTemplateManager.AddVaultFile(savedGunSerializable);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for vault file! Caused Error: " + ex.ToString());
			}
		}
	}
	public static class TNHMenuInitializer
	{
		public static bool TNHInitialized;

		public static bool MagazineCacheFailed;

		public static List<TNH_CharacterDef> SavedCharacters;

		public static IEnumerator InitializeTNHMenuAsync(string path, Text progressText, Text itemsText, SceneLoader hotdog, List<CharacterCategory> Categories, TNH_CharacterDatabase CharDatabase, TNH_UIManager instance, bool outputFiles)
		{
			((Component)hotdog).gameObject.SetActive(false);
			bool isMagPatcherLoaded = 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!");
			}
			if (Chainloader.PluginInfos.ContainsKey("MagazinePatcher"))
			{
				PokeMagPatcher();
				isMagPatcherLoaded = true;
				TNHFrameworkLogger.LogWarning("Mag patcher is detected.");
			}
			else
			{
				List<FVRObject> gunsToIterate = new List<FVRObject>();
				foreach (KeyValuePair<string, FVRObject> item in IM.OD)
				{
					if ((int)item.Value.Category == 1)
					{
						gunsToIterate.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>());
						}
						TNHFramework.SpeedloaderDictionary[item.Value.RoundType].Add(item.Value);
					}
				}
				foreach (FVRObject firearm in gunsToIterate)
				{
					if ((firearm.CompatibleSingleRounds == null || firearm.CompatibleSingleRounds.Count == 0) && TNHFramework.CartridgeDictionary.ContainsKey(firearm.RoundType))
					{
						TNHFrameworkLogger.Log("Given firearm " + firearm.DisplayName + " new rounds of type " + ((object)(FireArmRoundType)(ref firearm.RoundType)).ToString(), TNHFrameworkLogger.LogType.General);
						firearm.CompatibleSingleRounds = TNHFramework.CartridgeDictionary[firearm.RoundType];
					}
					if ((firearm.CompatibleMagazines == null || firearm.CompatibleMagazines.Count == 0) && TNHFramework.MagazineDictionary.ContainsKey(firearm.MagazineType) && (int)firearm.MagazineType > 0)
					{
						TNHFrameworkLogger.Log("Given firearm " + firearm.DisplayName + " new magazines of type " + ((object)(FireArmMagazineType)(ref firearm.MagazineType)).ToString(), TNHFrameworkLogger.LogType.General);
						firearm.CompatibleMagazines = TNHFramework.MagazineDictionary[firearm.MagazineType];
					}
					if ((firearm.CompatibleClips == null || firearm.CompatibleClips.Count == 0) && TNHFramework.StripperDictionary.ContainsKey(firearm.ClipType) && (int)firearm.ClipType > 0)
					{
						TNHFrameworkLogger.Log("Given firearm " + firearm.DisplayName + " new clips of type " + ((object)(FireArmClipType)(ref firearm.ClipType)).ToString(), TNHFrameworkLogger.LogType.General);
						firearm.CompatibleClips = TNHFramework.StripperDictionary[firearm.ClipType];
					}
					if ((firearm.CompatibleSpeedLoaders != null && firearm.CompatibleSpeedLoaders.Count != 0) || !TNHFramework.SpeedloaderDictionary.ContainsKey(firearm.RoundType) || !firearm.TagFirearmFeedOption.Contains((OTagFirearmFeedOption)1) || (int)firearm.TagFirearmAction == 10)
					{
						continue;
					}
					foreach (FVRObject speedloader in TNHFramework.SpeedloaderDictionary[firearm.RoundType])
					{
						if (speedloader.MagazineCapacity == firearm.MagazineCapacity)
						{
							TNHFrameworkLogger.Log("Given firearm " + firearm.DisplayName + " new speedloader of type " + ((object)(FireArmRoundType)(ref firearm.RoundType)).ToString(), TNHFrameworkLogger.LogType.General);
							firearm.CompatibleSpeedLoaders.Add(speedloader);
						}
					}
				}
			}
			float itemLoadProgress;
			do
			{
				yield return null;
				itemLoadProgress = AsyncLoadMonitor.GetProgress();
				if (isOtherLoaderLoaded)
				{
					itemLoadProgress = Mathf.Min(itemLoadProgress, GetOtherLoaderProgress());
					itemsText.text = GetLoadingItems();
				}
				progressText.text = "LOADING ITEMS : " + itemLoadProgress * 100f + "%";
			}
			while (itemLoadProgress < 1f);
			if (isMagPatcherLoaded)
			{
				float cachingProgress;
				do
				{
					yield return null;
					cachingProgress = PokeMagPatcher();
					itemsText.text = GetMagPatcherCacheLog();
					progressText.text = "CACHING ITEMS : " + cachingProgress * 100f + "%";
				}
				while (cachingProgress < 1f);
			}
			LoadTNHTemplates(CharDatabase);
			SavedCharacters = CharDatabase.Characters;
			if (outputFiles)
			{
				CreateTNHFiles(path);
			}
			RefreshTNHUI(instance, Categories, CharDatabase);
			itemsText.text = "";
			progressText.text = "";
			((Component)hotdog).gameObject.SetActive(true);
			TNHInitialized = true;
		}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		public static int NewSosigID = 30000;

		public static int NewCharacterID = 1000;

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

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

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

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

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

		public static void AddVaultFile(VaultFile template)
		{
			if (LoadedVaultFiles.ContainsKey(template.FileName))
			{
				return;
			}
			bool flag = false;
			string text = "";
			foreach (VaultObject @object in template.Objects)
			{
				foreach (VaultElement element in @object.Elements)
				{
					if (!IM.OD.ContainsKey(element.ObjectID))
					{
						flag = true;
						text = element.ObjectID;
					}
				}
			}
			if (!flag)
			{
				LoadedVaultFiles.Add(template.FileName, template);
				return;
			}
			TNHFrameworkLogger.LogWarning("Failed to load vault file '" + template.FileName + "', culprit was: '" + text + "'");
		}

		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;

		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 FVRFireArmMagazine detectedMag = null;

		private Speedloader detectedSpeedLoader = null;

		private FVRObject purchaseMag = null;

		private FVRObject upgradeMag = null;

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

		private float scanTick = 1f;

		public void Awake()
		{
			original = ((Component)this).gameObject.GetComponent<TNH_MagDuplicator>();
			if ((Object)(object)original == (Object)null)
			{
				TNHFrameworkLogger.LogError("Mag Upgrader failed, original Mag Duplicator was null!");
			}
			((Behaviour)original).enabled = false;
			blacklist = LoadedTemplateManager.LoadedCharactersDict[original.M.C].GetMagazineBlacklist();
			InitPanel();
			UpdateIcons();
		}

		private void InitPanel()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			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 val5 = ((Component)original).transform.Find("PointableButton_0");
			val5.position = val3.position;
			Transform val6 = ((Component)original).transform.Find("PointableButton_1");
			val6.position = val4.position;
			Transform transform2 = Object.Instantiate<GameObject>(((Component)val6).gameObject, val6.parent).transform;
			transform2.position = transform.position;
			Image component = ((Component)val).gameObject.GetComponent<Image>();
			component.sprite = background;
			DupeIcon = ((Component)val3).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			UpgradeIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			PurchaseIcon = ((Component)transform).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component2 = ((Component)val5).gameObject.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				DupeMagButton();
			});
			Button component3 = ((Component)val6).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				UpgradeMagButton();
			});
			Button component4 = ((Component)transform2).gameObject.GetComponent<Button>();
			component4.onClick = new ButtonClickedEvent();
			((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
			{
				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;
		}

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

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

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

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

		private void Update()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			scanTick -= Time.deltaTime;
			if (scanTick <= 0f)
			{
				scanTick = 1f;
				if (Vector3.Distance(((Component)this).transform.position, ((Component)GM.CurrentPlayerBody).transform.position) < 12f)
				{
					Scan();
					UpdateIcons();
				}
			}
		}

		private void Scan()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			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 i = 0; i < num; i++)
			{
				if (!((Object)(object)colBuffer[i].attachedRigidbody != (Object)null))
				{
					continue;
				}
				FVRFireArm component = ((Component)colBuffer[i]).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 = null;
					if (blacklist.ContainsKey(((FVRPhysicalObject)component).ObjectWrapper.ItemID))
					{
						magazineBlacklistEntry = blacklist[((FVRPhysicalObject)component).ObjectWrapper.ItemID];
					}
					List<FVRObject> compatibleMagazines = FirearmUtils.GetCompatibleMagazines(((FVRPhysicalObject)component).ObjectWrapper, -1, -1, smallestIfEmpty: false, magazineBlacklistEntry);
					if (compatibleMagazines.Count > 0)
					{
						purchaseMag = FirearmUtils.GetSmallestCapacityMagazine(compatibleMagazines);
					}
				}
				FVRFireArmMagazine component2 = ((Component)colBuffer[i]).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;
				}
				Speedloader component3 = ((Component)colBuffer[i]).GetComponent<Speedloader>();
				if ((Object)(object)component3 != (Object)null && !((FVRInteractiveObject)component3).IsHeld && (Object)(object)((FVRPhysicalObject)component3).QuickbeltSlot == (Object)null && component3.IsPretendingToBeAMagazine)
				{
					detectedSpeedLoader = component3;
				}
				if ((Object)(object)purchaseMag != (Object)null && ((Object)(object)detectedMag != (Object)null || (Object)(object)detectedSpeedLoader != (Object)null))
				{
					break;
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			DupeIcon.State = (IconState)2;
			UpgradeIcon.State = (IconState)2;
			PurchaseIcon.State = (IconState)2;
			if ((Object)(object)detectedMag != (Object)null || (Object)(object)detectedSpeedLoader != (Object)null)
			{
				DupeIcon.State = (IconState)1;
			}
			if ((Object)(object)purchaseMag != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
			}
			if ((Object)(object)detectedMag != (Object)null)
			{
				upgradeMag = FirearmUtils.GetNextHighestCapacityMagazine(((FVRPhysicalObject)detectedMag).ObjectWrapper);
				if ((Object)(object)upgradeMag != (Object)null)
				{
					UpgradeIcon.State = (IconState)1;
				}
			}
			DupeIcon.UpdateIconDisplay();
			UpgradeIcon.UpdateIconDisplay();
			PurchaseIcon.UpdateIconDisplay();
		}
	}
	public class AmmoPurchasePanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public Dictionary<string, MagazineBlacklistEntry> blacklist;

		public int PanelCost = 1;

		public static Sprite background;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		private FVRFireArm detectedFirearm = null;

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

		private float scanTick = 1f;

		public void Awake()
		{
			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();
		}

		private void InitPanel()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val3 = val2.Find("Icon_0");
			val3.localPosition = new Vector3(0f, -290f, 0f);
			Transform val4 = val2.Find("Icon_1");
			Object.Destroy((Object)(object)((Component)val4).gameObject);
			Transform val5 = ((Component)original).transform.Find("PointableButton_0");
			val5.position = val3.position;
			Transform val6 = ((Component)original).transform.Find("PointableButton_1");
			Object.Destroy((Object)(object)((Component)val6).gameObject);
			Image component = ((Component)val).gameObject.GetComponent<Image>();
			component.sprite = background;
			PurchaseIcon = ((Component)val3).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component2 = ((Component)val5).gameObject.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				PurchaseAmmoButton();
			});
		}

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

		public IEnumerator SpawnRounds(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(gameObject, original.Spawnpoint_Mag.position, count);
		}

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

		private void Update()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			scanTick -= Time.deltaTime;
			if (scanTick <= 0f)
			{
				scanTick = 1f;
				if (Vector3.Distance(((Component)this).transform.position, ((Component)GM.CurrentPlayerBody).transform.position) < 12f)
				{
					Scan();
					UpdateIcons();
				}
			}
		}

		private void Scan()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			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 i = 0; i < num; i++)
			{
				if ((Object)(object)colBuffer[i].attachedRigidbody != (Object)null)
				{
					FVRFireArm component = ((Component)colBuffer[i]).GetComponent<FVRFireArm>();
					if ((Object)(object)component != (Object)null && !((FVRInteractiveObject)component).IsHeld && (Object)(object)((FVRPhysicalObject)component).QuickbeltSlot == (Object)null)
					{
						detectedFirearm = component;
						break;
					}
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			PurchaseIcon.State = (IconState)2;
			if ((Object)(object)detectedFirearm != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
			}
			PurchaseIcon.UpdateIconDisplay();
		}
	}
	public class FullAutoPanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public int PanelCost = 4;

		public static Sprite background;

		private TNH_ObjectConstructorIcon PurchaseIcon;

		public Handgun detectedHandgun = null;

		public ClosedBoltWeapon detectedClosedBolt = null;

		public OpenBoltReceiver detectedOpenBolt = null;

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

		private float scanTick = 1f;

		public void Awake()
		{
			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();
		}

		private void InitPanel()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val3 = val2.Find("Icon_0");
			val3.localPosition = new Vector3(0f, -290f, 0f);
			Transform val4 = val2.Find("Icon_1");
			Object.Destroy((Object)(object)((Component)val4).gameObject);
			Transform val5 = ((Component)original).transform.Find("PointableButton_0");
			val5.position = val3.position;
			Transform val6 = ((Component)original).transform.Find("PointableButton_1");
			Object.Destroy((Object)(object)((Component)val6).gameObject);
			Image component = ((Component)val).gameObject.GetComponent<Image>();
			component.sprite = background;
			PurchaseIcon = ((Component)val3).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			Button component2 = ((Component)val5).gameObject.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				AddFullAutoButton();
			});
		}

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

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

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

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

		private void Update()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			scanTick -= Time.deltaTime;
			if (scanTick <= 0f)
			{
				scanTick = 1f;
				if (Vector3.Distance(((Component)this).transform.position, ((Component)GM.CurrentPlayerBody).transform.position) < 12f)
				{
					Scan();
					UpdateIcons();
				}
			}
		}

		private void Scan()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			detectedHandgun = null;
			detectedClosedBolt = null;
			detectedOpenBolt = null;
			int num = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, LayerMask.op_Implicit(original.ScanningLM), (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				if ((Object)(object)colBuffer[i].attachedRigidbody != (Object)null)
				{
					Handgun component = ((Component)colBuffer[i]).GetComponent<Handgun>();
					if ((Object)(object)component != (Object)null && (component.FireSelectorModes == null || !component.FireSelectorModes.Any((FireSelectorMode o) => (int)o.ModeType == 2)))
					{
						detectedHandgun = component;
						break;
					}
					ClosedBoltWeapon component2 = ((Component)colBuffer[i]).GetComponent<ClosedBoltWeapon>();
					if ((Object)(object)component2 != (Object)null && (component2.FireSelector_Modes == null || !component2.FireSelector_Modes.Any((FireSelectorMode o) => (int)o.ModeType == 3)))
					{
						detectedClosedBolt = component2;
						break;
					}
					OpenBoltReceiver component3 = ((Component)colBuffer[i]).GetComponent<OpenBoltReceiver>();
					if ((Object)(object)component3 != (Object)null && (component3.FireSelector_Modes == null || !component3.FireSelector_Modes.Any((FireSelectorMode o) => (int)o.ModeType == 2)))
					{
						detectedOpenBolt = component3;
						break;
					}
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			PurchaseIcon.State = (IconState)2;
			if ((Object)(object)detectedHandgun != (Object)null || (Object)(object)detectedClosedBolt != (Object)null || (Object)(object)detectedOpenBolt != (Object)null)
			{
				PurchaseIcon.State = (IconState)1;
			}
			PurchaseIcon.UpdateIconDisplay();
		}
	}
	public class FireRatePanel : MonoBehaviour
	{
		public TNH_MagDuplicator original;

		public static Sprite background;

		public static Sprite plusSprite;

		public static Sprite minusSprite;

		private TNH_ObjectConstructorIcon PlusIcon;

		private TNH_ObjectConstructorIcon MinusIcon;

		public Handgun detectedHandgun = null;

		public ClosedBoltWeapon detectedClosedBolt = null;

		public OpenBoltReceiver detectedOpenBolt = null;

		private int PanelCost = 1;

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

		private float scanTick = 1f;

		private float fireRateMultiplier = 1.5f;

		public void Awake()
		{
			original = ((Component)this).gameObject.GetComponent<TNH_MagDuplicator>();
			if ((Object)(object)original == (Object)null)
			{
				TNHFrameworkLogger.LogError("Fire Rate Modifier failed, original Mag Duplicator was null!");
			}
			((Behaviour)original).enabled = false;
			InitPanel();
			UpdateIcons();
		}

		public void InitPanel()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			Transform val = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas/Backing");
			Transform val2 = ((Component)original).transform.Find("_CanvasHolder/_UITest_Canvas");
			Transform val3 = val2.Find("Icon_0");
			val3.localPosition = new Vector3(-165f, -290f, 0f);
			Transform val4 = val2.Find("Icon_1");
			val4.localPosition = new Vector3(165f, -290f, 0f);
			Transform val5 = ((Component)original).transform.Find("PointableButton_0");
			val5.position = val3.position;
			Transform val6 = ((Component)original).transform.Find("PointableButton_1");
			val6.position = val4.position;
			Image component = ((Component)val).gameObject.GetComponent<Image>();
			component.sprite = background;
			MinusIcon = ((Component)val3).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			PlusIcon = ((Component)val4).gameObject.GetComponent<TNH_ObjectConstructorIcon>();
			MinusIcon.Sprite_Accept = minusSprite;
			PlusIcon.Sprite_Accept = plusSprite;
			Button component2 = ((Component)val5).gameObject.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				DecreaseFireRateButton();
			});
			Button component3 = ((Component)val6).gameObject.GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				IncreaseFireRateButton();
			});
		}

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

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

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

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

		private void Update()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			scanTick -= Time.deltaTime;
			if (scanTick <= 0f)
			{
				scanTick = 1f;
				if (Vector3.Distance(((Component)this).transform.position, ((Component)GM.CurrentPlayerBody).transform.position) < 12f)
				{
					Scan();
					UpdateIcons();
				}
			}
		}

		private void Scan()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			detectedHandgun = null;
			detectedClosedBolt = null;
			detectedOpenBolt = null;
			int num = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, LayerMask.op_Implicit(original.ScanningLM), (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				if ((Object)(object)colBuffer[i].attachedRigidbody != (Object)null)
				{
					Handgun component = ((Component)colBuffer[i]).GetComponent<Handgun>();
					if ((Object)(object)component != (Object)null)
					{
						detectedHandgun = component;
						break;
					}
					ClosedBoltWeapon component2 = ((Component)colBuffer[i]).GetComponent<ClosedBoltWeapon>();
					if ((Object)(object)component2 != (Object)null)
					{
						detectedClosedBolt = component2;
						break;
					}
					OpenBoltReceiver component3 = ((Component)colBuffer[i]).GetComponent<OpenBoltReceiver>();
					if ((Object)(object)component3 != (Object)null)
					{
						detectedOpenBolt = component3;
						break;
					}
				}
			}
		}

		private void UpdateIcons()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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)
			PlusIcon.State = (IconState)2;
			MinusIcon.State = (IconState)2;
			if ((Object)(object)detectedHandgun != (Object)null || (Object)(object)detectedClosedBolt != (Object)null || (Object)(object)detectedOpenBolt != (Object)null)
			{
				PlusIcon.State = (IconState)1;
				MinusIcon.State = (IconState)1;
			}
			PlusIcon.UpdateIconDisplay();
			MinusIcon.UpdateIconDisplay();
		}
	}
	public class TNHLoaders
	{
		public Empty LoadSosig(FileSystemInfo handle)
		{
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			FileInfo fileInfo = ExtFileSystemInfo.ConsumeFile(handle);
			try
			{
				SosigTemplate sosigTemplate = null;
				if (fileInfo.Name.EndsWith(".yaml"))
				{
					DeserializerBuilder val = new DeserializerBuilder();
					IDeserializer val2 = val.Build();
					sosigTemplate = val2.Deserialize<SosigTemplate>(File.ReadAllText(fileInfo.FullName));
					TNHFrameworkLogger.Log("Sosig loaded successfuly : " + sosigTemplate.DisplayName, TNHFrameworkLogger.LogType.File);
				}
				else if (fileInfo.Name.EndsWith(".json"))
				{
					JsonSerializerSettings val3 = new JsonSerializerSettings
					{
						NullValueHandling = (NullValueHandling)1
					};
					sosigTemplate = JsonConvert.DeserializeObject<SosigTemplate>(File.ReadAllText(fileInfo.FullName));
					TNHFrameworkLogger.Log("Sosig loaded successfuly : " + sosigTemplate.DisplayName, TNHFrameworkLogger.LogType.File);
					if (TNHFramework.ConvertFilesToYAML.Value)
					{
						using (StreamWriter streamWriter = File.CreateText(fileInfo.FullName.Replace(".json", ".yaml")))
						{
							SerializerBuilder val4 = new SerializerBuilder();
							val4.WithIndentedSequences();
							ISerializer val5 = val4.Build();
							string value = val5.Serialize((object)sosigTemplate);
							streamWriter.WriteLine(value);
							streamWriter.Close();
						}
						File.Delete(fileInfo.FullName);
					}
				}
				LoadedTemplateManager.AddSosigTemplate(sosigTemplate);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for sosig file! Caused Error: " + ex.ToString());
			}
			return default(Empty);
		}

		public Empty LoadChar(FileSystemInfo handle)
		{
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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_0140: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			DirectoryInfo directoryInfo = ExtFileSystemInfo.ConsumeDirectory(handle);
			try
			{
				global::TNHFramework.ObjectTemplates.CustomCharacter customCharacter = null;
				Sprite val = null;
				FileInfo[] files = directoryInfo.GetFiles();
				foreach (FileInfo fileInfo in files)
				{
					if (fileInfo.Name.EndsWith("character.yaml"))
					{
						DeserializerBuilder val2 = new DeserializerBuilder();
						foreach (KeyValuePair<string, Type> serializable in TNHFramework.Serializables)
						{
							((BuilderSkeleton<DeserializerBuilder>)(object)val2).WithTagMapping(TagName.op_Implicit(serializable.Key), serializable.Value);
						}
						IDeserializer val3 = val2.Build();
						customCharacter = val3.Deserialize<global::TNHFramework.ObjectTemplates.CustomCharacter>(File.ReadAllText(fileInfo.FullName));
						TNHFrameworkLogger.Log("Character partially loaded - loaded character file", TNHFrameworkLogger.LogType.File);
					}
					else if (fileInfo.Name.EndsWith("character.json"))
					{
						JsonSerializerSettings val4 = new JsonSerializerSettings
						{
							NullValueHandling = (NullValueHandling)1
						};
						customCharacter = new global::TNHFramework.ObjectTemplates.CustomCharacter(JsonConvert.DeserializeObject<global::TNHFramework.ObjectTemplates.V1.CustomCharacter>(File.ReadAllText(fileInfo.FullName), val4));
						if (TNHFramework.ConvertFilesToYAML.Value)
						{
							using (StreamWriter streamWriter = File.CreateText(fileInfo.FullName.Replace(".json", ".yaml")))
							{
								SerializerBuilder val5 = new SerializerBuilder();
								val5.WithIndentedSequences();
								foreach (KeyValuePair<string, Type> serializable2 in TNHFramework.Serializables)
								{
									((BuilderSkeleton<SerializerBuilder>)(object)val5).WithTagMapping(TagName.op_Implicit(serializable2.Key), serializable2.Value);
								}
								ISerializer val6 = val5.Build();
								string value = val6.Serialize((object)customCharacter);
								streamWriter.WriteLine(value);
								streamWriter.Close();
							}
							File.Delete(fileInfo.FullName);
						}
						TNHFrameworkLogger.Log("Character partially loaded - loaded character file", TNHFrameworkLogger.LogType.File);
					}
					else if (fileInfo.FullName.EndsWith("thumb.png"))
					{
						val = TNHFrameworkUtils.LoadSprite(fileInfo);
						TNHFrameworkLogger.Log("Character partially loaded - loaded character icon", TNHFrameworkLogger.LogType.File);
					}
				}
				if (customCharacter == null)
				{
					TNHFrameworkLogger.LogError("Failed to load custom character! No character.json file found");
					return default(Empty);
				}
				if ((Object)(object)val == (Object)null)
				{
					TNHFrameworkLogger.LogError("Failed to load custom character! No thumb.png file found");
					return default(Empty);
				}
				FileInfo[] files2 = directoryInfo.GetFiles();
				foreach (FileInfo fileInfo2 in files2)
				{
					foreach (global::TNHFramework.ObjectTemplates.EquipmentPool equipmentPool in customCharacter.EquipmentPools)
					{
						if (fileInfo2.FullName.Split(new char[1] { '\\' }).Last() == equipmentPool.IconName)
						{
							equipmentPool.GetPoolEntry().TableDef.Icon = TNHFrameworkUtils.LoadSprite(fileInfo2);
							TNHFrameworkLogger.Log("Character partially loaded - loaded misc icon " + fileInfo2.Name, TNHFrameworkLogger.LogType.File);
						}
					}
				}
				TNHFrameworkLogger.Log("Character loaded successfuly : " + customCharacter.DisplayName, TNHFrameworkLogger.LogType.File);
				LoadedTemplateManager.AddCharacterTemplate(customCharacter, val);
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for character! Caused Error: " + ex.ToString());
			}
			return default(Empty);
		}

		public Empty LoadVaultFile(FileSystemInfo handle)
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			FileInfo fileInfo = ExtFileSystemInfo.ConsumeFile(handle);
			try
			{
				VaultFile val = null;
				if (fileInfo.Name.EndsWith(".yaml"))
				{
					DeserializerBuilder val2 = new DeserializerBuilder();
					IDeserializer val3 = val2.Build();
					val = val3.Deserialize<VaultFile>(File.ReadAllText(fileInfo.FullName));
					TNHFrameworkLogger.Log("Vault file loaded successfuly : " + val.FileName, TNHFrameworkLogger.LogType.File);
				}
				else if (fileInfo.Name.EndsWith(".json"))
				{
					JsonSerializerSettings val4 = new JsonSerializerSettings
					{
						NullValueHandling = (NullValueHandling)1
					};
					val = JsonConvert.DeserializeObject<VaultFile>(File.ReadAllText(fileInfo.FullName));
					TNHFrameworkLogger.Log("Vault file loaded successfuly : " + val.FileName, TNHFrameworkLogger.LogType.File);
					if (TNHFramework.ConvertFilesToYAML.Value)
					{
						using (StreamWriter streamWriter = File.CreateText(fileInfo.FullName.Replace(".json", ".yaml")))
						{
							SerializerBuilder val5 = new SerializerBuilder();
							val5.WithIndentedSequences();
							ISerializer val6 = val5.Build();
							string value = val6.Serialize((object)val);
							streamWriter.WriteLine(value);
							streamWriter.Close();
						}
						File.Delete(fileInfo.FullName);
					}
				}
				if (val != null)
				{
					LoadedTemplateManager.AddVaultFile(val);
				}
			}
			catch (Exception ex)
			{
				TNHFrameworkLogger.LogError("Failed to load setup assets for vault file! Caused Error: " + ex.ToString());
			}
			return default(Empty);
		}
	}
	[BepInPlugin("h3vr.tnhframework", "TNH Framework", "0.0.1")]
	[BepInDependency("stratum", "1.1.0")]
	public class TNHFramework : StratumPlugin
	{
		private static ConfigEntry<bool> printCharacters;

		private static ConfigEntry<bool> logTNH;

		private static ConfigEntry<bool> logFileReads;

		private static ConfigEntry<bool> allowLog;

		public static ConfigEntry<bool> BuildCharacterFiles;

		public static ConfigEntry<bool> ConvertFilesToYAML;

		public static ConfigEntry<bool> UnlimitedTokens;

		public static ConfigEntry<bool> EnableDebugText;

		public static ConfigEntry<bool> EnableScoring;

		public static string InfoPath;

		public static string OutputFilePath;

		public static Dictionary<string, Type> Serializables = new Dictionary<string, Type>();

		public static Dictionary<FireArmRoundType, List<FVRObject>> CartridgeDictionary = new Dictionary<FireArmRoundType, List<FVRObject>>();

		public static Dictionary<FireArmMagazineType, List<FVRObject>> MagazineDictionary = new Dictionary<FireArmMagazineType, List<FVRObject>>();

		public static Dictionary<FireArmClipType, List<FVRObject>> StripperDictionary = new Dictionary<FireArmClipType, List<FVRObject>>();

		public static Dictionary<FireArmRoundType, List<FVRObject>> SpeedloaderDictionary = new Dictionary<FireArmRoundType, List<FVRObject>>();

		public static bool PreventOutfitFunctionality = false;

		public static List<int> SpawnedBossIndexes = new List<int>();

		public static List<int> SupplyPointIFFList = new List<int>();

		public static List<GameObject> SpawnedConstructors = new List<GameObject>();

		public static List<GameObject> SpawnedPanels = new List<GameObject>();

		public static List<PoolEntry> SpawnedPools = new List<PoolEntry>();

		public static List<List<string>> HoldActions = new List<List<string>>();

		public static List<HoldStats> HoldStats = new List<HoldStats>();

		public static int GunsRecycled;

		public static int ShotsFired;

		private void Awake()
		{
			InfoPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (TNHFrameworkLogger.BepLog == null)
			{
				TNHFrameworkLogger.Init();
			}
			TNHFrameworkLogger.Log("Hello World (from TNH Tweaker)", TNHFrameworkLogger.LogType.General);
			SetupOutputDirectory();
			LoadConfigFile();
			LoadPanelSprites();
			Harmony.CreateAndPatchAll(typeof(TNHFramework), (string)null);
			Harmony.CreateAndPatchAll(typeof(TNHPatches), (string)null);
			Harmony.CreateAndPatchAll(typeof(PatrolPatches), (string)null);
			Harmony.CreateAndPatchAll(typeof(HoldPatches), (string)null);
			if (EnableScoring.Value)
			{
				Harmony.CreateAndPatchAll(typeof(HighScorePatches), (string)null);
			}
			if (EnableDebugText.Value)
			{
				Harmony.CreateAndPatchAll(typeof(DebugPatches), (string)null);
			}
		}

		public override void OnSetup(IStageContext<Empty> ctx)
		{
			TNHLoaders tNHLoaders = new TNHLoaders();
			ctx.Loaders.Add("tnhchar", tNHLoaders.LoadChar);
			ctx.Loaders.Add("tnhsosig", tNHLoaders.LoadSosig);
			ctx.Loaders.Add("tnhvaultgun", tNHLoaders.LoadVaultFile);
		}

		public override IEnumerator OnRuntime(IStageContext<IEnumerator> ctx)
		{
			yield break;
		}

		private void LoadPanelSprites()
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
			FileInfo file = ExtDirectoryInfo.GetFile(directoryInfo, "mag_dupe_background.png");
			Sprite background = TNHFrameworkUtils.LoadSprite(file);
			MagazinePanel.background = background;
			file = ExtDirectoryInfo.GetFile(directoryInfo, "ammo_purchase_background.png");
			background = TNHFrameworkUtils.LoadSprite(file);
			AmmoPurchasePanel.background = background;
			file = ExtDirectoryInfo.GetFile(directoryInfo, "full_auto_background.png");
			background = TNHFrameworkUtils.LoadSprite(file);
			FullAutoPanel.background = background;
			file = ExtDirectoryInfo.GetFile(directoryInfo, "fire_rate_background.png");
			background = TNHFrameworkUtils.LoadSprite(file);
			FireRatePanel.background = background;
			file = ExtDirectoryInfo.GetFile(directoryInfo, "minus_icon.png");
			background = TNHFrameworkUtils.LoadSprite(file);
			FireRatePanel.minusSprite = background;
			file = ExtDirectoryInfo.GetFile(directoryInfo, "plus_icon.png");
			background = TNHFrameworkUtils.LoadSprite(file);
			FireRatePanel.plusSprite = background;
		}

		private void LoadConfigFile()
		{
			TNHFrameworkLogger.Log("Getting config file", TNHFrameworkLogger.LogType.File);
			BuildCharacterFiles = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BuildCharacterFiles", false, "If true, files useful for character creation will be generated in TNHTweaker folder");
			ConvertFilesToYAML = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ConvertFilesToYAML", false, "If true, any Stratum-based custom characters will have their JSON files converted to YAML");
			EnableScoring = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableScoring", true, "If true, TNH scores will be uploaded to the TNH Dashboard (https://devyndamonster.github.io/TNHDashboard/index.html)");
			allowLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableLogging", true, "Set to true to enable logging");
			printCharacters = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogCharacterInfo", false, "Decide if should print all character info");
			logTNH = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogTNH", false, "If true, general TNH information will be logged");
			logFileReads = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogFileReads", false, "If true, reading from a file will log the reading process");
			UnlimitedTokens = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableUnlimitedTokens", false, "If true, you will spawn with 999999 tokens for any character in TNH (useful for testing loot pools)");
			EnableDebugText = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugText", false, "If true, some text will appear in TNH maps showing additional info");
			TNHFrameworkLogger.AllowLogging = allowLog.Value;
			TNHFrameworkLogger.LogCharacter = printCharacters.Value;
			TNHFrameworkLogger.LogTNH = logTNH.Value;
			TNHFrameworkLogger.LogFile = logFileReads.Value;
		}

		private void SetupOutputDirectory()
		{
			OutputFilePath = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "CharFiles");
			if (!Directory.Exists(OutputFilePath))
			{
				Directory.CreateDirectory(OutputFilePath);
			}
		}

		[HarmonyPatch(typeof(TNH_ScoreDisplay), "SubmitScoreAndGoToBoard")]
		[HarmonyPrefix]
		public static bool PreventScoring(TNH_ScoreDisplay __instance, int score)
		{
			TNHFrameworkLogger.Log("Preventing vanilla score submition", TNHFrameworkLogger.LogType.TNH);
			GM.Omni.OmniFlags.AddScore(__instance.m_curSequenceID, score);
			__instance.m_hasCurrentScore = true;
			__instance.m_currentScore = score;
			if (EnableScoring.Value)
			{
				((MonoBehaviour)AnvilManager.Instance).StartCoroutine(HighScorePatches.SendScore(score));
			}
			__instance.RedrawHighScoreDisplay(__instance.m_curSequenceID);
			GM.Omni.SaveToFile();
			return false;
		}
	}
	public class TNHTweakerDeli : DeliBehaviour
	{
		public void Awake()
		{
			if (TNHFrameworkLogger.BepLog == null)
			{
				TNHFrameworkLogger.Init();
			}
			((DeliBehaviour)this).Stages.Setup += DeliOnSetup;
		}

		private void DeliOnSetup(SetupStage stage)
		{
			((NestedServiceCollection<Mod, string, ImmediateAssetLoader<SetupStage>>)(object)stage.SetupAssetLoaders)[((DeliBehaviour)this).Source, "sosig"] = new SosigLoaderDeli().LoadAsset;
			((NestedServiceCollection<Mod, string, ImmediateAssetLoader<SetupStage>>)(object)stage.SetupAssetLoaders)[((DeliBehaviour)this).Source, "vault_file"] = new VaultFileLoaderDeli().LoadAsset;
			((NestedServiceCollection<Mod, string, ImmediateAssetLoader<SetupStage>>)(object)stage.SetupAssetLoaders)[((DeliBehaviour)this).Source, "character"] = new CharacterLoaderDeli().LoadAsset;
		}
	}
}
namespace TNHFramework.Utilities
{
	internal static class FirearmUtils
	{
		public static List<FVRObject> GetCompatibleAmmoContainers(FVRObject firearm, int minCapacity = 0, int maxCapacity = 9999, bool smallestIfEmpty = true, MagazineBlacklistEntry blacklist = null)
		{
			firearm = IM.OD[firearm.ItemID];
			if (maxCapacity <= 0)
			{
				maxCapacity = 9999;
			}
			List<FVRObject> list = new List<FVRObject>();
			if (firearm.CompatibleSpeedLoaders != null)
			{
				list.AddRange(firearm.CompatibleSpeedLoaders);
			}
			foreach (FVRObject compatibleMagazine in firearm.CompatibleMagazines)
			{
				if ((blacklist == null || blacklist.IsMagazineAllowed(compatibleMagazine.ItemID)) && compatibleMagazine.MagazineCapacity >= minCapacity && compatibleMagazine.MagazineCapacity <= maxCapacity)
				{
					list.Add(compatibleMagazine);
				}
			}
			foreach (FVRObject compatibleClip in firearm.CompatibleClips)
			{
				if ((blacklist == null || blacklist.IsClipAllowed(compatibleClip.ItemID)) && compatibleClip.MagazineCapacity >= minCapacity && compatibleClip.MagazineCapacity <= maxCapacity)
				{
					list.Add(compatibleClip);
				}
			}
			if (list.Count == 0 && smallestIfEmpty && firearm.CompatibleMagazines != null)
			{
				FVRObject smallestCapacityMagazine = GetSmallestCapacityMagazine(firearm.CompatibleMagazines);
				if (smallestCapacityMagazine != null)
				{
					list.Add(smallestCapacityMagazine);
				}
			}
			return list;
		}

		public static List<FVRObject> GetCompatibleMagazines(FVRObject firearm, int minCapacity = 0, int maxCapacity = 9999, bool smallestIfEmpty = true, MagazineBlacklistEntry blacklist = null)
		{
			firearm = IM.OD[firearm.ItemID];
			if (maxCapacity <= 0)
			{
				maxCapacity = 9999;
			}
			List<FVRObject> list = new List<FVRObject>();
			if (firearm.CompatibleMagazines != null)
			{
				list.AddRange(firearm.CompatibleMagazines);
			}
			for (int num = list.Count - 1; num >= 0; num--)
			{
				if (blacklist != null && !blacklist.IsMagazineAllowed(list[num].ItemID))
				{
					list.RemoveAt(num);
				}
				else if (list[num].MagazineCapacity < minCapacity || list[num].MagazineCapacity > maxCapacity)
				{
					list.RemoveAt(num);
				}
			}
			if (list.Count == 0 && smallestIfEmpty && firearm.CompatibleMagazines != null)
			{
				FVRObject smallestCapacityMagazine = GetSmallestCapacityMagazine(firearm.CompatibleMagazines, blacklist);
				if (smallestCapacityMagazine != null)
				{
					list.Add(smallestCapacityMagazine);
				}
			}
			return list;
		}

		public static List<FVRObject> GetCompatibleClips(FVRObject firearm, int minCapacity = 0, int maxCapacity = 9999, MagazineBlacklistEntry blacklist = null)
		{
			firearm = IM.OD[firearm.ItemID];
			if (maxCapacity <= 0)
			{
				maxCapacity = 9999;
			}
			List<FVRObject> list = new List<FVRObject>();
			if (firearm.CompatibleClips != null)
			{
				list.AddRange(firearm.CompatibleClips);
			}
			for (int num = list.Count - 1; num >= 0; num--)
			{
				if (blacklist != null && !blacklist.IsClipAllowed(list[num].ItemID))
				{
					list.RemoveAt(num);
				}
				else if (list[num].MagazineCapacity < minCapacity || list[num].MagazineCapacity > maxCapacity)
				{
					list.RemoveAt(num);
				}
			}
			return list;
		}

		public static List<FVRObject> GetCompatibleRounds(FVRObject firearm, List<TagEra> eras, List<TagSet> sets, List<string> globalBulletBlacklist = null, MagazineBlacklistEntry blacklist = null)
		{
			return GetCompatibleRounds(firearm, eras.Select((TagEra o) => (OTagEra)o).ToList(), sets.Select((TagSet o) => (OTagSet)o).ToList(), globalBulletBlacklist, blacklist);
		}

		public static List<FVRObject> GetCompatibleRounds(FVRObject firearm, List<OTagEra> eras, List<OTagSet> sets, List<string> globalBulletBlacklist = null, MagazineBlacklistEntry blacklist = null)
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			firearm = IM.OD[firearm.ItemID];
			List<FVRObject> list = new List<FVRObject>();
			if (firearm.CompatibleSingleRounds != null)
			{
				list.AddRange(firearm.CompatibleSingleRounds);
			}
			for (int num = list.Count - 1; num >= 0; num--)
			{
				if (blacklist != null && !blacklist.IsRoundAllowed(list[num].ItemID))
				{
					list.RemoveAt(num);
				}
				else if (globalBulletBlacklist != null && globalBulletBlacklist.Contains(list[num].ItemID))
				{
					list.RemoveAt(num);
				}
				else if (!eras.Contains(list[num].TagEra) || !sets.Contains(list[num].TagSet))
				{
					list.RemoveAt(num);
				}
			}
			foreach (KeyValuePair<FireArmRoundClass, DisplayDataClass> item in AM.STypeDic[firearm.RoundType])
			{
				if (list.Contains(item.Value.ObjectID) && item.Value.Cost > 0)
				{
					list.Remove(item.Value.ObjectID);
				}
			}
			return list;
		}

		public static FVRObject GetSmallestCapacityMagazine(List<FVRObject> magazines, MagazineBlacklistEntry blacklist = null)
		{
			if (magazines == null || magazines.Count == 0)
			{
				return null;
			}
			List<FVRObject> list = new List<FVRObject>();
			foreach (FVRObject magazine in magazines)
			{
				if (blacklist == null || blacklist.IsMagazineAllowed(magazine.ItemID))
				{
					if (list.Count == 0)
					{
						list.Add(magazine);
					}
					else if (magazine.MagazineCapacity < list[0].MagazineCapacity)
					{
						list.Clear();
						list.Add(magazine);
					}
					else if (magazine.MagazineCapacity == list[0].MagazineCapacity)
					{
						list.Add(magazine);
					}
				}
			}
			if (list.Count == 0)
			{
				return null;
			}
			return list.GetRandom();
		}

		public static FVRObject GetSmallestCapacityMagazine(FVRObject firearm, MagazineBlacklistEntry blacklist = null)
		{
			firearm = IM.OD[firearm.ItemID];
			return GetSmallestCapacityMagazine(firearm.CompatibleMagazines, blacklist);
		}

		public static bool FVRObjectHasAmmoObject(FVRObject item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			item = IM.OD[item.ItemID];
			return (item.CompatibleSingleRounds != n