Implemented score hooks

This commit is contained in:
Hyper 2024-10-17 23:41:38 +01:00
parent ce95692d8a
commit ceee6948a8
6 changed files with 70 additions and 4 deletions

View file

@ -5,8 +5,9 @@ namespace SWA
class CApplicationDocument // : public Hedgehog::Base::CSynchronizedObject
{
public:
// TODO: use g_memory.Translate?
// TODO: Hedgehog::Base::TSynchronizedPtr<CApplicationDocument>*
inline static xpointer<CApplicationDocument>* ms_pInstance = (xpointer<CApplicationDocument>*)g_memory.Translate(0x833678A0);
inline static xpointer<CApplicationDocument>* ms_pInstance = (xpointer<CApplicationDocument>*)0x1833678A0;
// TODO: Hedgehog::Base::TSynchronizedPtr<CApplicationDocument>
static CApplicationDocument* GetInstance();

View file

@ -12,8 +12,9 @@ namespace SWA
be<uint32_t> m_Score;
};
// TODO: use g_memory.Translate?
// TODO: Hedgehog::Base::TSynchronizedPtr<CGameDocument>*
inline static xpointer<CGameDocument>* ms_pInstance = (xpointer<CGameDocument>*)g_memory.Translate(0x83367900);
inline static xpointer<CGameDocument>* ms_pInstance = (xpointer<CGameDocument>*)0x183367900;
// TODO: Hedgehog::Base::TSynchronizedPtr<CGameDocument>
static CGameDocument* GetInstance();

View file

@ -8,8 +8,9 @@ namespace SWA
class CInputState // : public Hedgehog::Base::CSynchronizedObject
{
public:
// TODO: use g_memory.Translate?
// TODO: Hedgehog::Base::TSynchronizedPtr<CInputState>*
inline static xpointer<CInputState>* ms_pInstance = (xpointer<CInputState>*)g_memory.Translate(0x833671EC);
inline static xpointer<CInputState>* ms_pInstance = (xpointer<CInputState>*)0x1833671EC;
// TODO: Hedgehog::Base::TSynchronizedPtr<CInputState>
static CInputState* GetInstance();

View file

@ -5,6 +5,8 @@
constexpr float m_baseAspectRatio = 16.0f / 9.0f;
uint32_t m_lastCheckpointScore = 0;
void Game::Exit()
{
s_isSignalExit = true;
@ -16,6 +18,8 @@ bool GracefulLoopExitMidAsmHook()
return Game::s_isSignalExit;
}
#pragma region Aspect Ratio Hooks
bool CameraAspectRatioMidAsmHook(PPCRegister& r31)
{
auto pCamera = (SWA::CCamera*)g_memory.Translate(r31.u32);
@ -72,6 +76,57 @@ void CSDOffsetMidAsmHook(PPCRegister& f1, PPCRegister& f2)
}
}
#pragma endregion
#pragma region Score Hooks
/* Hook function for when checkpoints are activated
to preserve the current checkpoint score. */
PPC_FUNC_IMPL(__imp__sub_82624308);
PPC_FUNC(sub_82624308)
{
__imp__sub_82624308(ctx, base);
if (Config::ScoreBehaviour != EScoreBehaviour_CheckpointRetain)
return;
auto pGameDocument = SWA::CGameDocument::GetInstance();
if (!pGameDocument)
return;
m_lastCheckpointScore = pGameDocument->m_pMember->m_Score;
}
/* Hook function that resets the score
and restore the last checkpoint score. */
PPC_FUNC_IMPL(__imp__sub_8245F048);
PPC_FUNC(sub_8245F048)
{
__imp__sub_8245F048(ctx, base);
if (Config::ScoreBehaviour != EScoreBehaviour_CheckpointRetain)
return;
auto pGameDocument = SWA::CGameDocument::GetInstance();
if (!pGameDocument)
return;
printf("Resetting score to %d\n", m_lastCheckpointScore);
pGameDocument->m_pMember->m_Score = m_lastCheckpointScore;
}
void ResetScoreOnRestartMidAsmHook()
{
m_lastCheckpointScore = 0;
}
#pragma endregion
#pragma region Miscellaneous Hooks
bool DisableHintsMidAsmHook()
{
return !Config::Hints;
@ -91,3 +146,5 @@ PPC_FUNC(sub_825197C0)
__imp__sub_825197C0(ctx, base);
}
#pragma endregion

View file

@ -79,6 +79,8 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
void Window::Init()
{
/* TODO: move this since it'll have to change
on soft reboot from the options menu. */
auto title = Config::Language == ELanguage_Japanese
? "Sonic World Adventure"
: "SONIC UNLEASHED";

View file

@ -24,7 +24,7 @@ savevmx_64_address = 0x831B34E4
longjmp_address = 0x831B6790
setjmp_address = 0x831B6AB0
# These functions do not exist in .pdata and
# These functions do not exist in .pdata and do
# not analyze properly due to having jump tables
functions = [
{ address = 0x824E7EF0, size = 0x98 },
@ -132,6 +132,10 @@ address = 0x830C0A78
registers = ["f1", "f2"]
return = true
[[midasm_hook]]
name = "ResetScoreOnRestartMidAsmHook"
address = 0x82304374
# Disable hint volumes
[[midasm_hook]]
name = "DisableHintsMidAsmHook"