Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion MarathonRecomp/api/Marathon.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Sonicteam/Enemy/EnemyShot.h"
#include "Sonicteam/Enemy/EnemyShotNormal.h"
#include "Sonicteam/Enemy/EnemyShotPoint.h"
#include "Sonicteam/Fixture.h"
#include "Sonicteam/GameImp.h"
#include "Sonicteam/GameMode.h"
#include "Sonicteam/Globals.h"
Expand All @@ -52,8 +53,9 @@
#include "Sonicteam/MainDisplayTask.h"
#include "Sonicteam/MainMenuTask.h"
#include "Sonicteam/MainMode.h"
#include "Sonicteam/Message/MsgSuckPlayer.h"
#include "Sonicteam/Message/MsgCameramanCameraMode.h"
#include "Sonicteam/Message/MsgObjJump123GetNextPoint.h"
#include "Sonicteam/Message/MsgSuckPlayer.h"
#include "Sonicteam/MessageWindowTask.h"
#include "Sonicteam/MovieObject.h"
#include "Sonicteam/MovieObjectWmv.h"
Expand Down
17 changes: 17 additions & 0 deletions MarathonRecomp/api/Sonicteam/Fixture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <Marathon.inl>
#include <Sonicteam/Actor.h>
#include <Sonicteam/SoX/Math/Quaternion.h>
#include <Sonicteam/SoX/Math/Vector.h>

namespace Sonicteam
{
class Fixture : public Actor
{
public:
Sonicteam::SoX::Math::Quaternion m_Rotation;
Sonicteam::SoX::Math::Vector m_Position;
MARATHON_INSERT_PADDING(0xF0);
};
}
8 changes: 6 additions & 2 deletions MarathonRecomp/api/Sonicteam/GameImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
#include <Sonicteam/SoX/Scenery/Camera.h>
#include <Sonicteam/SoX/Scenery/CameraImp.h>
#include <Sonicteam/SoX/RefSharedPointer.h>
#include <Sonicteam/SoX/RefCountObject.h>
#include <stdx/vector.h>

namespace Sonicteam
{
class ActorManager; // Gauge patch
class GameScript;
class GameImp : public SoX::MessageReceiver
{
public:
Expand Down Expand Up @@ -57,7 +58,10 @@ namespace Sonicteam
bool m_IsStage;
MARATHON_INSERT_PADDING(0x0C);
be<uint32_t> m_Field1180;
MARATHON_INSERT_PADDING(0x54);
xpointer<GameScript> m_pGameScript;
be<uint32_t> m_aObjPlayerActorID[0xF];
boost::shared_ptr<ActorManager> m_spActorManager;
MARATHON_INSERT_PADDING(0xC);
stdx::vector<stdx::vector<boost::shared_ptr<SoX::Scenery::Camera>>> m_vvspCameras;
MARATHON_INSERT_PADDING(0x7D4);
SoX::RefSharedPointer<SoX::Physics::World> m_spPhysicsWorld;
Expand Down
14 changes: 14 additions & 0 deletions MarathonRecomp/api/Sonicteam/Message/MsgObjJump123GetNextPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <Marathon.inl>
#include <Sonicteam/SoX/Math/Vector.h>
#include <Sonicteam/SoX/Message.h>

namespace Sonicteam::Message
{
struct MsgObjJump123GetNextPoint : SoX::Message<0x10007>
{
Sonicteam::SoX::Math::Quaternion m_Rotation;
Sonicteam::SoX::Math::Vector m_Position;
};
}
2 changes: 1 addition & 1 deletion MarathonRecomp/api/Sonicteam/Player/RootFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Sonicteam::Player
public:
SoX::Math::Matrix4x4 m_Field70;
SoX::Math::Matrix4x4 m_FieldB0;
SoX::Math::Vector m_FieldF0;
SoX::Math::Vector m_PositionF0;
SoX::Math::Vector m_Field100;
SoX::Math::Vector m_Impulse;
MARATHON_INSERT_PADDING(0x30);
Expand Down
9 changes: 9 additions & 0 deletions MarathonRecomp/api/Sonicteam/SoX/Math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ namespace Sonicteam::SoX::Math
{
return { X + addend, Y + addend, Z + addend, W + addend };
}

float DistanceTo(const Vector& other) const
{
float dx = static_cast<float>(X) - static_cast<float>(other.X);
float dy = static_cast<float>(Y) - static_cast<float>(other.Y);
float dz = static_cast<float>(Z) - static_cast<float>(other.Z);

return std::sqrt(dx * dx + dy * dy + dz * dz);
}
};
}
2 changes: 1 addition & 1 deletion MarathonRecomp/api/Sonicteam/SoX/MessageReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Sonicteam::SoX

bool OnMessageReceived(IMessage* pMessage)
{
return GuestToHostFunction<uint32_t>(m_pVftable->fpOnMessageReceived, this, pMessage);
return GuestToHostFunction<bool>(m_pVftable->fpOnMessageReceived, this, pMessage);
}
};
}
85 changes: 38 additions & 47 deletions MarathonRecomp/patches/player_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,66 +204,57 @@ void RestoreChaosBoostJump(PPCRegister& r10, PPCRegister& r11)
r11.u32 = 2;
}

bool RestoreChainJumpFlips1(PPCRegister& f3, PPCRegister& r1)
void RestoreChainJumpFlips(PPCRegister& r_ObjectPlayer, PPCRegister& r_Message, PPCRegister& r_ObjectContext, PPCRegister& f1, PPCRegister& f2, PPCRegister& f3)
{
if (Config::RestoreChainJumpFlips)
{
auto base = g_memory.base;

PPCRegister temp{};
temp.u32 = PPC_LOAD_U32(r1.u32 + 0x7C);
f3.f64 = double(temp.f32);

return true;
}

return false;
}
if (!Config::RestoreChainJumpFlips)
return;

bool RestoreChainJumpFlips2(PPCRegister& r10, PPCRegister& r11)
{
if (Config::RestoreChainJumpFlips)
struct Message0x11047
{
auto base = g_memory.base;

PPC_STORE_U32(r10.u32 + 0x44, r11.u32);
be<uint32_t> m_id;
Sonicteam::SoX::Math::Quaternion m_rotation;
Sonicteam::SoX::Math::Vector m_position;
be<uint32_t> m_ActorID;
};

auto pObjectPlayer = static_cast<Sonicteam::Player::Object *>(g_memory.Translate(r_ObjectPlayer.u32));
auto pMessage = static_cast<Message0x11047 *>(g_memory.Translate(r_Message.u32));
auto pObjectContext = static_cast<Sonicteam::Player::State::ICommonContext *>(g_memory.Translate(r_ObjectContext.u32));
auto speedHorizontal = f1.f64;
auto speedForward = f2.f64;

auto point = pObjectPlayer->m_spRootFrame->m_PositionF0;
auto target = pMessage->m_position;

if (pMessage->m_ActorID.get() != -1)
{
auto pFixture = GuestToHostFunction<Sonicteam::Fixture*>(sub_821609D0,App::s_pApp->m_pDoc->GetDocMode<Sonicteam::GameMode>()->m_pGameImp->m_spActorManager.get(), &pMessage->m_ActorID);
auto sMessage = guest_stack_var<Sonicteam::Message::MsgObjJump123GetNextPoint>();
sMessage->m_Rotation = { 0, 0, 0, 1 };
sMessage->m_Position = { 0, 0, 0, 1 };

return true;
if (pFixture->OnMessageReceived(sMessage))
{
target = sMessage->m_Position;
}
}

return false;
}
auto distance = point.DistanceTo(target);
double combinedSpeed = std::sqrt(speedHorizontal * speedHorizontal + speedForward * speedForward);
double timeValue = 1.0; // Default fallback

bool RestoreChainJumpFlips3(PPCRegister& f31, PPCRegister& r11)
{
if (Config::RestoreChainJumpFlips)
if (distance > 0.0 && combinedSpeed > 0.0)
{
auto base = g_memory.base;

PPCRegister temp{};
temp.f32 = float(f31.f64);
PPC_STORE_U32(r11.u32 + 0x44, temp.u32);

return true;
timeValue = distance / combinedSpeed;
}

return false;
}

bool RestoreChainJumpFlips4(PPCRegister& f0, PPCRegister& r11)
{
if (Config::RestoreChainJumpFlips)
// CommonContext has a slightly different algorithm to process chain flips
if (reinterpret_cast<Sonicteam::Player::IPlugIn*>(pObjectContext)->m_pVftable.get() != g_memory.Translate(0x8200A728))
{
auto base = g_memory.base;

PPCRegister temp{};
temp.f32 = float(f0.f64);
PPC_STORE_U32(r11.u32 + 0x44, temp.u32);

return true;
timeValue *= 0.35;
}

return false;
f3.f64 = timeValue;
}

bool DisablePushState()
Expand Down
25 changes: 3 additions & 22 deletions MarathonRecompLib/config/Marathon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -418,28 +418,9 @@ address = 0x821A6988
registers = ["r10", "r11"]

[[midasm_hook]]
name = "RestoreChainJumpFlips1"
address = 0x82199650
registers = ["f3", "r1"]
jump_address_on_true = 0x82199654

[[midasm_hook]]
name = "RestoreChainJumpFlips2"
address = 0x82209B74
registers = ["r10", "r11"]
jump_address_on_true = 0x82209B78

[[midasm_hook]]
name = "RestoreChainJumpFlips3"
address = 0x8220C0BC
registers = ["f31", "r11"]
jump_address_on_true = 0x8220C0C0

[[midasm_hook]]
name = "RestoreChainJumpFlips4"
address = 0x822106BC
registers = ["f0", "r11"]
jump_address_on_true = 0x822106C0
name = "RestoreChainJumpFlips"
address = 0x82199654
registers = ["r31","r30","r11","f1", "f2", "f3"]

[[midasm_hook]]
name = "DisablePushState"
Expand Down
Loading