-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace old pause buffer input experience with a more accurate one
- Loading branch information
1 parent
8244d63
commit 60e483a
Showing
15 changed files
with
137 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <libultraship/libultraship.h> | ||
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" | ||
#include "soh/ShipInit.hpp" | ||
|
||
extern "C" { | ||
#include "variables.h" | ||
#include "overlays/misc/ovl_kaleido_scope/z_kaleido_scope.h" | ||
} | ||
|
||
#define CVAR_FRAME_ADVANCE_NAME CVAR_CHEAT("EasyFrameAdvance") | ||
#define CVAR_FRAME_ADVANCE_DEFAULT 0 | ||
#define CVAR_FRAME_ADVANCE_VALUE CVarGetInteger(CVAR_FRAME_ADVANCE_NAME, CVAR_FRAME_ADVANCE_DEFAULT) | ||
|
||
static int frameAdvanceTimer = 0; | ||
#define PAUSE_STATE_OFF 0 | ||
#define PAUSE_STATE_UNPAUSE_CLOSE 19 | ||
|
||
void RegisterEasyFrameAdvance() { | ||
COND_HOOK(OnGameStateMainStart, CVAR_FRAME_ADVANCE_VALUE, []() { | ||
if (gPlayState == NULL) { | ||
return; | ||
} | ||
|
||
Input* input = &gPlayState->state.input[0]; | ||
PauseContext* pauseCtx = &gPlayState->pauseCtx; | ||
|
||
if (frameAdvanceTimer > 0 && pauseCtx->state == PAUSE_STATE_OFF) { | ||
frameAdvanceTimer--; | ||
if (frameAdvanceTimer == 0 && CHECK_BTN_ALL(input->cur.button, BTN_START)) { | ||
input->press.button |= BTN_START; | ||
} | ||
} | ||
|
||
if (pauseCtx->state == PAUSE_STATE_UNPAUSE_CLOSE) { | ||
frameAdvanceTimer = 2; | ||
} | ||
}); | ||
} | ||
|
||
static RegisterShipInitFunc initFunc(RegisterEasyFrameAdvance, { CVAR_FRAME_ADVANCE_NAME }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <libultraship/libultraship.h> | ||
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" | ||
#include "soh/ShipInit.hpp" | ||
|
||
extern "C" { | ||
#include "variables.h" | ||
#include "overlays/misc/ovl_kaleido_scope/z_kaleido_scope.h" | ||
} | ||
|
||
#define CVAR_BUFFER_NAME CVAR_ENHANCEMENT("PauseBufferWindow") | ||
#define CVAR_BUFFER_DEFAULT 0 | ||
#define CVAR_BUFFER_VALUE CVarGetInteger(CVAR_BUFFER_NAME, CVAR_BUFFER_DEFAULT) | ||
|
||
#define CVAR_INCLUDE_NAME CVAR_ENHANCEMENT("IncludeHeldInputsBufferWindow") | ||
#define CVAR_INCLUDE_DEFAULT 0 | ||
#define CVAR_INCLUDE_VALUE CVarGetInteger(CVAR_INCLUDE_NAME, CVAR_INCLUDE_DEFAULT) | ||
|
||
#define CVAR_FRAME_ADVANCE_NAME CVAR_CHEAT("EasyFrameAdvance") | ||
#define CVAR_FRAME_ADVANCE_DEFAULT 0 | ||
#define CVAR_FRAME_ADVANCE_VALUE CVarGetInteger(CVAR_FRAME_ADVANCE_NAME, CVAR_FRAME_ADVANCE_DEFAULT) | ||
|
||
static u16 inputBufferTimer = 0; | ||
static u16 pauseInputs = 0; | ||
#define PAUSE_STATE_OFF 0 | ||
#define PAUSE_STATE_UNPAUSE_SETUP 18 | ||
|
||
void RegisterPauseBufferInputs() { | ||
COND_VB_SHOULD(VB_KALEIDO_UNPAUSE_CLOSE, CVAR_BUFFER_VALUE || CVAR_INCLUDE_VALUE, { | ||
Input* input = &gPlayState->state.input[0]; | ||
|
||
// Store all inputs that were pressed during the buffer window | ||
pauseInputs |= input->press.button; | ||
|
||
// If the user opts to include held inputs in the buffer window, store the held inputs as well | ||
if (CVAR_INCLUDE_VALUE && inputBufferTimer == 0) { | ||
pauseInputs |= input->cur.button; | ||
} | ||
|
||
// Wait a specified number of frames before continuing the unpause | ||
inputBufferTimer++; | ||
if (inputBufferTimer < CVAR_BUFFER_VALUE) { | ||
*should = false; | ||
} | ||
}); | ||
|
||
COND_HOOK(OnGameStateMainStart, CVAR_BUFFER_VALUE || CVAR_INCLUDE_VALUE, []() { | ||
if (gPlayState == NULL) { | ||
return; | ||
} | ||
|
||
Input* input = &gPlayState->state.input[0]; | ||
PauseContext* pauseCtx = &gPlayState->pauseCtx; | ||
|
||
// if the input buffer timer is not 0 and the pause state is off, then the player just unpaused | ||
if (inputBufferTimer != 0 && pauseCtx->state == PAUSE_STATE_OFF) { | ||
inputBufferTimer = 0; | ||
|
||
// If the user opts into easy frame advance, remove START input | ||
if (CVAR_FRAME_ADVANCE_VALUE) { | ||
pauseInputs &= ~BTN_START; | ||
} | ||
|
||
// So we need to re-apply the inputs that were pressed during the buffer window | ||
input->press.button |= pauseInputs; | ||
} | ||
|
||
// Reset the timer and stored inputs at the beginning of the unpause process | ||
if (pauseCtx->state == PAUSE_STATE_UNPAUSE_SETUP && pauseCtx->unk_1F4 != 160.0f) { | ||
inputBufferTimer = 0; | ||
pauseInputs = 0; | ||
} | ||
}); | ||
} | ||
|
||
static RegisterShipInitFunc initFunc(RegisterPauseBufferInputs, { CVAR_BUFFER_NAME, CVAR_INCLUDE_NAME }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters