-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
215 lines (175 loc) · 7.83 KB
/
Main.cs
File metadata and controls
215 lines (175 loc) · 7.83 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
// OculusReportMenu/Main.cs - The Main class, that handles ORM-related stuff
// (C) Copyright 2024 - 2026 SirKingBinx - MIT License
using GorillaLocomotion;
using GorillaNetworking;
using System;
#if MELONLOADER
/*
* MelonLoader also contains some extra dependencies that we need here, all of them are
* just for allowing custom configurations.
*/
using System.IO;
using MelonLoader;
#endif
using UnityEngine;
namespace OculusReportMenu;
/*
* Here is the bulk of the code that makes reporting work, in our Main class.
* This handles opening/closing the report menu, updating controller input,
* loading config, and much more.
*/
internal class Main
{
#nullable enable
public static Main? Instance;
#nullable disable
public static GorillaMetaReport Menu;
/*
* This variable tells OculusReportMenu when to start updating itself.
* If the GorillaMetaReport system isn't initialized, then we aren't needed
* and can halt ourselves until it is.
*/
public static bool _menuInit {
get {
if (!field)
field = (Menu != null);
return field;
}
}
/*
* These are saved for faster updating.
* The report menu's hands, the black background (called the occluder),
* and if you're on Steam or not (since custom input code is required if you are)
*/
private GameObject _occluder, _leftHand, _rightHand;
public bool _platformSteam;
/*
* This is just a shortcut for us, not really required.
*/
public bool _showingMenu => Menu.gameObject.activeInHierarchy;
internal void Start() {
Instance = this;
#if MELONLOADER
/*
* MelonLoader config is set up here.
* We specify a custom path so it's easy to find it.
*/
var configCategory = MelonPreferences.CreateCategory("Keybinds");
configCategory.SetFilePath($"UserData{Path.DirectorySeparatorChar}OculusReportMenu.cfg", true);
Input.OpenButton1 = configCategory.CreateEntry("OpenButton1", ORM_Button.LeftSecondary,
description: "Button you use to open the report menu").Value;
Input.OpenButton2 = configCategory.CreateEntry("OpenButton2", ORM_Button.RightSecondary,
description: "Button you use to open the report menu").Value;
Input.Sensitivity = configCategory.CreateEntry("Sensitivity", 0.5f,
description: "Sensitivity of trigger / grip detection (0.5f = 50%)").Value;
Input.EnableTabOpening =
configCategory.CreateEntry("AllowTabOpen", false, description: "Press TAB to open the report menu").Value;
configCategory.SaveToFile();
#elif BEPINEX
/*
* Same thing as above, but for BepInEx.
*/
Input.EnableTabOpening = Plugin.Instance.Config.Bind("Keybinds", "AllowTabOpen", false, "Press TAB to open").Value;
Input.OpenButton1 = Plugin.Instance.Config.Bind("Keybinds", "OpenButton1", ORM_Button.LeftSecondary,
"Button you use to open the report menu").Value;
Input.OpenButton2 = Plugin.Instance.Config.Bind("Keybinds", "OpenButton2", ORM_Button.RightSecondary,
"Button you use to open the report menu").Value;
Input.Sensitivity = Plugin.Instance.Config.Bind("Keybinds", "Sensitivity", 0.5f,
"Sensitivity of trigger / grip detection (0.5f = 50%)").Value;
#endif
GorillaTagger.OnPlayerSpawned(delegate
{
/*
* 99% of the time, this code doesn't require a try {} block, but we do anyway just in case.
* This makes it so other mods will load properly, even if ours doesn't.
*/
try {
UpdateObjects();
} catch (Exception ex) {
Debug.Log($"Failed to load OculusReportMenu: ${ex}");
}
});
}
private bool objectsOk = false;
private void UpdateObjects()
{
_platformSteam = PlayFabAuthenticator.instance.platform.PlatformTag.ToLower().Contains("steam");
_occluder = GameObject.Find("Miscellaneous Scripts/MetaReporting/ReportOccluder");
_leftHand = GameObject.Find("Miscellaneous Scripts/MetaReporting/CollisionRB/LeftHandParent");
_rightHand = GameObject.Find("Miscellaneous Scripts/MetaReporting/CollisionRB/RightHandParent");
objectsOk = (_occluder != null && _leftHand != null && _rightHand != null);
}
/*
* This variable stops the menu opening and closing every single frame your button is held down.
* This holds the last (updated) state of your controller inputs, so when you release the buttons
* it will allow you to press them again, allowing for a toggle button.
*/
private bool inputActivatedBefore;
internal void Update() {
if (!_menuInit)
return; // GorillaMetaReport isn't alive yet, keep waiting
if (!objectsOk)
UpdateObjects();
if (Menu.blockButtonsUntilTimestamp > Time.time)
return; // Waiting until buttons can be pressed again to update stuff
if (_showingMenu) {
/*
* Make us in the report menu and in an overlay, which turns off movement and
* stops our hands from colliding, so we don't hit or tag anybody while reporting.
*/
GTPlayer.Instance.inOverlay = true;
/*
* Since the menu doesn't update itself, here is where we do that.
* In the next 18 lines, we:
* - update positions of the background (occluder) and your hands,
* - fix the distance of the report menu so you can always reach it
* - submit reports if you are done reporting stuff
*/
_occluder.transform.position = GorillaTagger.Instance.mainCamera.transform.position;
_rightHand.transform.SetPositionAndRotation(
GorillaTagger.Instance.rightHandTransform.position,
GorillaTagger.Instance.rightHandTransform.rotation);
_leftHand.transform.SetPositionAndRotation(
GorillaTagger.Instance.leftHandTransform.position,
GorillaTagger.Instance.leftHandTransform.rotation);
if (!_platformSteam)
{
_leftHand.transform.Rotate(90, 0, 0);
_rightHand.transform.Rotate(90, 0, 0);
}
// If the menu close button is being activated, close the menu
if (_showingMenu && (Menu.closeButton.selected || Menu.closeButton.testPress))
goto teardown;
Menu.CheckDistance();
Menu.CheckReportSubmit();
} else if (!inputActivatedBefore && Input.Activated)
{
/*
* Here's where the menu gets activated.
*/
inputActivatedBefore = true;
Menu.gameObject.SetActive(true);
Menu.ToggleLevelVisibility(false);
Menu.enabled = true;
Menu.StartOverlay();
}
// This `if` block resets "inputActivatedBefore" so you can press the buttons again.
if (inputActivatedBefore && !Input.Activated)
inputActivatedBefore = false;
// If you pressed your activation buttons again on the controller, close the menu
if (!inputActivatedBefore && Input.Activated)
goto teardown;
return; // Stop us from reaching the "teardown" block if we don't want to close the menu yet
/*
* The code only reaches this `teardown` block when the menu is being closed to save code.
* It skips the "return" statement above, don't worry.
* This will let you move again and close the menu so your game returns.
*/
teardown:
Menu.Teardown();
Menu.ToggleLevelVisibility(true);
GTPlayer.Instance.InReportMenu = false;
GTPlayer.Instance.inOverlay = false;
inputActivatedBefore = true;
}
}