-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.cs
More file actions
273 lines (247 loc) · 10.2 KB
/
Plugin.cs
File metadata and controls
273 lines (247 loc) · 10.2 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using ImGuiNET;
using System.Reflection;
using UnityEngine;
namespace TackleboxDbg
{
static class ModInfo
{
public const string PLUGIN_GUID = "TackleboxDbg";
public const string PLUGIN_NAME = "TackleboxDbg";
public const string PLUGIN_VERSION = "1.4.0";
}
[BepInPlugin(ModInfo.PLUGIN_GUID, ModInfo.PLUGIN_NAME, ModInfo.PLUGIN_VERSION)]
[BepInProcess("The Big Catch Tacklebox.exe")]
public class Plugin : BaseUnityPlugin
{
#region KEYBINDS
ConfigEntry<KeyboardShortcut> ToggleDebugKey;
ConfigEntry<KeyboardShortcut> RespawnCollectiblesKey;
ConfigEntry<KeyboardShortcut> ClearShreddersKey;
ConfigEntry<KeyboardShortcut> SaveStateKey;
ConfigEntry<KeyboardShortcut> LoadStateKey;
ConfigEntry<KeyboardShortcut> TeleportStateKey;
ConfigEntry<KeyboardShortcut> GiveWhistleKey;
ConfigEntry<KeyboardShortcut> ResetCheckpointsKey;
public static ConfigEntry<bool> OverrideDebugArrow;
#endregion
#region REFLECTION
static FieldInfo spewedCoin = AccessTools.DeclaredField(typeof(Collectible), "_spewedCoin");
static FieldInfo activeShredders = AccessTools.DeclaredField(typeof(ShredderManager), "_activeShredders");
#endregion
SaveStateManager SSManager;
private void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {ModInfo.PLUGIN_NAME} is loaded!");
Logger.LogInfo($"Detected Game version: {BuildDate.Version()}");
var harmony = new Harmony(ModInfo.PLUGIN_GUID);
try
{
harmony.PatchAll();
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to patch: " + ex));
}
ToggleDebugKey = Config.Bind("Inputs", "ToggleDebug", new KeyboardShortcut(KeyCode.F11), "The key for toggling Debug HUD");
RespawnCollectiblesKey = Config.Bind("Inputs", "RespawnCollectibles", new KeyboardShortcut(KeyCode.F10), "Respawn Coins/Fish");
ClearShreddersKey = Config.Bind("Inputs", "ClearShredders", new KeyboardShortcut(KeyCode.F9), "Despawn untethered shredders");
GiveWhistleKey = Config.Bind("Inputs", "GiveWhistle", new KeyboardShortcut(KeyCode.F8), "Give the player the whistle");
ResetCheckpointsKey = Config.Bind("Inputs", "ResetCheckpoints", new KeyboardShortcut(KeyCode.F7), "Give the player the whistle");
TeleportStateKey = Config.Bind("Inputs", "TeleportState", new KeyboardShortcut(KeyCode.F5), "Teleport to the saved game data's position");
LoadStateKey = Config.Bind("Inputs", "LoadState", new KeyboardShortcut(KeyCode.F4), "Load the saved game data");
SaveStateKey = Config.Bind("Inputs", "SaveState", new KeyboardShortcut(KeyCode.F3), "Save the current game data");
OverrideDebugArrow = Config.Bind("Misc", "OverrideDbgArrow", true, "Changes Debug Arrow behavior to display the respawn area");
SSManager = new();
}
private void OnEnable()
{
PatchesCommon.Layout += OnLayout;
}
private void OnDisable()
{
PatchesCommon.Layout -= OnLayout;
}
private void Update()
{
if (ToggleDebugKey.Value.IsDown())
{
Manager._instance.ToggleDebugEnabled();
}
if (Manager._instance._debugEnabled)
{
if (RespawnCollectiblesKey.Value.IsDown())
{
ResetCollectibles();
ResetMookCoins();
}
if (ClearShreddersKey.Value.IsDown())
{
BurrowShredders();
}
if (GiveWhistleKey.Value.IsDown())
{
GiveWhistle();
}
if (ResetCheckpointsKey.Value.IsDown())
{
ResetCheckpoints();
}
if (SaveStateKey.Value.IsDown())
{
SSManager.SaveCurrentDataToQuickSlot();
}
if (LoadStateKey.Value.IsDown())
{
SSManager.LoadCurrent();
}
if (TeleportStateKey.Value.IsDown())
{
SSManager.LoadCurrentNonSaveData();
}
}
}
private void OnLayout()
{
if (ImGui.BeginTabItem("Tacklebox Debug"))
{
if (ImGui.CollapsingHeader("SaveStates"))
{
if (SSManager.IsInGame)
{
if (ImGui.Button("Load"))
{
SSManager.LoadCurrent();
}
ImGui.SameLine();
if (ImGui.Button("Teleport"))
{
SSManager.LoadCurrentNonSaveData();
}
}
ImGui.ListBox("", ref SSManager.CurrentIndex, SSManager.SaveStateNames, SSManager.SaveStateNames.Length, 10);
if (ImGui.Button("Delete"))
{
SSManager.DeleteCurrent();
}
if (SSManager.IsInGame)
{
ImGui.SameLine();
if (ImGui.Button("Create"))
{
SSManager.SaveCurrentDataToNewFile();
}
}
if (ImGui.Button("Open SaveStates Folder"))
{
SSManager.OpenSaveStateFolder();
}
}
ImGui.EndTabItem();
}
}
void ResetCollectibles()
{
var currentCapt = Manager.GetPlayerMachine()._currentCapturingCapturable;
#if V1_2_4
var captList = FindObjectsByType<CapturableWalkingFish>(FindObjectsInactive.Include, FindObjectsSortMode.None);
#elif V1_1_0
var captList = FindObjectsByType<IntroWalkingFish>(FindObjectsInactive.Include, FindObjectsSortMode.None);
#endif
foreach (var fish in captList)
{
Capturable capturable = fish._capturable;
if (capturable == currentCapt)
continue;
if (capturable._state == Capturable.State.Captured)
{
fish._agent.Enable();
capturable._state = Capturable.State.NotCapturing;
fish.PlayerRespawned(null);
fish._gameObject.SetActive(true);
}
}
var coinList = FindObjectsByType<Coin>(FindObjectsInactive.Include, FindObjectsSortMode.None);
var coinMgr = Manager.GetCoinManager();
foreach (var coin in coinList)
{
if (!coin._collectible._collected ||
coinMgr._coinPoolSmall._entries.Contains(coin) || coinMgr._coinPoolMedium._entries.Contains(coin) || coinMgr._coinPoolLarge._entries.Contains(coin))
continue;
coin._collectible._collected = false;
coin._artObject.SetActive(true);
coin._gameObject.SetActive(true);
}
coinMgr._coinPoolSmall.DisableAll();
coinMgr._coinPoolMedium.DisableAll();
coinMgr._coinPoolLarge.DisableAll();
}
void ResetCheckpoints()
{
var zipList = FindObjectsByType<ZipRing>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach (var zip in zipList)
{
if (zip._activatedReference is not null && zip._activatedReference.GetValue())
// The zips don't instant-deactivate properly if they're active.
zip.Deactivate(IsInstant: !zip._gameObject.activeInHierarchy);
}
}
void BurrowShredders()
{
var shredMgr = FindFirstObjectByType<ShredderManager>();
var activeShredderList = activeShredders.GetValue(shredMgr) as List<SandShredder>;
foreach (var shredder in activeShredderList)
{
shredder.Burrow();
}
}
void GiveWhistle()
{
Manager.GetPlayerMachine()._hasWhistle.SetValue(true);
}
void ResetMookCoins()
{
var mooks = FindObjectsByType<BasicMook>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
var turretMooks = FindObjectsByType<MortarDesertMook>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
var saveData = Manager.GetSaveManager()?._currentSaveData;
if (saveData == null)
return;
foreach (var mook in mooks)
{
ResetAgentCollectibles(mook._agent, saveData);
}
foreach (var mook in turretMooks)
{
ResetAgentCollectibles(mook._headAgent, saveData);
}
#if V1_2_4
Patch_124.ClearCoins();
#endif
}
void ResetAgentCollectibles(FiletNavAgent agent, SaveData saveData)
{
foreach (var collectible in agent._collectibles)
{
collectible._collected = false;
var guid = collectible._asset._guid;
if ((saveData._collectibles?.Remove(guid)).GetValueOrDefault(false))
{
Logger.LogDebug("Reset coins for: " + agent.ToString());
}
else
{
var emittedCoin = spewedCoin.GetValue(collectible) as Coin;
if (emittedCoin != null && emittedCoin._isActiveAndEnabled)
{
Logger.LogDebug("Despawned coins for: " + agent.ToString());
emittedCoin._gameObject.SetActive(false);
spewedCoin.SetValue(collectible, null);
}
}
}
}
}
}