Decompiled source of AutoPickUp v1.0.0

BepInEx/plugins/AutoPickUp.dll

Decompiled 11 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using PerfectRandom.Sulfur.Core;
using PerfectRandom.Sulfur.Core.UI;
using PerfectRandom.Sulfur.Core.Units;
using PerfectRandom.Sulfur.Core.World;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoPickUp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoPickUp")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("14ba83c2-9591-4254-83a4-c49a7ca31487")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AetharNet.Mods.Autoitem;

[BepInPlugin("AetharNet.Mods.Autoitem", "AutoPickUp by:SPM", "1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class loaderfix : BaseUnityPlugin
{
	public const string PluginGUID = "AetharNet.Mods.Autoitem";

	public const string PluginAuthor = "12981";

	public const string PluginName = "AutoPickUp by:SPM";

	public const string PluginVersion = "1.0";

	internal static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		Set.LoadFromFile();
		Set.SaveToFile();
		OptionsRegistration.Register();
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "AetharNet.Mods.Autoitem");
	}
}
public class Mod : MonoBehaviour
{
	public static bool backisboom;

	public static InputAction showmlese;

	public static int showmint;

	private static readonly FieldInfo ActiveInteractablesField = AccessTools.Field(typeof(InteractionManager), "_activeInteractables");

	private static readonly FieldInfo AllInteractablesField = AccessTools.Field(typeof(InteractionManager), "_allInteractables");

	private static readonly FieldInfo MovingPickupsField = AccessTools.Field(typeof(InteractionManager), "_movingPickups");

	private static readonly MethodInfo ExecutePickupMethod = AccessTools.Method(typeof(InteractionManager), "ExecutePickup", (Type[])null, (Type[])null);

	private const float PickupScanInterval = 0.1f;

	private float nextPickupScanTime;

	private bool backMessageCoroutineRunning;

	private string message = "";

	private bool showMessage;

	private Color messageColor;

	private bool backisboom1;

	public void Update()
	{
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: 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_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)StaticInstance<GameManager>.Instance.PlayerScript == (Object)null)
		{
			return;
		}
		if (OptionsRegistration.AutoPickupPressedThisFrame())
		{
			Set.autopickup = !Set.autopickup;
			Set.SaveToFile();
			ShowAutoPickupMessage(Set.autopickup);
		}
		if (backisboom && !backMessageCoroutineRunning)
		{
			backisboom1 = true;
			backMessageCoroutineRunning = true;
			((MonoBehaviour)this).StartCoroutine(DisplayMessage1());
		}
		else if (!backisboom)
		{
			backisboom1 = false;
		}
		if (!Set.autopickup || Time.unscaledTime < nextPickupScanTime)
		{
			return;
		}
		nextPickupScanTime = Time.unscaledTime + 0.1f;
		InteractionManager instance = StaticInstance<InteractionManager>.Instance;
		if ((Object)(object)instance == (Object)null || ActiveInteractablesField == null || !(ActiveInteractablesField.GetValue(instance) is List<Interactable> { Count: not 0 } list))
		{
			return;
		}
		Vector3 position = ((Component)StaticInstance<GameManager>.Instance.PlayerScript).transform.position;
		float pickupdis = Set.pickupdis;
		float num = pickupdis * pickupdis;
		for (int num2 = list.Count - 1; num2 >= 0; num2--)
		{
			if (num2 < list.Count)
			{
				try
				{
					Interactable val = list[num2];
					if (!((Object)(object)val == (Object)null))
					{
						Pickup component = ((Component)val).GetComponent<Pickup>();
						if (!((Object)(object)component == (Object)null))
						{
							Vector3 val2 = ((Component)component).transform.position - position;
							if (!(((Vector3)(ref val2)).sqrMagnitude > num))
							{
								if (StaticInstance<UIManager>.Instance.PlayerBackpackGrid.GetPossibleSpace(component.ItemSO.inventorySize, false, false, false) == new Vector2Int(-1, -1))
								{
									backisboom = true;
									break;
								}
								if (CallExecutePickup(instance, component))
								{
									RemovePickedUpInteractable(instance, component);
								}
							}
						}
					}
				}
				catch
				{
				}
			}
		}
	}

	private void Start()
	{
	}

	private void OnGUI()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		if (showMessage)
		{
			GUI.color = messageColor;
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.alignment = (TextAnchor)4;
			GUILayout.BeginArea(new Rect((float)(Screen.width / 2 - 150), (float)(Screen.height / 4 - 20), 300f, 40f));
			GUILayout.Label(message, val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.EndArea();
			GUI.color = Color.white;
		}
		if (backisboom1)
		{
			GUI.color = Color.red;
			GUIStyle val2 = new GUIStyle(GUI.skin.label);
			val2.fontSize = 22;
			val2.alignment = (TextAnchor)4;
			GUILayout.BeginArea(new Rect((float)(Screen.width / 2 - 100), (float)(Screen.height / 4 - 45), 300f, 40f));
			GUILayout.Label("Your bag is full!! Can't pick up anytings", val2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.EndArea();
			GUI.color = Color.white;
		}
	}

	public void ShowAutoPickupMessage(bool isOn)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		message = (isOn ? "Auto pickup is activated" : "Auto pickup is turned off");
		messageColor = (isOn ? Color.green : Color.red);
		((MonoBehaviour)this).StartCoroutine(DisplayMessage());
	}

	private IEnumerator DisplayMessage()
	{
		showMessage = true;
		yield return (object)new WaitForSeconds(2f);
		showMessage = false;
	}

	private IEnumerator DisplayMessage1()
	{
		yield return (object)new WaitForSeconds(2f);
		backisboom = false;
		backisboom1 = false;
		backMessageCoroutineRunning = false;
	}

	public bool CallExecutePickup(object targetInstance, Pickup pickup)
	{
		if (targetInstance == null || (Object)(object)pickup == (Object)null || ExecutePickupMethod == null)
		{
			return false;
		}
		return (bool)ExecutePickupMethod.Invoke(targetInstance, new object[1] { pickup });
	}

	private static void RemovePickedUpInteractable(InteractionManager interactionManager, Pickup pickup)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		if (!((Object)(object)interactionManager == (Object)null) && !((Object)(object)pickup == (Object)null))
		{
			List<Pickup> list = ((MovingPickupsField != null) ? (MovingPickupsField.GetValue(interactionManager) as List<Pickup>) : null);
			List<Interactable> list2 = ((ActiveInteractablesField != null) ? (ActiveInteractablesField.GetValue(interactionManager) as List<Interactable>) : null);
			List<Interactable> obj = ((AllInteractablesField != null) ? (AllInteractablesField.GetValue(interactionManager) as List<Interactable>) : null);
			list?.Remove(pickup);
			list2?.Remove((Interactable)pickup);
			obj?.Remove((Interactable)pickup);
		}
	}
}
internal static class OptionsRegistration
{
	internal const string OwnerMod = "AutoPickUp";

	internal const string AutoPickupKeyName = "AutoPickup_Toggle";

	private static bool registered;

	private static bool registryMissing;

	private static bool registryMissingLogged;

	private static bool incompatibleLogged;

	private static bool refreshedOptionsScreen;

	private static bool registryIncompatible;

	private static KeyCode cachedInputKey;

	private static Keyboard cachedKeyboard;

	private static Mouse cachedMouse;

	private static ButtonControl cachedKeyboardControl;

	private static ButtonControl cachedMouseControl;

	private static bool inputControlsCached;

	internal static void Register()
	{
		Register(forceRetry: false);
	}

	internal static void Register(bool forceRetry)
	{
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		if (registered || ((registryMissing || registryIncompatible) && !forceRetry))
		{
			return;
		}
		Type type = AccessTools.TypeByName("SulfurOptionsScreenSettings.ModOptionsRegistry");
		if (type == null)
		{
			registryMissing = true;
			if (!registryMissingLogged && loaderfix.Logger != null)
			{
				registryMissingLogged = true;
				loaderfix.Logger.LogInfo((object)"OptionsScreen settings mod was not found; using AutoPickSet.txt key.");
			}
			return;
		}
		registryMissing = false;
		MethodInfo methodInfo = AccessTools.Method(type, "AddInfo", new Type[4]
		{
			typeof(string),
			typeof(string),
			typeof(int),
			typeof(string)
		}, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(type, "AddKeyBind", new Type[7]
		{
			typeof(string),
			typeof(string),
			typeof(string),
			typeof(KeyCode),
			typeof(Action<KeyCode>),
			typeof(int),
			typeof(string)
		}, (Type[])null);
		if (methodInfo == null || methodInfo2 == null)
		{
			registryIncompatible = true;
			if (!incompatibleLogged && loaderfix.Logger != null)
			{
				incompatibleLogged = true;
				loaderfix.Logger.LogWarning((object)"OptionsScreen settings registry API was not compatible; AutoPickup key setting will be skipped.");
			}
			return;
		}
		methodInfo.Invoke(null, new object[4] { "AutoPickup_Header", "AutoPickUp", 0, "Here you can modify the switch shortcut keys for automatic picking." });
		methodInfo2.Invoke(null, new object[7]
		{
			"AutoPickUp",
			"AutoPickup_Toggle",
			"Auto-pickup toggle",
			Set.autopickKey,
			new Action<KeyCode>(OnAutoPickupKeyChanged),
			20,
			"PluginConfigs/AutoPickSet.txt."
		});
		registryIncompatible = false;
		registered = true;
		if (loaderfix.Logger != null)
		{
			loaderfix.Logger.LogInfo((object)"Registered AutoPickup key binding in OptionsScreen Mod settings.");
		}
	}

	internal static void RegisterForOptionsScreen(object optionsScreen)
	{
		int num;
		if (registered)
		{
			num = (registryMissing ? 1 : 0);
			if (num == 0)
			{
				goto IL_001d;
			}
		}
		else
		{
			num = 1;
		}
		Register(forceRetry: true);
		goto IL_001d;
		IL_001d:
		if (num != 0 && optionsScreen != null && !refreshedOptionsScreen)
		{
			RefreshOptionsScreenRegistry(optionsScreen);
			refreshedOptionsScreen = true;
		}
	}

	internal static bool AutoPickupPressedThisFrame()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Register();
		return IsFallbackKeyPressedThisFrame(Set.autopickKey);
	}

	private static void RefreshOptionsScreenRegistry(object optionsScreen)
	{
		Type type = AccessTools.TypeByName("SulfurOptionsScreenSettings.ModOptionsRegistry");
		if (!(type == null))
		{
			InvokeRegistryMethod(type, "EnsureRegistered", Type.EmptyTypes, null);
			InvokeRegistryMethod(type, "ApplyLocalizedTexts", Type.EmptyTypes, null);
			if (optionsScreen != null)
			{
				Type type2 = optionsScreen.GetType();
				InvokeRegistryMethod(type, "EnsureCategoryInMenuOrder", new Type[1] { type2 }, new object[1] { optionsScreen });
				InvokeRegistryMethod(type, "ApplyCategoryLabels", new Type[1] { type2 }, new object[1] { optionsScreen });
			}
		}
	}

	private static void InvokeRegistryMethod(Type registryType, string methodName, Type[] parameters, object[] args)
	{
		MethodInfo methodInfo = AccessTools.Method(registryType, methodName, parameters, (Type[])null);
		if (!(methodInfo == null))
		{
			methodInfo.Invoke(null, args);
		}
	}

	private static void OnAutoPickupKeyChanged(KeyCode key)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		Set.autopickKey = key;
		Set.SaveToFile();
	}

	private static bool IsFallbackKeyPressedThisFrame(KeyCode key)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if ((int)key == 0)
		{
			return false;
		}
		CacheInputControls(key);
		if (cachedKeyboardControl != null)
		{
			return cachedKeyboardControl.wasPressedThisFrame;
		}
		if (cachedMouseControl != null)
		{
			return cachedMouseControl.wasPressedThisFrame;
		}
		try
		{
			return Input.GetKeyDown(key);
		}
		catch
		{
			return false;
		}
	}

	private static void CacheInputControls(KeyCode key)
	{
		//IL_0032: 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_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected I4, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected O, but got Unknown
		Keyboard current = Keyboard.current;
		Mouse current2 = Mouse.current;
		if (inputControlsCached && cachedInputKey == key && cachedKeyboard == current && cachedMouse == current2)
		{
			return;
		}
		inputControlsCached = true;
		cachedInputKey = key;
		cachedKeyboard = current;
		cachedMouse = current2;
		cachedKeyboardControl = null;
		cachedMouseControl = null;
		Mouse current3 = Mouse.current;
		if (current3 != null)
		{
			switch (key - 323)
			{
			case 0:
				cachedMouseControl = current3.leftButton;
				return;
			case 1:
				cachedMouseControl = current3.rightButton;
				return;
			case 2:
				cachedMouseControl = current3.middleButton;
				return;
			}
		}
		Keyboard current4 = Keyboard.current;
		if (current4 != null && TryConvertKeyCodeToInputSystemKey(key, out var key2))
		{
			cachedKeyboardControl = (ButtonControl)current4[key2];
		}
	}

	private static bool TryConvertKeyCodeToInputSystemKey(KeyCode keyCode, out Key key)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Invalid comparison between Unknown and I4
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Invalid comparison between Unknown and I4
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Invalid comparison between Unknown and I4
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Invalid comparison between Unknown and I4
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Invalid comparison between Unknown and I4
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected I4, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Invalid comparison between Unknown and I4
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Invalid comparison between Unknown and I4
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Invalid comparison between Unknown and I4
		//IL_0133: 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_013b: Expected I4, but got Unknown
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected I4, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected I4, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Invalid comparison between Unknown and I4
		key = (Key)0;
		if ((int)keyCode <= 47)
		{
			if ((int)keyCode <= 13)
			{
				if ((int)keyCode == 8)
				{
					key = (Key)65;
					return true;
				}
				if ((int)keyCode == 9)
				{
					key = (Key)3;
					return true;
				}
				if ((int)keyCode == 13)
				{
					key = (Key)2;
					return true;
				}
			}
			else
			{
				if ((int)keyCode == 27)
				{
					key = (Key)60;
					return true;
				}
				if ((int)keyCode == 32)
				{
					key = (Key)1;
					return true;
				}
				switch (keyCode - 39)
				{
				case 0:
					key = (Key)5;
					return true;
				case 5:
					key = (Key)7;
					return true;
				case 7:
					key = (Key)8;
					return true;
				case 8:
					key = (Key)9;
					return true;
				case 6:
					key = (Key)13;
					return true;
				}
			}
		}
		else if ((int)keyCode <= 96)
		{
			if ((int)keyCode == 59)
			{
				key = (Key)6;
				return true;
			}
			if ((int)keyCode == 61)
			{
				key = (Key)14;
				return true;
			}
			switch (keyCode - 91)
			{
			case 5:
				key = (Key)4;
				return true;
			case 1:
				key = (Key)10;
				return true;
			case 0:
				key = (Key)11;
				return true;
			case 2:
				key = (Key)12;
				return true;
			}
		}
		else
		{
			if ((int)keyCode == 127)
			{
				key = (Key)71;
				return true;
			}
			switch (keyCode - 271)
			{
			default:
				switch (keyCode - 303)
				{
				case 3:
					key = (Key)55;
					return true;
				case 2:
					key = (Key)56;
					return true;
				case 1:
					key = (Key)51;
					return true;
				case 0:
					key = (Key)52;
					return true;
				case 5:
					key = (Key)53;
					return true;
				case 4:
					key = (Key)54;
					return true;
				}
				break;
			case 0:
				key = (Key)77;
				return true;
			case 2:
				key = (Key)63;
				return true;
			case 3:
				key = (Key)64;
				return true;
			case 5:
				key = (Key)61;
				return true;
			case 4:
				key = (Key)62;
				return true;
			case 6:
				key = (Key)70;
				return true;
			case 7:
				key = (Key)68;
				return true;
			case 8:
				key = (Key)69;
				return true;
			case 9:
				key = (Key)67;
				return true;
			case 10:
				key = (Key)66;
				return true;
			case 1:
				break;
			}
		}
		string text = ((object)keyCode).ToString();
		if (text.StartsWith("Alpha", StringComparison.Ordinal))
		{
			return Enum.TryParse<Key>("Digit" + text.Substring(5), ignoreCase: true, out key);
		}
		if (text.StartsWith("Keypad", StringComparison.Ordinal))
		{
			return Enum.TryParse<Key>("Numpad" + text.Substring(6), ignoreCase: true, out key);
		}
		return Enum.TryParse<Key>(text, ignoreCase: true, out key);
	}
}
[HarmonyPatch(typeof(OptionsScreen), "SetCategory")]
public class Patch_autoitem_OptionsScreen_SetCategory_Patch
{
	[HarmonyPrefix]
	[HarmonyPriority(800)]
	public static void Prefix(OptionsScreen __instance)
	{
		OptionsRegistration.RegisterForOptionsScreen(__instance);
	}
}
[HarmonyPatch(typeof(OptionsScreen), "SetupMenu")]
public class Patch_autoitem_OptionsScreen_SetupMenu_Patch
{
	[HarmonyPrefix]
	[HarmonyPriority(800)]
	public static void Prefix(OptionsScreen __instance)
	{
		OptionsRegistration.RegisterForOptionsScreen(__instance);
	}

	[HarmonyPostfix]
	public static void Postfix(OptionsScreen __instance)
	{
		OptionsRegistration.RegisterForOptionsScreen(__instance);
	}
}
[HarmonyPatch(typeof(UnitManager), "Start")]
public class Patch_autoitem_Restart_Patch
{
	[HarmonyPostfix]
	public static void Postfix(UnitManager __instance)
	{
		((Component)__instance).gameObject.AddComponent<Mod>();
		Set.LoadFromFile();
		Set.SaveToFile();
	}
}
public class Set
{
	private const string ConfigDirectoryName = "PluginConfigs";

	private const string ConfigFileName = "AutoPickSet.txt";

	internal static float pickupdis = 3f;

	internal static bool autopickup = false;

	internal static KeyCode autopickKey = (KeyCode)106;

	internal static string ConfigPath => Path.Combine(GetConfigDirectory(), "AutoPickSet.txt");

	public static void SaveToFile()
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		string configPath = ConfigPath;
		Directory.CreateDirectory(Path.GetDirectoryName(configPath));
		using StreamWriter streamWriter = new StreamWriter(configPath);
		streamWriter.WriteLine("pickDis=" + pickupdis.ToString(CultureInfo.InvariantCulture));
		streamWriter.WriteLine($"autopickup={autopickup}");
		streamWriter.WriteLine($"AutopickKey={autopickKey}");
	}

	public static void LoadFromFile()
	{
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		string path = ConfigPath;
		string text = Path.Combine(Application.dataPath, "AutoPickSet.txt");
		if (!File.Exists(path) && File.Exists(text))
		{
			path = text;
		}
		if (!File.Exists(path))
		{
			return;
		}
		string[] array = File.ReadAllLines(path);
		for (int i = 0; i < array.Length; i++)
		{
			string[] array2 = array[i].Split(new char[1] { '=' }, 2);
			if (array2.Length != 2)
			{
				continue;
			}
			string text2 = array2[0].Trim();
			string text3 = array2[1].Trim();
			switch (text2)
			{
			case "pickDis":
			case "自动拾取距离pickDis":
			{
				if (float.TryParse(text3, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || float.TryParse(text3, out result2))
				{
					pickupdis = result2;
				}
				break;
			}
			case "autopickup":
			case "自动拾取开关autopickup":
			{
				if (bool.TryParse(text3, out var result))
				{
					autopickup = result;
				}
				break;
			}
			case "AutopickKey":
			case "自动拾取开关按键AutopickKey(注意字母按键一定要大写,其他的需要去网上查找C#KeyCode代码)":
				try
				{
					autopickKey = (KeyCode)Enum.Parse(typeof(KeyCode), text3, ignoreCase: true);
				}
				catch
				{
					Debug.LogWarning((object)("Can't Not turn'" + text3 + "'Into KeyCode"));
				}
				break;
			}
		}
	}

	private static string GetConfigDirectory()
	{
		string text = Paths.GameRootPath;
		if (string.IsNullOrWhiteSpace(text))
		{
			text = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
		}
		return Path.Combine(text, "PluginConfigs");
	}
}