Skip to content

Commit 62ae340

Browse files
committed
DebugPlayerSwitch
1 parent b4062c3 commit 62ae340

10 files changed

Lines changed: 174 additions & 11 deletions

File tree

MarathonRecomp/api/Marathon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@
5858
#include "Sonicteam/SoX/Object.h"
5959
#include "Sonicteam/SoX/Physics/Havok/WorldHavok.h"
6060
#include "Sonicteam/SoX/Physics/World.h"
61+
#include "Sonicteam/SoX/Input/Manager.h"
6162
#include "Sonicteam/SoX/RefCountObject.h"
6263
#include "Sonicteam/System/CreateStatic.h"
6364
#include "Sonicteam/System/Singleton.h"
6465
#include "Sonicteam/TitleTask.h"
6566
#include "boost/smart_ptr/make_shared_object.h"
6667
#include "boost/smart_ptr/shared_ptr.h"
6768
#include "stdx/string.h"
69+
#include "stdx/vector.h"

MarathonRecomp/api/Sonicteam/DocMarathonImp.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
#include <Marathon.inl>
44
#include <Sonicteam/SoX/Engine/Doc.h>
5+
#include <Sonicteam/SoX/Input/Manager.h>
6+
#include <boost/smart_ptr/shared_ptr.h>
7+
#include <api/stdx/vector.h>
8+
59

610
namespace Sonicteam
711
{
812
class DocMarathonImp : public SoX::Engine::Doc
913
{
1014
public:
11-
MARATHON_INSERT_PADDING(0x74);
15+
MARATHON_INSERT_PADDING(0x40);
16+
stdx::vector<boost::shared_ptr<Sonicteam::SoX::Input::Manager>> m_vspInputManager;
17+
MARATHON_INSERT_PADDING(0x24);
1218
bool m_VFrame;
19+
MARATHON_INSERT_PADDING(0x55B58);
20+
be<uint32_t> m_PlayerControllerID[4];
1321
};
1422
}

MarathonRecomp/api/Sonicteam/GameImp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ namespace Sonicteam
3636

3737
template <typename T>
3838
inline T* GetPhysicsWorld();
39+
40+
uint32_t PlayerActorIDToIndex(uint32_t ActorID)
41+
{
42+
for (int i = 0; i < 4; i++)
43+
{
44+
if (m_PlayerData[i].ActorID == ActorID)
45+
return i;
46+
}
47+
return -1;
48+
}
3949
};
4050
}
4151

MarathonRecomp/api/Sonicteam/Player/Object.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ namespace Sonicteam::Player
1010
public:
1111
MARATHON_INSERT_PADDING(0x40);
1212
be<uint32_t> m_PlayerIndex;
13-
MARATHON_INSERT_PADDING(0x48);
13+
MARATHON_INSERT_PADDING(0x2C);
14+
uint8_t isPlayer;
15+
uint8_t isPosture;
16+
uint8_t isAI;
17+
MARATHON_INSERT_PADDING(0x19);
1418
boost::shared_ptr<State::Machine2> m_spStateMachine;
15-
MARATHON_INSERT_PADDING(0x18);
19+
MARATHON_INSERT_PADDING(0x10);
20+
be<uint32_t> m_SetupModuleIndexPre;
21+
be<uint32_t> m_SetupModuleIndexPost;
1622
boost::shared_ptr<IGauge> m_spGauge;
1723
MARATHON_INSERT_PADDING(0x204);
1824

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include <Marathon.inl>
4+
5+
namespace Sonicteam::SoX::Input
6+
{
7+
static const uint32_t XENON_GAMEPAD_BACK = 2048;
8+
struct MGamepad
9+
{
10+
be<uint32_t> wLastButtons;
11+
be<uint32_t> wCLastButtons; // ~wLastButtons
12+
MARATHON_INSERT_PADDING(8);
13+
14+
//Left Stick
15+
be<float> fX1;
16+
be<float> fY1;
17+
be<short> sThumbLX;
18+
be<short> sThumbLY;
19+
20+
//Right Stick
21+
be<float> fX2;
22+
be<float> fY2;
23+
be<short> sThumbRX;
24+
be<short> sThumbRY;
25+
};
26+
27+
class Manager
28+
{
29+
public:
30+
be<uint32_t> m_ControllerID;
31+
MARATHON_INSERT_PADDING(0xC);
32+
MGamepad m_Gamepad;
33+
MARATHON_INSERT_PADDING(0x28);
34+
};
35+
}

MarathonRecomp/api/stdx/string.h

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <kernel/heap.h>
44
#include <kernel/function.h>
55

6+
67
namespace stdx
78
{
89
class string
@@ -56,9 +57,28 @@ namespace stdx
5657
_Myres = 0xF;
5758
_Mysize = 0;
5859
_bx._buffer[0] = '\0';
60+
from_cstr(str);
61+
}
5962

60-
auto len = strlen(str);
63+
~string()
64+
{
65+
cleanup();
66+
_Myres = 0xF;
67+
_Mysize = 0;
68+
_bx._buffer[0] = '\0';
69+
}
6170

71+
72+
void cleanup()
73+
{
74+
if (!is_short()) {
75+
g_userHeap.Free((void*)_bx._str.get());
76+
}
77+
}
78+
79+
void from_cstr(const char* str)
80+
{
81+
auto len = strlen(str);
6282
if (len <= 0xF)
6383
{
6484
memcpy((void*)&_bx._buffer, str, len + 1);
@@ -68,6 +88,7 @@ namespace stdx
6888
{
6989
if (is_short() || capacity() < len + 1)
7090
{
91+
cleanup();
7192
char* new_buf = g_userHeap.Alloc<char>(len + 1);
7293
memset((void*)(new_buf), 0, len + 1);
7394
memcpy((void*)(new_buf), (const void*)(str), len + 1);
@@ -83,14 +104,10 @@ namespace stdx
83104
}
84105
}
85106

86-
~string()
107+
string& operator=(const char* str)
87108
{
88-
if (!is_short())
89-
g_userHeap.Free((void*)_bx._str.get());
90-
91-
_Myres = 0xF;
92-
_Mysize = 0;
93-
_bx._buffer[0] = '\0';
109+
from_cstr(str);
110+
return *this;
94111
}
95112

96113
bool operator==(const char* str) const

MarathonRecomp/api/stdx/vector.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include <kernel/heap.h>
4+
#include <kernel/function.h>
5+
6+
namespace stdx
7+
{
8+
template <typename Type>
9+
struct vector
10+
{
11+
be<uint32_t> _MyProxy;
12+
xpointer<Type> _MyFirst;
13+
xpointer<Type> _MyLast;
14+
xpointer<Type> _MyEnd;
15+
16+
Type& operator[](uint32_t index)
17+
{
18+
return *(Type*)((uint64_t)_MyFirst.get() + (index * sizeof(Type)));
19+
}
20+
size_t size()
21+
{
22+
return (_MyLast.ptr.get() - _MyFirst.ptr.get()) / sizeof(Type);
23+
}
24+
};
25+
}

MarathonRecomp/patches/player_patches.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,55 @@ bool MidairSnowboardControl3()
9999
{
100100
return Config::MidairControlForSnowboards;
101101
}
102+
103+
104+
//Add Missing SetupModuleDebug to table
105+
void DebugPlayerSwitch_0(PPCRegister& r_sstring, PPCRegister& r_index)
106+
{
107+
if (!Config::DebugSwitch)
108+
{
109+
return;
110+
}
111+
112+
auto pString = (stdx::string*)(g_memory.Translate(r_sstring.u32));
113+
auto Index = r_index.u32;
114+
switch (Index)
115+
{
116+
case 0:
117+
*pString = "SetupModuleDebug";
118+
break;
119+
case 1:
120+
*pString = "SetupModule";
121+
break;
122+
case 2:
123+
*pString = "SetupModuleDebug";
124+
break;
125+
}
126+
}
127+
128+
PPC_FUNC_IMPL(__imp__sub_82195500);
129+
PPC_FUNC(sub_82195500)
130+
{
131+
if (!Config::DebugSwitch)
132+
{
133+
__imp__sub_82195500(ctx, base);
134+
return;
135+
}
136+
137+
auto pDoc = App::s_pApp->m_pDoc;
138+
auto pGameImp = App::s_pApp->m_pDoc->GetDocMode<Sonicteam::GameMode>()->m_pGameImp;
139+
auto pPlayer = (Sonicteam::Player::Object*)(base + ctx.r3.u32);
140+
141+
142+
if (pPlayer->m_SetupModuleIndexPost != -2 && pPlayer->isPlayer)
143+
{
144+
auto PIndex = pGameImp->PlayerActorIDToIndex(pPlayer->m_ActorID);
145+
auto PManager = pDoc->m_vspInputManager[pDoc->m_PlayerControllerID[PIndex].get()].get();
146+
if ((PManager->m_Gamepad.wLastButtons.get() & Sonicteam::SoX::Input::XENON_GAMEPAD_BACK) != 0)
147+
{
148+
pPlayer->m_SetupModuleIndexPost = 2;
149+
}
150+
}
151+
152+
__imp__sub_82195500(ctx, base);
153+
}

MarathonRecomp/user/config_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ CONFIG_DEFINE_HIDDEN("Codes", bool, DisableLowResolutionFontOnCustomUI, false);
8080
CONFIG_DEFINE_HIDDEN("Codes", bool, RestoreContextualHUDColours, false);
8181
CONFIG_DEFINE_HIDDEN("Codes", bool, DisableEdgeGrabLeftover, false);
8282
CONFIG_DEFINE_HIDDEN("Codes", bool, TailsGauge, false);
83+
CONFIG_DEFINE_HIDDEN("Codes", bool, DebugSwitch, false);
8384
CONFIG_DEFINE_HIDDEN("Codes", bool, MidairControlForMachSpeed, false);
8485
CONFIG_DEFINE_HIDDEN("Codes", bool, MidairControlForSnowboards, false);
8586

MarathonRecompLib/config/Marathon.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,10 @@ registers = ["r4"]
199199
name = "FurtherObjectShadows"
200200
address = 0x8260D7E0
201201
registers = ["r26"]
202+
203+
204+
205+
[[midasm_hook]]
206+
name = "DebugPlayerSwitch_0"
207+
address = 0x82195AD0
208+
registers = ["r5","r27"]

0 commit comments

Comments
 (0)