From 7ba2c2d3f116f2844b8b9395f74d6b5bda6ec7be Mon Sep 17 00:00:00 2001 From: NSGolova Date: Fri, 26 Apr 2024 13:54:36 +0100 Subject: [PATCH] Fixed crashes on Continue and soft restar --- include/UI/PreferencesViewController.hpp | 7 ++++--- src/UI/LeaderboardUI.cpp | 8 ++++---- src/UI/PreferencesViewController.cpp | 22 ++++++++++++++-------- src/UI/QuestUI.cpp | 6 ++++++ src/main.cpp | 22 ++++++++++++++-------- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/include/UI/PreferencesViewController.hpp b/include/UI/PreferencesViewController.hpp index bceb5dd..97c3165 100644 --- a/include/UI/PreferencesViewController.hpp +++ b/include/UI/PreferencesViewController.hpp @@ -11,6 +11,7 @@ #include "bsml/shared/BSML/Components/TableView.hpp" #include "bsml/shared/BSML/Components/Backgroundable.hpp" -namespace BeatLeader::PreferencesViewController { - void DidActivate(HMUI::ViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling); -} \ No newline at end of file +DECLARE_CLASS_CODEGEN(BeatLeader, PreferencesViewController, HMUI::ViewController, + DECLARE_OVERRIDE_METHOD_MATCH(void, DidActivate, &HMUI::ViewController::DidActivate, bool firstActivation, bool addedToHeirarchy, bool screenSystemDisabling); + DECLARE_OVERRIDE_METHOD_MATCH(void, DidDeactivate, &HMUI::ViewController::DidDeactivate, bool removedFromHierarchy, bool screenSystemDisabling); +) \ No newline at end of file diff --git a/src/UI/LeaderboardUI.cpp b/src/UI/LeaderboardUI.cpp index 2d62bc5..c423275 100644 --- a/src/UI/LeaderboardUI.cpp +++ b/src/UI/LeaderboardUI.cpp @@ -23,6 +23,7 @@ #include "include/UI/LeaderboardUI.hpp" #include "include/UI/ModifiersUI.hpp" #include "include/UI/CaptorClanUI.hpp" +#include "include/UI/QuestUI.hpp" #include "include/Utils/WebUtils.hpp" #include "include/Utils/StringUtils.hpp" @@ -790,8 +791,7 @@ namespace LeaderboardUI { logoAnimation->SetGlowing(false); }; - if (retryButton) UnityEngine::GameObject::Destroy(retryButton); - retryButton = ::BSML::Lite::CreateUIButton(parentScreen->get_transform(), "Retry", UnityEngine::Vector2(105, 63), UnityEngine::Vector2(15, 8), [](){ + retryButton = QuestUI::CreateUIButton(parentScreen->get_transform(), "Retry", UnityEngine::Vector2(116, 59), UnityEngine::Vector2(15, 8), [](){ retryButton->get_gameObject()->SetActive(false); showRetryButton = false; retryCallback(); @@ -799,8 +799,8 @@ namespace LeaderboardUI { retryButton->get_gameObject()->SetActive(false); retryButton->GetComponentInChildren()->set_alignment(TMPro::TextAlignmentOptions::Left); - if(uploadStatus) UnityEngine::GameObject::DestroyImmediate(uploadStatus); - uploadStatus = ::BSML::Lite::CreateText(parentScreen->get_transform(), "", {150, 60}); + + uploadStatus = QuestUI::CreateText(parentScreen->get_transform(), "", {200, 60}); resize(uploadStatus, 100, 3); uploadStatus->set_fontSize(3); uploadStatus->set_richText(true); diff --git a/src/UI/PreferencesViewController.cpp b/src/UI/PreferencesViewController.cpp index 29a5959..e3af075 100644 --- a/src/UI/PreferencesViewController.cpp +++ b/src/UI/PreferencesViewController.cpp @@ -32,6 +32,8 @@ using namespace BSML; using namespace std; +DEFINE_TYPE(BeatLeader, PreferencesViewController); + UnityEngine::Transform* containerTransform; UnityEngine::UI::Button* logoutButton; @@ -120,18 +122,18 @@ std::vector starValueOptions = { "Pass" }; -void BeatLeader::PreferencesViewController::DidActivate(HMUI::ViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { +void BeatLeader::PreferencesViewController::DidActivate(bool firstActivation, bool addedToHeirarchy, bool screenSystemDisabling) { if (firstActivation) { // Make Touchable - self->get_gameObject()->AddComponent(); + this->get_gameObject()->AddComponent(); // Create Container - auto* container = BSML::Lite::CreateScrollableSettingsContainer(self->get_transform()); + auto* container = BSML::Lite::CreateScrollableSettingsContainer(this->get_transform()); containerTransform = container->get_transform(); - auto spinnerImage = ::BSML::Lite::CreateImage(self->get_transform(), BundleLoader::bundle->beatLeaderLogoGradient, {0, 20}, {20, 20}); - spinner = self->get_gameObject()->AddComponent(); + auto spinnerImage = ::BSML::Lite::CreateImage(this->get_transform(), BundleLoader::bundle->beatLeaderLogoGradient, {0, 20}, {20, 20}); + spinner = this->get_gameObject()->AddComponent(); spinner->Init(spinnerImage); spinnerImage->get_gameObject()->SetActive(false); @@ -196,9 +198,9 @@ void BeatLeader::PreferencesViewController::DidActivate(HMUI::ViewController* se }); }); - auto captureSelf = self; - PlayerController::playerChanged.emplace_back([captureSelf](std::optional const& updated) { - if (!captureSelf->isActivated) return; + auto capturethis = this; + PlayerController::playerChanged.emplace_back([capturethis](std::optional const& updated) { + if (!capturethis->isActivated) return; BSML::MainThreadScheduler::Schedule([updated] { if (updated) { UpdateUI(updated); @@ -224,4 +226,8 @@ void BeatLeader::PreferencesViewController::DidActivate(HMUI::ViewController* se } UpdateUI(PlayerController::currentPlayer); +} + +void BeatLeader::PreferencesViewController::DidDeactivate(bool removedFromHierarchy, bool screenSystemDisabling) { + errorDescription = ""; } \ No newline at end of file diff --git a/src/UI/QuestUI.cpp b/src/UI/QuestUI.cpp index 75311c7..1ebd571 100644 --- a/src/UI/QuestUI.cpp +++ b/src/UI/QuestUI.cpp @@ -163,6 +163,12 @@ namespace QuestUI { void ClearCache() { diContainer = nullptr; physicsRaycaster = nullptr; + beatSaberUIObject = nullptr; + dropdownListPrefab = nullptr; + modalPrefab = nullptr; + + mainTextFont = nullptr; + mainUIFontMaterial = nullptr; } ModalView* CreateModal(Transform* parent, UnityEngine::Vector2 sizeDelta, UnityEngine::Vector2 anchoredPosition, std::function onBlockerClicked, bool dismissOnBlockerClicked) { diff --git a/src/main.cpp b/src/main.cpp index ab15f0b..12fb8dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,9 @@ #include "GlobalNamespace/MenuTransitionsHelper.hpp" #include "GlobalNamespace/AppInit.hpp" #include "GlobalNamespace/RichPresenceManager.hpp" +#include "GlobalNamespace/MainFlowCoordinator.hpp" +#include "GlobalNamespace/SettingsFlowCoordinator.hpp" + #include "BeatSaber/Init/BSAppInit.hpp" #include "UnityEngine/SceneManagement/SceneManager.hpp" #include "UnityEngine/SceneManagement/Scene.hpp" @@ -46,13 +49,15 @@ MOD_EXPORT void setup(CModInfo *info) noexcept { BeatLeaderLogger.info("Completed setup!"); } -MAKE_HOOK_MATCH(Restart, &MenuTransitionsHelper::RestartGame, void, MenuTransitionsHelper* self, ::System::Action_1<::Zenject::DiContainer*>* finishCallback) { - Restart(self, finishCallback); +MAKE_HOOK_MATCH(HandleSettingsFlowCoordinatorDidFinish, &MainFlowCoordinator::HandleSettingsFlowCoordinatorDidFinish, void, MainFlowCoordinator* self, ::GlobalNamespace::SettingsFlowCoordinator* settingsFlowCoordinator, ::GlobalNamespace::__SettingsFlowCoordinator__FinishAction finishAction) { + HandleSettingsFlowCoordinatorDidFinish(self, settingsFlowCoordinator, finishAction); - LeaderboardUI::reset(); - LevelInfoUI::reset(); - EmojiSupport::Reset(); - Sprites::ResetCache(); + if (finishAction != ::GlobalNamespace::__SettingsFlowCoordinator__FinishAction::Cancel) { + LeaderboardUI::reset(); + LevelInfoUI::reset(); + EmojiSupport::Reset(); + Sprites::ResetCache(); + } } void replayPostCallback(ReplayUploadStatus status, const string& description, float progress, int code) { @@ -144,7 +149,8 @@ MOD_EXPORT "C" void late_load() { FileManager::EnsureReplaysFolderExists(); BSML::Init(); - BSML::Register::RegisterSettingsMenu("BeatLeader", BeatLeader::PreferencesViewController::DidActivate, false); + BSML::Register::RegisterSettingsMenu("BeatLeader"); + LeaderboardUI::retryCallback = []() { ReplayManager::RetryPosting(replayPostCallback); }; @@ -175,7 +181,7 @@ MOD_EXPORT "C" void late_load() { BeatLeaderLogger.info("Installing main hooks..."); - INSTALL_HOOK(BeatLeaderLogger, Restart); + INSTALL_HOOK(BeatLeaderLogger, HandleSettingsFlowCoordinatorDidFinish); INSTALL_HOOK(BeatLeaderLogger, AppInitStart); INSTALL_HOOK(BeatLeaderLogger, SceneManager_Internal_ActiveSceneChanged); INSTALL_HOOK(BeatLeaderLogger, RichPresenceManager_HandleGameScenesManagerTransitionDidFinish);