-
Notifications
You must be signed in to change notification settings - Fork 1
/
RememberBreakDownItem.cs
101 lines (81 loc) · 2.77 KB
/
RememberBreakDownItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using Harmony;
using MelonLoader;
using Il2Cpp = Il2CppSystem.Collections.Generic;
internal static class RememberBreakDownItem {
internal class RememberBreakDownItemMod : MelonMod {
public override void OnApplicationStart() {
UnityEngine.Debug.Log($"[{InfoAttribute.Name}] version {InfoAttribute.Version} loaded!");
}
}
private static readonly Dictionary<string, int> rememberedToolIDs = new Dictionary<string, int>();
private static int lastUsedID = -1;
[HarmonyPatch(typeof(Panel_BreakDown), "Update", new Type[0])]
private static class KeyboardShortcuts {
private static void Postfix(Panel_BreakDown __instance) {
if (!__instance.IsEnabled() || InterfaceManager.ShouldImmediatelyExitOverlay()
|| InputManager.GetEscapePressed(__instance) || __instance.IsBreakingDown())
return;
if (__instance.m_FramesInPanel > 1 && Utils.IsMouseActive()) {
float movement = Utils.GetMenuMovementHorizontal(__instance, true, true);
if (movement < 0) {
__instance.OnPrevTool();
} else if (movement > 0) {
__instance.OnNextTool();
} else if (InputManager.GetRadialButton(__instance)) {
__instance.OnBreakDown();
}
}
}
}
[HarmonyPatch(typeof(Panel_BreakDown), "OnBreakDown", new Type[0])]
private static class Store {
private static void Prefix(Panel_BreakDown __instance) {
BreakDown breakDown = __instance.m_BreakDown;
if (breakDown == null)
return;
string breakDownName = breakDown.m_LocalizedDisplayName.m_LocalizationID;
GearItem selectedTool = __instance.GetSelectedTool();
int instanceId = (selectedTool == null) ? 0 : selectedTool.m_InstanceID;
rememberedToolIDs[breakDownName] = instanceId;
lastUsedID = instanceId;
}
}
[HarmonyPatch(typeof(Panel_BreakDown), "Enable", new Type[] { typeof(bool) })]
private static class Load {
private static void Postfix(Panel_BreakDown __instance, bool enable) {
if (!enable)
return;
BreakDown breakDown = __instance.m_BreakDown;
if (breakDown == null)
return;
string breakDownName = breakDown.m_LocalizedDisplayName.m_LocalizationID;
if (rememberedToolIDs.ContainsKey(breakDownName)) {
Use(__instance, rememberedToolIDs[breakDownName]);
} else {
Use(__instance, lastUsedID);
}
__instance.m_FramesInPanel = 0;
__instance.Update();
}
}
private static void Use(Panel_BreakDown panel, int toolInstanceID) {
if (toolInstanceID == 0) {
panel.m_SelectedToolItemIndex = 0;
return;
}
Il2Cpp.List<GearItem> tools = panel.m_Tools;
int index = -1;
for (int i = 0; i < tools.Count; ++i) {
GearItem tool = tools[i];
if (tool != null && tool.m_InstanceID == toolInstanceID) {
index = i;
break;
}
}
if (index >= 0) {
panel.m_SelectedToolItemIndex = index;
}
}
}