-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
221 lines (197 loc) · 6.25 KB
/
Plugin.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using BepInEx;
using BepInEx.Logging;
using BepInEx.IL2CPP;
using UnityEngine;
using HarmonyLib;
using UnhollowerRuntimeLib;
using System.Collections.Generic;
namespace FasterCrafting {
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BasePlugin {
internal static new ManualLogSource Log;
public override void Load() {
// Plugin startup logic
Plugin.Log = base.Log;
Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
Harmony.CreateAndPatchAll(typeof(FasterCraft));
Harmony.CreateAndPatchAll(typeof(Warper));
}
public enum SynthMode {
NONE,
CRAFT,
UPGRADE
}
[HarmonyPatch]
public class FasterCraft {
public static UIStrengthening strengthMenu = null;
public static UICraftMenu craftMenu = null;
public static UICraftResult craftResult = null;
public static UICraftSuccess success = null;
public static CursorController cursor = null;
public static CursorLinker lastSelect = null;
public static ButtonWorkBase okBtn = null;
//public static bool canSkip = false;
public static bool startSynthAnim = false;
public static bool startResultAnim = false;
public static bool doneUpgrade = false;
public static SynthMode synthMode = SynthMode.NONE;
public static bool TrytoSearch(SynthMode mode) {
CursorLinkConnector parent;
switch (mode) {
case SynthMode.CRAFT: {
parent = craftMenu;
okBtn = parent.GetComponentInChildren<UICraftSynthesisOK>(true);
if (okBtn == null) {
Log.LogError("Failed to find OK Button!");
return false;
}
break;
}
case SynthMode.UPGRADE: {
parent = strengthMenu;
okBtn = parent.GetComponentInChildren<UIStrengtheningOK>(true);
if (okBtn == null) {
Log.LogError("Failed to find OK Button!");
return false;
}
break;
}
default: {
Log.LogError("No SynthMode defined!");
return false;
}
}
success = parent.GetComponentInChildren<UICraftSuccess>(true);
if (success == null) {
Log.LogError("Failed to find success Component!");
return false;
}
cursor = parent.GetComponentInChildren<CursorController>(true);
if (cursor == null) {
Log.LogError("Failed to find cursor Component!");
return false;
}
return true;
}
[HarmonyPatch(typeof(UICraftMenu), "Start")]
[HarmonyPostfix]
public static void StartCraft(UICraftMenu __instance) {
synthMode = SynthMode.CRAFT;
craftMenu = __instance;
Log.LogInfo("Starting crafting shorcut");
}
[HarmonyPatch(typeof(UICraftMenu), "OnDestroy")]
[HarmonyPostfix]
public static void EndCraft() {
synthMode = SynthMode.NONE;
craftMenu = null;
craftResult = null;
success = null;
cursor = null;
lastSelect = null;
okBtn = null;
startSynthAnim = false;
doneUpgrade = false;
Log.LogInfo("Ending crafting shorcut");
}
[HarmonyPatch(typeof(UIStrengthening), "Start")]
[HarmonyPostfix]
public static void StartUpgrade(UIStrengthening __instance) {
synthMode = SynthMode.UPGRADE;
strengthMenu = __instance;
Log.LogInfo("Starting upgrade shorcut");
}
[HarmonyPatch(typeof(UIStrengthening), "OnDestroy")]
[HarmonyPostfix]
public static void EndUpgrade() {
synthMode = SynthMode.NONE;
strengthMenu = null;
craftResult = null;
success = null;
cursor = null;
lastSelect = null;
okBtn = null;
startSynthAnim = false;
doneUpgrade = false;
Log.LogInfo("Ending upgrade shorcut");
}
[HarmonyPatch(typeof(UICraftResult), "Start")]
[HarmonyPostfix]
public static void ResultStart(UICraftResult __instance) {
if (synthMode == SynthMode.NONE) {
return;
}
craftResult = __instance;
}
[HarmonyPatch(typeof(UICraftResult), "Update")]
[HarmonyPostfix]
public static void ResultUpdate() {
if (success == null || cursor == null || okBtn == null) {
Log.LogInfo($"Something is missing");
bool found = TrytoSearch(synthMode);
if (!found) return;
}
//success.IsDone() start at false
//Log.LogInfo($"canSkip:{canSkip}\tresultplay:{craftResult.isPlaying}\tsuccess:{success.IsDone()}");
//Log.LogInfo($"cursor focus: {cursor.NowFocusObject.gameObject.name}\nok button: {okBtn.gameObject.name}");
if (craftResult.isPlaying) {
startSynthAnim = true;
}
if (!craftResult.isPlaying && startSynthAnim && success.isActiveAndEnabled) {
startSynthAnim = false;
startResultAnim = true;
}
if (!success.isActiveAndEnabled && startResultAnim) {
startResultAnim = false;
if (synthMode == SynthMode.UPGRADE) {
doneUpgrade = true;
}
}
if (doneUpgrade && lastSelect != null) {
doneUpgrade = false;
cursor.NextFocusObject = lastSelect;
cursor.NowFocusObject = lastSelect;
Log.LogInfo("Try to change back position");
}
}
[HarmonyPatch(typeof(UIMainController), "Update")]
[HarmonyPostfix]
public static void InputUpdate() {
if (RF5Input.Pad.End(RF5Input.Key.PS) && !startResultAnim && !startSynthAnim) {
if (synthMode == SynthMode.CRAFT && craftMenu != null) {
Log.LogInfo("Crafting...");
lastSelect = cursor?.NowFocusObject;
okBtn?.ButtonWork(RF5Input.Key.A);
}
else if (synthMode == SynthMode.UPGRADE && strengthMenu != null && !doneUpgrade) {
Log.LogInfo("Upgrading...");
lastSelect = cursor?.NowFocusObject;
okBtn?.ButtonWork(RF5Input.Key.A);
}
}
}
}
[HarmonyPatch]
public class Warper {
[HarmonyPatch(typeof(UICraftMenu), nameof(UICraftMenu.CanRequestCraftNum))]
[HarmonyPostfix]
public static void CanRequestPatch(UICraftMenu __instance, ref bool __result) {
if (__instance.CraftNum == 1 || __instance.CraftNum == __instance.CraftNumMax) {
__result = true;
}
}
[HarmonyPatch(typeof(UICraftMenu), nameof(UICraftMenu.RequestCraftNum))]
[HarmonyPrefix]
public static void RequestPatch(UICraftMenu __instance, ref bool isLeft) {
if (__instance.CraftNum == 1 && isLeft) {
__instance.CraftNum = __instance.CraftNumMax;
isLeft = false;
}
else if (__instance.CraftNum == __instance.CraftNumMax && !isLeft) {
__instance.CraftNum = 1;
isLeft = true;
}
}
}
}
}