From b5b0af0e15c2222a6ddab0fc6177999e4e756c73 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:17:58 +1100 Subject: [PATCH] pause: pause on focus lost (+ some minor cleanup) --- .../source/plugins/TLAC/Components/Pause.cpp | 19 +++++++++++++++++-- .../source/plugins/TLAC/Components/Pause.h | 10 ++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/source-code/source/plugins/TLAC/Components/Pause.cpp b/source-code/source/plugins/TLAC/Components/Pause.cpp index 593ef69..a2ede51 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.cpp +++ b/source-code/source/plugins/TLAC/Components/Pause.cpp @@ -14,6 +14,10 @@ namespace TLAC::Components bool Pause::isPaused = false; bool Pause::giveUp = false; bool Pause::showUI = true; + int Pause::triangleAet = 0; + int Pause::squareAet = 0; + int Pause::crossAet = 0; + int Pause::circleAet = 0; int Pause::curMenuPos = 0; int Pause::mainMenuPos = 0; Pause::menusets Pause::curMenuSet = MENUSET_MAIN; @@ -125,7 +129,7 @@ namespace TLAC::Components } // always exit pause if key is tapped or no longer in game somehow - if (isPauseKeyTapped() || *(GameState*)CURRENT_GAME_STATE_ADDRESS != GS_GAME || *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS != SUB_GAME_MAIN) + if (isPauseKeyTapped() || !isInGame()) { pause = false; } @@ -221,7 +225,7 @@ namespace TLAC::Components filteredButtons = (JvsButtons)(filteredButtons & ~inputState->Tapped.Buttons); // only enter pause if in game - if (*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN) + if (isInGame()) { if (isPauseKeyTapped()) { @@ -357,11 +361,22 @@ namespace TLAC::Components } } + void Pause::OnFocusLost() + { + if (isInGame()) + pause = true; + } + bool Pause::isPauseKeyTapped() { return inputState->Tapped.Buttons & JVS_START; } + bool Pause::isInGame() + { + return *(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN; + } + bool Pause::hookedGiveUpFunc(void* cls) { if (giveUp) diff --git a/source-code/source/plugins/TLAC/Components/Pause.h b/source-code/source/plugins/TLAC/Components/Pause.h index 6f0d9b2..fbe4072 100644 --- a/source-code/source/plugins/TLAC/Components/Pause.h +++ b/source-code/source/plugins/TLAC/Components/Pause.h @@ -22,12 +22,14 @@ namespace TLAC::Components virtual void Update() override; virtual void UpdatePostInput() override; virtual void UpdateDraw2D() override; + virtual void OnFocusLost() override; static bool pause; // set pause to change pause state static bool giveUp; // set give up to end current song private: // this is a mess of static so that menuItems can work static bool isPauseKeyTapped(); + static bool isInGame(); static std::vector streamPlayStates; static void InjectCode(void* address, const std::vector data); @@ -62,10 +64,10 @@ namespace TLAC::Components static bool showUI; - int triangleAet; - int squareAet; - int crossAet; - int circleAet; + static int triangleAet; + static int squareAet; + static int crossAet; + static int circleAet; enum menusets {