diff --git a/UnleashedRecomp/api/SWA/System/ApplicationDocument.h b/UnleashedRecomp/api/SWA/System/ApplicationDocument.h index 8dcda66..717c81a 100644 --- a/UnleashedRecomp/api/SWA/System/ApplicationDocument.h +++ b/UnleashedRecomp/api/SWA/System/ApplicationDocument.h @@ -5,8 +5,9 @@ namespace SWA class CApplicationDocument // : public Hedgehog::Base::CSynchronizedObject { public: + // TODO: use g_memory.Translate? // TODO: Hedgehog::Base::TSynchronizedPtr* - inline static xpointer* ms_pInstance = (xpointer*)g_memory.Translate(0x833678A0); + inline static xpointer* ms_pInstance = (xpointer*)0x1833678A0; // TODO: Hedgehog::Base::TSynchronizedPtr static CApplicationDocument* GetInstance(); diff --git a/UnleashedRecomp/api/SWA/System/GameDocument.h b/UnleashedRecomp/api/SWA/System/GameDocument.h index 78b6e05..db4fecf 100644 --- a/UnleashedRecomp/api/SWA/System/GameDocument.h +++ b/UnleashedRecomp/api/SWA/System/GameDocument.h @@ -12,8 +12,9 @@ namespace SWA be m_Score; }; + // TODO: use g_memory.Translate? // TODO: Hedgehog::Base::TSynchronizedPtr* - inline static xpointer* ms_pInstance = (xpointer*)g_memory.Translate(0x83367900); + inline static xpointer* ms_pInstance = (xpointer*)0x183367900; // TODO: Hedgehog::Base::TSynchronizedPtr static CGameDocument* GetInstance(); diff --git a/UnleashedRecomp/api/SWA/System/InputState.h b/UnleashedRecomp/api/SWA/System/InputState.h index d5dea02..e6d8f6a 100644 --- a/UnleashedRecomp/api/SWA/System/InputState.h +++ b/UnleashedRecomp/api/SWA/System/InputState.h @@ -8,8 +8,9 @@ namespace SWA class CInputState // : public Hedgehog::Base::CSynchronizedObject { public: + // TODO: use g_memory.Translate? // TODO: Hedgehog::Base::TSynchronizedPtr* - inline static xpointer* ms_pInstance = (xpointer*)g_memory.Translate(0x833671EC); + inline static xpointer* ms_pInstance = (xpointer*)0x1833671EC; // TODO: Hedgehog::Base::TSynchronizedPtr static CInputState* GetInstance(); diff --git a/UnleashedRecomp/game.cpp b/UnleashedRecomp/game.cpp index 839c2f0..9c3afa3 100644 --- a/UnleashedRecomp/game.cpp +++ b/UnleashedRecomp/game.cpp @@ -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 diff --git a/UnleashedRecomp/ui/window.cpp b/UnleashedRecomp/ui/window.cpp index 5474539..ce5d5e9 100644 --- a/UnleashedRecomp/ui/window.cpp +++ b/UnleashedRecomp/ui/window.cpp @@ -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"; diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 53dded8..6ad1b8d 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -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"