From 5542178611e5e6be1a4cd3363b2d01703c2e4c52 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sat, 2 Nov 2024 16:11:17 +0100 Subject: [PATCH 1/6] Fix AsciiManager constructor accuracy --- src/AsciiManager.cpp | 1 + src/AsciiManager.hpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/AsciiManager.cpp b/src/AsciiManager.cpp index ab228e55..c5a6db99 100644 --- a/src/AsciiManager.cpp +++ b/src/AsciiManager.cpp @@ -16,6 +16,7 @@ DIFFABLE_STATIC(ChainElem, g_AsciiManagerOnDrawPopupsChain) AsciiManager::AsciiManager() { + i32 pad01, pad02, pad03, pad04, pad05, pad06, pad07, pad08; } ChainCallbackResult AsciiManager::OnUpdate(AsciiManager *mgr) diff --git a/src/AsciiManager.hpp b/src/AsciiManager.hpp index 707cd934..ab52a8ea 100644 --- a/src/AsciiManager.hpp +++ b/src/AsciiManager.hpp @@ -36,6 +36,17 @@ struct AsciiManagerPopup }; C_ASSERT(sizeof(AsciiManagerPopup) == 0x28); +struct WeirdPadding +{ + WeirdPadding() + { + i32 pad11, pad12, pad13, pad14, pad15, pad16, pad17, pad18; + i32 pad21, pad22, pad23, pad24, pad25, pad26, pad27, pad28; + i32 pad31, pad32; + } + u32 unk; +}; + // The AsciiManager is responsible for drawing various textual elements on the // screen: // @@ -85,7 +96,7 @@ struct AsciiManager i32 nextPopupIndex1; i32 nextPopupIndex2; // Seems unused - u32 unk3; + WeirdPadding unk3; // Menu that shows up when the player presses the menu button while in-game. StageMenu gameMenu; // Menu that shows up when the player dies after losing their last life. From 4fc7746a055107bddc49e6e988994a93e53776f2 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sat, 2 Nov 2024 16:11:42 +0100 Subject: [PATCH 2/6] Move main object to the end of the file --- scripts/configure.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/configure.py b/scripts/configure.py index ffc952fb..24d2196c 100644 --- a/scripts/configure.py +++ b/scripts/configure.py @@ -90,7 +90,6 @@ def configure(build_type): "python scripts/generate_objdiff_objs.py $in", ) - main_sources = ["main"] cxx_sources = [ "AsciiManager", "BulletData", @@ -123,6 +122,7 @@ def configure(build_type): "utils", "ZunTimer", "zwave", + "main", ] pbg3_sources = [ @@ -163,7 +163,7 @@ def configure(build_type): objdiff_deps.append(obj["base_path"].replace("build", "$builddir")) writer.build("objdiff", "phony", [], objdiff_deps) - for rule in main_sources + cxx_sources: + for rule in cxx_sources: writer.build( "$builddir/" + rule + ".obj", "cc", @@ -269,13 +269,12 @@ def configure(build_type): "gendef", inputs=[ "$builddir/" + x + ".obj" - for x in (main_sources + cxx_sources + pbg3_sources + ["stubs"]) + for x in (cxx_sources + pbg3_sources + ["stubs"]) ], implicit=["scripts/gendef.py"], ) objfiles = ( - ["$builddir/" + src + ".obj" for src in main_sources] - + ["$builddir/" + src + ".obj" for src in cxx_sources] + ["$builddir/" + src + ".obj" for src in cxx_sources] + ["$builddir/" + src + ".obj" for src in pbg3_sources] + ["$builddir/th06.res", "$builddir/stubs.obj"] ) From 15b270aaf1789e361f0276118992ae8c9c2915d6 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sat, 2 Nov 2024 16:18:03 +0100 Subject: [PATCH 3/6] Move StageMenu to AsciiManager --- config/ghidra_ns_to_obj.csv | 3 +- objdiff.json | 8 - scripts/configure.py | 1 - src/AsciiManager.cpp | 478 +++++++++++++++++++++++++++++++++++ src/StageMenu.cpp | 483 ------------------------------------ 5 files changed, 479 insertions(+), 494 deletions(-) delete mode 100644 src/StageMenu.cpp diff --git a/config/ghidra_ns_to_obj.csv b/config/ghidra_ns_to_obj.csv index 3030f076..64424b2a 100644 --- a/config/ghidra_ns_to_obj.csv +++ b/config/ghidra_ns_to_obj.csv @@ -1,6 +1,6 @@ AnmManager,th06::AnmManager AnmVm,th06::AnmVm -AsciiManager,th06::AsciiManager +AsciiManager,th06::AsciiManager,th06::StageMenu BulletManager,th06::BulletManager Chain,th06::Chain,th06::ChainElem EclManager,th06::EclManager @@ -26,7 +26,6 @@ Rng,th06::Rng ScreenEffect,th06::ScreenEffect SoundPlayer,th06::SoundPlayer Stage,th06::Stage -StageMenu,th06::StageMenu Supervisor,th06::Supervisor,th06::Controller TextHelper,th06::TextHelper utils,th06::utils diff --git a/objdiff.json b/objdiff.json index 8a39d1ba..88473ccd 100644 --- a/objdiff.json +++ b/objdiff.json @@ -250,14 +250,6 @@ "reverse_fn_order": false }, - { - "name": "StageMenu", - - "target_path": "build/objdiff/orig/StageMenu.obj", - "base_path": "build/objdiff/reimpl/StageMenu.obj", - - "reverse_fn_order": false - }, { "name": "Supervisor", diff --git a/scripts/configure.py b/scripts/configure.py index 24d2196c..c0d44e0b 100644 --- a/scripts/configure.py +++ b/scripts/configure.py @@ -112,7 +112,6 @@ def configure(build_type): "SoundPlayer", "Player", "Stage", - "StageMenu", "AnmVm", "AnmManager", "GameManager", diff --git a/src/AsciiManager.cpp b/src/AsciiManager.cpp index c5a6db99..bb31bec6 100644 --- a/src/AsciiManager.cpp +++ b/src/AsciiManager.cpp @@ -1,8 +1,10 @@ #include "AsciiManager.hpp" +#include "StageMenu.hpp" #include "AnmManager.hpp" #include "ChainPriorities.hpp" #include "GameManager.hpp" +#include "Gui.hpp" #include "Supervisor.hpp" #include "utils.hpp" #include @@ -19,6 +21,11 @@ AsciiManager::AsciiManager() i32 pad01, pad02, pad03, pad04, pad05, pad06, pad07, pad08; } +StageMenu::StageMenu() +{ + i32 pad01, pad02, pad03, pad04; +} + ChainCallbackResult AsciiManager::OnUpdate(AsciiManager *mgr) { if (!g_GameManager.isInGameMenu && !g_GameManager.isInRetryMenu) @@ -357,4 +364,475 @@ void AsciiManager::CreatePopup2(D3DXVECTOR3 *position, i32 value, D3DCOLOR color this->nextPopupIndex2++; } + +enum UpdateGameMenuState +{ + GAME_MENU_PAUSE_OPENING, + GAME_MENU_PAUSE_CURSOR_UNPAUSE, + GAME_MENU_PAUSE_CURSOR_QUIT, + GAME_MENU_PAUSE_SELECTED_UNPAUSE, + GAME_MENU_QUIT_CURSOR_YES, + GAME_MENU_QUIT_CURSOR_NO, + GAME_MENU_QUIT_SELECTED_YES, +}; + +#define GAME_MENU_SPRITE_TITLE_PAUSE 0 +#define GAME_MENU_SPRITE_CURSOR_UNPAUSE 1 +#define GAME_MENU_SPRITE_CURSOR_QUIT 2 +#define GAME_MENU_SPRITE_TITLE_QUIT 3 +#define GAME_MENU_SPRITE_CURSOR_YES 4 +#define GAME_MENU_SPRITE_CURSOR_NO 5 + +#define GAME_MENU_SPRITES_START_PAUSE GAME_MENU_SPRITE_TITLE_PAUSE +#define GAME_MENU_SPRITES_COUNT_PAUSE 3 +#define GAME_MENU_SPRITES_END_PAUSE (GAME_MENU_SPRITES_START_PAUSE + GAME_MENU_SPRITES_COUNT_PAUSE) +#define GAME_MENU_SPRITES_START_QUIT GAME_MENU_SPRITE_TITLE_QUIT +#define GAME_MENU_SPRITES_COUNT_QUIT 3 +#define GAME_MENU_SPRITES_END_QUIT (GAME_MENU_SPRITES_START_QUIT + GAME_MENU_SPRITES_COUNT_QUIT) + +i32 StageMenu::OnUpdateGameMenu() +{ + i32 vmIdx; + + if (WAS_PRESSED(TH_BUTTON_MENU)) + { + this->curState = GAME_MENU_PAUSE_SELECTED_UNPAUSE; + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + if (this->menuSprites[vmIdx].flags.isVisible) + { + this->menuSprites[vmIdx].pendingInterrupt = 2; + } + } + this->numFrames = 0; + this->menuBackground.pendingInterrupt = 1; + } + if (WAS_PRESSED(TH_BUTTON_Q)) + { + this->curState = GAME_MENU_QUIT_SELECTED_YES; + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + if (this->menuSprites[vmIdx].flags.isVisible) + { + this->menuSprites[vmIdx].pendingInterrupt = 2; + } + } + this->numFrames = 0; + } + switch (this->curState) + { + case GAME_MENU_PAUSE_OPENING: + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + g_AnmManager->SetAndExecuteScriptIdx(&this->menuSprites[vmIdx], vmIdx + 2); + } + for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 1; + } + this->curState++; + this->numFrames = 0; + if (g_Supervisor.lockableBackbuffer) + { + g_AnmManager->RequestScreenshot(); + g_AnmManager->SetAndExecuteScriptIdx(&this->menuBackground, ANM_SCRIPT_CAPTURE_PAUSE_BG); + this->menuBackground.pos.x = GAME_REGION_LEFT; + this->menuBackground.pos.y = GAME_REGION_TOP; + this->menuBackground.pos.z = 0.0f; + } + case GAME_MENU_PAUSE_CURSOR_UNPAUSE: + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].color = COLOR_LIGHT_RED; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleY = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleX = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleY = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleX = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + if (4 <= this->numFrames) + { + if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) + { + this->curState = GAME_MENU_PAUSE_CURSOR_QUIT; + } + if (WAS_PRESSED(TH_BUTTON_SHOOT)) + { + for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 2; + } + this->curState = GAME_MENU_PAUSE_SELECTED_UNPAUSE; + this->numFrames = 0; + this->menuBackground.pendingInterrupt = 1; + } + } + break; + case GAME_MENU_PAUSE_CURSOR_QUIT: + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].color = COLOR_LIGHT_RED; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleY = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleX = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleY = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleX = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); + if (4 <= this->numFrames) + { + if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) + { + this->curState = GAME_MENU_PAUSE_CURSOR_UNPAUSE; + } + if (WAS_PRESSED(TH_BUTTON_SHOOT)) + { + for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 2; + } + for (vmIdx = GAME_MENU_SPRITES_START_QUIT; vmIdx < GAME_MENU_SPRITES_END_QUIT; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 1; + } + this->curState = GAME_MENU_QUIT_CURSOR_NO; + this->numFrames = 0; + } + } + break; + case GAME_MENU_PAUSE_SELECTED_UNPAUSE: + /* Close menu, wait 20 frames for the animation? */ + if (20 <= this->numFrames) + { + this->curState = GAME_MENU_PAUSE_OPENING; + g_GameManager.isInGameMenu = 0; + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + this->menuSprites[vmIdx].SetInvisible(); + } + } + break; + case GAME_MENU_QUIT_CURSOR_YES: + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].color = COLOR_LIGHT_RED; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleY = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleX = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleY = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleX = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + if (4 <= this->numFrames) + { + if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) + { + this->curState = GAME_MENU_QUIT_CURSOR_NO; + } + if (WAS_PRESSED(TH_BUTTON_SHOOT)) + { + for (vmIdx = GAME_MENU_SPRITES_START_QUIT; vmIdx < GAME_MENU_SPRITES_END_QUIT; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 2; + } + this->curState = GAME_MENU_QUIT_SELECTED_YES; + this->numFrames = 0; + } + } + break; + case GAME_MENU_QUIT_CURSOR_NO: + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].color = COLOR_LIGHT_RED; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleY = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleX = 1.5f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleY = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleX = 1.7f; + this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); + if (GAME_MENU_SPRITE_CURSOR_YES <= this->numFrames) + { + if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) + { + this->curState = GAME_MENU_QUIT_CURSOR_YES; + } + if (WAS_PRESSED(TH_BUTTON_SHOOT)) + { + for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 1; + } + for (vmIdx = GAME_MENU_SPRITES_START_QUIT; vmIdx < GAME_MENU_SPRITES_END_QUIT; vmIdx++) + { + this->menuSprites[vmIdx].pendingInterrupt = 2; + } + this->curState = GAME_MENU_PAUSE_CURSOR_QUIT; + this->numFrames = 0; + } + } + break; + case GAME_MENU_QUIT_SELECTED_YES: + if (20 <= this->numFrames) + { + this->curState = GAME_MENU_PAUSE_OPENING; + g_GameManager.isInGameMenu = 0; + g_Supervisor.curState = SUPERVISOR_STATE_MAINMENU; + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + this->menuSprites[vmIdx].SetInvisible(); + } + } + } + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + g_AnmManager->ExecuteScript(&this->menuSprites[vmIdx]); + } + if (g_Supervisor.lockableBackbuffer) + { + g_AnmManager->ExecuteScript(&this->menuBackground); + } + this->numFrames++; + return 0; +} + +void StageMenu::OnDrawGameMenu() +{ + i32 vmIdx; + + if (g_GameManager.isInGameMenu) + { + g_Supervisor.viewport.X = g_GameManager.arcadeRegionTopLeftPos.x; + g_Supervisor.viewport.Y = g_GameManager.arcadeRegionTopLeftPos.y; + g_Supervisor.viewport.Width = g_GameManager.arcadeRegionSize.x; + g_Supervisor.viewport.Height = g_GameManager.arcadeRegionSize.y; + g_Supervisor.d3dDevice->SetViewport(&g_Supervisor.viewport); + if (g_Supervisor.lockableBackbuffer && this->curState != GAME_MENU_PAUSE_OPENING) + { + AnmVm menuBackground = this->menuBackground; + menuBackground.flags.zWriteDisable = 1; + g_AnmManager->DrawNoRotation(&menuBackground); + } + for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) + { + if (this->menuSprites[vmIdx].flags.isVisible) + { + g_AnmManager->DrawNoRotation(&this->menuSprites[vmIdx]); + } + } + } + return; +} + +enum RetryGameMenuState +{ + RETRY_MENU_OPENING, + RETRY_MENU_CURSOR_YES, + RETRY_MENU_CURSOR_NO, + RETRY_MENU_SELECTED_YES, + RETRY_MENU_SELECTED_NO, +}; + +#define RETRY_MENU_SPRITE_TITLE 0 +#define RETRY_MENU_SPRITE_RETRIES_LABEL 1 +#define RETRY_MENU_SPRITE_YES 2 +#define RETRY_MENU_SPRITE_NO 3 +#define RETRY_MENU_SPRITE_RETRIES_NUMBER 4 + +#define RETRY_MENU_SPRITES_START RETRY_MENU_SPRITE_TITLE +#define RETRY_MENU_SPRITES_COUNT 4 +#define RETRY_MENU_SPRITES_END (RETRY_MENU_SPRITES_START + RETRY_MENU_SPRITES_COUNT) + +i32 StageMenu::OnUpdateRetryMenu() +{ + i32 idx; + + if (g_GameManager.isInPracticeMode) + { + g_GameManager.isInRetryMenu = 0; + g_GameManager.guiScore = g_GameManager.score; + g_Supervisor.curState = SUPERVISOR_STATE_RESULTSCREEN_FROMGAME; + return 1; + } + if (g_GameManager.isInReplay) + { + g_GameManager.isInRetryMenu = 0; + g_Supervisor.curState = SUPERVISOR_STATE_MAINMENU_REPLAY; + g_GameManager.guiScore = g_GameManager.score; + return 1; + } + if (g_GameManager.numRetries >= 3 || g_GameManager.difficulty >= EXTRA) + { + g_GameManager.isInRetryMenu = 0; + g_Supervisor.curState = SUPERVISOR_STATE_RESULTSCREEN_FROMGAME; + g_GameManager.guiScore = g_GameManager.score; + return 1; + } + switch (this->curState) + { + case RETRY_MENU_OPENING: + if (this->numFrames == 0) + { + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + if (idx < 2) + { + g_AnmManager->SetAndExecuteScriptIdx(&this->menuSprites[idx], idx + 8); + } + else + { + g_AnmManager->SetAndExecuteScriptIdx(&this->menuSprites[idx], idx + 4); + } + this->menuSprites[idx].pendingInterrupt = 1; + } + if (g_Supervisor.lockableBackbuffer) + { + g_AnmManager->RequestScreenshot(); + g_AnmManager->SetAndExecuteScriptIdx(&this->menuBackground, ANM_SCRIPT_CAPTURE_PAUSE_BG); + this->menuBackground.pos.x = GAME_REGION_LEFT; + this->menuBackground.pos.y = GAME_REGION_TOP; + this->menuBackground.pos.z = 0.0f; + } + } + if (this->numFrames > 8) + break; + this->curState += RETRY_MENU_CURSOR_NO; + this->numFrames = 0; + case RETRY_MENU_CURSOR_YES: + this->menuSprites[RETRY_MENU_SPRITE_YES].color = COLOR_LIGHT_RED; + this->menuSprites[RETRY_MENU_SPRITE_NO].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); + this->menuSprites[RETRY_MENU_SPRITE_YES].scaleY = 1.7f; + this->menuSprites[RETRY_MENU_SPRITE_YES].scaleX = 1.7f; + this->menuSprites[RETRY_MENU_SPRITE_NO].scaleY = 1.5f; + this->menuSprites[RETRY_MENU_SPRITE_NO].scaleX = 1.5f; + this->menuSprites[RETRY_MENU_SPRITE_YES].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); + this->menuSprites[RETRY_MENU_SPRITE_NO].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + if (3 < this->numFrames) + { + if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) + { + this->curState = RETRY_MENU_CURSOR_NO; + } + if (WAS_PRESSED(TH_BUTTON_SHOOT)) + { + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + this->menuSprites[idx].pendingInterrupt = 2; + } + this->curState = RETRY_MENU_SELECTED_YES; + this->menuBackground.pendingInterrupt = 1; + this->numFrames = 0; + } + } + break; + case RETRY_MENU_CURSOR_NO: + this->menuSprites[RETRY_MENU_SPRITE_NO].color = COLOR_LIGHT_RED; + this->menuSprites[RETRY_MENU_SPRITE_YES].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); + this->menuSprites[RETRY_MENU_SPRITE_YES].scaleY = 1.5f; + this->menuSprites[RETRY_MENU_SPRITE_YES].scaleX = 1.5f; + this->menuSprites[RETRY_MENU_SPRITE_NO].scaleY = 1.7f; + this->menuSprites[RETRY_MENU_SPRITE_NO].scaleX = 1.7f; + this->menuSprites[RETRY_MENU_SPRITE_NO].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); + this->menuSprites[RETRY_MENU_SPRITE_YES].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + if (this->numFrames >= 30) + { + if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) + { + this->curState = RETRY_MENU_CURSOR_YES; + } + if (WAS_PRESSED(TH_BUTTON_SHOOT)) + { + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + this->menuSprites[idx].pendingInterrupt = 2; + } + this->curState = RETRY_MENU_SELECTED_NO; + this->numFrames = 0; + } + } + break; + case RETRY_MENU_SELECTED_NO: + if (this->numFrames >= 20) + { + this->curState = 0; + this->numFrames = 0; + g_GameManager.isInRetryMenu = 0; + g_Supervisor.curState = SUPERVISOR_STATE_RESULTSCREEN_FROMGAME; + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + this->menuSprites[idx].SetInvisible(); + } + g_GameManager.guiScore = g_GameManager.score; + return 0; + } + break; + case RETRY_MENU_SELECTED_YES: + if (this->numFrames >= 30) + { + this->curState = 0; + this->numFrames = 0; + g_GameManager.isInRetryMenu = 0; + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + this->menuSprites[idx].SetInvisible(); + } + g_GameManager.numRetries++; + g_GameManager.guiScore = g_GameManager.numRetries; + g_GameManager.nextScoreIncrement = 0; + g_GameManager.score = g_GameManager.guiScore; + g_GameManager.livesRemaining = g_Supervisor.defaultConfig.lifeCount; + g_GameManager.bombsRemaining = g_Supervisor.defaultConfig.bombCount; + g_GameManager.grazeInStage = 0; + g_GameManager.currentPower = 0; + g_GameManager.pointItemsCollectedInStage = 0; + g_GameManager.extraLives = 0; + g_Gui.flags.flag0 = 2; + g_Gui.flags.flag1 = 2; + g_Gui.flags.flag3 = 2; + g_Gui.flags.flag4 = 2; + g_Gui.flags.flag2 = 2; + return 0; + } + break; + } + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + g_AnmManager->ExecuteScript(&this->menuSprites[idx]); + } + if (g_Supervisor.lockableBackbuffer) + { + g_AnmManager->ExecuteScript(&this->menuBackground); + } + this->numFrames++; + return 0; +} + +void StageMenu::OnDrawRetryMenu() +{ + int idx; + + if (g_GameManager.isInRetryMenu) + { + g_Supervisor.viewport.X = g_GameManager.arcadeRegionTopLeftPos.x; + g_Supervisor.viewport.Y = g_GameManager.arcadeRegionTopLeftPos.y; + g_Supervisor.viewport.Width = g_GameManager.arcadeRegionSize.x; + g_Supervisor.viewport.Height = g_GameManager.arcadeRegionSize.y; + g_Supervisor.d3dDevice->SetViewport(&g_Supervisor.viewport); + if (g_Supervisor.lockableBackbuffer && (this->curState != RETRY_MENU_OPENING || this->numFrames > 2)) + { + g_AnmManager->DrawNoRotation(&this->menuBackground); + } + if (this->curState == RETRY_MENU_CURSOR_YES || this->curState == RETRY_MENU_CURSOR_NO) + { + this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER] = this->menuSprites[RETRY_MENU_SPRITE_RETRIES_LABEL]; + this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER].pos.x += + 8.0f * this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER].scaleX; + this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER].sprite = + &g_AnmManager->sprites[30 - g_GameManager.numRetries]; + g_AnmManager->DrawNoRotation(&this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER]); + } + for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) + { + if (this->menuSprites[idx].flags.isVisible) + { + g_AnmManager->DrawNoRotation(&this->menuSprites[idx]); + } + } + } + return; +} + }; // namespace th06 diff --git a/src/StageMenu.cpp b/src/StageMenu.cpp deleted file mode 100644 index 341141ce..00000000 --- a/src/StageMenu.cpp +++ /dev/null @@ -1,483 +0,0 @@ -#include "StageMenu.hpp" -#include "AnmManager.hpp" -#include "GameManager.hpp" -#include "Gui.hpp" -#include "utils.hpp" - -namespace th06 -{ - -StageMenu::StageMenu() -{ -} - -enum UpdateGameMenuState -{ - GAME_MENU_PAUSE_OPENING, - GAME_MENU_PAUSE_CURSOR_UNPAUSE, - GAME_MENU_PAUSE_CURSOR_QUIT, - GAME_MENU_PAUSE_SELECTED_UNPAUSE, - GAME_MENU_QUIT_CURSOR_YES, - GAME_MENU_QUIT_CURSOR_NO, - GAME_MENU_QUIT_SELECTED_YES, -}; - -#define GAME_MENU_SPRITE_TITLE_PAUSE 0 -#define GAME_MENU_SPRITE_CURSOR_UNPAUSE 1 -#define GAME_MENU_SPRITE_CURSOR_QUIT 2 -#define GAME_MENU_SPRITE_TITLE_QUIT 3 -#define GAME_MENU_SPRITE_CURSOR_YES 4 -#define GAME_MENU_SPRITE_CURSOR_NO 5 - -#define GAME_MENU_SPRITES_START_PAUSE GAME_MENU_SPRITE_TITLE_PAUSE -#define GAME_MENU_SPRITES_COUNT_PAUSE 3 -#define GAME_MENU_SPRITES_END_PAUSE (GAME_MENU_SPRITES_START_PAUSE + GAME_MENU_SPRITES_COUNT_PAUSE) -#define GAME_MENU_SPRITES_START_QUIT GAME_MENU_SPRITE_TITLE_QUIT -#define GAME_MENU_SPRITES_COUNT_QUIT 3 -#define GAME_MENU_SPRITES_END_QUIT (GAME_MENU_SPRITES_START_QUIT + GAME_MENU_SPRITES_COUNT_QUIT) - -i32 StageMenu::OnUpdateGameMenu() -{ - i32 vmIdx; - - if (WAS_PRESSED(TH_BUTTON_MENU)) - { - this->curState = GAME_MENU_PAUSE_SELECTED_UNPAUSE; - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - if (this->menuSprites[vmIdx].flags.isVisible) - { - this->menuSprites[vmIdx].pendingInterrupt = 2; - } - } - this->numFrames = 0; - this->menuBackground.pendingInterrupt = 1; - } - if (WAS_PRESSED(TH_BUTTON_Q)) - { - this->curState = GAME_MENU_QUIT_SELECTED_YES; - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - if (this->menuSprites[vmIdx].flags.isVisible) - { - this->menuSprites[vmIdx].pendingInterrupt = 2; - } - } - this->numFrames = 0; - } - switch (this->curState) - { - case GAME_MENU_PAUSE_OPENING: - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - g_AnmManager->SetAndExecuteScriptIdx(&this->menuSprites[vmIdx], vmIdx + 2); - } - for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 1; - } - this->curState++; - this->numFrames = 0; - if (g_Supervisor.lockableBackbuffer) - { - g_AnmManager->RequestScreenshot(); - g_AnmManager->SetAndExecuteScriptIdx(&this->menuBackground, ANM_SCRIPT_CAPTURE_PAUSE_BG); - this->menuBackground.pos.x = GAME_REGION_LEFT; - this->menuBackground.pos.y = GAME_REGION_TOP; - this->menuBackground.pos.z = 0.0f; - } - case GAME_MENU_PAUSE_CURSOR_UNPAUSE: - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].color = COLOR_LIGHT_RED; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleY = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleX = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleY = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleX = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - if (4 <= this->numFrames) - { - if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) - { - this->curState = GAME_MENU_PAUSE_CURSOR_QUIT; - } - if (WAS_PRESSED(TH_BUTTON_SHOOT)) - { - for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 2; - } - this->curState = GAME_MENU_PAUSE_SELECTED_UNPAUSE; - this->numFrames = 0; - this->menuBackground.pendingInterrupt = 1; - } - } - break; - case GAME_MENU_PAUSE_CURSOR_QUIT: - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].color = COLOR_LIGHT_RED; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleY = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].scaleX = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleY = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].scaleX = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_UNPAUSE].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_QUIT].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); - if (4 <= this->numFrames) - { - if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) - { - this->curState = GAME_MENU_PAUSE_CURSOR_UNPAUSE; - } - if (WAS_PRESSED(TH_BUTTON_SHOOT)) - { - for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 2; - } - for (vmIdx = GAME_MENU_SPRITES_START_QUIT; vmIdx < GAME_MENU_SPRITES_END_QUIT; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 1; - } - this->curState = GAME_MENU_QUIT_CURSOR_NO; - this->numFrames = 0; - } - } - break; - case GAME_MENU_PAUSE_SELECTED_UNPAUSE: - /* Close menu, wait 20 frames for the animation? */ - if (20 <= this->numFrames) - { - this->curState = GAME_MENU_PAUSE_OPENING; - g_GameManager.isInGameMenu = 0; - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - this->menuSprites[vmIdx].SetInvisible(); - } - } - break; - case GAME_MENU_QUIT_CURSOR_YES: - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].color = COLOR_LIGHT_RED; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleY = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleX = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleY = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleX = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - if (4 <= this->numFrames) - { - if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) - { - this->curState = GAME_MENU_QUIT_CURSOR_NO; - } - if (WAS_PRESSED(TH_BUTTON_SHOOT)) - { - for (vmIdx = GAME_MENU_SPRITES_START_QUIT; vmIdx < GAME_MENU_SPRITES_END_QUIT; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 2; - } - this->curState = GAME_MENU_QUIT_SELECTED_YES; - this->numFrames = 0; - } - } - break; - case GAME_MENU_QUIT_CURSOR_NO: - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].color = COLOR_LIGHT_RED; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleY = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].scaleX = 1.5f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleY = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].scaleX = 1.7f; - this->menuSprites[GAME_MENU_SPRITE_CURSOR_YES].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - this->menuSprites[GAME_MENU_SPRITE_CURSOR_NO].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); - if (GAME_MENU_SPRITE_CURSOR_YES <= this->numFrames) - { - if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) - { - this->curState = GAME_MENU_QUIT_CURSOR_YES; - } - if (WAS_PRESSED(TH_BUTTON_SHOOT)) - { - for (vmIdx = GAME_MENU_SPRITES_START_PAUSE; vmIdx < GAME_MENU_SPRITES_END_PAUSE; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 1; - } - for (vmIdx = GAME_MENU_SPRITES_START_QUIT; vmIdx < GAME_MENU_SPRITES_END_QUIT; vmIdx++) - { - this->menuSprites[vmIdx].pendingInterrupt = 2; - } - this->curState = GAME_MENU_PAUSE_CURSOR_QUIT; - this->numFrames = 0; - } - } - break; - case GAME_MENU_QUIT_SELECTED_YES: - if (20 <= this->numFrames) - { - this->curState = GAME_MENU_PAUSE_OPENING; - g_GameManager.isInGameMenu = 0; - g_Supervisor.curState = SUPERVISOR_STATE_MAINMENU; - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - this->menuSprites[vmIdx].SetInvisible(); - } - } - } - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - g_AnmManager->ExecuteScript(&this->menuSprites[vmIdx]); - } - if (g_Supervisor.lockableBackbuffer) - { - g_AnmManager->ExecuteScript(&this->menuBackground); - } - this->numFrames++; - return 0; -} - -void StageMenu::OnDrawGameMenu() -{ - i32 vmIdx; - - if (g_GameManager.isInGameMenu) - { - g_Supervisor.viewport.X = g_GameManager.arcadeRegionTopLeftPos.x; - g_Supervisor.viewport.Y = g_GameManager.arcadeRegionTopLeftPos.y; - g_Supervisor.viewport.Width = g_GameManager.arcadeRegionSize.x; - g_Supervisor.viewport.Height = g_GameManager.arcadeRegionSize.y; - g_Supervisor.d3dDevice->SetViewport(&g_Supervisor.viewport); - if (g_Supervisor.lockableBackbuffer && this->curState != GAME_MENU_PAUSE_OPENING) - { - AnmVm menuBackground = this->menuBackground; - menuBackground.flags.zWriteDisable = 1; - g_AnmManager->DrawNoRotation(&menuBackground); - } - for (vmIdx = 0; vmIdx < ARRAY_SIZE_SIGNED(this->menuSprites); vmIdx++) - { - if (this->menuSprites[vmIdx].flags.isVisible) - { - g_AnmManager->DrawNoRotation(&this->menuSprites[vmIdx]); - } - } - } - return; -} - -enum RetryGameMenuState -{ - RETRY_MENU_OPENING, - RETRY_MENU_CURSOR_YES, - RETRY_MENU_CURSOR_NO, - RETRY_MENU_SELECTED_YES, - RETRY_MENU_SELECTED_NO, -}; - -#define RETRY_MENU_SPRITE_TITLE 0 -#define RETRY_MENU_SPRITE_RETRIES_LABEL 1 -#define RETRY_MENU_SPRITE_YES 2 -#define RETRY_MENU_SPRITE_NO 3 -#define RETRY_MENU_SPRITE_RETRIES_NUMBER 4 - -#define RETRY_MENU_SPRITES_START RETRY_MENU_SPRITE_TITLE -#define RETRY_MENU_SPRITES_COUNT 4 -#define RETRY_MENU_SPRITES_END (RETRY_MENU_SPRITES_START + RETRY_MENU_SPRITES_COUNT) - -i32 StageMenu::OnUpdateRetryMenu() -{ - i32 idx; - - if (g_GameManager.isInPracticeMode) - { - g_GameManager.isInRetryMenu = 0; - g_GameManager.guiScore = g_GameManager.score; - g_Supervisor.curState = SUPERVISOR_STATE_RESULTSCREEN_FROMGAME; - return 1; - } - if (g_GameManager.isInReplay) - { - g_GameManager.isInRetryMenu = 0; - g_Supervisor.curState = SUPERVISOR_STATE_MAINMENU_REPLAY; - g_GameManager.guiScore = g_GameManager.score; - return 1; - } - if (g_GameManager.numRetries >= 3 || g_GameManager.difficulty >= EXTRA) - { - g_GameManager.isInRetryMenu = 0; - g_Supervisor.curState = SUPERVISOR_STATE_RESULTSCREEN_FROMGAME; - g_GameManager.guiScore = g_GameManager.score; - return 1; - } - switch (this->curState) - { - case RETRY_MENU_OPENING: - if (this->numFrames == 0) - { - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - if (idx < 2) - { - g_AnmManager->SetAndExecuteScriptIdx(&this->menuSprites[idx], idx + 8); - } - else - { - g_AnmManager->SetAndExecuteScriptIdx(&this->menuSprites[idx], idx + 4); - } - this->menuSprites[idx].pendingInterrupt = 1; - } - if (g_Supervisor.lockableBackbuffer) - { - g_AnmManager->RequestScreenshot(); - g_AnmManager->SetAndExecuteScriptIdx(&this->menuBackground, ANM_SCRIPT_CAPTURE_PAUSE_BG); - this->menuBackground.pos.x = GAME_REGION_LEFT; - this->menuBackground.pos.y = GAME_REGION_TOP; - this->menuBackground.pos.z = 0.0f; - } - } - if (this->numFrames > 8) - break; - this->curState += RETRY_MENU_CURSOR_NO; - this->numFrames = 0; - case RETRY_MENU_CURSOR_YES: - this->menuSprites[RETRY_MENU_SPRITE_YES].color = COLOR_LIGHT_RED; - this->menuSprites[RETRY_MENU_SPRITE_NO].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); - this->menuSprites[RETRY_MENU_SPRITE_YES].scaleY = 1.7f; - this->menuSprites[RETRY_MENU_SPRITE_YES].scaleX = 1.7f; - this->menuSprites[RETRY_MENU_SPRITE_NO].scaleY = 1.5f; - this->menuSprites[RETRY_MENU_SPRITE_NO].scaleX = 1.5f; - this->menuSprites[RETRY_MENU_SPRITE_YES].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); - this->menuSprites[RETRY_MENU_SPRITE_NO].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - if (3 < this->numFrames) - { - if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) - { - this->curState = RETRY_MENU_CURSOR_NO; - } - if (WAS_PRESSED(TH_BUTTON_SHOOT)) - { - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - this->menuSprites[idx].pendingInterrupt = 2; - } - this->curState = RETRY_MENU_SELECTED_YES; - this->menuBackground.pendingInterrupt = 1; - this->numFrames = 0; - } - } - break; - case RETRY_MENU_CURSOR_NO: - this->menuSprites[RETRY_MENU_SPRITE_NO].color = COLOR_LIGHT_RED; - this->menuSprites[RETRY_MENU_SPRITE_YES].color = COLOR_SET_ALPHA(COLOR_GREY, 0x80); - this->menuSprites[RETRY_MENU_SPRITE_YES].scaleY = 1.5f; - this->menuSprites[RETRY_MENU_SPRITE_YES].scaleX = 1.5f; - this->menuSprites[RETRY_MENU_SPRITE_NO].scaleY = 1.7f; - this->menuSprites[RETRY_MENU_SPRITE_NO].scaleX = 1.7f; - this->menuSprites[RETRY_MENU_SPRITE_NO].posOffset = D3DXVECTOR3(-4.0f, -4.0f, 0.0f); - this->menuSprites[RETRY_MENU_SPRITE_YES].posOffset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); - if (this->numFrames >= 30) - { - if (WAS_PRESSED(TH_BUTTON_UP) || WAS_PRESSED(TH_BUTTON_DOWN)) - { - this->curState = RETRY_MENU_CURSOR_YES; - } - if (WAS_PRESSED(TH_BUTTON_SHOOT)) - { - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - this->menuSprites[idx].pendingInterrupt = 2; - } - this->curState = RETRY_MENU_SELECTED_NO; - this->numFrames = 0; - } - } - break; - case RETRY_MENU_SELECTED_NO: - if (this->numFrames >= 20) - { - this->curState = 0; - this->numFrames = 0; - g_GameManager.isInRetryMenu = 0; - g_Supervisor.curState = SUPERVISOR_STATE_RESULTSCREEN_FROMGAME; - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - this->menuSprites[idx].SetInvisible(); - } - g_GameManager.guiScore = g_GameManager.score; - return 0; - } - break; - case RETRY_MENU_SELECTED_YES: - if (this->numFrames >= 30) - { - this->curState = 0; - this->numFrames = 0; - g_GameManager.isInRetryMenu = 0; - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - this->menuSprites[idx].SetInvisible(); - } - g_GameManager.numRetries++; - g_GameManager.guiScore = g_GameManager.numRetries; - g_GameManager.nextScoreIncrement = 0; - g_GameManager.score = g_GameManager.guiScore; - g_GameManager.livesRemaining = g_Supervisor.defaultConfig.lifeCount; - g_GameManager.bombsRemaining = g_Supervisor.defaultConfig.bombCount; - g_GameManager.grazeInStage = 0; - g_GameManager.currentPower = 0; - g_GameManager.pointItemsCollectedInStage = 0; - g_GameManager.extraLives = 0; - g_Gui.flags.flag0 = 2; - g_Gui.flags.flag1 = 2; - g_Gui.flags.flag3 = 2; - g_Gui.flags.flag4 = 2; - g_Gui.flags.flag2 = 2; - return 0; - } - break; - } - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - g_AnmManager->ExecuteScript(&this->menuSprites[idx]); - } - if (g_Supervisor.lockableBackbuffer) - { - g_AnmManager->ExecuteScript(&this->menuBackground); - } - this->numFrames++; - return 0; -} - -void StageMenu::OnDrawRetryMenu() -{ - int idx; - - if (g_GameManager.isInRetryMenu) - { - g_Supervisor.viewport.X = g_GameManager.arcadeRegionTopLeftPos.x; - g_Supervisor.viewport.Y = g_GameManager.arcadeRegionTopLeftPos.y; - g_Supervisor.viewport.Width = g_GameManager.arcadeRegionSize.x; - g_Supervisor.viewport.Height = g_GameManager.arcadeRegionSize.y; - g_Supervisor.d3dDevice->SetViewport(&g_Supervisor.viewport); - if (g_Supervisor.lockableBackbuffer && (this->curState != RETRY_MENU_OPENING || this->numFrames > 2)) - { - g_AnmManager->DrawNoRotation(&this->menuBackground); - } - if (this->curState == RETRY_MENU_CURSOR_YES || this->curState == RETRY_MENU_CURSOR_NO) - { - this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER] = this->menuSprites[RETRY_MENU_SPRITE_RETRIES_LABEL]; - this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER].pos.x += - 8.0f * this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER].scaleX; - this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER].sprite = - &g_AnmManager->sprites[30 - g_GameManager.numRetries]; - g_AnmManager->DrawNoRotation(&this->menuSprites[RETRY_MENU_SPRITE_RETRIES_NUMBER]); - } - for (idx = RETRY_MENU_SPRITES_START; idx < RETRY_MENU_SPRITES_END; idx++) - { - if (this->menuSprites[idx].flags.isVisible) - { - g_AnmManager->DrawNoRotation(&this->menuSprites[idx]); - } - } - } - return; -} -}; // namespace th06 From d520bb3a5dc51ea9740d51908d67f2cbd3120148 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sat, 2 Nov 2024 16:48:20 +0100 Subject: [PATCH 4/6] Add /Gy to the commandline flags to better match orig binary --- scripts/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/configure.py b/scripts/configure.py index c0d44e0b..6ef1585f 100644 --- a/scripts/configure.py +++ b/scripts/configure.py @@ -27,7 +27,7 @@ def configure(build_type): "cl_common_flags", "/MT /EHsc /G5 /Gs /GS /DNDEBUG /Zi /I $builddir/autogenerated /I src /I 3rdparty/munit /I 3rdparty/Detours/src", ) - writer.variable("cl_flags", "$cl_common_flags /Od /Oi /Ob1 /Op") + writer.variable("cl_flags", "$cl_common_flags /Od /Oi /Ob1 /Op /Gy") writer.variable("cl_flags_pbg3", "$cl_common_flags /O2") writer.variable( "cl_flags_detours", From 875b6de6dcdc62c1aaedf1a4996b1c7901a972a9 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sat, 2 Nov 2024 16:48:36 +0100 Subject: [PATCH 5/6] Improve AsciiManager::OnUpdate accuracy --- src/AsciiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AsciiManager.cpp b/src/AsciiManager.cpp index bb31bec6..ce098471 100644 --- a/src/AsciiManager.cpp +++ b/src/AsciiManager.cpp @@ -41,7 +41,7 @@ ChainCallbackResult AsciiManager::OnUpdate(AsciiManager *mgr) curPopup->position.y -= 0.5f * g_Supervisor.effectiveFramerateMultiplier; curPopup->timer.Tick(); - if ((bool)(curPopup->timer.current > 60)) + if ((i32)(curPopup->timer.current > 60)) { curPopup->inUse = false; } From 1c71f7aa5d9105cdc85e7041ea764ef6d1914800 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sat, 2 Nov 2024 16:48:58 +0100 Subject: [PATCH 6/6] Reorder AsciiManager functions to better match original --- src/AsciiManager.cpp | 78 ++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/AsciiManager.cpp b/src/AsciiManager.cpp index ce098471..6142af6a 100644 --- a/src/AsciiManager.cpp +++ b/src/AsciiManager.cpp @@ -170,6 +170,45 @@ void AsciiManager::CutChain() // to free it! } +void AsciiManager::AddString(D3DXVECTOR3 *position, char *text) +{ + if (this->numStrings >= 0x100) + { + return; + } + + AsciiManagerString *curString = &this->strings[this->numStrings]; + this->numStrings += 1; + // Hello unguarded strcpy my old friend. If text is bigger than 64 + // characters, kboom. + strcpy(curString->text, text); + curString->position = *position; + curString->color = this->color; + curString->scale.x = this->scale.x; + curString->scale.y = this->scale.y; + curString->isGui = this->isGui; + if (g_Supervisor.cfg.IsSoftwareTexturing()) + { + curString->isSelected = this->isSelected; + } + else + { + curString->isSelected = 0; + } +} + +void AsciiManager::AddFormatText(D3DXVECTOR3 *position, const char *fmt, ...) +{ + char tmpBuffer[512]; + va_list args; + + va_start(args, fmt); + vsprintf(tmpBuffer, fmt, args); + AddString(position, tmpBuffer); + + va_end(args); +} + #pragma var_order(charWidth, i, string, text, guiString, padding_1, padding_2, padding_3) void AsciiManager::DrawStrings(void) { @@ -244,45 +283,6 @@ void AsciiManager::DrawStrings(void) } } -void AsciiManager::AddString(D3DXVECTOR3 *position, char *text) -{ - if (this->numStrings >= 0x100) - { - return; - } - - AsciiManagerString *curString = &this->strings[this->numStrings]; - this->numStrings += 1; - // Hello unguarded strcpy my old friend. If text is bigger than 64 - // characters, kboom. - strcpy(curString->text, text); - curString->position = *position; - curString->color = this->color; - curString->scale.x = this->scale.x; - curString->scale.y = this->scale.y; - curString->isGui = this->isGui; - if (g_Supervisor.cfg.IsSoftwareTexturing()) - { - curString->isSelected = this->isSelected; - } - else - { - curString->isSelected = 0; - } -} - -void AsciiManager::AddFormatText(D3DXVECTOR3 *position, const char *fmt, ...) -{ - char tmpBuffer[512]; - va_list args; - - va_start(args, fmt); - vsprintf(tmpBuffer, fmt, args); - AddString(position, tmpBuffer); - - va_end(args); -} - void AsciiManager::CreatePopup1(D3DXVECTOR3 *position, i32 value, D3DCOLOR color) { AsciiManagerPopup *popup;