Decompiled source of ReservedFlashlightSlot v2.0.8

ReservedFlashlightSlot.dll

Decompiled 3 months ago
using System;
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.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using ReservedFlashlightSlot.Config;
using ReservedFlashlightSlot.Patches;
using ReservedItemSlotCore;
using ReservedItemSlotCore.Config;
using ReservedItemSlotCore.Data;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ReservedFlashlightSlot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReservedFlashlightSlot")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5b7d6563-4e51-4a69-bcf9-fa1dea6eff75")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ReservedFlashlightSlot
{
	[BepInPlugin("FlipMods.ReservedFlashlightSlot", "ReservedFlashlightSlot", "2.0.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		private static ManualLogSource logger;

		private Harmony _harmony;

		public static ReservedItemSlotData flashlightSlotData;

		public static ReservedItemData flashlightData;

		public static ReservedItemData proFlashlightData;

		public static ReservedItemData laserPointerData;

		public static List<ReservedItemData> additionalItemData = new List<ReservedItemData>();

		private void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			instance = this;
			CreateCustomLogger();
			ConfigSettings.BindConfigSettings();
			CreateReservedItemSlots();
			CreateAdditionalReservedItemSlots();
			_harmony = new Harmony("ReservedFlashlightSlot");
			PatchAll();
			Log("ReservedFlashlightSlot loaded");
		}

		private void CreateReservedItemSlots()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00d0: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			flashlightSlotData = ReservedItemSlotData.CreateReservedItemSlotData("flashlight", ConfigSettings.overrideItemSlotPriority.Value, ConfigSettings.overridePurchasePrice.Value);
			flashlightData = flashlightSlotData.AddItemToReservedItemSlot(new ReservedItemData("Flashlight", (PlayerBone)4, new Vector3(0.2f, 0.25f, 0f), new Vector3(90f, 0f, 0f)));
			proFlashlightData = flashlightSlotData.AddItemToReservedItemSlot(new ReservedItemData("Pro-flashlight", (PlayerBone)4, new Vector3(0.2f, 0.25f, 0f), new Vector3(90f, 0f, 0f)));
			if (ConfigSettings.includeLaserPointer.Value)
			{
				laserPointerData = flashlightSlotData.AddItemToReservedItemSlot(new ReservedItemData("Laser pointer", (PlayerBone)4, new Vector3(0.2f, 0.25f, 0f), new Vector3(90f, 0f, 0f)));
			}
		}

		private void CreateAdditionalReservedItemSlots()
		{
			//IL_003d: 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)
			//IL_0047: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			string[] array = ConfigSettings.ParseAdditionalItems();
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (!flashlightSlotData.ContainsItem(text))
				{
					LogWarning("Adding additional item to reserved item slot. Item: " + text);
					ReservedItemData val = new ReservedItemData(text, (PlayerBone)0, default(Vector3), default(Vector3));
					additionalItemData.Add(val);
					flashlightSlotData.AddItemToReservedItemSlot(val);
				}
			}
		}

		private void PatchAll()
		{
			IEnumerable<Type> enumerable;
			try
			{
				enumerable = Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				enumerable = ex.Types.Where((Type t) => t != null);
			}
			foreach (Type item in enumerable)
			{
				_harmony.PatchAll(item);
			}
		}

		private void CreateCustomLogger()
		{
			try
			{
				logger = Logger.CreateLogSource(string.Format("{0}-{1}", "ReservedFlashlightSlot", "2.0.8"));
			}
			catch
			{
				logger = ((BaseUnityPlugin)this).Logger;
			}
		}

		public static void Log(string message)
		{
			logger.LogInfo((object)message);
		}

		public static void LogError(string message)
		{
			logger.LogError((object)message);
		}

		public static void LogWarning(string message)
		{
			logger.LogWarning((object)message);
		}

		public static bool IsModLoaded(string guid)
		{
			return Chainloader.PluginInfos.ContainsKey(guid);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FlipMods.ReservedFlashlightSlot";

		public const string PLUGIN_NAME = "ReservedFlashlightSlot";

		public const string PLUGIN_VERSION = "2.0.8";
	}
}
namespace ReservedFlashlightSlot.Patches
{
	[HarmonyPatch]
	public static class FlashlightPatcher
	{
		public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;

		public static PlayerControllerB GetPreviousPlayerHeldBy(FlashlightItem flashlightItem)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			return (PlayerControllerB)Traverse.Create((object)flashlightItem).Field("previousPlayerHeldBy").GetValue();
		}

		public static FlashlightItem GetMainFlashlight(PlayerControllerB playerController)
		{
			FlashlightItem currentlySelectedFlashlight = GetCurrentlySelectedFlashlight(playerController);
			if (Object.op_Implicit((Object)(object)currentlySelectedFlashlight))
			{
				return currentlySelectedFlashlight;
			}
			GrabbableObject obj = playerController?.pocketedFlashlight;
			FlashlightItem val = (FlashlightItem)(object)((obj is FlashlightItem) ? obj : null);
			FlashlightItem reservedFlashlight = GetReservedFlashlight(playerController);
			return (Object.op_Implicit((Object)(object)val) && (!Object.op_Implicit((Object)(object)reservedFlashlight) || (((GrabbableObject)val).isBeingUsed && !((GrabbableObject)reservedFlashlight).isBeingUsed))) ? val : reservedFlashlight;
		}

		public static FlashlightItem GetReservedFlashlight(PlayerControllerB playerController)
		{
			ReservedItemSlotData val = default(ReservedItemSlotData);
			ReservedPlayerData value;
			return (FlashlightItem)((SessionManager.TryGetUnlockedItemSlotData(Plugin.flashlightSlotData.slotName, ref val) && ReservedPlayerData.allPlayerData.TryGetValue(playerController, out value)) ? /*isinst with value type is only supported in some contexts*/: null);
		}

		public static FlashlightItem GetCurrentlySelectedFlashlight(PlayerControllerB playerController)
		{
			return (FlashlightItem)((playerController.currentItemSlot >= 0 && playerController.currentItemSlot < playerController.ItemSlots.Length) ? /*isinst with value type is only supported in some contexts*/: null);
		}

		public static FlashlightItem GetFirstFlashlightItem(PlayerControllerB playerController)
		{
			GrabbableObject[] itemSlots = playerController.ItemSlots;
			foreach (GrabbableObject val in itemSlots)
			{
				if ((Object)(object)val != (Object)null)
				{
					FlashlightItem val2 = (FlashlightItem)(object)((val is FlashlightItem) ? val : null);
					if (val2 != null)
					{
						return val2;
					}
				}
			}
			return null;
		}

		[HarmonyPatch(typeof(FlashlightItem), "PocketItem")]
		[HarmonyPostfix]
		private static void OnPocketFlashlight(FlashlightItem __instance)
		{
			OnPocketFlashlightLocal(__instance);
		}

		[HarmonyPatch(typeof(FlashlightItem), "PocketFlashlightClientRpc")]
		[HarmonyPostfix]
		private static void OnPocketFlashlightClientRpc(bool stillUsingFlashlight, FlashlightItem __instance)
		{
			PlayerControllerB val = ((GrabbableObject)(__instance?)).playerHeldBy;
			if (Object.op_Implicit((Object)(object)val) && !((Object)(object)val == (Object)(object)localPlayerController) && NetworkManager.Singleton.IsClient && (int)Traverse.Create((object)__instance).Field("__rpc_exec_stage").GetValue() == 2)
			{
				OnPocketFlashlightLocal(__instance);
			}
		}

		private static void OnPocketFlashlightLocal(FlashlightItem flashlightItem)
		{
			PlayerControllerB val = ((GrabbableObject)(flashlightItem?)).playerHeldBy;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			GrabbableObject pocketedFlashlight = val.pocketedFlashlight;
			FlashlightItem val2 = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null);
			if (((GrabbableObject)flashlightItem).isBeingUsed)
			{
				if (Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)flashlightItem)
				{
					UpdateFlashlightState(val2, active: false);
				}
				UpdateFlashlightState(flashlightItem, active: true);
				val.pocketedFlashlight = (GrabbableObject)(object)flashlightItem;
			}
		}

		[HarmonyPatch(typeof(FlashlightItem), "EquipItem")]
		[HarmonyPostfix]
		private static void OnEquipFlashlight(FlashlightItem __instance)
		{
			PlayerControllerB val = ((GrabbableObject)(__instance?)).playerHeldBy;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			GrabbableObject pocketedFlashlight = val.pocketedFlashlight;
			FlashlightItem val2 = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null);
			if (!((Object)(object)__instance != (Object)(object)val2))
			{
				return;
			}
			if (((GrabbableObject)__instance).isBeingUsed)
			{
				UpdateFlashlightState(__instance, active: true);
				if (Object.op_Implicit((Object)(object)val2))
				{
					UpdateFlashlightState(val2, active: false);
				}
			}
			else if (Object.op_Implicit((Object)(object)val2) && ((GrabbableObject)val2).isBeingUsed)
			{
				UpdateFlashlightState(__instance, active: false);
				UpdateFlashlightState(val2, active: true);
			}
		}

		[HarmonyPatch(typeof(FlashlightItem), "DiscardItem")]
		[HarmonyPostfix]
		private static void ResetPocketedFlashlightPost(FlashlightItem __instance)
		{
			if (!Object.op_Implicit((Object)(object)__instance))
			{
				return;
			}
			PlayerControllerB val = GetPreviousPlayerHeldBy(__instance);
			if (!Object.op_Implicit((Object)(object)val))
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val2 in allPlayerScripts)
				{
					if ((Object)(object)__instance == (Object)(object)val2.pocketedFlashlight)
					{
						val = val2;
						break;
					}
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					return;
				}
			}
			FlashlightItem currentlySelectedFlashlight = GetCurrentlySelectedFlashlight(val);
			FlashlightItem reservedFlashlight = GetReservedFlashlight(val);
			GrabbableObject pocketedFlashlight = val.pocketedFlashlight;
			FlashlightItem val3 = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null);
			if ((Object)(object)__instance == (Object)(object)val3)
			{
				FlashlightItem val4 = ((Object.op_Implicit((Object)(object)reservedFlashlight) && (!Object.op_Implicit((Object)(object)currentlySelectedFlashlight) || (((GrabbableObject)reservedFlashlight).isBeingUsed && !((GrabbableObject)currentlySelectedFlashlight).isBeingUsed))) ? reservedFlashlight : currentlySelectedFlashlight);
				val.pocketedFlashlight = null;
				if (Object.op_Implicit((Object)(object)val4))
				{
					if ((Object)(object)val4 != (Object)(object)currentlySelectedFlashlight)
					{
						val.pocketedFlashlight = (GrabbableObject)(object)val4;
					}
					UpdateFlashlightState(val4, ((GrabbableObject)val4).isBeingUsed);
				}
			}
			else if ((Object)(object)val3 != (Object)null && ((GrabbableObject)val3).isBeingUsed)
			{
				UpdateFlashlightState(val3, active: true);
			}
		}

		[HarmonyPatch(typeof(FlashlightItem), "SwitchFlashlight")]
		[HarmonyPostfix]
		private static void OnToggleFlashlight(bool on, FlashlightItem __instance)
		{
			PlayerControllerB val = ((GrabbableObject)(__instance?)).playerHeldBy;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			GrabbableObject pocketedFlashlight = val.pocketedFlashlight;
			FlashlightItem val2 = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null);
			if (!((GrabbableObject)__instance).isBeingUsed)
			{
				if ((Object)(object)__instance == (Object)(object)val2)
				{
					val.pocketedFlashlight = null;
				}
				return;
			}
			Traverse.Create((object)__instance).Field("previousPlayerHeldBy").SetValue((object)val);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)__instance)
			{
				if (((GrabbableObject)val2).isBeingUsed)
				{
					val2.SwitchFlashlight(false);
					UpdateFlashlightState(val2, active: false);
				}
				val.pocketedFlashlight = null;
			}
			if ((Object)(object)__instance != (Object)(object)GetCurrentlySelectedFlashlight(val))
			{
				val.pocketedFlashlight = (GrabbableObject)(object)__instance;
			}
			UpdateFlashlightState(__instance, active: true);
		}

		internal static void UpdateFlashlightState(FlashlightItem flashlightItem, bool active)
		{
			PlayerControllerB val = ((GrabbableObject)(flashlightItem?)).playerHeldBy;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			((GrabbableObject)flashlightItem).isBeingUsed = active;
			bool flag = active && ((Object)(object)flashlightItem == (Object)(object)GetCurrentlySelectedFlashlight(val) || ((Object)(object)val != (Object)(object)localPlayerController && (Object)(object)flashlightItem == (Object)(object)GetReservedFlashlight(val)));
			bool flag2 = active && !flag;
			((Behaviour)flashlightItem.flashlightBulb).enabled = flag;
			((Behaviour)flashlightItem.flashlightBulbGlow).enabled = flag;
			flashlightItem.usingPlayerHelmetLight = flag2;
			((Behaviour)val.helmetLight).enabled = flag2;
			if (flag2)
			{
				val.ChangeHelmetLight(flashlightItem.flashlightTypeID, true);
			}
			if (!flashlightItem.changeMaterial)
			{
				return;
			}
			try
			{
				((Renderer)flashlightItem.flashlightMesh).sharedMaterials[1] = (flag ? flashlightItem.bulbLight : flashlightItem.bulbDark);
			}
			catch
			{
			}
		}
	}
}
namespace ReservedFlashlightSlot.Input
{
	internal class IngameKeybinds : LcInputActions
	{
		internal static IngameKeybinds Instance = new IngameKeybinds();

		[InputAction("<Keyboard>/f", Name = "[ReservedItemSlots]\nToggle flashlight")]
		public InputAction ToggleFlashlightHotkey { get; set; }

		internal static InputActionAsset GetAsset()
		{
			return ((LcInputActions)Instance).Asset;
		}
	}
	internal class InputUtilsCompat
	{
		internal static InputActionAsset Asset => IngameKeybinds.GetAsset();

		internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils");

		public static InputAction ToggleFlashlightHotkey => IngameKeybinds.Instance.ToggleFlashlightHotkey;
	}
	[HarmonyPatch]
	public static class KeybindDisplayNames
	{
		public static bool usingControllerPrevious = false;

		public static string[] keyboardKeywords = new string[2] { "keyboard", "mouse" };

		public static string[] controllerKeywords = new string[2] { "gamepad", "controller" };

		public static bool usingController => StartOfRound.Instance.localPlayerUsingController;

		public static string GetKeybindDisplayName(InputAction inputAction)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (inputAction == null || !inputAction.enabled)
			{
				return "";
			}
			int num = (usingController ? 1 : 0);
			InputBinding val = inputAction.bindings[num];
			string effectivePath = ((InputBinding)(ref val)).effectivePath;
			return GetKeybindDisplayName(effectivePath);
		}

		public static string GetKeybindDisplayName(string controlPath)
		{
			if (controlPath.Length <= 1)
			{
				return "";
			}
			string text = controlPath.ToLower();
			int num = text.IndexOf(">/");
			text = ((num >= 0) ? text.Substring(num + 2) : text);
			if (text.Contains("not-bound"))
			{
				return "";
			}
			text = text.Replace("leftalt", "Alt");
			text = text.Replace("rightalt", "Alt");
			text = text.Replace("leftctrl", "Ctrl");
			text = text.Replace("rightctrl", "Ctrl");
			text = text.Replace("leftshift", "Shift");
			text = text.Replace("rightshift", "Shift");
			text = text.Replace("leftbutton", "LMB");
			text = text.Replace("rightbutton", "RMB");
			text = text.Replace("middlebutton", "MMB");
			text = text.Replace("lefttrigger", "LT");
			text = text.Replace("righttrigger", "RT");
			text = text.Replace("leftshoulder", "LB");
			text = text.Replace("rightshoulder", "RB");
			text = text.Replace("leftstickpress", "LS");
			text = text.Replace("rightstickpress", "RS");
			text = text.Replace("dpad/", "DPad-");
			text = text.Replace("backquote", "`");
			try
			{
				text = char.ToUpper(text[0]) + text.Substring(1);
			}
			catch
			{
			}
			return text;
		}
	}
	[HarmonyPatch]
	internal static class Keybinds
	{
		public static InputActionAsset Asset;

		public static InputActionMap ActionMap;

		private static InputAction ActivateFlashlightAction;

		public static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;

		[HarmonyPatch(typeof(PreInitSceneScript), "Awake")]
		[HarmonyPrefix]
		public static void AddToKeybindMenu()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log("Initializing hotkeys.");
			if (InputUtilsCompat.Enabled)
			{
				Asset = InputUtilsCompat.Asset;
				ActionMap = Asset.actionMaps[0];
				ActivateFlashlightAction = InputUtilsCompat.ToggleFlashlightHotkey;
			}
			else
			{
				Asset = ScriptableObject.CreateInstance<InputActionAsset>();
				ActionMap = new InputActionMap("ReservedItemSlots");
				InputActionSetupExtensions.AddActionMap(Asset, ActionMap);
				ActivateFlashlightAction = InputActionSetupExtensions.AddAction(ActionMap, "ReservedItemSlots.ToggleFlashlight", (InputActionType)0, "<keyboard>/f", (string)null, (string)null, (string)null, (string)null);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable()
		{
			Asset.Enable();
			ActivateFlashlightAction.performed += OnActivateFlashlightPerformed;
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable()
		{
			Asset.Disable();
			ActivateFlashlightAction.performed -= OnActivateFlashlightPerformed;
		}

		private static void OnActivateFlashlightPerformed(CallbackContext context)
		{
			if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerControlled || (((NetworkBehaviour)localPlayerController).IsServer && !localPlayerController.isHostPlayerObject) || !((CallbackContext)(ref context)).performed || ShipBuildModeManager.Instance.InBuildMode || localPlayerController.inTerminalMenu || ReservedPlayerData.localPlayerData.timeSinceSwitchingSlots < 0.075f || localPlayerController.isTypingChat || localPlayerController.inTerminalMenu || localPlayerController.quickMenuManager.isMenuOpen || localPlayerController.isPlayerDead || localPlayerController.isGrabbingObjectAnimation || ReservedPlayerData.localPlayerData.isGrabbingReservedItem)
			{
				return;
			}
			FlashlightItem val = FlashlightPatcher.GetMainFlashlight(localPlayerController);
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = FlashlightPatcher.GetFirstFlashlightItem(localPlayerController);
				if (!Object.op_Implicit((Object)(object)val))
				{
					return;
				}
			}
			bool flag = !((GrabbableObject)val).isBeingUsed;
			if (flag && (Object)(object)val != (Object)(object)FlashlightPatcher.GetCurrentlySelectedFlashlight(localPlayerController))
			{
				localPlayerController.pocketedFlashlight = (GrabbableObject)(object)val;
			}
			((GrabbableObject)val).UseItemOnClient(flag);
			Traverse.Create((object)localPlayerController).Field("timeSinceSwitchingSlots").SetValue((object)0);
		}
	}
}
namespace ReservedFlashlightSlot.Config
{
	public static class ConfigSettings
	{
		public static ConfigEntry<int> overrideItemSlotPriority;

		public static ConfigEntry<int> overridePurchasePrice;

		public static ConfigEntry<bool> includeLaserPointer;

		public static ConfigEntry<string> additionalItemsInSlot;

		public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>();

		public static void BindConfigSettings()
		{
			Plugin.Log("BindingConfigs");
			overrideItemSlotPriority = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "FlashlightSlotPriorityOverride", 200, "[Host only] Manually set the priority for this item slot. Higher priority slots will come first in the reserved item slots, which will appear below the other slots. Negative priority items will appear on the left side of the screen, this is disabled in the core mod's config."));
			includeLaserPointer = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Server-side", "IncludeLaserPointer", false, "[Host only] If enabled, the laser pointer will be added to the reserved flashlight slot."));
			overridePurchasePrice = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Server-side", "FlashlightSlotPriceOverride", 200, "[Host only] Manually set the price for this item in the store. Setting 0 will force this item to be unlocked immediately after the game starts."));
			additionalItemsInSlot = AddConfigEntry<string>(((BaseUnityPlugin)Plugin.instance).Config.Bind<string>("Server-side", "AdditionalItemsInSlot", "", "[Host only] Syntax: \"Item1,Item name2\" (without quotes). When adding items, use the item's name as it appears in game. Include spaces if there are spaces in the item name. Adding items that do not exist, or that are from a mod which is not enabled will not cause any problems.\nNOTE: IF YOU ARE USING A TRANSLATION MOD, YOU MAY NEED TO ADD THE TRANSLATED NAME OF ANY ITEM YOU WANT IN THIS SLOT."));
			additionalItemsInSlot.Value = additionalItemsInSlot.Value.Replace(", ", ",");
			TryRemoveOldConfigSettings();
		}

		public static ConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry)
		{
			currentConfigEntries.Add(((ConfigEntryBase)configEntry).Definition.Key, (ConfigEntryBase)(object)configEntry);
			return configEntry;
		}

		public static string[] ParseAdditionalItems()
		{
			return ConfigSettings.ParseItemNames(additionalItemsInSlot.Value);
		}

		public static void TryRemoveOldConfigSettings()
		{
			HashSet<string> hashSet = new HashSet<string>();
			HashSet<string> hashSet2 = new HashSet<string>();
			foreach (ConfigEntryBase value in currentConfigEntries.Values)
			{
				hashSet.Add(value.Definition.Section);
				hashSet2.Add(value.Definition.Key);
			}
			try
			{
				ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config;
				string configFilePath = config.ConfigFilePath;
				if (!File.Exists(configFilePath))
				{
					return;
				}
				string text = File.ReadAllText(configFilePath);
				string[] array = File.ReadAllLines(configFilePath);
				string text2 = "";
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = array[i].Replace("\n", "");
					if (array[i].Length <= 0)
					{
						continue;
					}
					if (array[i].StartsWith("["))
					{
						if (text2 != "" && !hashSet.Contains(text2))
						{
							text2 = "[" + text2 + "]";
							int num = text.IndexOf(text2);
							int num2 = text.IndexOf(array[i]);
							text = text.Remove(num, num2 - num);
						}
						text2 = array[i].Replace("[", "").Replace("]", "").Trim();
					}
					else
					{
						if (!(text2 != ""))
						{
							continue;
						}
						if (i <= array.Length - 4 && array[i].StartsWith("##"))
						{
							int j;
							for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++)
							{
							}
							if (hashSet.Contains(text2))
							{
								int num3 = array[i + j - 1].IndexOf("=");
								string item = array[i + j - 1].Substring(0, num3 - 1);
								if (!hashSet2.Contains(item))
								{
									int num4 = text.IndexOf(array[i]);
									int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length;
									text = text.Remove(num4, num5 - num4);
								}
							}
							i += j - 1;
						}
						else if (array[i].Length > 3)
						{
							text = text.Replace(array[i], "");
						}
					}
				}
				if (!hashSet.Contains(text2))
				{
					text2 = "[" + text2 + "]";
					int num6 = text.IndexOf(text2);
					text = text.Remove(num6, text.Length - num6);
				}
				while (text.Contains("\n\n\n"))
				{
					text = text.Replace("\n\n\n", "\n\n");
				}
				File.WriteAllText(configFilePath, text);
				config.Reload();
			}
			catch
			{
			}
		}
	}
}