Decompiled source of Vanguards Modpack v0.5.3

CustomUI.dll

Decompiled 7 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomUI;

[BepInPlugin("aedenthorn.CustomUI", "Custom UI", "0.7.0")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
	private static class HotkeyBar_UpdateIcons_Patch
	{
		private static void Postfix(HotkeyBar __instance)
		{
			//IL_0095: 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)
			if (modEnabled.Value && !((Object)(object)Player.m_localPlayer == (Object)null) && !(((Object)__instance).name != "HotKeyBar"))
			{
				int childCount = ((Component)__instance).transform.childCount;
				float num = __instance.m_elementSpace * toolbarItemScale.Value;
				for (int i = 0; i < childCount; i++)
				{
					int num2 = i % toolbarItemsPerRow.Value;
					int num3 = i / toolbarItemsPerRow.Value;
					Transform child = ((Component)__instance).transform.GetChild(i);
					((Component)child).GetComponent<RectTransform>().anchoredPosition = new Vector2(num * (float)num2, (0f - num) * (float)num3);
					((Transform)((Component)child).GetComponent<RectTransform>()).localScale = new Vector3(toolbarItemScale.Value, toolbarItemScale.Value, 1f);
				}
			}
		}
	}

	[HarmonyPatch(typeof(Hud), "Update")]
	private static class Hud_Update_Patch
	{
		private static void Postfix(Hud __instance)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_006f: 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_00b0: 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_0095: 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_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_067b: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0723: Unknown result type (might be due to invalid IL or missing references)
			//IL_073d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_076a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0791: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0826: Unknown result type (might be due to invalid IL or missing references)
			//IL_084a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0883: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_105b: Unknown result type (might be due to invalid IL or missing references)
			//IL_105c: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a24: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a45: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a93: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a98: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b36: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b58: Unknown result type (might be due to invalid IL or missing references)
			//IL_0910: Unknown result type (might be due to invalid IL or missing references)
			//IL_092c: Unknown result type (might be due to invalid IL or missing references)
			//IL_094f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0977: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b9c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d13: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d57: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d7c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e3d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e81: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ea6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ee8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f2c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f51: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f8e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1024: Unknown result type (might be due to invalid IL or missing references)
			//IL_102a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fd2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ff7: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value || (Object)(object)Player.m_localPlayer == (Object)null || InventoryGui.IsVisible())
			{
				return;
			}
			float scaleFactor = GameObject.Find("LoadingGUI").GetComponent<CanvasScaler>().scaleFactor;
			int num = healthbarRotation.Value / 90 % 4 * 90;
			Vector3 mousePosition = Input.mousePosition;
			if (!modEnabled.Value)
			{
				lastMousePos = mousePosition;
				return;
			}
			SetElementPositions();
			if (lastMousePos == Vector3.zero)
			{
				lastMousePos = mousePosition;
			}
			Transform val = ((Component)Hud.instance).transform.Find("hudroot");
			Rect zero = Rect.zero;
			switch (num)
			{
			case 0:
				((Rect)(ref zero))..ctor(((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.x * scaleFactor, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.y * scaleFactor - ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * healthbarScale.Value);
				break;
			case 90:
				((Rect)(ref zero))..ctor(((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.x * scaleFactor, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.y * scaleFactor, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * healthbarScale.Value);
				break;
			case 180:
				((Rect)(ref zero))..ctor(((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.x * scaleFactor - ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.y * scaleFactor, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * healthbarScale.Value);
				break;
			case 270:
				((Rect)(ref zero))..ctor(((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.x * scaleFactor - ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.y * scaleFactor - ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * healthbarScale.Value, ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * healthbarScale.Value);
				break;
			}
			if (Object.op_Implicit((Object)(object)val.Find("healthpanel").Find("Health").Find("QuickSlotsHotkeyBar")))
			{
				val.Find("healthpanel").Find("Health").Find("QuickSlotsHotkeyBar")
					.SetParent(val);
				RectTransform component = ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>();
				component.anchoredPosition += new Vector2(((Rect)(ref zero)).x, ((Rect)(ref zero)).y);
				((Transform)((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>()).localEulerAngles = new Vector3(0f, 0f, 0f);
			}
			if (CheckKeyHeld(modKeyOne.Value) && CheckKeyHeld(modKeyTwo.Value))
			{
				Rect val2 = default(Rect);
				((Rect)(ref val2))..ctor(((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMin.x * (float)Screen.width + ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchoredPosition.x * scaleFactor, ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMax.y * (float)Screen.height + ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchoredPosition.y * scaleFactor - ((Component)val.Find("HotKeyBar")).GetComponent<HotkeyBar>().m_elementSpace * scaleFactor * toolbarItemScale.Value * (float)(7 / toolbarItemsPerRow.Value + 1), ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * toolbarItemScale.Value * ((float)toolbarItemsPerRow.Value / 8f), ((Component)val.Find("HotKeyBar")).GetComponent<HotkeyBar>().m_elementSpace * scaleFactor * toolbarItemScale.Value * (float)(7 / toolbarItemsPerRow.Value + 1));
				float x = ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().anchoredPosition.x;
				Rect rect = ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().rect;
				float num2 = (x + ((Rect)(ref rect)).x * guardianScale.Value) * scaleFactor;
				float y = ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().anchoredPosition.y;
				rect = ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().rect;
				Rect val3 = default(Rect);
				((Rect)(ref val3))..ctor(num2, (y + ((Rect)(ref rect)).y * guardianScale.Value) * scaleFactor, ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * guardianScale.Value, ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * guardianScale.Value);
				float num3 = Screen.width;
				float x2 = ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().anchoredPosition.x;
				rect = ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().rect;
				float num4 = num3 + (x2 + ((Rect)(ref rect)).x * statusScale.Value) * scaleFactor;
				float num5 = Screen.height;
				float y2 = ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().anchoredPosition.y;
				rect = ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().rect;
				Rect val4 = default(Rect);
				((Rect)(ref val4))..ctor(num4, num5 + (y2 + ((Rect)(ref rect)).y * statusScale.Value) * scaleFactor, ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * statusScale.Value, ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * statusScale.Value);
				Rect val5 = default(Rect);
				((Rect)(ref val5))..ctor((((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().anchoredPosition.x - ((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().sizeDelta.x * mapScale.Value) * scaleFactor + (float)Screen.width, (((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().anchoredPosition.y - ((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().sizeDelta.y * mapScale.Value) * scaleFactor + (float)Screen.height, ((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * mapScale.Value, ((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * mapScale.Value);
				Rect zero2 = Rect.zero;
				Transform obj = val.Find("QuickSlotsHotkeyBar");
				if ((Object)(object)((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null) != (Object)null)
				{
					((Rect)(ref zero2))..ctor(((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().anchoredPosition.x * scaleFactor, ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().anchoredPosition.y * scaleFactor + (float)Screen.height - ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * quickSlotsScale.Value, ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().sizeDelta.x * scaleFactor * quickSlotsScale.Value * 0.375f, ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().sizeDelta.y * scaleFactor * quickSlotsScale.Value);
				}
				float num6 = Screen.width;
				float x3 = ((Terminal)Chat.instance).m_chatWindow.anchoredPosition.x;
				rect = ((Terminal)Chat.instance).m_chatWindow.rect;
				Rect val6 = default(Rect);
				((Rect)(ref val6))..ctor(num6 + (x3 + ((Rect)(ref rect)).x * chatScale.Value) * scaleFactor, ((Terminal)Chat.instance).m_chatWindow.anchoredPosition.y * scaleFactor, ((Terminal)Chat.instance).m_chatWindow.sizeDelta.x * scaleFactor * chatScale.Value, ((Terminal)Chat.instance).m_chatWindow.sizeDelta.y * scaleFactor * chatScale.Value);
				float num7 = Screen.width / 2;
				float x4 = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().anchoredPosition.x;
				rect = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().rect;
				float num8 = num7 + (x4 + ((Rect)(ref rect)).x * buildingScale.Value) * scaleFactor;
				float num9 = Screen.height / 2;
				float y3 = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().anchoredPosition.y;
				rect = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().rect;
				float num10 = num9 + (y3 + ((Rect)(ref rect)).y * buildingScale.Value) * scaleFactor;
				rect = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().rect;
				float num11 = ((Rect)(ref rect)).width * scaleFactor * buildingScale.Value;
				rect = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().rect;
				Rect val7 = default(Rect);
				((Rect)(ref val7))..ctor(num8, num10, num11, ((Rect)(ref rect)).height * scaleFactor * buildingScale.Value);
				if (((Rect)(ref val2)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "HotKeyBar"))
				{
					ConfigEntry<float> toolbarX = BepInExPlugin.toolbarX;
					toolbarX.Value += mousePosition.x - lastMousePos.x;
					ConfigEntry<float> toolbarY = BepInExPlugin.toolbarY;
					toolbarY.Value += mousePosition.y - lastMousePos.y;
					currentlyDragging = "HotKeyBar";
				}
				else if (((Rect)(ref zero)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "healthpanel"))
				{
					ConfigEntry<float> healthbarX = BepInExPlugin.healthbarX;
					healthbarX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> healthbarY = BepInExPlugin.healthbarY;
					healthbarY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "healthpanel";
				}
				else if (((Rect)(ref val3)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "GuardianPower"))
				{
					ConfigEntry<float> guardianX = BepInExPlugin.guardianX;
					guardianX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> guardianY = BepInExPlugin.guardianY;
					guardianY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "GuardianPower";
				}
				else if (((Rect)(ref val5)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "MiniMap"))
				{
					ConfigEntry<float> mapX = BepInExPlugin.mapX;
					mapX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> mapY = BepInExPlugin.mapY;
					mapY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "MiniMap";
				}
				else if (((Rect)(ref val4)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "StatusEffects"))
				{
					ConfigEntry<float> statusX = BepInExPlugin.statusX;
					statusX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> statusY = BepInExPlugin.statusY;
					statusY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "StatusEffects";
				}
				else if (((Rect)(ref zero2)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "QuickSlots"))
				{
					ConfigEntry<float> quickSlotsX = BepInExPlugin.quickSlotsX;
					quickSlotsX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> quickSlotsY = BepInExPlugin.quickSlotsY;
					quickSlotsY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "QuickSlots";
				}
				else if (((Component)((Terminal)Chat.instance).m_chatWindow).gameObject.activeInHierarchy && ((Rect)(ref val6)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "Chat"))
				{
					ConfigEntry<float> chatX = BepInExPlugin.chatX;
					chatX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> chatY = BepInExPlugin.chatY;
					chatY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "Chat";
				}
				else if (Hud.instance.m_pieceSelectionWindow.activeSelf && ((Rect)(ref val7)).Contains(lastMousePos) && (currentlyDragging == "" || currentlyDragging == "Building"))
				{
					ConfigEntry<float> buildingX = BepInExPlugin.buildingX;
					buildingX.Value += (mousePosition.x - lastMousePos.x) / scaleFactor;
					ConfigEntry<float> buildingY = BepInExPlugin.buildingY;
					buildingY.Value += (mousePosition.y - lastMousePos.y) / scaleFactor;
					currentlyDragging = "Building";
				}
				else
				{
					Dbgl($"mouse {mousePosition} build rect {val7} game scale {scaleFactor}");
					currentlyDragging = "";
				}
			}
			else
			{
				currentlyDragging = "";
			}
			lastMousePos = mousePosition;
		}
	}

	[HarmonyPatch(typeof(Terminal), "InputText")]
	private static class InputText_Patch
	{
		private static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				__instance.AddString(text);
				__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
				return false;
			}
			return true;
		}
	}

	private static readonly bool isDebug = true;

	private static BepInExPlugin context;

	private Harmony harmony;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<float> toolbarX;

	public static ConfigEntry<float> toolbarY;

	public static ConfigEntry<float> toolbarItemScale;

	public static ConfigEntry<int> toolbarItemsPerRow;

	public static ConfigEntry<int> healthbarRotation;

	public static ConfigEntry<float> healthbarX;

	public static ConfigEntry<float> healthbarY;

	public static ConfigEntry<float> healthbarScale;

	public static ConfigEntry<float> guardianX;

	public static ConfigEntry<float> guardianY;

	public static ConfigEntry<float> guardianScale;

	public static ConfigEntry<float> mapX;

	public static ConfigEntry<float> mapY;

	public static ConfigEntry<float> mapScale;

	public static ConfigEntry<float> statusX;

	public static ConfigEntry<float> statusY;

	public static ConfigEntry<float> statusScale;

	public static ConfigEntry<float> quickSlotsX;

	public static ConfigEntry<float> quickSlotsY;

	public static ConfigEntry<float> quickSlotsScale;

	public static ConfigEntry<float> buildingX;

	public static ConfigEntry<float> buildingY;

	public static ConfigEntry<float> buildingScale;

	public static ConfigEntry<float> chatX;

	public static ConfigEntry<float> chatY;

	public static ConfigEntry<float> chatScale;

	public static ConfigEntry<string> modKeyOne;

	public static ConfigEntry<string> modKeyTwo;

	public static ConfigEntry<int> nexusID;

	public static int itemSize = 48;

	private static Vector3 lastMousePos;

	private static string currentlyDragging;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		//IL_0480: Unknown result type (might be due to invalid IL or missing references)
		//IL_048a: Expected O, but got Unknown
		context = this;
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 625, "Nexus mod ID for updates");
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		modKeyOne = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ModKeyOne", "mouse 0", "First modifier key. Use https://docs.unity3d.com/Manual/ConventionalGameInput.html format.");
		modKeyTwo = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ModKeyTwo", "left ctrl", "Second modifier key. Use https://docs.unity3d.com/Manual/ConventionalGameInput.html format.");
		toolbarItemsPerRow = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ToolbarItemsPerRow", 8, "Number of items per row in the toolbar");
		toolbarItemsPerRow = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ToolbarItemsPerRow", 8, "Number of items per row in the toolbar");
		healthbarRotation = ((BaseUnityPlugin)this).Config.Bind<int>("General", "HealthbarRotation", 0, "Rotation of healthbar. Must be a multiple of 90.");
		toolbarItemScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "ToolbarItemScale", 1f, "Toolbar item scale");
		healthbarScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "HealthbarScale", 1f, "Healthbar scale");
		guardianScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "GuardianScale", 1f, "Guardian power scale");
		mapScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "MapScale", 1f, "map scale");
		statusScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "StatusScale", 1f, "status scale");
		quickSlotsScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "QuickSlotsScale", 1f, "Quick slots scale");
		buildingScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "BuildingScale", 1f, "Building scale");
		chatScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "ChatScale", 1f, "Chat scale");
		toolbarX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "ToolbarX", 9999f, "Current X of toolbar");
		toolbarY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "ToolbarY", 9999f, "Current Y of toolbar");
		healthbarX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "HealthbarX", 9999f, "Current X of healthbar");
		healthbarY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "HealthbarY", 9999f, "Current Y of healthbar");
		guardianX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "GuardianX", 9999f, "Current X of guardian power");
		guardianY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "GuardianY", 9999f, "Current Y of guardian power");
		mapX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "MapX", 9999f, "Current X of map");
		mapY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "MapY", 9999f, "Current Y of map");
		quickSlotsX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "QuickSlotsX", 9999f, "Current X of Quick Slots");
		quickSlotsY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "QuickSlotsY", 9999f, "Current Y of Quick Slots");
		statusX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "StatusX", 9999f, "Current X of status");
		statusY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "StatusY", 9999f, "Current Y of status");
		chatX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "ChatX", 9999f, "Current X of chat");
		chatY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "ChatY", 9999f, "Current Y of chat");
		buildingX = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "BuildingX", 9999f, "Current X of building");
		buildingY = ((BaseUnityPlugin)this).Config.Bind<float>("ZCurrentPositions", "BuildingY", 9999f, "Current Y of building");
		toolbarItemsPerRow.Value = Mathf.Clamp(toolbarItemsPerRow.Value, 1, 8);
		harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
		harmony.PatchAll();
	}

	private void OnDestroy()
	{
		Dbgl("Destroying plugin");
		harmony.UnpatchAll((string)null);
	}

	private static bool CheckKeyHeld(string value)
	{
		try
		{
			return Input.GetKey(value.ToLower());
		}
		catch
		{
			return false;
		}
	}

	private static void SetElementPositions()
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0402: Unknown result type (might be due to invalid IL or missing references)
		//IL_0431: Unknown result type (might be due to invalid IL or missing references)
		//IL_0458: Unknown result type (might be due to invalid IL or missing references)
		//IL_049b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_050a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0539: Unknown result type (might be due to invalid IL or missing references)
		//IL_0568: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0609: Unknown result type (might be due to invalid IL or missing references)
		//IL_063d: Unknown result type (might be due to invalid IL or missing references)
		//IL_067b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0700: Unknown result type (might be due to invalid IL or missing references)
		//IL_0733: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0791: Unknown result type (might be due to invalid IL or missing references)
		//IL_0801: Unknown result type (might be due to invalid IL or missing references)
		//IL_0835: Unknown result type (might be due to invalid IL or missing references)
		//IL_07cd: Unknown result type (might be due to invalid IL or missing references)
		Transform val = ((Component)Hud.instance).transform.Find("hudroot");
		int num = healthbarRotation.Value / 90 % 4 * 90;
		if (toolbarX.Value == 9999f)
		{
			toolbarX.Value = ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMin.x * (float)Screen.width;
		}
		if (toolbarY.Value == 9999f)
		{
			toolbarY.Value = ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMax.y * (float)Screen.height;
		}
		if (healthbarX.Value == 9999f)
		{
			healthbarX.Value = ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.x;
		}
		if (healthbarY.Value == 9999f)
		{
			healthbarY.Value = ((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition.y;
		}
		if (guardianX.Value == 9999f)
		{
			guardianX.Value = ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().anchoredPosition.x;
		}
		if (guardianY.Value == 9999f)
		{
			guardianY.Value = ((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().anchoredPosition.y;
		}
		if (statusX.Value == 9999f)
		{
			statusX.Value = ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().anchoredPosition.x;
		}
		if (statusY.Value == 9999f)
		{
			statusY.Value = ((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().anchoredPosition.y;
		}
		if (mapX.Value == 9999f)
		{
			mapX.Value = ((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().anchoredPosition.x;
		}
		if (mapY.Value == 9999f)
		{
			mapY.Value = ((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().anchoredPosition.y;
		}
		if (chatX.Value == 9999f)
		{
			chatX.Value = ((Terminal)Chat.instance).m_chatWindow.anchoredPosition.x;
		}
		if (chatY.Value == 9999f)
		{
			chatY.Value = ((Terminal)Chat.instance).m_chatWindow.anchoredPosition.y;
		}
		if (buildingX.Value == 9999f)
		{
			buildingX.Value = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().anchoredPosition.x;
		}
		if (buildingY.Value == 9999f)
		{
			buildingY.Value = Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().anchoredPosition.y;
		}
		((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMax = new Vector2(((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMax.x, toolbarY.Value / (float)Screen.height);
		((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMin = new Vector2(toolbarX.Value / (float)Screen.width, ((Component)val.Find("HotKeyBar")).GetComponent<RectTransform>().anchorMin.y);
		((Component)val.Find("healthpanel")).GetComponent<RectTransform>().anchoredPosition = new Vector2(healthbarX.Value, healthbarY.Value);
		((Transform)((Component)val.Find("healthpanel")).GetComponent<RectTransform>()).localEulerAngles = new Vector3(0f, 0f, (float)num);
		((Transform)((Component)val.Find("healthpanel").Find("Health").Find("fast")
			.Find("bar")
			.Find("HealthText")).GetComponent<RectTransform>()).eulerAngles = Vector3.zero;
		((Transform)((Component)val.Find("healthpanel").Find("food0")).GetComponent<RectTransform>()).eulerAngles = Vector3.zero;
		((Transform)((Component)val.Find("healthpanel").Find("food1")).GetComponent<RectTransform>()).eulerAngles = Vector3.zero;
		((Transform)((Component)val.Find("healthpanel").Find("food2")).GetComponent<RectTransform>()).eulerAngles = Vector3.zero;
		((Component)val.Find("GuardianPower")).GetComponent<RectTransform>().anchoredPosition = new Vector2(guardianX.Value, guardianY.Value);
		((Component)val.Find("StatusEffects")).GetComponent<RectTransform>().anchoredPosition = new Vector2(statusX.Value, statusY.Value);
		((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>().anchoredPosition = new Vector2(mapX.Value, mapY.Value);
		((Transform)((Component)val.Find("healthpanel")).GetComponent<RectTransform>()).localScale = new Vector3(healthbarScale.Value, healthbarScale.Value, 1f);
		((Transform)((Component)val.Find("GuardianPower")).GetComponent<RectTransform>()).localScale = new Vector3(guardianScale.Value, guardianScale.Value, 1f);
		((Transform)((Component)val.Find("StatusEffects")).GetComponent<RectTransform>()).localScale = new Vector3(statusScale.Value, statusScale.Value, 1f);
		((Transform)((Component)val.Find("MiniMap").Find("small")).GetComponent<RectTransform>()).localScale = new Vector3(mapScale.Value, mapScale.Value, 1f);
		((Terminal)Chat.instance).m_chatWindow.anchoredPosition = new Vector2(chatX.Value, chatY.Value);
		((Transform)((Terminal)Chat.instance).m_chatWindow).localScale = new Vector3(chatScale.Value, chatScale.Value, 1f);
		Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>().anchoredPosition = new Vector2(buildingX.Value, buildingY.Value);
		((Transform)Hud.instance.m_pieceSelectionWindow.GetComponent<RectTransform>()).localScale = new Vector3(buildingScale.Value, buildingScale.Value, 1f);
		Transform obj = val.Find("QuickSlotsHotkeyBar");
		if ((Object)(object)((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null) != (Object)null)
		{
			if (quickSlotsX.Value == 9999f)
			{
				quickSlotsX.Value = ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().anchoredPosition.x;
			}
			if (quickSlotsY.Value == 9999f)
			{
				quickSlotsY.Value = ((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().anchoredPosition.y;
			}
			((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>().anchoredPosition = new Vector2(quickSlotsX.Value, quickSlotsY.Value);
			((Transform)((Component)val.Find("QuickSlotsHotkeyBar")).GetComponent<RectTransform>()).localScale = new Vector3(quickSlotsScale.Value, quickSlotsScale.Value, 1f);
		}
	}
}