1616#include " GlobalNamespace/PauseController.hpp"
1717#include " GlobalNamespace/NoteCutInfo.hpp"
1818#include " GlobalNamespace/OVRPlugin_OVRP_1_1_0.hpp"
19+ #include " GlobalNamespace/ResultsViewController.hpp"
20+ #include " GlobalNamespace/LevelCompletionResults.hpp"
1921
2022#include " beatsaber-hook/shared/config/config-utils.hpp"
2123
@@ -44,93 +46,58 @@ Logger& getLogger() {
4446void Crash () {
4547 getModConfig ().CrashCounter .SetValue (getModConfig ().CrashCounter .GetValue () + 1 );
4648 getLogger ().info (" Crash number " + std::to_string (getModConfig ().CrashCounter .GetValue ()) + " by Crash mod" );
47- if (getModConfig ().OnCrashAction .GetValue () == 0 ) {
48- CRASH_UNLESS (false );
49- } else if (getModConfig ().OnCrashAction .GetValue () == 1 ){
50- Application::Quit ();
51- } else if (getModConfig ().OnCrashAction .GetValue () == 2 ){
52- while (true )
53- {
54- malloc (1024 );
55- }
56- }
49+ if (getModConfig ().OnCrashAction .GetValue () == 0 ) CRASH_UNLESS (false );
50+ else if (getModConfig ().OnCrashAction .GetValue () == 1 ) Application::Quit ();
51+ else if (getModConfig ().OnCrashAction .GetValue () == 2 ) while (true ) malloc (1024 );
5752}
5853
5954MAKE_HOOK_OFFSETLESS (ScoreController_HandleNoteWasMissed, void , ScoreController* self, NoteController* note) {
6055 ScoreController_HandleNoteWasMissed (self, note);
61- if (getModConfig ().Active .GetValue ()) {
62- if (getModConfig ().MissCrash .GetValue ()) Crash ();
63- }
56+ if (getModConfig ().Active .GetValue () && getModConfig ().MissCrash .GetValue ()) Crash ();
6457}
6558
6659MAKE_HOOK_OFFSETLESS (ScoreController_HandleNoteWasCut, void , ScoreController* self, NoteController* note, NoteCutInfo* info) {
6760 ScoreController_HandleNoteWasCut (self, note, info);
68- if (getModConfig ().Active .GetValue ()) {
69- if (info->get_allIsOK () && getModConfig ().CrashOnGoodCut .GetValue ()) Crash ();
70- }
61+ if (getModConfig ().Active .GetValue () && info->get_allIsOK () && getModConfig ().CrashOnGoodCut .GetValue ()) Crash ();
7162}
7263
7364MAKE_HOOK_OFFSETLESS (RelativeScoreAndImmediateRankCounter_UpdateRelativeScoreAndImmediateRank, void , RelativeScoreAndImmediateRankCounter* self, int score, int modifiedscore, int maxscore, int maxmodfifiedscore) {
7465 RelativeScoreAndImmediateRankCounter_UpdateRelativeScoreAndImmediateRank (self, score, modifiedscore, maxscore, maxmodfifiedscore);
75- if (getModConfig ().Active .GetValue ()) {
76-
77- float percentage = self->get_relativeScore ();
78- // getLogger().info("current Score percentage: " + std::to_string(percentage));
79- if (getModConfig ().PercentageActive .GetValue ()) {
80- if (percentage < getModConfig ().Percentage .GetValue () / 100 ) Crash ();
81- }
82- }
66+ if (getModConfig ().Active .GetValue () && getModConfig ().PercentageActive .GetValue () && self->get_relativeScore () < getModConfig ().Percentage .GetValue () / 100 ) Crash ();
8367}
8468
8569MAKE_HOOK_OFFSETLESS (StandardLevelScenesTransitionSetupDataSO_Init, void , StandardLevelScenesTransitionSetupDataSO* self, Il2CppString* gameMode, IDifficultyBeatmap* dbm, IPreviewBeatmapLevel previewBeatmapLevel, OverrideEnvironmentSettings* overrideEnvironmentSettings, ColorScheme* overrideColorScheme, GameplayModifiers* gameplayModifiers, PlayerSpecificSettings* playerSpecificSettings, PracticeSettings* practiceSettings, Il2CppString* backButtonText, bool useTestNoteCutSoundEffects) {
8670 StandardLevelScenesTransitionSetupDataSO_Init (self, gameMode, dbm, previewBeatmapLevel, overrideEnvironmentSettings, overrideColorScheme, gameplayModifiers, playerSpecificSettings, practiceSettings, backButtonText, useTestNoteCutSoundEffects);
8771 if (getModConfig ().Active .GetValue ()) {
88- if (getModConfig ().CrashOnPlay .GetValue ()) {
89- Crash ();
90- }
91- if (getModConfig ().CrashOnNoFailOn .GetValue ()) {
92- if (gameplayModifiers->noFailOn0Energy ) Crash ();
93- }
72+ if (getModConfig ().CrashOnPlay .GetValue () || getModConfig ().CrashOnNoFailOn .GetValue () && gameplayModifiers->noFailOn0Energy ) Crash ();
9473 }
9574}
9675
9776MAKE_HOOK_OFFSETLESS (PlayerTransforms_Update, void , PlayerTransforms* self) {
9877 PlayerTransforms_Update (self);
99- if (getModConfig ().Active .GetValue ()) {
100- if (getModConfig ().CrashOnTurn .GetValue ()) {
101- getLogger ().info (" Current y turn: " + std::to_string (self->headWorldRot .get_eulerAngles ().y ));
102- if (self->headWorldRot .get_eulerAngles ().y > 165 && self->headWorldRot .get_eulerAngles ().y < 195 ) {
103- Crash ();
104- }
105-
106- }
107- }
78+ if (getModConfig ().Active .GetValue () && getModConfig ().CrashOnTurn .GetValue () && self->headWorldRot .get_eulerAngles ().y > 165 && self->headWorldRot .get_eulerAngles ().y < 195 ) Crash ();
10879}
10980
11081MAKE_HOOK_OFFSETLESS (PauseController_HandleMenuButtonTriggered, void , PauseController* self) {
11182 PauseController_HandleMenuButtonTriggered (self);
112- if (getModConfig ().Active .GetValue ()) {
113- if (getModConfig ().CrashOnPause .GetValue ()) {
114- Crash ();
115- }
116- }
117-
83+ if (getModConfig ().Active .GetValue () && getModConfig ().CrashOnPause .GetValue ()) Crash ();
11884}
11985
12086MAKE_HOOK_OFFSETLESS (PauseController_HandlePauseMenuManagerDidFinishResumeAnimation, void , PauseController* self) {
12187 PauseController_HandlePauseMenuManagerDidFinishResumeAnimation (self);
122- if (getModConfig ().Active .GetValue ()) {
123- if (getModConfig ().CrashOnUnpause .GetValue ()) {
124- Crash ();
125- }
126- }
88+ if (getModConfig ().Active .GetValue () && getModConfig ().CrashOnUnpause .GetValue ()) Crash ();
12789}
12890
12991MAKE_HOOK_OFFSETLESS (SceneManager_ActiveSceneChanged, void , UnityEngine::SceneManagement::Scene previousActiveScene, UnityEngine::SceneManagement::Scene nextActiveScene) {
13092 SceneManager_ActiveSceneChanged (previousActiveScene, nextActiveScene);
13193 if (getModConfig ().Active .GetValue () && getModConfig ().CrashOnOver5PerBattery .GetValue () && GlobalNamespace::OVRPlugin::OVRP_1_1_0::ovrp_GetSystemBatteryLevel () > getModConfig ().BatteryThreshold .GetValue () / 100 ) Crash ();
13294}
13395
96+ MAKE_HOOK_OFFSETLESS (ResultsViewController_Init, void , ResultsViewController* self, LevelCompletionResults* result, IDifficultyBeatmap* beatmap, bool practice, bool newHighScore) {
97+ ResultsViewController_Init (self, result, beatmap, practice, newHighScore);
98+ if (getModConfig ().Active .GetValue () && ((getModConfig ().CrashOnNotFullCombo .GetValue () && !result->fullCombo ) || (getModConfig ().CrashOnNewHighscore .GetValue () && self->newHighScore ))) Crash ();
99+ }
100+
134101extern " C" void setup (ModInfo& info) {
135102 info.id = ID ;
136103 info.version = VERSION ;
@@ -156,6 +123,7 @@ extern "C" void load() {
156123 INSTALL_HOOK_OFFSETLESS (logger, RelativeScoreAndImmediateRankCounter_UpdateRelativeScoreAndImmediateRank, il2cpp_utils::FindMethodUnsafe (" " , " RelativeScoreAndImmediateRankCounter" , " UpdateRelativeScoreAndImmediateRank" , 4 ));
157124 INSTALL_HOOK_OFFSETLESS (logger, StandardLevelScenesTransitionSetupDataSO_Init, il2cpp_utils::FindMethodUnsafe (" " , " StandardLevelScenesTransitionSetupDataSO" , " Init" , 10 ));
158125 INSTALL_HOOK_OFFSETLESS (logger, SceneManager_ActiveSceneChanged, il2cpp_utils::FindMethodUnsafe (" UnityEngine.SceneManagement" , " SceneManager" , " Internal_ActiveSceneChanged" , 2 ));
126+ INSTALL_HOOK_OFFSETLESS (logger, ResultsViewController_Init, il2cpp_utils::FindMethodUnsafe (" " , " ResultsViewController" , " Init" , 4 ));
159127 // INSTALL_HOOK_OFFSETLESS(logger, PauseController_HandleMenuButtonTriggered, il2cpp_utils::FindMethodUnsafe("", "PauseController", "HandleMenuButtonTriggered", 0));
160128 // INSTALL_HOOK_OFFSETLESS(logger, PauseController_HandlePauseMenuManagerDidFinishResumeAnimation, il2cpp_utils::FindMethodUnsafe("", "PauseController", "HandlePauseMenuManagerDidFinishResumeAnimation", 0));
161129 getLogger ().info (" Installed all hooks!" );
0 commit comments