using System.Collections.Generic;
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.EventSystems;
[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 MovableInventoryWindows;
[BepInPlugin("aedenthorn.MovableInventoryWindows", "Movable Inventory Windows", "0.3.0")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(InventoryGui), "Update")]
private static class InventoryGui_Update_Patch
{
private static void Postfix(InventoryGui __instance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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_001a: 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_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: 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_0062: 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_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: 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_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: 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_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: 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_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Expected O, but got Unknown
//IL_031f: Unknown result type (might be due to invalid IL or missing references)
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
//IL_0363: Unknown result type (might be due to invalid IL or missing references)
//IL_0368: Unknown result type (might be due to invalid IL or missing references)
//IL_0586: Unknown result type (might be due to invalid IL or missing references)
//IL_0587: 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_03a6: Unknown result type (might be due to invalid IL or missing references)
//IL_03e4: 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_03fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0401: Unknown result type (might be due to invalid IL or missing references)
//IL_0419: 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_0436: Unknown result type (might be due to invalid IL or missing references)
//IL_049e: 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_045e: Unknown result type (might be due to invalid IL or missing references)
//IL_0476: Unknown result type (might be due to invalid IL or missing references)
//IL_048e: Unknown result type (might be due to invalid IL or missing references)
//IL_0493: Unknown result type (might be due to invalid IL or missing references)
//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0513: Unknown result type (might be due to invalid IL or missing references)
//IL_0518: Unknown result type (might be due to invalid IL or missing references)
//IL_0530: Unknown result type (might be due to invalid IL or missing references)
//IL_0548: Unknown result type (might be due to invalid IL or missing references)
//IL_054d: Unknown result type (might be due to invalid IL or missing references)
Vector3 mousePosition = Input.mousePosition;
if (!modEnabled.Value)
{
lastMousePos = mousePosition;
return;
}
if (BepInExPlugin.inventoryPosition.Value.x == 9999f && BepInExPlugin.inventoryPosition.Value.y == 9999f)
{
BepInExPlugin.inventoryPosition.Value = __instance.m_player.anchorMin;
}
__instance.m_player.anchorMin = BepInExPlugin.inventoryPosition.Value;
__instance.m_player.anchorMax = BepInExPlugin.inventoryPosition.Value;
((Transform)__instance.m_player).localScale = new Vector3(inventoryScale.Value, inventoryScale.Value, 1f);
if (BepInExPlugin.chestInventoryPosition.Value.x == 9999f || BepInExPlugin.chestInventoryPosition.Value.y == 9999f)
{
BepInExPlugin.chestInventoryPosition.Value = __instance.m_container.anchorMin;
}
__instance.m_container.anchorMin = BepInExPlugin.chestInventoryPosition.Value;
__instance.m_container.anchorMax = BepInExPlugin.chestInventoryPosition.Value;
((Transform)__instance.m_container).localScale = new Vector3(chestInventoryScale.Value, chestInventoryScale.Value, 1f);
if (BepInExPlugin.craftingPanelPosition.Value.x == 9999f || BepInExPlugin.craftingPanelPosition.Value.y == 9999f)
{
BepInExPlugin.craftingPanelPosition.Value = ((Component)((Transform)__instance.m_player).parent.Find("Crafting")).GetComponent<RectTransform>().anchorMin;
}
((Component)((Transform)__instance.m_player).parent.Find("Crafting")).GetComponent<RectTransform>().anchorMin = BepInExPlugin.craftingPanelPosition.Value;
((Component)((Transform)__instance.m_player).parent.Find("Crafting")).GetComponent<RectTransform>().anchorMax = BepInExPlugin.craftingPanelPosition.Value;
((Transform)((Component)((Transform)__instance.m_player).parent.Find("Crafting")).GetComponent<RectTransform>()).localScale = new Vector3(craftingPanelScale.Value, craftingPanelScale.Value, 1f);
if (BepInExPlugin.infoPanelPosition.Value.x == 9999f || BepInExPlugin.infoPanelPosition.Value.y == 9999f)
{
BepInExPlugin.infoPanelPosition.Value = ((Component)__instance.m_infoPanel).GetComponent<RectTransform>().anchorMin;
}
((Component)__instance.m_infoPanel).GetComponent<RectTransform>().anchorMin = BepInExPlugin.infoPanelPosition.Value;
((Component)__instance.m_infoPanel).GetComponent<RectTransform>().anchorMax = BepInExPlugin.infoPanelPosition.Value;
((Transform)((Component)__instance.m_infoPanel).GetComponent<RectTransform>()).localScale = new Vector3(infoPanelScale.Value, infoPanelScale.Value, 1f);
if (lastMousePos == Vector3.zero)
{
lastMousePos = mousePosition;
}
PointerEventData val = new PointerEventData(EventSystem.current)
{
position = Vector2.op_Implicit(lastMousePos)
};
if (CheckKeyHeld(modKeyOne.Value) && CheckKeyHeld(modKeyTwo.Value) && lastMousePos != mousePosition)
{
List<RaycastResult> list = new List<RaycastResult>();
EventSystem.current.RaycastAll(val, list);
foreach (RaycastResult item in list)
{
RaycastResult current = item;
if (((RaycastResult)(ref current)).gameObject.layer == LayerMask.NameToLayer("UI") && ((Object)((RaycastResult)(ref current)).gameObject).name == "Bkg")
{
if (IsDragging(current, "Player"))
{
ConfigEntry<Vector2> inventoryPosition = BepInExPlugin.inventoryPosition;
inventoryPosition.Value += new Vector2((mousePosition.x - lastMousePos.x) / (float)Screen.width, (mousePosition.y - lastMousePos.y) / (float)Screen.height);
}
if (IsDragging(current, "Container"))
{
ConfigEntry<Vector2> chestInventoryPosition = BepInExPlugin.chestInventoryPosition;
chestInventoryPosition.Value += new Vector2((mousePosition.x - lastMousePos.x) / (float)Screen.width, (mousePosition.y - lastMousePos.y) / (float)Screen.height);
}
if (IsDragging(current, "Crafting"))
{
ConfigEntry<Vector2> craftingPanelPosition = BepInExPlugin.craftingPanelPosition;
craftingPanelPosition.Value += new Vector2((mousePosition.x - lastMousePos.x) / (float)Screen.width, (mousePosition.y - lastMousePos.y) / (float)Screen.height);
}
if (IsDragging(current, "Info"))
{
ConfigEntry<Vector2> infoPanelPosition = BepInExPlugin.infoPanelPosition;
infoPanelPosition.Value += new Vector2((mousePosition.x - lastMousePos.x) / (float)Screen.width, (mousePosition.y - lastMousePos.y) / (float)Screen.height);
}
}
}
}
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();
Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
Traverse.Create((object)__instance).Method("AddString", new object[1] { ((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded" }).GetValue();
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<Vector2> inventoryPosition;
public static ConfigEntry<Vector2> chestInventoryPosition;
public static ConfigEntry<Vector2> craftingPanelPosition;
public static ConfigEntry<Vector2> infoPanelPosition;
public static ConfigEntry<float> inventoryScale;
public static ConfigEntry<float> chestInventoryScale;
public static ConfigEntry<float> craftingPanelScale;
public static ConfigEntry<float> infoPanelScale;
public static ConfigEntry<string> modKeyOne;
public static ConfigEntry<string> modKeyTwo;
public static ConfigEntry<int> nexusID;
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_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Expected O, but got Unknown
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 577, "Nexus mod ID for updates");
inventoryScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "InventoryScale", 1f, "Scale of inventory");
chestInventoryScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChestInventoryScale", 1f, "Scale of chest");
craftingPanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CraftingPanelScale", 1f, "Scale of crafting panel");
infoPanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "InfoPanelScale", 1f, "Scale of crafting panel");
modKeyOne = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ModKeyOne", "mouse 0", "First modifier key. Use https://docs.unity3d.com/Manual/class-InputManager.html format.");
modKeyTwo = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ModKeyTwo", "left ctrl", "Second modifier key. Use https://docs.unity3d.com/Manual/class-InputManager.html format.");
inventoryPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("ZPositions", "InventoryPosition", new Vector2(9999f, 9999f), "Current position of inventory");
chestInventoryPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("ZPositions", "ChestInventoryPosition", new Vector2(9999f, 9999f), "Current position of chest");
craftingPanelPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("ZPositions", "CraftingPanelPosition", new Vector2(9999f, 9999f), "Current position of crafting panel");
infoPanelPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("ZPositions", "InfoPanelPosition", new Vector2(9999f, 9999f), "Current position of crafting panel");
if (modEnabled.Value)
{
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 bool IsDragging(RaycastResult rcr, string name)
{
if (((Object)((RaycastResult)(ref rcr)).gameObject.transform.parent).name == name)
{
if (currentlyDragging == "" || currentlyDragging == name)
{
currentlyDragging = name;
return true;
}
return false;
}
return false;
}
}