Skip to content

Commit 15296b1

Browse files
make code shorter tm
1 parent 074f56c commit 15296b1

3 files changed

Lines changed: 25 additions & 52 deletions

File tree

mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"version": "0.2.0",
66
"author": "ComputerElite",
77
"packageId": "com.beatgames.beatsaber",
8-
"packageVersion": "1.16.1",
8+
"packageVersion": "1.16.2",
99
"modFiles": [
1010
"libCrashMod.so"
1111
],
1212
"dependencies": [],
1313
"fileCopies": []
14-
}
14+
}

src/CrashModViewController.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ void DidActivate(ViewController* self, bool firstActivation, bool addedToHierarc
6060
// CrashOnNoFailOn
6161
QuestUI::BeatSaberUI::AddHoverHint(AddConfigValueToggle(container->get_transform(), getModConfig().CrashOnNoFailOn)->get_gameObject(), "No fail is a great feature (especially for torture). So why don't just let you not do it at all?");
6262

63+
// CrashOnNotFullCombo
64+
QuestUI::BeatSaberUI::AddHoverHint(AddConfigValueToggle(container->get_transform(), getModConfig().CrashOnNotFullCombo)->get_gameObject(), "Do a full combo or crash");
65+
66+
// CrashOnNewHighscore
67+
QuestUI::BeatSaberUI::AddHoverHint(AddConfigValueToggle(container->get_transform(), getModConfig().CrashOnNewHighscore)->get_gameObject(), "Why would you want new high scores??? Don't get better");
6368

6469
// BatteryThreshold
6570
QuestUI::BeatSaberUI::AddHoverHint(AddConfigValueIncrementFloat(container->get_transform(), getModConfig().BatteryThreshold, 0, 1.0f, 0.0f, 100.0f)->get_gameObject(), "Over this percentage your game will crash.");

src/main.cpp

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
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() {
4446
void 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

5954
MAKE_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

6659
MAKE_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

7364
MAKE_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

8569
MAKE_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

9776
MAKE_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

11081
MAKE_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

12086
MAKE_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

12991
MAKE_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+
134101
extern "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

Comments
 (0)