Skip to content

Commit 855c0c6

Browse files
ReimousTHReimousTHIsaacMarovitz
authored
Restore Chainjump behavior EX (#151)
* ChainFlips * Config and Style Fix * Cleanup mess Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * More mess. Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Style + Cleanup Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Final cleanup Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> --------- Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> Co-authored-by: ReimousTH <reimousth@gmail.com> Co-authored-by: Isaac Marovitz <isaacryu@icloud.com>
1 parent 3183c62 commit 855c0c6

10 files changed

Lines changed: 93 additions & 75 deletions

File tree

MarathonRecomp/api/Marathon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "Sonicteam/Enemy/EnemyShot.h"
3434
#include "Sonicteam/Enemy/EnemyShotNormal.h"
3535
#include "Sonicteam/Enemy/EnemyShotPoint.h"
36+
#include "Sonicteam/Fixture.h"
3637
#include "Sonicteam/GameImp.h"
3738
#include "Sonicteam/GameMode.h"
3839
#include "Sonicteam/Globals.h"
@@ -52,8 +53,9 @@
5253
#include "Sonicteam/MainDisplayTask.h"
5354
#include "Sonicteam/MainMenuTask.h"
5455
#include "Sonicteam/MainMode.h"
55-
#include "Sonicteam/Message/MsgSuckPlayer.h"
5656
#include "Sonicteam/Message/MsgCameramanCameraMode.h"
57+
#include "Sonicteam/Message/MsgObjJump123GetNextPoint.h"
58+
#include "Sonicteam/Message/MsgSuckPlayer.h"
5759
#include "Sonicteam/MessageWindowTask.h"
5860
#include "Sonicteam/MovieObject.h"
5961
#include "Sonicteam/MovieObjectWmv.h"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <Marathon.inl>
4+
#include <Sonicteam/Actor.h>
5+
#include <Sonicteam/SoX/Math/Quaternion.h>
6+
#include <Sonicteam/SoX/Math/Vector.h>
7+
8+
namespace Sonicteam
9+
{
10+
class Fixture : public Actor
11+
{
12+
public:
13+
Sonicteam::SoX::Math::Quaternion m_Rotation;
14+
Sonicteam::SoX::Math::Vector m_Position;
15+
MARATHON_INSERT_PADDING(0xF0);
16+
};
17+
}

MarathonRecomp/api/Sonicteam/GameImp.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#include <Sonicteam/SoX/Scenery/Camera.h>
77
#include <Sonicteam/SoX/Scenery/CameraImp.h>
88
#include <Sonicteam/SoX/RefSharedPointer.h>
9-
#include <Sonicteam/SoX/RefCountObject.h>
109
#include <stdx/vector.h>
1110

1211
namespace Sonicteam
1312
{
13+
class ActorManager; // Gauge patch
14+
class GameScript;
1415
class GameImp : public SoX::MessageReceiver
1516
{
1617
public:
@@ -57,7 +58,10 @@ namespace Sonicteam
5758
bool m_IsStage;
5859
MARATHON_INSERT_PADDING(0x0C);
5960
be<uint32_t> m_Field1180;
60-
MARATHON_INSERT_PADDING(0x54);
61+
xpointer<GameScript> m_pGameScript;
62+
be<uint32_t> m_aObjPlayerActorID[0xF];
63+
boost::shared_ptr<ActorManager> m_spActorManager;
64+
MARATHON_INSERT_PADDING(0xC);
6165
stdx::vector<stdx::vector<boost::shared_ptr<SoX::Scenery::Camera>>> m_vvspCameras;
6266
MARATHON_INSERT_PADDING(0x7D4);
6367
SoX::RefSharedPointer<SoX::Physics::World> m_spPhysicsWorld;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <Marathon.inl>
4+
#include <Sonicteam/SoX/Math/Vector.h>
5+
#include <Sonicteam/SoX/Message.h>
6+
7+
namespace Sonicteam::Message
8+
{
9+
struct MsgObjJump123GetNextPoint : SoX::Message<0x10007>
10+
{
11+
Sonicteam::SoX::Math::Quaternion m_Rotation;
12+
Sonicteam::SoX::Math::Vector m_Position;
13+
};
14+
}

MarathonRecomp/api/Sonicteam/Player/RootFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Sonicteam::Player
1414
public:
1515
SoX::Math::Matrix4x4 m_Field70;
1616
SoX::Math::Matrix4x4 m_FieldB0;
17-
SoX::Math::Vector m_FieldF0;
17+
SoX::Math::Vector m_PositionF0;
1818
SoX::Math::Vector m_Field100;
1919
SoX::Math::Vector m_Impulse;
2020
MARATHON_INSERT_PADDING(0x30);

MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,14 @@ namespace Sonicteam::SoX::Math
3131
{
3232
return { X + addend, Y + addend, Z + addend, W + addend };
3333
}
34+
35+
float DistanceTo(const Vector& other) const
36+
{
37+
float dx = static_cast<float>(X) - static_cast<float>(other.X);
38+
float dy = static_cast<float>(Y) - static_cast<float>(other.Y);
39+
float dz = static_cast<float>(Z) - static_cast<float>(other.Z);
40+
41+
return std::sqrt(dx * dx + dy * dy + dz * dz);
42+
}
3443
};
3544
}

MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Sonicteam::SoX
1818

1919
bool OnMessageReceived(IMessage* pMessage)
2020
{
21-
return GuestToHostFunction<uint32_t>(m_pVftable->fpOnMessageReceived, this, pMessage);
21+
return GuestToHostFunction<bool>(m_pVftable->fpOnMessageReceived, this, pMessage);
2222
}
2323
};
2424
}

MarathonRecomp/patches/player_patches.cpp

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -204,66 +204,57 @@ void RestoreChaosBoostJump(PPCRegister& r10, PPCRegister& r11)
204204
r11.u32 = 2;
205205
}
206206

207-
bool RestoreChainJumpFlips1(PPCRegister& f3, PPCRegister& r1)
207+
void RestoreChainJumpFlips(PPCRegister& r_ObjectPlayer, PPCRegister& r_Message, PPCRegister& r_ObjectContext, PPCRegister& f1, PPCRegister& f2, PPCRegister& f3)
208208
{
209-
if (Config::RestoreChainJumpFlips)
210-
{
211-
auto base = g_memory.base;
212-
213-
PPCRegister temp{};
214-
temp.u32 = PPC_LOAD_U32(r1.u32 + 0x7C);
215-
f3.f64 = double(temp.f32);
216-
217-
return true;
218-
}
219-
220-
return false;
221-
}
209+
if (!Config::RestoreChainJumpFlips)
210+
return;
222211

223-
bool RestoreChainJumpFlips2(PPCRegister& r10, PPCRegister& r11)
224-
{
225-
if (Config::RestoreChainJumpFlips)
212+
struct Message0x11047
226213
{
227-
auto base = g_memory.base;
228-
229-
PPC_STORE_U32(r10.u32 + 0x44, r11.u32);
214+
be<uint32_t> m_id;
215+
Sonicteam::SoX::Math::Quaternion m_rotation;
216+
Sonicteam::SoX::Math::Vector m_position;
217+
be<uint32_t> m_ActorID;
218+
};
219+
220+
auto pObjectPlayer = static_cast<Sonicteam::Player::Object *>(g_memory.Translate(r_ObjectPlayer.u32));
221+
auto pMessage = static_cast<Message0x11047 *>(g_memory.Translate(r_Message.u32));
222+
auto pObjectContext = static_cast<Sonicteam::Player::State::ICommonContext *>(g_memory.Translate(r_ObjectContext.u32));
223+
auto speedHorizontal = f1.f64;
224+
auto speedForward = f2.f64;
225+
226+
auto point = pObjectPlayer->m_spRootFrame->m_PositionF0;
227+
auto target = pMessage->m_position;
228+
229+
if (pMessage->m_ActorID.get() != -1)
230+
{
231+
auto pFixture = GuestToHostFunction<Sonicteam::Fixture*>(sub_821609D0,App::s_pApp->m_pDoc->GetDocMode<Sonicteam::GameMode>()->m_pGameImp->m_spActorManager.get(), &pMessage->m_ActorID);
232+
auto sMessage = guest_stack_var<Sonicteam::Message::MsgObjJump123GetNextPoint>();
233+
sMessage->m_Rotation = { 0, 0, 0, 1 };
234+
sMessage->m_Position = { 0, 0, 0, 1 };
230235

231-
return true;
236+
if (pFixture->OnMessageReceived(sMessage))
237+
{
238+
target = sMessage->m_Position;
239+
}
232240
}
233241

234-
return false;
235-
}
242+
auto distance = point.DistanceTo(target);
243+
double combinedSpeed = std::sqrt(speedHorizontal * speedHorizontal + speedForward * speedForward);
244+
double timeValue = 1.0; // Default fallback
236245

237-
bool RestoreChainJumpFlips3(PPCRegister& f31, PPCRegister& r11)
238-
{
239-
if (Config::RestoreChainJumpFlips)
246+
if (distance > 0.0 && combinedSpeed > 0.0)
240247
{
241-
auto base = g_memory.base;
242-
243-
PPCRegister temp{};
244-
temp.f32 = float(f31.f64);
245-
PPC_STORE_U32(r11.u32 + 0x44, temp.u32);
246-
247-
return true;
248+
timeValue = distance / combinedSpeed;
248249
}
249250

250-
return false;
251-
}
252-
253-
bool RestoreChainJumpFlips4(PPCRegister& f0, PPCRegister& r11)
254-
{
255-
if (Config::RestoreChainJumpFlips)
251+
// CommonContext has a slightly different algorithm to process chain flips
252+
if (reinterpret_cast<Sonicteam::Player::IPlugIn*>(pObjectContext)->m_pVftable.get() != g_memory.Translate(0x8200A728))
256253
{
257-
auto base = g_memory.base;
258-
259-
PPCRegister temp{};
260-
temp.f32 = float(f0.f64);
261-
PPC_STORE_U32(r11.u32 + 0x44, temp.u32);
262-
263-
return true;
254+
timeValue *= 0.35;
264255
}
265256

266-
return false;
257+
f3.f64 = timeValue;
267258
}
268259

269260
bool DisablePushState()

MarathonRecompLib/config/Marathon.toml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -418,28 +418,9 @@ address = 0x821A6988
418418
registers = ["r10", "r11"]
419419

420420
[[midasm_hook]]
421-
name = "RestoreChainJumpFlips1"
422-
address = 0x82199650
423-
registers = ["f3", "r1"]
424-
jump_address_on_true = 0x82199654
425-
426-
[[midasm_hook]]
427-
name = "RestoreChainJumpFlips2"
428-
address = 0x82209B74
429-
registers = ["r10", "r11"]
430-
jump_address_on_true = 0x82209B78
431-
432-
[[midasm_hook]]
433-
name = "RestoreChainJumpFlips3"
434-
address = 0x8220C0BC
435-
registers = ["f31", "r11"]
436-
jump_address_on_true = 0x8220C0C0
437-
438-
[[midasm_hook]]
439-
name = "RestoreChainJumpFlips4"
440-
address = 0x822106BC
441-
registers = ["f0", "r11"]
442-
jump_address_on_true = 0x822106C0
421+
name = "RestoreChainJumpFlips"
422+
address = 0x82199654
423+
registers = ["r31","r30","r11","f1", "f2", "f3"]
443424

444425
[[midasm_hook]]
445426
name = "DisablePushState"

0 commit comments

Comments
 (0)