From d7e9179de0bea8877411fde8ad1b925d1e6a35fa Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 00:50:17 +0300 Subject: [PATCH 1/8] SonicGaugeCode --- MarathonRecomp/api/Marathon.h | 1 + MarathonRecomp/api/Sonicteam/GameImp.h | 2 +- .../api/Sonicteam/Player/SonicGauge.h | 11 +- .../Sonicteam/Player/State/CommonContext.h | 28 ++- .../Player/State/ContextSpeedAndJump.h | 8 +- .../Sonicteam/Player/State/ICommonContext.h | 10 +- .../api/Sonicteam/Player/State/Machine2.h | 1 + .../api/Sonicteam/Player/State/SonicContext.h | 60 +++++ MarathonRecomp/patches/player_patches.cpp | 233 ++++++++++++++++++ MarathonRecomp/user/config_def.h | 1 + MarathonRecompLib/config/Marathon.toml | 25 ++ 11 files changed, 373 insertions(+), 7 deletions(-) create mode 100644 MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index ebdf1f766..a7cf39e60 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -46,6 +46,7 @@ #include "Sonicteam/Player/State/IMachine.h" #include "Sonicteam/Player/State/Machine2.h" #include "Sonicteam/Player/State/Object2.h" +#include "Sonicteam/Player/State/SonicContext.h" #include "Sonicteam/Player/State/TailsContext.h" #include "Sonicteam/SoX/AI/StateMachine.h" #include "Sonicteam/SoX/Component.h" diff --git a/MarathonRecomp/api/Sonicteam/GameImp.h b/MarathonRecomp/api/Sonicteam/GameImp.h index 2dc4855a1..1af2b999b 100644 --- a/MarathonRecomp/api/Sonicteam/GameImp.h +++ b/MarathonRecomp/api/Sonicteam/GameImp.h @@ -11,7 +11,7 @@ namespace Sonicteam { be ActorID; be RingCount; - MARATHON_INSERT_PADDING(4); + be TownRingCount; be LifeCount; be ScoreCount; be AliveTime; diff --git a/MarathonRecomp/api/Sonicteam/Player/SonicGauge.h b/MarathonRecomp/api/Sonicteam/Player/SonicGauge.h index 07b7dd9d0..d628e4114 100644 --- a/MarathonRecomp/api/Sonicteam/Player/SonicGauge.h +++ b/MarathonRecomp/api/Sonicteam/Player/SonicGauge.h @@ -12,6 +12,15 @@ namespace Sonicteam::Player be m_Flags; be m_GroundedFlags; be m_Maximum; - MARATHON_INSERT_PADDING(0x28); + be m_Green; + be m_Red; + be m_Blue; + be m_White; + be m_Sky; + be m_Yellow; + be m_Purple; + be m_Super; + be m_Heal; + be m_HealDelay; }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h b/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h index 11922870c..52dca2f68 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h @@ -1,5 +1,4 @@ #pragma once - #include #include #include @@ -8,10 +7,35 @@ namespace Sonicteam::Player::State { + + + class CommonContext : public ICommonContext, public IExportPostureRequestFlag, public IExportWeaponRequestFlag { public: - MARATHON_INSERT_PADDING(0x90); + + //(Gordon Ramsay) + enum PostureEnum:uint32_t{ + CC_GROUND = 0x1, // detects Ground + CC_WALLBRUSHING = 0x8, // detects brushing against a wall + CC_HEADONWALL = 0x10, // detects head-on wall collision (will always be enabled w/ 2^3) + CC_RAILGRIND = 0x40, // Rail grinding + CC_BEFOREFALL = 0x100, // seems like Neutral or Pre-Fall? The moment before transitioning from the Jump to Fall animation + CC_FALL = 0x200, // FALL + CC_WATERLCOL = 0x800, // Water collision (making you slide down an incline)? 2^8(CC_BEFOREFALL) is often set with this + CC_LIGHTDASHIN = 0x4000, // Light Dashing (2 ^ 14) + CC_QUICKROTATE = 0x8000, // is moving the control stick in a non-forward direction (usually only active for a frame since the character instantly rotates) + CC_TENTATIVE = 0x10000, // is Tentative collision + CC_WATERSLIDE = 0x20000, // Water sliding (2^17) + CC_GRASS = 0x100000, // grass 2^20 + CC_DIRTCLAY = 0x200000, // dirt/clay (2^21) + CC_STONE = 0x400000, // stone (2^22) + CC_SHORELINE = 0x1000000, // shoreline? sand? Uncertain (2^24) + }; + + MARATHON_INSERT_PADDING(0x2C); + be m_PostureFlags; + MARATHON_INSERT_PADDING(0x60); xpointer m_pScore; MARATHON_INSERT_PADDING(0x104); }; diff --git a/MarathonRecomp/api/Sonicteam/Player/State/ContextSpeedAndJump.h b/MarathonRecomp/api/Sonicteam/Player/State/ContextSpeedAndJump.h index 8a9f012a7..b781b7b7b 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/ContextSpeedAndJump.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/ContextSpeedAndJump.h @@ -4,5 +4,11 @@ namespace Sonicteam::Player::State { - class ContextSpeedAndJump {}; + class ContextSpeedAndJump + { + be base_speed_z; + be gimmick_speed_z; + be base_speed_y; + be gimmick_speed_y; + }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/State/ICommonContext.h b/MarathonRecomp/api/Sonicteam/Player/State/ICommonContext.h index a98b2d2a8..e8c482e68 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/ICommonContext.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/ICommonContext.h @@ -1,5 +1,4 @@ #pragma once - #include #include #include @@ -10,6 +9,13 @@ namespace Sonicteam::Player::State class ICommonContext : public IContext, public ICommonContextIF, public ContextSpeedAndJump { public: - MARATHON_INSERT_PADDING(0x60); + be m_CurrentAnimation; + be m_LockInputTime; + be m_LastVelocityZ; + be m_LastVelocityY; + be m_LastLockInputTime; + be m_Input; + MARATHON_INSERT_PADDING(0x38); }; + } diff --git a/MarathonRecomp/api/Sonicteam/Player/State/Machine2.h b/MarathonRecomp/api/Sonicteam/Player/State/Machine2.h index 3fe896e79..522397b79 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/Machine2.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/Machine2.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace Sonicteam::Player::State { diff --git a/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h b/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h new file mode 100644 index 000000000..597041467 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h @@ -0,0 +1,60 @@ +#pragma once +#include +#include +#include +#include + + +namespace Sonicteam::Player::State +{ + class SonicContext : public CommonContext + { + public: + + + //Sprite + enum GemsS:uint32_t { + SGreen = 1, + SRed, + SBlue, + SWhite, + SSky, + SYellow, + SPurple, + SSuper + }; + enum Gems:uint32_t { + Blue = 1, + Red, + Green, + Purple, + Sky, + White, + Yellow, + Super + }; + + + + be m_CurrentGemSprite; + boost::shared_ptr m_Gauge; + uint8_t m_HomingLockOn; + uint8_t m_DisablePlayerMovement; + uint8_t m_AntigravityHitBox; + uint8_t m_23F; + uint8_t m_BoundAttackHitBox; + uint8_t m_241; + uint8_t m_Shrink; + uint8_t m_ThunderGuard; + uint8_t m_Tornado; + uint8_t m_FPS; + uint8_t m_ThrowGem; + uint8_t m_SlowTime; + uint8_t m_MachAura; + uint8_t m_GemsEnabled; + uint8_t m_24A; + uint8_t m_24B; + be m_HomingFlip; + be m_CurrentGem; + }; +} diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 265934425..eb28615fb 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -41,6 +41,7 @@ PPC_FUNC(sub_8221A7D8) __imp__sub_8221A7D8(ctx, base); } + // Sonicteam::Player::State::*Context IDynamicLink::Init PPC_FUNC_IMPL(__imp__sub_8220F330); PPC_FUNC(sub_8220F330) @@ -74,3 +75,235 @@ PPC_FUNC(sub_8220F330) __imp__sub_8220F330(ctx, base); } + + + + +//////////////////////////////////////////////////////// +///////////// Sonic Gauge Restoration //////////////// +//////////////////////////////////////////////////////// +//TODO Rei: Sky Gem Throw Lock Heal + +const Sonicteam::Player::State::SonicContext::GemsS gemConversionTable[] = { + Sonicteam::Player::State::SonicContext::GemsS::SBlue, + Sonicteam::Player::State::SonicContext::GemsS::SRed, + Sonicteam::Player::State::SonicContext::GemsS::SGreen, + Sonicteam::Player::State::SonicContext::GemsS::SPurple, + Sonicteam::Player::State::SonicContext::GemsS::SSky, + Sonicteam::Player::State::SonicContext::GemsS::SWhite, + Sonicteam::Player::State::SonicContext::GemsS::SYellow, + Sonicteam::Player::State::SonicContext::GemsS::SSuper +}; + +//Check Gauge Drain +//SonicTeam::Player::SonicGauge (IVariable), IVariable::Init(REF_TYPE(SonicTeam::LuaSystem)) +PPC_FUNC_IMPL(__imp__sub_82217FC0); +PPC_FUNC(sub_82217FC0) { + + if (!Config::SonicGauge) + { + __imp__sub_82217FC0(ctx, base); + return; + } + + auto context = (Sonicteam::Player::State::SonicContext*)g_memory.Translate(ctx.r3.u32); + auto gauge = context->m_Gauge.get(); + + using enum Sonicteam::Player::State::SonicContext::Gems; + auto gem_id = (Sonicteam::Player::State::SonicContext::Gems)(ctx.r4.u32); + + switch (gem_id) { + case Blue: + case Green: + case Yellow: + case Sky: + case White: + case Super: + { + size_t index = gemConversionTable[gem_id - 1] - 1; + if (gauge->m_Value >= (&gauge->m_Green)[index].get()) { + ctx.r3.u64 = 1; + return; + } + break; + } + case Red: + case Purple: + if (context->m_24A == 0) + { + ctx.r3.u64 = 1; + return; + } + break; + } + ctx.r3.u64 = 0; + return; + +} +//Gauge Drain +PPC_FUNC_IMPL(__imp__sub_82218068); +PPC_FUNC(sub_82218068) { + + if (!Config::SonicGauge) + { + __imp__sub_82217FC0(ctx, base); + return; + } + + auto context = (Sonicteam::Player::State::SonicContext*)g_memory.Translate(ctx.r3.u32); + auto gauge = context->m_Gauge.get(); + + using enum Sonicteam::Player::State::SonicContext::Gems; + auto gem_id = (Sonicteam::Player::State::SonicContext::Gems)(ctx.r4.u32); + double delta = ctx.f1.f64; + + switch (gem_id) { + case Blue: + case Green: + case Yellow: + case Sky: + case White: + case Super: + { + uint32_t index = gemConversionTable[gem_id - 1] - 1; + gauge->m_Value = gauge->m_Value.get() - (&gauge->m_Green)[index].get(); + gauge->m_GroundedTime = 0.0; + break; + } + case Red: + case Purple: + { + uint32_t index = gemConversionTable[gem_id - 1] - 1; + gauge->m_Value = gauge->m_Value.get() - (&gauge->m_Green)[index].get() * delta; + gauge->m_GroundedTime = 0.0; + if (gauge->m_Value <= 0) + { + gauge->m_Value = 0.0; + context->m_Shrink = 0; + context->m_SlowTime = 0; + context->m_24A = 1; + + } + break; + } + } +} + + +PPC_FUNC_IMPL(__imp__sub_8223F360); +PPC_FUNC(sub_8223F360) { + + auto IVariable = ctx.r3.u32; + auto RefTypeLuaSystem = ctx.r4.u32; + __imp__sub_8223F360(ctx, base); + if (!Config::SonicGauge) + return; + + auto gauge = (Sonicteam::Player::SonicGauge*)g_memory.Translate(IVariable - 0x20); + auto buffer = g_userHeap.Alloc(); + + // if (gauge->m_Gem == 0.0) if m_Gem not intitialized by __imp__sub_8223F360 + *buffer = "c_gauge_green"; + if (gauge->m_Green.get() == 0.0) + gauge->m_Green = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_red"; + if (gauge->m_Red.get()== 0.0) + gauge->m_Red = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_blue"; + if (gauge->m_Blue.get() == 0.0) + gauge->m_Blue = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_white"; + if (gauge->m_White.get() == 0.0) + gauge->m_White = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_sky"; + if (gauge->m_Sky.get() == 0.0) + gauge->m_Sky = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_yellow"; + if (gauge->m_Yellow.get() == 0.0) + gauge->m_Yellow = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_purple"; + if (gauge->m_Purple.get() == 0.0) + gauge->m_Purple = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + *buffer = "c_gauge_super"; + if (gauge->m_Super.get() == 0.0) + gauge->m_Super = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + /* For Testing + gauge->m_Green = 10; + gauge->m_Blue = 20; + gauge->m_White = 40; + gauge->m_Sky = 60; + gauge->m_Yellow = 80; + gauge->m_Super = 100; + gauge->m_Red = 20; + gauge->m_Purple = 40; + */ +} + + +void SonicGaugeRestorationGaugeGemSpriteResetFix(PPCRegister& r_GameImp) { + + Sonicteam::GameImp* pGameImp = (Sonicteam::GameImp*)g_memory.Translate(r_GameImp.u32); + for (int i = 0; i < 4; i++) pGameImp->m_PlayerData[i].GemIndex = 0; +} + + +void SonicGaugeRestorationGaugeFlagFix(PPCRegister& r_gauge, PPCRegister& r_context) { + + if (!Config::SonicGauge || !r_gauge.u32) + return; + + + auto pGauge = (Sonicteam::Player::SonicGauge*)g_memory.Translate(r_gauge.u32); + auto PContext = (Sonicteam::Player::State::SonicContext*)g_memory.Translate(r_context.u32); + if ((uint32_t)(static_cast(pGauge)->m_pVftable.get()) != 0x8200D4D8) // != SonicGauge + return; + + + + + if (PContext->m_Tornado != 0 || PContext->m_CurrentAnimation == 0xCB || PContext->m_CurrentAnimation == 0xCC || PContext->m_CurrentAnimation == 0x46) + { + pGauge->m_GroundedFlags = 1; // Lock game + } + else + { + using enum Sonicteam::Player::State::SonicContext::Gems; + + if ((PContext->m_Input.get() & 0x10000) != 0) { + printf("RT PRESS \n"); + PContext->m_24A = 0; + } + + if ((PContext->m_Input.get() & 0x20000) != 0 && (PContext->m_CurrentGem == Red || PContext->m_CurrentGem == Purple)) + { + pGauge->m_GroundedFlags = 1; + + + if (PContext->m_24A) + { + pGauge->m_GroundedFlags = 0; + PContext->m_Shrink = 0; + PContext->m_SlowTime = 0; + } + + } + else if ((PContext->m_PostureFlags.get() & Sonicteam::Player::State::CommonContext::CC_GROUND) != 0 || PContext->m_24A) + { + pGauge->m_GroundedFlags = 0; + + } + printf("pGauge->m_GroundedFlags : %d\n", pGauge->m_GroundedFlags.get()); + + } + + +} +//Sonic Gauge Restoration diff --git a/MarathonRecomp/user/config_def.h b/MarathonRecomp/user/config_def.h index f683e3468..a21e5a5a0 100644 --- a/MarathonRecomp/user/config_def.h +++ b/MarathonRecomp/user/config_def.h @@ -79,5 +79,6 @@ CONFIG_DEFINE_HIDDEN("Codes", bool, DisableLowResolutionFontOnCustomUI, false); CONFIG_DEFINE_HIDDEN("Codes", bool, RestoreContextualHUDColours, false); CONFIG_DEFINE_HIDDEN("Codes", bool, DisableEdgeGrabLeftover, false); CONFIG_DEFINE_HIDDEN("Codes", bool, TailsGauge, false); +CONFIG_DEFINE_HIDDEN("Codes", bool, SonicGauge, false); CONFIG_DEFINE("Update", time_t, LastChecked, 0); diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index f7f57503d..bbd658cf0 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -153,3 +153,28 @@ registers = ["r5", "r31"] name = "PostureDisableEdgeGrabLeftover" address = 0x82200568 registers = ["r31"] + + +[[midasm_hook]] +name = "SonicGaugeRestorationGaugeFlagFix" +address = 0x822196EC +registers = ["r3","r31"] + +[[midasm_hook]] +name = "SonicGaugeRestorationGaugeGemSpriteResetFix" +address = 0x82185768 +registers = ["r30"] + + +[[midasm_hook]] +name = "SonicGaugeRestorationGaugeGemSpriteResetFix" +address = 0x821855A4 +registers = ["r29"] + + +[[midasm_hook]] +name = "SonicGaugeRestorationGaugeGemSpriteResetFix" +address = 0x82177DFC +registers = ["r31"] + + From 86299f33cb6f03ffb9186fca151c9697f3886106 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 00:59:25 +0300 Subject: [PATCH 2/8] QuickEdit --- .../api/Sonicteam/Player/State/SonicContext.h | 6 +----- MarathonRecomp/patches/player_patches.cpp | 11 ----------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h b/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h index 597041467..f18dd0768 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h @@ -10,8 +10,6 @@ namespace Sonicteam::Player::State class SonicContext : public CommonContext { public: - - //Sprite enum GemsS:uint32_t { SGreen = 1, @@ -33,9 +31,6 @@ namespace Sonicteam::Player::State Yellow, Super }; - - - be m_CurrentGemSprite; boost::shared_ptr m_Gauge; uint8_t m_HomingLockOn; @@ -56,5 +51,6 @@ namespace Sonicteam::Player::State uint8_t m_24B; be m_HomingFlip; be m_CurrentGem; + MARATHON_INSERT_PADDING(0x58); }; } diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index eb28615fb..3a01d4794 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -260,15 +260,11 @@ void SonicGaugeRestorationGaugeFlagFix(PPCRegister& r_gauge, PPCRegister& r_cont if (!Config::SonicGauge || !r_gauge.u32) return; - auto pGauge = (Sonicteam::Player::SonicGauge*)g_memory.Translate(r_gauge.u32); auto PContext = (Sonicteam::Player::State::SonicContext*)g_memory.Translate(r_context.u32); if ((uint32_t)(static_cast(pGauge)->m_pVftable.get()) != 0x8200D4D8) // != SonicGauge return; - - - if (PContext->m_Tornado != 0 || PContext->m_CurrentAnimation == 0xCB || PContext->m_CurrentAnimation == 0xCC || PContext->m_CurrentAnimation == 0x46) { pGauge->m_GroundedFlags = 1; // Lock game @@ -278,32 +274,25 @@ void SonicGaugeRestorationGaugeFlagFix(PPCRegister& r_gauge, PPCRegister& r_cont using enum Sonicteam::Player::State::SonicContext::Gems; if ((PContext->m_Input.get() & 0x10000) != 0) { - printf("RT PRESS \n"); PContext->m_24A = 0; } if ((PContext->m_Input.get() & 0x20000) != 0 && (PContext->m_CurrentGem == Red || PContext->m_CurrentGem == Purple)) { pGauge->m_GroundedFlags = 1; - - if (PContext->m_24A) { pGauge->m_GroundedFlags = 0; PContext->m_Shrink = 0; PContext->m_SlowTime = 0; } - } else if ((PContext->m_PostureFlags.get() & Sonicteam::Player::State::CommonContext::CC_GROUND) != 0 || PContext->m_24A) { pGauge->m_GroundedFlags = 0; } - printf("pGauge->m_GroundedFlags : %d\n", pGauge->m_GroundedFlags.get()); - } - } //Sonic Gauge Restoration From c83f0fbc0312371aa87dee1fdb4c531eeaf756f5 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 09:18:43 +0300 Subject: [PATCH 3/8] QuickEdit2 --- MarathonRecomp/patches/player_patches.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 3a01d4794..de11e7130 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -235,6 +235,10 @@ PPC_FUNC(sub_8223F360) { if (gauge->m_Super.get() == 0.0) gauge->m_Super = GuestToHostFunction(sub_821EA350, RefTypeLuaSystem, g_memory.MapVirtual(buffer)); + + buffer->~string(); + g_userHeap.Free(buffer); + /* For Testing gauge->m_Green = 10; gauge->m_Blue = 20; From f7ac76396a849144568afc6525cabfa4498fec72 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 13:10:51 +0300 Subject: [PATCH 4/8] Sky & Rainbow HealBlock, Yellow Spam Drain Fix & More vector.h --- MarathonRecomp/api/Marathon.h | 3 + .../api/Sonicteam/Player/INotification.h | 12 + MarathonRecomp/api/Sonicteam/Player/Object.h | 65 ++- .../api/Sonicteam/Player/Object.inl | 14 + MarathonRecomp/api/Sonicteam/Player/Score.h | 2 + .../Sonicteam/Player/Weapon/SonicWeapons.h | 37 ++ MarathonRecomp/api/stdx/vector.h | 391 ++++++++++++++++++ MarathonRecomp/patches/player_patches.cpp | 12 +- 8 files changed, 529 insertions(+), 7 deletions(-) create mode 100644 MarathonRecomp/api/Sonicteam/Player/INotification.h create mode 100644 MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h create mode 100644 MarathonRecomp/api/stdx/vector.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index a7cf39e60..aeb09af1a 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -33,9 +33,11 @@ #include "Sonicteam/Player/IScore.h" #include "Sonicteam/Player/IStepable.h" #include "Sonicteam/Player/IVariable.h" +#include "Sonicteam/Player/INotification.h" #include "Sonicteam/Player/Object.h" #include "Sonicteam/Player/Score.h" #include "Sonicteam/Player/SonicGauge.h" +#include "Sonicteam/Player/Weapon/SonicWeapons.h" #include "Sonicteam/Player/State/CommonContext.h" #include "Sonicteam/Player/State/CommonFall.h" #include "Sonicteam/Player/State/CommonObject.h" @@ -59,3 +61,4 @@ #include "boost/smart_ptr/make_shared_object.h" #include "boost/smart_ptr/shared_ptr.h" #include "stdx/string.h" +#include "stdx/vector.h" diff --git a/MarathonRecomp/api/Sonicteam/Player/INotification.h b/MarathonRecomp/api/Sonicteam/Player/INotification.h new file mode 100644 index 000000000..0a2ea3dd9 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/INotification.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace Sonicteam::Player +{ + class INotification + { + public: + xpointer m_pVftable; + }; +} diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index deab3e83c..b6b79b494 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -2,23 +2,78 @@ #include #include +#include +#include namespace Sonicteam::Player { - class Object : public Actor + //xbox vector + struct _vector { + union { + struct { + be x, y, z, w; + }; + be _f[4]; + }; + _vector(float x = 0.0f, float y = 0.0f, float z = 0.0f, float w = 0.0f) + : x(x), y(y), z(z), w(w) + { + } + }; + typedef _vector XMVECTOR; + + #pragma pack(push, 1) + class __declspec(align(1)) Object : public Actor { + struct ObjectPlayerUpgrade { + unsigned int global_flag; + unsigned int equip_flag; + }; + public: - MARATHON_INSERT_PADDING(0x40); + stdx::string m_PlayerLUA; + stdx::string m_PlayerPKG; + be m_CameramanActorID; + xpointer m_Cameraman; be m_PlayerIndex; - MARATHON_INSERT_PADDING(0x48); + be m_PlayerControllerIndex; + XMVECTOR m_SpawnRotation; + XMVECTOR m_SpawnPosition; + be m_SpawnRing; + xpointer m_SpawnSource; // REF_TYPE(RefCountObject) + uint8_t m_IsPlayer; + uint8_t m_IsPosture; + uint8_t m_FlagCA; + uint8_t m_FlagCB; + xpointer m_RootFrame; // REF_TYPE(RefCountObject) + xpointer m_PackageBinary; // REF_TYPE(RefCountObject) + boost::shared_ptr m_PlayerModel; + boost::shared_ptr m_PlayerPosture; boost::shared_ptr m_spStateMachine; - MARATHON_INSERT_PADDING(0x18); + boost::shared_ptr m_PlayerGravity; + boost::shared_ptr m_PlayerImpulse; + be m_LastSetupModule; + be m_NextSetupModule; boost::shared_ptr m_spGauge; - MARATHON_INSERT_PADDING(0x204); + MARATHON_INSERT_PADDING(0x8); + stdx::vector> m_PlayerPlugins; + MARATHON_INSERT_PADDING(0x58); + be m_PlayerDelta; + MARATHON_INSERT_PADDING(0x48); + stdx::vector m_PlayerUpgrade; + stdx::string m_PlayerName; + MARATHON_INSERT_PADDING(0x134); template inline T* GetGauge(); + + template + inline T* GetPlugin(const char* v_name); + + }; + #pragma pack(pop) + } #include diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.inl b/MarathonRecomp/api/Sonicteam/Player/Object.inl index b4de60501..4a275b010 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.inl +++ b/MarathonRecomp/api/Sonicteam/Player/Object.inl @@ -1,3 +1,4 @@ +#include "Object.h" namespace Sonicteam::Player { template @@ -5,4 +6,17 @@ namespace Sonicteam::Player { return (T*)m_spGauge.get(); } + + template + inline T* Sonicteam::Player::Object::GetPlugin(const char* v_name) + { + for (stdx::vector>::iterator it = m_PlayerPlugins.begin(); it != m_PlayerPlugins.end(); it = it + 1) + { + if (it->get()->m_Name == v_name) { + return static_cast(it->get()); + } + } + + return nullptr; + } } diff --git a/MarathonRecomp/api/Sonicteam/Player/Score.h b/MarathonRecomp/api/Sonicteam/Player/Score.h index ff270c709..d78421108 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Score.h +++ b/MarathonRecomp/api/Sonicteam/Player/Score.h @@ -2,6 +2,7 @@ #include + namespace Sonicteam::Player { class Score : public IScore, public IVariable, public IStepable @@ -9,5 +10,6 @@ namespace Sonicteam::Player public: MARATHON_INSERT_PADDING(0x0C); xpointer m_pPlayer; + }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h b/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h new file mode 100644 index 000000000..d4237ad05 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h @@ -0,0 +1,37 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include + + + + +namespace Sonicteam::Player::Weapon +{ + template + struct LinkSoxNode + { + xpointer> m_prev; + xpointer> m_next; + Type* m_this; + }; + + template + struct EntityContainer { + xpointer Entity; + LinkSoxNode m_Link; + }; + + class SonicWeapons : public IPlugIn, public IFlagCommunicator, public IStepable, public IDynamicLink, public IVariable, public INotification + { + public: + MARATHON_INSERT_PADDING(0x4C); + EntityContainer m_GunDrive; + MARATHON_INSERT_PADDING(0x24); + }; +} diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h new file mode 100644 index 000000000..47c980c87 --- /dev/null +++ b/MarathonRecomp/api/stdx/vector.h @@ -0,0 +1,391 @@ +#pragma once + +#include +#include +#include + + +namespace stdx +{ + template + class vector + { + private: + be _Myproxy; + xpointer _First; + xpointer _Last; + xpointer _End; + + void _ConstructRange(T* first, T* last, const T& value) + { + for (; first != last; ++first) + { + new (first) T(value); + } + } + + void _DestroyRange(T* first, T* last) + { + while (first != last) + { + first->~T(); + ++first; + } + } + + void _Reallocate(size_t newCapacity) + { + T* newBlock = static_cast(g_userHeap.Alloc(sizeof(T) * newCapacity)); + const size_t oldSize = size(); + try + { + for (size_t i = 0; i < oldSize; ++i) + { + new (newBlock + i) T(std::move(_First[i])); + _First[i].~T(); + } + } + catch (...) + { + _DestroyRange(newBlock, newBlock + oldSize); + g_userHeap.Free(newBlock); + throw; + } + + if (_First) + { + _DestroyRange(_First, _Last); + g_userHeap.Free(_First.get()); + } + + _First = xpointer(newBlock); + _Last = xpointer(newBlock + oldSize); + _End = xpointer(newBlock + newCapacity); + } + + void _GrowIfNeeded() + { + if (_Last.get() == _End.get()) + { + _Reallocate(size() ? size() * 2 : 1); + } + } + + public: + // Iterator + using iterator = xpointer; + using const_iterator = xpointer; + + + vector() noexcept + : _First(nullptr) + , _Last(nullptr) + , _End(nullptr) + { + } + + explicit vector(size_t count) + : _First(static_cast(g_userHeap.Alloc(sizeof(T)* count))) + , _Last(_First.get() + count) + , _End(_Last) + { + _ConstructRange(_First, _Last, T()); + } + + vector(size_t count, const T& value) + : _First(static_cast(g_userHeap.Alloc(sizeof(T)* count))) + , _Last(_First.get() + count) + , _End(_Last) + { + _ConstructRange(_First, _Last, value); + } + + vector(const vector& other) + : _First(static_cast(g_userHeap.Alloc(sizeof(T) * other.size()))) + , _Last(_First.get() + other.size()) + , _End(_Last) + { + try + { + for (size_t i = 0; i < other.size(); ++i) + { + new (_First.get() + i) T(other._First[i]); + } + } + catch (...) + { + _DestroyRange(_First, _Last); + g_userHeap.Free(_First.get()); + throw; + } + } + + vector(vector&& other) noexcept + : _First(other._First) + , _Last(other._Last) + , _End(other._End) + { + other._First = other._Last = other._End = nullptr; + } + + ~vector() + { + _DestroyRange(_First, _Last); + if (_First) + { + g_userHeap.Free(_First.get()); + } + } + + vector& operator=(const vector& other) + { + if (this != &other) + { + vector tmp(other); + swap(tmp); + } + return *this; + } + + vector& operator=(vector&& other) noexcept + { + if (this != &other) + { + _DestroyRange(_First, _Last); + if (_First) + { + g_userHeap.Free(_First.get()); + } + + _First = other._First; + _Last = other._Last; + _End = other._End; + + other._First = other._Last = other._End = nullptr; + } + return *this; + } + + + T& operator[](size_t pos) + { + return _First.get()[pos]; + } + const T& operator[](size_t pos) const + { + return _First.get()[pos]; + } + + T& at(size_t pos) + { + if (pos >= size()) throw std::out_of_range("vector index out of range"); + return _First.get()[pos]; + } + + const T& at(size_t pos) const + { + if (pos >= size()) throw std::out_of_range("vector index out of range"); + return _First.get()[pos]; + } + + T& front() { + return *_First; + } + const T& front() const { + return *_First; + } + T& back() { + return *(_Last.get() - 1); + } + const T& back() const + { + return *(_Last.get() - 1); + } + T* data() + { + return _First; + } + const T* data() const { + return _First; + } + + // Iterators + iterator begin() { + return _First; + } + const_iterator begin() const + { + return _First; + } + const_iterator cbegin() const + { + return _First; + } + iterator end() + { + return _Last; + } + const_iterator end() const + { + return _Last; + } + const_iterator cend() const + { + return _Last; + } + + // Capacity + bool empty() const + { + return _First.get() == _Last.get(); + } + size_t size() const + { + return _Last.get() - _First.get(); + } + size_t capacity() const { + return _End.get() - _First.get(); + } + + void reserve(size_t newCapacity) + { + if (newCapacity > capacity()) + { + _Reallocate(newCapacity); + } + } + + void shrink_to_fit() + { + if (size() < capacity()) + { + _Reallocate(size()); + } + } + + + void clear() + { + _DestroyRange(_First, _Last); + _Last = _First; + } + + void push_back(const T& value) + { + _GrowIfNeeded(); + new (_Last.get()) T(value); + _Last = xpointer(_Last.get() + 1); + } + + void push_back(T&& value) + { + _GrowIfNeeded(); + new (_Last.get()) T(std::move(value)); + _Last = xpointer(_Last.get() + 1); + } + + template + void emplace_back(Args&&... args) + { + _GrowIfNeeded(); + new (_Last.get()) T(std::forward(args)...); + _Last = xpointer(_Last.get() + 1); + } + + void pop_back() + { + (_Last.get() - 1)->~T(); + _Last = xpointer(_Last.get() - 1); + } + + void resize(size_t count) + { + if (count < size()) + { + _DestroyRange(_First.get() + count, _Last); + _Last = xpointer(_First.get() + count); + } + else if (count > size()) + { + reserve(count); + while (_Last.get() != _First.get() + count) + { + new (_Last.get()) T(); + _Last = xpointer(_Last.get() + 1); + } + } + } + + void resize(size_t count, const T& value) + { + if (count < size()) + { + _DestroyRange(_First.get() + count, _Last); + _Last = xpointer(_First.get() + count); + } + else if (count > size()) + { + reserve(count); + while (_Last.get() != _First.get() + count) + { + new (_Last.get()) T(value); + _Last = xpointer(_Last.get() + 1); + } + } + } + + void swap(vector& other) noexcept + { + std::swap(_First, other._First); + std::swap(_Last, other._Last); + std::swap(_End, other._End); + } + }; + + // Non-member functions + template + void swap(vector& lhs, vector& rhs) noexcept + { + lhs.swap(rhs); + } + + template + bool operator==(const vector& lhs, const vector& rhs) + { + return lhs.size() == rhs.size() && + std::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + + template + bool operator!=(const vector& lhs, const vector& rhs) + { + return !(lhs == rhs); + } + + template + bool operator<(const vector& lhs, const vector& rhs) + { + return std::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()); + } + + template + bool operator<=(const vector& lhs, const vector& rhs) + { + return !(rhs < lhs); + } + + template + bool operator>(const vector& lhs, const vector& rhs) + { + return rhs < lhs; + } + + template + bool operator>=(const vector& lhs, const vector& rhs) + { + return !(lhs < rhs); + } + + +} diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index de11e7130..73343097a 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // Sonicteam::Player::State::TailsContext::Update PPC_FUNC_IMPL(__imp__sub_8221A7D8); @@ -113,9 +114,10 @@ PPC_FUNC(sub_82217FC0) { auto gem_id = (Sonicteam::Player::State::SonicContext::Gems)(ctx.r4.u32); switch (gem_id) { + case Yellow: + if (context->m_ThunderGuard) break; case Blue: case Green: - case Yellow: case Sky: case White: case Super: @@ -264,12 +266,18 @@ void SonicGaugeRestorationGaugeFlagFix(PPCRegister& r_gauge, PPCRegister& r_cont if (!Config::SonicGauge || !r_gauge.u32) return; + + auto pGauge = (Sonicteam::Player::SonicGauge*)g_memory.Translate(r_gauge.u32); auto PContext = (Sonicteam::Player::State::SonicContext*)g_memory.Translate(r_context.u32); if ((uint32_t)(static_cast(pGauge)->m_pVftable.get()) != 0x8200D4D8) // != SonicGauge return; - if (PContext->m_Tornado != 0 || PContext->m_CurrentAnimation == 0xCB || PContext->m_CurrentAnimation == 0xCC || PContext->m_CurrentAnimation == 0x46) + auto weapons = PContext->m_pScore->m_pPlayer->GetPlugin("sonic_weapons"); + + + + if (PContext->m_Tornado != 0 || PContext->m_CurrentAnimation == 0xCB || PContext->m_CurrentAnimation == 0xCC || PContext->m_CurrentAnimation == 0x46 || PContext->m_CurrentAnimation == 0xCE || weapons->m_GunDrive.Entity != 0) { pGauge->m_GroundedFlags = 1; // Lock game } From ea15ccdd2a2f252a27101f5234d78de11f9bb4f2 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 13:24:22 +0300 Subject: [PATCH 5/8] QuickModify --- MarathonRecomp/api/Sonicteam/Player/Object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index b6b79b494..29e59d1c0 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -43,8 +43,8 @@ namespace Sonicteam::Player xpointer m_SpawnSource; // REF_TYPE(RefCountObject) uint8_t m_IsPlayer; uint8_t m_IsPosture; - uint8_t m_FlagCA; - uint8_t m_FlagCB; + uint8_t m_IsAI; + MARATHON_INSERT_PADDING(1); xpointer m_RootFrame; // REF_TYPE(RefCountObject) xpointer m_PackageBinary; // REF_TYPE(RefCountObject) boost::shared_ptr m_PlayerModel; From e50dccd2103e0e863354b2526e70a1cacc6d3a07 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 13:56:58 +0300 Subject: [PATCH 6/8] Remove TODO --- MarathonRecomp/patches/player_patches.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 73343097a..c31901d88 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -83,7 +83,7 @@ PPC_FUNC(sub_8220F330) //////////////////////////////////////////////////////// ///////////// Sonic Gauge Restoration //////////////// //////////////////////////////////////////////////////// -//TODO Rei: Sky Gem Throw Lock Heal + const Sonicteam::Player::State::SonicContext::GemsS gemConversionTable[] = { Sonicteam::Player::State::SonicContext::GemsS::SBlue, From 5685cdc9be8e9a76c51a07eb2eb5ef9394baaa18 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 2 Aug 2025 22:48:44 +0300 Subject: [PATCH 7/8] QuickEdit --- MarathonRecomp/api/Sonicteam/Player/Object.h | 14 +++++++----- .../api/Sonicteam/Player/Object.inl | 4 ++-- MarathonRecomp/api/Sonicteam/Player/Score.h | 1 - .../Sonicteam/Player/State/CommonContext.h | 3 ++- .../api/Sonicteam/Player/State/SonicContext.h | 8 +++++-- .../Sonicteam/Player/Weapon/SonicWeapons.h | 9 ++++---- MarathonRecomp/api/stdx/vector.h | 2 -- MarathonRecomp/patches/player_patches.cpp | 22 ++++++++----------- 8 files changed, 33 insertions(+), 30 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index 29e59d1c0..1b9da7990 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -8,18 +8,22 @@ namespace Sonicteam::Player { //xbox vector - struct _vector { - union { - struct { + struct _vector + { + union + { + struct + { be x, y, z, w; }; + be _f[4]; }; - _vector(float x = 0.0f, float y = 0.0f, float z = 0.0f, float w = 0.0f) - : x(x), y(y), z(z), w(w) + _vector(float x = 0.0f, float y = 0.0f, float z = 0.0f, float w = 0.0f): x(x), y(y), z(z), w(w) { } }; + typedef _vector XMVECTOR; #pragma pack(push, 1) diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.inl b/MarathonRecomp/api/Sonicteam/Player/Object.inl index 4a275b010..1c241f7a0 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.inl +++ b/MarathonRecomp/api/Sonicteam/Player/Object.inl @@ -12,11 +12,11 @@ namespace Sonicteam::Player { for (stdx::vector>::iterator it = m_PlayerPlugins.begin(); it != m_PlayerPlugins.end(); it = it + 1) { - if (it->get()->m_Name == v_name) { + if (it->get()->m_Name == v_name) + { return static_cast(it->get()); } } - return nullptr; } } diff --git a/MarathonRecomp/api/Sonicteam/Player/Score.h b/MarathonRecomp/api/Sonicteam/Player/Score.h index d78421108..5ee4d79c2 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Score.h +++ b/MarathonRecomp/api/Sonicteam/Player/Score.h @@ -10,6 +10,5 @@ namespace Sonicteam::Player public: MARATHON_INSERT_PADDING(0x0C); xpointer m_pPlayer; - }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h b/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h index 52dca2f68..9335afe76 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/CommonContext.h @@ -15,7 +15,8 @@ namespace Sonicteam::Player::State public: //(Gordon Ramsay) - enum PostureEnum:uint32_t{ + enum PostureEnum:uint32_t + { CC_GROUND = 0x1, // detects Ground CC_WALLBRUSHING = 0x8, // detects brushing against a wall CC_HEADONWALL = 0x10, // detects head-on wall collision (will always be enabled w/ 2^3) diff --git a/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h b/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h index f18dd0768..b54528082 100644 --- a/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h +++ b/MarathonRecomp/api/Sonicteam/Player/State/SonicContext.h @@ -11,7 +11,8 @@ namespace Sonicteam::Player::State { public: //Sprite - enum GemsS:uint32_t { + enum GemsS:uint32_t + { SGreen = 1, SRed, SBlue, @@ -21,7 +22,9 @@ namespace Sonicteam::Player::State SPurple, SSuper }; - enum Gems:uint32_t { + + enum Gems:uint32_t + { Blue = 1, Red, Green, @@ -31,6 +34,7 @@ namespace Sonicteam::Player::State Yellow, Super }; + be m_CurrentGemSprite; boost::shared_ptr m_Gauge; uint8_t m_HomingLockOn; diff --git a/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h b/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h index d4237ad05..6760ddace 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h +++ b/MarathonRecomp/api/Sonicteam/Player/Weapon/SonicWeapons.h @@ -16,13 +16,14 @@ namespace Sonicteam::Player::Weapon template struct LinkSoxNode { - xpointer> m_prev; - xpointer> m_next; - Type* m_this; + xpointer> m_Prev; + xpointer> m_Next; + Type* m_This; }; template - struct EntityContainer { + struct EntityContainer + { xpointer Entity; LinkSoxNode m_Link; }; diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index 47c980c87..8ae9ce76e 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -263,7 +263,6 @@ namespace stdx } } - void clear() { _DestroyRange(_First, _Last); @@ -342,7 +341,6 @@ namespace stdx } }; - // Non-member functions template void swap(vector& lhs, vector& rhs) noexcept { diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index c31901d88..200960237 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -42,7 +42,6 @@ PPC_FUNC(sub_8221A7D8) __imp__sub_8221A7D8(ctx, base); } - // Sonicteam::Player::State::*Context IDynamicLink::Init PPC_FUNC_IMPL(__imp__sub_8220F330); PPC_FUNC(sub_8220F330) @@ -84,7 +83,6 @@ PPC_FUNC(sub_8220F330) ///////////// Sonic Gauge Restoration //////////////// //////////////////////////////////////////////////////// - const Sonicteam::Player::State::SonicContext::GemsS gemConversionTable[] = { Sonicteam::Player::State::SonicContext::GemsS::SBlue, Sonicteam::Player::State::SonicContext::GemsS::SRed, @@ -113,7 +111,8 @@ PPC_FUNC(sub_82217FC0) { using enum Sonicteam::Player::State::SonicContext::Gems; auto gem_id = (Sonicteam::Player::State::SonicContext::Gems)(ctx.r4.u32); - switch (gem_id) { + switch (gem_id) + { case Yellow: if (context->m_ThunderGuard) break; case Blue: @@ -123,7 +122,8 @@ PPC_FUNC(sub_82217FC0) { case Super: { size_t index = gemConversionTable[gem_id - 1] - 1; - if (gauge->m_Value >= (&gauge->m_Green)[index].get()) { + if (gauge->m_Value >= (&gauge->m_Green)[index].get()) + { ctx.r3.u64 = 1; return; } @@ -159,7 +159,8 @@ PPC_FUNC(sub_82218068) { auto gem_id = (Sonicteam::Player::State::SonicContext::Gems)(ctx.r4.u32); double delta = ctx.f1.f64; - switch (gem_id) { + switch (gem_id) + { case Blue: case Green: case Yellow: @@ -257,7 +258,8 @@ PPC_FUNC(sub_8223F360) { void SonicGaugeRestorationGaugeGemSpriteResetFix(PPCRegister& r_GameImp) { Sonicteam::GameImp* pGameImp = (Sonicteam::GameImp*)g_memory.Translate(r_GameImp.u32); - for (int i = 0; i < 4; i++) pGameImp->m_PlayerData[i].GemIndex = 0; + for (int i = 0; i < 4; i++) + pGameImp->m_PlayerData[i].GemIndex = 0; } @@ -266,17 +268,12 @@ void SonicGaugeRestorationGaugeFlagFix(PPCRegister& r_gauge, PPCRegister& r_cont if (!Config::SonicGauge || !r_gauge.u32) return; - - auto pGauge = (Sonicteam::Player::SonicGauge*)g_memory.Translate(r_gauge.u32); auto PContext = (Sonicteam::Player::State::SonicContext*)g_memory.Translate(r_context.u32); if ((uint32_t)(static_cast(pGauge)->m_pVftable.get()) != 0x8200D4D8) // != SonicGauge return; auto weapons = PContext->m_pScore->m_pPlayer->GetPlugin("sonic_weapons"); - - - if (PContext->m_Tornado != 0 || PContext->m_CurrentAnimation == 0xCB || PContext->m_CurrentAnimation == 0xCC || PContext->m_CurrentAnimation == 0x46 || PContext->m_CurrentAnimation == 0xCE || weapons->m_GunDrive.Entity != 0) { pGauge->m_GroundedFlags = 1; // Lock game @@ -284,11 +281,10 @@ void SonicGaugeRestorationGaugeFlagFix(PPCRegister& r_gauge, PPCRegister& r_cont else { using enum Sonicteam::Player::State::SonicContext::Gems; - if ((PContext->m_Input.get() & 0x10000) != 0) { PContext->m_24A = 0; } - + if ((PContext->m_Input.get() & 0x20000) != 0 && (PContext->m_CurrentGem == Red || PContext->m_CurrentGem == Purple)) { pGauge->m_GroundedFlags = 1; From cb35a46eecdfcd0b4e08c37f287d13e0b6987621 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Tue, 5 Aug 2025 20:57:28 +0300 Subject: [PATCH 8/8] FinalUpdateMB --- MarathonRecomp/api/Marathon.h | 4 +- MarathonRecomp/api/Sonicteam/Player/Object.h | 8 +- MarathonRecomp/api/stdx/vector.h | 174 ++++++++++--------- 3 files changed, 94 insertions(+), 92 deletions(-) diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index aeb09af1a..9d9d17948 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -29,15 +29,14 @@ #include "Sonicteam/Player/IExportWeaponRequestFlag.h" #include "Sonicteam/Player/IFlagCommunicator.h" #include "Sonicteam/Player/IGauge.h" +#include "Sonicteam/Player/INotification.h" #include "Sonicteam/Player/IPlugIn.h" #include "Sonicteam/Player/IScore.h" #include "Sonicteam/Player/IStepable.h" #include "Sonicteam/Player/IVariable.h" -#include "Sonicteam/Player/INotification.h" #include "Sonicteam/Player/Object.h" #include "Sonicteam/Player/Score.h" #include "Sonicteam/Player/SonicGauge.h" -#include "Sonicteam/Player/Weapon/SonicWeapons.h" #include "Sonicteam/Player/State/CommonContext.h" #include "Sonicteam/Player/State/CommonFall.h" #include "Sonicteam/Player/State/CommonObject.h" @@ -50,6 +49,7 @@ #include "Sonicteam/Player/State/Object2.h" #include "Sonicteam/Player/State/SonicContext.h" #include "Sonicteam/Player/State/TailsContext.h" +#include "Sonicteam/Player/Weapon/SonicWeapons.h" #include "Sonicteam/SoX/AI/StateMachine.h" #include "Sonicteam/SoX/Component.h" #include "Sonicteam/SoX/Engine/Doc.h" diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index 1b9da7990..d21bcb4ca 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -5,9 +5,11 @@ #include #include + namespace Sonicteam::Player { //xbox vector + //pull/74 SoX::Math::Vector4, replace _vector,XMVECTOR to SoX::Math::Vector4 - struct _vector { union @@ -30,8 +32,8 @@ namespace Sonicteam::Player class __declspec(align(1)) Object : public Actor { struct ObjectPlayerUpgrade { - unsigned int global_flag; - unsigned int equip_flag; + uint32_t global_flag; + uint32_t equip_flag; }; public: @@ -74,10 +76,8 @@ namespace Sonicteam::Player template inline T* GetPlugin(const char* v_name); - }; #pragma pack(pop) - } #include diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index 8ae9ce76e..e3982e35a 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -12,9 +12,9 @@ namespace stdx { private: be _Myproxy; - xpointer _First; - xpointer _Last; - xpointer _End; + xpointer _MyFirst; + xpointer _MyLast; + xpointer _MyEnd; void _ConstructRange(T* first, T* last, const T& value) { @@ -41,8 +41,8 @@ namespace stdx { for (size_t i = 0; i < oldSize; ++i) { - new (newBlock + i) T(std::move(_First[i])); - _First[i].~T(); + new (newBlock + i) T(std::move(_MyFirst[i])); + _MyFirst[i].~T(); } } catch (...) @@ -52,20 +52,20 @@ namespace stdx throw; } - if (_First) + if (_MyFirst) { - _DestroyRange(_First, _Last); - g_userHeap.Free(_First.get()); + _DestroyRange(_MyFirst, _MyLast); + g_userHeap.Free(_MyFirst.get()); } - _First = xpointer(newBlock); - _Last = xpointer(newBlock + oldSize); - _End = xpointer(newBlock + newCapacity); + _MyFirst = xpointer(newBlock); + _MyLast = xpointer(newBlock + oldSize); + _MyEnd = xpointer(newBlock + newCapacity); } void _GrowIfNeeded() { - if (_Last.get() == _End.get()) + if (_MyLast.get() == _MyEnd.get()) { _Reallocate(size() ? size() * 2 : 1); } @@ -78,62 +78,62 @@ namespace stdx vector() noexcept - : _First(nullptr) - , _Last(nullptr) - , _End(nullptr) + : _MyFirst(nullptr) + , _MyLast(nullptr) + , _MyEnd(nullptr) { } explicit vector(size_t count) - : _First(static_cast(g_userHeap.Alloc(sizeof(T)* count))) - , _Last(_First.get() + count) - , _End(_Last) + : _MyFirst(static_cast(g_userHeap.Alloc(sizeof(T)* count))) + , _MyLast(_MyFirst.get() + count) + , _MyEnd(_MyLast) { - _ConstructRange(_First, _Last, T()); + _ConstructRange(_MyFirst, _MyLast, T()); } vector(size_t count, const T& value) - : _First(static_cast(g_userHeap.Alloc(sizeof(T)* count))) - , _Last(_First.get() + count) - , _End(_Last) + : _MyFirst(static_cast(g_userHeap.Alloc(sizeof(T)* count))) + , _MyLast(_MyFirst.get() + count) + , _MyEnd(_MyLast) { - _ConstructRange(_First, _Last, value); + _ConstructRange(_MyFirst, _MyLast, value); } vector(const vector& other) - : _First(static_cast(g_userHeap.Alloc(sizeof(T) * other.size()))) - , _Last(_First.get() + other.size()) - , _End(_Last) + : _MyFirst(static_cast(g_userHeap.Alloc(sizeof(T) * other.size()))) + , _MyLast(_MyFirst.get() + other.size()) + , _MyEnd(_MyLast) { try { for (size_t i = 0; i < other.size(); ++i) { - new (_First.get() + i) T(other._First[i]); + new (_MyFirst.get() + i) T(other._MyFirst[i]); } } catch (...) { - _DestroyRange(_First, _Last); - g_userHeap.Free(_First.get()); + _DestroyRange(_MyFirst, _MyLast); + g_userHeap.Free(_MyFirst.get()); throw; } } vector(vector&& other) noexcept - : _First(other._First) - , _Last(other._Last) - , _End(other._End) + : _MyFirst(other._MyFirst) + , _MyLast(other._MyLast) + , _MyEnd(other._MyEnd) { - other._First = other._Last = other._End = nullptr; + other._MyFirst = other._MyLast = other._MyEnd = nullptr; } ~vector() { - _DestroyRange(_First, _Last); - if (_First) + _DestroyRange(_MyFirst, _MyLast); + if (_MyFirst) { - g_userHeap.Free(_First.get()); + g_userHeap.Free(_MyFirst.get()); } } @@ -151,17 +151,17 @@ namespace stdx { if (this != &other) { - _DestroyRange(_First, _Last); - if (_First) + _DestroyRange(_MyFirst, _MyLast); + if (_MyFirst) { - g_userHeap.Free(_First.get()); + g_userHeap.Free(_MyFirst.get()); } - _First = other._First; - _Last = other._Last; - _End = other._End; + _MyFirst = other._MyFirst; + _MyLast = other._MyLast; + _MyEnd = other._MyEnd; - other._First = other._Last = other._End = nullptr; + other._MyFirst = other._MyLast = other._MyEnd = nullptr; } return *this; } @@ -169,82 +169,84 @@ namespace stdx T& operator[](size_t pos) { - return _First.get()[pos]; + return _MyFirst.get()[pos]; } const T& operator[](size_t pos) const { - return _First.get()[pos]; + return _MyFirst.get()[pos]; } T& at(size_t pos) { if (pos >= size()) throw std::out_of_range("vector index out of range"); - return _First.get()[pos]; + return _MyFirst.get()[pos]; } const T& at(size_t pos) const { if (pos >= size()) throw std::out_of_range("vector index out of range"); - return _First.get()[pos]; + return _MyFirst.get()[pos]; } T& front() { - return *_First; + return *_MyFirst; } const T& front() const { - return *_First; + return *_MyFirst; } T& back() { - return *(_Last.get() - 1); + return *(_MyLast.get() - 1); } const T& back() const { - return *(_Last.get() - 1); + return *(_MyLast.get() - 1); } T* data() { - return _First; + return _MyFirst; } const T* data() const { - return _First; + return _MyFirst; } // Iterators iterator begin() { - return _First; + return _MyFirst; } const_iterator begin() const { - return _First; + return _MyFirst; } const_iterator cbegin() const { - return _First; + return _MyFirst; } iterator end() { - return _Last; + return _MyLast; } const_iterator end() const { - return _Last; + return _MyLast; } const_iterator cend() const { - return _Last; + return _MyLast; } // Capacity bool empty() const { - return _First.get() == _Last.get(); + return _MyFirst.get() == _MyLast.get(); } size_t size() const { - return _Last.get() - _First.get(); + return _MyLast.get() - _MyFirst.get(); } - size_t capacity() const { - return _End.get() - _First.get(); + + size_t capacity() const + { + return _MyEnd.get() - _MyFirst.get(); } void reserve(size_t newCapacity) @@ -265,52 +267,52 @@ namespace stdx void clear() { - _DestroyRange(_First, _Last); - _Last = _First; + _DestroyRange(_MyFirst, _MyLast); + _MyLast = _MyFirst; } void push_back(const T& value) { _GrowIfNeeded(); - new (_Last.get()) T(value); - _Last = xpointer(_Last.get() + 1); + new (_MyLast.get()) T(value); + _MyLast = xpointer(_MyLast.get() + 1); } void push_back(T&& value) { _GrowIfNeeded(); - new (_Last.get()) T(std::move(value)); - _Last = xpointer(_Last.get() + 1); + new (_MyLast.get()) T(std::move(value)); + _MyLast = xpointer(_MyLast.get() + 1); } template void emplace_back(Args&&... args) { _GrowIfNeeded(); - new (_Last.get()) T(std::forward(args)...); - _Last = xpointer(_Last.get() + 1); + new (_MyLast.get()) T(std::forward(args)...); + _MyLast = xpointer(_MyLast.get() + 1); } void pop_back() { - (_Last.get() - 1)->~T(); - _Last = xpointer(_Last.get() - 1); + (_MyLast.get() - 1)->~T(); + _MyLast = xpointer(_MyLast.get() - 1); } void resize(size_t count) { if (count < size()) { - _DestroyRange(_First.get() + count, _Last); - _Last = xpointer(_First.get() + count); + _DestroyRange(_MyFirst.get() + count, _MyLast); + _MyLast = xpointer(_MyFirst.get() + count); } else if (count > size()) { reserve(count); - while (_Last.get() != _First.get() + count) + while (_MyLast.get() != _MyFirst.get() + count) { - new (_Last.get()) T(); - _Last = xpointer(_Last.get() + 1); + new (_MyLast.get()) T(); + _MyLast = xpointer(_MyLast.get() + 1); } } } @@ -319,25 +321,25 @@ namespace stdx { if (count < size()) { - _DestroyRange(_First.get() + count, _Last); - _Last = xpointer(_First.get() + count); + _DestroyRange(_MyFirst.get() + count, _MyLast); + _MyLast = xpointer(_MyFirst.get() + count); } else if (count > size()) { reserve(count); - while (_Last.get() != _First.get() + count) + while (_MyLast.get() != _MyFirst.get() + count) { - new (_Last.get()) T(value); - _Last = xpointer(_Last.get() + 1); + new (_MyLast.get()) T(value); + _MyLast = xpointer(_MyLast.get() + 1); } } } void swap(vector& other) noexcept { - std::swap(_First, other._First); - std::swap(_Last, other._Last); - std::swap(_End, other._End); + std::swap(_MyFirst, other._MyFirst); + std::swap(_MyLast, other._MyLast); + std::swap(_MyEnd, other._MyEnd); } };