-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unity-FreeCamPlugin.cs
567 lines (518 loc) · 28.8 KB
/
Unity-FreeCamPlugin.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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
namespace Unity_FreeCam
{
[BepInPlugin(GUID, "Unity-FreeCam", Version)]
public sealed class FreeCamPlugin : BaseUnityPlugin
{
public const string GUID = "TollyH.Unity-FreeCam";
public const string Version = "1.1.0";
private static new ManualLogSource Logger;
private static ConfigEntry<KeyCode> configToggleFreecamKey;
private static ConfigEntry<KeyCode> configSelectCameraKey;
private static ConfigEntry<KeyCode> configListCamerasKey;
private static ConfigEntry<KeyCode> configToggleGameFreezeKey;
private static ConfigEntry<KeyCode> configToggleUIVisibilityKey;
private static ConfigEntry<KeyCode> configResetPositionKey;
private static ConfigEntry<KeyCode> configResetRotationKey;
private static ConfigEntry<KeyCode> configResetViewKey;
private static ConfigEntry<KeyCode> configMoveForwardKey;
private static ConfigEntry<KeyCode> configMoveBackwardKey;
private static ConfigEntry<KeyCode> configMoveLeftKey;
private static ConfigEntry<KeyCode> configMoveRightKey;
private static ConfigEntry<KeyCode> configMoveUpKey;
private static ConfigEntry<KeyCode> configMoveDownKey;
private static ConfigEntry<KeyCode> configRotatePitchForwardKey;
private static ConfigEntry<KeyCode> configRotatePitchBackwardKey;
private static ConfigEntry<KeyCode> configRotateYawLeftKey;
private static ConfigEntry<KeyCode> configRotateYawRightKey;
private static ConfigEntry<KeyCode> configRotateRollCounterClockwiseKey;
private static ConfigEntry<KeyCode> configRotateRollClockwiseKey;
private static ConfigEntry<KeyCode> configIncreaseFovKey;
private static ConfigEntry<KeyCode> configDecreaseFovKey;
private static ConfigEntry<KeyCode> configIncreaseNearClipKey;
private static ConfigEntry<KeyCode> configDecreaseNearClipKey;
private static ConfigEntry<KeyCode> configIncreaseFarClipKey;
private static ConfigEntry<KeyCode> configDecreaseFarClipKey;
private static ConfigEntry<KeyCode> configIncreaseMoveSpeedKey;
private static ConfigEntry<KeyCode> configDecreaseMoveSpeedKey;
private static ConfigEntry<KeyCode> configIncreaseRotationSpeedKey;
private static ConfigEntry<KeyCode> configDecreaseRotationSpeedKey;
private static int selectedCameraIndex = 0;
private static float moveSpeed = 5.0f;
private static float rotationSpeed = 75.0f;
private static bool freecamActive = false;
private static bool gameFrozen = false;
private static bool hideUI = false;
private static float oldTimeScale = 1.0f;
private static bool processingInput = false;
private static readonly Dictionary<Camera, Vector3> originalCameraPositions = new Dictionary<Camera, Vector3>();
private static readonly Dictionary<Camera, Quaternion> originalCameraRotations = new Dictionary<Camera, Quaternion>();
private static readonly Dictionary<Camera, float> originalCameraFovs = new Dictionary<Camera, float>();
private static readonly Dictionary<Camera, float> originalCameraNearClips = new Dictionary<Camera, float>();
private static readonly Dictionary<Camera, float> originalCameraFarClips = new Dictionary<Camera, float>();
private static readonly Dictionary<Camera, Vector3?> overrideCameraPositions = new Dictionary<Camera, Vector3?>();
private static readonly Dictionary<Camera, Quaternion?> overrideCameraRotations = new Dictionary<Camera, Quaternion?>();
private static readonly Dictionary<Camera, float?> overrideCameraFovs = new Dictionary<Camera, float?>();
private static readonly Dictionary<Camera, float?> overrideCameraNearClips = new Dictionary<Camera, float?>();
private static readonly Dictionary<Camera, float?> overrideCameraFarClips = new Dictionary<Camera, float?>();
private static List<Canvas> disabledCanvases = new List<Canvas>();
public void Start()
{
Harmony harmony = new Harmony(GUID);
harmony.PatchAll(typeof(FreeCamPlugin));
// The methods for the new input system must only be patched if the Assembly is loaded, otherwise they won't be found
if (AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == "Unity.InputSystem"))
{
Logger.LogDebug("New input system present - patching additional methods");
harmony.PatchAll(typeof(NewInputSystemPatches));
}
}
public void Awake()
{
Logger = base.Logger;
configToggleFreecamKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Toggle FreeCam", KeyCode.KeypadMultiply);
configSelectCameraKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Select Camera", KeyCode.KeypadMinus);
configListCamerasKey = Config.Bind("Keyboard Shortcuts - Plugin State", "List Cameras", KeyCode.Keypad5);
configToggleGameFreezeKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Toggle Game Freeze", KeyCode.KeypadPeriod);
configToggleUIVisibilityKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Toggle UI Visibility", KeyCode.KeypadPlus);
configResetPositionKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Reset Camera Position", KeyCode.KeypadDivide);
configResetRotationKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Reset Camera Rotation", KeyCode.KeypadDivide);
configResetViewKey = Config.Bind("Keyboard Shortcuts - Plugin State", "Reset Camera View", KeyCode.KeypadDivide);
configMoveForwardKey = Config.Bind("Keyboard Shortcuts - Camera Movement", "Move Forward", KeyCode.W);
configMoveBackwardKey = Config.Bind("Keyboard Shortcuts - Camera Movement", "Move Backward", KeyCode.S);
configMoveLeftKey = Config.Bind("Keyboard Shortcuts - Camera Movement", "Move Left", KeyCode.A);
configMoveRightKey = Config.Bind("Keyboard Shortcuts - Camera Movement", "Move Right", KeyCode.D);
configMoveUpKey = Config.Bind("Keyboard Shortcuts - Camera Movement", "Move Up", KeyCode.E);
configMoveDownKey = Config.Bind("Keyboard Shortcuts - Camera Movement", "Move Down", KeyCode.Q);
configRotatePitchForwardKey = Config.Bind("Keyboard Shortcuts - Camera Rotation", "Pitch Forward", KeyCode.Keypad8);
configRotatePitchBackwardKey = Config.Bind("Keyboard Shortcuts - Camera Rotation", "Pitch Backward", KeyCode.Keypad2);
configRotateYawLeftKey = Config.Bind("Keyboard Shortcuts - Camera Rotation", "Yaw Left", KeyCode.Keypad4);
configRotateYawRightKey = Config.Bind("Keyboard Shortcuts - Camera Rotation", "Yaw Right", KeyCode.Keypad6);
configRotateRollCounterClockwiseKey = Config.Bind("Keyboard Shortcuts - Camera Rotation", "Roll Counter-clockwise", KeyCode.Keypad7);
configRotateRollClockwiseKey = Config.Bind("Keyboard Shortcuts - Camera Rotation", "Roll Clockwise", KeyCode.Keypad9);
configIncreaseFovKey = Config.Bind("Keyboard Shortcuts - Camera View", "Increase FOV", KeyCode.Alpha3);
configDecreaseFovKey = Config.Bind("Keyboard Shortcuts - Camera View", "Decrease FOV", KeyCode.Alpha1);
configIncreaseNearClipKey = Config.Bind("Keyboard Shortcuts - Camera View", "Increase Near Clip Plane", KeyCode.X);
configDecreaseNearClipKey = Config.Bind("Keyboard Shortcuts - Camera View", "Decrease Near Clip Plane", KeyCode.Z);
configIncreaseFarClipKey = Config.Bind("Keyboard Shortcuts - Camera View", "Increase Far Clip Plane", KeyCode.V);
configDecreaseFarClipKey = Config.Bind("Keyboard Shortcuts - Camera View", "Decrease Far Clip Plane", KeyCode.C);
configIncreaseMoveSpeedKey = Config.Bind("Keyboard Shortcuts - Speed Control", "Increase Movement Speed", KeyCode.R);
configDecreaseMoveSpeedKey = Config.Bind("Keyboard Shortcuts - Speed Control", "Decrease Movement Speed", KeyCode.F);
configIncreaseRotationSpeedKey = Config.Bind("Keyboard Shortcuts - Speed Control", "Increase Rotation Speed", KeyCode.Keypad3);
configDecreaseRotationSpeedKey = Config.Bind("Keyboard Shortcuts - Speed Control", "Decrease Rotation Speed", KeyCode.Keypad1);
}
public static void LogCameraList()
{
string message = $"Current cameras ({Camera.allCamerasCount}):";
for (int i = 0; i < Camera.allCamerasCount; i++)
{
Camera camera = Camera.allCameras[i];
message += $"\n {i + 1}. {GetFullHierarchyPath(camera.gameObject)}";
if (i == selectedCameraIndex)
{
message += " (selected)";
}
if (overrideCameraPositions.TryGetValue(camera, out Vector3? position) && position != null)
{
message += " (overriding position)";
}
if (overrideCameraRotations.TryGetValue(camera, out Quaternion? rotation) && rotation != null)
{
message += " (overriding rotation)";
}
if (overrideCameraFovs.TryGetValue(camera, out float? fov) && fov != null)
{
message += " (overriding fov)";
}
if (overrideCameraNearClips.TryGetValue(camera, out float? nearClip) && nearClip != null)
{
message += " (overriding near clip plane)";
}
if (overrideCameraFarClips.TryGetValue(camera, out float? farClip) && farClip != null)
{
message += " (overriding far clip plane)";
}
}
Logger.LogMessage(message);
if (selectedCameraIndex >= Camera.allCamerasCount)
{
Logger.LogWarning("No camera is selected as the selected index is greater than the number of cameras! Pressing the select camera key should fix this.");
}
}
private static void StartPositionControl(Camera selectedCamera)
{
if (!overrideCameraPositions.ContainsKey(selectedCamera) || overrideCameraPositions[selectedCamera] == null)
{
originalCameraPositions[selectedCamera] = selectedCamera.transform.position;
overrideCameraPositions[selectedCamera] = selectedCamera.transform.position;
}
}
private static void StartRotationControl(Camera selectedCamera)
{
if (!overrideCameraRotations.ContainsKey(selectedCamera) || overrideCameraRotations[selectedCamera] == null)
{
originalCameraRotations[selectedCamera] = selectedCamera.transform.rotation;
overrideCameraRotations[selectedCamera] = selectedCamera.transform.rotation;
}
}
private static void StartViewControl(Camera selectedCamera)
{
if (!overrideCameraFovs.ContainsKey(selectedCamera) || overrideCameraFovs[selectedCamera] == null)
{
originalCameraFovs[selectedCamera] = selectedCamera.fieldOfView;
overrideCameraFovs[selectedCamera] = selectedCamera.fieldOfView;
}
if (!overrideCameraNearClips.ContainsKey(selectedCamera) || overrideCameraNearClips[selectedCamera] == null)
{
originalCameraNearClips[selectedCamera] = selectedCamera.nearClipPlane;
overrideCameraNearClips[selectedCamera] = selectedCamera.nearClipPlane;
}
if (!overrideCameraFarClips.ContainsKey(selectedCamera) || overrideCameraFarClips[selectedCamera] == null)
{
originalCameraFarClips[selectedCamera] = selectedCamera.farClipPlane;
overrideCameraFarClips[selectedCamera] = selectedCamera.farClipPlane;
}
}
private static void StopPositionControl(Camera selectedCamera)
{
overrideCameraPositions[selectedCamera] = null;
if (originalCameraPositions.TryGetValue(selectedCamera, out Vector3 position))
{
selectedCamera.transform.position = position;
}
}
private static void StopRotationControl(Camera selectedCamera)
{
overrideCameraRotations[selectedCamera] = null;
if (originalCameraRotations.TryGetValue(selectedCamera, out Quaternion rotation))
{
selectedCamera.transform.rotation = rotation;
}
}
private static void StopViewControl(Camera selectedCamera)
{
overrideCameraFovs[selectedCamera] = null;
overrideCameraNearClips[selectedCamera] = null;
overrideCameraFarClips[selectedCamera] = null;
if (originalCameraFovs.TryGetValue(selectedCamera, out float fov))
{
selectedCamera.fieldOfView = fov;
}
if (originalCameraNearClips.TryGetValue(selectedCamera, out float nearClip))
{
selectedCamera.nearClipPlane = nearClip;
}
if (originalCameraFarClips.TryGetValue(selectedCamera, out float farClip))
{
selectedCamera.farClipPlane = farClip;
}
}
private static void ProcessInput()
{
// Flag that our input is being processed to stop it being overridden
processingInput = true;
try
{
if (UnityInput.Current.GetKeyDown(configToggleFreecamKey.Value))
{
freecamActive = !freecamActive;
Logger.LogMessage($"FreeCam is now {(freecamActive ? "enabled" : "disabled")}");
}
if (!freecamActive)
{
return;
}
if (UnityInput.Current.GetKeyDown(configSelectCameraKey.Value))
{
if (Camera.allCamerasCount == 0)
{
Logger.LogWarning("There are no cameras to select");
}
else
{
selectedCameraIndex = (selectedCameraIndex + 1) % Camera.allCamerasCount;
Logger.LogMessage($"Switched to camera {selectedCameraIndex + 1}/{Camera.allCamerasCount} at {GetFullHierarchyPath(Camera.allCameras[selectedCameraIndex].gameObject)}");
}
}
if (UnityInput.Current.GetKeyDown(configListCamerasKey.Value))
{
LogCameraList();
}
if (UnityInput.Current.GetKeyDown(configToggleGameFreezeKey.Value))
{
gameFrozen = !gameFrozen;
if (!gameFrozen)
{
Time.timeScale = oldTimeScale;
}
else
{
oldTimeScale = Time.timeScale;
}
Logger.LogMessage($"Game is now {(gameFrozen ? "frozen" : "un-frozen")}");
}
if (UnityInput.Current.GetKeyDown(configToggleUIVisibilityKey.Value))
{
hideUI = !hideUI;
if (hideUI)
{
disabledCanvases = FindObjectsOfType<Canvas>().Where(c => c.isActiveAndEnabled).ToList();
}
else
{
foreach (Canvas canvas in disabledCanvases)
{
if (canvas == null)
{
continue;
}
canvas.enabled = true;
}
}
Logger.LogMessage($"UI is now {(hideUI ? "hidden" : "visible")}");
}
if (UnityInput.Current.GetKey(configIncreaseMoveSpeedKey.Value))
{
moveSpeed += moveSpeed * Time.unscaledDeltaTime;
}
if (UnityInput.Current.GetKey(configDecreaseMoveSpeedKey.Value))
{
moveSpeed -= moveSpeed * Time.unscaledDeltaTime;
}
if (UnityInput.Current.GetKey(configIncreaseRotationSpeedKey.Value))
{
rotationSpeed += rotationSpeed * Time.unscaledDeltaTime;
}
if (UnityInput.Current.GetKey(configDecreaseRotationSpeedKey.Value))
{
rotationSpeed -= rotationSpeed * Time.unscaledDeltaTime;
}
// Following key-binds need an existing selected camera
if (selectedCameraIndex < Camera.allCamerasCount)
{
Camera selectedCamera = Camera.allCameras[selectedCameraIndex];
if (UnityInput.Current.GetKeyDown(configResetPositionKey.Value))
{
StopPositionControl(selectedCamera);
}
if (UnityInput.Current.GetKeyDown(configResetRotationKey.Value))
{
StopRotationControl(selectedCamera);
}
if (UnityInput.Current.GetKeyDown(configResetViewKey.Value))
{
StopViewControl(selectedCamera);
}
if (UnityInput.Current.GetKey(configMoveForwardKey.Value))
{
StartPositionControl(selectedCamera);
overrideCameraPositions[selectedCamera] += selectedCamera.transform.TransformDirection(Vector3.forward * Time.unscaledDeltaTime * moveSpeed);
}
if (UnityInput.Current.GetKey(configMoveBackwardKey.Value))
{
StartPositionControl(selectedCamera);
overrideCameraPositions[selectedCamera] += selectedCamera.transform.TransformDirection(Vector3.back * Time.unscaledDeltaTime * moveSpeed);
}
if (UnityInput.Current.GetKey(configMoveLeftKey.Value))
{
StartPositionControl(selectedCamera);
overrideCameraPositions[selectedCamera] += selectedCamera.transform.TransformDirection(Vector3.left * Time.unscaledDeltaTime * moveSpeed);
}
if (UnityInput.Current.GetKey(configMoveRightKey.Value))
{
StartPositionControl(selectedCamera);
overrideCameraPositions[selectedCamera] += selectedCamera.transform.TransformDirection(Vector3.right * Time.unscaledDeltaTime * moveSpeed);
}
if (UnityInput.Current.GetKey(configMoveUpKey.Value))
{
StartPositionControl(selectedCamera);
overrideCameraPositions[selectedCamera] += selectedCamera.transform.TransformDirection(Vector3.up * Time.unscaledDeltaTime * moveSpeed);
}
if (UnityInput.Current.GetKey(configMoveDownKey.Value))
{
StartPositionControl(selectedCamera);
overrideCameraPositions[selectedCamera] += selectedCamera.transform.TransformDirection(Vector3.down * Time.unscaledDeltaTime * moveSpeed);
}
if (UnityInput.Current.GetKey(configRotatePitchForwardKey.Value))
{
StartRotationControl(selectedCamera);
Vector3 currentEuler = overrideCameraRotations[selectedCamera].Value.eulerAngles;
overrideCameraRotations[selectedCamera] = Quaternion.Euler(currentEuler.x - (Time.unscaledDeltaTime * rotationSpeed), currentEuler.y, currentEuler.z);
}
if (UnityInput.Current.GetKey(configRotatePitchBackwardKey.Value))
{
StartRotationControl(selectedCamera);
Vector3 currentEuler = overrideCameraRotations[selectedCamera].Value.eulerAngles;
overrideCameraRotations[selectedCamera] = Quaternion.Euler(currentEuler.x + (Time.unscaledDeltaTime * rotationSpeed), currentEuler.y, currentEuler.z);
}
if (UnityInput.Current.GetKey(configRotateYawLeftKey.Value))
{
StartRotationControl(selectedCamera);
Vector3 currentEuler = overrideCameraRotations[selectedCamera].Value.eulerAngles;
overrideCameraRotations[selectedCamera] = Quaternion.Euler(currentEuler.x, currentEuler.y - (Time.unscaledDeltaTime * rotationSpeed), currentEuler.z);
}
if (UnityInput.Current.GetKey(configRotateYawRightKey.Value))
{
StartRotationControl(selectedCamera);
Vector3 currentEuler = overrideCameraRotations[selectedCamera].Value.eulerAngles;
overrideCameraRotations[selectedCamera] = Quaternion.Euler(currentEuler.x, currentEuler.y + (Time.unscaledDeltaTime * rotationSpeed), currentEuler.z);
}
if (UnityInput.Current.GetKey(configRotateRollCounterClockwiseKey.Value))
{
StartRotationControl(selectedCamera);
Vector3 currentEuler = overrideCameraRotations[selectedCamera].Value.eulerAngles;
overrideCameraRotations[selectedCamera] = Quaternion.Euler(currentEuler.x, currentEuler.y, currentEuler.z + (Time.unscaledDeltaTime * rotationSpeed));
}
if (UnityInput.Current.GetKey(configRotateRollClockwiseKey.Value))
{
StartRotationControl(selectedCamera);
Vector3 currentEuler = overrideCameraRotations[selectedCamera].Value.eulerAngles;
overrideCameraRotations[selectedCamera] = Quaternion.Euler(currentEuler.x, currentEuler.y, currentEuler.z - (Time.unscaledDeltaTime * rotationSpeed));
}
if (UnityInput.Current.GetKey(configIncreaseFovKey.Value))
{
StartViewControl(selectedCamera);
overrideCameraFovs[selectedCamera] += Time.unscaledDeltaTime * rotationSpeed;
}
if (UnityInput.Current.GetKey(configDecreaseFovKey.Value))
{
StartViewControl(selectedCamera);
overrideCameraFovs[selectedCamera] -= Time.unscaledDeltaTime * rotationSpeed;
}
if (UnityInput.Current.GetKey(configIncreaseNearClipKey.Value))
{
StartViewControl(selectedCamera);
overrideCameraNearClips[selectedCamera] += Time.unscaledDeltaTime * moveSpeed;
}
if (UnityInput.Current.GetKey(configDecreaseNearClipKey.Value))
{
StartViewControl(selectedCamera);
overrideCameraNearClips[selectedCamera] -= Time.unscaledDeltaTime * moveSpeed;
if (overrideCameraNearClips[selectedCamera] < 0.01f)
{
overrideCameraNearClips[selectedCamera] = 0.01f;
}
}
if (UnityInput.Current.GetKey(configIncreaseFarClipKey.Value))
{
StartViewControl(selectedCamera);
overrideCameraFarClips[selectedCamera] += Time.unscaledDeltaTime * moveSpeed;
}
if (UnityInput.Current.GetKey(configDecreaseFarClipKey.Value))
{
StartViewControl(selectedCamera);
overrideCameraFarClips[selectedCamera] -= Time.unscaledDeltaTime * moveSpeed;
if (overrideCameraFarClips[selectedCamera] < 0.01f)
{
overrideCameraFarClips[selectedCamera] = 0.01f;
}
}
}
}
finally
{
processingInput = false;
}
}
public void Update()
{
ProcessInput();
}
public void LateUpdate()
{
if (gameFrozen)
{
Time.timeScale = 0;
}
if (hideUI)
{
foreach (Canvas canvas in disabledCanvases)
{
if (canvas == null)
{
continue;
}
canvas.enabled = false;
}
}
foreach (Camera camera in Camera.allCameras)
{
if (overrideCameraPositions.ContainsKey(camera) && overrideCameraPositions[camera] != null)
{
camera.transform.position = overrideCameraPositions[camera].Value;
}
if (overrideCameraRotations.ContainsKey(camera) && overrideCameraRotations[camera] != null)
{
camera.transform.rotation = overrideCameraRotations[camera].Value;
}
if (overrideCameraFovs.ContainsKey(camera) && overrideCameraFovs[camera] != null)
{
camera.fieldOfView = overrideCameraFovs[camera].Value;
}
if (overrideCameraNearClips.ContainsKey(camera) && overrideCameraNearClips[camera] != null)
{
camera.nearClipPlane = overrideCameraNearClips[camera].Value;
}
if (overrideCameraFarClips.ContainsKey(camera) && overrideCameraFarClips[camera] != null)
{
camera.farClipPlane = overrideCameraFarClips[camera].Value;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), nameof(Input.GetKey), typeof(string))]
[HarmonyPatch(typeof(Input), nameof(Input.GetKey), typeof(KeyCode))]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyDown), typeof(string))]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyDown), typeof(KeyCode))]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyUp), typeof(string))]
[HarmonyPatch(typeof(Input), nameof(Input.GetKeyUp), typeof(KeyCode))]
public static bool OverrideKeybinds(ref bool __result)
{
if (freecamActive && !processingInput)
{
__result = false;
return false;
}
return true;
}
public static class NewInputSystemPatches
{
[HarmonyPrefix]
[HarmonyPatch("UnityEngine.InputSystem.Controls.ButtonControl, Unity.InputSystem", "IsValueConsideredPressed")]
[HarmonyPatch("UnityEngine.InputSystem.Controls.ButtonControl, Unity.InputSystem", "isPressed", MethodType.Getter)]
[HarmonyPatch("UnityEngine.InputSystem.Controls.ButtonControl, Unity.InputSystem", "wasPressedThisFrame", MethodType.Getter)]
[HarmonyPatch("UnityEngine.InputSystem.InputAction, Unity.InputSystem", "IsPressed")]
[HarmonyPatch("UnityEngine.InputSystem.InputAction, Unity.InputSystem", "IsInProgress")]
[HarmonyPatch("UnityEngine.InputSystem.InputAction, Unity.InputSystem", "WasPressedThisFrame")]
[HarmonyPatch("UnityEngine.InputSystem.InputAction, Unity.InputSystem", "WasPerformedThisFrame")]
public static bool OverrideNewKeybinds(ref bool __result)
{
if (freecamActive && !processingInput)
{
__result = false;
return false;
}
return true;
}
}
public static string GetFullHierarchyPath(GameObject gameObject)
{
StringBuilder sb = new StringBuilder(gameObject.name);
GameObject currentObject = gameObject.transform.parent?.gameObject;
while (currentObject != null)
{
_ = sb.Insert(0, '/').Insert(0, currentObject.name);
currentObject = currentObject.transform.parent?.gameObject;
}
return sb.ToString();
}
}
}