Skip to content

Commit

Permalink
Fixed crashes on Continue and soft restar
Browse files Browse the repository at this point in the history
  • Loading branch information
NSGolova committed Apr 26, 2024
1 parent f31e0e8 commit 7ba2c2d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
7 changes: 4 additions & 3 deletions include/UI/PreferencesViewController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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);
)
8 changes: 4 additions & 4 deletions src/UI/LeaderboardUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -790,17 +791,16 @@ 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();
});
retryButton->get_gameObject()->SetActive(false);
retryButton->GetComponentInChildren<CurvedTextMeshPro*>()->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);
Expand Down
22 changes: 14 additions & 8 deletions src/UI/PreferencesViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using namespace BSML;
using namespace std;

DEFINE_TYPE(BeatLeader, PreferencesViewController);

UnityEngine::Transform* containerTransform;

UnityEngine::UI::Button* logoutButton;
Expand Down Expand Up @@ -120,18 +122,18 @@ std::vector<std::string_view> 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<HMUI::Touchable*>();
this->get_gameObject()->AddComponent<HMUI::Touchable*>();

// 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<BeatLeader::LogoAnimation*>();
auto spinnerImage = ::BSML::Lite::CreateImage(this->get_transform(), BundleLoader::bundle->beatLeaderLogoGradient, {0, 20}, {20, 20});
spinner = this->get_gameObject()->AddComponent<BeatLeader::LogoAnimation*>();
spinner->Init(spinnerImage);
spinnerImage->get_gameObject()->SetActive(false);

Expand Down Expand Up @@ -196,9 +198,9 @@ void BeatLeader::PreferencesViewController::DidActivate(HMUI::ViewController* se
});
});

auto captureSelf = self;
PlayerController::playerChanged.emplace_back([captureSelf](std::optional<Player> const& updated) {
if (!captureSelf->isActivated) return;
auto capturethis = this;
PlayerController::playerChanged.emplace_back([capturethis](std::optional<Player> const& updated) {
if (!capturethis->isActivated) return;
BSML::MainThreadScheduler::Schedule([updated] {
if (updated) {
UpdateUI(updated);
Expand All @@ -224,4 +226,8 @@ void BeatLeader::PreferencesViewController::DidActivate(HMUI::ViewController* se
}

UpdateUI(PlayerController::currentPlayer);
}

void BeatLeader::PreferencesViewController::DidDeactivate(bool removedFromHierarchy, bool screenSystemDisabling) {
errorDescription = "";
}
6 changes: 6 additions & 0 deletions src/UI/QuestUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(ModalView*)> onBlockerClicked, bool dismissOnBlockerClicked) {
Expand Down
22 changes: 14 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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::PreferencesViewController*>("BeatLeader");

LeaderboardUI::retryCallback = []() {
ReplayManager::RetryPosting(replayPostCallback);
};
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7ba2c2d

Please sign in to comment.