|
1 | 1 | using UnityEngine; |
2 | | -using System.Linq; |
3 | 2 | using System; |
4 | 3 | using MiraAPI.Hud; |
5 | 4 | using MiraAPI.Modifiers; |
|
18 | 17 |
|
19 | 18 | namespace NewMod |
20 | 19 | { |
21 | | - [RegisterInIl2Cpp] |
22 | | - public class DebugWindow(nint ptr) : MonoBehaviour(ptr) |
23 | | - { |
24 | | - [HideFromIl2Cpp] public bool EnableDebugger { get; set; } = false; |
25 | | - public float Zoom = 3f; |
26 | | - public const float ZoomMin = 3f; |
27 | | - public const float ZoomMax = 15f; |
28 | | - public bool ScrollZoomWhileOpen = true; |
29 | | - public static DebugWindow Instance; |
30 | | - |
31 | | - public void ApplyZoom(float size) |
32 | | - { |
33 | | - size = Mathf.Clamp(size, ZoomMin, ZoomMax); |
34 | | - if (Camera.main) Camera.main.orthographicSize = size; |
35 | | - foreach (var cam in Camera.allCameras) if (cam) cam.orthographicSize = size; |
36 | | - ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen); |
37 | | - if (HudManager.Instance && HudManager.Instance.ShadowQuad) |
38 | | - { |
39 | | - bool zoomingOut = size > 3f; |
40 | | - HudManager.Instance.ShadowQuad.gameObject.SetActive(!zoomingOut); |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - private static bool AllowDebug() |
45 | | - { |
46 | | - return AmongUsClient.Instance && AmongUsClient.Instance.NetworkMode == NetworkModes.FreePlay; |
47 | | - } |
48 | | - |
49 | | - public readonly DragWindow DebuggingWindow = new(new Rect(10, 10, 0, 0), "NewMod Debug Window", () => |
50 | | - { |
51 | | - bool allow = AllowDebug(); |
52 | | - |
53 | | - GUILayout.BeginVertical(GUI.skin.box); |
54 | | - GUILayout.Label("Camera Zoom"); |
55 | | - var newZoom = GUILayout.HorizontalSlider(Instance.Zoom, ZoomMin, ZoomMax, GUILayout.Width(220f)); |
56 | | - GUILayout.BeginHorizontal(); |
57 | | - if (GUILayout.Button("-", GUILayout.Width(28f)) && allow) newZoom = Mathf.Clamp(Instance.Zoom / 1.25f, ZoomMin, ZoomMax); |
58 | | - if (GUILayout.Button("+", GUILayout.Width(28f)) && allow) newZoom = Mathf.Clamp(Instance.Zoom * 1.25f, ZoomMin, ZoomMax); |
59 | | - if (GUILayout.Button("Reset", GUILayout.Width(64f)) && allow) newZoom = 3f; |
60 | | - Instance.ScrollZoomWhileOpen = GUILayout.Toggle(Instance.ScrollZoomWhileOpen, "Scroll-wheel zoom"); |
61 | | - GUILayout.EndHorizontal(); |
62 | | - if (!Mathf.Approximately(newZoom, Instance.Zoom) && allow) |
63 | | - { |
64 | | - Instance.Zoom = newZoom; |
65 | | - Instance.ApplyZoom(Instance.Zoom); |
66 | | - } |
67 | | - GUILayout.Label($"Size: {Instance.Zoom:0.00}"); |
68 | | - GUILayout.EndVertical(); |
69 | | - |
70 | | - GUILayout.Space(6); |
71 | | - |
72 | | - if (GUILayout.Button("Become Explosive Modifier") && allow) PlayerControl.LocalPlayer.RpcAddModifier<ExplosiveModifier>(); |
73 | | - if (GUILayout.Button("Remove Explosive Modifier") && allow) PlayerControl.LocalPlayer.RpcRemoveModifier<ExplosiveModifier>(); |
74 | | - if (GUILayout.Button("Become Necromancer") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<NecromancerRole>(), false); |
75 | | - if (GUILayout.Button("Become DoubleAgent") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<DoubleAgent>(), false); |
76 | | - if (GUILayout.Button("Become EnergyThief") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<EnergyThief>(), false); |
77 | | - if (GUILayout.Button("Become SpecialAgent") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<SpecialAgent>(), false); |
78 | | - if (GUILayout.Button("Force Start Game") && allow) if (GameOptionsManager.Instance.CurrentGameOptions.NumImpostors is not 1) AmongUsClient.Instance.StartGame(); |
79 | | - if (GUILayout.Button("Increases Uses by 3") && allow) foreach (var button in CustomButtonManager.Buttons) button.SetUses(3); |
80 | | - if (GUILayout.Button("Randomly Cast a Vote") && allow && MeetingHud.Instance) |
81 | | - { |
82 | | - var randPlayer = Utils.GetRandomPlayer(p => !p.Data.IsDead && !p.Data.Disconnected); |
83 | | - MeetingHud.Instance.CmdCastVote(PlayerControl.LocalPlayer.PlayerId, randPlayer.PlayerId); |
84 | | - } |
85 | | - if (GUILayout.Button("End Meeting") && allow && MeetingHud.Instance) |
86 | | - { |
87 | | - MeetingHud.Instance.Close(); |
88 | | - } |
89 | | - if (GUILayout.Button("Apply Glitch Effect to Main Camera") && allow) |
90 | | - { |
91 | | - Camera.main.gameObject.AddComponent<GlitchEffect>(); |
92 | | - } |
93 | | - if (GUILayout.Button("Apply Earthquake Effect to Main Camera") && allow) |
94 | | - { |
95 | | - Camera.main.gameObject.AddComponent<EarthquakeEffect>(); |
96 | | - } |
97 | | - if (GUILayout.Button("Apply Slow Hue Pulse Effect to Main Camera") && allow) |
98 | | - { |
99 | | - Camera.main.gameObject.AddComponent<SlowPulseHueEffect>(); |
100 | | - } |
101 | | - if (GUILayout.Button("Apply DistorationWave Effect to Main Camera") && allow) |
102 | | - { |
103 | | - Camera.main.gameObject.AddComponent<DistorationWaveEffect>(); |
104 | | - } |
105 | | - if (GUILayout.Button("Apply ShadowFlux Effect to Main Camera") && allow) |
106 | | - { |
107 | | - Camera.main.gameObject.AddComponent<ShadowFluxEffect>(); |
108 | | - } |
109 | | - if (GUILayout.Button("Reset Camera Effects") && allow) |
110 | | - { |
111 | | - Coroutines.Start(CoroutinesHelper.RemoveCameraEffect(Camera.main, 1f)); |
112 | | - } |
113 | | - if (GUILayout.Button("Show Toast") && LobbyBehaviour.Instance) |
114 | | - { |
115 | | - var toast = Toast.CreateToast(); |
116 | | - toast.ShowToast(string.Empty, "NewMod v1.2.6", Color.red, 5f); |
117 | | - } |
118 | | - /*if (GUILayout.Button("Spawn General NPC") && allow) |
119 | | - { |
120 | | - var npc = new GameObject("GeneralNPC").AddComponent<GeneralNPC>(); |
121 | | - npc.Initialize(PlayerControl.LocalPlayer); |
122 | | - }*/ |
123 | | - }); |
124 | | - |
125 | | - public void OnGUI() |
126 | | - { |
127 | | - if (EnableDebugger) DebuggingWindow.OnGUI(); |
128 | | - } |
129 | | - |
130 | | - public void Start() |
131 | | - { |
132 | | - Instance = this; |
133 | | - if (Camera.main) Zoom = Mathf.Clamp(Camera.main.orthographicSize, ZoomMin, ZoomMax); |
134 | | - } |
135 | | - |
136 | | - public void Update() |
137 | | - { |
138 | | - if (Input.GetKeyDown(KeyCode.F3)) EnableDebugger = !EnableDebugger; |
139 | | - if (EnableDebugger && ScrollZoomWhileOpen && AllowDebug()) |
140 | | - { |
141 | | - float wheel = Input.GetAxis("Mouse ScrollWheel"); |
142 | | - if (Mathf.Abs(wheel) > 0.0001f) |
| 20 | + [RegisterInIl2Cpp] |
| 21 | + public class DebugWindow(nint ptr) : MonoBehaviour(ptr) |
| 22 | + { |
| 23 | + [HideFromIl2Cpp] public bool EnableDebugger { get; set; } = false; |
| 24 | + public float Zoom = 3f; |
| 25 | + public const float ZoomMin = 3f; |
| 26 | + public const float ZoomMax = 15f; |
| 27 | + public bool ScrollZoomWhileOpen = true; |
| 28 | + public static DebugWindow Instance; |
| 29 | + public int tab; |
| 30 | + |
| 31 | + //ShadowFlux |
| 32 | + public float noiseScale = 2f; |
| 33 | + public float fluxSpeed = 0.3f; |
| 34 | + public float edgeWidth = 0.25f; |
| 35 | + public float threshold = 0.55f; |
| 36 | + public float opacity = 0.75f; |
| 37 | + public float darkness = 0.8f; |
| 38 | + |
| 39 | + //DistorationWave |
| 40 | + public float amplitude = 0.05f; |
| 41 | + public float frequency = 5f; |
| 42 | + public float distoSpeed = 1f; |
| 43 | + public float radius = 0.25f; |
| 44 | + public float falloff = 1f; |
| 45 | + |
| 46 | + public void ApplyZoom(float size) |
| 47 | + { |
| 48 | + size = Mathf.Clamp(size, ZoomMin, ZoomMax); |
| 49 | + if (Camera.main) Camera.main.orthographicSize = size; |
| 50 | + foreach (var cam in Camera.allCameras) if (cam) cam.orthographicSize = size; |
| 51 | + ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen); |
| 52 | + if (HudManager.Instance && HudManager.Instance.ShadowQuad) |
| 53 | + HudManager.Instance.ShadowQuad.gameObject.SetActive(size <= 3f); |
| 54 | + } |
| 55 | + |
| 56 | + public static bool AllowDebug() => AmongUsClient.Instance && AmongUsClient.Instance.NetworkMode == NetworkModes.FreePlay; |
| 57 | + public readonly DragWindow DebuggingWindow = new(new Rect(10, 10, 0, 0), "NewMod Debug Window", () => |
| 58 | + { |
| 59 | + bool allow = AllowDebug(); |
| 60 | + |
| 61 | + GUILayout.BeginHorizontal(); |
| 62 | + if (GUILayout.Toggle(Instance.tab == 0, "Game", GUI.skin.button)) Instance.tab = 0; |
| 63 | + if (GUILayout.Toggle(Instance.tab == 1, "Effects", GUI.skin.button)) Instance.tab = 1; |
| 64 | + GUILayout.EndHorizontal(); |
| 65 | + |
| 66 | + if (Instance.tab == 0) |
| 67 | + { |
| 68 | + GUILayout.BeginVertical(GUI.skin.box); |
| 69 | + GUILayout.Label("Camera Zoom"); |
| 70 | + var newZoom = GUILayout.HorizontalSlider(Instance.Zoom, ZoomMin, ZoomMax, GUILayout.Width(220f)); |
| 71 | + if (!Mathf.Approximately(newZoom, Instance.Zoom) && allow) |
| 72 | + { |
| 73 | + Instance.Zoom = newZoom; |
| 74 | + Instance.ApplyZoom(Instance.Zoom); |
| 75 | + } |
| 76 | + GUILayout.Label($"Size: {Instance.Zoom:0.00}"); |
| 77 | + GUILayout.EndVertical(); |
| 78 | + |
| 79 | + GUILayout.Space(6); |
| 80 | + |
| 81 | + if (GUILayout.Button("Become Necromancer") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<NecromancerRole>(), false); |
| 82 | + if (GUILayout.Button("Become DoubleAgent") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<DoubleAgent>(), false); |
| 83 | + if (GUILayout.Button("Become EnergyThief") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<EnergyThief>(), false); |
| 84 | + if (GUILayout.Button("Become SpecialAgent") && allow) PlayerControl.LocalPlayer.RpcSetRole((RoleTypes)RoleId.Get<SpecialAgent>(), false); |
| 85 | + if (GUILayout.Button("Increase Uses by 3") && allow) foreach (var b in CustomButtonManager.Buttons) b.SetUses(3); |
| 86 | + if (GUILayout.Button("Random Vote") && allow && MeetingHud.Instance) |
| 87 | + { |
| 88 | + var p = Utils.GetRandomPlayer(x => !x.Data.IsDead && !x.Data.Disconnected); |
| 89 | + MeetingHud.Instance.CmdCastVote(PlayerControl.LocalPlayer.PlayerId, p.PlayerId); |
| 90 | + } |
| 91 | + if (GUILayout.Button("End Meeting") && allow && MeetingHud.Instance) MeetingHud.Instance.Close(); |
| 92 | + if (GUILayout.Button("Apply Glitch Effect") && allow) Camera.main.gameObject.AddComponent<GlitchEffect>(); |
| 93 | + if (GUILayout.Button("Apply Earthquake Effect") && allow) Camera.main.gameObject.AddComponent<EarthquakeEffect>(); |
| 94 | + if (GUILayout.Button("Apply PulseHue Effect") && allow) Camera.main.gameObject.AddComponent<SlowPulseHueEffect>(); |
| 95 | + if (GUILayout.Button("Apply DistortionWave Effect") && allow) Camera.main.gameObject.AddComponent<DistorationWaveEffect>(); |
| 96 | + if (GUILayout.Button("Apply ShadowFlux Effect") && allow) Camera.main.gameObject.AddComponent<ShadowFluxEffect>(); |
| 97 | + if (GUILayout.Button("Reset Effects") && allow) Coroutines.Start(CoroutinesHelper.RemoveCameraEffect(Camera.main, 1f)); |
| 98 | + } |
| 99 | + |
| 100 | + if (Instance.tab == 1) |
| 101 | + { |
| 102 | + var cam = Camera.main; |
| 103 | + |
| 104 | + if (cam.gameObject.TryGetComponent(out ShadowFluxEffect flux) && flux._mat) |
| 105 | + { |
| 106 | + GUILayout.Label("ShadowFlux"); |
| 107 | + Instance.noiseScale = Slider("NoiseScale", Instance.noiseScale, 0f, 5f); |
| 108 | + Instance.fluxSpeed = Slider("Speed", Instance.fluxSpeed, 0f, 3f); |
| 109 | + Instance.edgeWidth = Slider("EdgeWidth", Instance.edgeWidth, 0f, 1f); |
| 110 | + Instance.threshold = Slider("Threshold", Instance.threshold, 0f, 1f); |
| 111 | + Instance.opacity = Slider("Opacity", Instance.opacity, 0f, 1f); |
| 112 | + Instance.darkness = Slider("Darkness", Instance.darkness, 0f, 1f); |
| 113 | + |
| 114 | + var m = flux._mat; |
| 115 | + m.SetFloat("_NoiseScale", Instance.noiseScale); |
| 116 | + m.SetFloat("_Speed", Instance.fluxSpeed); |
| 117 | + m.SetFloat("_EdgeWidth", Instance.edgeWidth); |
| 118 | + m.SetFloat("_Threshold", Instance.threshold); |
| 119 | + m.SetFloat("_Opacity", Instance.opacity); |
| 120 | + m.SetFloat("_Darkness", Instance.darkness); |
| 121 | + } |
| 122 | + |
| 123 | + GUILayout.Space(8); |
| 124 | + |
| 125 | + if (cam.gameObject.TryGetComponent(out DistorationWaveEffect disto) && disto._mat) |
| 126 | + { |
| 127 | + GUILayout.Label("DistortionWave"); |
| 128 | + Instance.amplitude = Slider("Amplitude", Instance.amplitude, 0f, 1f); |
| 129 | + Instance.frequency = Slider("Frequency", Instance.frequency, 0f, 10f); |
| 130 | + Instance.distoSpeed = Slider("Speed", Instance.distoSpeed, 0f, 5f); |
| 131 | + Instance.radius = Slider("Radius", Instance.radius, 0f, 1f); |
| 132 | + Instance.falloff = Slider("Falloff", Instance.falloff, 0f, 5f); |
| 133 | + |
| 134 | + var m = disto._mat; |
| 135 | + m.SetFloat("_Amplitude", Instance.amplitude); |
| 136 | + m.SetFloat("_Frequency", Instance.frequency); |
| 137 | + m.SetFloat("_Speed", Instance.distoSpeed); |
| 138 | + m.SetFloat("_Radius", Instance.radius); |
| 139 | + m.SetFloat("_Falloff", Instance.falloff); |
| 140 | + } |
| 141 | + } |
| 142 | + }); |
| 143 | + |
| 144 | + public static float Slider(string name, float value, float min, float max) |
| 145 | + { |
| 146 | + GUILayout.BeginHorizontal(); |
| 147 | + GUILayout.Label(name, GUILayout.Width(100f)); |
| 148 | + value = GUILayout.HorizontalSlider(value, min, max, GUILayout.Width(200f)); |
| 149 | + GUILayout.EndHorizontal(); |
| 150 | + return value; |
| 151 | + } |
| 152 | + |
| 153 | + public void OnGUI() |
| 154 | + { |
| 155 | + if (EnableDebugger) DebuggingWindow.OnGUI(); |
| 156 | + } |
| 157 | + |
| 158 | + public void Start() |
| 159 | + { |
| 160 | + Instance = this; |
| 161 | + if (Camera.main) Zoom = Mathf.Clamp(Camera.main.orthographicSize, ZoomMin, ZoomMax); |
| 162 | + } |
| 163 | + |
| 164 | + public void Update() |
| 165 | + { |
| 166 | + if (Input.GetKeyDown(KeyCode.F3)) EnableDebugger = !EnableDebugger; |
| 167 | + if (EnableDebugger && ScrollZoomWhileOpen && AllowDebug()) |
143 | 168 | { |
144 | | - var factor = wheel > 0 ? 1f / 1.25f : 1.25f; |
145 | | - Zoom = Mathf.Clamp(Zoom * factor, ZoomMin, ZoomMax); |
146 | | - ApplyZoom(Zoom); |
| 169 | + float wheel = Input.GetAxis("Mouse ScrollWheel"); |
| 170 | + if (Mathf.Abs(wheel) > 0.0001f) |
| 171 | + { |
| 172 | + var factor = wheel > 0 ? 1f / 1.25f : 1.25f; |
| 173 | + Zoom = Mathf.Clamp(Zoom * factor, ZoomMin, ZoomMax); |
| 174 | + ApplyZoom(Zoom); |
| 175 | + } |
147 | 176 | } |
148 | | - } |
149 | | - } |
150 | | - } |
| 177 | + } |
| 178 | + } |
151 | 179 | } |
0 commit comments