using System;
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 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: AssemblyDescription("Use Mouse in the Inventory (Work in Progress).")]
[assembly: AssemblyFileVersion("0.1.7.0")]
[assembly: AssemblyInformationalVersion("0.1.7+ff7137623f3f1da7b8d9e1cd840f9413a41efb54")]
[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.7.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.7")]
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 virtual void OnMouseOver()
{
if (IsInventoryOpen() && !IsScrolling())
{
WhileMouseOvered();
if (!MouseAlreadyIn || SwitchedPanesThisFrame)
{
MouseAlreadyIn = true;
MouseOverFunction();
}
}
}
public virtual void OnMouseExit()
{
MouseAlreadyIn = false;
}
protected virtual void ClickFunction()
{
CurrentPanesCursorControlFsm.SendEvent("UI CONFIRM");
}
protected virtual void MouseOverFunction()
{
CurrentPanesCursorControlFsm.SetState("Accept Input");
}
protected virtual void WhileMouseOvered()
{
}
protected void VisualSelectMyObj()
{
CurrentPaneObject.GetComponent<InventoryItemManager>().SetSelected(((Component)this).gameObject, false);
}
}
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()
{
VisualSelectMyObj();
}
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
{
protected override void MouseOverFunction()
{
if (!((Object)(object)CurrentPaneObject == (Object)null))
{
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 OnMouseoverRosaryCannon : OnClickInventoryItem
{
public override void OnMouseOver()
{
PreventBackOut = true;
base.OnMouseOver();
}
public override void OnMouseExit()
{
PreventBackOut = false;
base.OnMouseExit();
}
}
public class OnMouseoverAttackSlotAuxRosaryCannon : OnClickInventoryItem
{
private InventoryToolCrestSlot slotScript;
public override void OnMouseOver()
{
if ((Object)(object)slotScript == (Object)null)
{
slotScript = ((Component)this).gameObject.GetComponent<InventoryToolCrestSlot>();
}
if ((Object)(object)slotScript != (Object)null && ((InventoryItemSelectable)slotScript).DisplayName == "Rosary Cannon")
{
PreventBackOut = true;
}
base.OnMouseOver();
}
public override void OnMouseExit()
{
PreventBackOut = false;
base.OnMouseExit();
}
}
public class MarkerClicker : OnClickClass
{
public MapMarkerMenu MarkerController;
public int Index = -1;
protected override void ClickFunction()
{
if (IsInventoryOpen() && MarkerController.inPlacementMode)
{
MarkerController.timer = MarkerController.uiPause;
MarkerController.selectedIndex = Index;
MarkerController.MarkerSelect(MarkerController.selectedIndex, false);
}
}
}
public class ShowHideCompletedQuestsClicker : OnClickClass
{
protected override void ClickFunction()
{
DoInjectMenuSuperForCompletedQuestToggle = true;
}
protected override void MouseOverFunction()
{
VisualSelectMyObj();
}
}
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)));
VisualSelectMyObj();
}
protected override void WhileMouseOvered()
{
Logger.LogInfo((object)("do this every frame for obj: " + SafeToString(((Object)((Component)this).gameObject).name)));
}
}
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 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);
}
}
}
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();
}
public void Stop()
{
Release();
}
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);
}
}
[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);
}
try
{
Transform obj2 = transform.Find("Quests").Find("Toggle Completed Action").Find("ActionButtonIcon");
((Component)obj2).gameObject.AddComponent<ShowHideCompletedQuestsClicker>();
((Component)obj2).gameObject.AddComponent<BoxCollider2D>();
Logger.LogInfo((object)"Attached comps");
}
catch (Exception ex8)
{
Logger.LogError((object)"Failed attaching onclick to missed inv items");
Logger.LogError((object)ex8.Message);
}
}
private static void AttachTestClicker(Transform tfm)
{
AttachTestClicker(((Component)tfm).gameObject);
}
private static void AttachTestClicker(GameObject go)
{
go.AddComponent<TestClicker>();
go.AddComponent<BoxCollider2D>();
}
}
[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)
{
GameObject gameObject = ((Component)__instance).gameObject;
OnClickInventoryItem onClickInventoryItem = default(OnClickInventoryItem);
bool flag = gameObject.TryGetComponent<OnClickInventoryItem>(ref onClickInventoryItem);
if (((Object)gameObject).name == "Rosary Cannon")
{
if (flag)
{
Object.Destroy((Object)(object)onClickInventoryItem);
}
gameObject.AddComponent<OnMouseoverRosaryCannon>();
}
else if (((Object)gameObject).name == "Attack Slot(Clone)")
{
if (flag)
{
Object.Destroy((Object)(object)onClickInventoryItem);
}
gameObject.AddComponent<OnMouseoverAttackSlotAuxRosaryCannon>();
}
else if (!flag)
{
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 DisableAttackForMouseClickJank
{
[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_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Invalid comparison between Unknown and I4
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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");
}
bool mouseButtonDown = Input.GetMouseButtonDown(1);
bool mouseButtonDown2 = Input.GetMouseButtonDown(3);
bool mouseButtonDown3 = Input.GetMouseButtonDown(4);
if ((int)CurrentPaneType != 1)
{
PreventBackOut = false;
}
if (mouseButtonDown)
{
InventoryBack();
}
if (mouseButtonDown2)
{
MapZoomStateFsm.SendEvent("UI CANCEL");
}
ScrollHover scrollHoverForPane = GetScrollHoverForPane(CurrentPaneType);
if ((Object)(object)scrollHoverForPane != (Object)null)
{
scrollHoverForPane.Update();
}
if ((int)CurrentPaneType != 4)
{
return;
}
if (MapZoomStateFsm.ActiveStateName == "Wide Map")
{
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f || mouseButtonDown3)
{
CurrentPanesCursorControlFsm.SendEvent("UI CONFIRM");
}
MapDragging.Stop();
}
UnstuckZoomControls();
if (MapZoomStateFsm.ActiveStateName == "Zoomed In")
{
if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f)
{
MapBack();
}
bool flag = WasDoubleClick();
if (flag)
{
JustEnteredMarkerState = true;
}
if (mouseButtonDown3 || flag)
{
MapZoomStateFsm.SendEvent("UI CONFIRM");
}
MapDragging.Update();
}
if (MapZoomStateFsm.ActiveStateName == "Marker Select Menu")
{
MapDragging.Stop();
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error: " + ex.Message));
}
}
private static bool WasDoubleClick()
{
DoubleClickTimer -= Time.unscaledDeltaTime;
DoubleClickTimer = Math.Max(DoubleClickTimer, 0f);
bool mouseButtonDown = Input.GetMouseButtonDown(0);
if (Input.GetMouseButtonUp(0))
{
AwaitMouseUp = false;
}
if (!mouseButtonDown || AwaitMouseUp)
{
return false;
}
if (DoubleClickTimer != 0f)
{
DoubleClickTimer = 0f;
return true;
}
DoubleClickTimer = 0.25f;
AwaitMouseUp = true;
return false;
}
private static void UnstuckZoomControls()
{
if (MapZoomStateFsm.ActiveStateName == "Map Zoom")
{
CountTransitionFrames--;
if (CountTransitionFrames == 0)
{
CountTransitionFrames = 3;
MapZoomStateFsm.SendEvent("ZOOMED IN");
}
}
if (MapZoomStateFsm.ActiveStateName == "Zoom Out")
{
CountTransitionFrames--;
if (CountTransitionFrames == 0)
{
CountTransitionFrames = 3;
MapZoomStateFsm.SendEvent("ZOOMED OUT");
}
}
}
private static void InventoryBack()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
if (!PreventBackOut)
{
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");
}
}
}
[HarmonyPatch(typeof(MapMarkerMenu), "Start")]
public class MapMarkerStartInject
{
[HarmonyPostfix]
private static void Postfix(MapMarkerMenu __instance)
{
for (int i = 0; i < __instance.markers.Length; i++)
{
GameObject gameObject = ((Component)__instance.markers[i]).gameObject;
gameObject.AddComponent<BoxCollider2D>();
MarkerClicker markerClicker = gameObject.AddComponent<MarkerClicker>();
markerClicker.MarkerController = __instance;
markerClicker.Index = i;
}
}
}
[HarmonyPatch(typeof(MapMarkerMenu), "Update")]
public class PinsCursorMouseControl
{
[HarmonyPostfix]
private static void Postfix(MapMarkerMenu __instance, ref GameObject ___placementCursor, ref List<GameObject> ___collidingMarkers, ref GameMap ___gameMap, ref GameObject ___gameMapObject, ref bool ___inPlacementMode, ref float ___placementTimer, ref float ___panSpeed)
{
//IL_0022: 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_002a: 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)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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_00a0: 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_0060: 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_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: 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)
if (!___inPlacementMode)
{
return;
}
if (((OneAxisInputControl)ManagerSingleton<InputHandler>.Instance.inputActions.QuickMap).WasPressed)
{
__instance.MarkerSelectRight();
}
Vector2 mousePosLimited = GetLocalMousePos();
Bounds mapMarkerScrollArea = ___gameMap.mapMarkerScrollArea;
bool num = IsMousePastEdge(mapMarkerScrollArea, mousePosLimited);
if (num)
{
Vector3 panVecAndConstrainMouse = GetPanVecAndConstrainMouse(ref mousePosLimited, mapMarkerScrollArea, ___panSpeed, ___placementTimer);
if (___gameMap.CanMarkerPan())
{
Transform transform = ___gameMapObject.transform;
transform.localPosition -= panVecAndConstrainMouse;
___gameMap.KeepWithinBounds(Vector2.op_Implicit(InventoryMapManager.SceneMapMarkerZoomScale));
}
}
bool flag = false;
if (!num && IsAPinSelected(___collidingMarkers))
{
flag = AreTwoPointsClose(p2: GetPinCorrectedPos(___collidingMarkers, ___gameMap), p1: mousePosLimited);
}
ProcessMouseCursorMovement(ref ___placementCursor, flag, mousePosLimited);
if (!num && Input.GetMouseButtonDown(0))
{
ProcessMarkerPutRemove(__instance, flag);
}
if (Input.GetAxisRaw("Mouse ScrollWheel") < 0f)
{
__instance.MarkerSelectLeft();
}
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0f)
{
__instance.MarkerSelectRight();
}
JustEnteredMarkerState = false;
}
private static Vector3 GetPanVecAndConstrainMouse(ref Vector2 mousePosLimited, Bounds bounds, float ___panSpeed, float ___placementTimer)
{
//IL_0002: 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)
//IL_000e: 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_0016: 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)
//IL_0022: 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_0038: 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_0071: 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_009b: 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)
//IL_00c8: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = ((Bounds)(ref bounds)).center - ((Bounds)(ref bounds)).extents;
Vector3 val2 = ((Bounds)(ref bounds)).center + ((Bounds)(ref bounds)).extents;
float num = PIN_MAP_PAN_SPEED * ___panSpeed * Time.unscaledDeltaTime;
Vector3 result = default(Vector3);
if (mousePosLimited.x < val.x)
{
mousePosLimited.x = val.x;
if (___placementTimer <= 0f)
{
result.x = 0f - num;
}
}
else if (mousePosLimited.x > val2.x)
{
mousePosLimited.x = val2.x;
if (___placementTimer <= 0f)
{
result.x = num;
}
}
if (mousePosLimited.y < val.y)
{
mousePosLimited.y = val.y;
if (___placementTimer <= 0f)
{
result.y = 0f - num;
}
}
else if (mousePosLimited.y > val2.y)
{
mousePosLimited.y = val2.y;
if (___placementTimer <= 0f)
{
result.y = num;
}
}
return result;
}
private static bool IsMousePastEdge(Bounds bounds, Vector2 mousePosLimited)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return !((Bounds)(ref bounds)).Contains(Vector2.op_Implicit(mousePosLimited));
}
private static void ProcessMouseCursorMovement(ref GameObject placementCursor, bool mouseoverPin, Vector2 mousePos)
{
//IL_0008: 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)
if (JustEnteredMarkerState)
{
MoveCursorToMouse(ref placementCursor, mousePos);
}
if (!mouseoverPin && HasMouseMoved())
{
MoveCursorToMouse(ref placementCursor, mousePos);
}
}
private static Vector2 GetPinCorrectedPos(List<GameObject> collidingMarkers, GameMap gameMap)
{
//IL_000b: 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_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
return Vector2.op_Implicit(collidingMarkers.Last().transform.position - ((Component)gameMap).transform.parent.position);
}
private static bool AreTwoPointsClose(Vector2 p1, Vector2 p2)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//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)
Vector2 val = p1 - p2;
return ((Vector2)(ref val)).magnitude < MAGIC_GAME_PIN_COLLIDER_DISTANCE;
}
private static bool IsAPinSelected(List<GameObject> collidingMarkers)
{
return collidingMarkers.Count > 0;
}
private static void MoveCursorToMouse(ref GameObject placementCursor, Vector2 mousePos)
{
//IL_0007: 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)
placementCursor.transform.position = Vector2.op_Implicit(mousePos);
}
private static void ProcessMarkerPutRemove(MapMarkerMenu instance, bool mouseover)
{
if (mouseover)
{
instance.RemoveMarker();
}
else
{
instance.PlaceMarker();
}
}
private static bool IsMouseWithinBounds(Vector2 mousePos, float placementCursorMinX, float placementCursorMaxX, float placementCursorMinY, float placementCursorMaxY)
{
//IL_0000: 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_0016: 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 (mousePos.x < placementCursorMinX)
{
return false;
}
if (mousePos.x > placementCursorMaxX)
{
return false;
}
if (mousePos.x < placementCursorMinY)
{
return false;
}
if (mousePos.x > placementCursorMaxY)
{
return false;
}
return true;
}
private static bool HasMouseMoved()
{
if (Input.GetAxis("Mouse X") == 0f)
{
return Input.GetAxis("Mouse Y") != 0f;
}
return true;
}
}
[HarmonyPatch(typeof(InventoryItemQuestManager), "Update")]
public class InjectSuperCommandForCompletedQuestToggle
{
[HarmonyPrefix]
private static void Prefix(InventoryItemQuestManager __instance)
{
if (DoInjectMenuSuperForCompletedQuestToggle)
{
((OneAxisInputControl)ManagerSingleton<InputHandler>.Instance.inputActions.MenuSuper).thisState.State = true;
DoInjectMenuSuperForCompletedQuestToggle = false;
}
}
}
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_HALF_ZOOM = "Map Zoom";
private const string MAP_STATE_HALF_UNZOOM = "Zoom Out";
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 float MAGIC_GAME_PIN_COLLIDER_DISTANCE = 0.57f;
private static float PIN_MAP_PAN_SPEED = 3f;
private const float DOUBLE_CLICK_DELAY_MAX = 0.25f;
private const int FRAMES_TO_TRANSITION = 3;
private static int CountTransitionFrames = 3;
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 DraggingAction MapDragging = new DraggingAction();
private static Dictionary<PaneTypes, ScrollHover> ScrollHoverSet = new Dictionary<PaneTypes, ScrollHover>();
private static float DoubleClickTimer = 0f;
private static bool AwaitMouseUp = false;
private static bool JustEnteredMarkerState = false;
private static bool DoInjectMenuSuperForCompletedQuestToggle = false;
private static bool PreventBackOut = false;
private static bool IsInventoryOpen()
{
if ((Object)(object)TabbingControlFSM == (Object)null)
{
return false;
}
string activeStateName = TabbingControlFSM.ActiveStateName;
if (activeStateName == "Closed" || activeStateName == "Init")
{
return false;
}
return true;
}
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.7";
}
}