Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit f602924

Browse files
Merge pull request #3 from CabbageCrow/master
Fix: Random items, Fix: Noclip & teleporters, Fix: Deactivation of bug reporting, Added: Build bat
2 parents 39e54c6 + 319ff4e commit f602924

File tree

3 files changed

+94
-31
lines changed

3 files changed

+94
-31
lines changed

Build.SRDebugMenu.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
3+
set BaseDir=%cd%
4+
5+
cd %BaseDir%
6+
dotnet build SrDebug.csproj -c Release
7+
8+
echo Press any key to exit . . .
9+
pause > nul

Source/SrDebugDirector.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,25 @@ private void Update()
6363
_inputDir = FindObjectOfType<InputDirector>();
6464
if (_inputDir) // prevent user from submitting bug reports.
6565
{
66-
_inputDir.bugReportPrefab = new GameObject();
67-
_inputDir.bugReportPrefab.SetActive(false);
66+
var bugReportUI = _inputDir.bugReportPrefab.GetComponentInChildren<BugReportUI>();
67+
bugReportUI.submitButton.interactable = false;
68+
bugReportUI.summaryField.interactable = false;
69+
bugReportUI.descField.interactable = false;
70+
71+
bugReportUI.summaryField.text = "Debug Menu Mod installed - Reporting Issues is deactivated";
72+
bugReportUI.descField.text = "Notice: While this debug menu mod is active, you will not be able to report bugs. " +
73+
"This mod is not supported by Monomi Park and never will be.";
6874
}
6975
}
7076

7177
// retrieve object and component references
7278
if (!_player) _player = GameObject.Find("SimplePlayer");
73-
if (!_fpController) _fpController = _player?.GetComponent<vp_FPController>();
79+
if (!_fpController)
80+
{
81+
_fpController = _player?.GetComponent<vp_FPController>();
82+
if (_noclip)
83+
StartNoclip();
84+
}
7485
if (!_camera) _camera = GameObject.Find("FPSCamera");
7586
if (!_hudUi) _hudUi = GameObject.Find("HudUI");
7687

@@ -188,8 +199,10 @@ private void Update()
188199
// toggle noclip
189200
if (Input.GetKeyDown(KeyCode.N) && _player)
190201
{
191-
_noclip = !_noclip;
192-
_noclipPos = _player.transform.position;
202+
if (!_noclip)
203+
StartNoclip();
204+
else
205+
StopNoclip();
193206
}
194207

195208
// force the game to save
@@ -276,4 +289,28 @@ private void OnGUI()
276289
GUI.skin.label.alignment = oldAnchor;
277290
GUI.skin.label.normal.textColor = oldTextColor;
278291
}
292+
293+
294+
public void StartNoclip()
295+
{
296+
if (_player && _fpController)
297+
{
298+
_noclip = true;
299+
_noclipPos = _player.transform.position;
300+
301+
// Set player object with collision box to layer "RaycastOnly"
302+
_fpController.gameObject.layer = 14;
303+
}
304+
}
305+
306+
public void StopNoclip()
307+
{
308+
if (_fpController)
309+
{
310+
_noclip = false;
311+
312+
// Set player object with collision box back to layer "Player"
313+
_fpController.gameObject.layer = 8;
314+
}
315+
}
279316
}

Source/SrDebugExtensions.cs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@
66
/// <summary>Debug functions that were removed from the game</summary>
77
public static class SrDebugExtensions
88
{
9-
/// <summary>Retrieves a private field of type T2 from a class instance of type T1</summary>
10-
/// <param name="fieldName">The name of the field to retrieve</param>
11-
/// <param name="instance">The instance to retrieve the field from</param>
12-
private static T2 GetPrivateField<T1, T2>(string fieldName, T1 instance)
9+
public static BindingFlags all = BindingFlags.Public
10+
| BindingFlags.NonPublic
11+
| BindingFlags.Instance
12+
| BindingFlags.Static
13+
| BindingFlags.GetField
14+
| BindingFlags.SetField
15+
| BindingFlags.GetProperty
16+
| BindingFlags.SetProperty;
17+
18+
/// <summary>Retrieves a field/property (which can be private, but doesn't have to be)
19+
/// of type T2 from a class instance of type T1</summary>
20+
/// <param name="fieldName">The name of the field/property to retrieve</param>
21+
/// <param name="instance">The instance to retrieve the field/property from</param>
22+
private static T2 GetFieldOrPropertyValue<T1, T2>(string fieldName, T1 instance)
1323
{
14-
var field = typeof(T1).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
15-
return (T2) field?.GetValue(instance);
24+
var field = typeof(T1).GetField(fieldName, all);
25+
if (field != null)
26+
return (T2)field?.GetValue(instance);
27+
28+
var property = typeof(T1).GetProperty(fieldName, all);
29+
return (T2)property?.GetValue(instance, null);
1630
}
1731

1832
// PediaDirector
@@ -22,8 +36,8 @@ private static T2 GetPrivateField<T1, T2>(string fieldName, T1 instance)
2236
/// <param name="self">The PediaDirector instance</param>
2337
public static void DebugClearUnlocked(this PediaDirector self)
2438
{
25-
var unlock = typeof(PediaDirector).GetMethod("Unlock", BindingFlags.NonPublic | BindingFlags.Instance);
26-
GetPrivateField<PediaDirector, HashSet<PediaDirector.Id>>("unlocked", self).Clear();
39+
var unlock = typeof(PediaDirector).GetMethod("Unlock", all);
40+
GetFieldOrPropertyValue<PediaDirector, HashSet<PediaDirector.Id>>("unlocked", self).Clear();
2741
foreach (var t in self.initUnlocked)
2842
unlock.Invoke(self, new object[] { t });
2943
}
@@ -32,7 +46,7 @@ public static void DebugClearUnlocked(this PediaDirector self)
3246
/// <param name="self">The PediaDirector instance</param>
3347
public static void DebugAllUnlocked(this PediaDirector self)
3448
{
35-
var unlock = typeof(PediaDirector).GetMethod("Unlock", BindingFlags.NonPublic | BindingFlags.Instance);
49+
var unlock = typeof(PediaDirector).GetMethod("Unlock", all);
3650
foreach (PediaDirector.Id id in Enum.GetValues(typeof(PediaDirector.Id)))
3751
unlock.Invoke(self, new object[] { id });
3852
}
@@ -44,14 +58,14 @@ public static void DebugAllUnlocked(this PediaDirector self)
4458
/// <param name="self">The TutorialDirector instance</param>
4559
public static void DebugClearCompleted(this TutorialDirector self)
4660
{
47-
GetPrivateField<TutorialDirector, HashSet<TutorialDirector.Id>>("completed", self).Clear();
61+
GetFieldOrPropertyValue<TutorialDirector, HashSet<TutorialDirector.Id>>("completed", self).Clear();
4862
}
4963

5064
/// <summary>Completes all tutorials</summary>
5165
/// <param name="self">The TutorialDirector instance</param>
5266
public static void DebugAllCompleted(this TutorialDirector self)
5367
{
54-
var completed = GetPrivateField<TutorialDirector, HashSet<TutorialDirector.Id>>("completed", self);
68+
var completed = GetFieldOrPropertyValue<TutorialDirector, HashSet<TutorialDirector.Id>>("completed", self);
5569
foreach (TutorialDirector.Id id in Enum.GetValues(typeof(TutorialDirector.Id))) completed.Add(id);
5670
}
5771

@@ -62,18 +76,18 @@ public static void DebugAllCompleted(this TutorialDirector self)
6276
/// <param name="self">The AchievementsDirector instance</param>
6377
public static void DebugClearAwarded(this AchievementsDirector self)
6478
{
65-
GetPrivateField<AchievementsDirector, HashSet<AchievementsDirector.Achievement>>("earnedAchievements", self).Clear();
66-
GetPrivateField<AchievementsDirector, Dictionary<AchievementsDirector.BoolStat, bool>>("boolStatDict", self).Clear();
67-
GetPrivateField<AchievementsDirector, Dictionary<AchievementsDirector.IntStat, int>>("intStatDict", self).Clear();
68-
GetPrivateField<AchievementsDirector, Dictionary<AchievementsDirector.EnumStat, HashSet<Enum>>>("enumStatDict", self).Clear();
69-
GetPrivateField<AchievementsDirector, Dictionary<AchievementsDirector.GameFloatStat, float>>("gameFloatStatDict", self).Clear();
79+
GetFieldOrPropertyValue<AchievementsDirector, HashSet<AchievementsDirector.Achievement>>("earnedAchievements", self).Clear();
80+
GetFieldOrPropertyValue<AchievementsDirector, Dictionary<AchievementsDirector.BoolStat, bool>>("boolStatDict", self).Clear();
81+
GetFieldOrPropertyValue<AchievementsDirector, Dictionary<AchievementsDirector.IntStat, int>>("intStatDict", self).Clear();
82+
GetFieldOrPropertyValue<AchievementsDirector, Dictionary<AchievementsDirector.EnumStat, HashSet<Enum>>>("enumStatDict", self).Clear();
83+
GetFieldOrPropertyValue<AchievementsDirector, Dictionary<AchievementsDirector.GameFloatStat, float>>("gameFloatStatDict", self).Clear();
7084
}
7185

7286
/// <summary>Awards all achievements</summary>
7387
/// <param name="self">The AchievementsDirector instance</param>
7488
public static void DebugAllAwarded(this AchievementsDirector self)
7589
{
76-
var earnedAchievements = GetPrivateField<AchievementsDirector, HashSet<AchievementsDirector.Achievement>>("earnedAchievements", self);
90+
var earnedAchievements = GetFieldOrPropertyValue<AchievementsDirector, HashSet<AchievementsDirector.Achievement>>("earnedAchievements", self);
7791
foreach (AchievementsDirector.Achievement achievement in Enum.GetValues(typeof(AchievementsDirector.Achievement))) earnedAchievements.Add(achievement);
7892
}
7993

@@ -84,7 +98,7 @@ public static void DebugAllAwarded(this AchievementsDirector self)
8498
/// <param name="self">The ProgressDirector instance</param>
8599
public static void DebugClearProgress(this ProgressDirector self)
86100
{
87-
GetPrivateField<ProgressDirector, Dictionary<ProgressDirector.ProgressType, int>>("progressDict", self).Clear();
101+
GetFieldOrPropertyValue<ProgressDirector, Dictionary<ProgressDirector.ProgressType, int>>("progressDict", self).Clear();
88102
}
89103

90104
/// <summary>Unlocks all progress</summary>
@@ -126,12 +140,12 @@ public static void DebugGiveAllUpgrades(this PlayerState self)
126140
/// <param name="fillTo"></param>
127141
public static void DebugFillRandomAmmo(this Ammo self)
128142
{
129-
var potentialAmmo = GetPrivateField<Ammo, GameObject[]>("potentialAmmo", self);
130-
var numSlots = GetPrivateField<Ammo, int>("numSlots", self);
143+
var potentialAmmo = GetFieldOrPropertyValue<Ammo, GameObject[]>("potentialAmmo", self);
144+
var numSlots = GetFieldOrPropertyValue<Ammo, int>("numSlots", self);
131145

132-
var ammoSlot = typeof(Ammo).GetNestedType("Slot", BindingFlags.NonPublic | BindingFlags.Instance);
133-
var slots = GetPrivateField<Ammo, object[]>("slots", self);
134-
var emotions = ammoSlot.GetField("emotions", BindingFlags.Public | BindingFlags.Instance);
146+
var ammoSlot = typeof(Ammo).GetNestedType("Slot", all);
147+
var slots = GetFieldOrPropertyValue<Ammo, object[]>("slots", self);
148+
var emotions = ammoSlot.GetField("emotions", all);
135149

136150
for (var i = 0; i < numSlots; i++)
137151
{
@@ -157,17 +171,20 @@ public static void DebugFillRandomAmmo(this Ammo self)
157171
};
158172
emotions?.SetValue(slots[i], emotionData);
159173
}
174+
175+
// Refill Ammo again, because some mods might change the max value depending on what is in the slot
176+
DebugRefillAmmo(self);
160177
}
161178

162179
/// <summary>Refills the player's inventory</summary>
163180
/// <param name="self">The Ammo instance</param>
164181
/// <param name="fillTo"></param>
165182
public static void DebugRefillAmmo(this Ammo self)
166183
{
167-
var ammoSlot = typeof(Ammo).GetNestedType("Slot", BindingFlags.NonPublic | BindingFlags.Instance);
184+
var ammoSlot = typeof(Ammo).GetNestedType("Slot", all);
168185
var slotCount = ammoSlot.GetField("count");
169-
var numSlots = GetPrivateField<Ammo, int>("numSlots", self);
170-
var slots = GetPrivateField<Ammo, object[]>("slots", self);
186+
var numSlots = GetFieldOrPropertyValue<Ammo, int>("numSlots", self);
187+
var slots = GetFieldOrPropertyValue<Ammo, object[]>("slots", self);
171188

172189
for (var i = 0; i < numSlots; i++)
173190
{

0 commit comments

Comments
 (0)