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
2 changes: 2 additions & 0 deletions MarathonRecomp/api/Marathon.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "Sonicteam/MyPhantom.h"
#include "Sonicteam/MyTexture.h"
#include "Sonicteam/MyTransforms.h"
#include "Sonicteam/NoSyncThread.h"
#include "Sonicteam/Player/IDynamicLink.h"
#include "Sonicteam/Player/IExportExternalFlag.h"
#include "Sonicteam/Player/IExportPostureRequestFlag.h"
Expand Down Expand Up @@ -133,6 +134,7 @@
#include "Sonicteam/SoX/Scenery/CameraEventCallback.h"
#include "Sonicteam/SoX/Scenery/CameraImp.h"
#include "Sonicteam/SoX/Scenery/Drawable.h"
#include "Sonicteam/SoX/Thread.h"
#include "Sonicteam/StdImageFilters/BurnoutBlurFilter.h"
#include "Sonicteam/StdImageFilters/SingleTechniqueFilter.h"
#include "Sonicteam/System/CreateStatic.h"
Expand Down
5 changes: 4 additions & 1 deletion MarathonRecomp/api/Sonicteam/HUDLoading.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ namespace Sonicteam
public:
enum HUDLoadingFlags
{
HUDLoadingFlags_Finished = 6
HUDLoadingFlags_Finished = 6,
HUDLoadingFlags_Open = 0x200,
HUDLoadingFlags_End = 0x400
};

MARATHON_INSERT_PADDING(0x5C);
be<uint32_t> m_Flags;
MARATHON_INSERT_PADDING(8);
};
}
2 changes: 1 addition & 1 deletion MarathonRecomp/api/Sonicteam/HUDMessageWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Sonicteam
public:
xpointer<CsdObject> m_pCsdObject;
MARATHON_INSERT_PADDING(0x1C);
xpointer<HUDMessageWindow> m_pThis;
xpointer<HUDMessageWindow> m_pParent;
MARATHON_INSERT_PADDING(0x14);
xpointer<HintWindowTask> m_pHintWindowTask;
};
Expand Down
9 changes: 9 additions & 0 deletions MarathonRecomp/api/Sonicteam/NoSyncThread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <Marathon.inl>
#include <Sonicteam/SoX/Thread.h>

namespace Sonicteam
{
class NoSyncThread : SoX::Thread {};
}
2 changes: 2 additions & 0 deletions MarathonRecomp/api/Sonicteam/SelectWindowTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ namespace Sonicteam
be<uint32_t> m_ChosenIndex;
MARATHON_INSERT_PADDING(0x28);
be<uint32_t> m_SelectedIndex;
MARATHON_INSERT_PADDING(0x14);
be<uint32_t> m_BreatheFrame;
};
}
2 changes: 1 addition & 1 deletion MarathonRecomp/api/Sonicteam/SoX/Graphics/FrameObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Sonicteam::SoX::Graphics
public:
xpointer<void> m_pVftable;
MARATHON_INSERT_PADDING(8);
xpointer<FrameObserver> m_pThis;
xpointer<FrameObserver> m_pParent;
xpointer<FrameGP> m_pFrameGP;
};
}
2 changes: 1 addition & 1 deletion MarathonRecomp/api/Sonicteam/SoX/Graphics/TechniqueFXL.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Sonicteam::SoX::Graphics
public:
xpointer<void> m_pShader;
MARATHON_INSERT_PADDING(0x10);
xpointer<TechniqueFXL> m_pThis;
xpointer<TechniqueFXL> m_pParent;
MARATHON_INSERT_PADDING(4);
stdx::string m_TechniqueName;
};
Expand Down
4 changes: 2 additions & 2 deletions MarathonRecomp/api/Sonicteam/SoX/Physics/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Sonicteam::SoX::Physics
public:
struct Vftable : public RefCountObject::Vftable
{
be<uint32_t> VFunction04; // (__out VECTOR* u1, __out VECTOR* u2)
be<uint32_t> InitializeVolume;
be<uint32_t> fpVFunction04; // (__out VECTOR* u1, __out VECTOR* u2)
be<uint32_t> fpInitializeVolume;
};

be<uint32_t> m_ShapeType;
Expand Down
4 changes: 2 additions & 2 deletions MarathonRecomp/api/Sonicteam/SoX/RefCountObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Sonicteam::SoX
public:
struct Vftable
{
be<uint32_t> Destroy;
be<uint32_t> fpDestroy;
};

xpointer<Vftable> m_pVftable;
Expand All @@ -30,7 +30,7 @@ namespace Sonicteam::SoX

void* Destroy(uint32_t flag)
{
return GuestToHostFunction<void*>(m_pVftable->Destroy, this, flag);
return GuestToHostFunction<void*>(m_pVftable->fpDestroy, this, flag);
}
};
}
35 changes: 35 additions & 0 deletions MarathonRecomp/api/Sonicteam/SoX/Thread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <Marathon.inl>

namespace Sonicteam::SoX
{
class Thread
{
public:
xpointer<void> m_pVftable;
MARATHON_INSERT_PADDING(8);
xpointer<Thread> m_pParent;
be<uint32_t> m_EventHandleA;
be<uint32_t> m_EventHandleB;
MARATHON_INSERT_PADDING(4);
be<uint32_t> m_ThreadHandle;
bool m_Field20;
MARATHON_INSERT_PADDING(3);
be<float> m_DeltaTime;
MARATHON_INSERT_PADDING(8);
xpointer<const char> m_pName;
MARATHON_INSERT_PADDING(4);
bool m_Field38;
bool m_Field39;
MARATHON_INSERT_PADDING(6);
xpointer<void> m_pContext;
MARATHON_INSERT_PADDING(8);

template <typename T>
T* GetContext()
{
return (T*)m_pContext.get();
}
};
}
5 changes: 5 additions & 0 deletions MarathonRecomp/api/stdx/wstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ namespace stdx
}

bool operator==(const uint16_t* str) const
{
return strcmpU16(c_str(), str, false, true);
}

bool operator==(xpointer<const uint16_t> str) const
{
return strcmpU16(c_str(), str);
}
Expand Down
94 changes: 94 additions & 0 deletions MarathonRecomp/patches/fps_patches.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#include <api/Marathon.h>
#include <user/config.h>

constexpr double REFERENCE_DELTA_TIME = 1.0 / 60.0;

// Only use this in threaded context with fixed delta time!
double MakeDeltaTime(std::chrono::steady_clock::time_point& prev)
{
auto now = std::chrono::steady_clock::now();
auto deltaTime = std::min(std::chrono::duration<double>(now - prev).count(), 1.0 / 15.0);

prev = now;
now = std::chrono::steady_clock::now();

return deltaTime;
}

bool HasFrameElapsed(double reference, double& timeElapsed, double deltaTime)
{
timeElapsed += deltaTime;

if (timeElapsed < reference)
return false;

timeElapsed = 0.0f;

return true;
}

// Sonicteam::SoX::Physics::Havok::WorldHavok::Update
PPC_FUNC_IMPL(__imp__sub_82587AA8);
PPC_FUNC(sub_82587AA8)
Expand Down Expand Up @@ -121,3 +147,71 @@ void PlayerObject_ProcessMsgSuckPlayer_FixDeltaTime(PPCRegister& message, PPCReg

deltaTime.f64 = pMessage->DeltaTime;
}

// Allocate more space to store the previous loading
// time for this instance of Sonicteam::HUDLoading.
void HUDLoadingAlloc(PPCRegister& r3)
{
r3.u32 += sizeof(std::chrono::steady_clock::time_point);
}

// Sonicteam::HUDLoading::HUDLoading
PPC_FUNC_IMPL(__imp__sub_824D7BC8);
PPC_FUNC(sub_824D7BC8)
{
auto pPrevLoadingTime = (std::chrono::steady_clock::time_point*)(base + ctx.r3.u32 + sizeof(Sonicteam::HUDLoading));

*pPrevLoadingTime = {};

__imp__sub_824D7BC8(ctx, base);
}

// Accumulate own delta time and provide it to the CSD update function.
void HUDLoading_DeltaTimeFix(PPCRegister& pThis, PPCRegister& deltaTime)
{
auto pPrevLoadingTime = (std::chrono::steady_clock::time_point*)g_memory.Translate(pThis.u32 + sizeof(Sonicteam::HUDLoading));

deltaTime.f64 = MakeDeltaTime(*pPrevLoadingTime);
}

// This function is an override of Sonicteam::SoX::Engine::Task::Update,
// it does not pass delta time to HUDCALLBACK::Update, so we must preserve
// the register here in order to do it ourselves.
void HUDWindow_PreserveDeltaTime(PPCRegister& f31, PPCRegister& f1)
{
f31.f64 = f1.f64;
}

// HUDCALLBACK::Update doesn't have a delta time argument,
// so we pass one in here to do some delta time accumulation
// safely in the hooks below.
void HUDWindow_Callback(PPCRegister& f1, PPCRegister& f31)
{
f1.f64 = f31.f64;
}

// Sonicteam::PriceListWindowTask::HUDCALLBACK::Update
PPC_FUNC_IMPL(__imp__sub_8250AAB0);
PPC_FUNC(sub_8250AAB0)
{
static auto s_time = 0.0;

// Fix for white ⇄ red text breathing animation.
if (!HasFrameElapsed(REFERENCE_DELTA_TIME, s_time, ctx.f1.f64))
return;

__imp__sub_8250AAB0(ctx, base);
}

// Sonicteam::SelectWindowTask::HUDCALLBACK::Update
PPC_FUNC_IMPL(__imp__sub_8250D698);
PPC_FUNC(sub_8250D698)
{
static auto s_time = 0.0;

// Fix for white ⇄ red text breathing animation.
if (!HasFrameElapsed(REFERENCE_DELTA_TIME, s_time, ctx.f1.f64))
return;

__imp__sub_8250D698(ctx, base);
}
30 changes: 30 additions & 0 deletions MarathonRecompLib/config/Marathon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,33 @@ registers = ["r28", "f1"]
name = "PlayerObject_ProcessMsgSuckPlayer_FixDeltaTime"
address = 0x8219B660
registers = ["r28", "f31"]

[[midasm_hook]]
name = "HUDLoadingAlloc"
address = 0x824FAE14
registers = ["r3"]

[[midasm_hook]]
name = "HUDLoadingAlloc"
address = 0x824FAF60
registers = ["r3"]

[[midasm_hook]]
name = "HUDLoadingAlloc"
address = 0x824FB008
registers = ["r3"]

[[midasm_hook]]
name = "HUDLoading_DeltaTimeFix"
address = 0x824D7510
registers = ["r31", "f1"]

[[midasm_hook]]
name = "HUDWindow_PreserveDeltaTime"
address = 0x824FA03C
registers = ["f31", "f1"]

[[midasm_hook]]
name = "HUDWindow_Callback"
address = 0x824FA088
registers = ["f1", "f31"]
Loading