Files
UnleashedRecomp-hedge-dev/UnleashedRecomp/patches/player_patches.cpp
T
Hyper ec5c51f54c Migrate game.cpp to categorised source files (#3)
* Migrate game.cpp to categorised source files

Co-Authored-By: Skyth (Asilkan) <19259897+blueskythlikesclouds@users.noreply.github.com>
Co-Authored-By: Michael <15317421+ActualMandM@users.noreply.github.com>

* Move motion blur hook to video_patches.cpp

---------

Co-authored-by: Skyth (Asilkan) <19259897+blueskythlikesclouds@users.noreply.github.com>
Co-authored-by: Michael <15317421+ActualMandM@users.noreply.github.com>
2024-11-08 16:18:41 +03:00

92 lines
2.3 KiB
C++

#include <cpu/guest_code.h>
#include "api/SWA.h"
#include "config.h"
uint32_t m_lastCheckpointScore = 0;
float m_lastDarkGaiaEnergy = 0.0f;
bool m_isUnleashCancelled = false;
/* 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;
}
// Dark Gaia energy change hook.
PPC_FUNC_IMPL(__imp__sub_823AF7A8);
PPC_FUNC(sub_823AF7A8)
{
auto pEvilSonicContext = (SWA::Player::CEvilSonicContext*)g_memory.Translate(ctx.r3.u32);
m_lastDarkGaiaEnergy = pEvilSonicContext->m_DarkGaiaEnergy;
// Don't drain energy if out of control.
if (!Config::UnleashOutOfControlDrain && pEvilSonicContext->m_OutOfControlCount && ctx.f1.f64 < 0.0)
return;
__imp__sub_823AF7A8(ctx, base);
if (!Config::UnleashCancel)
return;
auto pInputState = SWA::CInputState::GetInstance();
// Don't allow cancelling Unleash if the intro anim is still playing.
if (!pInputState || pEvilSonicContext->m_AnimationID == 39)
return;
if (pInputState->GetPadState().IsTapped(SWA::eKeyState_RightBumper))
{
pEvilSonicContext->m_DarkGaiaEnergy = 0.0f;
m_isUnleashCancelled = true;
}
}
void PostUnleashMidAsmHook(PPCRegister& r30)
{
if (m_isUnleashCancelled)
{
if (auto pEvilSonicContext = (SWA::Player::CEvilSonicContext*)g_memory.Translate(r30.u32))
pEvilSonicContext->m_DarkGaiaEnergy = m_lastDarkGaiaEnergy;
m_isUnleashCancelled = false;
}
}