-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMiniDebug.cs
More file actions
361 lines (314 loc) · 12.9 KB
/
Copy pathMiniDebug.cs
File metadata and controls
361 lines (314 loc) · 12.9 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GlobalEnums;
using HutongGames.PlayMaker.Actions;
using IL.HutongGames.PlayMaker.Actions;
using MiniDebug.Hitbox;
using MiniDebug.Util;
using Modding;
using On.HutongGames.PlayMaker.Actions;
using UnityEngine;
using UnityEngine.SceneManagement;
using USceneManager = UnityEngine.SceneManagement.SceneManager;
namespace MiniDebug
{
public class MiniDebug : MonoBehaviour
{
private static MiniDebug _instance;
public static MiniDebug Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<MiniDebug>();
}
if (_instance == null)
{
GameObject gameObject = new GameObject();
_instance = gameObject.AddComponent<MiniDebug>();
_instance.SaveStateManager = gameObject.AddComponent<SaveStateManager>();
_instance.HitboxManager = gameObject.AddComponent<HitboxManager>();
DontDestroyOnLoad(gameObject);
}
return _instance;
}
}
// Vanilla game object references
private static HeroController HC => HeroController.instance;
private static GameManager GM => GameManager.instance;
private static PlayerData PD
{
get => PlayerData.instance;
set => PlayerData.instance = value;
}
private static Rigidbody2D _hcRb2d;
private static Rigidbody2D HCRb2d
=> _hcRb2d == null
? _hcRb2d = HC.GetField<HeroController, Rigidbody2D>("rb2d")
: _hcRb2d;
// MiniDebug sub-components
public Settings Settings { get; private set; } = new Settings();
public SaveStateManager SaveStateManager { get; private set; }
public HitboxManager HitboxManager { get; private set; }
// Active cheat values
private bool _noclip;
public bool NoClip
{
get => _noclip;
private set
{
_noclip = value;
if (_noclip)
{
_noclipPos = HC.transform.position;
}
}
}
private bool _cameraFollow;
public bool CameraFollow
{
get => _cameraFollow;
private set
{
_cameraFollow = value;
if (!CameraFollow)
{
GM.cameraCtrl.SetField("isGameplayScene", GM.IsGameplayScene());
}
}
}
private float _timescale = 1f;
public float TimeScale
{
get => _timescale;
private set
{
_timescale = value;
if (_timescale == 1f && Time.timeScale != 0f)
{
Time.timeScale = 1f;
}
}
}
public bool Superslides { get; private set; } = true;
public bool ShowSpeed { get; private set; }
public bool VignetteDisabled { get; private set; }
public bool InfSoul { get; private set; }
public bool InfHealth { get; private set; }
public int LoadAdder { get; private set; } = 1;
public int activeLoad { get; private set; }
// Cheat method dictionary, filled in ReloadSettings
private Dictionary<string, Action> _binds;
// Misc fields
private readonly List<Renderer> _invRenders = new List<Renderer>();
private Vector3 _noclipPos;
public bool AcceptingInput { get; set; } = true;
private Vector3 cameraControllerPosition;
private TransitionPoint[] loadzones;
public delegate void UpdateEvent();
public event UpdateEvent OnUpdate;
private void Start()
{
Directory.CreateDirectory(Application.persistentDataPath + "/MiniDebug Savestates");
ReloadSettings();
Camera.onPreCull += OnPreCullCallback;
Camera.onPostRender += OnPostRenderCallback;
}
private void Update()
{
OnUpdate?.Invoke();
if (AcceptingInput)
{
foreach ((string key, Action action) in _binds)
{
if (Input.GetKeyDown(key))
{
action();
}
}
}
HC.vignette.enabled = !VignetteDisabled;
if (InfHealth)
{
HC.MaxHealth();
}
if (InfSoul)
{
HC.AddMPCharge(999);
}
if (Time.timeScale != TimeScale && Time.timeScale != 0f && TimeScale != 1f)
{
Time.timeScale = TimeScale;
}
if (!NoClip)
{
return;
}
if (GM.inputHandler.inputActions.left.IsPressed)
{
_noclipPos += Vector3.left * Time.deltaTime * 20f;
}
if (GM.inputHandler.inputActions.right.IsPressed)
{
_noclipPos += Vector3.right * Time.deltaTime * 20f;
}
if (GM.inputHandler.inputActions.up.IsPressed)
{
_noclipPos += Vector3.up * Time.deltaTime * 20f;
}
if (GM.inputHandler.inputActions.down.IsPressed)
{
_noclipPos += Vector3.down * Time.deltaTime * 20f;
}
// Checking for sly storeroom is a dirty fix for a savestate bug
// This scene is unimportant enough that this shouldn't cause issues
if (HC.transitionState == HeroTransitionState.WAITING_TO_TRANSITION
&& GM.GetSceneNameString() != "Room_Sly_Storeroom")
{
HC.gameObject.transform.position = _noclipPos;
}
else
{
_noclipPos = HC.gameObject.transform.position;
}
}
private void OnGUI()
{
if (GM.GetSceneNameString() == Constants.MENU_SCENE || !ShowSpeed)
{
return;
}
string[] scenes = Enumerable.Range(0, UnityEngine.SceneManagement.SceneManager.sceneCount).Select(i => UnityEngine.SceneManagement.SceneManager.GetSceneAt(i).name).ToArray<string>();
GUIHelper.Config cfg = GUIHelper.SaveConfig();
GUI.Label(new Rect(0f, 0f, 200f, 200f), $"(X, Y): {HCRb2d.velocity.x}, {HCRb2d.velocity.y}");
GUI.Label(new Rect(0f, 25f, 200f, 200f), $"(Xpos, Ypos) {HCRb2d.position.x}, {HCRb2d.position.y}");
GUI.Label(new Rect(0f, 50f, 200 * scenes.Length, 200f), $"(Scene Names) {String.Join(", ", scenes)}");
GUI.Label(new Rect(0f, 75f, 200f, 200f), $"(Bench Room) {PD.respawnScene}");
GUI.Label(new Rect(0f, 100f, 200f, 200f), $"(Load Extension) {LoadAdder}");
GUI.Label(new Rect(0f, 125f, 200f, 200f), $"(Timescale) {TimeScale}");
GUI.Label(new Rect(0f, 150f, 200f, 200f), $"(SelectedLoad) {activeLoad}");
GUIHelper.RestoreConfig(cfg);
}
private void ReloadSettings()
{
string path = Application.persistentDataPath + "/minidebug.json";
if (File.Exists(path))
{
Settings = JsonUtility.FromJson<Settings>(File.ReadAllText(path));
}
File.WriteAllText(path, JsonUtility.ToJson(Settings, true));
SaveStateManager.LoadStateNames();
_binds = new Dictionary<string, Action>
{
[Settings.showSpeed] = () => ShowSpeed = !ShowSpeed,
[Settings.infiniteHealth] = () => InfHealth = !InfHealth,
[Settings.infiniteSoul] = () => InfSoul = !InfSoul,
[Settings.increaseLoadTime] = () => LoadAdder++,
[Settings.decreaseLoadTime] = () => LoadAdder--,
[Settings.toggleSuperslides] = () => Superslides = !Superslides,
[Settings.cameraFollow] = () => CameraFollow = !CameraFollow,
[Settings.transparentInv] = ToggleInventory,
[Settings.reloadSettings] = ReloadSettings,
[Settings.noclip] = () => NoClip = !NoClip,
[Settings.yeetLoadScreens] = DestroyLoadScreens,
[Settings.showHitboxes] = () => HitboxManager.ShowHitboxes = !HitboxManager.ShowHitboxes,
[Settings.createSaveState] = () => SaveStateManager.SaveState(false),
[Settings.createDetailedSaveState] = () => SaveStateManager.SaveState(true),
[Settings.loadSaveState] = () => SaveStateManager.LoadSaveState(false),
[Settings.loadSaveStateDuped] = () => SaveStateManager.LoadSaveState(true),
[Settings.kill] = () => HC.StartCoroutine("Die"),
[Settings.dupeRoom] = () => USceneManager.LoadScene(GM.GetSceneNameString(), LoadSceneMode.Additive),
[Settings.zoomIn] = () => GameCameras.instance.tk2dCam.ZoomFactor *= 1.05f,
[Settings.zoomOut] = () => GameCameras.instance.tk2dCam.ZoomFactor /= 1.05f,
[Settings.resetZoom] = () => GameCameras.instance.tk2dCam.ZoomFactor = 1f,
[Settings.hideVignette] = () => VignetteDisabled = !VignetteDisabled,
[Settings.increaseTimeScale] = () => TimeScale += 0.1f,
[Settings.decreaseTimeScale] = () => TimeScale -= 0.1f,
[Settings.resetTimeScale] = () => TimeScale = 1f,
[Settings.giveBadFloat] = () => HC.AffectedByGravity(false),
[Settings.increaseSelectedLoad] = () => activeLoad++,
[Settings.decreaseSelectedLoad] = () => activeLoad--,
[Settings.toggleLoads] = ToggleLoadzones,
[Settings.revealHiddenAreas] = RevealHiddenAreas,
// [Settings._DEBUG] = DEBUG_doThings
};
}
private void RevealHiddenAreas()
{
foreach (var go in FindObjectsOfType<Collider2D>().Select(c2d => c2d.gameObject)
.Where(go => go.LocateMyFSM("unmasker")))
{
go.LocateMyFSM("unmasker").SendEvent("UNCOVER");
}
}
private void DEBUG_doThings()
{
MiniDebugMod.Instance.Log("BEGIN DEBUG INFO");
MiniDebugMod.Instance.Log("END DEBUG INFO");
}
private void ToggleLoadzones()
{
loadzones = UnityEngine.Object.FindObjectsOfType<TransitionPoint>();
for (int i = 0; i < this.loadzones.Length; i++)
{
if (i == this.activeLoad)
{
Debug.Log(this.loadzones[i].name + " : Active");
this.loadzones[i].GetComponent<Collider2D>().enabled = true;
}
else
{
Debug.Log(this.loadzones[i].name + " : Inactive");
this.loadzones[i].GetComponent<Collider2D>().enabled = false;
}
}
}
private void ToggleInventory()
{
_invRenders.RemoveAll(r => r == null);
if (_invRenders.Count == 0)
{
foreach (Renderer renderer in GameObject.FindGameObjectWithTag("Inventory Top").GetComponentsInChildren<Renderer>(true))
{
if (renderer.enabled)
{
_invRenders.Add(renderer);
}
}
}
foreach (Renderer renderer in _invRenders)
{
renderer.enabled = !renderer.enabled;
}
}
private void DestroyLoadScreens()
{
foreach (GameObject obj in FindObjectsOfType<GameObject>()
.Where(obj => obj.name.Contains("Blanker")))
{
Destroy(obj);
}
}
private void OnPostRenderCallback(Camera cam)
{
if (cam == Camera.main && GameManager.instance.IsGameplayScene() && CameraFollow)
{
cam.transform.position = cameraControllerPosition;
}
}
private void OnPreCullCallback(Camera cam)
{
if (cam == Camera.main && GameManager.instance.IsGameplayScene() && CameraFollow)
{
cameraControllerPosition = cam.transform.position;
cam.transform.position = new Vector3(HeroController.instance.transform.position.x, HeroController.instance.transform.position.y, cam.transform.position.z);
HitboxRender.camWorldToScreenMatrix = cam.worldToCameraMatrix;
HitboxRender.camProjectionMatrix = cam.projectionMatrix;
}
}
}
}