diff --git a/UnleashedRecomp/api/CSD/Manager/csdmBase.h b/UnleashedRecomp/api/CSD/Manager/csdmBase.h index 39eff13d..d2ffca59 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmBase.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmBase.h @@ -2,7 +2,5 @@ namespace Chao::CSD { - class CBase - { - }; + class CBase {}; } diff --git a/UnleashedRecomp/api/CSD/Manager/csdmMotionPattern.h b/UnleashedRecomp/api/CSD/Manager/csdmMotionPattern.h new file mode 100644 index 00000000..dd5df27b --- /dev/null +++ b/UnleashedRecomp/api/CSD/Manager/csdmMotionPattern.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace Chao::CSD +{ + class CMotionPattern : CBase {}; +} diff --git a/UnleashedRecomp/api/CSD/Manager/csdmNode.h b/UnleashedRecomp/api/CSD/Manager/csdmNode.h index 3bba6c33..08942f7a 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmNode.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmNode.h @@ -13,13 +13,15 @@ namespace Chao::CSD class CNode : public CResourceBase, SubjectBase, CBase { public: - SWA_INSERT_PADDING(0x4C); + SWA_INSERT_PADDING(0x34); + xpointer m_pMotionPattern; + SWA_INSERT_PADDING(0x18); - ~CNode() override = default; + ~CNode(); void SetText(const char* in_pText); void SetText(const wchar_t* in_pText); - Hedgehog::Math::CVector2 GetPosition() const; + Hedgehog::Math::CVector2* GetPosition() const; void SetPosition(float in_X, float in_Y); void SetHideFlag(uint32_t in_HideFlag); void SetRotation(float in_Rotation); diff --git a/UnleashedRecomp/api/CSD/Manager/csdmNode.inl b/UnleashedRecomp/api/CSD/Manager/csdmNode.inl index 4cca9069..92e64079 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmNode.inl +++ b/UnleashedRecomp/api/CSD/Manager/csdmNode.inl @@ -2,6 +2,11 @@ namespace Chao::CSD { + inline CNode::~CNode() + { + SWA_VIRTUAL_FUNCTION(void, 0, this); + } + inline void CNode::SetText(const char* in_pText) { GuestToHostFunction(0x830BF640, this, in_pText); @@ -12,11 +17,11 @@ namespace Chao::CSD GuestToHostFunction(0x830BF640, this, in_pText); } - inline Hedgehog::Math::CVector2 CNode::GetPosition() const + inline Hedgehog::Math::CVector2* CNode::GetPosition() const { - Hedgehog::Math::CVector2 position; - GuestToHostFunction(0x830BF008, this, &position); - return position; + guest_stack_var pos; + GuestToHostFunction(0x830BF008, pos.get(), this); + return pos.get(); } inline void CNode::SetPosition(float in_X, float in_Y) diff --git a/UnleashedRecomp/api/CSD/Manager/csdmNodeObserver.h b/UnleashedRecomp/api/CSD/Manager/csdmNodeObserver.h index 19fcf3cb..abfba980 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmNodeObserver.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmNodeObserver.h @@ -6,7 +6,5 @@ namespace Chao::CSD { class CNode; - class CNodeObserver : public CObserverBase - { - }; + class CNodeObserver : public CObserverBase {}; } diff --git a/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.h b/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.h index 1cec107e..63daf398 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.h @@ -8,8 +8,16 @@ namespace Chao::CSD class CObserverBase { public: - SWA_INSERT_PADDING(0x0C); + struct Vftable + { + be m_fpDtor; + }; - virtual ~CObserverBase() = default; + xpointer m_pVftable; + SWA_INSERT_PADDING(0x08); + + ~CObserverBase(); }; } + +#include "CSD/Manager/csdmObserverBase.inl" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.inl b/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.inl new file mode 100644 index 00000000..beeabb4f --- /dev/null +++ b/UnleashedRecomp/api/CSD/Manager/csdmObserverBase.inl @@ -0,0 +1,8 @@ +namespace Chao::CSD +{ + template + inline CObserverBase::~CObserverBase() + { + GuestToHostFunction(m_pVftable->m_fpDtor, this); + } +} diff --git a/UnleashedRecomp/api/CSD/Manager/csdmRCObject.h b/UnleashedRecomp/api/CSD/Manager/csdmRCObject.h index 81844c64..143dcb07 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmRCObject.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmRCObject.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "CSD/Manager/csdmRCPtrAbs.h" @@ -7,14 +7,22 @@ namespace Chao::CSD class RCPtrAbs::RCObject { public: + struct Vftable + { + be m_fpDtor; + be m_fpDeallocate; + }; + + xpointer m_pVftable; xpointer m_pMemory; be m_RefCount; xpointer m_pDealloctor; be m_eDealloctor; - virtual ~RCObject(); - virtual void Deallocate(void* in_pMemory) = 0; - + ~RCObject(); + void Deallocate(void* in_pMemory); void Release(); }; } + +#include "CSD/Manager/csdmRCObject.inl" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmRCObject.inl b/UnleashedRecomp/api/CSD/Manager/csdmRCObject.inl index f9c7741f..60909972 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmRCObject.inl +++ b/UnleashedRecomp/api/CSD/Manager/csdmRCObject.inl @@ -1,13 +1,14 @@ namespace Chao::CSD { - inline void RCPtrAbs::RCObject::Release() + inline RCPtrAbs::RCObject::~RCObject() { - GuestToHostFunction(0x830BA068, this); + GuestToHostFunction(m_pVftable->m_fpDtor, this); } inline RCPtrAbs::~RCPtrAbs() { - RCObject* pObj = m_pObject; + RCPtrAbs::RCObject* pObj = m_pObject; + m_pObject = nullptr; if (pObj) @@ -21,4 +22,14 @@ namespace Chao::CSD return m_pObject->m_pMemory; } + + inline void RCPtrAbs::RCObject::Deallocate(void* in_pMemory) + { + GuestToHostFunction(m_pVftable->m_fpDeallocate, this, in_pMemory); + } + + inline void RCPtrAbs::RCObject::Release() + { + GuestToHostFunction(0x830BA068, this); + } } diff --git a/UnleashedRecomp/api/CSD/Manager/csdmRCObjectImp.h b/UnleashedRecomp/api/CSD/Manager/csdmRCObjectImp.h index c21987d8..aa814cfa 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmRCObjectImp.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmRCObjectImp.h @@ -5,8 +5,5 @@ namespace Chao::CSD { template - class RCPtr::RCObjectImp : public RCObject - { - void Deallocate(void* in_pMemory) override; - }; + class RCPtr::RCObjectImp : public RCObject {}; } diff --git a/UnleashedRecomp/api/CSD/Manager/csdmRCPtr.h b/UnleashedRecomp/api/CSD/Manager/csdmRCPtr.h index a4a3caf5..10878100 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmRCPtr.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmRCPtr.h @@ -15,8 +15,6 @@ namespace Chao::CSD RCPtr(const RCPtr& in_rOther) : RCPtrAbs(in_rOther) {} RCPtr(RCPtr&& in_rOther) : RCPtrAbs(std::move(in_rOther)) {} - RCObject* CreateRCObject() override; - void Attach(T* in_pObject); T* Get() const; @@ -30,3 +28,5 @@ namespace Chao::CSD operator bool() const; }; } + +#include "CSD/Manager/csdmRCPtr.inl" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.h b/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.h index 429df724..e1e46be8 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.h @@ -9,6 +9,13 @@ namespace Chao::CSD public: class RCObject; + struct Vftable + { + be m_fpDtor; + be m_fpCreateRCObject; + }; + + xpointer m_pVftable; xpointer m_pObject; RCPtrAbs(); @@ -16,8 +23,8 @@ namespace Chao::CSD RCPtrAbs(const RCPtrAbs& in_rOther); RCPtrAbs(RCPtrAbs&& in_rPtr); - virtual ~RCPtrAbs(); - virtual RCObject* CreateRCObject() = 0; + ~RCPtrAbs(); + RCObject* CreateRCObject(); void AttachAbs(void* in_pMemory); void* GetAbs() const; @@ -31,3 +38,5 @@ namespace Chao::CSD operator bool() const; }; } + +#include "CSD/Manager/csdmRCPtrAbs.inl" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.inl b/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.inl index c6d68674..2925fc54 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.inl +++ b/UnleashedRecomp/api/CSD/Manager/csdmRCPtrAbs.inl @@ -20,6 +20,11 @@ namespace Chao::CSD in_rPtr.m_pObject = nullptr; } + inline RCPtrAbs::RCObject* RCPtrAbs::CreateRCObject() + { + return GuestToHostFunction(m_pVftable->m_fpCreateRCObject, this); + } + inline void RCPtrAbs::AttachAbs(void* in_pMemory) { GuestToHostFunction(0x830BA298, this, in_pMemory); diff --git a/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.h b/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.h index 089c3048..094ed06f 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.h @@ -8,11 +8,19 @@ namespace Chao::CSD class CResourceBase { public: + struct Vftable + { + be m_fpDtor; + be m_fpCopyResource; + }; + + xpointer m_pVftable; RCPtr m_rcResourceHolder; xpointer m_pResource; - virtual ~CResourceBase() = default; - - virtual void CopyResource(const CResourceBase& in_rOther); + ~CResourceBase(); + void CopyResource(const CResourceBase& in_rOther); }; } + +#include "CSD/Manager/csdmResourceBase.h" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.inl b/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.inl index 923b8073..d459e3c9 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.inl +++ b/UnleashedRecomp/api/CSD/Manager/csdmResourceBase.inl @@ -1,7 +1,13 @@ namespace Chao::CSD { template - void CResourceBase::CopyResource(const CResourceBase& in_rOther) + inline CResourceBase::~CResourceBase() + { + GuestToHostFunction(m_pVftable->m_fpDtor, this); + } + + template + inline void CResourceBase::CopyResource(const CResourceBase& in_rOther) { m_rcResourceHolder = in_rOther.m_rcResourceHolder; m_pResource = in_rOther.m_pResource; diff --git a/UnleashedRecomp/api/CSD/Manager/csdmScene.h b/UnleashedRecomp/api/CSD/Manager/csdmScene.h index d8e683a1..e26f2b91 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmScene.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmScene.h @@ -23,7 +23,7 @@ namespace Chao::CSD class CScene : public CResourceBase, SubjectBase, CBase { public: - SWA_INSERT_PADDING(0x5C); + SWA_INSERT_PADDING(0x60); be m_PrevMotionFrame; be m_MotionFrame; be m_MotionSpeed; @@ -35,24 +35,11 @@ namespace Chao::CSD be m_MotionRepeatType; SWA_INSERT_PADDING(0x2C); - ~CScene() override = default; + ~CScene(); + void Update(float in_DeltaTime = 0.0f); + void Render(void* in_pUnk); - // Update should be called with a delta time of zero - // after making changes to a motion. - - // Example: - // SetMotion("Intro_Anim"); - // SetMotionFrame(0.0); - // m_MotionSpeed = 2.0f; - // Update(0.0f); - - // Changes are not going to be recognized if - // update is not called. - - virtual void Update(float in_DeltaTime = 0.0f); - virtual void Render(void*); - - RCPtr GetNode(const char* in_pName) const; + void GetNode(RCPtr& out_rResult, const char* in_pName); bool SetMotion(const char* in_pName); void SetMotionFrame(float in_MotionFrame); @@ -62,3 +49,5 @@ namespace Chao::CSD void SetScale(float in_X, float in_Y); }; } + +#include "CSD/Manager/csdmScene.inl" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmScene.inl b/UnleashedRecomp/api/CSD/Manager/csdmScene.inl index c045987d..a44a6cda 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmScene.inl +++ b/UnleashedRecomp/api/CSD/Manager/csdmScene.inl @@ -1,10 +1,23 @@ namespace Chao::CSD { - inline RCPtr CScene::GetNode(const char* in_pName) const + inline CScene::~CScene() { - RCPtr rcNode; - GuestToHostFunction(0x830BCCA8, this, rcNode, in_pName); - return rcNode; + SWA_VIRTUAL_FUNCTION(void, 0, this); + } + + inline void CScene::Update(float in_DeltaTime) + { + SWA_VIRTUAL_FUNCTION(void, 2, this, in_DeltaTime); + } + + inline void CScene::Render(void* in_pUnk) + { + SWA_VIRTUAL_FUNCTION(void, 3, this, in_pUnk); + } + + inline void CScene::GetNode(RCPtr& out_rResult, const char* in_pName) + { + GuestToHostFunction(sub_830BCCA8, &out_rResult, this, in_pName); } inline bool CScene::SetMotion(const char* in_pName) diff --git a/UnleashedRecomp/api/CSD/Manager/csdmSceneObserver.h b/UnleashedRecomp/api/CSD/Manager/csdmSceneObserver.h index a238062f..2e6abb2c 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmSceneObserver.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmSceneObserver.h @@ -6,7 +6,5 @@ namespace Chao::CSD { class CScene; - class CSceneObserver : public CObserverBase - { - }; + class CSceneObserver : public CObserverBase {}; } diff --git a/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.h b/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.h index 2570e24c..cb420c30 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.h @@ -8,9 +8,18 @@ namespace Chao::CSD class SubjectBase { public: + struct Vftable + { + be m_fpDtor; + be m_fpGetObservee; + }; + + xpointer m_pVftable; SWA_INSERT_PADDING(0x0C); - virtual ~SubjectBase() = default; - virtual TObservee* GetObservee() const { return nullptr; } + ~SubjectBase(); + TObservee* GetObservee() const; }; } + +#include "CSD/Manager/csdmSubjectBase.inl" diff --git a/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.inl b/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.inl new file mode 100644 index 00000000..9c9b7f8f --- /dev/null +++ b/UnleashedRecomp/api/CSD/Manager/csdmSubjectBase.inl @@ -0,0 +1,14 @@ +namespace Chao::CSD +{ + template + inline SubjectBase::~SubjectBase() + { + GuestToHostFunction(m_pVftable->m_fpDtor, this); + } + + template + inline TObservee* SubjectBase::GetObservee() const + { + return nullptr; + } +} diff --git a/UnleashedRecomp/api/CSD/Platform/csdTexList.h b/UnleashedRecomp/api/CSD/Platform/csdTexList.h index 3f5f162c..88fb7c81 100644 --- a/UnleashedRecomp/api/CSD/Platform/csdTexList.h +++ b/UnleashedRecomp/api/CSD/Platform/csdTexList.h @@ -8,8 +8,16 @@ namespace Chao::CSD class CTexList : public CBase { public: + struct Vftable + { + be m_fpDtor; + }; + + xpointer m_pVftable; RCPtr m_rcData; - virtual ~CTexList() = default; + ~CTexList(); }; } + +#include "CSD/Platform/csdTexList.inl" diff --git a/UnleashedRecomp/api/CSD/Platform/csdTexList.inl b/UnleashedRecomp/api/CSD/Platform/csdTexList.inl new file mode 100644 index 00000000..14835026 --- /dev/null +++ b/UnleashedRecomp/api/CSD/Platform/csdTexList.inl @@ -0,0 +1,7 @@ +namespace Chao::CSD +{ + inline CTexList::~CTexList() + { + GuestToHostFunction(m_pVftable->m_fpDtor, this); + } +} diff --git a/UnleashedRecomp/api/Hedgehog/Base/Type/detail/hhStringHolder.inl b/UnleashedRecomp/api/Hedgehog/Base/Type/detail/hhStringHolder.inl index 235b9426..5fede682 100644 --- a/UnleashedRecomp/api/Hedgehog/Base/Type/detail/hhStringHolder.inl +++ b/UnleashedRecomp/api/Hedgehog/Base/Type/detail/hhStringHolder.inl @@ -20,7 +20,7 @@ namespace Hedgehog::Base const size_t memSize = GetMemorySize(in_Length); const size_t memSizeAligned = GetMemorySizeAligned(in_Length); - SStringHolder* pHolder = (SStringHolder*)__HH_ALLOC(memSizeAligned); + auto pHolder = (SStringHolder*)__HH_ALLOC(memSizeAligned); pHolder->RefCount = 1; pHolder->Length = (uint16_t)in_Length; diff --git a/UnleashedRecomp/api/Hedgehog/Base/Type/hhSharedString.inl b/UnleashedRecomp/api/Hedgehog/Base/Type/hhSharedString.inl index 023bebef..67013585 100644 --- a/UnleashedRecomp/api/Hedgehog/Base/Type/hhSharedString.inl +++ b/UnleashedRecomp/api/Hedgehog/Base/Type/hhSharedString.inl @@ -332,7 +332,7 @@ namespace Hedgehog::Base inline int CSharedString::compare(const CSharedString& in_rOther) const { // TODO: DO NOT PASS BY REFERENCE. - GuestToHostFunction(0x82DFB028, this, &in_rOther); + return GuestToHostFunction(0x82DFB028, this, &in_rOther); } inline CSharedString& CSharedString::operator=(const CSharedString& in_rOther) diff --git a/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.h b/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.h index 7bfdb4f9..8552a514 100644 --- a/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.h +++ b/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.h @@ -15,11 +15,18 @@ namespace Hedgehog::Database class CDatabaseData : public Base::CObject { public: - uint8_t m_Flags; // see EDatabaseDataFlags - SWA_INSERT_PADDING(0x04); // TODO: Base::CSharedString m_TypeAndName; + struct Vftable + { + be m_fpDtor; + be m_fpCheckMadeAll; + }; - virtual ~CDatabaseData() = default; - virtual bool CheckMadeAll(); + xpointer m_pVftable; + uint8_t m_Flags; + Base::CSharedString m_TypeAndName; + + ~CDatabaseData(); + bool CheckMadeAll(); bool IsMadeOne() const; void SetMadeOne(); diff --git a/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.inl b/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.inl index b544a718..7e3e383f 100644 --- a/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.inl +++ b/UnleashedRecomp/api/Hedgehog/Database/System/hhDatabaseData.inl @@ -1,5 +1,10 @@ namespace Hedgehog::Database { + inline CDatabaseData::~CDatabaseData() + { + GuestToHostFunction(m_pVftable->m_fpDtor, this); + } + inline bool CDatabaseData::CheckMadeAll() { return true; diff --git a/UnleashedRecomp/api/Hedgehog/MirageCore/Renderable/hhRenderable.h b/UnleashedRecomp/api/Hedgehog/MirageCore/Renderable/hhRenderable.h index ccca4133..73fd409e 100644 --- a/UnleashedRecomp/api/Hedgehog/MirageCore/Renderable/hhRenderable.h +++ b/UnleashedRecomp/api/Hedgehog/MirageCore/Renderable/hhRenderable.h @@ -8,7 +8,7 @@ namespace Hedgehog::Mirage class CRenderable : public Base::CObject { public: + xpointer m_pVftable; bool m_Enabled; - be m_SortDepth; }; } diff --git a/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhMessageActor.h b/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhMessageActor.h index 978e31de..c7d55493 100644 --- a/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhMessageActor.h +++ b/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhMessageActor.h @@ -9,6 +9,6 @@ namespace Hedgehog::Universe class CMessageActor : public IMessageProcess, public IParallelJob { public: - SWA_INSERT_PADDING(0x7C); + SWA_INSERT_PADDING(0x88); }; } diff --git a/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhUpdateUnit.h b/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhUpdateUnit.h index ac04cda0..64513e66 100644 --- a/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhUpdateUnit.h +++ b/UnleashedRecomp/api/Hedgehog/Universe/Engine/hhUpdateUnit.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "SWA.inl" #include "Hedgehog/Universe/Thread/hhParallelJob.h" @@ -8,15 +8,18 @@ namespace Hedgehog::Universe class CUpdateUnit : public Base::CObject, public IParallelJob { public: - SWA_INSERT_PADDING(0x24); + xpointer m_pVftable; + SWA_INSERT_PADDING(0x20); CUpdateUnit(const swa_null_ctor& nil) : CObject(nil), IParallelJob(nil) {} CUpdateUnit(); - virtual ~CUpdateUnit(); - virtual void ExecuteParallelJob(const SUpdateInfo& in_rUpdateInfo) override; - - virtual void UpdateParallel(const SUpdateInfo& in_rUpdateInfo) {} - virtual void UpdateSerial(const SUpdateInfo& in_rUpdateInfo) {} + // TODO: implement virtual functions. + // virtual ~CUpdateUnit(); + // + // virtual void ExecuteParallelJob(const SUpdateInfo& in_rUpdateInfo) override; + // + // virtual void UpdateParallel(const SUpdateInfo& in_rUpdateInfo) {} + // virtual void UpdateSerial(const SUpdateInfo& in_rUpdateInfo) {} }; } diff --git a/UnleashedRecomp/api/Hedgehog/Universe/Thread/hhParallelJob.h b/UnleashedRecomp/api/Hedgehog/Universe/Thread/hhParallelJob.h index adf23117..60b59be3 100644 --- a/UnleashedRecomp/api/Hedgehog/Universe/Thread/hhParallelJob.h +++ b/UnleashedRecomp/api/Hedgehog/Universe/Thread/hhParallelJob.h @@ -8,11 +8,14 @@ namespace Hedgehog::Universe class IParallelJob { public: + xpointer m_pVftable; + IParallelJob() {} IParallelJob(const swa_null_ctor&) {} - virtual ~IParallelJob() = default; - - virtual void ExecuteParallelJob(const SUpdateInfo& in_rUpdateInfo) = 0; + // TODO: implement virtual functions. + // virtual ~IParallelJob() = default; + // + // virtual void ExecuteParallelJob(const SUpdateInfo& in_rUpdateInfo) = 0; }; } diff --git a/UnleashedRecomp/api/SWA.h b/UnleashedRecomp/api/SWA.h index 555c49c8..305f36d4 100644 --- a/UnleashedRecomp/api/SWA.h +++ b/UnleashedRecomp/api/SWA.h @@ -17,6 +17,7 @@ #include "Hedgehog/Universe/Thread/hhParallelJob.h" #include "CSD/Manager/csdmBase.h" +#include "CSD/Manager/csdmMotionPattern.h" #include "CSD/Manager/csdmNode.h" #include "CSD/Manager/csdmNodeObserver.h" #include "CSD/Manager/csdmObserverBase.h" @@ -36,10 +37,32 @@ #include "SWA/CSD/CsdProject.h" #include "SWA/CSD/CsdTexListMirage.h" #include "SWA/CSD/GameObjectCSD.h" +#include "SWA/HUD/GeneralWindow/GeneralWindow.h" +#include "SWA/HUD/Loading/Loading.h" +#include "SWA/HUD/Pause/HudPause.h" +#include "SWA/HUD/Sonic/HudSonicStage.h" +#include "SWA/Movie/MovieDisplayer.h" +#include "SWA/Movie/MovieManager.h" #include "SWA/Player/Character/EvilSonic/Hud/EvilHudGuide.h" #include "SWA/Player/Character/EvilSonic/EvilSonic.h" #include "SWA/Player/Character/EvilSonic/EvilSonicContext.h" +#include "SWA/Sequence/Unit/SequenceUnitBase.h" +#include "SWA/Sequence/Unit/SequenceUnitPlayMovie.h" +#include "SWA/Sequence/Utility/SequencePlayMovieWrapper.h" +#include "SWA/Sound/Sound.h" +#include "SWA/Sound/SoundBGMActSonic.h" +#include "SWA/Sound/SoundBGMBase.h" +#include "SWA/System/GameMode/Title/TitleMenu.h" +#include "SWA/System/GameMode/Title/TitleStateBase.h" +#include "SWA/System/GameMode/GameMode.h" +#include "SWA/System/GameMode/GameModeStage.h" +#include "SWA/System/GameMode/GameModeStageMovie.h" +#include "SWA/System/Application.h" +#include "SWA/System/ApplicationD3D9.h" +#include "SWA/System/ApplicationXenon.h" #include "SWA/System/ApplicationDocument.h" +#include "SWA/System/Game.h" #include "SWA/System/GameDocument.h" +#include "SWA/System/GameObject.h" #include "SWA/System/InputState.h" #include "SWA/System/PadState.h" diff --git a/UnleashedRecomp/api/SWA.inl b/UnleashedRecomp/api/SWA.inl index b83b15eb..3c6261f8 100644 --- a/UnleashedRecomp/api/SWA.inl +++ b/UnleashedRecomp/api/SWA.inl @@ -1,6 +1,7 @@ #pragma once #include +#include #include #define SWA__CONCAT2(x, y) x##y @@ -9,4 +10,7 @@ #define SWA_INSERT_PADDING(length) \ uint8_t SWA_CONCAT2(pad, __LINE__)[length] +#define SWA_VIRTUAL_FUNCTION(returnType, virtualIndex, ...) \ + GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(this) + (4 * virtualIndex))), __VA_ARGS__) + struct swa_null_ctor {}; diff --git a/UnleashedRecomp/api/SWA/CSD/GameObjectCSD.h b/UnleashedRecomp/api/SWA/CSD/GameObjectCSD.h index 834fbb57..5049fdb0 100644 --- a/UnleashedRecomp/api/SWA/CSD/GameObjectCSD.h +++ b/UnleashedRecomp/api/SWA/CSD/GameObjectCSD.h @@ -14,7 +14,7 @@ namespace SWA class CGameObjectCSD : public CGameObject { public: + xpointer m_pVftable; Chao::CSD::RCPtr m_rcProject; - SWA_INSERT_PADDING(0x38); }; } diff --git a/UnleashedRecomp/api/SWA/Camera/Camera.h b/UnleashedRecomp/api/SWA/Camera/Camera.h index 7737d9cb..1d3db6c6 100644 --- a/UnleashedRecomp/api/SWA/Camera/Camera.h +++ b/UnleashedRecomp/api/SWA/Camera/Camera.h @@ -1,13 +1,15 @@ #pragma once -#include "SWA.inl" +#include +#include namespace SWA { - class CCamera // : public CGameObject, public Hedgehog::Universe::TStateMachine + class CCamera : public CGameObject // , public Hedgehog::Universe::TStateMachine { public: - SWA_INSERT_PADDING(0x184); + xpointer m_pVftable; + SWA_INSERT_PADDING(0xC4); be m_VertAspectRatio; SWA_INSERT_PADDING(0x48); be m_HorzAspectRatio; @@ -15,5 +17,8 @@ namespace SWA be m_FieldOfView; be m_VertFieldOfView; be m_HorzFieldOfView; + SWA_INSERT_PADDING(0x18); + bool m_InvertY; + bool m_InvertX; }; } diff --git a/UnleashedRecomp/api/SWA/HUD/GeneralWindow/GeneralWindow.h b/UnleashedRecomp/api/SWA/HUD/GeneralWindow/GeneralWindow.h new file mode 100644 index 00000000..6728eba1 --- /dev/null +++ b/UnleashedRecomp/api/SWA/HUD/GeneralWindow/GeneralWindow.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace SWA +{ + class CGeneralWindow + { + public: + SWA_INSERT_PADDING(0xD0); + Chao::CSD::RCPtr m_rcGeneral; + Chao::CSD::RCPtr m_rcBg; + Chao::CSD::RCPtr m_rcWindow; + Chao::CSD::RCPtr m_rcWindow_2; + Chao::CSD::RCPtr m_rcWindowSelect; + Chao::CSD::RCPtr m_rcFooter; + }; +} diff --git a/UnleashedRecomp/api/SWA/HUD/Loading/Loading.h b/UnleashedRecomp/api/SWA/HUD/Loading/Loading.h new file mode 100644 index 00000000..a70dad0d --- /dev/null +++ b/UnleashedRecomp/api/SWA/HUD/Loading/Loading.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace SWA +{ + enum ELoadingDisplayType + { + eLoadingDisplayType_MilesElectric, + eLoadingDisplayType_None, + eLoadingDisplayType_WerehogMovie, + eLoadingDisplayType_MilesElectricContext, + eLoadingDisplayType_Arrows, + eLoadingDisplayType_NowLoading, + eLoadingDisplayType_EventGallery, + eLoadingDisplayType_ChangeTimeOfDay, + eLoadingDisplayType_Blank + }; + + class CLoading + { + public: + SWA_INSERT_PADDING(0x128); + bool m_IsVisible; + SWA_INSERT_PADDING(0x0C); + be m_LoadingDisplayType; + SWA_INSERT_PADDING(0x65); + bool m_IsNightToDay; + }; +} diff --git a/UnleashedRecomp/api/SWA/HUD/Pause/HudPause.h b/UnleashedRecomp/api/SWA/HUD/Pause/HudPause.h new file mode 100644 index 00000000..f4e67093 --- /dev/null +++ b/UnleashedRecomp/api/SWA/HUD/Pause/HudPause.h @@ -0,0 +1,67 @@ +#pragma once + +#include + +using namespace Chao::CSD; + +namespace SWA +{ + enum EActionType : uint32_t + { + eActionType_Undefined, + eActionType_Status, + eActionType_Return, + eActionType_Inventory, + eActionType_Skills, + eActionType_Lab, + eActionType_Wait, + eActionType_Restart = 8, + eActionType_Continue + }; + + enum EMenuType : uint32_t + { + eMenuType_WorldMap, + eMenuType_Village, + eMenuType_Stage, + eMenuType_Hub, + eMenuType_Misc + }; + + enum EStatusType : uint32_t + { + eStatusType_Idle, + eStatusType_Accept, + eStatusType_Decline + }; + + enum ETransitionType : uint32_t + { + eTransitionType_Undefined, + eTransitionType_Quit = 2, + eTransitionType_Dialog = 5, + eTransitionType_Hide, + eTransitionType_Abort, + eTransitionType_SubMenu + }; + + class CHudPause : public CGameObject + { + public: + xpointer m_pVftable; + SWA_INSERT_PADDING(0x2C); + RCPtr m_rcPause; + RCPtr m_rcBg; + RCPtr m_rcBg1; + RCPtr m_rcBg1_2; + RCPtr m_rcBg1Select; + RCPtr m_rcBg1Select_2; + RCPtr m_rcStatusTitle; + RCPtr m_rcFooterA; + SWA_INSERT_PADDING(0x5C); + be m_Action; + be m_Menu; + be m_Status; + be m_Transition; + }; +} diff --git a/UnleashedRecomp/api/SWA/HUD/Sonic/HudSonicStage.h b/UnleashedRecomp/api/SWA/HUD/Sonic/HudSonicStage.h new file mode 100644 index 00000000..59e2d070 --- /dev/null +++ b/UnleashedRecomp/api/SWA/HUD/Sonic/HudSonicStage.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace SWA +{ + class CHudSonicStage + { + public: + SWA_INSERT_PADDING(0xE0); + Chao::CSD::RCPtr m_rcPlayScreen; + Chao::CSD::RCPtr m_rcSpeedGauge; + Chao::CSD::RCPtr m_rcRingEnergyGauge; + Chao::CSD::RCPtr m_rcGaugeFrame; + SWA_INSERT_PADDING(0x28); + Chao::CSD::RCPtr m_rcScoreCount; + Chao::CSD::RCPtr m_rcTimeCount; + Chao::CSD::RCPtr m_rcTimeCount2; + Chao::CSD::RCPtr m_rcTimeCount3; + Chao::CSD::RCPtr m_rcPlayerCount; + }; +} diff --git a/UnleashedRecomp/api/SWA/Movie/MovieDisplayer.h b/UnleashedRecomp/api/SWA/Movie/MovieDisplayer.h new file mode 100644 index 00000000..64e13e34 --- /dev/null +++ b/UnleashedRecomp/api/SWA/Movie/MovieDisplayer.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace SWA +{ + class CMovieDisplayer : public Hedgehog::Universe::CUpdateUnit, public Hedgehog::Mirage::CRenderable + { + public: + SWA_INSERT_PADDING(0x04); + be m_MovieWidth; + be m_MovieHeight; + }; +} diff --git a/UnleashedRecomp/api/SWA/Movie/MovieManager.h b/UnleashedRecomp/api/SWA/Movie/MovieManager.h new file mode 100644 index 00000000..4de3429e --- /dev/null +++ b/UnleashedRecomp/api/SWA/Movie/MovieManager.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace SWA +{ + class CMovieManager // : Hedgehog::Base::TSingleton + { + public: + static CMovieManager* GetInstance(); + + xpointer m_pVftable; + SWA_INSERT_PADDING(0x330); + }; +} + +#include "SWA/Movie/MovieManager.inl" diff --git a/UnleashedRecomp/api/SWA/Movie/MovieManager.inl b/UnleashedRecomp/api/SWA/Movie/MovieManager.inl new file mode 100644 index 00000000..e9412070 --- /dev/null +++ b/UnleashedRecomp/api/SWA/Movie/MovieManager.inl @@ -0,0 +1,7 @@ +namespace SWA +{ + inline CMovieManager* CMovieManager::GetInstance() + { + return *(xpointer*)MmGetHostAddress(0x8336758C); + } +} diff --git a/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/EvilSonic.h b/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/EvilSonic.h index d6b510ea..bee25d07 100644 --- a/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/EvilSonic.h +++ b/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/EvilSonic.h @@ -5,7 +5,7 @@ namespace SWA::Player { - class CEvilSonic + class CEvilSonic // : public CPlayer { public: SWA_INSERT_PADDING(0xC4); diff --git a/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/Hud/EvilHudGuide.h b/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/Hud/EvilHudGuide.h index 090d5b09..d872fe48 100644 --- a/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/Hud/EvilHudGuide.h +++ b/UnleashedRecomp/api/SWA/Player/Character/EvilSonic/Hud/EvilHudGuide.h @@ -18,12 +18,13 @@ namespace SWA::Player eGuideType_Y }; - class CEvilHudGuide + class CEvilHudGuide : public CGameObject { public: - SWA_INSERT_PADDING(0x14D); + xpointer m_pVftable; + SWA_INSERT_PADDING(0x8D); bool m_IsShown; bool m_IsVisible; - EGuideType m_GuideType; + be m_GuideType; }; } diff --git a/UnleashedRecomp/api/SWA/Sequence/Unit/SequenceUnitBase.h b/UnleashedRecomp/api/SWA/Sequence/Unit/SequenceUnitBase.h new file mode 100644 index 00000000..d45387f2 --- /dev/null +++ b/UnleashedRecomp/api/SWA/Sequence/Unit/SequenceUnitBase.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace SWA::Sequence::Unit +{ + class CUnitBase : public Hedgehog::Base::CObject + { + public: + xpointer m_pVftable; + SWA_INSERT_PADDING(0x14); + }; +} diff --git a/UnleashedRecomp/api/SWA/Sequence/Unit/SequenceUnitPlayMovie.h b/UnleashedRecomp/api/SWA/Sequence/Unit/SequenceUnitPlayMovie.h new file mode 100644 index 00000000..b7f64e36 --- /dev/null +++ b/UnleashedRecomp/api/SWA/Sequence/Unit/SequenceUnitPlayMovie.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace SWA::Sequence::Unit +{ + class CPlayMovieUnit : public CUnitBase {}; +} diff --git a/UnleashedRecomp/api/SWA/Sequence/Utility/SequencePlayMovieWrapper.h b/UnleashedRecomp/api/SWA/Sequence/Utility/SequencePlayMovieWrapper.h index c225c01a..a73c7add 100644 --- a/UnleashedRecomp/api/SWA/Sequence/Utility/SequencePlayMovieWrapper.h +++ b/UnleashedRecomp/api/SWA/Sequence/Utility/SequencePlayMovieWrapper.h @@ -7,16 +7,33 @@ namespace SWA::Sequence::Utility { class CPlayMovieWrapper { + public: class CRender : public Hedgehog::Mirage::CRenderable { - SWA_INSERT_PADDING(0x08); + public: be m_ScreenWidth; be m_ScreenHeight; be m_MovieWidth; be m_MovieHeight; + SWA_INSERT_PADDING(0x74); + be m_TopLeftX; + be m_TopLeftY; + SWA_INSERT_PADDING(0x0C); + be m_TopRightX; + be m_TopRightY; + SWA_INSERT_PADDING(0x0C); + be m_BottomRightX; + be m_BottomRightY; + SWA_INSERT_PADDING(0x0C); + be m_BottomLeftX; + be m_BottomLeftY; + SWA_INSERT_PADDING(0xD4); + bool m_MaintainAspectRatio; + SWA_INSERT_PADDING(0x18); + be m_TimeElapsed; }; SWA_INSERT_PADDING(0x18); - CRender* m_pRender; + xpointer m_pRender; }; } diff --git a/UnleashedRecomp/api/SWA/Sound/Sound.h b/UnleashedRecomp/api/SWA/Sound/Sound.h index f31c82fd..d43c43a7 100644 --- a/UnleashedRecomp/api/SWA/Sound/Sound.h +++ b/UnleashedRecomp/api/SWA/Sound/Sound.h @@ -1,20 +1,56 @@ #pragma once +#include +#include + namespace SWA { - class CSound // : public CGameObject + class CSoundAdministrator : public CGameObject { public: - struct SSoundInfo + class CSimplePlayer {}; + + class CBgm { public: - SWA_INSERT_PADDING(0x04); - xpointer m_pAdminSimplePlayer; - SWA_INSERT_PADDING(0x04); - xpointer m_pAdminBgm; + xpointer m_pThis; + boost::shared_ptr m_spSoundBGM; + be m_Volume1; + be m_Volume2; + be m_Volume3; + be m_Volume4; + SWA_INSERT_PADDING(0x10); }; - SWA_INSERT_PADDING(0xC4); - xpointer m_pSoundInfo; + class CCommunicator + { + public: + class CCommunicatorDevice : Hedgehog::Base::CSynchronizedObject + { + public: + SWA_INSERT_PADDING(0x08); + Hedgehog::Base::CSharedString m_HostName; + SWA_INSERT_PADDING(0x04); + Hedgehog::Base::CSharedString m_Category; + Hedgehog::Base::CSharedString m_Command; + SWA_INSERT_PADDING(0x04); + }; + + xpointer m_pThis; + boost::shared_ptr m_spCommunicatorDevice; + }; + + class CMember + { + public: + boost::shared_ptr m_spSimplePlayer; + boost::shared_ptr m_spBgm; + boost::shared_ptr m_spCommunicator; + SWA_INSERT_PADDING(0x58); + }; + + xpointer m_pVftable; + SWA_INSERT_PADDING(0x04); + xpointer m_pMember; }; } diff --git a/UnleashedRecomp/api/SWA/Sound/SoundBGMActEvil.h b/UnleashedRecomp/api/SWA/Sound/SoundBGMActEvil.h deleted file mode 100644 index c23a3f03..00000000 --- a/UnleashedRecomp/api/SWA/Sound/SoundBGMActEvil.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace SWA -{ - class CSoundBGMActEvil - { - }; -} diff --git a/UnleashedRecomp/api/SWA/Sound/SoundBGMActSonic.h b/UnleashedRecomp/api/SWA/Sound/SoundBGMActSonic.h new file mode 100644 index 00000000..5f3371ac --- /dev/null +++ b/UnleashedRecomp/api/SWA/Sound/SoundBGMActSonic.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace SWA +{ + class CSoundBGMActSonic : public CSoundBGMBase + { + public: + class CMember + { + public: + SWA_INSERT_PADDING(0x58); + be m_Volume1; + be m_Volume2; + }; + + xpointer m_pMember; + }; +} diff --git a/UnleashedRecomp/api/SWA/Sound/SoundBGMBase.h b/UnleashedRecomp/api/SWA/Sound/SoundBGMBase.h new file mode 100644 index 00000000..3f8a7c2f --- /dev/null +++ b/UnleashedRecomp/api/SWA/Sound/SoundBGMBase.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace SWA +{ + class CSoundBGMBase : Hedgehog::Universe::CMessageActor + { + public: + SWA_INSERT_PADDING(0x04); // vftable ptr + SWA_INSERT_PADDING(0x04); + xpointer m_pGameDocument; + bool m_Unk; + }; +} diff --git a/UnleashedRecomp/api/SWA/System/Application.h b/UnleashedRecomp/api/SWA/System/Application.h new file mode 100644 index 00000000..5efd399a --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/Application.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace SWA +{ + class CApplication : public Hedgehog::Base::CObject + { + public: + class CMember + { + public: + xpointer m_pApplicationDocument; + }; + + xpointer m_pVftable; + xpointer m_pMember; + SWA_INSERT_PADDING(0x18); + }; +} diff --git a/UnleashedRecomp/api/SWA/System/ApplicationD3D9.h b/UnleashedRecomp/api/SWA/System/ApplicationD3D9.h new file mode 100644 index 00000000..ef88f297 --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/ApplicationD3D9.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace SWA +{ + class CApplicationD3D9 : public CApplication {}; +} diff --git a/UnleashedRecomp/api/SWA/System/ApplicationDocument.h b/UnleashedRecomp/api/SWA/System/ApplicationDocument.h index 598c4715..6dfdc7da 100644 --- a/UnleashedRecomp/api/SWA/System/ApplicationDocument.h +++ b/UnleashedRecomp/api/SWA/System/ApplicationDocument.h @@ -1,24 +1,54 @@ #pragma once +#include +#include + namespace SWA { - class CApplicationDocument // : public Hedgehog::Base::CSynchronizedObject + enum ELanguage : uint32_t + { + eLanguage_English, + eLanguage_Japanese, + eLanguage_German, + eLanguage_French, + eLanguage_Italian, + eLanguage_Spanish + }; + + enum EVoiceLanguage : uint32_t + { + eVoiceLanguage_English, + eVoiceLanguage_Japanese + }; + + enum ERegion : uint32_t + { + eRegion_Japan, + eRegion_RestOfWorld + }; + + class CApplicationDocument : public Hedgehog::Base::CSynchronizedObject { public: class CMember { public: - SWA_INSERT_PADDING(0x138); - void* m_spGameParameter; + SWA_INSERT_PADDING(0x20); + boost::shared_ptr m_pGame; + SWA_INSERT_PADDING(0x114); + xpointer m_spGameParameter; }; // TODO: Hedgehog::Base::TSynchronizedPtr static CApplicationDocument* GetInstance(); - SWA_INSERT_PADDING(0x04); xpointer m_pMember; - SWA_INSERT_PADDING(0x14); - be m_Region; + be m_Language; + be m_VoiceLanguage; + SWA_INSERT_PADDING(0x08); + be m_Region; + bool m_InspireVoices; + bool m_InspireSubtitles; }; } diff --git a/UnleashedRecomp/api/SWA/System/ApplicationXenon.h b/UnleashedRecomp/api/SWA/System/ApplicationXenon.h new file mode 100644 index 00000000..ed5d6c1c --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/ApplicationXenon.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace SWA +{ + class CApplicationXenon : public CApplicationD3D9 + { + public: + SWA_INSERT_PADDING(0x1B4); + }; +} diff --git a/UnleashedRecomp/api/SWA/System/Game.h b/UnleashedRecomp/api/SWA/System/Game.h new file mode 100644 index 00000000..9e0101ae --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/Game.h @@ -0,0 +1,10 @@ +#pragma once + +namespace SWA +{ + class CGame // : Hedgehog::Universe::TStateMachine + { + public: + SWA_INSERT_PADDING(0xFC); + }; +} diff --git a/UnleashedRecomp/api/SWA/System/GameDocument.h b/UnleashedRecomp/api/SWA/System/GameDocument.h index f4695315..f07c3240 100644 --- a/UnleashedRecomp/api/SWA/System/GameDocument.h +++ b/UnleashedRecomp/api/SWA/System/GameDocument.h @@ -1,7 +1,5 @@ #pragma once -#include "SWA/Sound/Sound.h" - namespace Hedgehog::Database { class CDatabase; @@ -17,8 +15,8 @@ namespace SWA public: SWA_INSERT_PADDING(0x1C); boost::shared_ptr m_spDatabase; - SWA_INSERT_PADDING(0x90); - xpointer m_pSound; + SWA_INSERT_PADDING(0x8C); + xpointer m_pSoundAdministrator; SWA_INSERT_PADDING(0x158); be m_Score; }; @@ -26,7 +24,7 @@ namespace SWA // TODO: Hedgehog::Base::TSynchronizedPtr static CGameDocument* GetInstance(); - SWA_INSERT_PADDING(0x04); + xpointer m_pVftable; xpointer m_pMember; }; } diff --git a/UnleashedRecomp/api/SWA/System/GameMode/GameMode.h b/UnleashedRecomp/api/SWA/System/GameMode/GameMode.h new file mode 100644 index 00000000..5b6c35dc --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/GameMode/GameMode.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace SWA +{ + class CGameMode // : Hedgehog::Universe::TStateMachine::TState + { + public: + SWA_INSERT_PADDING(0x60); // base + SWA_INSERT_PADDING(0x08); + }; +} diff --git a/UnleashedRecomp/api/SWA/System/GameMode/GameModeStage.h b/UnleashedRecomp/api/SWA/System/GameMode/GameModeStage.h new file mode 100644 index 00000000..eeba70c5 --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/GameMode/GameModeStage.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace SWA +{ + class CGameModeStage : public CGameMode + { + public: + xpointer m_pVftable; + SWA_INSERT_PADDING(0x1B4); + }; +} diff --git a/UnleashedRecomp/api/SWA/System/GameMode/GameModeStageMovie.h b/UnleashedRecomp/api/SWA/System/GameMode/GameModeStageMovie.h new file mode 100644 index 00000000..e1a95df4 --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/GameMode/GameModeStageMovie.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace SWA +{ + class CGameModeStageMovie : public CGameModeStage + { + public: + class CRender : public Hedgehog::Mirage::CRenderable + { + public: + xpointer m_pThis; + }; + + xpointer m_pVftable; + SWA_INSERT_PADDING(0x224); + xpointer m_pRender; + }; +} diff --git a/UnleashedRecomp/api/SWA/System/GameMode/Title/TitleMenu.h b/UnleashedRecomp/api/SWA/System/GameMode/Title/TitleMenu.h new file mode 100644 index 00000000..a533e260 --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/GameMode/Title/TitleMenu.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace SWA +{ + class CTitleMenu + { + public: + SWA_INSERT_PADDING(0x44); + be m_CursorIndex; + }; +} diff --git a/UnleashedRecomp/api/SWA/System/GameMode/Title/TitleStateBase.h b/UnleashedRecomp/api/SWA/System/GameMode/Title/TitleStateBase.h new file mode 100644 index 00000000..6782f3b5 --- /dev/null +++ b/UnleashedRecomp/api/SWA/System/GameMode/Title/TitleStateBase.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace SWA +{ + class CTitleStateBase // : Hedgehog::Universe::TStateMachine::TState + { + public: + class CMember + { + public: + SWA_INSERT_PADDING(0x1E8); + xpointer m_pTitleMenu; + }; + + SWA_INSERT_PADDING(0x08); + xpointer m_pMember; + SWA_INSERT_PADDING(0x5C); + be m_State; + }; +} diff --git a/UnleashedRecomp/api/SWA/System/GameObject.h b/UnleashedRecomp/api/SWA/System/GameObject.h index 962c8d15..dd4f7fd1 100644 --- a/UnleashedRecomp/api/SWA/System/GameObject.h +++ b/UnleashedRecomp/api/SWA/System/GameObject.h @@ -18,9 +18,10 @@ namespace SWA public: Hedgehog::Base::TSynchronizedPtr m_pGameDocument; Hedgehog::Base::TSynchronizedPtr m_pWorld; - SWA_INSERT_PADDING(0x78); + SWA_INSERT_PADDING(0x70); }; + xpointer m_pVftable; xpointer m_pMember; }; } diff --git a/UnleashedRecomp/api/SWA/System/InputState.h b/UnleashedRecomp/api/SWA/System/InputState.h index defe936e..b42c67eb 100644 --- a/UnleashedRecomp/api/SWA/System/InputState.h +++ b/UnleashedRecomp/api/SWA/System/InputState.h @@ -5,16 +5,14 @@ namespace SWA { - class CInputState // : public Hedgehog::Base::CSynchronizedObject + class CInputState : public Hedgehog::Base::CSynchronizedObject { public: // TODO: Hedgehog::Base::TSynchronizedPtr static CInputState* GetInstance(); - SPadState m_PadStates[40]; - SWA_INSERT_PADDING(0x50); + SPadState m_PadStates[8]; be m_CurrentPadStateIndex; - SWA_INSERT_PADDING(0x04); const SPadState& GetPadState() const; }; diff --git a/UnleashedRecomp/api/SWA/System/InputState.inl b/UnleashedRecomp/api/SWA/System/InputState.inl index 5eba9408..7b961c4d 100644 --- a/UnleashedRecomp/api/SWA/System/InputState.inl +++ b/UnleashedRecomp/api/SWA/System/InputState.inl @@ -3,7 +3,7 @@ namespace SWA // TODO: Hedgehog::Base::TSynchronizedPtr inline CInputState* CInputState::GetInstance() { - return *(xpointer*)MmGetHostAddress(0x833671EC); + return *(xpointer*)MmGetHostAddress(0x83361F5C); } inline const SPadState& CInputState::GetPadState() const diff --git a/UnleashedRecomp/api/SWA/System/PadState.h b/UnleashedRecomp/api/SWA/System/PadState.h index eca4a5a8..a27df47d 100644 --- a/UnleashedRecomp/api/SWA/System/PadState.h +++ b/UnleashedRecomp/api/SWA/System/PadState.h @@ -43,15 +43,11 @@ namespace SWA struct SPadState { - SWA_INSERT_PADDING(0x20); - be DownState; be UpState; be TappedState; be ReleasedState; - SWA_INSERT_PADDING(0x04); - be LeftStickHorizontal; be LeftStickVertical; @@ -65,7 +61,7 @@ namespace SWA be LeftTrigger; be RightTrigger; - SWA_INSERT_PADDING(0x20); + SWA_INSERT_PADDING(0x08); bool IsDown(const EKeyState in_Keys) const; bool IsUp(const EKeyState in_Keys) const; diff --git a/UnleashedRecomp/api/boost/smart_ptr/shared_ptr.h b/UnleashedRecomp/api/boost/smart_ptr/shared_ptr.h index afe54f20..ecea043a 100644 --- a/UnleashedRecomp/api/boost/smart_ptr/shared_ptr.h +++ b/UnleashedRecomp/api/boost/smart_ptr/shared_ptr.h @@ -5,35 +5,117 @@ namespace boost { + namespace detail + { + class sp_counted_base + { + protected: + struct vftable_t + { + be destructor; + be dispose; + be destroy; + be get_deleter; + }; + + xpointer vftable_; + be use_count_; + be weak_count_; + + public: + // TODO + sp_counted_base() = delete; + + void add_ref() + { + be original, incremented; + do + { + original = use_count_; + incremented = original + 1; + } while (InterlockedCompareExchange((unsigned long*)&use_count_, incremented.value, original.value) != original.value); + } + + void release() + { + be original, decremented; + do + { + original = use_count_; + decremented = original - 1; + } while (InterlockedCompareExchange((unsigned long*)&use_count_, decremented.value, original.value) != original.value); + + if (decremented == 0) + { + GuestToHostFunction(vftable_->dispose, this); + weak_release(); + } + } + + void weak_release() + { + be original, decremented; + do + { + original = weak_count_; + decremented = original - 1; + } while (InterlockedCompareExchange((unsigned long*)&weak_count_, decremented.value, original.value) != original.value); + + if (decremented == 0) + { + GuestToHostFunction(vftable_->destroy, this); + } + } + + uint32_t use_count() const + { + return use_count_; + } + }; + + template< class T > struct sp_dereference + { + typedef T& type; + }; + + template<> struct sp_dereference< void > + { + typedef void type; + }; + } + template class shared_ptr { private: - xpointer m_pObject; - xpointer m_pRefCount; + xpointer px; + xpointer pn; + + void add_ref() + { + if (pn) + pn->add_ref(); + } void release() { - if (m_pRefCount && --(*m_pRefCount) == 0) - { - delete m_pObject; - delete m_pRefCount; - } + if (pn) + pn->release(); } public: - shared_ptr() : m_pObject(nullptr), m_pRefCount(nullptr) {} + shared_ptr() : px(nullptr), pn(nullptr) {} - explicit shared_ptr(T* p) : m_pObject(p), m_pRefCount(new size_t(1)) {} + // TODO + explicit shared_ptr(T* p) = delete; - shared_ptr(const shared_ptr& other) : m_pObject(other.m_pObject), m_pRefCount(other.m_pRefCount) + shared_ptr(const shared_ptr& other) : px(other.px), pn(other.pn) { - if (m_pRefCount) - ++(*m_pRefCount); + add_ref(); } - shared_ptr(shared_ptr&& other) noexcept : m_pObject(std::exchange(other.m_pObject, nullptr)), - m_pRefCount(std::exchange(other.m_pRefCount, nullptr)) {} + shared_ptr(shared_ptr&& other) noexcept : px(std::exchange(other.px, nullptr)), + pn(std::exchange(other.pn, nullptr)) {} ~shared_ptr() { @@ -46,11 +128,10 @@ namespace boost { release(); - m_pObject = other.m_pObject; - m_pRefCount = other.m_pRefCount; + px = other.px; + pn = other.pn; - if (m_pRefCount) - ++(*m_pRefCount); + add_ref(); } return *this; @@ -62,20 +143,22 @@ namespace boost { release(); - m_pObject = std::exchange(other.m_pObject, nullptr); - m_pRefCount = std::exchange(other.m_pRefCount, nullptr); + px = std::exchange(other.px, nullptr); + pn = std::exchange(other.pn, nullptr); } return *this; } - T* get() const { return m_pObject; } + T* get() const { return px; } - T& operator*() const { assert(m_pObject); return *m_pObject; } - T* operator->() const { assert(m_pObject); return m_pObject; } + detail::sp_dereference operator*() const { assert(px); return *px; } + T* operator->() const { assert(px); return px; } - explicit operator bool() const { return m_pObject != nullptr; } + explicit operator bool() const { return px != nullptr; } - size_t use_count() const { return m_pRefCount ? *m_pRefCount : 0; } + size_t use_count() const { return pn ? pn->use_count() : 0; } }; + + using anonymous_shared_ptr = shared_ptr; } diff --git a/UnleashedRecomp/cpu/guest_stack_var.h b/UnleashedRecomp/cpu/guest_stack_var.h new file mode 100644 index 00000000..e4e9406d --- /dev/null +++ b/UnleashedRecomp/cpu/guest_stack_var.h @@ -0,0 +1,123 @@ +#pragma once + +#include "ppc_context.h" +#include + +// DO NOT use this type as anything other than a local variable. +// This includes returning. It'll cause memory to leak in the guest stack! + +template +class guest_stack_var +{ +private: + uint32_t m_ptr = NULL; + uint32_t m_oldStackPtr = NULL; + + void AllocGuestStackMemory() + { + auto ctx = GetPPCContext(); + m_oldStackPtr = ctx->r1.u32; + m_ptr = (ctx->r1.u32 - sizeof(T)) & ~(std::max(alignof(T), 8) - 1); + ctx->r1.u32 = m_ptr; + } + +public: + T* get() + { + return reinterpret_cast(g_memory.Translate(m_ptr)); + } + + const T* get() const + { + return reinterpret_cast(g_memory.Translate(m_ptr)); + } + + template + guest_stack_var(Args&&... args) + { + AllocGuestStackMemory(); + + if (Init) + new (get()) T(std::forward(args)...); + } + + guest_stack_var(const guest_stack_var& other) + { + AllocGuestStackMemory(); + + if (Init) + new (get()) T(*other->get()); + } + + guest_stack_var(guest_stack_var&& other) + { + AllocGuestStackMemory(); + + if (Init) + new (get()) T(std::move(*other->get())); + } + + ~guest_stack_var() + { + get()->~T(); + + auto ctx = GetPPCContext(); + // This assert will fail if the type was used as anything other than a local variable. + assert(ctx->r1.u32 == m_ptr); + ctx->r1.u32 = m_oldStackPtr; + } + + void operator=(const guest_stack_var& other) + { + if (this != &other) + *get() = *other->get(); + } + + void operator=(guest_stack_var&& other) + { + if (this != &other) + *get() = std::move(*other->get()); + } + + void operator=(const T& other) + { + if (get() != &other) + *get() = *other; + } + + void operator=(T&& other) + { + if (get() != &other) + *get() = std::move(*other); + } + + operator const T* () const + { + return get(); + } + + operator T* () + { + return get(); + } + + const T* operator->() const + { + return get(); + } + + T* operator->() + { + return get(); + } + + const T& operator*() const + { + return *get(); + } + + T& operator*() + { + return *get(); + } +}; diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 180c714e..109468e0 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -3831,8 +3831,8 @@ void SetShadowResolutionMidAsmHook(PPCRegister& r11) static void SetResolution(be* device) { - uint32_t width = uint32_t(g_swapChain->getWidth() * Config::ResolutionScale); - uint32_t height = uint32_t(g_swapChain->getHeight() * Config::ResolutionScale); + uint32_t width = uint32_t(round(g_swapChain->getWidth() * Config::ResolutionScale)); + uint32_t height = uint32_t(round(g_swapChain->getHeight() * Config::ResolutionScale)); device[46] = width == 0 ? 880 : width; device[47] = height == 0 ? 720 : height; } diff --git a/UnleashedRecomp/kernel/function.h b/UnleashedRecomp/kernel/function.h index ee41a742..14e88ea7 100644 --- a/UnleashedRecomp/kernel/function.h +++ b/UnleashedRecomp/kernel/function.h @@ -193,10 +193,10 @@ struct Argument int ordinal{}; }; -template -constexpr std::array::value> GatherFunctionArguments() +template +constexpr std::array> GatherFunctionArguments(const T1& tpl) { - std::array::value> args{}; + std::array> args{}; int floatOrdinal{}; size_t i{}; @@ -205,9 +205,9 @@ constexpr std::array::value> GatherFunctionArguments { std::apply([&](const auto& first, const auto&... rest) { - auto append = [&](const T & v) + auto append = [&](const T2& v) { - if constexpr (is_precise_v) + if constexpr (is_precise_v) { args[i] = { 1, floatOrdinal++ }; } @@ -221,12 +221,18 @@ constexpr std::array::value> GatherFunctionArguments append(first); (append(rest), ...); - }, function_args(Func)); + }, tpl); } return args; } +template +constexpr std::array::value> GatherFunctionArguments() +{ + return GatherFunctionArguments(function_args(Func)); +} + template struct arg_ordinal_t { @@ -248,19 +254,19 @@ FORCEINLINE std::enable_if_t<(I < sizeof...(TArgs)), void> _translate_args_to_ho _translate_args_to_host(ctx, base, tpl); } -template +template FORCEINLINE void _translate_args_to_guest(PPCContext& ctx, uint8_t* base, std::tuple&) noexcept requires (I >= sizeof...(TArgs)) { } -template +template FORCEINLINE std::enable_if_t<(I < sizeof...(TArgs)), void> _translate_args_to_guest(PPCContext& ctx, uint8_t* base, std::tuple& tpl) noexcept { using T = std::tuple_element_t>; - ArgTranslator::SetValue(ctx, base, I, std::get(tpl)); + ArgTranslator::SetValue(ctx, base, GatherFunctionArguments(std::tuple{})[I].ordinal, std::get(tpl)); - _translate_args_to_guest(ctx, base, tpl); + _translate_args_to_guest(ctx, base, tpl); } template @@ -301,22 +307,27 @@ FORCEINLINE PPC_FUNC(HostToGuestFunction) } } -template -FORCEINLINE T GuestToHostFunction(uint32_t addr, TArgs... argv) +template +FORCEINLINE T GuestToHostFunction(const TFunction& func, TArgs&&... argv) { - auto args = std::make_tuple(argv...); + auto args = std::make_tuple(std::forward(argv)...); auto& currentCtx = *GetPPCContext(); - auto newCtx = PPCContext{}; + PPCContext newCtx; // NOTE: No need for zero initialization, has lots of unnecessary code generation. newCtx.fn = currentCtx.fn; newCtx.r1 = currentCtx.r1; newCtx.r13 = currentCtx.r13; newCtx.fpscr = currentCtx.fpscr; - _translate_args_to_guest>(newCtx, (uint8_t*)g_memory.base, args); + _translate_args_to_guest(newCtx, (uint8_t*)g_memory.base, args); SetPPCContext(newCtx); - (*(PPCFunc**)(newCtx.fn + uint64_t(addr) * 2))(newCtx, (uint8_t*)g_memory.base); + + if constexpr (std::is_function_v) + func(newCtx, (uint8_t*)g_memory.base); + else + (*(PPCFunc**)(newCtx.fn + uint64_t(func) * 2))(newCtx, (uint8_t*)g_memory.base); + currentCtx.fpscr = newCtx.fpscr; SetPPCContext(currentCtx); diff --git a/UnleashedRecomp/kernel/heap.h b/UnleashedRecomp/kernel/heap.h index 90da8e64..4e583be5 100644 --- a/UnleashedRecomp/kernel/heap.h +++ b/UnleashedRecomp/kernel/heap.h @@ -1,7 +1,6 @@ #pragma once #include "mutex.h" -#include struct Heap { diff --git a/UnleashedRecomp/kernel/memory.h b/UnleashedRecomp/kernel/memory.h index 8cea4c4f..0a1eba22 100644 --- a/UnleashedRecomp/kernel/memory.h +++ b/UnleashedRecomp/kernel/memory.h @@ -16,11 +16,17 @@ public: void* Translate(size_t offset) const noexcept { + if (offset) + assert(offset < 0x100000000ull); + return base + offset; } uint32_t MapVirtual(void* host) const noexcept { + if (host) + assert(host >= base && host < (base + size)); + return static_cast(static_cast(host) - base); } }; diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index 96152f7b..4eabefad 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "framework.h" #include "mutex.h" diff --git a/thirdparty/PowerRecomp b/thirdparty/PowerRecomp index d8676283..7dd4f91a 160000 --- a/thirdparty/PowerRecomp +++ b/thirdparty/PowerRecomp @@ -1 +1 @@ -Subproject commit d8676283fd1e8990b415cc0e4810c6db895b9fba +Subproject commit 7dd4f91ac635b001a56cc7a27af48f0436bbad3f