From 4f3144472ad72e8e4e7526ebbeb9872c98c8f360 Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 13 Feb 2025 18:25:42 +0300 Subject: [PATCH] Fix model explosion in Temple Entrance cutscene. (#395) --- UnleashedRecomp/patches/inspire_patches.cpp | 31 +++++++++++++++++++++ UnleashedRecompLib/config/SWA.toml | 5 ++++ 2 files changed, 36 insertions(+) diff --git a/UnleashedRecomp/patches/inspire_patches.cpp b/UnleashedRecomp/patches/inspire_patches.cpp index a918936..4e493bc 100644 --- a/UnleashedRecomp/patches/inspire_patches.cpp +++ b/UnleashedRecomp/patches/inspire_patches.cpp @@ -32,6 +32,11 @@ static std::unordered_map> g_evilSonic { "evrt_m8_04", { 0, 2314 } } // Dark Gaia Appears }; +// Sonic's mouth EXPLODES for a single frame in Temple Entrance cutscene. +// Looks very nasty. Let's hide morph models inbetween certain frames to solve it. +static bool g_loadedMouthExplosionAnimation; +static bool g_hideMorphModels; + // SWA::Inspire::CScene PPC_FUNC_IMPL(__imp__sub_82B98D80); PPC_FUNC(sub_82B98D80) @@ -53,6 +58,9 @@ PPC_FUNC(sub_82B98D30) InspirePatches::s_sceneName.clear(); SDL_User_EvilSonic(App::s_isWerehog); + + g_loadedMouthExplosionAnimation = false; + g_hideMorphModels = false; } PPC_FUNC_IMPL(__imp__sub_82B9BA98); @@ -65,6 +73,26 @@ PPC_FUNC(sub_82B9BA98) __imp__sub_82B9BA98(ctx, base); } +void AnimationDataMakeMidAsmHook(PPCRegister& r31, PPCRegister& r29, PPCRegister& r28) +{ + uint8_t* base = g_memory.base; + + if (r28.u32 == 0x222E0 && + strcmp(reinterpret_cast(base + PPC_LOAD_U32(r31.u32)), "t0_04_SN") == 0 && + XXH3_64bits(base + r29.u32, r28.u32) == 0xEC634F0F379F478A) + { + g_loadedMouthExplosionAnimation = true; + } +} + +// Hedgehog::Mirage::CSingleMorphElement::Render +PPC_FUNC_IMPL(__imp__sub_82E32048); +PPC_FUNC(sub_82E32048) +{ + if (!g_hideMorphModels) + __imp__sub_82E32048(ctx, base); +} + void InspirePatches::DrawDebug() { if (!g_pScene) @@ -101,6 +129,9 @@ void InspirePatches::Update() if (!g_pScene || !InspirePatches::s_sceneName.size()) return; + g_hideMorphModels = g_loadedMouthExplosionAnimation && g_pScene->m_pData->Frame >= 185.0f && + g_pScene->m_pData->Frame < 195.0f && InspirePatches::s_sceneName == "evrt_t0_04"; + if (!g_isFirstFrameChecked && std::find(g_alwaysEvilSonic.begin(), g_alwaysEvilSonic.end(), InspirePatches::s_sceneName) != g_alwaysEvilSonic.end()) { SDL_User_EvilSonic(true); diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 09ccfee..509134d 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -1056,3 +1056,8 @@ registers = ["v62"] name = "BossEggDragoonDrillMissileCMissileSetRotationMidAsmHook" address = 0x82A9BADC registers = ["r4"] + +[[midasm_hook]] +name = "AnimationDataMakeMidAsmHook" +address = 0x82BB38E4 +registers = ["r31", "r29", "r28"]