pause: prevent pausing during loading screen, clear give up flag after exiting gameplay, work towards restart

This commit is contained in:
somewhatlurker
2020-02-25 00:15:05 +11:00
parent 933e12accf
commit ec3eb1884e
2 changed files with 67 additions and 6 deletions
@@ -17,6 +17,7 @@ namespace TLAC::Components
bool Pause::pause = false;
bool Pause::isPaused = false;
bool Pause::giveUp = false;
bool Pause::autoPause = false;
bool Pause::showUI = true;
int Pause::selResultAet1 = 0;
int Pause::selResultAet2 = 0;
@@ -181,6 +182,17 @@ namespace TLAC::Components
}
}
/* for testing `-ss` stuff
if (inputState->Tapped.Buttons & JVS_TRIANGLE)
{
void** ScreenShotImplAddr = (void**)0x1412016d0;
Drawing::MsString path; // just a small struct from TLAC::Utilities::Drawing::MsString
path.SetCharBuf("blahblahblah");
((void(*)(void* impl, Drawing::MsString* path, int width, int height))0x140557210)(*ScreenShotImplAddr, &path, 1280, 720);
}
*/
// only process menu events when UI is visible
if (showUI)
{
@@ -293,6 +305,11 @@ namespace TLAC::Components
pause = true;
}
}
else
{
// ensure giveUp isn't retained after already quitting
giveUp = false;
}
}
// swallow filtered button inputs
@@ -550,7 +567,7 @@ namespace TLAC::Components
void Pause::OnFocusLost()
{
if (isInGame() && autoPause)
if (autoPause && isInGame())
pause = true;
}
@@ -561,7 +578,7 @@ namespace TLAC::Components
bool Pause::isInGame()
{
return *(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN;
return *(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_GAME_MAIN && *(uint8_t*)PV_STATE_ADDRESS == 1;
}
bool Pause::hookedGiveUpFunc(void* cls)
@@ -29,6 +29,8 @@ namespace TLAC::Components
static bool pause; // set pause to change pause state
static bool giveUp; // set give up to end current song
static bool autoPause; // pause when window loses focus
private:
// this is a mess of static so that menuItems can work
static bool isPauseKeyTapped();
@@ -37,7 +39,7 @@ namespace TLAC::Components
static void InjectCode(void* address, const std::vector<uint8_t> data);
static bool isPaused; // tracks internal state
static void saveOldPatchOps();
static std::vector<uint8_t> origAetMovOp;
@@ -119,7 +121,51 @@ namespace TLAC::Components
static void mainmenu() { setMenuPos(MENUSET_MAIN, mainMenuPos); };
static void unpause() { pause = false; };
//static void restart() { *(uint8_t*)0x140d0b512 = 2; ((void(*)(uint64_t))0x140127a30)(0x140d0b510); ((void(*)(uint64_t))0x140674e20)(PV_GAME_BASE_ADDRESS); /* *(uint8_t*)0x140d0b512 = 1; *(uint8_t*)0x140d0b513 = 1; *(int32_t*)0x140d0b534 = 0; ((void(*)(uint64_t))0x140127a30)(0x140d0b510); */ unpause(); }
static void restart() {
/*
140d0b510+2 = 0, 140d0b510+14 = 8 for restart
also 140cdd8d0+8 (something less than 0x1a but idk what) -- controls a switch statement in FUN_1400fddc0
0x18: PV seems good, audio good, chart and score broken? -- timing resets, notes don't
0x14: PVs a little bugged (not major), chart and scoring fine, life still doesn't reset
0x10: life resets now, but old graphics don't clear
0x15: same as 0x14
0x16: doesn't actually reset????
0x17: crash
0x12: like 0x10 but life isn't cleared
case 0x11 seems to clear life
case 0x15 seems to clear score (maybe note data)
case 0x18 seems to fix timing
patch 0x15 at 1401038cd (was 0x12), 0x18 at 140103b94 (was 0x16)
then call with 0x11
hopefully it'll work
percentage doesn't fully reset by the looks of it????
rip
*/
// inject flow overrides to switch cases in FUN_1400fddc0
InjectCode((void*)0x1401038cd, { 0x15 }); InjectCode((void*)0x140103b94, { 0x18 });
// set parameters
*(uint8_t*)PV_STATE_ADDRESS = 0; *(uint8_t*)PV_LOADING_STATE_ADDRESS = 8; *(int*)PV_INNER_LOADING_STATE_ADDRESS = 0x11;
void(*doLoading)(uint64_t) = (void(*)(uint64_t))0x1400fddc0;
// do loading until definitely done
while (*(int*)PV_INNER_LOADING_STATE_ADDRESS < 0x18)
{
doLoading(0x140cdd8d0);
}
// revert patches and unpause
InjectCode((void*)0x1401038cd, { 0x12 }); InjectCode((void*)0x140103b94, { 0x16 });
unpause();
}
static void giveup() { giveUp = true; };
static void sevolmenu() { setMenuPos(MENUSET_SEVOL, 1); };
@@ -134,7 +180,5 @@ namespace TLAC::Components
static float getMenuAnimPos();
static TLAC::Utilities::Drawing::Point getMenuItemCoords(menusets set, int pos);
bool autoPause;
};
}