From 62ae34047a7393ffb37df1b9ec97f3614d709f40 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Fri, 15 Aug 2025 17:22:48 +0300 Subject: [PATCH 01/16] DebugPlayerSwitch --- MarathonRecomp/api/Marathon.h | 2 + MarathonRecomp/api/Sonicteam/DocMarathonImp.h | 10 +++- MarathonRecomp/api/Sonicteam/GameImp.h | 10 ++++ MarathonRecomp/api/Sonicteam/Player/Object.h | 10 +++- .../api/Sonicteam/SoX/Input/Manager.h | 35 +++++++++++++ MarathonRecomp/api/stdx/string.h | 33 +++++++++--- MarathonRecomp/api/stdx/vector.h | 25 +++++++++ MarathonRecomp/patches/player_patches.cpp | 52 +++++++++++++++++++ MarathonRecomp/user/config_def.h | 1 + MarathonRecompLib/config/Marathon.toml | 7 +++ 10 files changed, 174 insertions(+), 11 deletions(-) create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h create mode 100644 MarathonRecomp/api/stdx/vector.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index 49b8141f8..49c7c4ed8 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -58,6 +58,7 @@ #include "Sonicteam/SoX/Object.h" #include "Sonicteam/SoX/Physics/Havok/WorldHavok.h" #include "Sonicteam/SoX/Physics/World.h" +#include "Sonicteam/SoX/Input/Manager.h" #include "Sonicteam/SoX/RefCountObject.h" #include "Sonicteam/System/CreateStatic.h" #include "Sonicteam/System/Singleton.h" @@ -65,3 +66,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/DocMarathonImp.h b/MarathonRecomp/api/Sonicteam/DocMarathonImp.h index 75b0b6e73..4b9a6a476 100644 --- a/MarathonRecomp/api/Sonicteam/DocMarathonImp.h +++ b/MarathonRecomp/api/Sonicteam/DocMarathonImp.h @@ -2,13 +2,21 @@ #include #include +#include +#include +#include + namespace Sonicteam { class DocMarathonImp : public SoX::Engine::Doc { public: - MARATHON_INSERT_PADDING(0x74); + MARATHON_INSERT_PADDING(0x40); + stdx::vector> m_vspInputManager; + MARATHON_INSERT_PADDING(0x24); bool m_VFrame; + MARATHON_INSERT_PADDING(0x55B58); + be m_PlayerControllerID[4]; }; } diff --git a/MarathonRecomp/api/Sonicteam/GameImp.h b/MarathonRecomp/api/Sonicteam/GameImp.h index dde0e1224..48a638083 100644 --- a/MarathonRecomp/api/Sonicteam/GameImp.h +++ b/MarathonRecomp/api/Sonicteam/GameImp.h @@ -36,6 +36,16 @@ namespace Sonicteam template inline T* GetPhysicsWorld(); + + uint32_t PlayerActorIDToIndex(uint32_t ActorID) + { + for (int i = 0; i < 4; i++) + { + if (m_PlayerData[i].ActorID == ActorID) + return i; + } + return -1; + } }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index deab3e83c..4360d4173 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -10,9 +10,15 @@ namespace Sonicteam::Player public: MARATHON_INSERT_PADDING(0x40); be m_PlayerIndex; - MARATHON_INSERT_PADDING(0x48); + MARATHON_INSERT_PADDING(0x2C); + uint8_t isPlayer; + uint8_t isPosture; + uint8_t isAI; + MARATHON_INSERT_PADDING(0x19); boost::shared_ptr m_spStateMachine; - MARATHON_INSERT_PADDING(0x18); + MARATHON_INSERT_PADDING(0x10); + be m_SetupModuleIndexPre; + be m_SetupModuleIndexPost; boost::shared_ptr m_spGauge; MARATHON_INSERT_PADDING(0x204); diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h new file mode 100644 index 000000000..9a2f380c3 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h @@ -0,0 +1,35 @@ +#pragma once + +#include + +namespace Sonicteam::SoX::Input +{ + static const uint32_t XENON_GAMEPAD_BACK = 2048; + struct MGamepad + { + be wLastButtons; + be wCLastButtons; // ~wLastButtons + MARATHON_INSERT_PADDING(8); + + //Left Stick + be fX1; + be fY1; + be sThumbLX; + be sThumbLY; + + //Right Stick + be fX2; + be fY2; + be sThumbRX; + be sThumbRY; + }; + + class Manager + { + public: + be m_ControllerID; + MARATHON_INSERT_PADDING(0xC); + MGamepad m_Gamepad; + MARATHON_INSERT_PADDING(0x28); + }; +} diff --git a/MarathonRecomp/api/stdx/string.h b/MarathonRecomp/api/stdx/string.h index d652e7769..2840c7707 100644 --- a/MarathonRecomp/api/stdx/string.h +++ b/MarathonRecomp/api/stdx/string.h @@ -3,6 +3,7 @@ #include #include + namespace stdx { class string @@ -56,9 +57,28 @@ namespace stdx _Myres = 0xF; _Mysize = 0; _bx._buffer[0] = '\0'; + from_cstr(str); + } - auto len = strlen(str); + ~string() + { + cleanup(); + _Myres = 0xF; + _Mysize = 0; + _bx._buffer[0] = '\0'; + } + + void cleanup() + { + if (!is_short()) { + g_userHeap.Free((void*)_bx._str.get()); + } + } + + void from_cstr(const char* str) + { + auto len = strlen(str); if (len <= 0xF) { memcpy((void*)&_bx._buffer, str, len + 1); @@ -68,6 +88,7 @@ namespace stdx { if (is_short() || capacity() < len + 1) { + cleanup(); char* new_buf = g_userHeap.Alloc(len + 1); memset((void*)(new_buf), 0, len + 1); memcpy((void*)(new_buf), (const void*)(str), len + 1); @@ -83,14 +104,10 @@ namespace stdx } } - ~string() + string& operator=(const char* str) { - if (!is_short()) - g_userHeap.Free((void*)_bx._str.get()); - - _Myres = 0xF; - _Mysize = 0; - _bx._buffer[0] = '\0'; + from_cstr(str); + return *this; } bool operator==(const char* str) const diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h new file mode 100644 index 000000000..f898204ba --- /dev/null +++ b/MarathonRecomp/api/stdx/vector.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +namespace stdx +{ + template + struct vector + { + be _MyProxy; + xpointer _MyFirst; + xpointer _MyLast; + xpointer _MyEnd; + + Type& operator[](uint32_t index) + { + return *(Type*)((uint64_t)_MyFirst.get() + (index * sizeof(Type))); + } + size_t size() + { + return (_MyLast.ptr.get() - _MyFirst.ptr.get()) / sizeof(Type); + } + }; +} \ No newline at end of file diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 47fd00636..f4696e0f6 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -99,3 +99,55 @@ bool MidairSnowboardControl3() { return Config::MidairControlForSnowboards; } + + +//Add Missing SetupModuleDebug to table +void DebugPlayerSwitch_0(PPCRegister& r_sstring, PPCRegister& r_index) +{ + if (!Config::DebugSwitch) + { + return; + } + + auto pString = (stdx::string*)(g_memory.Translate(r_sstring.u32)); + auto Index = r_index.u32; + switch (Index) + { + case 0: + *pString = "SetupModuleDebug"; + break; + case 1: + *pString = "SetupModule"; + break; + case 2: + *pString = "SetupModuleDebug"; + break; + } +} + +PPC_FUNC_IMPL(__imp__sub_82195500); +PPC_FUNC(sub_82195500) +{ + if (!Config::DebugSwitch) + { + __imp__sub_82195500(ctx, base); + return; + } + + auto pDoc = App::s_pApp->m_pDoc; + auto pGameImp = App::s_pApp->m_pDoc->GetDocMode()->m_pGameImp; + auto pPlayer = (Sonicteam::Player::Object*)(base + ctx.r3.u32); + + + if (pPlayer->m_SetupModuleIndexPost != -2 && pPlayer->isPlayer) + { + auto PIndex = pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); + auto PManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[PIndex].get()].get(); + if ((PManager->m_Gamepad.wLastButtons.get() & Sonicteam::SoX::Input::XENON_GAMEPAD_BACK) != 0) + { + pPlayer->m_SetupModuleIndexPost = 2; + } + } + + __imp__sub_82195500(ctx, base); +} diff --git a/MarathonRecomp/user/config_def.h b/MarathonRecomp/user/config_def.h index 2c5bd780d..0ed7b3e08 100644 --- a/MarathonRecomp/user/config_def.h +++ b/MarathonRecomp/user/config_def.h @@ -80,6 +80,7 @@ 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, DebugSwitch, false); CONFIG_DEFINE_HIDDEN("Codes", bool, MidairControlForMachSpeed, false); CONFIG_DEFINE_HIDDEN("Codes", bool, MidairControlForSnowboards, false); diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index 1dc468edd..600d231d4 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -199,3 +199,10 @@ registers = ["r4"] name = "FurtherObjectShadows" address = 0x8260D7E0 registers = ["r26"] + + + +[[midasm_hook]] +name = "DebugPlayerSwitch_0" +address = 0x82195AD0 +registers = ["r5","r27"] From af75753fd9a59f38cc9c7af336b8fbf912a0d930 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 16 Aug 2025 16:30:27 +0300 Subject: [PATCH 02/16] Style --- MarathonRecomp/api/Sonicteam/DocMarathonImp.h | 1 - MarathonRecomp/api/Sonicteam/GameImp.h | 2 +- MarathonRecomp/api/Sonicteam/Player/Object.h | 6 +-- .../api/Sonicteam/SoX/Input/Manager.h | 45 +++++++++++++------ MarathonRecomp/api/stdx/string.h | 2 - MarathonRecomp/api/stdx/vector.h | 4 +- MarathonRecomp/patches/player_patches.cpp | 1 - MarathonRecompLib/config/Marathon.toml | 2 - 8 files changed, 38 insertions(+), 25 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/DocMarathonImp.h b/MarathonRecomp/api/Sonicteam/DocMarathonImp.h index 4b9a6a476..e54674e0b 100644 --- a/MarathonRecomp/api/Sonicteam/DocMarathonImp.h +++ b/MarathonRecomp/api/Sonicteam/DocMarathonImp.h @@ -6,7 +6,6 @@ #include #include - namespace Sonicteam { class DocMarathonImp : public SoX::Engine::Doc diff --git a/MarathonRecomp/api/Sonicteam/GameImp.h b/MarathonRecomp/api/Sonicteam/GameImp.h index 48a638083..baa10f721 100644 --- a/MarathonRecomp/api/Sonicteam/GameImp.h +++ b/MarathonRecomp/api/Sonicteam/GameImp.h @@ -37,7 +37,7 @@ namespace Sonicteam template inline T* GetPhysicsWorld(); - uint32_t PlayerActorIDToIndex(uint32_t ActorID) + int32_t PlayerActorIDToIndex(int32_t ActorID) { for (int i = 0; i < 4; i++) { diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index 4360d4173..ca07955f8 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -11,9 +11,9 @@ namespace Sonicteam::Player MARATHON_INSERT_PADDING(0x40); be m_PlayerIndex; MARATHON_INSERT_PADDING(0x2C); - uint8_t isPlayer; - uint8_t isPosture; - uint8_t isAI; + bool m_IsPlayer; + bool m_IsPosture; + bool m_IsAmigo; //AI::Amigo MARATHON_INSERT_PADDING(0x19); boost::shared_ptr m_spStateMachine; MARATHON_INSERT_PADDING(0x10); diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h index 9a2f380c3..7bc4433f6 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h @@ -5,23 +5,40 @@ namespace Sonicteam::SoX::Input { static const uint32_t XENON_GAMEPAD_BACK = 2048; - struct MGamepad + + enum KeyState + { + KeyState_DpadUp = 0x40, + KeyState_DpadDown = 0x80, + KeyState_DpadLeft = 0x100, + KeyState_DpadRight = 0x200, + KeyState_Start = 0x400, + KeyState_Select = 0x800, + KeyState_LeftStick = 0x10000, + KeyState_RightStick = 0x20000, + KeyState_LeftBumper = 0x1000, + KeyState_RightBumper = 0x2000, + KeyState_A = 0x1, + KeyState_B = 0x2, + KeyState_X = 0x8, + KeyState_Y = 0x10, + }; + + struct PadState { - be wLastButtons; - be wCLastButtons; // ~wLastButtons + be LastButtons; + be InvertedLastButtons; // ~wLastButtons MARATHON_INSERT_PADDING(8); - //Left Stick - be fX1; - be fY1; - be sThumbLX; - be sThumbLY; + be LeftStickHorizontal; + be LeftStickVertical; + be LeftStickHorizontalS16; + be LeftStickVerticalS16; - //Right Stick - be fX2; - be fY2; - be sThumbRX; - be sThumbRY; + be RightStickHorizontal; + be RightStickVertical; + be RightStickHorizontalS16; + be RightStickVerticalS16; }; class Manager @@ -29,7 +46,7 @@ namespace Sonicteam::SoX::Input public: be m_ControllerID; MARATHON_INSERT_PADDING(0xC); - MGamepad m_Gamepad; + PadState m_PadState; MARATHON_INSERT_PADDING(0x28); }; } diff --git a/MarathonRecomp/api/stdx/string.h b/MarathonRecomp/api/stdx/string.h index 2840c7707..258fd1e77 100644 --- a/MarathonRecomp/api/stdx/string.h +++ b/MarathonRecomp/api/stdx/string.h @@ -3,7 +3,6 @@ #include #include - namespace stdx { class string @@ -68,7 +67,6 @@ namespace stdx _bx._buffer[0] = '\0'; } - void cleanup() { if (!is_short()) { diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index f898204ba..a0e811601 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -17,9 +17,11 @@ namespace stdx { return *(Type*)((uint64_t)_MyFirst.get() + (index * sizeof(Type))); } + size_t size() { return (_MyLast.ptr.get() - _MyFirst.ptr.get()) / sizeof(Type); } }; -} \ No newline at end of file +} + diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index f4696e0f6..90f013dcf 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -100,7 +100,6 @@ bool MidairSnowboardControl3() return Config::MidairControlForSnowboards; } - //Add Missing SetupModuleDebug to table void DebugPlayerSwitch_0(PPCRegister& r_sstring, PPCRegister& r_index) { diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index 600d231d4..e80e56c76 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -200,8 +200,6 @@ name = "FurtherObjectShadows" address = 0x8260D7E0 registers = ["r26"] - - [[midasm_hook]] name = "DebugPlayerSwitch_0" address = 0x82195AD0 From de8fbf5439d7f6164501261018263fb46f34f7c9 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 16 Aug 2025 16:38:19 +0300 Subject: [PATCH 03/16] Correction --- MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h | 1 - MarathonRecomp/patches/player_patches.cpp | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h index 7bc4433f6..35eb4595c 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h @@ -4,7 +4,6 @@ namespace Sonicteam::SoX::Input { - static const uint32_t XENON_GAMEPAD_BACK = 2048; enum KeyState { diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 90f013dcf..693eb4b2a 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -137,12 +137,11 @@ PPC_FUNC(sub_82195500) auto pGameImp = App::s_pApp->m_pDoc->GetDocMode()->m_pGameImp; auto pPlayer = (Sonicteam::Player::Object*)(base + ctx.r3.u32); - - if (pPlayer->m_SetupModuleIndexPost != -2 && pPlayer->isPlayer) + if (pPlayer->m_SetupModuleIndexPost != -2 && pPlayer->m_IsPlayer) { auto PIndex = pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); auto PManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[PIndex].get()].get(); - if ((PManager->m_Gamepad.wLastButtons.get() & Sonicteam::SoX::Input::XENON_GAMEPAD_BACK) != 0) + if ((PManager->m_PadState.LastButtons.get() & Sonicteam::SoX::Input::KeyState_Select) != 0) { pPlayer->m_SetupModuleIndexPost = 2; } From 90cbec45b3408e0c753f0d736d8489a86aa82842 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 23 Aug 2025 20:21:36 +0300 Subject: [PATCH 04/16] Update Marathon.toml --- MarathonRecompLib/config/Marathon.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index 929a69e07..0e3e79545 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -201,11 +201,11 @@ address = 0x8260D7E0 registers = ["r26"] [[midasm_hook]] -DebugPlayerSwitch name = "DebugPlayerSwitch_0" address = 0x82195AD0 registers = ["r5","r27"] +[[midasm_hook]] name = "DisableRadialBlur" address = 0x82653834 jump_address_on_true = 0x82653840 From 45a177d8aca99eb17f4151c9f74f8d8aa1775da5 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 23 Aug 2025 20:21:58 +0300 Subject: [PATCH 05/16] Update vector.h --- MarathonRecomp/api/stdx/vector.h | 1 - 1 file changed, 1 deletion(-) diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index a0e811601..3b6c608dd 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -24,4 +24,3 @@ namespace stdx } }; } - From 9dac5811f5cc3e284e043ca3adc7979923477d5a Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sat, 23 Aug 2025 20:22:32 +0300 Subject: [PATCH 06/16] Update player_patches.cpp From 30823af10cbf8cddffd30f842e39d919acb3ba61 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Sat, 23 Aug 2025 18:44:59 +0100 Subject: [PATCH 07/16] Clean-up --- MarathonRecomp/api/Sonicteam/GameImp.h | 5 +++-- MarathonRecomp/api/Sonicteam/Player/Object.h | 6 +++--- MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h | 3 +-- MarathonRecomp/api/stdx/vector.h | 3 --- MarathonRecomp/patches/player_patches.cpp | 15 ++++++++------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/GameImp.h b/MarathonRecomp/api/Sonicteam/GameImp.h index baa10f721..e8037ba35 100644 --- a/MarathonRecomp/api/Sonicteam/GameImp.h +++ b/MarathonRecomp/api/Sonicteam/GameImp.h @@ -37,13 +37,14 @@ namespace Sonicteam template inline T* GetPhysicsWorld(); - int32_t PlayerActorIDToIndex(int32_t ActorID) + int32_t PlayerActorIDToIndex(int32_t actorId) const { for (int i = 0; i < 4; i++) { - if (m_PlayerData[i].ActorID == ActorID) + if (m_PlayerData[i].ActorID == actorId) return i; } + return -1; } }; diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index ca07955f8..65ae3817a 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -13,12 +13,12 @@ namespace Sonicteam::Player MARATHON_INSERT_PADDING(0x2C); bool m_IsPlayer; bool m_IsPosture; - bool m_IsAmigo; //AI::Amigo + bool m_IsAmigo; MARATHON_INSERT_PADDING(0x19); boost::shared_ptr m_spStateMachine; MARATHON_INSERT_PADDING(0x10); - be m_SetupModuleIndexPre; - be m_SetupModuleIndexPost; + be m_SetupModuleIndexPrefix; + be m_SetupModuleIndexPostfix; boost::shared_ptr m_spGauge; MARATHON_INSERT_PADDING(0x204); diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h index 35eb4595c..f81e412f0 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h @@ -4,7 +4,6 @@ namespace Sonicteam::SoX::Input { - enum KeyState { KeyState_DpadUp = 0x40, @@ -26,7 +25,7 @@ namespace Sonicteam::SoX::Input struct PadState { be LastButtons; - be InvertedLastButtons; // ~wLastButtons + be InvertedLastButtons; MARATHON_INSERT_PADDING(8); be LeftStickHorizontal; diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index 3b6c608dd..afb8f1499 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -1,8 +1,5 @@ #pragma once -#include -#include - namespace stdx { template diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 693eb4b2a..9b4f9e9af 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -133,17 +133,18 @@ PPC_FUNC(sub_82195500) return; } - auto pDoc = App::s_pApp->m_pDoc; - auto pGameImp = App::s_pApp->m_pDoc->GetDocMode()->m_pGameImp; auto pPlayer = (Sonicteam::Player::Object*)(base + ctx.r3.u32); + auto pDoc = App::s_pApp->m_pDoc; - if (pPlayer->m_SetupModuleIndexPost != -2 && pPlayer->m_IsPlayer) + if (auto pGameMode = pDoc->GetDocMode()) { - auto PIndex = pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); - auto PManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[PIndex].get()].get(); - if ((PManager->m_PadState.LastButtons.get() & Sonicteam::SoX::Input::KeyState_Select) != 0) + if (pPlayer->m_SetupModuleIndexPostfix != -2 && pPlayer->m_IsPlayer) { - pPlayer->m_SetupModuleIndexPost = 2; + auto playerIndex = pGameMode->m_pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); + auto& spManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[playerIndex]]; + + if ((spManager->m_PadState.LastButtons.get() & Sonicteam::SoX::Input::KeyState_Select) != 0) + pPlayer->m_SetupModuleIndexPostfix = 2; } } From 802ed8cce672d159eaee75b9d5e2c82cc5b7d668 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Sat, 23 Aug 2025 18:48:45 +0100 Subject: [PATCH 08/16] Clean-up 2 --- MarathonRecomp/patches/player_patches.cpp | 32 +++++++++++------------ MarathonRecompLib/config/Marathon.toml | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 9b4f9e9af..7c1c7b9a7 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -100,27 +100,27 @@ bool MidairSnowboardControl3() return Config::MidairControlForSnowboards; } -//Add Missing SetupModuleDebug to table -void DebugPlayerSwitch_0(PPCRegister& r_sstring, PPCRegister& r_index) +// Add missing SetupModuleDebug to table. +void DebugPlayerSwitch(PPCRegister& str, PPCRegister& index) { if (!Config::DebugSwitch) - { return; - } - auto pString = (stdx::string*)(g_memory.Translate(r_sstring.u32)); - auto Index = r_index.u32; - switch (Index) + auto pString = (stdx::string*)g_memory.Translate(str.u32); + + switch (index.u32) { - case 0: - *pString = "SetupModuleDebug"; - break; - case 1: - *pString = "SetupModule"; - break; - case 2: - *pString = "SetupModuleDebug"; - break; + case 0: + *pString = "SetupModuleDebug"; + break; + + case 1: + *pString = "SetupModule"; + break; + + case 2: + *pString = "SetupModuleDebug"; + break; } } diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index 0e3e79545..974786537 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -201,9 +201,9 @@ address = 0x8260D7E0 registers = ["r26"] [[midasm_hook]] -name = "DebugPlayerSwitch_0" +name = "DebugPlayerSwitch" address = 0x82195AD0 -registers = ["r5","r27"] +registers = ["r5", "r27"] [[midasm_hook]] name = "DisableRadialBlur" From f898dc9d206e033a7f336e740637c2a7df24f060 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sun, 24 Aug 2025 21:25:21 +0300 Subject: [PATCH 09/16] Select Map | B Switch Zock State --- MarathonRecomp/api/Marathon.h | 15 +- MarathonRecomp/api/Physics/Entity.h | 12 + MarathonRecomp/api/Physics/RigidBody.h | 12 + MarathonRecomp/api/Physics/Shape.h | 16 + MarathonRecomp/api/Sonicteam/MyPhantom.h | 11 + MarathonRecomp/api/Sonicteam/Player/IZock.h | 10 + MarathonRecomp/api/Sonicteam/Player/Object.h | 14 +- .../api/Sonicteam/Player/Object.inl | 13 + MarathonRecomp/api/Sonicteam/Player/Zock.h | 23 + .../api/Sonicteam/SoX/Input/Manager.h | 12 +- .../api/Sonicteam/SoX/Input/Manger.inl | 17 + .../api/Sonicteam/SoX/Math/Vector.h | 31 ++ .../api/Sonicteam/SoX/Physics/Entity.h | 18 + .../Sonicteam/SoX/Physics/Havok/EntityHavok.h | 21 + .../SoX/Physics/Havok/EntityHavokImp.h | 16 + .../SoX/Physics/Havok/PhantomHavok.h | 13 + .../api/Sonicteam/SoX/Physics/Phantom.h | 11 + .../api/Sonicteam/SoX/Physics/Shape.h | 17 + .../api/Sonicteam/SoX/RefCountObject.h | 15 + MarathonRecomp/api/stdx/vector.h | 518 +++++++++++++++++- MarathonRecomp/patches/player_patches.cpp | 29 +- MarathonRecompLib/config/Marathon.toml | 8 + 22 files changed, 830 insertions(+), 22 deletions(-) create mode 100644 MarathonRecomp/api/Physics/Entity.h create mode 100644 MarathonRecomp/api/Physics/RigidBody.h create mode 100644 MarathonRecomp/api/Physics/Shape.h create mode 100644 MarathonRecomp/api/Sonicteam/MyPhantom.h create mode 100644 MarathonRecomp/api/Sonicteam/Player/IZock.h create mode 100644 MarathonRecomp/api/Sonicteam/Player/Zock.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Input/Manger.inl create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index 49c7c4ed8..dbd959324 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -25,6 +25,7 @@ #include "Sonicteam/DocMarathonState.h" #include "Sonicteam/GameImp.h" #include "Sonicteam/GameMode.h" +#include "Sonicteam/MyPhantom.h" #include "Sonicteam/Player/IDynamicLink.h" #include "Sonicteam/Player/IExportPostureRequestFlag.h" #include "Sonicteam/Player/IExportWeaponRequestFlag.h" @@ -34,6 +35,8 @@ #include "Sonicteam/Player/IScore.h" #include "Sonicteam/Player/IStepable.h" #include "Sonicteam/Player/IVariable.h" +#include "Sonicteam/Player/IZock.h" +#include "Sonicteam/Player/Zock.h" #include "Sonicteam/Player/Object.h" #include "Sonicteam/Player/Score.h" #include "Sonicteam/Player/SonicGauge.h" @@ -54,16 +57,24 @@ #include "Sonicteam/SoX/Engine/Doc.h" #include "Sonicteam/SoX/Engine/DocMode.h" #include "Sonicteam/SoX/Engine/Task.h" +#include "Sonicteam/SoX/Input/Manager.h" #include "Sonicteam/SoX/MessageReceiver.h" #include "Sonicteam/SoX/Object.h" -#include "Sonicteam/SoX/Physics/Havok/WorldHavok.h" +#include "Sonicteam/SoX/Math/Vector.h" +#include "Sonicteam/SoX/Physics/Havok/EntityHavok.h" +#include "Sonicteam/SoX/Physics/Havok/EntityHavokImp.h" +#include "Sonicteam/SoX/Physics/Havok/PhantomHavok.h" #include "Sonicteam/SoX/Physics/World.h" -#include "Sonicteam/SoX/Input/Manager.h" +#include "Sonicteam/SoX/Physics/Entity.h" +#include "Sonicteam/SoX/Physics/Phantom.h" #include "Sonicteam/SoX/RefCountObject.h" #include "Sonicteam/System/CreateStatic.h" #include "Sonicteam/System/Singleton.h" #include "Sonicteam/TitleTask.h" #include "boost/smart_ptr/make_shared_object.h" #include "boost/smart_ptr/shared_ptr.h" +#include "Physics/RigidBody.h" +#include "Physics/Entity.h" +#include "Physics/Shape.h" #include "stdx/string.h" #include "stdx/vector.h" diff --git a/MarathonRecomp/api/Physics/Entity.h b/MarathonRecomp/api/Physics/Entity.h new file mode 100644 index 000000000..7040f025b --- /dev/null +++ b/MarathonRecomp/api/Physics/Entity.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace Phys +{ + class Entity:public Shape + { + MARATHON_INSERT_PADDING(0x5C); + }; +} + diff --git a/MarathonRecomp/api/Physics/RigidBody.h b/MarathonRecomp/api/Physics/RigidBody.h new file mode 100644 index 000000000..a8e3c84db --- /dev/null +++ b/MarathonRecomp/api/Physics/RigidBody.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace Phys +{ + class RigidBody:public Entity + { + }; +} + diff --git a/MarathonRecomp/api/Physics/Shape.h b/MarathonRecomp/api/Physics/Shape.h new file mode 100644 index 000000000..5ff54bd14 --- /dev/null +++ b/MarathonRecomp/api/Physics/Shape.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace Phys +{ + class Shape + { + public: + xpointer m_pVftable; + MARATHON_INSERT_PADDING(0x34); + be m_CollisionFilter; + MARATHON_INSERT_PADDING(0x34); + }; +} + diff --git a/MarathonRecomp/api/Sonicteam/MyPhantom.h b/MarathonRecomp/api/Sonicteam/MyPhantom.h new file mode 100644 index 000000000..367e9141a --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/MyPhantom.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace Sonicteam +{ + class MyPhantom : public SoX::Physics::Havok::PhantomHavok + { + }; +} diff --git a/MarathonRecomp/api/Sonicteam/Player/IZock.h b/MarathonRecomp/api/Sonicteam/Player/IZock.h new file mode 100644 index 000000000..b63da8036 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/IZock.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + + +namespace Sonicteam::Player +{ + class IZock : public IPlugIn {}; +} diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index 65ae3817a..7bb9d0e1b 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -2,6 +2,9 @@ #include #include +#include +#include +#include namespace Sonicteam::Player { @@ -14,16 +17,23 @@ namespace Sonicteam::Player bool m_IsPlayer; bool m_IsPosture; bool m_IsAmigo; - MARATHON_INSERT_PADDING(0x19); + MARATHON_INSERT_PADDING(0x1); + xpointer m_RootFrame; + MARATHON_INSERT_PADDING(0x14); boost::shared_ptr m_spStateMachine; MARATHON_INSERT_PADDING(0x10); be m_SetupModuleIndexPrefix; be m_SetupModuleIndexPostfix; boost::shared_ptr m_spGauge; - MARATHON_INSERT_PADDING(0x204); + MARATHON_INSERT_PADDING(0x8); + stdx::vector> m_PlayerPlugins; + MARATHON_INSERT_PADDING(0x1F4); template inline T* GetGauge(); + + template + inline T* GetPlugin(const char* PluginName); }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.inl b/MarathonRecomp/api/Sonicteam/Player/Object.inl index b4de60501..3a0854da2 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.inl +++ b/MarathonRecomp/api/Sonicteam/Player/Object.inl @@ -5,4 +5,17 @@ namespace Sonicteam::Player { return (T*)m_spGauge.get(); } + + template + inline T* Sonicteam::Player::Object::GetPlugin(const char* PluginName) + { + for (stdx::vector>::iterator it = m_PlayerPlugins.begin(); it != m_PlayerPlugins.end(); it = it + 1) + { + if (it->get()->m_Name == PluginName) + { + return static_cast(it->get()); + } + } + return nullptr; + } } diff --git a/MarathonRecomp/api/Sonicteam/Player/Zock.h b/MarathonRecomp/api/Sonicteam/Player/Zock.h new file mode 100644 index 000000000..7c12428c9 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/Zock.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace Sonicteam::Player +{ + class Zock : public IZock, public IFlagCommunicator, public IStepable, public IDynamicLink, public IVariable + { + public: + MARATHON_INSERT_PADDING(0x8); + xpointer m_pPhantom; + MARATHON_INSERT_PADDING(0x20); + xpointer m_pPhantomB; + MARATHON_INSERT_PADDING(0x84); + + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h index f81e412f0..c3b7047ff 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h @@ -4,6 +4,7 @@ namespace Sonicteam::SoX::Input { + enum KeyState { KeyState_DpadUp = 0x40, @@ -20,13 +21,16 @@ namespace Sonicteam::SoX::Input KeyState_B = 0x2, KeyState_X = 0x8, KeyState_Y = 0x10, + KeyState_LeftTrigger = 0x4000, + KeyState_RightTrigger = 0x8000, }; struct PadState { be LastButtons; be InvertedLastButtons; - MARATHON_INSERT_PADDING(8); + be PressedButtons; + be ReleasedButtons; be LeftStickHorizontal; be LeftStickVertical; @@ -37,6 +41,10 @@ namespace Sonicteam::SoX::Input be RightStickVertical; be RightStickHorizontalS16; be RightStickVerticalS16; + + bool IsDown(const KeyState in_Keys) const; + bool IsPressed(const KeyState in_Keys) const; + bool IsReleased(const KeyState in_Keys) const; }; class Manager @@ -48,3 +56,5 @@ namespace Sonicteam::SoX::Input MARATHON_INSERT_PADDING(0x28); }; } + +#include "Manger.inl" diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manger.inl b/MarathonRecomp/api/Sonicteam/SoX/Input/Manger.inl new file mode 100644 index 000000000..ad56a2da4 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manger.inl @@ -0,0 +1,17 @@ +namespace Sonicteam::SoX::Input +{ + inline bool PadState::IsDown(const KeyState in_Keys) const + { + return (LastButtons & in_Keys) == in_Keys; + } + + inline bool PadState::IsPressed(const KeyState in_Keys) const + { + return (PressedButtons & in_Keys) == in_Keys; + } + + inline bool PadState::IsReleased(const KeyState in_Keys) const + { + return (ReleasedButtons & in_Keys) == in_Keys; + } +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h new file mode 100644 index 000000000..f779f4e6a --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Marathon.inl" + +namespace Sonicteam::SoX::Math +{ + class Vector2 + { + public: + be X; + be Y; + }; + + class __declspec(align(16)) Vector + { + public: + be X; + be Y; + be Z; + be W; + }; + + class __declspec(align(16)) Vector4 + { + public: + be X; + be Y; + be Z; + be W; + }; +} \ No newline at end of file diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h new file mode 100644 index 000000000..00e08f2ca --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace Sonicteam::SoX::Physics +{ + class Entity : public SoX::MessageReceiver, public SoX::RefCountObject + { + public: + MARATHON_INSERT_PADDING(0x14); + xpointer m_Receiver; + xpointer m_RefShape; //Reference_type + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h new file mode 100644 index 000000000..f44010511 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include + +namespace Sonicteam::SoX::Physics::Havok +{ + class EntityHavok + { + public: + xpointer m_pVftable; + MARATHON_INSERT_PADDING(0xC); + xpointer m_RigidBody; + xpointer m_RefWorldHavok; //Ref_type + Sonicteam::SoX::Math::Vector m_Rotation; + Sonicteam::SoX::Math::Vector m_Translation; + MARATHON_INSERT_PADDING(0xC); + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h new file mode 100644 index 000000000..a65d48967 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +namespace Sonicteam::SoX::Physics::Havok +{ + template + class EntityHavokImp : + public T, + public Sonicteam::SoX::Physics::Havok::EntityHavok + { + //padding 0x8????? + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h new file mode 100644 index 000000000..46e7c021d --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include + +namespace Sonicteam::SoX::Physics::Havok +{ + + class PhantomHavok : public EntityHavokImp + { + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h new file mode 100644 index 000000000..bc4dab1e7 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace Sonicteam::SoX::Physics +{ + class Phantom : public Entity + { + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h new file mode 100644 index 000000000..aba1997d2 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace Sonicteam::SoX::Physics +{ + class Shape : public RefCountObject + { + be m_ShapeType; + be m_ShapeVolume; //w * h *... * FLT_MIN + //vft + //Destruction + //ShapeVFT4(_out VECTOR* u1,__out VECTOR* u2) + //InitializeVolume() + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h b/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h index 4f006d9b7..61955d248 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h +++ b/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace Sonicteam::SoX { class RefCountObject @@ -7,5 +9,18 @@ namespace Sonicteam::SoX public: xpointer m_pVftable; be m_ReferenceCount; + + void Release(uint32_t Flag = 1) + { + m_ReferenceCount = m_ReferenceCount - 1; + if (!m_ReferenceCount.get()) + MARATHON_VIRTUAL_FUNCTION(void*, 0,this, Flag); + } + + inline void AddRef() + { + m_ReferenceCount = m_ReferenceCount + 1; + } + }; } diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index afb8f1499..5d1b9d9a6 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -1,23 +1,515 @@ #pragma once -namespace stdx -{ - template - struct vector - { - be _MyProxy; - xpointer _MyFirst; - xpointer _MyLast; - xpointer _MyEnd; +#include +#include +#include +#include + +namespace stdx { + + template + class vector { + private: + be _Myproxy; + xpointer _MyFirst; + xpointer _MyLast; + xpointer _MyEnd; + + static xpointer xpointer_add(xpointer ptr, size_t offset) + { + return xpointer(reinterpret_cast( + reinterpret_cast(ptr.get()) + offset * sizeof(T))); + } + + 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 new_capacity) + { + T* new_block = static_cast(g_userHeap.Alloc(sizeof(T) * new_capacity)); + const size_t old_size = size(); + + for (size_t i = 0; i < old_size; ++i) { + T* target = reinterpret_cast( + reinterpret_cast(new_block) + i * sizeof(T)); + new (target) T(std::move(_MyFirst[i])); + _MyFirst[i].~T(); + } + + if (_MyFirst) { + _DestroyRange(_MyFirst.get(), _MyLast.get()); + g_userHeap.Free(_MyFirst.get()); + } + + _MyFirst = xpointer(new_block); + _MyLast = xpointer_add(_MyFirst, old_size); + _MyEnd = xpointer_add(_MyFirst, new_capacity); + } + + void _GrowIfNeeded() + { + if (_MyLast.get() == _MyEnd.get()) { + _Reallocate(size() ? size() * 2 : 1); + } + } + + class iterator_wrapper { + private: + xpointer _ptr; + + public: + explicit iterator_wrapper(xpointer ptr) + : _ptr(ptr) + { + } + + T& operator*() const + { + return *_ptr; + } + + T* operator->() const + { + return _ptr.get(); + } + + iterator_wrapper& operator++() + { + _ptr = xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) + sizeof(T))); + return *this; + } + + iterator_wrapper operator++(int) + { + iterator_wrapper tmp = *this; + ++(*this); + return tmp; + } + + iterator_wrapper& operator--() + { + _ptr = xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) - sizeof(T))); + return *this; + } + + iterator_wrapper operator--(int) + { + iterator_wrapper tmp = *this; + --(*this); + return tmp; + } + + iterator_wrapper operator+(size_t n) const + { + return iterator_wrapper(xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) + n * sizeof(T)))); + } + + iterator_wrapper operator-(size_t n) const + { + return iterator_wrapper(xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) - n * sizeof(T)))); + } + + bool operator==(const iterator_wrapper& other) const + { + return _ptr.get() == other._ptr.get(); + } + + bool operator!=(const iterator_wrapper& other) const + { + return _ptr.get() != other._ptr.get(); + } + }; + + class const_iterator_wrapper { + private: + xpointer _ptr; + + public: + explicit const_iterator_wrapper(xpointer ptr) + : _ptr(ptr) + { + } + + const T& operator*() const + { + return *_ptr; + } + + const T* operator->() const + { + return _ptr.get(); + } + + const_iterator_wrapper& operator++() + { + _ptr = xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) + sizeof(T))); + return *this; + } + + const_iterator_wrapper operator++(int) + { + const_iterator_wrapper tmp = *this; + ++(*this); + return tmp; + } + + const_iterator_wrapper& operator--() + { + _ptr = xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) - sizeof(T))); + return *this; + } + + const_iterator_wrapper operator--(int) + { + const_iterator_wrapper tmp = *this; + --(*this); + return tmp; + } + + const_iterator_wrapper operator+(size_t n) const + { + return const_iterator_wrapper(xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) + n * sizeof(T)))); + } + + const_iterator_wrapper operator-(size_t n) const + { + return const_iterator_wrapper(xpointer(reinterpret_cast( + reinterpret_cast(_ptr.get()) - n * sizeof(T)))); + } + + bool operator==(const const_iterator_wrapper& other) const + { + return _ptr.get() == other._ptr.get(); + } + + bool operator!=(const const_iterator_wrapper& other) const + { + return _ptr.get() != other._ptr.get(); + } + }; + + public: + using iterator = iterator_wrapper; + using const_iterator = const_iterator_wrapper; + + vector() noexcept + : _MyFirst(nullptr) + , _MyLast(nullptr) + , _MyEnd(nullptr) + { + } + + explicit vector(size_t count) + { + _MyFirst = xpointer(static_cast(g_userHeap.Alloc(sizeof(T) * count))); + _MyLast = xpointer_add(_MyFirst, count); + _MyEnd = _MyLast; + _ConstructRange(_MyFirst.get(), _MyLast.get(), T()); + } + + vector(size_t count, const T& value) + { + _MyFirst = xpointer(static_cast(g_userHeap.Alloc(sizeof(T) * count))); + _MyLast = xpointer_add(_MyFirst, count); + _MyEnd = _MyLast; + _ConstructRange(_MyFirst.get(), _MyLast.get(), value); + } + + vector(const vector& other) + { + _MyFirst = xpointer(static_cast(g_userHeap.Alloc(sizeof(T) * other.size()))); + _MyLast = xpointer_add(_MyFirst, other.size()); + _MyEnd = _MyLast; + + for (size_t i = 0; i < other.size(); ++i) { + new (xpointer_add(_MyFirst, i).get()) T(other._MyFirst[i]); + } + } + + vector(vector&& other) noexcept + : _MyFirst(other._MyFirst) + , _MyLast(other._MyLast) + , _MyEnd(other._MyEnd) + { + other._MyFirst = other._MyLast = other._MyEnd = nullptr; + } + + ~vector() + { + clear(); + if (_MyFirst) { + g_userHeap.Free(_MyFirst.get()); + } + } + + vector& operator=(const vector& other) + { + if (this != &other) { + vector tmp(other); + swap(tmp); + } + return *this; + } + + vector& operator=(vector&& other) noexcept + { + if (this != &other) { + clear(); + if (_MyFirst) { + g_userHeap.Free(_MyFirst.get()); + } + + _MyFirst = other._MyFirst; + _MyLast = other._MyLast; + _MyEnd = other._MyEnd; + + other._MyFirst = other._MyLast = other._MyEnd = nullptr; + } + return *this; + } + + T& operator[](size_t pos) + { + return _MyFirst.get()[pos]; + } + + const T& operator[](size_t pos) const + { + return _MyFirst.get()[pos]; + } + + T& at(size_t pos) + { + return _MyFirst.get()[pos]; + } + + const T& at(size_t pos) const + { + return _MyFirst.get()[pos]; + } - Type& operator[](uint32_t index) + T& front() { - return *(Type*)((uint64_t)_MyFirst.get() + (index * sizeof(Type))); + return *_MyFirst; } - size_t size() + const T& front() const { - return (_MyLast.ptr.get() - _MyFirst.ptr.get()) / sizeof(Type); + return *_MyFirst; + } + + T& back() + { + return *(xpointer_add(_MyLast, -1).get()); + } + + const T& back() const + { + return *(xpointer_add(_MyLast, -1).get()); + } + + T* data() + { + return _MyFirst.get(); + } + + const T* data() const + { + return _MyFirst.get(); + } + + iterator begin() + { + return iterator(_MyFirst); + } + + const_iterator begin() const + { + return const_iterator(_MyFirst); + } + + const_iterator cbegin() const + { + return const_iterator(_MyFirst); + } + + iterator end() + { + return iterator(_MyLast); + } + + const_iterator end() const + { + return const_iterator(_MyLast); + } + + const_iterator cend() const + { + return const_iterator(_MyLast); + } + + bool empty() const + { + return _MyFirst.get() == _MyLast.get(); + } + + size_t size() const + { + return (_MyLast.get() - _MyFirst.get()); + } + + size_t capacity() const + { + return (_MyEnd.get() - _MyFirst.get()); + } + + void reserve(size_t new_capacity) + { + if (new_capacity > capacity()) { + _Reallocate(new_capacity); + } + } + + void shrink_to_fit() + { + if (size() < capacity()) { + _Reallocate(size()); + } + } + + void clear() + { + _DestroyRange(_MyFirst.get(), _MyLast.get()); + _MyLast = _MyFirst; + } + + void push_back(const T& value) + { + _GrowIfNeeded(); + new (_MyLast.get()) T(value); + _MyLast = xpointer_add(_MyLast, 1); + } + + void push_back(T&& value) + { + _GrowIfNeeded(); + new (_MyLast.get()) T(std::move(value)); + _MyLast = xpointer_add(_MyLast, 1); + } + + template + void emplace_back(Args&&... args) + { + _GrowIfNeeded(); + new (_MyLast.get()) T(std::forward(args)...); + _MyLast = xpointer_add(_MyLast, 1); + } + + void pop_back() + { + _MyLast = xpointer_add(_MyLast, -1); + _MyLast.get()->~T(); + } + + void resize(size_t count) + { + if (count < size()) { + _DestroyRange(xpointer_add(_MyFirst, count).get(), _MyLast.get()); + _MyLast = xpointer_add(_MyFirst, count); + } + else if (count > size()) { + reserve(count); + while (_MyLast.get() != xpointer_add(_MyFirst, count).get()) { + new (_MyLast.get()) T(); + _MyLast = xpointer_add(_MyLast, 1); + } + } + } + + void resize(size_t count, const T& value) + { + if (count < size()) { + _DestroyRange(xpointer_add(_MyFirst, count).get(), _MyLast.get()); + _MyLast = xpointer_add(_MyFirst, count); + } + else if (count > size()) { + reserve(count); + while (_MyLast.get() != xpointer_add(_MyFirst, count).get()) { + new (_MyLast.get()) T(value); + _MyLast = xpointer_add(_MyLast, 1); + } + } + } + + void swap(vector& other) noexcept + { + std::swap(_MyFirst, other._MyFirst); + std::swap(_MyLast, other._MyLast); + std::swap(_MyEnd, other._MyEnd); } }; + + 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 7c1c7b9a7..93d899e0f 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -124,6 +124,13 @@ void DebugPlayerSwitch(PPCRegister& str, PPCRegister& index) } } +bool DebugPlayerSwitchPostureSwitchButton(PPCRegister& r_PadState, PPCRegister& r_out) +{ + + auto pPadState = (Sonicteam::SoX::Input::PadState*)(g_memory.Translate(r_PadState.u32)); + return pPadState->IsPressed(Sonicteam::SoX::Input::KeyState_Select); +} + PPC_FUNC_IMPL(__imp__sub_82195500); PPC_FUNC(sub_82195500) { @@ -135,16 +142,30 @@ PPC_FUNC(sub_82195500) auto pPlayer = (Sonicteam::Player::Object*)(base + ctx.r3.u32); auto pDoc = App::s_pApp->m_pDoc; - + auto pZock = pPlayer->GetPlugin("zock"); + if (auto pGameMode = pDoc->GetDocMode()) { - if (pPlayer->m_SetupModuleIndexPostfix != -2 && pPlayer->m_IsPlayer) + + if (pPlayer->m_IsPlayer) { auto playerIndex = pGameMode->m_pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); auto& spManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[playerIndex]]; - if ((spManager->m_PadState.LastButtons.get() & Sonicteam::SoX::Input::KeyState_Select) != 0) - pPlayer->m_SetupModuleIndexPostfix = 2; + if (pPlayer->m_SetupModuleIndexPostfix == 2 && spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_B)) + { + auto pValue = (pZock->m_pPhantom->m_RigidBody->m_CollisionFilter = pZock->m_pPhantom->m_RigidBody->m_CollisionFilter.get() == 6) ? 0x383 : 6; + if (pZock->m_pPhantom.get()) pZock->m_pPhantom->Release(); + if (pZock->m_pPhantomB.get()) pZock->m_pPhantomB->Release(); + GuestToHostFunction(sub_821E3628, &pZock->m_pPhantom, &pPlayer->m_RootFrame,static_cast(pPlayer), pValue, 50.0); + pZock->m_pPhantomB = pZock->m_pPhantom; + pZock->m_pPhantom->AddRef(); + GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(pZock->m_pPhantom.get()) + (0x3C))), pZock->m_pPhantom.get(), &pGameMode->m_pGameImp->m_pPhysicsWorld); + GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(pZock->m_pPhantom.get()) + (0x58))), pZock->m_pPhantom.get(), (uint64_t)pZock + 0xA0); + } + + if (pPlayer->m_SetupModuleIndexPostfix != 2 && !(pPlayer->m_SetupModuleIndexPrefix == 2 && pPlayer->m_SetupModuleIndexPostfix == 1) && spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_Select)) + pPlayer->m_SetupModuleIndexPostfix = 2; } } diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index 974786537..a13b7a845 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -205,6 +205,14 @@ name = "DebugPlayerSwitch" address = 0x82195AD0 registers = ["r5", "r27"] +[[midasm_hook]] +name = "DebugPlayerSwitchPostureSwitchButton" +address = 0x82221CA8 +registers = ["r30","r11"] +jump_address_on_true = 0x82221CAC +jump_address_on_false = 0x82221CD8 + + [[midasm_hook]] name = "DisableRadialBlur" address = 0x82653834 From 558d7778ce461f34c78b0f7769d956498809fcb3 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Sun, 24 Aug 2025 21:31:56 +0300 Subject: [PATCH 10/16] Update Vector.h --- MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h index f779f4e6a..85f14df90 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h @@ -11,6 +11,14 @@ namespace Sonicteam::SoX::Math be Y; }; + class Vector3 + { + public: + be X; + be Y; + be Z; + }; + class __declspec(align(16)) Vector { public: @@ -28,4 +36,4 @@ namespace Sonicteam::SoX::Math be Z; be W; }; -} \ No newline at end of file +} From c2d35a84e95ef9001c1076d3f163cbe8da655ada Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:33:00 +0300 Subject: [PATCH 11/16] More --- MarathonRecomp/api/Marathon.h | 36 +++-- MarathonRecomp/api/Marathon.inl | 10 ++ MarathonRecomp/api/Physics/Entity.h | 12 -- MarathonRecomp/api/Physics/RigidBody.h | 12 -- MarathonRecomp/api/Physics/Shape.h | 16 --- MarathonRecomp/api/Sonicteam/GameImp.h | 4 +- MarathonRecomp/api/Sonicteam/GameImp.inl | 2 +- .../Sonicteam/Player/IExportExternalFlag.h | 12 ++ MarathonRecomp/api/Sonicteam/Player/IZock.h | 1 - MarathonRecomp/api/Sonicteam/Player/Object.h | 9 +- .../api/Sonicteam/Player/Object.inl | 6 +- .../api/Sonicteam/Player/RootFrame.h | 22 +++ MarathonRecomp/api/Sonicteam/Player/Zock.h | 17 ++- .../api/Sonicteam/SoX/Graphics/Frame.h | 16 +++ .../api/Sonicteam/SoX/Input/Manager.h | 3 +- .../SoX/Input/{Manger.inl => Manager.inl} | 0 .../api/Sonicteam/SoX/Math/Vector.h | 4 +- .../api/Sonicteam/SoX/MessageReceiver.h | 15 ++- .../api/Sonicteam/SoX/Physics/Entity.h | 31 ++++- .../Sonicteam/SoX/Physics/Havok/EntityHavok.h | 8 +- .../SoX/Physics/Havok/EntityHavokImp.h | 7 +- .../SoX/Physics/Havok/PhantomHavok.h | 5 +- .../api/Sonicteam/SoX/Physics/Phantom.h | 4 +- .../Sonicteam/SoX/Physics/PhantomListener.h | 9 ++ .../api/Sonicteam/SoX/Physics/Shape.h | 11 +- .../api/Sonicteam/SoX/RefCountObject.h | 17 ++- .../api/Sonicteam/SoX/RefSharedPointer.h | 125 ++++++++++++++++++ MarathonRecomp/api/hk330/hkArray.h | 22 +++ MarathonRecomp/api/hk330/hkReferencedObject.h | 14 ++ .../api/hk330/hkpBroadPhaseHandle.h | 14 ++ MarathonRecomp/api/hk330/hkpCdBody.h | 15 +++ MarathonRecomp/api/hk330/hkpCollidable.h | 18 +++ MarathonRecomp/api/hk330/hkpEntity.h | 12 ++ .../api/hk330/hkpLinkedCollidable.h | 20 +++ MarathonRecomp/api/hk330/hkpProperty.h | 13 ++ MarathonRecomp/api/hk330/hkpRigidBody.h | 12 ++ MarathonRecomp/api/hk330/hkpShape.h | 15 +++ .../api/hk330/hkpTypedBroadPhaseHandle.h | 18 +++ MarathonRecomp/api/hk330/hkpWorld.h | 13 ++ MarathonRecomp/api/hk330/hkpWorldObject.h | 24 ++++ MarathonRecomp/patches/player_patches.cpp | 20 +-- MarathonRecompLib/config/Marathon.toml | 1 - 42 files changed, 539 insertions(+), 106 deletions(-) delete mode 100644 MarathonRecomp/api/Physics/Entity.h delete mode 100644 MarathonRecomp/api/Physics/RigidBody.h delete mode 100644 MarathonRecomp/api/Physics/Shape.h create mode 100644 MarathonRecomp/api/Sonicteam/Player/IExportExternalFlag.h create mode 100644 MarathonRecomp/api/Sonicteam/Player/RootFrame.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h rename MarathonRecomp/api/Sonicteam/SoX/Input/{Manger.inl => Manager.inl} (100%) create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h create mode 100644 MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h create mode 100644 MarathonRecomp/api/hk330/hkArray.h create mode 100644 MarathonRecomp/api/hk330/hkReferencedObject.h create mode 100644 MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h create mode 100644 MarathonRecomp/api/hk330/hkpCdBody.h create mode 100644 MarathonRecomp/api/hk330/hkpCollidable.h create mode 100644 MarathonRecomp/api/hk330/hkpEntity.h create mode 100644 MarathonRecomp/api/hk330/hkpLinkedCollidable.h create mode 100644 MarathonRecomp/api/hk330/hkpProperty.h create mode 100644 MarathonRecomp/api/hk330/hkpRigidBody.h create mode 100644 MarathonRecomp/api/hk330/hkpShape.h create mode 100644 MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h create mode 100644 MarathonRecomp/api/hk330/hkpWorld.h create mode 100644 MarathonRecomp/api/hk330/hkpWorldObject.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index ebda40eb1..ec5a8cc4a 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -27,7 +27,6 @@ #include "Sonicteam/DocMarathonState.h" #include "Sonicteam/GameImp.h" #include "Sonicteam/GameMode.h" -#include "Sonicteam/MyPhantom.h" #include "Sonicteam/HUDCALLBACK.h" #include "Sonicteam/HUDLoading.h" #include "Sonicteam/ImageFilter.h" @@ -35,10 +34,12 @@ #include "Sonicteam/MovieObjectWmv.h" #include "Sonicteam/MovieTask.h" #include "Sonicteam/MyGraphicsDevice.h" +#include "Sonicteam/MyPhantom.h" #include "Sonicteam/MyTexture.h" #include "Sonicteam/Player/IDynamicLink.h" #include "Sonicteam/Player/IExportPostureRequestFlag.h" #include "Sonicteam/Player/IExportWeaponRequestFlag.h" +#include "Sonicteam/Player/IExportExternalFlag.h" #include "Sonicteam/Player/IFlagCommunicator.h" #include "Sonicteam/Player/IGauge.h" #include "Sonicteam/Player/IPlugIn.h" @@ -46,10 +47,10 @@ #include "Sonicteam/Player/IStepable.h" #include "Sonicteam/Player/IVariable.h" #include "Sonicteam/Player/IZock.h" -#include "Sonicteam/Player/Zock.h" #include "Sonicteam/Player/Object.h" #include "Sonicteam/Player/Score.h" #include "Sonicteam/Player/SonicGauge.h" +#include "Sonicteam/Player/RootFrame.h" #include "Sonicteam/Player/State/CommonContext.h" #include "Sonicteam/Player/State/CommonFall.h" #include "Sonicteam/Player/State/CommonObject.h" @@ -61,6 +62,7 @@ #include "Sonicteam/Player/State/Machine2.h" #include "Sonicteam/Player/State/Object2.h" #include "Sonicteam/Player/State/TailsContext.h" +#include "Sonicteam/Player/Zock.h" #include "Sonicteam/SaveDataTask.h" #include "Sonicteam/SaveDataTaskXENON.h" #include "Sonicteam/SelectWindowTask.h" @@ -70,25 +72,29 @@ #include "Sonicteam/SoX/Engine/Doc.h" #include "Sonicteam/SoX/Engine/DocMode.h" #include "Sonicteam/SoX/Engine/Task.h" -#include "Sonicteam/SoX/Input/Manager.h" +#include "Sonicteam/SoX/Graphics/Device.h" #include "Sonicteam/SoX/Graphics/Technique.h" #include "Sonicteam/SoX/Graphics/TechniqueFXL.h" -#include "Sonicteam/SoX/Graphics/Device.h" +#include "Sonicteam/SoX/Graphics/Frame.h" #include "Sonicteam/SoX/Graphics/Xenon/DeviceXenon.h" #include "Sonicteam/SoX/Graphics/Xenon/TextureXenon.h" #include "Sonicteam/SoX/IResource.h" +#include "Sonicteam/SoX/Input/Manager.h" #include "Sonicteam/SoX/Math/Matrix.h" #include "Sonicteam/SoX/Math/Vector.h" #include "Sonicteam/SoX/MessageReceiver.h" #include "Sonicteam/SoX/Object.h" -#include "Sonicteam/SoX/Math/Vector.h" +#include "Sonicteam/SoX/Physics/Entity.h" #include "Sonicteam/SoX/Physics/Havok/EntityHavok.h" #include "Sonicteam/SoX/Physics/Havok/EntityHavokImp.h" #include "Sonicteam/SoX/Physics/Havok/PhantomHavok.h" -#include "Sonicteam/SoX/Physics/World.h" -#include "Sonicteam/SoX/Physics/Entity.h" +#include "Sonicteam/SoX/Physics/Havok/WorldHavok.h" #include "Sonicteam/SoX/Physics/Phantom.h" +#include "Sonicteam/SoX/Physics/PhantomListener.h" +#include "Sonicteam/SoX/Physics/Shape.h" +#include "Sonicteam/SoX/Physics/World.h" #include "Sonicteam/SoX/RefCountObject.h" +#include "Sonicteam/SoX/RefSharedPointer.h" #include "Sonicteam/StdImageFilters/BurnoutBlurFilter.h" #include "Sonicteam/StdImageFilters/SingleTechniqueFilter.h" #include "Sonicteam/System/CreateStatic.h" @@ -96,8 +102,18 @@ #include "Sonicteam/TitleTask.h" #include "boost/smart_ptr/make_shared_object.h" #include "boost/smart_ptr/shared_ptr.h" -#include "Physics/RigidBody.h" -#include "Physics/Entity.h" -#include "Physics/Shape.h" +#include "hk330/hkArray.h" +#include "hk330/hkReferencedObject.h" +#include "hk330/hkpBroadPhaseHandle.h" +#include "hk330/hkpCdBody.h" +#include "hk330/hkpCollidable.h" +#include "hk330/hkpEntity.h" +#include "hk330/hkpLinkedCollidable.h" +#include "hk330/hkpProperty.h" +#include "hk330/hkpRigidBody.h" +#include "hk330/hkpShape.h" +#include "hk330/hkpTypedBroadPhaseHandle.h" +#include "hk330/hkpWorld.h" +#include "hk330/hkpWorldObject.h" #include "stdx/string.h" #include "stdx/vector.h" diff --git a/MarathonRecomp/api/Marathon.inl b/MarathonRecomp/api/Marathon.inl index 134f99646..37ea3214e 100644 --- a/MarathonRecomp/api/Marathon.inl +++ b/MarathonRecomp/api/Marathon.inl @@ -18,4 +18,14 @@ #define MARATHON_VIRTUAL_FUNCTION(returnType, virtualIndex, ...) \ GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(this) + (4 * virtualIndex))), __VA_ARGS__) +#define MARATHON_DEFINE_VIRTUAL_FUNCTION(returnType, virtualFunc, ...) \ + returnType virtualFunc(__VA_ARGS__) \ + { \ + return GuestToHostFunction(m_pVftable->virtualFunc, this, __VA_ARGS__); \ + } + + + +#define MARATHON_VIRTUAL_FUNCTION_ATTRITUBE __attribute__((annotate("__virtual_function__"))) + struct marathon_null_ctor {}; diff --git a/MarathonRecomp/api/Physics/Entity.h b/MarathonRecomp/api/Physics/Entity.h deleted file mode 100644 index 7040f025b..000000000 --- a/MarathonRecomp/api/Physics/Entity.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -namespace Phys -{ - class Entity:public Shape - { - MARATHON_INSERT_PADDING(0x5C); - }; -} - diff --git a/MarathonRecomp/api/Physics/RigidBody.h b/MarathonRecomp/api/Physics/RigidBody.h deleted file mode 100644 index a8e3c84db..000000000 --- a/MarathonRecomp/api/Physics/RigidBody.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace Phys -{ - class RigidBody:public Entity - { - }; -} - diff --git a/MarathonRecomp/api/Physics/Shape.h b/MarathonRecomp/api/Physics/Shape.h deleted file mode 100644 index 5ff54bd14..000000000 --- a/MarathonRecomp/api/Physics/Shape.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -namespace Phys -{ - class Shape - { - public: - xpointer m_pVftable; - MARATHON_INSERT_PADDING(0x34); - be m_CollisionFilter; - MARATHON_INSERT_PADDING(0x34); - }; -} - diff --git a/MarathonRecomp/api/Sonicteam/GameImp.h b/MarathonRecomp/api/Sonicteam/GameImp.h index 6d26dbf19..9b1459c01 100644 --- a/MarathonRecomp/api/Sonicteam/GameImp.h +++ b/MarathonRecomp/api/Sonicteam/GameImp.h @@ -2,6 +2,8 @@ #include #include +#include +#include namespace Sonicteam { @@ -52,7 +54,7 @@ namespace Sonicteam MARATHON_INSERT_PADDING(0x0C); be m_Field1180; MARATHON_INSERT_PADDING(0x838); - xpointer m_pPhysicsWorld; + SoX::RefSharedPointer m_spPhysicsWorld; xpointer m_pMyCollisionFilter; template diff --git a/MarathonRecomp/api/Sonicteam/GameImp.inl b/MarathonRecomp/api/Sonicteam/GameImp.inl index ed1de103f..40ad4b37d 100644 --- a/MarathonRecomp/api/Sonicteam/GameImp.inl +++ b/MarathonRecomp/api/Sonicteam/GameImp.inl @@ -3,6 +3,6 @@ namespace Sonicteam template inline T* GameImp::GetPhysicsWorld() { - return (T*)m_pPhysicsWorld.get(); + return (T*)m_spPhysicsWorld.get(); } } diff --git a/MarathonRecomp/api/Sonicteam/Player/IExportExternalFlag.h b/MarathonRecomp/api/Sonicteam/Player/IExportExternalFlag.h new file mode 100644 index 000000000..49f323156 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/IExportExternalFlag.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace Sonicteam::Player +{ + class IExportExternalFlag + { + public: + xpointer m_pVftable; + }; +} diff --git a/MarathonRecomp/api/Sonicteam/Player/IZock.h b/MarathonRecomp/api/Sonicteam/Player/IZock.h index b63da8036..2efae5034 100644 --- a/MarathonRecomp/api/Sonicteam/Player/IZock.h +++ b/MarathonRecomp/api/Sonicteam/Player/IZock.h @@ -3,7 +3,6 @@ #include #include - namespace Sonicteam::Player { class IZock : public IPlugIn {}; diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index 6dff7d467..1b9b901e6 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include namespace Sonicteam::Player { @@ -20,7 +23,7 @@ namespace Sonicteam::Player bool m_IsPosture; bool m_IsAmigo; MARATHON_INSERT_PADDING(0x1); - xpointer m_RootFrame; + SoX::RefSharedPointer m_spRootFrame; MARATHON_INSERT_PADDING(0x14); boost::shared_ptr m_spStateMachine; MARATHON_INSERT_PADDING(0x10); @@ -28,14 +31,14 @@ namespace Sonicteam::Player be m_SetupModuleIndexPostfix; boost::shared_ptr m_spGauge; MARATHON_INSERT_PADDING(0x8); - stdx::vector> m_PlayerPlugins; + stdx::vector> m_vspPlayerPlugins; MARATHON_INSERT_PADDING(0x1F4); template inline T* GetGauge(); template - inline T* GetPlugin(const char* PluginName); + inline T* GetPlugin(const char* pluginName); }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.inl b/MarathonRecomp/api/Sonicteam/Player/Object.inl index 3a0854da2..b32336f07 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.inl +++ b/MarathonRecomp/api/Sonicteam/Player/Object.inl @@ -7,11 +7,11 @@ namespace Sonicteam::Player } template - inline T* Sonicteam::Player::Object::GetPlugin(const char* PluginName) + inline T* Sonicteam::Player::Object::GetPlugin(const char* pluginName) { - for (stdx::vector>::iterator it = m_PlayerPlugins.begin(); it != m_PlayerPlugins.end(); it = it + 1) + for (stdx::vector>::iterator it = m_vspPlayerPlugins.begin(); it != m_vspPlayerPlugins.end(); it = it + 1) { - if (it->get()->m_Name == PluginName) + if (it->get()->m_Name == pluginName) { return static_cast(it->get()); } diff --git a/MarathonRecomp/api/Sonicteam/Player/RootFrame.h b/MarathonRecomp/api/Sonicteam/Player/RootFrame.h new file mode 100644 index 000000000..dd7193a1c --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/Player/RootFrame.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace Sonicteam::Player +{ + class RootFrame : public SoX::Graphics::Frame, public IPlugIn + { + public: + SoX::Math::Matrix4x4 m_TransformMatrix0x70; //set/get + SoX::Math::Matrix4x4 m_TransformMatrix0xB0; //get + SoX::Math::Vector m_Position0xF0; + SoX::Math::Vector m_Position0x100; + SoX::Math::Vector m_Impulse; + MARATHON_INSERT_PADDING(0x30); + be m_ExternalFlag; + }; +} diff --git a/MarathonRecomp/api/Sonicteam/Player/Zock.h b/MarathonRecomp/api/Sonicteam/Player/Zock.h index 7c12428c9..0510e430b 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Zock.h +++ b/MarathonRecomp/api/Sonicteam/Player/Zock.h @@ -7,17 +7,24 @@ #include #include #include +#include +#include +#include +#include +#include namespace Sonicteam::Player { class Zock : public IZock, public IFlagCommunicator, public IStepable, public IDynamicLink, public IVariable { public: - MARATHON_INSERT_PADDING(0x8); - xpointer m_pPhantom; + SoX::RefSharedPointer m_spWorld; + SoX::RefSharedPointer m_spRootFrame; + SoX::RefSharedPointer m_pPhantom; MARATHON_INSERT_PADDING(0x20); - xpointer m_pPhantomB; - MARATHON_INSERT_PADDING(0x84); - + SoX::RefSharedPointer m_pPhantomB; + MARATHON_INSERT_PADDING(0x40); + SoX::RefSharedPointer m_spPhantomListener; + MARATHON_INSERT_PADDING(0x3C); }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h b/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h new file mode 100644 index 000000000..c03ce7c9f --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include + +namespace Sonicteam::SoX::Graphics +{ + class Frame:SoX::RefCountObject + { + public: + MARATHON_INSERT_PADDING(0x18); //SimpleNode + MARATHON_INSERT_PADDING(0x2C); + + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h index c3b7047ff..b4558da1e 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.h @@ -4,7 +4,6 @@ namespace Sonicteam::SoX::Input { - enum KeyState { KeyState_DpadUp = 0x40, @@ -57,4 +56,4 @@ namespace Sonicteam::SoX::Input }; } -#include "Manger.inl" +#include "Manager.inl" diff --git a/MarathonRecomp/api/Sonicteam/SoX/Input/Manger.inl b/MarathonRecomp/api/Sonicteam/SoX/Input/Manager.inl similarity index 100% rename from MarathonRecomp/api/Sonicteam/SoX/Input/Manger.inl rename to MarathonRecomp/api/Sonicteam/SoX/Input/Manager.inl diff --git a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h index 85f14df90..ac303e2bd 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h @@ -19,7 +19,7 @@ namespace Sonicteam::SoX::Math be Z; }; - class __declspec(align(16)) Vector + class alignas(16) Vector { public: be X; @@ -28,7 +28,7 @@ namespace Sonicteam::SoX::Math be W; }; - class __declspec(align(16)) Vector4 + class alignas(16) Vector4 { public: be X; diff --git a/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h b/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h index 284906c71..d8a1c1340 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h +++ b/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h @@ -2,9 +2,22 @@ namespace Sonicteam::SoX { + struct Message{}; + class MessageReceiver { public: - xpointer m_pVftable; + struct Vftable + { + be OnMessageRecieved; + }; + + xpointer m_pVftable; + + //Virtual + bool OnMessageRecieved(Message* message) + { + return GuestToHostFunction(m_pVftable->OnMessageRecieved, this, message); + } }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h index 00e08f2ca..5252cb80b 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h @@ -3,16 +3,41 @@ #include #include #include +#include #include #include +#include +#include namespace Sonicteam::SoX::Physics { class Entity : public SoX::MessageReceiver, public SoX::RefCountObject { public: - MARATHON_INSERT_PADDING(0x14); - xpointer m_Receiver; - xpointer m_RefShape; //Reference_type + struct Vftable:MessageReceiver::Vftable + { + MARATHON_INSERT_PADDING(0x38); + be InitializeToWorld; + MARATHON_INSERT_PADDING(0x18); + be SetPhantomListener; + }; + + MARATHON_INSERT_PADDING(0x10); + SoX::RefSharedPointer m_spPhantomListener; + xpointer m_pReceiver; + SoX::RefSharedPointer m_spShape; + + //Virtual + void InitializeToWorld(SoX::RefSharedPointer& world) + { + auto vft = static_cast(MessageReceiver::m_pVftable.get()); + GuestToHostFunction(vft->InitializeToWorld, this, &world); + } + + void SetPhantomListener(SoX::RefSharedPointer& phantomListener) + { + auto vft = static_cast(MessageReceiver::m_pVftable.get()); + GuestToHostFunction(vft->SetPhantomListener, this, &phantomListener); + } }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h index f44010511..1df52e9f1 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h @@ -1,9 +1,11 @@ #pragma once #include +#include +#include #include #include -#include +#include namespace Sonicteam::SoX::Physics::Havok { @@ -12,8 +14,8 @@ namespace Sonicteam::SoX::Physics::Havok public: xpointer m_pVftable; MARATHON_INSERT_PADDING(0xC); - xpointer m_RigidBody; - xpointer m_RefWorldHavok; //Ref_type + xpointer m_pRigidBody; + RefSharedPointer m_spWorldHavok; Sonicteam::SoX::Math::Vector m_Rotation; Sonicteam::SoX::Math::Vector m_Translation; MARATHON_INSERT_PADDING(0xC); diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h index a65d48967..3b6e6ecc3 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h @@ -7,10 +7,5 @@ namespace Sonicteam::SoX::Physics::Havok { template - class EntityHavokImp : - public T, - public Sonicteam::SoX::Physics::Havok::EntityHavok - { - //padding 0x8????? - }; + class EntityHavokImp :public T,public Sonicteam::SoX::Physics::Havok::EntityHavok {}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h index 46e7c021d..e61a6b5d1 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h @@ -6,8 +6,5 @@ namespace Sonicteam::SoX::Physics::Havok { - - class PhantomHavok : public EntityHavokImp - { - }; + class PhantomHavok : public EntityHavokImp {}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h index bc4dab1e7..a1edbc640 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h @@ -5,7 +5,5 @@ namespace Sonicteam::SoX::Physics { - class Phantom : public Entity - { - }; + class Phantom : public Entity{}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h new file mode 100644 index 000000000..28098d128 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +namespace Sonicteam::SoX::Physics +{ + class PhantomListener : public SoX::RefCountObject{}; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h index aba1997d2..8f417c30a 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h @@ -7,11 +7,14 @@ namespace Sonicteam::SoX::Physics { class Shape : public RefCountObject { + public: + struct Vftable: RefCountObject::Vftable + { + be ShapeVFT4; //(_out VECTOR* u1,__out VECTOR* u2) + be InitializeVolume; + }; + be m_ShapeType; be m_ShapeVolume; //w * h *... * FLT_MIN - //vft - //Destruction - //ShapeVFT4(_out VECTOR* u1,__out VECTOR* u2) - //InitializeVolume() }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h b/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h index 61955d248..bf3e24dd8 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h +++ b/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h @@ -1,20 +1,25 @@ #pragma once -#include +#include namespace Sonicteam::SoX { class RefCountObject { public: - xpointer m_pVftable; + struct Vftable + { + be Destroy; + }; + + xpointer m_pVftable; be m_ReferenceCount; void Release(uint32_t Flag = 1) { m_ReferenceCount = m_ReferenceCount - 1; if (!m_ReferenceCount.get()) - MARATHON_VIRTUAL_FUNCTION(void*, 0,this, Flag); + Destroy(1); } inline void AddRef() @@ -22,5 +27,11 @@ namespace Sonicteam::SoX m_ReferenceCount = m_ReferenceCount + 1; } + //Virtual + void* Destroy(uint32_t flag) + { + return GuestToHostFunction(m_pVftable->Destroy,this,flag); + } + }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h b/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h new file mode 100644 index 000000000..293cecea4 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h @@ -0,0 +1,125 @@ +#pragma once + +#include +#include + +namespace Sonicteam::SoX +{ + + template + class RefSharedPointer + { + private: + xpointer m_value; + + public: + explicit RefSharedPointer(RefType* value) + : m_value(value) + { + if (m_value.get()) + { + m_value->AddRef(); + } + } + + explicit RefSharedPointer(xpointer value) + : m_value(value) + { + if (m_value.get()) + { + m_value->AddRef(); + } + } + + RefSharedPointer(const RefSharedPointer& other) + : m_value(other.m_value) + { + if (m_value.get()) + { + m_value->AddRef(); + } + } + + RefSharedPointer(RefSharedPointer&& other) noexcept + : m_value(std::move(other.m_value)) + { + other.m_value = nullptr; + } + + ~RefSharedPointer() + { + if (m_value.get()) + { + m_value->Release(); + } + } + + RefSharedPointer& operator=(const RefSharedPointer& other) + { + if (this != &other) { + if (m_value.get()) { + m_value->Release(); + } + + m_value = other.m_value; + + if (m_value.get()) { + m_value->AddRef(); + } + } + return *this; + } + + RefSharedPointer& operator=(RefSharedPointer&& other) noexcept + { + if (this != &other) { + if (m_value.get()) { + m_value->Release(); + } + + m_value = std::move(other.m_value); + other.m_value = nullptr; + } + return *this; + } + + void reset() + { + if (m_value.get()) + { + m_value->Release(); + } + m_value = 0; + } + + RefType* get() const noexcept + { + return m_value.get(); + } + + RefType* operator->() const noexcept + { + return m_value.get(); + } + + RefType& operator*() const noexcept + { + return *m_value.get(); + } + + explicit operator bool() const noexcept + { + return m_value.get() != nullptr; + } + + bool operator==(const RefSharedPointer& other) const noexcept + { + return m_value.get() == other.m_value.get(); + } + + bool operator!=(const RefSharedPointer& other) const noexcept + { + return !(*this == other); + } + }; +} diff --git a/MarathonRecomp/api/hk330/hkArray.h b/MarathonRecomp/api/hk330/hkArray.h new file mode 100644 index 000000000..69f27e8bb --- /dev/null +++ b/MarathonRecomp/api/hk330/hkArray.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace hk330 +{ + template + class hkArray + { + public: + xpointer m_ptr; + uint32_t m_numElements; + uint32_t m_maxElements; + + template + T* GetAt(P at) + { + return (T*)((uintptr_t)m_ptr.get() + (at * sizeof(T))); + } + }; +} + diff --git a/MarathonRecomp/api/hk330/hkReferencedObject.h b/MarathonRecomp/api/hk330/hkReferencedObject.h new file mode 100644 index 000000000..9c2008c02 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkReferencedObject.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace hk330 +{ + class hkReferencedObject + { + xpointer m_pVftable; + be m_memSizeAndFlags{}; + be m_referenceCount{}; + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h b/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h new file mode 100644 index 000000000..db96d53d4 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpBroadPhaseHandle + { + public: + be m_id; + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpCdBody.h b/MarathonRecomp/api/hk330/hkpCdBody.h new file mode 100644 index 000000000..21860d8b6 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpCdBody.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpCdBody + { + public: + xpointer m_shape; + MARATHON_INSERT_PADDING(0xC); + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpCollidable.h b/MarathonRecomp/api/hk330/hkpCollidable.h new file mode 100644 index 000000000..6d17ae3e8 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpCollidable.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +namespace hk330 +{ + class hkpCollidable : hkpCdBody + { + public: + MARATHON_INSERT_PADDING(0x4); + hkpTypedBroadPhaseHandle m_BroadPhaseHandle; + MARATHON_INSERT_PADDING(0x28); + be m_PenetrationDepth; + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpEntity.h b/MarathonRecomp/api/hk330/hkpEntity.h new file mode 100644 index 000000000..add800ed7 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpEntity.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace hk330 +{ + class hkpEntity: public hkpWorldObject + { + MARATHON_INSERT_PADDING(0x1E0); + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpLinkedCollidable.h b/MarathonRecomp/api/hk330/hkpLinkedCollidable.h new file mode 100644 index 000000000..8e72d1f64 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpLinkedCollidable.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +namespace hk330 +{ + class hkpLinkedCollidable : public hkpCollidable + { + public: + struct Entry + { + MARATHON_INSERT_PADDING(4); + xpointer m_other; + }; + hkArray m_Entries; + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpProperty.h b/MarathonRecomp/api/hk330/hkpProperty.h new file mode 100644 index 000000000..044572baa --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpProperty.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpProperty + { + MARATHON_INSERT_PADDING(0x8); + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpRigidBody.h b/MarathonRecomp/api/hk330/hkpRigidBody.h new file mode 100644 index 000000000..3ee09752d --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpRigidBody.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpRigidBody : public hkpEntity + { + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpShape.h b/MarathonRecomp/api/hk330/hkpShape.h new file mode 100644 index 000000000..578a6f47d --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpShape.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpShape : hkReferencedObject + { + public: + be m_userdata; + be m_type; + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h b/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h new file mode 100644 index 000000000..43c2cb141 --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpTypedBroadPhaseHandle : hkpBroadPhaseHandle + { + public: + int8_t m_type; + int8_t m_owner; + be m_QualityType; + be m_CollisionFilter; + + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpWorld.h b/MarathonRecomp/api/hk330/hkpWorld.h new file mode 100644 index 000000000..c666cdd9d --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpWorld.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace hk330 +{ + class hkpWorld:hkReferencedObject + { + MARATHON_INSERT_PADDING(0x308); + }; +} + diff --git a/MarathonRecomp/api/hk330/hkpWorldObject.h b/MarathonRecomp/api/hk330/hkpWorldObject.h new file mode 100644 index 000000000..c94a151dc --- /dev/null +++ b/MarathonRecomp/api/hk330/hkpWorldObject.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace hk330 +{ + class hkpWorldObject : hkReferencedObject + { + public: + xpointer m_world; + uint32_t m_userData; + MARATHON_INSERT_PADDING(0xC); //xbox 360 padding + hkpLinkedCollidable m_collidable; + MARATHON_INSERT_PADDING(8); + xpointer m_name; + hkArray m_properties; + }; +} + diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 535e848b0..0d3a7d8ae 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -107,7 +107,6 @@ void DebugPlayerSwitch(PPCRegister& str, PPCRegister& index) bool DebugPlayerSwitchPostureSwitchButton(PPCRegister& r_PadState, PPCRegister& r_out) { - auto pPadState = (Sonicteam::SoX::Input::PadState*)(g_memory.Translate(r_PadState.u32)); return pPadState->IsPressed(Sonicteam::SoX::Input::KeyState_Select); } @@ -127,7 +126,6 @@ PPC_FUNC(sub_82195500) if (auto pGameMode = pDoc->GetDocMode()) { - if (pPlayer->m_IsPlayer) { auto playerIndex = pGameMode->m_pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); @@ -135,18 +133,20 @@ PPC_FUNC(sub_82195500) if (pPlayer->m_SetupModuleIndexPostfix == 2 && spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_B)) { - auto pValue = (pZock->m_pPhantom->m_RigidBody->m_CollisionFilter = pZock->m_pPhantom->m_RigidBody->m_CollisionFilter.get() == 6) ? 0x383 : 6; - if (pZock->m_pPhantom.get()) pZock->m_pPhantom->Release(); - if (pZock->m_pPhantomB.get()) pZock->m_pPhantomB->Release(); - GuestToHostFunction(sub_821E3628, &pZock->m_pPhantom, &pPlayer->m_RootFrame,static_cast(pPlayer), pValue, 50.0); + auto pValue = (pZock->m_pPhantom->m_pRigidBody->m_collidable.m_BroadPhaseHandle.m_CollisionFilter = pZock->m_pPhantom->m_pRigidBody->m_collidable.m_BroadPhaseHandle.m_CollisionFilter.get() == 6) ? 0x383 : 6; + + pZock->m_pPhantom.reset(); + pZock->m_pPhantomB.reset(); + + GuestToHostFunction(sub_821E3628, &pZock->m_pPhantom, &pPlayer->m_spRootFrame, static_cast(pPlayer), pValue, 50.0); + pZock->m_pPhantomB = pZock->m_pPhantom; - pZock->m_pPhantom->AddRef(); - GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(pZock->m_pPhantom.get()) + (0x3C))), pZock->m_pPhantom.get(), &pGameMode->m_pGameImp->m_pPhysicsWorld); - GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(pZock->m_pPhantom.get()) + (0x58))), pZock->m_pPhantom.get(), (uint64_t)pZock + 0xA0); + pZock->m_pPhantom->InitializeToWorld(pGameMode->m_pGameImp->m_spPhysicsWorld); + pZock->m_pPhantom->SetPhantomListener(pZock->m_spPhantomListener); } if (pPlayer->m_SetupModuleIndexPostfix != 2 && !(pPlayer->m_SetupModuleIndexPrefix == 2 && pPlayer->m_SetupModuleIndexPostfix == 1) && spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_Select)) - pPlayer->m_SetupModuleIndexPostfix = 2; + pPlayer->m_SetupModuleIndexPostfix = 2; } } diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index 3a911deeb..c4efbba3c 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -207,7 +207,6 @@ registers = ["r30","r11"] jump_address_on_true = 0x82221CAC jump_address_on_false = 0x82221CD8 - [[midasm_hook]] name = "DisableRadialBlur" address = 0x82653834 From 4522a8bbe5d98c493db989c37279055508ceba77 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:34:40 +0300 Subject: [PATCH 12/16] Woops --- MarathonRecomp/api/Marathon.inl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MarathonRecomp/api/Marathon.inl b/MarathonRecomp/api/Marathon.inl index 37ea3214e..cca092669 100644 --- a/MarathonRecomp/api/Marathon.inl +++ b/MarathonRecomp/api/Marathon.inl @@ -24,8 +24,4 @@ return GuestToHostFunction(m_pVftable->virtualFunc, this, __VA_ARGS__); \ } - - -#define MARATHON_VIRTUAL_FUNCTION_ATTRITUBE __attribute__((annotate("__virtual_function__"))) - struct marathon_null_ctor {}; From af1e9e6f91d8596ba0b8064ee498b8ae0fe53460 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:35:19 +0300 Subject: [PATCH 13/16] WoopsX2 --- MarathonRecomp/api/Marathon.inl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MarathonRecomp/api/Marathon.inl b/MarathonRecomp/api/Marathon.inl index cca092669..134f99646 100644 --- a/MarathonRecomp/api/Marathon.inl +++ b/MarathonRecomp/api/Marathon.inl @@ -18,10 +18,4 @@ #define MARATHON_VIRTUAL_FUNCTION(returnType, virtualIndex, ...) \ GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(this) + (4 * virtualIndex))), __VA_ARGS__) -#define MARATHON_DEFINE_VIRTUAL_FUNCTION(returnType, virtualFunc, ...) \ - returnType virtualFunc(__VA_ARGS__) \ - { \ - return GuestToHostFunction(m_pVftable->virtualFunc, this, __VA_ARGS__); \ - } - struct marathon_null_ctor {}; From f31e06d4403eb313f628940f0cf833e9fc427eb9 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:38:04 +0300 Subject: [PATCH 14/16] Woops3 --- .../api/Sonicteam/SoX/RefSharedPointer.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h b/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h index 293cecea4..daff6ac05 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h +++ b/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h @@ -5,7 +5,6 @@ namespace Sonicteam::SoX { - template class RefSharedPointer { @@ -56,14 +55,13 @@ namespace Sonicteam::SoX RefSharedPointer& operator=(const RefSharedPointer& other) { - if (this != &other) { - if (m_value.get()) { - m_value->Release(); - } - + if (this != &other) + { + reset(); m_value = other.m_value; - if (m_value.get()) { + if (m_value.get()) + { m_value->AddRef(); } } @@ -72,10 +70,9 @@ namespace Sonicteam::SoX RefSharedPointer& operator=(RefSharedPointer&& other) noexcept { - if (this != &other) { - if (m_value.get()) { - m_value->Release(); - } + if (this != &other) + { + reset(); m_value = std::move(other.m_value); other.m_value = nullptr; From 246a52876ac871a53ecc39583866a90ff3b8bac3 Mon Sep 17 00:00:00 2001 From: ReimousTH <51449880+ReimousTH@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:40:16 +0300 Subject: [PATCH 15/16] Woops4 --- MarathonRecomp/api/hk330/hkpWorld.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MarathonRecomp/api/hk330/hkpWorld.h b/MarathonRecomp/api/hk330/hkpWorld.h index c666cdd9d..6aada7132 100644 --- a/MarathonRecomp/api/hk330/hkpWorld.h +++ b/MarathonRecomp/api/hk330/hkpWorld.h @@ -5,7 +5,7 @@ namespace hk330 { - class hkpWorld:hkReferencedObject + class hkpWorld: hkReferencedObject { MARATHON_INSERT_PADDING(0x308); }; From e2dbd854bf5bdc9c0c110d55a99c0152ec886074 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Tue, 26 Aug 2025 01:05:30 +0100 Subject: [PATCH 16/16] Clean-up --- MarathonRecomp/api/Marathon.h | 7 +- MarathonRecomp/api/Sonicteam/DocMarathonImp.h | 2 +- MarathonRecomp/api/Sonicteam/MyPhantom.h | 4 +- MarathonRecomp/api/Sonicteam/Player/Object.h | 12 +-- .../api/Sonicteam/Player/Object.inl | 11 +- .../api/Sonicteam/Player/RootFrame.h | 8 +- MarathonRecomp/api/Sonicteam/Player/Zock.h | 10 +- .../api/Sonicteam/SoX/Graphics/Frame.h | 5 +- .../api/Sonicteam/SoX/Math/Quaternion.h | 15 +++ .../api/Sonicteam/SoX/Math/Vector.h | 11 +- .../api/Sonicteam/SoX/MessageReceiver.h | 3 +- .../api/Sonicteam/SoX/Physics/Entity.h | 15 ++- .../Sonicteam/SoX/Physics/Havok/EntityHavok.h | 11 +- .../SoX/Physics/Havok/EntityHavokImp.h | 2 +- .../SoX/Physics/Havok/PhantomHavok.h | 2 +- .../api/Sonicteam/SoX/Physics/Phantom.h | 2 +- .../Sonicteam/SoX/Physics/PhantomListener.h | 2 +- .../api/Sonicteam/SoX/Physics/Shape.h | 6 +- .../api/Sonicteam/SoX/RefCountObject.h | 9 +- .../api/Sonicteam/SoX/RefSharedPointer.h | 83 +++++++-------- MarathonRecomp/api/hk330/hkArray.h | 13 ++- MarathonRecomp/api/hk330/hkReferencedObject.h | 2 +- .../api/hk330/hkpBroadPhaseHandle.h | 1 - MarathonRecomp/api/hk330/hkpCdBody.h | 5 +- MarathonRecomp/api/hk330/hkpCollidable.h | 9 +- MarathonRecomp/api/hk330/hkpEntity.h | 4 +- .../api/hk330/hkpLinkedCollidable.h | 8 +- MarathonRecomp/api/hk330/hkpProperty.h | 4 +- MarathonRecomp/api/hk330/hkpRigidBody.h | 5 +- MarathonRecomp/api/hk330/hkpShape.h | 5 +- .../api/hk330/hkpTypedBroadPhaseHandle.h | 10 +- MarathonRecomp/api/hk330/hkpWorld.h | 4 +- MarathonRecomp/api/hk330/hkpWorldObject.h | 5 +- MarathonRecomp/api/stdx/string.h | 4 +- MarathonRecomp/api/stdx/vector.h | 100 +++++++++--------- MarathonRecomp/patches/player_patches.cpp | 36 ++++--- MarathonRecomp/user/config_def.h | 2 +- MarathonRecompLib/config/Marathon.toml | 4 +- 38 files changed, 216 insertions(+), 225 deletions(-) create mode 100644 MarathonRecomp/api/Sonicteam/SoX/Math/Quaternion.h diff --git a/MarathonRecomp/api/Marathon.h b/MarathonRecomp/api/Marathon.h index ec5a8cc4a..51662c8fe 100644 --- a/MarathonRecomp/api/Marathon.h +++ b/MarathonRecomp/api/Marathon.h @@ -37,9 +37,9 @@ #include "Sonicteam/MyPhantom.h" #include "Sonicteam/MyTexture.h" #include "Sonicteam/Player/IDynamicLink.h" +#include "Sonicteam/Player/IExportExternalFlag.h" #include "Sonicteam/Player/IExportPostureRequestFlag.h" #include "Sonicteam/Player/IExportWeaponRequestFlag.h" -#include "Sonicteam/Player/IExportExternalFlag.h" #include "Sonicteam/Player/IFlagCommunicator.h" #include "Sonicteam/Player/IGauge.h" #include "Sonicteam/Player/IPlugIn.h" @@ -48,9 +48,9 @@ #include "Sonicteam/Player/IVariable.h" #include "Sonicteam/Player/IZock.h" #include "Sonicteam/Player/Object.h" +#include "Sonicteam/Player/RootFrame.h" #include "Sonicteam/Player/Score.h" #include "Sonicteam/Player/SonicGauge.h" -#include "Sonicteam/Player/RootFrame.h" #include "Sonicteam/Player/State/CommonContext.h" #include "Sonicteam/Player/State/CommonFall.h" #include "Sonicteam/Player/State/CommonObject.h" @@ -73,14 +73,15 @@ #include "Sonicteam/SoX/Engine/DocMode.h" #include "Sonicteam/SoX/Engine/Task.h" #include "Sonicteam/SoX/Graphics/Device.h" +#include "Sonicteam/SoX/Graphics/Frame.h" #include "Sonicteam/SoX/Graphics/Technique.h" #include "Sonicteam/SoX/Graphics/TechniqueFXL.h" -#include "Sonicteam/SoX/Graphics/Frame.h" #include "Sonicteam/SoX/Graphics/Xenon/DeviceXenon.h" #include "Sonicteam/SoX/Graphics/Xenon/TextureXenon.h" #include "Sonicteam/SoX/IResource.h" #include "Sonicteam/SoX/Input/Manager.h" #include "Sonicteam/SoX/Math/Matrix.h" +#include "Sonicteam/SoX/Math/Quaternion.h" #include "Sonicteam/SoX/Math/Vector.h" #include "Sonicteam/SoX/MessageReceiver.h" #include "Sonicteam/SoX/Object.h" diff --git a/MarathonRecomp/api/Sonicteam/DocMarathonImp.h b/MarathonRecomp/api/Sonicteam/DocMarathonImp.h index e54674e0b..bc5f62f2d 100644 --- a/MarathonRecomp/api/Sonicteam/DocMarathonImp.h +++ b/MarathonRecomp/api/Sonicteam/DocMarathonImp.h @@ -12,7 +12,7 @@ namespace Sonicteam { public: MARATHON_INSERT_PADDING(0x40); - stdx::vector> m_vspInputManager; + stdx::vector> m_vspInputManager; MARATHON_INSERT_PADDING(0x24); bool m_VFrame; MARATHON_INSERT_PADDING(0x55B58); diff --git a/MarathonRecomp/api/Sonicteam/MyPhantom.h b/MarathonRecomp/api/Sonicteam/MyPhantom.h index 367e9141a..a17e6f1ad 100644 --- a/MarathonRecomp/api/Sonicteam/MyPhantom.h +++ b/MarathonRecomp/api/Sonicteam/MyPhantom.h @@ -5,7 +5,5 @@ namespace Sonicteam { - class MyPhantom : public SoX::Physics::Havok::PhantomHavok - { - }; + class MyPhantom : public SoX::Physics::Havok::PhantomHavok {}; } diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.h b/MarathonRecomp/api/Sonicteam/Player/Object.h index 1b9b901e6..8ea599e9e 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.h +++ b/MarathonRecomp/api/Sonicteam/Player/Object.h @@ -16,28 +16,28 @@ namespace Sonicteam::Player public: stdx::string m_PlayerLua; stdx::string m_PlayerPackage; - MARATHON_INSERT_PADDING(0x8); + MARATHON_INSERT_PADDING(8); be m_PlayerIndex; MARATHON_INSERT_PADDING(0x2C); bool m_IsPlayer; bool m_IsPosture; bool m_IsAmigo; - MARATHON_INSERT_PADDING(0x1); - SoX::RefSharedPointer m_spRootFrame; + MARATHON_INSERT_PADDING(1); + SoX::RefSharedPointer m_spRootFrame; MARATHON_INSERT_PADDING(0x14); boost::shared_ptr m_spStateMachine; MARATHON_INSERT_PADDING(0x10); be m_SetupModuleIndexPrefix; be m_SetupModuleIndexPostfix; boost::shared_ptr m_spGauge; - MARATHON_INSERT_PADDING(0x8); - stdx::vector> m_vspPlayerPlugins; + MARATHON_INSERT_PADDING(8); + stdx::vector> m_vspPlayerPlugins; MARATHON_INSERT_PADDING(0x1F4); template inline T* GetGauge(); - template + template inline T* GetPlugin(const char* pluginName); }; } diff --git a/MarathonRecomp/api/Sonicteam/Player/Object.inl b/MarathonRecomp/api/Sonicteam/Player/Object.inl index b32336f07..ed6ce292a 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Object.inl +++ b/MarathonRecomp/api/Sonicteam/Player/Object.inl @@ -7,15 +7,14 @@ namespace Sonicteam::Player } template - inline T* Sonicteam::Player::Object::GetPlugin(const char* pluginName) + inline T* Object::GetPlugin(const char* pluginName) { - for (stdx::vector>::iterator it = m_vspPlayerPlugins.begin(); it != m_vspPlayerPlugins.end(); it = it + 1) + for (auto& spPlugin : m_vspPlayerPlugins) { - if (it->get()->m_Name == pluginName) - { - return static_cast(it->get()); - } + if (spPlugin->m_Name == pluginName) + return static_cast(spPlugin.get()); } + return nullptr; } } diff --git a/MarathonRecomp/api/Sonicteam/Player/RootFrame.h b/MarathonRecomp/api/Sonicteam/Player/RootFrame.h index dd7193a1c..b47b070da 100644 --- a/MarathonRecomp/api/Sonicteam/Player/RootFrame.h +++ b/MarathonRecomp/api/Sonicteam/Player/RootFrame.h @@ -11,10 +11,10 @@ namespace Sonicteam::Player class RootFrame : public SoX::Graphics::Frame, public IPlugIn { public: - SoX::Math::Matrix4x4 m_TransformMatrix0x70; //set/get - SoX::Math::Matrix4x4 m_TransformMatrix0xB0; //get - SoX::Math::Vector m_Position0xF0; - SoX::Math::Vector m_Position0x100; + SoX::Math::Matrix4x4 m_Transform70; + SoX::Math::Matrix4x4 m_TransformB0; + SoX::Math::Vector m_PositionF0; + SoX::Math::Vector m_Position100; SoX::Math::Vector m_Impulse; MARATHON_INSERT_PADDING(0x30); be m_ExternalFlag; diff --git a/MarathonRecomp/api/Sonicteam/Player/Zock.h b/MarathonRecomp/api/Sonicteam/Player/Zock.h index 0510e430b..34fb8a2e3 100644 --- a/MarathonRecomp/api/Sonicteam/Player/Zock.h +++ b/MarathonRecomp/api/Sonicteam/Player/Zock.h @@ -18,13 +18,13 @@ namespace Sonicteam::Player class Zock : public IZock, public IFlagCommunicator, public IStepable, public IDynamicLink, public IVariable { public: - SoX::RefSharedPointer m_spWorld; - SoX::RefSharedPointer m_spRootFrame; - SoX::RefSharedPointer m_pPhantom; + SoX::RefSharedPointer m_spWorld; + SoX::RefSharedPointer m_spRootFrame; + SoX::RefSharedPointer m_spPhantomA; MARATHON_INSERT_PADDING(0x20); - SoX::RefSharedPointer m_pPhantomB; + SoX::RefSharedPointer m_spPhantomB; MARATHON_INSERT_PADDING(0x40); - SoX::RefSharedPointer m_spPhantomListener; + SoX::RefSharedPointer m_spPhantomListener; MARATHON_INSERT_PADDING(0x3C); }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h b/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h index c03ce7c9f..2e7ef91ba 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Graphics/Frame.h @@ -6,11 +6,10 @@ namespace Sonicteam::SoX::Graphics { - class Frame:SoX::RefCountObject + class Frame : public SoX::RefCountObject { public: - MARATHON_INSERT_PADDING(0x18); //SimpleNode + MARATHON_INSERT_PADDING(0x18); // SimpleNode MARATHON_INSERT_PADDING(0x2C); - }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Math/Quaternion.h b/MarathonRecomp/api/Sonicteam/SoX/Math/Quaternion.h new file mode 100644 index 000000000..587b4f543 --- /dev/null +++ b/MarathonRecomp/api/Sonicteam/SoX/Math/Quaternion.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace Sonicteam::SoX::Math +{ + class alignas(16) Quaternion + { + public: + be X; + be Y; + be Z; + be W; + }; +} diff --git a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h index ac303e2bd..261ac62c8 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h @@ -1,6 +1,6 @@ #pragma once -#include "Marathon.inl" +#include namespace Sonicteam::SoX::Math { @@ -27,13 +27,4 @@ namespace Sonicteam::SoX::Math be Z; be W; }; - - class alignas(16) Vector4 - { - public: - be X; - be Y; - be Z; - be W; - }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h b/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h index d8a1c1340..234a864a2 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h +++ b/MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h @@ -2,7 +2,7 @@ namespace Sonicteam::SoX { - struct Message{}; + struct Message; class MessageReceiver { @@ -14,7 +14,6 @@ namespace Sonicteam::SoX xpointer m_pVftable; - //Virtual bool OnMessageRecieved(Message* message) { return GuestToHostFunction(m_pVftable->OnMessageRecieved, this, message); diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h index 5252cb80b..499654612 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Entity.h @@ -11,10 +11,10 @@ namespace Sonicteam::SoX::Physics { - class Entity : public SoX::MessageReceiver, public SoX::RefCountObject + class Entity : public MessageReceiver, public RefCountObject { public: - struct Vftable:MessageReceiver::Vftable + struct Vftable : public MessageReceiver::Vftable { MARATHON_INSERT_PADDING(0x38); be InitializeToWorld; @@ -23,18 +23,17 @@ namespace Sonicteam::SoX::Physics }; MARATHON_INSERT_PADDING(0x10); - SoX::RefSharedPointer m_spPhantomListener; - xpointer m_pReceiver; - SoX::RefSharedPointer m_spShape; + RefSharedPointer m_spPhantomListener; + xpointer m_pReceiver; + RefSharedPointer m_spShape; - //Virtual - void InitializeToWorld(SoX::RefSharedPointer& world) + void InitializeToWorld(RefSharedPointer& world) { auto vft = static_cast(MessageReceiver::m_pVftable.get()); GuestToHostFunction(vft->InitializeToWorld, this, &world); } - void SetPhantomListener(SoX::RefSharedPointer& phantomListener) + void SetPhantomListener(RefSharedPointer& phantomListener) { auto vft = static_cast(MessageReceiver::m_pVftable.get()); GuestToHostFunction(vft->SetPhantomListener, this, &phantomListener); diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h index 1df52e9f1..cf2379807 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavok.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -13,11 +14,11 @@ namespace Sonicteam::SoX::Physics::Havok { public: xpointer m_pVftable; - MARATHON_INSERT_PADDING(0xC); + MARATHON_INSERT_PADDING(0x0C); xpointer m_pRigidBody; - RefSharedPointer m_spWorldHavok; - Sonicteam::SoX::Math::Vector m_Rotation; - Sonicteam::SoX::Math::Vector m_Translation; - MARATHON_INSERT_PADDING(0xC); + RefSharedPointer m_spWorldHavok; + Math::Quaternion m_Rotation; + Math::Vector m_Translation; + MARATHON_INSERT_PADDING(0x0C); }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h index 3b6e6ecc3..a202dfb04 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/EntityHavokImp.h @@ -7,5 +7,5 @@ namespace Sonicteam::SoX::Physics::Havok { template - class EntityHavokImp :public T,public Sonicteam::SoX::Physics::Havok::EntityHavok {}; + class EntityHavokImp : public T, public EntityHavok {}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h index e61a6b5d1..61494a176 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/PhantomHavok.h @@ -6,5 +6,5 @@ namespace Sonicteam::SoX::Physics::Havok { - class PhantomHavok : public EntityHavokImp {}; + class PhantomHavok : public EntityHavokImp {}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h index a1edbc640..aa5d7d30b 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Phantom.h @@ -5,5 +5,5 @@ namespace Sonicteam::SoX::Physics { - class Phantom : public Entity{}; + class Phantom : public Entity {}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h index 28098d128..92e24f964 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/PhantomListener.h @@ -5,5 +5,5 @@ namespace Sonicteam::SoX::Physics { - class PhantomListener : public SoX::RefCountObject{}; + class PhantomListener : public RefCountObject {}; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h b/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h index 8f417c30a..0dc068a4c 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h +++ b/MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h @@ -8,13 +8,13 @@ namespace Sonicteam::SoX::Physics class Shape : public RefCountObject { public: - struct Vftable: RefCountObject::Vftable + struct Vftable : public RefCountObject::Vftable { - be ShapeVFT4; //(_out VECTOR* u1,__out VECTOR* u2) + be VFunction04; // (__out VECTOR* u1, __out VECTOR* u2) be InitializeVolume; }; be m_ShapeType; - be m_ShapeVolume; //w * h *... * FLT_MIN + be m_ShapeVolume; // w * h * ... * FLT_MIN }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h b/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h index bf3e24dd8..a1486e02c 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h +++ b/MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h @@ -15,11 +15,12 @@ namespace Sonicteam::SoX xpointer m_pVftable; be m_ReferenceCount; - void Release(uint32_t Flag = 1) + void Release(uint32_t flag = 1) { m_ReferenceCount = m_ReferenceCount - 1; + if (!m_ReferenceCount.get()) - Destroy(1); + Destroy(flag); } inline void AddRef() @@ -27,11 +28,9 @@ namespace Sonicteam::SoX m_ReferenceCount = m_ReferenceCount + 1; } - //Virtual void* Destroy(uint32_t flag) { - return GuestToHostFunction(m_pVftable->Destroy,this,flag); + return GuestToHostFunction(m_pVftable->Destroy, this, flag); } - }; } diff --git a/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h b/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h index daff6ac05..ac87501e3 100644 --- a/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h +++ b/MarathonRecomp/api/Sonicteam/SoX/RefSharedPointer.h @@ -5,52 +5,40 @@ namespace Sonicteam::SoX { - template + template class RefSharedPointer { private: - xpointer m_value; + xpointer m_ptr; public: - explicit RefSharedPointer(RefType* value) - : m_value(value) + explicit RefSharedPointer(T* value) : m_ptr(value) { - if (m_value.get()) - { - m_value->AddRef(); - } + if (m_ptr.get()) + m_ptr->AddRef(); } - explicit RefSharedPointer(xpointer value) - : m_value(value) + explicit RefSharedPointer(xpointer value) : m_ptr(value) { - if (m_value.get()) - { - m_value->AddRef(); - } + if (m_ptr.get()) + m_ptr->AddRef(); } - RefSharedPointer(const RefSharedPointer& other) - : m_value(other.m_value) + RefSharedPointer(const RefSharedPointer& other) : m_ptr(other.m_ptr) { - if (m_value.get()) - { - m_value->AddRef(); - } + if (m_ptr.get()) + m_ptr->AddRef(); } - RefSharedPointer(RefSharedPointer&& other) noexcept - : m_value(std::move(other.m_value)) + RefSharedPointer(RefSharedPointer&& other) noexcept : m_ptr(std::move(other.m_ptr)) { - other.m_value = nullptr; + other.m_ptr = nullptr; } ~RefSharedPointer() { - if (m_value.get()) - { - m_value->Release(); - } + if (m_ptr.get()) + m_ptr->Release(); } RefSharedPointer& operator=(const RefSharedPointer& other) @@ -58,13 +46,13 @@ namespace Sonicteam::SoX if (this != &other) { reset(); - m_value = other.m_value; - if (m_value.get()) - { - m_value->AddRef(); - } + m_ptr = other.m_ptr; + + if (m_ptr.get()) + m_ptr->AddRef(); } + return *this; } @@ -74,44 +62,45 @@ namespace Sonicteam::SoX { reset(); - m_value = std::move(other.m_value); - other.m_value = nullptr; + m_ptr = std::move(other.m_ptr); + + other.m_ptr = nullptr; } + return *this; } void reset() { - if (m_value.get()) - { - m_value->Release(); - } - m_value = 0; + if (m_ptr.get()) + m_ptr->Release(); + + m_ptr = 0; } - RefType* get() const noexcept + T* get() const noexcept { - return m_value.get(); + return m_ptr.get(); } - RefType* operator->() const noexcept + T* operator->() const noexcept { - return m_value.get(); + return m_ptr.get(); } - RefType& operator*() const noexcept + T& operator*() const noexcept { - return *m_value.get(); + return *m_ptr.get(); } explicit operator bool() const noexcept { - return m_value.get() != nullptr; + return m_ptr.get() != nullptr; } bool operator==(const RefSharedPointer& other) const noexcept { - return m_value.get() == other.m_value.get(); + return m_ptr.get() == other.m_ptr.get(); } bool operator!=(const RefSharedPointer& other) const noexcept diff --git a/MarathonRecomp/api/hk330/hkArray.h b/MarathonRecomp/api/hk330/hkArray.h index 69f27e8bb..3645ec099 100644 --- a/MarathonRecomp/api/hk330/hkArray.h +++ b/MarathonRecomp/api/hk330/hkArray.h @@ -8,15 +8,14 @@ namespace hk330 class hkArray { public: - xpointer m_ptr; - uint32_t m_numElements; - uint32_t m_maxElements; + xpointer m_data; + be m_size; + be m_capacityAndFlags; - template - T* GetAt(P at) + template + T* GetIndex(E i) { - return (T*)((uintptr_t)m_ptr.get() + (at * sizeof(T))); + return (T*)(m_data.get() + ((int)i * sizeof(T))); } }; } - diff --git a/MarathonRecomp/api/hk330/hkReferencedObject.h b/MarathonRecomp/api/hk330/hkReferencedObject.h index 9c2008c02..583660f55 100644 --- a/MarathonRecomp/api/hk330/hkReferencedObject.h +++ b/MarathonRecomp/api/hk330/hkReferencedObject.h @@ -6,9 +6,9 @@ namespace hk330 { class hkReferencedObject { + public: xpointer m_pVftable; be m_memSizeAndFlags{}; be m_referenceCount{}; }; } - diff --git a/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h b/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h index db96d53d4..c451f661b 100644 --- a/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h +++ b/MarathonRecomp/api/hk330/hkpBroadPhaseHandle.h @@ -11,4 +11,3 @@ namespace hk330 be m_id; }; } - diff --git a/MarathonRecomp/api/hk330/hkpCdBody.h b/MarathonRecomp/api/hk330/hkpCdBody.h index 21860d8b6..f67d5770b 100644 --- a/MarathonRecomp/api/hk330/hkpCdBody.h +++ b/MarathonRecomp/api/hk330/hkpCdBody.h @@ -9,7 +9,8 @@ namespace hk330 { public: xpointer m_shape; - MARATHON_INSERT_PADDING(0xC); + be m_shapeKey; + xpointer m_motion; + xpointer m_parent; }; } - diff --git a/MarathonRecomp/api/hk330/hkpCollidable.h b/MarathonRecomp/api/hk330/hkpCollidable.h index 6d17ae3e8..8e67bd973 100644 --- a/MarathonRecomp/api/hk330/hkpCollidable.h +++ b/MarathonRecomp/api/hk330/hkpCollidable.h @@ -6,13 +6,12 @@ namespace hk330 { - class hkpCollidable : hkpCdBody + class hkpCollidable : public hkpCdBody { public: - MARATHON_INSERT_PADDING(0x4); - hkpTypedBroadPhaseHandle m_BroadPhaseHandle; + MARATHON_INSERT_PADDING(4); + hkpTypedBroadPhaseHandle m_broadPhaseHandle; MARATHON_INSERT_PADDING(0x28); - be m_PenetrationDepth; + be m_allowedPenetrationDepth; }; } - diff --git a/MarathonRecomp/api/hk330/hkpEntity.h b/MarathonRecomp/api/hk330/hkpEntity.h index add800ed7..c5174d4f4 100644 --- a/MarathonRecomp/api/hk330/hkpEntity.h +++ b/MarathonRecomp/api/hk330/hkpEntity.h @@ -4,9 +4,9 @@ namespace hk330 { - class hkpEntity: public hkpWorldObject + class hkpEntity : public hkpWorldObject { + public: MARATHON_INSERT_PADDING(0x1E0); }; } - diff --git a/MarathonRecomp/api/hk330/hkpLinkedCollidable.h b/MarathonRecomp/api/hk330/hkpLinkedCollidable.h index 8e72d1f64..c18a221a8 100644 --- a/MarathonRecomp/api/hk330/hkpLinkedCollidable.h +++ b/MarathonRecomp/api/hk330/hkpLinkedCollidable.h @@ -9,12 +9,12 @@ namespace hk330 class hkpLinkedCollidable : public hkpCollidable { public: - struct Entry + struct CollisionEntry { MARATHON_INSERT_PADDING(4); - xpointer m_other; + xpointer m_partner; }; - hkArray m_Entries; + + hkArray m_collisionEntries; }; } - diff --git a/MarathonRecomp/api/hk330/hkpProperty.h b/MarathonRecomp/api/hk330/hkpProperty.h index 044572baa..b28b95f5c 100644 --- a/MarathonRecomp/api/hk330/hkpProperty.h +++ b/MarathonRecomp/api/hk330/hkpProperty.h @@ -7,7 +7,7 @@ namespace hk330 { class hkpProperty { - MARATHON_INSERT_PADDING(0x8); + public: + MARATHON_INSERT_PADDING(8); }; } - diff --git a/MarathonRecomp/api/hk330/hkpRigidBody.h b/MarathonRecomp/api/hk330/hkpRigidBody.h index 3ee09752d..8fe32632b 100644 --- a/MarathonRecomp/api/hk330/hkpRigidBody.h +++ b/MarathonRecomp/api/hk330/hkpRigidBody.h @@ -5,8 +5,5 @@ namespace hk330 { - class hkpRigidBody : public hkpEntity - { - }; + class hkpRigidBody : public hkpEntity {}; } - diff --git a/MarathonRecomp/api/hk330/hkpShape.h b/MarathonRecomp/api/hk330/hkpShape.h index 578a6f47d..debcc1167 100644 --- a/MarathonRecomp/api/hk330/hkpShape.h +++ b/MarathonRecomp/api/hk330/hkpShape.h @@ -5,11 +5,10 @@ namespace hk330 { - class hkpShape : hkReferencedObject + class hkpShape : public hkReferencedObject { public: - be m_userdata; + be m_userData; be m_type; }; } - diff --git a/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h b/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h index 43c2cb141..7c308b1ad 100644 --- a/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h +++ b/MarathonRecomp/api/hk330/hkpTypedBroadPhaseHandle.h @@ -5,14 +5,12 @@ namespace hk330 { - class hkpTypedBroadPhaseHandle : hkpBroadPhaseHandle + class hkpTypedBroadPhaseHandle : public hkpBroadPhaseHandle { public: int8_t m_type; - int8_t m_owner; - be m_QualityType; - be m_CollisionFilter; - + int8_t m_ownerOffset; + be m_objectQualityType; + be m_collisionFilterInfo; }; } - diff --git a/MarathonRecomp/api/hk330/hkpWorld.h b/MarathonRecomp/api/hk330/hkpWorld.h index 6aada7132..95bd5f91c 100644 --- a/MarathonRecomp/api/hk330/hkpWorld.h +++ b/MarathonRecomp/api/hk330/hkpWorld.h @@ -5,9 +5,9 @@ namespace hk330 { - class hkpWorld: hkReferencedObject + class hkpWorld : public hkReferencedObject { + public: MARATHON_INSERT_PADDING(0x308); }; } - diff --git a/MarathonRecomp/api/hk330/hkpWorldObject.h b/MarathonRecomp/api/hk330/hkpWorldObject.h index c94a151dc..db0791d06 100644 --- a/MarathonRecomp/api/hk330/hkpWorldObject.h +++ b/MarathonRecomp/api/hk330/hkpWorldObject.h @@ -9,16 +9,15 @@ namespace hk330 { - class hkpWorldObject : hkReferencedObject + class hkpWorldObject : public hkReferencedObject { public: xpointer m_world; uint32_t m_userData; - MARATHON_INSERT_PADDING(0xC); //xbox 360 padding + MARATHON_INSERT_PADDING(0x0C); hkpLinkedCollidable m_collidable; MARATHON_INSERT_PADDING(8); xpointer m_name; hkArray m_properties; }; } - diff --git a/MarathonRecomp/api/stdx/string.h b/MarathonRecomp/api/stdx/string.h index 258fd1e77..9efb429f1 100644 --- a/MarathonRecomp/api/stdx/string.h +++ b/MarathonRecomp/api/stdx/string.h @@ -69,14 +69,14 @@ namespace stdx void cleanup() { - if (!is_short()) { + if (!is_short()) g_userHeap.Free((void*)_bx._str.get()); - } } void from_cstr(const char* str) { auto len = strlen(str); + if (len <= 0xF) { memcpy((void*)&_bx._buffer, str, len + 1); diff --git a/MarathonRecomp/api/stdx/vector.h b/MarathonRecomp/api/stdx/vector.h index 5d1b9d9a6..c58a904ab 100644 --- a/MarathonRecomp/api/stdx/vector.h +++ b/MarathonRecomp/api/stdx/vector.h @@ -5,10 +5,11 @@ #include #include -namespace stdx { - +namespace stdx +{ template - class vector { + class vector + { private: be _Myproxy; xpointer _MyFirst; @@ -23,14 +24,14 @@ namespace stdx { void _ConstructRange(T* first, T* last, const T& value) { - for (; first != last; ++first) { + for (; first != last; ++first) new (first) T(value); - } } void _DestroyRange(T* first, T* last) { - while (first != last) { + while (first != last) + { first->~T(); ++first; } @@ -41,14 +42,16 @@ namespace stdx { T* new_block = static_cast(g_userHeap.Alloc(sizeof(T) * new_capacity)); const size_t old_size = size(); - for (size_t i = 0; i < old_size; ++i) { + for (size_t i = 0; i < old_size; ++i) + { T* target = reinterpret_cast( reinterpret_cast(new_block) + i * sizeof(T)); new (target) T(std::move(_MyFirst[i])); _MyFirst[i].~T(); } - if (_MyFirst) { + if (_MyFirst) + { _DestroyRange(_MyFirst.get(), _MyLast.get()); g_userHeap.Free(_MyFirst.get()); } @@ -60,20 +63,17 @@ namespace stdx { void _GrowIfNeeded() { - if (_MyLast.get() == _MyEnd.get()) { + if (_MyLast.get() == _MyEnd.get()) _Reallocate(size() ? size() * 2 : 1); - } } - class iterator_wrapper { + class iterator_wrapper + { private: xpointer _ptr; public: - explicit iterator_wrapper(xpointer ptr) - : _ptr(ptr) - { - } + explicit iterator_wrapper(xpointer ptr) : _ptr(ptr) {} T& operator*() const { @@ -89,6 +89,7 @@ namespace stdx { { _ptr = xpointer(reinterpret_cast( reinterpret_cast(_ptr.get()) + sizeof(T))); + return *this; } @@ -103,6 +104,7 @@ namespace stdx { { _ptr = xpointer(reinterpret_cast( reinterpret_cast(_ptr.get()) - sizeof(T))); + return *this; } @@ -136,15 +138,13 @@ namespace stdx { } }; - class const_iterator_wrapper { + class const_iterator_wrapper + { private: xpointer _ptr; public: - explicit const_iterator_wrapper(xpointer ptr) - : _ptr(ptr) - { - } + explicit const_iterator_wrapper(xpointer ptr) : _ptr(ptr) {} const T& operator*() const { @@ -160,6 +160,7 @@ namespace stdx { { _ptr = xpointer(reinterpret_cast( reinterpret_cast(_ptr.get()) + sizeof(T))); + return *this; } @@ -174,6 +175,7 @@ namespace stdx { { _ptr = xpointer(reinterpret_cast( reinterpret_cast(_ptr.get()) - sizeof(T))); + return *this; } @@ -211,12 +213,7 @@ namespace stdx { using iterator = iterator_wrapper; using const_iterator = const_iterator_wrapper; - vector() noexcept - : _MyFirst(nullptr) - , _MyLast(nullptr) - , _MyEnd(nullptr) - { - } + vector() noexcept : _MyFirst(nullptr), _MyLast(nullptr), _MyEnd(nullptr) {} explicit vector(size_t count) { @@ -240,15 +237,11 @@ namespace stdx { _MyLast = xpointer_add(_MyFirst, other.size()); _MyEnd = _MyLast; - for (size_t i = 0; i < other.size(); ++i) { + for (size_t i = 0; i < other.size(); ++i) new (xpointer_add(_MyFirst, i).get()) T(other._MyFirst[i]); - } } - vector(vector&& other) noexcept - : _MyFirst(other._MyFirst) - , _MyLast(other._MyLast) - , _MyEnd(other._MyEnd) + vector(vector&& other) noexcept : _MyFirst(other._MyFirst), _MyLast(other._MyLast), _MyEnd(other._MyEnd) { other._MyFirst = other._MyLast = other._MyEnd = nullptr; } @@ -256,27 +249,30 @@ namespace stdx { ~vector() { clear(); - if (_MyFirst) { + + if (_MyFirst) g_userHeap.Free(_MyFirst.get()); - } } vector& operator=(const vector& other) { - if (this != &other) { + if (this != &other) + { vector tmp(other); swap(tmp); } + return *this; } vector& operator=(vector&& other) noexcept { - if (this != &other) { + if (this != &other) + { clear(); - if (_MyFirst) { + + if (_MyFirst) g_userHeap.Free(_MyFirst.get()); - } _MyFirst = other._MyFirst; _MyLast = other._MyLast; @@ -284,6 +280,7 @@ namespace stdx { other._MyFirst = other._MyLast = other._MyEnd = nullptr; } + return *this; } @@ -384,16 +381,14 @@ namespace stdx { void reserve(size_t new_capacity) { - if (new_capacity > capacity()) { + if (new_capacity > capacity()) _Reallocate(new_capacity); - } } void shrink_to_fit() { - if (size() < capacity()) { + if (size() < capacity()) _Reallocate(size()); - } } void clear() @@ -432,13 +427,17 @@ namespace stdx { void resize(size_t count) { - if (count < size()) { + if (count < size()) + { _DestroyRange(xpointer_add(_MyFirst, count).get(), _MyLast.get()); _MyLast = xpointer_add(_MyFirst, count); } - else if (count > size()) { + else if (count > size()) + { reserve(count); - while (_MyLast.get() != xpointer_add(_MyFirst, count).get()) { + + while (_MyLast.get() != xpointer_add(_MyFirst, count).get()) + { new (_MyLast.get()) T(); _MyLast = xpointer_add(_MyLast, 1); } @@ -447,13 +446,17 @@ namespace stdx { void resize(size_t count, const T& value) { - if (count < size()) { + if (count < size()) + { _DestroyRange(xpointer_add(_MyFirst, count).get(), _MyLast.get()); _MyLast = xpointer_add(_MyFirst, count); } - else if (count > size()) { + else if (count > size()) + { reserve(count); - while (_MyLast.get() != xpointer_add(_MyFirst, count).get()) { + + while (_MyLast.get() != xpointer_add(_MyFirst, count).get()) + { new (_MyLast.get()) T(value); _MyLast = xpointer_add(_MyLast, 1); } @@ -511,5 +514,4 @@ namespace stdx { { return !(lhs < rhs); } - } diff --git a/MarathonRecomp/patches/player_patches.cpp b/MarathonRecomp/patches/player_patches.cpp index 0d3a7d8ae..e39b8f3f5 100644 --- a/MarathonRecomp/patches/player_patches.cpp +++ b/MarathonRecomp/patches/player_patches.cpp @@ -82,9 +82,9 @@ bool MidairSnowboardControl() } // Add missing SetupModuleDebug to table. -void DebugPlayerSwitch(PPCRegister& str, PPCRegister& index) +void PlayerDebugMode_RegisterLuaSetup(PPCRegister& str, PPCRegister& index) { - if (!Config::DebugSwitch) + if (!Config::PlayerDebugMode) return; auto pString = (stdx::string*)g_memory.Translate(str.u32); @@ -105,24 +105,26 @@ void DebugPlayerSwitch(PPCRegister& str, PPCRegister& index) } } -bool DebugPlayerSwitchPostureSwitchButton(PPCRegister& r_PadState, PPCRegister& r_out) +bool PlayerDebugMode_RemapDebugExitButton(PPCRegister& r_PadState, PPCRegister& r_out) { auto pPadState = (Sonicteam::SoX::Input::PadState*)(g_memory.Translate(r_PadState.u32)); + return pPadState->IsPressed(Sonicteam::SoX::Input::KeyState_Select); } +// Sonicteam::Player::Object::Update PPC_FUNC_IMPL(__imp__sub_82195500); PPC_FUNC(sub_82195500) { - if (!Config::DebugSwitch) + if (!Config::PlayerDebugMode) { __imp__sub_82195500(ctx, base); return; } auto pPlayer = (Sonicteam::Player::Object*)(base + ctx.r3.u32); - auto pDoc = App::s_pApp->m_pDoc; auto pZock = pPlayer->GetPlugin("zock"); + auto pDoc = App::s_pApp->m_pDoc; if (auto pGameMode = pDoc->GetDocMode()) { @@ -131,22 +133,28 @@ PPC_FUNC(sub_82195500) auto playerIndex = pGameMode->m_pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID); auto& spManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[playerIndex]]; + // Disable camera volume collision on B press. if (pPlayer->m_SetupModuleIndexPostfix == 2 && spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_B)) { - auto pValue = (pZock->m_pPhantom->m_pRigidBody->m_collidable.m_BroadPhaseHandle.m_CollisionFilter = pZock->m_pPhantom->m_pRigidBody->m_collidable.m_BroadPhaseHandle.m_CollisionFilter.get() == 6) ? 0x383 : 6; - - pZock->m_pPhantom.reset(); - pZock->m_pPhantomB.reset(); + auto value = pZock->m_spPhantomA->m_pRigidBody->m_collidable.m_broadPhaseHandle.m_collisionFilterInfo == 6 ? 0x383 : 6; - GuestToHostFunction(sub_821E3628, &pZock->m_pPhantom, &pPlayer->m_spRootFrame, static_cast(pPlayer), pValue, 50.0); + pZock->m_spPhantomA.reset(); + pZock->m_spPhantomB.reset(); - pZock->m_pPhantomB = pZock->m_pPhantom; - pZock->m_pPhantom->InitializeToWorld(pGameMode->m_pGameImp->m_spPhysicsWorld); - pZock->m_pPhantom->SetPhantomListener(pZock->m_spPhantomListener); + GuestToHostFunction(sub_821E3628, &pZock->m_spPhantomA, &pPlayer->m_spRootFrame, static_cast(pPlayer), value, 50.0); + + pZock->m_spPhantomB = pZock->m_spPhantomA; + pZock->m_spPhantomA->InitializeToWorld(pGameMode->m_pGameImp->m_spPhysicsWorld); + pZock->m_spPhantomA->SetPhantomListener(pZock->m_spPhantomListener); } - if (pPlayer->m_SetupModuleIndexPostfix != 2 && !(pPlayer->m_SetupModuleIndexPrefix == 2 && pPlayer->m_SetupModuleIndexPostfix == 1) && spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_Select)) + // Enter debug posture on Select press. + if (pPlayer->m_SetupModuleIndexPostfix != 2 && + !(pPlayer->m_SetupModuleIndexPrefix == 2 && pPlayer->m_SetupModuleIndexPostfix == 1) && + spManager->m_PadState.IsPressed(Sonicteam::SoX::Input::KeyState_Select)) + { pPlayer->m_SetupModuleIndexPostfix = 2; + } } } diff --git a/MarathonRecomp/user/config_def.h b/MarathonRecomp/user/config_def.h index 16ecddfb5..27e104f49 100644 --- a/MarathonRecomp/user/config_def.h +++ b/MarathonRecomp/user/config_def.h @@ -84,7 +84,7 @@ 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, DebugSwitch, false); +CONFIG_DEFINE_HIDDEN("Codes", bool, PlayerDebugMode, false); CONFIG_DEFINE_HIDDEN("Codes", bool, MidairControlForMachSpeed, false); CONFIG_DEFINE_HIDDEN("Codes", bool, MidairControlForSnowboards, false); diff --git a/MarathonRecompLib/config/Marathon.toml b/MarathonRecompLib/config/Marathon.toml index c4efbba3c..74bb2c5ff 100644 --- a/MarathonRecompLib/config/Marathon.toml +++ b/MarathonRecompLib/config/Marathon.toml @@ -196,12 +196,12 @@ address = 0x8260D7E0 registers = ["r26"] [[midasm_hook]] -name = "DebugPlayerSwitch" +name = "PlayerDebugMode_RegisterLuaSetup" address = 0x82195AD0 registers = ["r5", "r27"] [[midasm_hook]] -name = "DebugPlayerSwitchPostureSwitchButton" +name = "PlayerDebugMode_RemapDebugExitButton" address = 0x82221CA8 registers = ["r30","r11"] jump_address_on_true = 0x82221CAC