using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using InControl;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Bigfootmech")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Bigfootmech")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4+44644f1927111814d7e6bc7cc58723321a1fe82b")]
[assembly: AssemblyProduct("Inventory Mouse for Silksong")]
[assembly: AssemblyTitle("inventory_mouse_use")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Bigfootmech/Silksong_mouse_inventory")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 inventory_mouse_use
{
[BepInPlugin("com.bigfootmech.silksong.inventory_mouse", "Inventory Mouse for Silksong", "0.1.4")]
public class Plugin : BaseUnityPlugin
{
public class OnClickClass : MonoBehaviour
{
private bool MouseAlreadyIn;
public void OnMouseUp()
{
CurrentPanesCursorControlFsm.SendEvent("UI CONFIRM RELEASED");
}
public void OnMouseDown()
{
if (IsInventoryOpen() && !IsScrolling())
{
ClickFunction();
}
}
public void OnMouseOver()
{
if (IsInventoryOpen() && !IsScrolling())
{
WhileMouseOvered();
if (!MouseAlreadyIn || SwitchedPanesThisFrame)
{
MouseAlreadyIn = true;
MouseOverFunction();
}
}
}
public void OnMouseExit()
{
MouseAlreadyIn = false;
}
protected virtual void ClickFunction()
{
CurrentPanesCursorControlFsm.SendEvent("UI CONFIRM");
}
protected virtual void MouseOverFunction()
{
CurrentPanesCursorControlFsm.SetState("Accept Input");
}
protected virtual void WhileMouseOvered()
{
}
}
public class OnClickBorderArrow : OnClickClass
{
public string stateName;
protected override void ClickFunction()
{
base.ClickFunction();
}
protected override void MouseOverFunction()
{
CurrentPanesCursorControlFsm.SetState(stateName);
}
}
public class OnClickTab : OnClickClass
{
protected override void ClickFunction()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
SwitchInventoryTabTo(GetTargetPane());
}
protected override void MouseOverFunction()
{
CurrentPaneObject.GetComponent<InventoryItemManager>().SetSelected(((Component)this).gameObject, false);
}
private PaneTypes GetTargetPane()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
InventoryPaneListItem component = ((Component)this).gameObject.GetComponent<InventoryPaneListItem>();
return GetPaneType(component.currentPane);
}
private PaneTypes GetPaneType(InventoryPane pane)
{
return (PaneTypes)PaneList.GetPaneIndex(pane);
}
private PaneTypes GetPaneType(string paneName)
{
return (PaneTypes)PaneList.GetPaneIndex(paneName);
}
}
public class OnClickInventoryItem : OnClickClass
{
public class DraggingAction
{
public bool IsDragging;
private Vector2 MouseLastPos;
public void Update()
{
if (IsDragging)
{
DoDragAction();
}
if (Input.GetMouseButtonDown(0) && !IsDragging)
{
StartDragging();
}
if (Input.GetMouseButtonUp(0) && IsDragging)
{
Release();
}
}
private void StartDragging()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
IsDragging = true;
MouseLastPos = GetLocalMousePos();
}
private void Release()
{
IsDragging = false;
}
private void DoDragAction()
{
if (!IsInventoryOpen())
{
Release();
}
else
{
SetMapCoordsByMouse();
}
}
private Vector2 GetMouseDragDelta()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
Vector2 localMousePos = GetLocalMousePos();
Vector2 result = localMousePos - MouseLastPos;
MouseLastPos = localMousePos;
return result;
}
private void SetMapCoordsByMouse()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
//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_0036: 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_0040: 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_0047: 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)
if ((int)CurrentPaneType != 4 || MapZoomStateFsm.ActiveStateName != "Zoomed In")
{
Release();
return;
}
Vector2 mouseDragDelta = GetMouseDragDelta();
Vector2 val = Vector2.op_Implicit(((Component)ZoomedMapControl).transform.localPosition);
ZoomedMapControl.UpdateMapPosition(val + mouseDragDelta);
}
}
protected override void MouseOverFunction()
{
InventoryItemSelectable ownSelectable = GetOwnSelectable();
if ((Object)(object)ownSelectable == (Object)null)
{
Logger.LogError((object)("selectable is null for " + ((Object)((Component)this).gameObject).name));
return;
}
CurrentPaneObject.GetComponent<InventoryItemManager>().SetSelected(ownSelectable, (SelectionDirection?)null, false);
base.MouseOverFunction();
}
private InventoryItemSelectable GetOwnSelectable()
{
return ((Component)this).gameObject.GetComponent<InventoryItemSelectable>();
}
}
public class ScrollArrowHover : OnClickClass
{
internal enum Dir
{
Up,
Down
}
private const float SPEED = 0.2f;
public ScrollView ScrollControllerScript;
private Vector3 TravelVector = new Vector3(0f, 0.2f, 0f);
protected override void WhileMouseOvered()
{
//IL_000c: 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_0017: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)ScrollControllerScript).transform;
transform.localPosition += TravelVector;
}
internal void SetDirection(Dir direction)
{
if (direction == Dir.Down)
{
TravelVector.y = 0.2f;
}
else
{
TravelVector.y = -0.2f;
}
}
}
public class TestClicker : OnClickClass
{
protected override void ClickFunction()
{
Logger.LogInfo((object)("Click Test. " + SafeToString(((Object)((Component)this).gameObject).name)));
}
protected override void MouseOverFunction()
{
Logger.LogInfo((object)("Mouseover Test." + SafeToString(((Object)((Component)this).gameObject).name)));
}
protected override void WhileMouseOvered()
{
Logger.LogInfo((object)("do this every frame." + SafeToString(((Object)((Component)this).gameObject).name)));
}
}
public class ScrollHover : MonoBehaviour
{
private const float SCROLL_WHEEL_SPEED = 8f;
public PaneTypes MyPane;
public ScrollView ScrollControllerScript;
public bool CheckMouseOver()
{
//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_0010: Unknown result type (might be due to invalid IL or missing references)
//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_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)
//IL_0028: 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)
Vector2 val = Vector2.op_Implicit(((Component)this).transform.position);
Vector2 val2 = GetLocalMousePos() - val;
return ((Bounds)(ref ScrollControllerScript.contentBounds)).Contains(Vector2.op_Implicit(val2));
}
public void Update()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
if (IsInventoryOpen() && CurrentPaneType == MyPane)
{
if (!CheckMouseOver())
{
SetScrolling(setVal: false, instant: true);
}
else
{
Scroll();
}
}
}
private void Scroll()
{
//IL_002e: 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_0043: Unknown result type (might be due to invalid IL or missing references)
float axisRaw = Input.GetAxisRaw("Mouse ScrollWheel");
if (axisRaw != 0f)
{
SetScrolling(setVal: true);
float num = axisRaw * 8f;
Transform transform = ((Component)ScrollControllerScript).transform;
transform.localPosition -= new Vector3(0f, num, 0f);
}
else
{
SetScrolling(setVal: false);
}
}
}
[HarmonyPatch(typeof(InventoryPaneList), "Start")]
public class AfterInventoryIsCreated_Setup
{
[HarmonyPostfix]
private static void Postfix(InventoryPaneList __instance)
{
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Expected O, but got Unknown
//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null)
{
Logger.LogError((object)"Inventory Setup Hook Failed");
}
PaneList = __instance;
Transform transform = ((Component)__instance).transform;
try
{
HudCamera = ((Component)((Component)__instance).transform.parent.parent).GetComponent<Camera>();
}
catch (Exception ex)
{
Logger.LogError((object)"Getting Hud Camera Failed");
Logger.LogError((object)ex.Message);
}
try
{
TabbingControlFSM = ((Component)((Component)__instance).transform).GetComponent<PlayMakerFSM>();
}
catch (Exception ex2)
{
Logger.LogError((object)"Getting Tabbing Control FSM (\"Inventory Control\") Failed");
Logger.LogError((object)ex2.Message);
}
try
{
Transform obj = transform.Find("Border").Find("Arrows");
((Component)obj.Find("Arrow Left")).gameObject.AddComponent<OnClickBorderArrow>().stateName = "L Arrow";
((Component)obj.Find("Arrow Right")).gameObject.AddComponent<OnClickBorderArrow>().stateName = "R Arrow";
}
catch (Exception ex3)
{
Logger.LogError((object)"Setting up Arrow click scripts Failed");
Logger.LogError((object)ex3.Message);
}
try
{
foreach (Transform item in transform.Find("Border").Find("PaneListDisplay").Find("List Items"))
{
((Component)item).gameObject.AddComponent<BoxCollider2D>();
((Component)item).gameObject.AddComponent<OnClickTab>();
}
}
catch (Exception ex4)
{
Logger.LogError((object)"Getting Tabs Failed");
Logger.LogError((object)ex4.Message);
}
try
{
foreach (Transform item2 in transform.Find("Inv").Find("Inv_Items").Find("Needle Shift"))
{
Transform val2 = item2;
if (((Object)val2).name != "Spool Group")
{
((Component)val2).gameObject.AddComponent<OnClickInventoryItem>();
}
}
}
catch (Exception ex5)
{
Logger.LogError((object)"Failed attaching onclick to missed inv items");
Logger.LogError((object)ex5.Message);
}
try
{
MapZoomStateFsm = FSMUtility.LocateMyFSM(((Component)transform.Find("Map")).gameObject, "UI Control");
}
catch (Exception ex6)
{
Logger.LogError((object)"Failed setting up map zoom control.");
Logger.LogError((object)ex6.Message);
}
try
{
foreach (Transform item3 in transform.Find("Map").Find("World Map").Find("Map Offset")
.GetChild(0))
{
GameObject gameObject = ((Component)item3).gameObject;
if (((Object)((Component)item3).gameObject).name.StartsWith("Wide_map_"))
{
gameObject.AddComponent<BoxCollider2D>();
gameObject.AddComponent<OnClickInventoryItem>();
}
}
}
catch (Exception ex7)
{
Logger.LogError((object)"Failed attaching onclick to missed overmap items");
Logger.LogError((object)ex7.Message);
}
}
}
[HarmonyPatch(typeof(ScrollView), "Start")]
public class GetAllScrollViews
{
[HarmonyPostfix]
private static void Postfix(ScrollView __instance)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: 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_0071: Unknown result type (might be due to invalid IL or missing references)
ScrollArrowHover scrollArrowHover = ((Component)((Component)__instance.upArrow).transform.parent).gameObject.AddComponent<ScrollArrowHover>();
ScrollArrowHover scrollArrowHover2 = ((Component)((Component)__instance.downArrow).transform.parent).gameObject.AddComponent<ScrollArrowHover>();
scrollArrowHover.ScrollControllerScript = __instance;
scrollArrowHover2.ScrollControllerScript = __instance;
scrollArrowHover.SetDirection(ScrollArrowHover.Dir.Up);
scrollArrowHover2.SetDirection(ScrollArrowHover.Dir.Down);
ScrollHover scrollHover = ((Component)__instance).gameObject.AddComponent<ScrollHover>();
scrollHover.ScrollControllerScript = __instance;
RegisterScroller(scrollHover.MyPane = FindPaneTypeForThis(__instance), scrollHover);
}
private static void RegisterScroller(PaneTypes paneType, ScrollHover testH)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Invalid comparison between Unknown and I4
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
if ((int)paneType != -1)
{
ScrollHoverSet.Add(paneType, testH);
}
}
private static PaneTypes FindPaneTypeForThis(ScrollView instance)
{
return (PaneTypes)(((Object)((Component)instance).gameObject).name switch
{
"Equipment" => 0,
"Tool List" => 1,
"Quest List" => 2,
"Enemy List" => 3,
_ => -1,
});
}
}
[HarmonyPatch(typeof(GameMap), "Start")]
public class HookRealMapStart
{
[HarmonyPostfix]
private static void Postfix(GameMap __instance)
{
ZoomedMapControl = __instance;
}
}
[HarmonyPatch(typeof(InventoryItemSelectable), "add_OnSelected")]
public class TryOnSelected
{
[HarmonyPrefix]
private static void Prefix(InventoryItemSelectable __instance, Action<InventoryItemSelectable> __0)
{
((Component)__instance).gameObject.AddComponent<OnClickInventoryItem>();
}
}
[HarmonyPatch(typeof(InputHandler), "SetCursorVisible")]
public class OverrideCursorVisible
{
[HarmonyPrefix]
private static void Prefix(InputHandler __instance, ref bool value)
{
if (IsInventoryOpen())
{
value = true;
}
}
}
[HarmonyPatch(typeof(InputHandler), "Update")]
public class testing
{
[HarmonyPrefix]
private static void Prefix(InputHandler __instance)
{
if (IsInventoryOpen())
{
((OneAxisInputControl)__instance.inputActions.Attack).Enabled = false;
}
else
{
((OneAxisInputControl)__instance.inputActions.Attack).Enabled = true;
}
}
}
[HarmonyPatch(typeof(InventoryPaneInput), "Update")]
public class OnUpdateDo
{
[HarmonyPostfix]
private static void Postfix(InventoryPaneInput __instance, ref InventoryPaneList ___paneList, ref PaneTypes ___paneControl)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
//IL_0017: 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_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Invalid comparison between Unknown and I4
try
{
SwitchedPanesThisFrame = false;
if ((int)CurrentPaneType != (int)___paneControl)
{
SwitchedPanesThisFrame = true;
CurrentPaneType = ___paneControl;
CurrentPaneObject = ((Component)__instance).gameObject;
CurrentPanesCursorControlFsm = FSMUtility.LocateMyFSM(CurrentPaneObject, "Inventory Proxy");
}
if (Input.GetMouseButtonDown(1))
{
InventoryBack();
}
ScrollHover scrollHoverForPane = GetScrollHoverForPane(CurrentPaneType);
if ((Object)(object)scrollHoverForPane != (Object)null)
{
scrollHoverForPane.Update();
}
if ((int)CurrentPaneType == 4)
{
if (MapZoomStateFsm.ActiveStateName == "Wide Map" && Input.GetAxisRaw("Mouse ScrollWheel") > 0f)
{
CurrentPanesCursorControlFsm.SendEvent("UI CONFIRM");
}
if (MapZoomStateFsm.ActiveStateName == "Zoomed In" && Input.GetAxisRaw("Mouse ScrollWheel") < 0f)
{
MapBack();
}
if (MapZoomStateFsm.ActiveStateName == "Zoomed In")
{
MapDragging.Update();
}
_ = MapZoomStateFsm.ActiveStateName == "Marker Select Menu";
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error: " + ex.Message));
}
}
private static void InventoryBack()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
if ((int)CurrentPaneType != 4)
{
TabbingControlFSM.SendEvent("BACK");
}
else
{
MapBack();
}
}
private static void MapBack()
{
PlayMakerFSM val = FSMUtility.LocateMyFSM(CurrentPaneObject, "UI Control");
if (val.ActiveStateName == "Wide Map")
{
TabbingControlFSM.SendEvent("BACK");
}
else
{
val.SendEvent("UI CANCEL");
}
}
}
private const string modGUID = "com.bigfootmech.silksong.inventory_mouse";
internal static ManualLogSource Logger;
private readonly Harmony harmony = new Harmony("com.bigfootmech.silksong.inventory_mouse");
private const string CURSOR_CONTROL_FSM_NAME = "Inventory Proxy";
private const string MAP_STATE_OVERMAP = "Wide Map";
private const string MAP_STATE_ZOOMED = "Zoomed In";
private const string MAP_STATE_MARKERING = "Marker Select Menu";
private static bool SwitchedPanesThisFrame = false;
private static bool Scrolling = false;
private const int FRAMES_TO_BLOCK_MOUSEOVER_WHILE_SCROLLING = 100;
private static int ScrollSmoothCountdown = 0;
private static Camera HudCamera = null;
private static PlayMakerFSM TabbingControlFSM = null;
private static InventoryPaneList PaneList = null;
private static PaneTypes CurrentPaneType = (PaneTypes)(-1);
private static GameObject CurrentPaneObject = null;
private static PlayMakerFSM CurrentPanesCursorControlFsm = null;
private static PlayMakerFSM MapZoomStateFsm = null;
private static GameMap ZoomedMapControl = null;
private static OnClickInventoryItem.DraggingAction MapDragging = new OnClickInventoryItem.DraggingAction();
private static Dictionary<PaneTypes, ScrollHover> ScrollHoverSet = new Dictionary<PaneTypes, ScrollHover>();
private static bool IsInventoryOpen()
{
if ((Object)(object)TabbingControlFSM == (Object)null)
{
return false;
}
return TabbingControlFSM.ActiveStateName != "Closed";
}
private static bool IsScrolling()
{
if (!Scrolling)
{
return Input.GetAxisRaw("Mouse ScrollWheel") != 0f;
}
return true;
}
private static void SetScrolling(bool setVal, bool instant = false)
{
if (setVal)
{
Scrolling = true;
ScrollSmoothCountdown = 100;
return;
}
if (instant)
{
ScrollSmoothCountdown = 0;
}
else if (ScrollSmoothCountdown > 0)
{
ScrollSmoothCountdown--;
}
if (ScrollSmoothCountdown <= 0)
{
Scrolling = false;
}
}
public static Vector2 GetLocalMousePos()
{
//IL_0005: 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_000f: Unknown result type (might be due to invalid IL or missing references)
return Vector2.op_Implicit(HudCamera.ScreenToWorldPoint(Input.mousePosition));
}
private static ScrollHover GetScrollHoverForPane(PaneTypes currentPaneType)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return GeneralExtensions.GetValueSafe<PaneTypes, ScrollHover>(ScrollHoverSet, currentPaneType);
}
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin inventory_mouse_use is loaded!");
harmony.PatchAll();
}
private static string SafeToString(object ob)
{
return ob?.ToString() ?? "null";
}
private static void SwitchInventoryTabTo(PaneTypes pane)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected I4, but got Unknown
if (!((Object)(object)TabbingControlFSM == (Object)null))
{
TabbingControlFSM.FsmVariables.FindFsmInt("Target Pane Index").Value = (int)pane;
TabbingControlFSM.SendEvent("MOVE PANE TO");
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "inventory_mouse_use";
public const string PLUGIN_NAME = "Inventory Mouse for Silksong";
public const string PLUGIN_VERSION = "0.1.4";
}
}