Skip to content

Commit 05b519a

Browse files
author
ReimousTH
committed
ChainFlips
1 parent efafdc7 commit 05b519a

7 files changed

Lines changed: 98 additions & 71 deletions

File tree

MarathonRecomp/api/Marathon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "CSD/Manager/csdmSubjectBase.h"
1717
#include "CSD/Platform/csdTexList.h"
1818
#include "Sonicteam/Actor.h"
19+
#include "Sonicteam/Fixture.h"
1920
#include "Sonicteam/AlertWindowTask.h"
2021
#include "Sonicteam/AppMarathon.h"
2122
#include "Sonicteam/AudioEngineXenon.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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Sonicteam
99
{
10+
class ActorManager; //gauge patch
11+
class GameScript;
1012
class GameImp : public SoX::MessageReceiver
1113
{
1214
public:
@@ -53,7 +55,10 @@ namespace Sonicteam
5355
bool m_IsStage;
5456
MARATHON_INSERT_PADDING(0x0C);
5557
be<uint32_t> m_Field1180;
56-
MARATHON_INSERT_PADDING(0x838);
58+
xpointer<GameScript> m_pGameScript;
59+
be<uint32_t> m_aObjPlayerActorID[0xF];
60+
boost::shared_ptr<ActorManager> m_spActorManager;
61+
MARATHON_INSERT_PADDING(0x7F0);
5762
SoX::RefSharedPointer<SoX::Physics::World> m_spPhysicsWorld;
5863
xpointer<void> m_pMyCollisionFilter;
5964

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,20 @@ namespace Sonicteam::SoX::Math
2626
be<float> Y;
2727
be<float> Z;
2828
be<float> W;
29+
std::string tostring()
30+
{
31+
return std::format("Vector({}, {}, {}, {})",
32+
static_cast<float>(X),
33+
static_cast<float>(Y),
34+
static_cast<float>(Z),
35+
static_cast<float>(W));
36+
}
37+
float distanceTo(const Vector& other) const
38+
{
39+
float dx = static_cast<float>(X) - static_cast<float>(other.X);
40+
float dy = static_cast<float>(Y) - static_cast<float>(other.Y);
41+
float dz = static_cast<float>(Z) - static_cast<float>(other.Z);
42+
return std::sqrt(dx * dx + dy * dy + dz * dz);
43+
}
2944
};
3045
}

MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h

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

33
namespace Sonicteam::SoX
44
{
5-
struct Message;
5+
struct Message
6+
{
7+
};
68

79
class MessageReceiver
810
{
911
public:
1012
struct Vftable
1113
{
14+
be<uint32_t> Destroy;
1215
be<uint32_t> OnMessageRecieved;
1316
};
1417

MarathonRecomp/patches/player_patches.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -198,66 +198,66 @@ void RestoreChaosBoostJump(PPCRegister& r10, PPCRegister& r11)
198198
r11.u32 = 2;
199199
}
200200

201-
bool RestoreChainJumpFlips1(PPCRegister& f3, PPCRegister& r1)
202-
{
203-
if (Config::RestoreChainJumpFlips)
204-
{
205-
auto base = g_memory.base;
206-
207-
PPCRegister temp{};
208-
temp.u32 = PPC_LOAD_U32(r1.u32 + 0x7C);
209-
f3.f64 = double(temp.f32);
210-
211-
return true;
212-
}
213-
214-
return false;
215-
}
216201

217-
bool RestoreChainJumpFlips2(PPCRegister& r10, PPCRegister& r11)
202+
void RestoreChainJumpFlips1(PPCRegister& r_ObjectPlayer, PPCRegister& r_Message,PPCRegister& r_ObjectContext,PPCRegister& f1, PPCRegister& f2, PPCRegister& f3)
218203
{
219-
if (Config::RestoreChainJumpFlips)
204+
struct Message0x11047
220205
{
221-
auto base = g_memory.base;
222-
223-
PPC_STORE_U32(r10.u32 + 0x44, r11.u32);
224-
225-
return true;
206+
be<uint32_t> m_id;
207+
Sonicteam::SoX::Math::Quaternion m_rotation;
208+
Sonicteam::SoX::Math::Vector m_position;
209+
be<uint32_t> m_ActorID;
210+
};
211+
212+
auto pObjectPlayer = ((Sonicteam::Player::Object*)g_memory.Translate(r_ObjectPlayer.u32));
213+
auto pMessage = ((Message0x11047*)g_memory.Translate(r_Message.u32));
214+
auto pObjectContext = ((Sonicteam::Player::State::ICommonContext*)g_memory.Translate(r_ObjectContext.u32));
215+
auto speed_horizontal = f1.f64;
216+
auto speed_forward = f2.f64;
217+
218+
auto Point = pObjectPlayer->m_spRootFrame->m_PositionF0;
219+
auto Target = pMessage->m_position;
220+
if (pMessage->m_ActorID.get() != -1)
221+
{
222+
auto pFixture = GuestToHostFunction<Sonicteam::Fixture*>(sub_821609D0,App::s_pApp->m_pDoc->GetDocMode<Sonicteam::GameMode>()->m_pGameImp->m_spActorManager.get(), &pMessage->m_ActorID);
223+
struct Message10007:Sonicteam::SoX::Message
224+
{
225+
be<uint32_t> m_id;
226+
Sonicteam::SoX::Math::Quaternion m_Rotation;
227+
Sonicteam::SoX::Math::Vector m_Position;
228+
};
229+
auto sMessage = guest_stack_var<Message10007>();
230+
sMessage->m_id = 0x10007;
231+
sMessage->m_Rotation = { 0,0,0,1 };
232+
sMessage->m_Position = { 0,0,0,1 };
233+
if (pFixture->OnMessageRecieved(sMessage))
234+
{
235+
Target = sMessage->m_Position;
236+
}
226237
}
227-
228-
return false;
229-
}
230-
231-
bool RestoreChainJumpFlips3(PPCRegister& f31, PPCRegister& r11)
232-
{
233-
if (Config::RestoreChainJumpFlips)
238+
auto Distance = Point.distanceTo(Target);
239+
double combined_speed = std::sqrt(speed_horizontal * speed_horizontal + speed_forward * speed_forward);
240+
double time_value = 1.0; // default fallback
241+
if (Distance > 0.0 && combined_speed > 0.0)
234242
{
235-
auto base = g_memory.base;
236-
237-
PPCRegister temp{};
238-
temp.f32 = float(f31.f64);
239-
PPC_STORE_U32(r11.u32 + 0x44, temp.u32);
240-
241-
return true;
243+
time_value = Distance / combined_speed;
244+
/*
245+
printf("PlayerPoint : (%s)\n", Point.tostring().c_str());
246+
printf("TargetPoint : (%s)\n", Target.tostring().c_str());
247+
printf("time_value : %f\n", time_value);
248+
printf("distance : %f\n", Distance);
249+
printf("c_speed_horizontal : %f\n", speed_horizontal);
250+
printf("c_speed_forward : %f\n", speed_forward);
251+
*/
242252
}
243253

244-
return false;
245-
}
246-
247-
bool RestoreChainJumpFlips4(PPCRegister& f0, PPCRegister& r11)
248-
{
249-
if (Config::RestoreChainJumpFlips)
254+
//optional (non fast context)
255+
//CommonContext has a slightly different algorithm to process chain flips
256+
if (reinterpret_cast<Sonicteam::Player::IPlugIn*>(pObjectContext)->m_pVftable.get() != g_memory.Translate(0x8200A728))
250257
{
251-
auto base = g_memory.base;
252-
253-
PPCRegister temp{};
254-
temp.f32 = float(f0.f64);
255-
PPC_STORE_U32(r11.u32 + 0x44, temp.u32);
256-
257-
return true;
258+
time_value *= 0.35;
258259
}
259-
260-
return false;
260+
f3.f64 = time_value;
261261
}
262262

263263
bool DisablePushState()

MarathonRecompLib/config/Marathon.toml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -372,27 +372,13 @@ registers = ["r10", "r11"]
372372

373373
[[midasm_hook]]
374374
name = "RestoreChainJumpFlips1"
375-
address = 0x82199650
376-
registers = ["f3", "r1"]
377-
jump_address_on_true = 0x82199654
375+
address = 0x82199654
376+
registers = ["r31","r30","r11","f1", "f2", "f3"]
378377

379378
[[midasm_hook]]
380379
name = "RestoreChainJumpFlips2"
381-
address = 0x82209B74
382-
registers = ["r10", "r11"]
383-
jump_address_on_true = 0x82209B78
384-
385-
[[midasm_hook]]
386-
name = "RestoreChainJumpFlips3"
387-
address = 0x8220C0BC
388-
registers = ["f31", "r11"]
389-
jump_address_on_true = 0x8220C0C0
390-
391-
[[midasm_hook]]
392-
name = "RestoreChainJumpFlips4"
393-
address = 0x822106BC
394-
registers = ["f0", "r11"]
395-
jump_address_on_true = 0x822106C0
380+
address = 0x82199654
381+
registers = ["r10","r11","r3"]
396382

397383
[[midasm_hook]]
398384
name = "DisablePushState"

0 commit comments

Comments
 (0)