Decompiled source of Joive BGMod v0.1.0

BGMod-Joive.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BGMod;
using BGMod.Config;
using BGMod.Core;
using BGMod.ESP;
using BGMod.Features;
using BGMod.HUD;
using BGMod.Patches;
using BGMod.Performance;
using BGMod.UI;
using BGMod.Utils;
using HarmonyLib;
using Lightbug.CharacterControllerPro.Core;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BGMod")]
[assembly: AssemblyProduct("BGMod")]
[assembly: AssemblyCompany("Joive")]
[assembly: AssemblyCopyright("Copyright (c) Joive")]
[assembly: MelonInfo(typeof(BGModMain), "BGMod", "0.1.0", "Joive", null)]
[assembly: MelonGame("GamesByFobri", "Gnomium")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BGMod
{
	public class BGModMain : MelonMod
	{
		private Harmony harmony;

		public static BGModMain Instance { get; private set; }

		public ModuleManager Modules { get; private set; }

		public MenuModule Menu { get; private set; }

		public override void OnInitializeMelon()
		{
			Instance = this;
			ModLog.Initialize(((MelonBase)this).LoggerInstance);
			ModConfig.Initialize();
			Modules = new ModuleManager();
			Modules.Register(new PerformanceModule());
			Modules.Register(new HUDModule());
			Modules.Register(new ESPModule());
			Modules.Register(new GnomeModule());
			Modules.Register(new ItemGiverModule());
			Modules.Register(new ResourcesModule());
			Modules.Register(new ItemESPModule());
			Modules.Register(new HumanESPModule());
			Modules.Register(new ChaosModule());
			Menu = new MenuModule(Modules);
			Modules.Register(Menu);
			Modules.Initialize();
			ApplyPatches();
			ModLog.Msg("BGMod 0.1.0 initialized.");
			ModLog.Msg("Game version: " + VersionInfo.GetGameVersionString());
			ModLog.Msg("Loaded modules: " + string.Join(", ", Modules.EnabledModuleNames));
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			Modules.OnSceneWasInitialized(buildIndex, sceneName);
		}

		public override void OnUpdate()
		{
			if (!ModConfig.EnableMod.Value)
			{
				return;
			}
			try
			{
				Modules.OnUpdate();
			}
			catch (Exception ex)
			{
				ModLog.Error("OnUpdate failed: " + ex.Message);
			}
		}

		public override void OnGUI()
		{
			if (!ModConfig.EnableMod.Value)
			{
				return;
			}
			try
			{
				Modules.OnGUI();
			}
			catch (Exception ex)
			{
				ModLog.Error("OnGUI failed: " + ex.Message);
			}
		}

		public override void OnApplicationQuit()
		{
			Modules.OnApplicationQuit();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		private void ApplyPatches()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			harmony = new Harmony("joive.bgmod");
			PatchManager.Apply(harmony);
		}
	}
}
namespace BGMod.Utils
{
	public static class GameAccess
	{
		public static PlayerNetworking LocalPlayer()
		{
			try
			{
				return ((IEnumerable<PlayerNetworking>)Object.FindObjectsByType<PlayerNetworking>((FindObjectsSortMode)0)).FirstOrDefault((Func<PlayerNetworking, bool>)((PlayerNetworking p) => (Object)(object)p != (Object)null && ((NetworkBehaviour)p).IsLocalPlayer));
			}
			catch (Exception ex)
			{
				ModLog.Warning("Local player lookup failed: " + ex.Message);
				return null;
			}
		}

		public static List<PlayerNetworking> AllPlayers()
		{
			try
			{
				return (from p in Object.FindObjectsByType<PlayerNetworking>((FindObjectsSortMode)0)
					where (Object)(object)p != (Object)null
					select p).ToList();
			}
			catch
			{
				return new List<PlayerNetworking>();
			}
		}

		public static string PlayerName(PlayerNetworking player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)player.SteamPlayer == (Object)null)
			{
				return "Player";
			}
			try
			{
				string text = "Player";
				player.SteamPlayer.TryGetName(ref text);
				return string.IsNullOrEmpty(text) ? "Player" : text;
			}
			catch
			{
				return "Player";
			}
		}

		public static Vector3 Position(Component component)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)component != (Object)null))
			{
				return Vector3.zero;
			}
			return component.transform.position;
		}

		public static float DistanceFromLocal(Component component)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			PlayerNetworking val = LocalPlayer();
			if ((Object)(object)val == (Object)null || (Object)(object)component == (Object)null)
			{
				return float.MaxValue;
			}
			return Vector3.Distance(((Component)val).transform.position, component.transform.position);
		}
	}
	public static class GuiStyles
	{
		private static bool initialized;

		private static Texture2D panelTexture;

		private static Texture2D buttonTexture;

		private static Texture2D buttonHoverTexture;

		private static Texture2D activeTexture;

		private static Texture2D activeHoverTexture;

		private static Texture2D boxTexture;

		public static GUIStyle Window;

		public static GUIStyle Tab;

		public static GUIStyle TabActive;

		public static GUIStyle Label;

		public static GUIStyle SmallLabel;

		public static GUIStyle Toggle;

		public static GUIStyle Button;

		public static GUIStyle Box;

		public static GUIStyle TextField;

		public static void Ensure()
		{
			//IL_001c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00cb: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//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_010b: Expected O, but got Unknown
			//IL_0110: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_0169: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Expected O, but got Unknown
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Expected O, but got Unknown
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Expected O, but got Unknown
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Expected O, but got Unknown
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Expected O, but got Unknown
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Expected O, but got Unknown
			//IL_0400: Expected O, but got Unknown
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			if (!initialized)
			{
				panelTexture = MakeTexture(new Color(0.045f, 0.05f, 0.055f, 1f));
				buttonTexture = MakeTexture(new Color(0.16f, 0.17f, 0.18f, 1f));
				buttonHoverTexture = MakeTexture(new Color(0.22f, 0.235f, 0.245f, 1f));
				activeTexture = MakeTexture(new Color(0.16f, 0.42f, 0.34f, 1f));
				activeHoverTexture = MakeTexture(new Color(0.2f, 0.5f, 0.4f, 1f));
				boxTexture = MakeTexture(new Color(0.02f, 0.025f, 0.03f, 1f));
				Window = new GUIStyle(GUI.skin.window)
				{
					padding = new RectOffset(14, 14, 12, 12),
					border = new RectOffset(1, 1, 1, 1)
				};
				SetAllStates(Window, panelTexture, Color.white);
				Tab = new GUIStyle(GUI.skin.button)
				{
					fontSize = 12,
					fixedHeight = 30f,
					margin = new RectOffset(2, 2, 2, 2),
					padding = new RectOffset(6, 6, 5, 5)
				};
				SetAllStates(Tab, buttonTexture, new Color(0.9f, 0.9f, 0.9f));
				Tab.hover.background = buttonHoverTexture;
				Tab.hover.textColor = Color.white;
				Tab.active.background = buttonHoverTexture;
				Tab.active.textColor = Color.white;
				Tab.focused.background = buttonTexture;
				Tab.focused.textColor = Color.white;
				TabActive = new GUIStyle(Tab);
				SetAllStates(TabActive, activeTexture, Color.white);
				TabActive.hover.background = activeHoverTexture;
				TabActive.active.background = activeHoverTexture;
				TabActive.focused.background = activeTexture;
				GUIStyle val = new GUIStyle(GUI.skin.label);
				val.normal.textColor = new Color(0.92f, 0.94f, 0.95f);
				val.fontSize = 13;
				val.richText = true;
				Label = val;
				GUIStyle val2 = new GUIStyle(Label)
				{
					fontSize = 11
				};
				val2.normal.textColor = new Color(0.72f, 0.76f, 0.78f);
				SmallLabel = val2;
				Toggle = new GUIStyle(GUI.skin.toggle)
				{
					fontSize = 13
				};
				SetTextStates(Toggle, new Color(0.92f, 0.94f, 0.95f));
				Button = new GUIStyle(GUI.skin.button)
				{
					fontSize = 13,
					fixedHeight = 28f
				};
				SetAllStates(Button, buttonTexture, Color.white);
				Button.hover.background = buttonHoverTexture;
				Button.active.background = buttonHoverTexture;
				Button.focused.background = buttonTexture;
				Box = new GUIStyle(GUI.skin.box)
				{
					padding = new RectOffset(8, 8, 6, 6),
					richText = true
				};
				SetAllStates(Box, boxTexture, Color.white);
				TextField = new GUIStyle(GUI.skin.textField)
				{
					fontSize = 13,
					fixedHeight = 28f,
					padding = new RectOffset(7, 7, 5, 5)
				};
				SetAllStates(TextField, boxTexture, Color.white);
				initialized = true;
			}
		}

		public static Texture2D MakeTexture(Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, color);
			val.Apply();
			return val;
		}

		private static void SetAllStates(GUIStyle style, Texture2D background, Color textColor)
		{
			//IL_0012: 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)
			//IL_0042: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			style.normal.background = background;
			style.normal.textColor = textColor;
			style.hover.background = background;
			style.hover.textColor = textColor;
			style.active.background = background;
			style.active.textColor = textColor;
			style.focused.background = background;
			style.focused.textColor = textColor;
			style.onNormal.background = background;
			style.onNormal.textColor = textColor;
			style.onHover.background = background;
			style.onHover.textColor = textColor;
			style.onActive.background = background;
			style.onActive.textColor = textColor;
			style.onFocused.background = background;
			style.onFocused.textColor = textColor;
		}

		private static void SetTextStates(GUIStyle style, Color textColor)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			style.normal.textColor = textColor;
			style.hover.textColor = Color.white;
			style.active.textColor = Color.white;
			style.focused.textColor = textColor;
			style.onNormal.textColor = textColor;
			style.onHover.textColor = Color.white;
			style.onActive.textColor = Color.white;
			style.onFocused.textColor = textColor;
		}
	}
	public static class ModLog
	{
		private static Instance logger;

		public static void Initialize(Instance instance)
		{
			logger = instance;
		}

		public static void Msg(string message)
		{
			Instance obj = logger;
			if (obj != null)
			{
				obj.Msg(message);
			}
		}

		public static void Warning(string message)
		{
			Instance obj = logger;
			if (obj != null)
			{
				obj.Warning(message);
			}
		}

		public static void Error(string message)
		{
			Instance obj = logger;
			if (obj != null)
			{
				obj.Error(message);
			}
		}
	}
	public static class ReflectionUtils
	{
		public const BindingFlags AnyInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		public const BindingFlags AnyStatic = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		public static object GetMemberValue(object target, string name)
		{
			if (target == null || string.IsNullOrEmpty(name))
			{
				return null;
			}
			Type type = target.GetType();
			PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.GetIndexParameters().Length == 0)
			{
				return property.GetValue(target, null);
			}
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field != null))
			{
				return null;
			}
			return field.GetValue(target);
		}

		public static bool TrySetMemberValue(object target, string name, object value)
		{
			if (target == null || string.IsNullOrEmpty(name))
			{
				return false;
			}
			Type type = target.GetType();
			PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.CanWrite && property.GetIndexParameters().Length == 0)
			{
				property.SetValue(target, value, null);
				return true;
			}
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(target, value);
				return true;
			}
			return false;
		}

		public static bool GetBool(object target, string name)
		{
			object memberValue = GetMemberValue(target, name);
			if (memberValue is bool)
			{
				return (bool)memberValue;
			}
			return false;
		}
	}
	public static class VersionInfo
	{
		public static string GetGameVersionString()
		{
			try
			{
				Bootstrap val = Object.FindFirstObjectByType<Bootstrap>();
				if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(val.GameVersionString))
				{
					return val.GameVersionString;
				}
				return Application.version;
			}
			catch
			{
				return "unknown";
			}
		}
	}
}
namespace BGMod.UI
{
	public class MenuModule : ModuleBase
	{
		private struct BehaviourState
		{
			public Behaviour Behaviour;

			public bool Enabled;
		}

		private readonly string[] tabs = new string[8] { "Main", "Player", "ESP", "Items", "Resources", "Chaos", "Performance", "Debug" };

		private Rect windowRect;

		private Vector2 scroll;

		private int selectedTab;

		private int itemMode;

		private KeyCode cachedMenuKey = (KeyCode)277;

		private bool centered;

		private bool modalActive;

		private bool timeScalePaused;

		private bool oldCursorVisible;

		private CursorLockMode oldCursorLock;

		private float oldTimeScale = 1f;

		private Texture2D dimTexture;

		private readonly List<BehaviourState> disabledBehaviours = new List<BehaviourState>();

		public override string Id => "menu";

		public override string DisplayName => "Menu";

		public override bool Enabled
		{
			get
			{
				return true;
			}
			set
			{
			}
		}

		public bool Visible { get; private set; }

		public MenuModule(ModuleManager modules)
		{
		}//IL_0052: Unknown result type (might be due to invalid IL or missing references)


		public override void Initialize(ModuleManager modules)
		{
			//IL_0017: 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)
			base.Initialize(modules);
			cachedMenuKey = ParseKey(ModConfig.MenuKey.Value, (KeyCode)277);
		}

		public override void OnUpdate()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(cachedMenuKey = ParseKey(ModConfig.MenuKey.Value, cachedMenuKey)) || Input.GetKeyDown((KeyCode)282))
			{
				SetVisible(!Visible);
			}
			if (Visible)
			{
				KeepModalState();
			}
		}

		public override void OnGUI()
		{
			//IL_0066: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (Visible)
			{
				GuiStyles.Ensure();
				EnsureWindowRect();
				GUI.depth = -10000;
				if ((Object)(object)dimTexture == (Object)null)
				{
					dimTexture = GuiStyles.MakeTexture(new Color(0f, 0f, 0f, 0.55f));
				}
				GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)dimTexture);
				windowRect = GUI.Window(3310, windowRect, new WindowFunction(DrawWindow), "BGMod", GuiStyles.Window);
				windowRect = ClampToScreen(windowRect);
			}
		}

		public override void OnApplicationQuit()
		{
			SetVisible(visible: false);
		}

		private void SetVisible(bool visible)
		{
			if (Visible != visible)
			{
				Visible = visible;
				if (Visible)
				{
					centered = false;
					EnableModalMode();
				}
				else
				{
					DisableModalMode();
				}
			}
		}

		private void DrawWindow(int id)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			DrawTabs();
			GUILayout.Space(8f);
			scroll = GUILayout.BeginScrollView(scroll, false, true, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
			switch (selectedTab)
			{
			case 0:
				DrawMainTab();
				break;
			case 1:
				DrawPlayerTab();
				break;
			case 2:
				DrawEspTab();
				break;
			case 3:
				DrawItemsTab();
				break;
			case 4:
				DrawResourcesTab();
				break;
			case 5:
				DrawChaosTab();
				break;
			case 6:
				DrawPerformanceTab();
				break;
			case 7:
				DrawDebugTab();
				break;
			}
			GUILayout.EndScrollView();
			GUILayout.FlexibleSpace();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("BGMod by Joive", GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Close", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) }))
			{
				SetVisible(visible: false);
			}
			GUILayout.EndHorizontal();
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, 26f));
			GUILayout.EndVertical();
		}

		private void DrawTabs()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			for (int i = 0; i < tabs.Length; i++)
			{
				if (GUILayout.Button(tabs[i], (selectedTab == i) ? GuiStyles.TabActive : GuiStyles.Tab, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
				{
					selectedTab = i;
					scroll = Vector2.zero;
				}
			}
			GUILayout.EndHorizontal();
		}

		private void DrawMainTab()
		{
			GUILayout.Label("BGMod by Joive", GuiStyles.Label, Array.Empty<GUILayoutOption>());
			Toggle(ModConfig.EnableMod, "Enable BGMod");
			Toggle(ModConfig.EnableHUD, "Enable HUD");
			Toggle(ModConfig.EnableESP, "Enable ESP");
			Toggle(ModConfig.EnableGnomeFeatures, "Enable player features");
			Toggle(ModConfig.EnableChaos, "Enable chaos features");
			Toggle(ModConfig.EnablePerformanceMode, "Enable FPS optimizations");
			Toggle(ModConfig.DebugMode, "Show debug info");
			Toggle(ModConfig.UsePauseTimeScale, "Pause game time while menu is open");
			GUILayout.Space(8f);
			GUILayout.Label("Menu key: " + ModConfig.MenuKey.Value + " (F1 also toggles)", GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Save config", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
			{
				ModConfig.Save();
			}
		}

		private void DrawPlayerTab()
		{
			Toggle(ModConfig.EnableGnomeFeatures, "Enable player features");
			Toggle(ModConfig.GodMode, "God mode");
			Toggle(ModConfig.InfiniteStamina, "Infinite stamina");
			Toggle(ModConfig.FlyMode, "Fly");
			Toggle(ModConfig.Noclip, "Noclip");
			Toggle(ModConfig.NoFallDamage, "No fall damage");
			Toggle(ModConfig.AntiKidnap, "Anti kidnap");
			Toggle(ModConfig.LongHands, "Long hands");
			Slider(ModConfig.SpeedMultiplier, "Speed multiplier", 0.25f, 6f);
			Slider(ModConfig.FlySpeed, "Fly speed", 1f, 60f);
			Slider(ModConfig.InteractionDistance, "Interaction distance", 1f, 12f);
			Slider(ModConfig.PlayerScale, "Player scale", 0.2f, 3f);
		}

		private void DrawEspTab()
		{
			Toggle(ModConfig.EnableESP, "Enable ESP");
			Toggle(ModConfig.EnableItemESP, "Enable Item ESP");
			Toggle(ModConfig.EnableHumanESP, "Enable Human ESP");
			Toggle(ModConfig.EnableGnomeESP, "Enable Player ESP");
			Slider(ModConfig.ESPRefreshRate, "ESP refresh", 0.1f, 3f);
			Slider(ModConfig.MaxESPDistance, "Max distance", 10f, 250f);
			IntSlider(ModConfig.MaxESPObjects, "Max objects", 5, 150);
			GUILayout.Label("Cached targets: " + (base.Modules.Get<ESPModule>()?.Targets.Count ?? 0), GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
		}

		private void DrawItemsTab()
		{
			ItemGiverModule itemGiverModule = base.Modules.Get<ItemGiverModule>();
			if (itemGiverModule == null)
			{
				GUILayout.Label("Item module not loaded", GuiStyles.Label, Array.Empty<GUILayoutOption>());
				return;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Inventory Items", (itemMode == 0) ? GuiStyles.TabActive : GuiStyles.Tab, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
			{
				itemMode = 0;
			}
			if (GUILayout.Button("Level / ESP Items", (itemMode == 1) ? GuiStyles.TabActive : GuiStyles.Tab, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(170f) }))
			{
				itemMode = 1;
				if (itemGiverModule.LevelItems.Count == 0)
				{
					itemGiverModule.RefreshLevelItems();
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			if (itemMode == 1)
			{
				DrawLevelItemsTab(itemGiverModule);
			}
			else
			{
				DrawInventoryItemsTab(itemGiverModule);
			}
		}

		private void DrawInventoryItemsTab(ItemGiverModule items)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search", GuiStyles.Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
			string text = GUILayout.TextField(items.SearchTerm ?? "", GuiStyles.TextField, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(260f) });
			if (text != items.SearchTerm)
			{
				items.SearchTerm = text;
				items.UpdateSearch();
			}
			if (GUILayout.Button("Refresh", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				items.RefreshItems();
			}
			GUILayout.EndHorizontal();
			IntSlider(ModConfig.ItemGiveAmount, "Amount", 1, 999);
			GUILayout.Space(6f);
			IReadOnlyList<ItemData> matches = items.Matches;
			int num = Math.Min(matches.Count, 24);
			for (int i = 0; i < num; i++)
			{
				ItemData val = matches[i];
				GUILayout.BeginHorizontal(GuiStyles.Box, Array.Empty<GUILayoutOption>());
				if (GUILayout.Toggle(items.SelectedIndex == i, ((CraftableItemBase)val).Name, GuiStyles.Toggle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(360f) }))
				{
					items.SelectedIndex = i;
				}
				if (GUILayout.Button("Give", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
				{
					items.SelectedIndex = i;
					items.GiveSelected(ModConfig.ItemGiveAmount.Value);
				}
				GUILayout.EndHorizontal();
			}
			DrawQuickItemButtons(items);
			GUILayout.Label(items.LastMessage, GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
		}

		private void DrawLevelItemsTab(ItemGiverModule items)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Refresh level items", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) }))
			{
				items.RefreshLevelItems();
			}
			if (GUILayout.Button("Teleport item to player", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(180f) }))
			{
				items.TeleportSelectedItemToPlayer();
			}
			if (GUILayout.Button("Teleport player to item", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(180f) }))
			{
				items.TeleportPlayerToSelectedItem();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Collect / Pick up", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
			{
				items.CollectSelectedLevelItem();
			}
			if (GUILayout.Button("Spawn copy near player", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) }))
			{
				items.SpawnCopyOfSelectedLevelItem();
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			IReadOnlyList<ItemGiverModule.LevelItemTarget> levelItems = items.LevelItems;
			int num = Math.Min(levelItems.Count, 28);
			for (int i = 0; i < num; i++)
			{
				ItemGiverModule.LevelItemTarget levelItemTarget = levelItems[i];
				GUILayout.BeginHorizontal(GuiStyles.Box, Array.Empty<GUILayoutOption>());
				string text = levelItemTarget.Name + "  [" + levelItemTarget.ComponentName + "]  " + levelItemTarget.Distance.ToString("F1") + "m";
				if (GUILayout.Toggle(items.LevelSelectedIndex == i, text, GuiStyles.Toggle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(480f) }))
				{
					items.LevelSelectedIndex = i;
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.Label(items.LastMessage, GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
		}

		private void DrawQuickItemButtons(ItemGiverModule items)
		{
			GUILayout.Space(8f);
			GUILayout.Label("Quick", GuiStyles.Label, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			string[] array = new string[6] { "gnomium", "metal", "fabric", "ceramics", "plastic", "chemicals" };
			foreach (string text in array)
			{
				if (GUILayout.Button(text, GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(86f) }))
				{
					items.Give(text, ModConfig.ItemGiveAmount.Value);
				}
			}
			GUILayout.EndHorizontal();
		}

		private void DrawResourcesTab()
		{
			ResourcesModule resourcesModule = base.Modules.Get<ResourcesModule>();
			if (resourcesModule == null)
			{
				GUILayout.Label("Resources module not loaded", GuiStyles.Label, Array.Empty<GUILayoutOption>());
				return;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Refresh resources", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
			{
				resourcesModule.Refresh();
			}
			GUILayout.Label(resourcesModule.CurrentValuesText, GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			IntSlider(ModConfig.ResourceGiveAmount, "Amount", 1, 9999);
			string[] array = new string[6] { "ceramics", "metal", "fabric", "plastic", "chemicals", "gnomium" };
			for (int i = 0; i < array.Length; i++)
			{
				GUILayout.BeginHorizontal(GuiStyles.Box, Array.Empty<GUILayoutOption>());
				GUILayout.Label(array[i] + ": " + resourcesModule.GetCount(i), GuiStyles.Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(220f) });
				if (GUILayout.Button("Add", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) }))
				{
					resourcesModule.AddResource(i, ModConfig.ResourceGiveAmount.Value);
				}
				GUILayout.EndHorizontal();
			}
			if (GUILayout.Button("Add all", GuiStyles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }))
			{
				resourcesModule.AddAll(ModConfig.ResourceGiveAmount.Value);
			}
			GUILayout.Label(resourcesModule.LastMessage, GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
		}

		private void DrawChaosTab()
		{
			Toggle(ModConfig.EnableChaos, "Enable chaos features");
			Toggle(ModConfig.PoltergeistMode, "Poltergeist mode");
			GUILayout.Label("G pulls the item you are looking at. Middle mouse blinks to the crosshair.", GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
		}

		private void DrawPerformanceTab()
		{
			Toggle(ModConfig.LowFPSMode, "Low FPS mode");
			Toggle(ModConfig.DisableExpensiveScans, "Disable expensive scans");
			Slider(ModConfig.CacheLifetime, "Cache lifetime", 0.5f, 10f);
			PerformanceModule performanceModule = base.Modules.Get<PerformanceModule>();
			if (performanceModule != null)
			{
				GUILayout.Label("Effective ESP refresh: " + performanceModule.EspRefreshRate.ToString("F2"), GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
				GUILayout.Label("Effective max objects: " + performanceModule.MaxEspObjects, GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			}
		}

		private void DrawDebugTab()
		{
			GUILayout.Label("BGMod by Joive", GuiStyles.Label, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Local player: " + ((Object)(object)GameAccess.LocalPlayer() != (Object)null), GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Time scale: " + Time.timeScale.ToString("F2"), GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
			foreach (IModModule allModule in base.Modules.AllModules)
			{
				GUILayout.Label(allModule.DisplayName + ": " + (allModule.Enabled ? "on" : "off"), GuiStyles.SmallLabel, Array.Empty<GUILayoutOption>());
			}
		}

		private void EnableModalMode()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (!modalActive)
			{
				modalActive = true;
				oldCursorVisible = Cursor.visible;
				oldCursorLock = Cursor.lockState;
				oldTimeScale = Time.timeScale;
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				timeScalePaused = ModConfig.UsePauseTimeScale.Value;
				if (timeScalePaused)
				{
					Time.timeScale = 0f;
				}
				DisablePlayerInput();
			}
		}

		private void DisableModalMode()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (modalActive)
			{
				modalActive = false;
				if (timeScalePaused)
				{
					Time.timeScale = ((oldTimeScale <= 0f) ? 1f : oldTimeScale);
				}
				timeScalePaused = false;
				Cursor.visible = oldCursorVisible;
				Cursor.lockState = oldCursorLock;
				RestorePlayerInput();
			}
		}

		private void KeepModalState()
		{
			Cursor.visible = true;
			Cursor.lockState = (CursorLockMode)0;
			DisablePlayerInput();
			Input.ResetInputAxes();
			if (ModConfig.UsePauseTimeScale.Value)
			{
				if (!timeScalePaused)
				{
					oldTimeScale = Time.timeScale;
					timeScalePaused = true;
				}
				if (Time.timeScale != 0f)
				{
					Time.timeScale = 0f;
				}
			}
			else if (timeScalePaused)
			{
				Time.timeScale = ((oldTimeScale <= 0f) ? 1f : oldTimeScale);
				timeScalePaused = false;
			}
		}

		private void DisablePlayerInput()
		{
			PlayerNetworking val = GameAccess.LocalPlayer();
			if (!((Object)(object)val == (Object)null))
			{
				SaveDisable((Behaviour)(object)val.Controller);
				SaveDisable((Behaviour)(object)val.Actor);
				SaveDisable((Behaviour)(object)val.StateController);
				DisableInputAsset(val.Controller);
			}
		}

		private void RestorePlayerInput()
		{
			foreach (BehaviourState disabledBehaviour in disabledBehaviours)
			{
				if ((Object)(object)disabledBehaviour.Behaviour != (Object)null)
				{
					disabledBehaviour.Behaviour.enabled = disabledBehaviour.Enabled;
				}
			}
			disabledBehaviours.Clear();
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val != (Object)null)
			{
				EnableInputAsset(val.Controller);
			}
		}

		private void SaveDisable(Behaviour behaviour)
		{
			if ((Object)(object)behaviour == (Object)null)
			{
				return;
			}
			foreach (BehaviourState disabledBehaviour in disabledBehaviours)
			{
				if ((Object)(object)disabledBehaviour.Behaviour == (Object)(object)behaviour)
				{
					behaviour.enabled = false;
					return;
				}
			}
			disabledBehaviours.Add(new BehaviourState
			{
				Behaviour = behaviour,
				Enabled = behaviour.enabled
			});
			behaviour.enabled = false;
		}

		private static void DisableInputAsset(PlayerController controller)
		{
			object inputAsset = GetInputAsset(controller);
			inputAsset?.GetType().GetMethod("Disable", BindingFlags.Instance | BindingFlags.Public)?.Invoke(inputAsset, null);
		}

		private static void EnableInputAsset(PlayerController controller)
		{
			object inputAsset = GetInputAsset(controller);
			inputAsset?.GetType().GetMethod("Enable", BindingFlags.Instance | BindingFlags.Public)?.Invoke(inputAsset, null);
		}

		private static object GetInputAsset(PlayerController controller)
		{
			if ((Object)(object)controller == (Object)null)
			{
				return null;
			}
			FieldInfo field = typeof(PlayerController).GetField("inputActionsAsset", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field != null))
			{
				return null;
			}
			return field.GetValue(controller);
		}

		private void EnsureWindowRect()
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Min(760f, Mathf.Max(460f, (float)Screen.width - 32f));
			float num2 = Mathf.Min(520f, Mathf.Max(360f, (float)Screen.height - 32f));
			if (!centered || ((Rect)(ref windowRect)).width <= 0f || ((Rect)(ref windowRect)).height <= 0f)
			{
				windowRect = new Rect(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
				centered = true;
			}
			else
			{
				((Rect)(ref windowRect)).width = num;
				((Rect)(ref windowRect)).height = num2;
				windowRect = ClampToScreen(windowRect);
			}
		}

		private static Rect ClampToScreen(Rect rect)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			((Rect)(ref rect)).x = Mathf.Clamp(((Rect)(ref rect)).x, 8f, Mathf.Max(8f, (float)Screen.width - ((Rect)(ref rect)).width - 8f));
			((Rect)(ref rect)).y = Mathf.Clamp(((Rect)(ref rect)).y, 8f, Mathf.Max(8f, (float)Screen.height - ((Rect)(ref rect)).height - 8f));
			return rect;
		}

		private static void Toggle(MelonPreferences_Entry<bool> entry, string label)
		{
			bool flag = GUILayout.Toggle(entry.Value, label, GuiStyles.Toggle, Array.Empty<GUILayoutOption>());
			if (flag != entry.Value)
			{
				entry.Value = flag;
			}
		}

		private static void Slider(MelonPreferences_Entry<float> entry, string label, float min, float max)
		{
			GUILayout.Label(label + ": " + entry.Value.ToString("F2"), GuiStyles.Label, Array.Empty<GUILayoutOption>());
			entry.Value = GUILayout.HorizontalSlider(entry.Value, min, max, Array.Empty<GUILayoutOption>());
		}

		private static void IntSlider(MelonPreferences_Entry<int> entry, string label, int min, int max)
		{
			GUILayout.Label(label + ": " + entry.Value, GuiStyles.Label, Array.Empty<GUILayoutOption>());
			entry.Value = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)entry.Value, (float)min, (float)max, Array.Empty<GUILayoutOption>()));
		}

		private static KeyCode ParseKey(string value, KeyCode fallback)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return (KeyCode)Enum.Parse(typeof(KeyCode), value, ignoreCase: true);
			}
			catch
			{
				return fallback;
			}
		}
	}
}
namespace BGMod.Performance
{
	public class PerformanceModule : ModuleBase
	{
		public override string Id => "performance";

		public override string DisplayName => "Performance";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnablePerformanceMode.Value;
			}
			set
			{
				ModConfig.EnablePerformanceMode.Value = value;
			}
		}

		public float EspRefreshRate
		{
			get
			{
				if (!ModConfig.LowFPSMode.Value)
				{
					return Math.Max(ModConfig.ESPRefreshRate.Value, 0.1f);
				}
				return Math.Max(ModConfig.ESPRefreshRate.Value, 1.5f);
			}
		}

		public float HudRefreshRate
		{
			get
			{
				if (!ModConfig.LowFPSMode.Value)
				{
					return Math.Max(ModConfig.HUDRefreshRate.Value, 0.05f);
				}
				return Math.Max(ModConfig.HUDRefreshRate.Value, 0.5f);
			}
		}

		public int MaxEspObjects
		{
			get
			{
				if (!ModConfig.LowFPSMode.Value)
				{
					return Math.Max(ModConfig.MaxESPObjects.Value, 1);
				}
				return Math.Min(ModConfig.MaxESPObjects.Value, 25);
			}
		}

		public float MaxEspDistance
		{
			get
			{
				if (!ModConfig.LowFPSMode.Value)
				{
					return Math.Max(ModConfig.MaxESPDistance.Value, 5f);
				}
				return Math.Min(ModConfig.MaxESPDistance.Value, 45f);
			}
		}

		public bool ExpensiveScansAllowed
		{
			get
			{
				if (!ModConfig.DisableExpensiveScans.Value)
				{
					return !ModConfig.LowFPSMode.Value;
				}
				return false;
			}
		}
	}
}
namespace BGMod.Patches
{
	public static class PatchManager
	{
		public static void Apply(Harmony harmony)
		{
			ModLog.Msg("No Harmony patches are required for this build.");
		}

		private static void TryPatch(Harmony harmony, string typeName, string methodName, string prefix, string postfix)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Type type = AccessTools.TypeByName(typeName);
				if (type == null)
				{
					ModLog.Warning("Patch skipped, type unavailable: " + typeName);
					return;
				}
				MethodInfo methodInfo = AccessTools.Method(type, methodName, (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					ModLog.Warning("Patch skipped, method unavailable: " + typeName + "." + methodName);
					return;
				}
				HarmonyMethod val = ((prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(PatchManager).GetMethod(prefix)));
				HarmonyMethod val2 = ((postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(PatchManager).GetMethod(postfix)));
				harmony.Patch((MethodBase)methodInfo, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ModLog.Msg("Patch applied: " + typeName + "." + methodName);
			}
			catch (Exception ex)
			{
				ModLog.Warning("Patch failed for " + typeName + "." + methodName + ": " + ex.Message);
			}
		}
	}
}
namespace BGMod.HUD
{
	public class HUDModule : ModuleBase
	{
		private float deltaTime;

		private float nextRefresh;

		private string activeModulesText = "";

		private string warningsText = "";

		private GUIStyle hudStyle;

		private GUIStyle fpsStyle;

		public override string Id => "hud";

		public override string DisplayName => "HUD";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnableHUD.Value;
			}
			set
			{
				ModConfig.EnableHUD.Value = value;
			}
		}

		public override void OnUpdate()
		{
			deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
			float num = base.Modules.Get<PerformanceModule>()?.HudRefreshRate ?? ModConfig.HUDRefreshRate.Value;
			if (Time.unscaledTime >= nextRefresh)
			{
				nextRefresh = Time.unscaledTime + num;
				activeModulesText = string.Join(", ", base.Modules.EnabledModuleNames.Where((string n) => n != "Menu").Take(8).ToArray());
				BuildWarnings();
			}
		}

		public override void OnGUI()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled)
			{
				InitStyles();
				float num = Mathf.Clamp(ModConfig.HUDScale.Value, 0.6f, 2f);
				float num2 = Mathf.Clamp(ModConfig.HUDPositionX.Value, 0f, (float)Screen.width - 80f);
				float num3 = Mathf.Clamp(ModConfig.HUDPositionY.Value, 0f, (float)Screen.height - 40f);
				int fontSize = Mathf.RoundToInt(12f * num);
				hudStyle.fontSize = fontSize;
				fpsStyle.fontSize = Mathf.RoundToInt(13f * num);
				GUILayout.BeginArea(new Rect(num2, num3, 380f * num, 160f * num), GUIContent.none, GUIStyle.none);
				if (ModConfig.ShowFPS.Value)
				{
					GUILayout.Label("FPS " + ((deltaTime > 0.0001f) ? (1f / deltaTime) : 0f).ToString("F0"), fpsStyle, Array.Empty<GUILayoutOption>());
				}
				if (ModConfig.ShowActiveModules.Value && !string.IsNullOrEmpty(activeModulesText))
				{
					GUILayout.Label("Active: " + activeModulesText, hudStyle, Array.Empty<GUILayoutOption>());
				}
				if (ModConfig.ShowWarnings.Value && !string.IsNullOrEmpty(warningsText))
				{
					GUILayout.Label(warningsText, hudStyle, Array.Empty<GUILayoutOption>());
				}
				if (ModConfig.DebugMode.Value)
				{
					PlayerNetworking val = GameAccess.LocalPlayer();
					string text = ((Object)(object)val != (Object)null).ToString();
					Scene activeScene = SceneManager.GetActiveScene();
					GUILayout.Label("Debug: local=" + text + " scene=" + ((Scene)(ref activeScene)).name, hudStyle, Array.Empty<GUILayoutOption>());
				}
				GUILayout.EndArea();
			}
		}

		private void InitStyles()
		{
			//IL_0014: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_008c: Expected O, but got Unknown
			if (hudStyle == null)
			{
				GUIStyle val = new GUIStyle(GUI.skin.label);
				val.normal.textColor = new Color(0.92f, 0.94f, 0.9f, 0.92f);
				val.richText = true;
				val.wordWrap = true;
				hudStyle = val;
				GUIStyle val2 = new GUIStyle(hudStyle)
				{
					fontStyle = (FontStyle)1
				};
				val2.normal.textColor = new Color(0.45f, 1f, 0.72f, 0.96f);
				fpsStyle = val2;
			}
		}

		private void BuildWarnings()
		{
			List<string> list = new List<string>();
			if ((Object)(object)Camera.main == (Object)null)
			{
				list.Add("camera unavailable");
			}
			if ((Object)(object)GameAccess.LocalPlayer() == (Object)null)
			{
				list.Add("local player not found");
			}
			warningsText = ((list.Count == 0) ? "" : ("Warn: " + string.Join(", ", list.ToArray())));
		}
	}
}
namespace BGMod.Features
{
	public class ChaosModule : ModuleBase
	{
		private object lastPossessTarget;

		public override string Id => "chaos";

		public override string DisplayName => "Chaos";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnableChaos.Value;
			}
			set
			{
				ModConfig.EnableChaos.Value = value;
			}
		}

		public override void OnUpdate()
		{
			if (!Enabled)
			{
				return;
			}
			PlayerNetworking local = GameAccess.LocalPlayer();
			if ((Object)(object)local == (Object)null)
			{
				return;
			}
			Guard("update", delegate
			{
				if (ModConfig.PoltergeistMode.Value)
				{
					RunPoltergeist(local);
				}
				if (Input.GetKeyDown((KeyCode)103))
				{
					SnatchLookedAtItem(local);
				}
				if (Input.GetMouseButtonDown(2))
				{
					BlinkToCrosshair(local);
				}
			});
		}

		private void RunPoltergeist(PlayerNetworking local)
		{
			Component val = ((Component)local).GetComponent("PlayerGhosty") ?? ((Component)local).GetComponentInChildren(TypeByName("PlayerGhosty"), true);
			if (!((Object)(object)val == (Object)null))
			{
				ReflectionUtils.TrySetMemberValue(val, "possessCooldown", 0f);
				object memberValue = ReflectionUtils.GetMemberValue(val, "CurrentPossessTarget");
				if (memberValue != null && memberValue != lastPossessTarget)
				{
					lastPossessTarget = memberValue;
					MelonCoroutines.Start(ExtendPossession(memberValue));
				}
			}
		}

		private IEnumerator ExtendPossession(object target)
		{
			for (int i = 0; i < 15; i++)
			{
				if (target == null)
				{
					break;
				}
				ReflectionUtils.TrySetMemberValue(target, "maxPossessTime", 99999f);
				yield return (object)new WaitForSeconds(0.1f);
			}
		}

		private void BlinkToCrosshair(PlayerNetworking local)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!((Object)(object)Camera.main == (Object)null) && Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f)), ref val, 250f))
			{
				Vector3 val2 = ((RaycastHit)(ref val)).point + Vector3.up * 1.15f;
				if ((Object)(object)local != (Object)null)
				{
					((GameEntityBase)local).Teleport(val2);
				}
				else
				{
					((Component)local).transform.position = val2;
				}
			}
		}

		private void SnatchLookedAtItem(PlayerNetworking local)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_008b: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if ((Object)(object)Camera.main == (Object)null || !Physics.Raycast(Camera.main.ScreenPointToRay(new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f)), ref val, 120f))
			{
				return;
			}
			StealableObject componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<StealableObject>();
			if (!((Object)(object)componentInParent == (Object)null))
			{
				((Component)componentInParent).transform.position = ((Component)local).transform.position + ((Component)local).transform.forward * 1.2f + Vector3.up * 0.4f;
				Rigidbody component = ((Component)componentInParent).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.linearVelocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
				}
			}
		}

		private static Type TypeByName(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type type = assemblies[i].GetType(name);
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}
	}
	public class GnomeModule : ModuleBase
	{
		private struct RigidbodyState
		{
			public Rigidbody Rigidbody;

			public bool UseGravity;

			public Vector3 LinearVelocity;

			public Vector3 AngularVelocity;
		}

		private struct ColliderState
		{
			public Collider Collider;

			public bool Enabled;
		}

		private struct BehaviourState
		{
			public Behaviour Behaviour;

			public bool Enabled;
		}

		private float originalBaseSpeed = -1f;

		private float originalBoostSpeed = -1f;

		private bool flyNoclipActive;

		private bool lastFly;

		private bool lastNoclip;

		private bool repairedVisionLayers;

		private readonly List<RigidbodyState> savedRigidbodies = new List<RigidbodyState>();

		private readonly List<ColliderState> savedColliders = new List<ColliderState>();

		private readonly List<ColliderState> savedCharacterControllers = new List<ColliderState>();

		private readonly List<BehaviourState> savedBehaviours = new List<BehaviourState>();

		public override string Id => "gnome";

		public override string DisplayName => "Player";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnableGnomeFeatures.Value;
			}
			set
			{
				ModConfig.EnableGnomeFeatures.Value = value;
			}
		}

		public override void OnUpdate()
		{
			PlayerNetworking local = GameAccess.LocalPlayer();
			if ((Object)(object)local == (Object)null)
			{
				return;
			}
			if (!Enabled)
			{
				RestoreSpeed(local);
				SetFlyNoclipState(local, active: false);
				ReflectionUtils.TrySetMemberValue(local, "godMode", false);
				lastFly = false;
				lastNoclip = false;
			}
			else
			{
				Guard("update", delegate
				{
					UpdateLocalFeatures(local);
				});
			}
		}

		public override void OnApplicationQuit()
		{
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val != (Object)null)
			{
				RestoreSpeed(val);
				SetFlyNoclipState(val, active: false);
			}
		}

		private void UpdateLocalFeatures(PlayerNetworking local)
		{
			UpdateGod(local);
			UpdateSpeed(local);
			UpdateFlyNoclipToggles(local);
			if (ModConfig.FlyMode.Value || ModConfig.Noclip.Value)
			{
				UpdateFly(local);
			}
			if (ModConfig.AntiKidnap.Value)
			{
				TryReleaseFromKidnappers(local);
			}
			if (ModConfig.InfiniteStamina.Value)
			{
				TryRestoreStamina(local);
			}
			if (ModConfig.LongHands.Value)
			{
				TryExtendHands(local);
			}
			ApplyScale(local);
		}

		private void UpdateGod(PlayerNetworking local)
		{
			if (ModConfig.GodMode.Value && (Object)(object)local.Health != (Object)null)
			{
				((HealthBase)local.Health).Respawn();
				ReflectionUtils.TrySetMemberValue(local, "godMode", true);
			}
			else
			{
				ReflectionUtils.TrySetMemberValue(local, "godMode", false);
			}
		}

		private void UpdateSpeed(PlayerNetworking local)
		{
			NormalMovement componentInChildren = ((Component)local).GetComponentInChildren<NormalMovement>(true);
			if (!((Object)(object)componentInChildren == (Object)null))
			{
				if (originalBaseSpeed < 0f)
				{
					originalBaseSpeed = componentInChildren.planarMovementParameters.baseSpeedLimit;
					originalBoostSpeed = componentInChildren.planarMovementParameters.boostSpeedLimit;
				}
				float num = Mathf.Clamp(ModConfig.SpeedMultiplier.Value, 0.25f, 6f);
				componentInChildren.planarMovementParameters.baseSpeedLimit = originalBaseSpeed * num;
				componentInChildren.planarMovementParameters.boostSpeedLimit = originalBoostSpeed * num;
			}
		}

		private void RestoreSpeed(PlayerNetworking local)
		{
			if (!(originalBaseSpeed < 0f))
			{
				NormalMovement componentInChildren = ((Component)local).GetComponentInChildren<NormalMovement>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.planarMovementParameters.baseSpeedLimit = originalBaseSpeed;
					componentInChildren.planarMovementParameters.boostSpeedLimit = originalBoostSpeed;
				}
			}
		}

		private void UpdateFlyNoclipToggles(PlayerNetworking local)
		{
			bool value = ModConfig.FlyMode.Value;
			bool value2 = ModConfig.Noclip.Value;
			if (value != lastFly || value2 != lastNoclip)
			{
				lastFly = value;
				lastNoclip = value2;
				SetFlyNoclipState(local, value || value2);
				SetNoclipColliders(local, value2);
				if (!value2)
				{
					RepairVisionLayers(local);
				}
			}
		}

		private void SetFlyNoclipState(PlayerNetworking local, bool active)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			if (flyNoclipActive == active)
			{
				return;
			}
			flyNoclipActive = active;
			if (active)
			{
				local.ForceNotRagdoll();
				SaveDisable((Behaviour)(object)local.Actor);
				SaveDisable((Behaviour)(object)local.StateController);
				CharacterController[] componentsInChildren = ((Component)local).GetComponentsInChildren<CharacterController>(true);
				foreach (CharacterController controller in componentsInChildren)
				{
					SaveDisableCharacterController(controller);
				}
				savedRigidbodies.Clear();
				Rigidbody[] componentsInChildren2 = ((Component)local).GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody val in componentsInChildren2)
				{
					if (!((Object)(object)val == (Object)null))
					{
						savedRigidbodies.Add(new RigidbodyState
						{
							Rigidbody = val,
							UseGravity = val.useGravity,
							LinearVelocity = val.linearVelocity,
							AngularVelocity = val.angularVelocity
						});
						val.useGravity = false;
						val.linearVelocity = Vector3.zero;
						val.angularVelocity = Vector3.zero;
					}
				}
			}
			else
			{
				RestoreNoclipColliders();
				RestoreCharacterControllers();
				RestoreRigidbodies();
				RestoreBehaviours();
				RepairVisionLayers(local);
			}
		}

		private void SetNoclipColliders(PlayerNetworking local, bool enabled)
		{
			if (enabled)
			{
				if (savedColliders.Count > 0)
				{
					return;
				}
				Collider[] componentsInChildren = ((Component)local).GetComponentsInChildren<Collider>(true);
				foreach (Collider val in componentsInChildren)
				{
					if (!((Object)(object)val == (Object)null))
					{
						savedColliders.Add(new ColliderState
						{
							Collider = val,
							Enabled = val.enabled
						});
						val.enabled = false;
					}
				}
			}
			else
			{
				RestoreNoclipColliders();
			}
		}

		private void RestoreNoclipColliders()
		{
			foreach (ColliderState savedCollider in savedColliders)
			{
				if ((Object)(object)savedCollider.Collider != (Object)null)
				{
					savedCollider.Collider.enabled = savedCollider.Enabled;
				}
			}
			savedColliders.Clear();
		}

		private void RestoreCharacterControllers()
		{
			foreach (ColliderState savedCharacterController in savedCharacterControllers)
			{
				if ((Object)(object)savedCharacterController.Collider != (Object)null)
				{
					savedCharacterController.Collider.enabled = savedCharacterController.Enabled;
				}
			}
			savedCharacterControllers.Clear();
		}

		private void RestoreRigidbodies()
		{
			//IL_003c: 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)
			foreach (RigidbodyState savedRigidbody in savedRigidbodies)
			{
				if (!((Object)(object)savedRigidbody.Rigidbody == (Object)null))
				{
					savedRigidbody.Rigidbody.useGravity = savedRigidbody.UseGravity;
					savedRigidbody.Rigidbody.linearVelocity = savedRigidbody.LinearVelocity;
					savedRigidbody.Rigidbody.angularVelocity = savedRigidbody.AngularVelocity;
				}
			}
			savedRigidbodies.Clear();
		}

		private void RestoreBehaviours()
		{
			foreach (BehaviourState savedBehaviour in savedBehaviours)
			{
				if ((Object)(object)savedBehaviour.Behaviour != (Object)null)
				{
					savedBehaviour.Behaviour.enabled = savedBehaviour.Enabled;
				}
			}
			savedBehaviours.Clear();
		}

		private void SaveDisable(Behaviour behaviour)
		{
			if ((Object)(object)behaviour == (Object)null)
			{
				return;
			}
			foreach (BehaviourState savedBehaviour in savedBehaviours)
			{
				if ((Object)(object)savedBehaviour.Behaviour == (Object)(object)behaviour)
				{
					return;
				}
			}
			savedBehaviours.Add(new BehaviourState
			{
				Behaviour = behaviour,
				Enabled = behaviour.enabled
			});
			behaviour.enabled = false;
		}

		private void SaveDisableCharacterController(CharacterController controller)
		{
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			foreach (ColliderState savedCharacterController in savedCharacterControllers)
			{
				if ((Object)(object)savedCharacterController.Collider == (Object)(object)controller)
				{
					return;
				}
			}
			savedCharacterControllers.Add(new ColliderState
			{
				Collider = (Collider)(object)controller,
				Enabled = ((Collider)controller).enabled
			});
			((Collider)controller).enabled = false;
		}

		private void UpdateFly(PlayerNetworking local)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Vector3 val = Vector3.zero;
				if (Input.GetKey((KeyCode)119))
				{
					val += ((Component)main).transform.forward;
				}
				if (Input.GetKey((KeyCode)115))
				{
					val -= ((Component)main).transform.forward;
				}
				if (Input.GetKey((KeyCode)97))
				{
					val -= ((Component)main).transform.right;
				}
				if (Input.GetKey((KeyCode)100))
				{
					val += ((Component)main).transform.right;
				}
				if (Input.GetKey((KeyCode)32))
				{
					val += Vector3.up;
				}
				if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305) || Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
				{
					val += Vector3.down;
				}
				local.ForceNotRagdoll();
				Rigidbody[] componentsInChildren = ((Component)local).GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody obj in componentsInChildren)
				{
					obj.linearVelocity = Vector3.zero;
					obj.angularVelocity = Vector3.zero;
				}
				if (!(val == Vector3.zero))
				{
					float num = Mathf.Clamp(ModConfig.FlySpeed.Value, 1f, 60f);
					Vector3 val2 = Vector3.ClampMagnitude(((Vector3)(ref val)).normalized * num * Time.unscaledDeltaTime, 2.5f);
					Transform transform = ((Component)local).transform;
					transform.position += val2;
				}
			}
		}

		private void RepairVisionLayers(PlayerNetworking local)
		{
			int num = LayerMask.NameToLayer("Ignore Raycast");
			if (num < 0)
			{
				return;
			}
			bool flag = SetDefaultIfIgnored(((Component)local).gameObject, num);
			Collider[] componentsInChildren = ((Component)local).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					flag |= SetDefaultIfIgnored(((Component)val).gameObject, num);
				}
			}
			if (flag && !repairedVisionLayers)
			{
				repairedVisionLayers = true;
				ModLog.Msg("Player layers restored from Ignore Raycast so AI can see the player again.");
			}
		}

		private static bool SetDefaultIfIgnored(GameObject go, int ignoreRaycast)
		{
			if ((Object)(object)go == (Object)null || go.layer != ignoreRaycast)
			{
				return false;
			}
			go.layer = 0;
			return true;
		}

		private void TryReleaseFromKidnappers(PlayerNetworking local)
		{
			TryApplyAntiKidnapEffect(local);
			HumanAILink[] array = Object.FindObjectsByType<HumanAILink>((FindObjectsSortMode)0);
			foreach (HumanAILink val in array)
			{
				if ((Object)(object)val != (Object)null && ReflectionUtils.GetMemberValue(val, "PlayerInHand") == local)
				{
					val.ReleasePlayer();
				}
			}
			PlayerKidnapper[] array2 = Object.FindObjectsByType<PlayerKidnapper>((FindObjectsSortMode)0);
			foreach (PlayerKidnapper val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && (object)val2.CurrentlyHeld == local)
				{
					val2.CurrentlyHeld = null;
				}
			}
		}

		private void TryRestoreStamina(PlayerNetworking local)
		{
			CharacterActor val = local.Actor ?? ((Component)local).GetComponentInChildren<CharacterActor>(true);
			if (!((Object)(object)val == (Object)null))
			{
				FieldInfo field = typeof(CharacterActor).GetField("currentStamina", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					field.SetValue(val, val.maxStamina);
				}
			}
		}

		private void TryApplyAntiKidnapEffect(PlayerNetworking local)
		{
			MethodInfo method = typeof(GameEntityBase).GetMethod("ApplyEffect", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(method == null))
			{
				ParameterInfo[] parameters = method.GetParameters();
				if (parameters.Length >= 2 && parameters[0].ParameterType.IsEnum)
				{
					object obj = Enum.ToObject(parameters[0].ParameterType, 3);
					method.Invoke(local, new object[2] { obj, 0f });
				}
			}
		}

		private void TryExtendHands(PlayerNetworking local)
		{
			PlayerHandController val = local.HandController ?? ((Component)local).GetComponentInChildren<PlayerHandController>(true);
			if (!((Object)(object)val == (Object)null))
			{
				BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
				float num = Mathf.Clamp(ModConfig.InteractionDistance.Value, 1f, 999f);
				SetField(val, "maxHandStretchDistance", num * 400f, flags);
				SetField(val, "handBreakDistance", num * 4000f, flags);
				SetField(val, "handReachDistance", num, flags);
				SetField(val, "handStretchSpeed", 1f, flags);
			}
		}

		private void ApplyScale(PlayerNetworking local)
		{
			//IL_0020: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp(ModConfig.PlayerScale.Value, 0.2f, 3f);
			if (Math.Abs(((Component)local).transform.localScale.x - num) > 0.01f)
			{
				((Component)local).transform.localScale = Vector3.one * num;
			}
		}

		private static void SetField(object target, string name, object value, BindingFlags flags)
		{
			FieldInfo field = target.GetType().GetField(name, flags);
			if (field != null)
			{
				field.SetValue(target, value);
			}
		}
	}
	public class ItemGiverModule : ModuleBase
	{
		public class LevelItemTarget
		{
			public string Name;

			public string ComponentName;

			public GameObject GameObject;

			public ItemInstance ItemInstance;

			public StealableObject StealableObject;

			public Vector3 Position;

			public float Distance;
		}

		private AllItems cachedAllItems;

		private readonly List<ItemData> allItems = new List<ItemData>();

		private readonly List<ItemData> matches = new List<ItemData>();

		private readonly List<LevelItemTarget> levelItems = new List<LevelItemTarget>();

		private string lastSearch = "";

		public string SearchTerm = "";

		public int SelectedIndex;

		public int LevelSelectedIndex;

		public string LastMessage = "";

		public override string Id => "items";

		public override string DisplayName => "Items";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnableMod.Value;
			}
			set
			{
			}
		}

		public IReadOnlyList<ItemData> Matches => matches;

		public IReadOnlyList<LevelItemTarget> LevelItems => levelItems;

		public void RefreshItems()
		{
			cachedAllItems = FindAllItems();
			allItems.Clear();
			matches.Clear();
			if ((Object)(object)cachedAllItems == (Object)null || cachedAllItems.items == null)
			{
				LastMessage = "AllItems not found";
				ModLog.Warning("Item Giver: AllItems not found.");
				return;
			}
			allItems.AddRange(from i in cachedAllItems.items
				where (Object)(object)i != (Object)null
				orderby ((CraftableItemBase)i).Name
				select i);
			lastSearch = null;
			UpdateSearch();
			LastMessage = "Loaded items: " + allItems.Count;
		}

		public void UpdateSearch()
		{
			string search = SearchTerm ?? "";
			if (search == lastSearch && matches.Count > 0)
			{
				return;
			}
			if (allItems.Count == 0)
			{
				RefreshItems();
				return;
			}
			lastSearch = search;
			matches.Clear();
			IEnumerable<ItemData> source = allItems;
			if (!string.IsNullOrWhiteSpace(search))
			{
				source = source.Where((ItemData i) => ((CraftableItemBase)i).Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0);
			}
			matches.AddRange(source.Take(80));
			SelectedIndex = Mathf.Clamp(SelectedIndex, 0, Math.Max(matches.Count - 1, 0));
		}

		public bool GiveSelected(int amount)
		{
			UpdateSearch();
			if (matches.Count == 0)
			{
				LastMessage = "No item selected";
				return false;
			}
			return Give(((CraftableItemBase)matches[SelectedIndex]).Name, amount);
		}

		public bool Give(string itemName, int amount)
		{
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val == (Object)null || (Object)(object)val.Inventory == (Object)null)
			{
				LastMessage = "Player inventory not found";
				ModLog.Warning("Item Giver: player inventory not found.");
				return false;
			}
			int num = Mathf.Clamp(amount, 1, 999);
			try
			{
				bool flag = ((InventoryBase)val.Inventory).TryAddItem(itemName, num);
				LastMessage = (flag ? ("Gave " + itemName + " x" + num) : ("Could not give " + itemName));
				if (!flag)
				{
					ModLog.Warning("Item Giver failed for item: " + itemName);
				}
				return flag;
			}
			catch (Exception ex)
			{
				LastMessage = "Give failed: " + ex.Message;
				ModLog.Warning("Item Giver exception: " + ex.Message);
				return false;
			}
		}

		public void RefreshLevelItems()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			PlayerNetworking val = GameAccess.LocalPlayer();
			Vector3 origin = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : Vector3.zero);
			levelItems.Clear();
			HashSet<GameObject> hashSet = new HashSet<GameObject>();
			ItemInstance[] array = Object.FindObjectsByType<ItemInstance>((FindObjectsSortMode)0);
			foreach (ItemInstance val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)((Component)val2).gameObject == (Object)null) && hashSet.Add(((Component)val2).gameObject))
				{
					levelItems.Add(MakeTarget(((Component)val2).gameObject, val2, null, origin));
				}
			}
			StealableObject[] array2 = Object.FindObjectsByType<StealableObject>((FindObjectsSortMode)0);
			foreach (StealableObject val3 in array2)
			{
				if (!((Object)(object)val3 == (Object)null) && !((Object)(object)((Component)val3).gameObject == (Object)null) && hashSet.Add(((Component)val3).gameObject))
				{
					levelItems.Add(MakeTarget(((Component)val3).gameObject, null, val3, origin));
				}
			}
			levelItems.Sort((LevelItemTarget a, LevelItemTarget b) => a.Distance.CompareTo(b.Distance));
			if (levelItems.Count > 120)
			{
				levelItems.RemoveRange(120, levelItems.Count - 120);
			}
			LevelSelectedIndex = Mathf.Clamp(LevelSelectedIndex, 0, Math.Max(levelItems.Count - 1, 0));
			LastMessage = "Level items: " + levelItems.Count;
			ModLog.Msg("Level/ESP item scan found " + levelItems.Count + " objects from ItemInstance/StealableObject.");
		}

		public bool TeleportSelectedItemToPlayer()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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)
			LevelItemTarget levelItemTarget = SelectedLevelTarget();
			if (levelItemTarget == null)
			{
				LastMessage = "No level item selected";
				return false;
			}
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val == (Object)null)
			{
				LastMessage = "Player not found";
				return false;
			}
			Vector3 position = ((Component)val).transform.position + ((Component)val).transform.forward * 1.2f + Vector3.up * 0.4f;
			MoveObject(levelItemTarget.GameObject, position);
			LastMessage = "Teleported " + levelItemTarget.Name + " to player (" + levelItemTarget.ComponentName + ")";
			ModLog.Msg("Level/ESP item teleport to player: " + levelItemTarget.Name + " via " + levelItemTarget.ComponentName);
			return true;
		}

		public bool TeleportPlayerToSelectedItem()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			LevelItemTarget levelItemTarget = SelectedLevelTarget();
			if (levelItemTarget == null)
			{
				LastMessage = "No level item selected";
				return false;
			}
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val == (Object)null)
			{
				LastMessage = "Player not found";
				return false;
			}
			Vector3 val2 = levelItemTarget.Position + Vector3.up * 1.15f;
			GameEntityBase val3 = (GameEntityBase)(object)val;
			if ((Object)(object)val3 != (Object)null)
			{
				val3.Teleport(val2);
			}
			else
			{
				((Component)val).transform.position = val2;
			}
			LastMessage = "Teleported player to " + levelItemTarget.Name;
			return true;
		}

		public bool CollectSelectedLevelItem()
		{
			LevelItemTarget levelItemTarget = SelectedLevelTarget();
			if (levelItemTarget == null)
			{
				LastMessage = "No level item selected";
				return false;
			}
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val == (Object)null || (Object)(object)val.Inventory == (Object)null)
			{
				LastMessage = "Player inventory not found";
				return false;
			}
			ItemInstance val2 = levelItemTarget.ItemInstance ?? levelItemTarget.GameObject.GetComponentInChildren<ItemInstance>(true) ?? levelItemTarget.GameObject.GetComponentInParent<ItemInstance>();
			if ((Object)(object)val2 != (Object)null)
			{
				try
				{
					bool flag = ((InventoryBase)val.Inventory).TryAddItem(val2);
					LastMessage = (flag ? ("Collected " + levelItemTarget.Name) : ("Could not collect " + levelItemTarget.Name));
					ModLog.Msg("Level/ESP item collect via ItemInstance: " + levelItemTarget.Name);
					return flag;
				}
				catch (Exception ex)
				{
					LastMessage = "Collect failed: " + ex.Message;
					ModLog.Warning("Level/ESP item collect failed: " + ex.Message);
					return false;
				}
			}
			Component[] components = levelItemTarget.GameObject.GetComponents<Component>();
			foreach (Component val3 in components)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					MethodInfo method = ((object)val3).GetType().GetMethod("Interact", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(PlayerNetworking) }, null);
					if (!(method == null))
					{
						method.Invoke(val3, new object[1] { val });
						LastMessage = "Used pickup method on " + levelItemTarget.Name;
						ModLog.Msg("Level/ESP item collect via " + ((object)val3).GetType().Name + ".Interact");
						return true;
					}
				}
			}
			TeleportSelectedItemToPlayer();
			LastMessage = "No safe pickup method; item moved to player";
			return false;
		}

		public bool SpawnCopyOfSelectedLevelItem()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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)
			LevelItemTarget levelItemTarget = SelectedLevelTarget();
			if (levelItemTarget == null)
			{
				LastMessage = "No level item selected";
				return false;
			}
			ItemInstance itemInstance = levelItemTarget.ItemInstance;
			string text = (((Object)(object)itemInstance != (Object)null) ? ResolveItemName(itemInstance) : null);
			if ((Object)(object)itemInstance == (Object)null || string.IsNullOrEmpty(text))
			{
				TeleportSelectedItemToPlayer();
				LastMessage = "Spawn copy is unsafe here; original item moved to player";
				return false;
			}
			AllItems val = cachedAllItems ?? FindAllItems();
			PlayerNetworking val2 = GameAccess.LocalPlayer();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				LastMessage = "Spawn source not found; try Refresh";
				return false;
			}
			try
			{
				Vector3 val3 = ((Component)val2).transform.position + ((Component)val2).transform.forward * 1.4f + Vector3.up * 0.4f;
				ItemInstance val4 = val.SpawnItemInstance(text, val3);
				if ((Object)(object)val4 != (Object)null)
				{
					val4.SetInstanceData(itemInstance.InstanceData);
				}
				LastMessage = "Spawned copy of " + text + " from ItemInstance";
				ModLog.Msg("Level/ESP item copy spawned from ItemInstance prefab: " + text);
				return true;
			}
			catch (Exception ex)
			{
				LastMessage = "Spawn failed, moved original: " + ex.Message;
				ModLog.Warning("Level/ESP item copy failed: " + ex.Message);
				TeleportSelectedItemToPlayer();
				return false;
			}
		}

		private LevelItemTarget SelectedLevelTarget()
		{
			if (levelItems.Count == 0)
			{
				RefreshLevelItems();
			}
			if (levelItems.Count == 0)
			{
				return null;
			}
			LevelSelectedIndex = Mathf.Clamp(LevelSelectedIndex, 0, levelItems.Count - 1);
			return levelItems[LevelSelectedIndex];
		}

		private LevelItemTarget MakeTarget(GameObject go, ItemInstance item, StealableObject stealable, Vector3 origin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = go.transform.position;
			string text = (((Object)(object)item != (Object)null) ? ResolveItemName(item) : ResolveStealableName(stealable));
			if (string.IsNullOrEmpty(text))
			{
				text = ((Object)go).name;
			}
			return new LevelItemTarget
			{
				Name = text,
				ComponentName = (((Object)(object)item != (Object)null) ? "ItemInstance" : "StealableObject"),
				GameObject = go,
				ItemInstance = item,
				StealableObject = stealable,
				Position = position,
				Distance = Vector3.Distance(origin, position)
			};
		}

		private string ResolveItemName(ItemInstance item)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			AllItems val = cachedAllItems ?? FindAllItems();
			if ((Object)(object)val == (Object)null || val.items == null)
			{
				return ((Object)((Component)item).gameObject).name;
			}
			int itemIndex = item.InstanceData.itemIndex;
			if (itemIndex >= 0 && itemIndex < val.items.Length && (Object)(object)val.items[itemIndex] != (Object)null)
			{
				return ((CraftableItemBase)val.items[itemIndex]).Name;
			}
			return ((Object)((Component)item).gameObject).name;
		}

		private static string ResolveStealableName(StealableObject stealable)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)stealable == (Object)null)
			{
				return "";
			}
			string text = ((object)stealable.ItemType/*cast due to .constrained prefix*/).ToString();
			if (string.IsNullOrEmpty(text) || !(text != "None"))
			{
				return ((Object)((Component)stealable).gameObject).name;
			}
			return text;
		}

		private static void MoveObject(GameObject go, Vector3 position)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)go == (Object)null))
			{
				go.transform.position = position;
				Rigidbody component = go.GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.position = position;
					component.linearVelocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
				}
			}
		}

		private static AllItems FindAllItems()
		{
			return Resources.FindObjectsOfTypeAll<AllItems>().FirstOrDefault();
		}
	}
	public class ResourcesModule : ModuleBase
	{
		public string LastMessage = "";

		public string CurrentValuesText = "";

		public override string Id => "resources";

		public override string DisplayName => "Resources";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnableMod.Value;
			}
			set
			{
			}
		}

		public int GetCount(int index)
		{
			PlayerNetworking val = GameAccess.LocalPlayer();
			ResourceStorage val2 = (ResourceStorage)(object)(((Object)(object)val != (Object)null) ? val.Resources : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return 0;
			}
			return index switch
			{
				0 => val2.CeramicsCount, 
				1 => val2.MetalCount, 
				2 => val2.FabricCount, 
				3 => val2.PlasticCount, 
				4 => val2.ChemicalsCount, 
				5 => val2.GnomiumCount, 
				_ => 0, 
			};
		}

		public void Refresh()
		{
			CurrentValuesText = BuildCurrentValuesText();
			LastMessage = (string.IsNullOrEmpty(CurrentValuesText) ? "Resources not found" : ("Resources refreshed: " + CurrentValuesText));
		}

		public bool AddResource(int index, int amount)
		{
			PlayerNetworking val = GameAccess.LocalPlayer();
			if ((Object)(object)val == (Object)null)
			{
				LastMessage = "Player not found";
				return false;
			}
			int num = Mathf.Clamp(amount, 1, 9999);
			string resourceName = ResourceStorage.GetResourceName(index);
			try
			{
				ResourceStorage resources = (ResourceStorage)(object)val.Resources;
				if ((Object)(object)resources != (Object)null)
				{
					SetCount(resources, index, GetCount(index) + num);
					RefreshResourceUi(resources);
					int count = GetCount(index);
					CurrentValuesText = BuildCurrentValuesText();
					LastMessage = "Added " + resourceName + " x" + num + ". Now: " + count;
					return true;
				}
				if ((Object)(object)val.Inventory != (Object)null && ((InventoryBase)val.Inventory).TryAddItem(resourceName, num))
				{
					LastMessage = "Added " + resourceName + " x" + num + " to inventory";
					return true;
				}
				LastMessage = "Could not add " + resourceName;
				ModLog.Warning("Resources: could not add " + resourceName);
				return false;
			}
			catch (Exception ex)
			{
				LastMessage = "Resource add failed: " + ex.Message;
				ModLog.Warning("Resources exception: " + ex.Message);
				return false;
			}
		}

		public bool AddAll(int amount)
		{
			bool flag = true;
			for (int i = 0; i < 6; i++)
			{
				flag &= AddResource(i, amount);
			}
			CurrentValuesText = BuildCurrentValuesText();
			LastMessage = (flag ? ("Added all x" + Mathf.Clamp(amount, 1, 9999) + ". Current: " + CurrentValuesText) : LastMessage);
			return flag;
		}

		private string BuildCurrentValuesText()
		{
			PlayerNetworking val = GameAccess.LocalPlayer();
			ResourceStorage val2 = (ResourceStorage)(object)(((Object)(object)val != (Object)null) ? val.Resources : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return "";
			}
			return "ceramics " + val2.CeramicsCount + ", metal " + val2.MetalCount + ", fabric " + val2.FabricCount + ", plastic " + val2.PlasticCount + ", chemicals " + val2.ChemicalsCount + ", gnomium " + val2.GnomiumCount;
		}

		private static void RefreshResourceUi(ResourceStorage storage)
		{
			try
			{
				MethodInfo methodInfo = typeof(ResourceStorage).GetMethod("UpdateResourceAmounts", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(ResourceStorage).GetMethod("OnResourcesChanged", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (methodInfo != null)
				{
					methodInfo.Invoke(storage, null);
				}
			}
			catch (Exception ex)
			{
				ModLog.Warning("Resources UI refresh failed: " + ex.Message);
			}
		}

		private static void SetCount(ResourceStorage storage, int index, int value)
		{
			switch (index)
			{
			case 0:
				storage.CeramicsCount = value;
				break;
			case 1:
				storage.MetalCount = value;
				break;
			case 2:
				storage.FabricCount = value;
				break;
			case 3:
				storage.PlasticCount = value;
				break;
			case 4:
				storage.ChemicalsCount = value;
				break;
			case 5:
				storage.GnomiumCount = value;
				break;
			}
		}
	}
}
namespace BGMod.ESP
{
	public class ESPModule : ModuleBase
	{
		private readonly List<ESPTarget> targets = new List<ESPTarget>();

		private Texture2D lineTex;

		private GUIStyle labelStyle;

		private float nextScanTime;

		private FieldInfo cabinetSpawnField;

		private bool reflectionInitialized;

		public override string Id => "esp";

		public override string DisplayName => "ESP";

		public override bool Enabled
		{
			get
			{
				return ModConfig.EnableESP.Value;
			}
			set
			{
				ModConfig.EnableESP.Value = value;
			}
		}

		public IReadOnlyList<ESPTarget> Targets => targets;

		public override void OnUpdate()
		{
			if (Enabled)
			{
				float num = base.Modules.Get<PerformanceModule>()?.EspRefreshRate ?? ModConfig.ESPRefreshRate.Value;
				if (!(Time.time < nextScanTime))
				{
					nextScanTime = Time.time + num;
					Guard("scan", ScanTargets);
				}
			}
		}

		public override void OnGUI()
		{
			//IL_003d: 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)
			//IL_004d: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled || (Object)(object)Camera.main == (Object)null)
			{
				return;
			}
			InitStyles();
			Camera main = Camera.main;
			foreach (ESPTarget target in targets)
			{
				Vector3 val = main.WorldToScreenPoint(target.Position + Vector3.up * target.Height);
				if (!(val.z <= 0f))
				{
					val.y = (float)Screen.height - val.y;
					DrawLabel(val, target.Label + "\n" + target.Distance.ToString("F0") + "m", target.Color);
					if (target.DrawBox)
					{
						DrawBox(new Rect(val.x - 22f, val.y - 36f, 44f, 58f), target.Color);
					}
					if (target.DrawTracer)
					{
						DrawLine(new Vector2((float)Screen.width / 2f, (float)Screen.height), new Vector2(val.x, val.y), target.Color, 1f);
					}
				}
			}
		}

		private void ScanTargets()
		{
			targets.Clear();
			PlayerNetworking val = GameAccess.LocalPlayer();
			if (!((Object)(object)val == (Object)null))
			{
				PerformanceModule performanceModule = base.Modules.Get<PerformanceModule>();
				float maxDistance = performanceModule?.MaxEspDistance ?? ModConfig.MaxESPDistance.Value;
				int maxObjects = performanceModule?.MaxEspObjects ?? ModConfig.MaxESPObjects.Value;
				if (ModConfig.EnableItemESP.Value)
				{
					AddItems(val, maxDistance, maxObjects);
					AddCabinets(val, maxDistance, maxObjects);
				}
				if (ModConfig.EnableHumanESP.Value)
				{
					AddHumans(val, maxDistance, maxObjects);
				}
				if (ModConfig.EnableGnomeESP.Value)
				{
					AddPlayers(val, maxDistance, maxObjects);
				}
			}
		}

		private void AddItems(PlayerNetworking local, float maxDistance, int maxObjects)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			StealableObject[] array = Object.FindObjectsByType<StealableObject>((FindObjectsSortMode)0);
			foreach (StealableObject val in array)
			{
				if ((Object)(object)val == (Object)null || targets.Count >= maxObjects)
				{
					break;
				}
				float num = Vector3.Distance(((Component)local).transform.position, ((Component)val).transform.position);
				if (!(num > maxDistance))
				{
					targets.Add(new ESPTarget
					{
						Label = CleanName(((Object)((Component)val).gameObject).name),
						Color = new Color(1f, 0.78f, 0.25f),
						Position = ((Component)val).transform.position,
						Height = 0.35f,
						Distance = num,
						DrawBox = false,
						DrawTracer = false
					});
				}
			}
		}

		private void AddCabinets(PlayerNetworking local, float maxDistance, int maxObjects)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			EnsureReflection();
			if (cabinetSpawnField == null)
			{
				return;
			}
			CabinetDrawer[] array = Object.FindObjectsByType<CabinetDrawer>((FindObjectsSortMode)0);
			foreach (CabinetDrawer val in array)
			{
				if ((Object)(object)val == (Object)null || targets.Count >= maxObjects)
				{
					break;
				}
				if (val.HasSpawnedContents)
				{
					continue;
				}
				float num = Vector3.Distance(((Component)local).transform.position, ((Component)val).transform.position);
				if (!(num > maxDistance))
				{
					string text = CabinetLabel(val);
					if (!string.IsNullOrEmpty(text))
					{
						targets.Add(new ESPTarget
						{
							Label = "Cabinet: " + text,
							Color = new Color(0.45f, 0.9f, 1f),
							Position = ((Component)val).transform.position,
							Height = 0.55f,
							Distance = num,
							DrawBox = false,
							DrawTracer = false
						});
					}
				}
			}
		}

		private void AddHumans(PlayerNetworking local, float maxDistance, int maxObjects)
		{
			//IL_0046: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			HumanAILink[] array = Object.FindObjectsByType<HumanAILink>((FindObjectsSortMode)0);
			foreach (HumanAILink val in array)
			{
				if ((Object)(object)val == (Object)null || targets.Count >= maxObjects)
				{
					break;
				}
				GameEntityBase val2 = (GameEntityBase)(object)val;
				if (!((Object)(object)val2 != (Object)null) || !val2.IsDead)
				{
					float num = Vector3.Distance(((Component)local).transform.position, ((Component)val).transform.position);
					if (!(num > maxDistance))
					{
						targets.Add(new ESPTarget
						{
							Label = HumanLabel(val),
							Color = new Color(1f, 0.36f, 0.32f),
							Position = ((Component)val).transform.position,
							Height = 2.2f,
							Distance = num,
							DrawBox = true,