From 49b0dbe4db4e3dac850ace723c82afdfa6e6090d Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:48:58 +0300 Subject: [PATCH] Auto generate SWA.h, add offsetof/sizeof asserts. --- UnleashedRecomp/CMakeLists.txt | 29 ++++++++++ UnleashedRecomp/api/CSD/Manager/csdmNode.h | 15 +++--- UnleashedRecomp/api/CSD/Manager/csdmNode.inl | 6 +-- UnleashedRecomp/api/SWA.h | 57 ++++++++++---------- UnleashedRecomp/api/SWA.inl | 28 ++++++++-- 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 6fb3e98..14ae843 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -197,3 +197,32 @@ compile_vertex_shader(movie_vs) compile_pixel_shader(resolve_msaa_depth_2x) compile_pixel_shader(resolve_msaa_depth_4x) compile_pixel_shader(resolve_msaa_depth_8x) + +function(generate_aggregate_header INPUT_DIRECTORY OUTPUT_FILE) + get_filename_component(ABS_OUTPUT_FILE "${OUTPUT_FILE}" ABSOLUTE) + file(GLOB_RECURSE HEADER_FILES "${INPUT_DIRECTORY}/*.h") + set(HEADER_CONTENT "#pragma once\n\n") + + foreach(HEADER_FILE IN LISTS HEADER_FILES) + get_filename_component(ABS_HEADER_FILE "${HEADER_FILE}" ABSOLUTE) + if (ABS_HEADER_FILE STREQUAL ABS_OUTPUT_FILE) + continue() + endif() + file(RELATIVE_PATH RELATIVE_HEADER_FILE "${INPUT_DIRECTORY}" "${HEADER_FILE}") + string(APPEND HEADER_CONTENT "#include \"${RELATIVE_HEADER_FILE}\"\n") + endforeach() + + if (EXISTS "${OUTPUT_FILE}") + file(READ "${OUTPUT_FILE}" EXISTING_CONTENT) + if (EXISTING_CONTENT STREQUAL HEADER_CONTENT) + return() + endif() + endif() + + file(WRITE "${OUTPUT_FILE}" "${HEADER_CONTENT}") +endfunction() + +generate_aggregate_header( + "${CMAKE_CURRENT_SOURCE_DIR}/api" + "${CMAKE_CURRENT_SOURCE_DIR}/api/SWA.h" +) diff --git a/UnleashedRecomp/api/CSD/Manager/csdmNode.h b/UnleashedRecomp/api/CSD/Manager/csdmNode.h index 08942f7..e4d6b53 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmNode.h +++ b/UnleashedRecomp/api/CSD/Manager/csdmNode.h @@ -1,10 +1,11 @@ #pragma once -#include "SWA.inl" -#include "CSD/Manager/csdmBase.h" -#include "CSD/Manager/csdmResourceBase.h" -#include "CSD/Manager/csdmNodeObserver.h" -#include "CSD/Manager/csdmSubjectBase.h" +#include +#include +#include +#include +#include +#include namespace Chao::CSD { @@ -21,7 +22,7 @@ namespace Chao::CSD void SetText(const char* in_pText); void SetText(const wchar_t* in_pText); - Hedgehog::Math::CVector2* GetPosition() const; + void GetPosition(Hedgehog::Math::CVector2& out_rResult) const; void SetPosition(float in_X, float in_Y); void SetHideFlag(uint32_t in_HideFlag); void SetRotation(float in_Rotation); @@ -30,4 +31,4 @@ namespace Chao::CSD }; } -#include "CSD/Manager/csdmNode.inl" +#include diff --git a/UnleashedRecomp/api/CSD/Manager/csdmNode.inl b/UnleashedRecomp/api/CSD/Manager/csdmNode.inl index 92e6407..c420167 100644 --- a/UnleashedRecomp/api/CSD/Manager/csdmNode.inl +++ b/UnleashedRecomp/api/CSD/Manager/csdmNode.inl @@ -17,11 +17,9 @@ namespace Chao::CSD GuestToHostFunction(0x830BF640, this, in_pText); } - inline Hedgehog::Math::CVector2* CNode::GetPosition() const + inline void CNode::GetPosition(Hedgehog::Math::CVector2& out_rResult) const { - guest_stack_var pos; - GuestToHostFunction(0x830BF008, pos.get(), this); - return pos.get(); + GuestToHostFunction(0x830BF008, &out_rResult, this); } inline void CNode::SetPosition(float in_X, float in_Y) diff --git a/UnleashedRecomp/api/SWA.h b/UnleashedRecomp/api/SWA.h index 305f36d..00939ff 100644 --- a/UnleashedRecomp/api/SWA.h +++ b/UnleashedRecomp/api/SWA.h @@ -1,21 +1,5 @@ #pragma once -#include "Hedgehog/Base/hhObject.h" -#include "Hedgehog/Base/System/hhAllocator.h" -#include "Hedgehog/Base/Thread/hhHolder.h" -#include "Hedgehog/Base/Thread/hhHolderBase.h" -#include "Hedgehog/Base/Thread/hhSynchronizedObject.h" -#include "Hedgehog/Base/Thread/hhSynchronizedPtr.h" -#include "Hedgehog/Base/Type/hhSharedString.h" -#include "Hedgehog/Database/System/hhDatabaseData.h" -#include "Hedgehog/Math/Vector2.h" -#include "Hedgehog/MirageCore/Renderable/hhRenderable.h" -#include "Hedgehog/Universe/Engine/hhMessageActor.h" -#include "Hedgehog/Universe/Engine/hhMessageProcess.h" -#include "Hedgehog/Universe/Engine/hhUpdateInfo.h" -#include "Hedgehog/Universe/Engine/hhUpdateUnit.h" -#include "Hedgehog/Universe/Thread/hhParallelJob.h" - #include "CSD/Manager/csdmBase.h" #include "CSD/Manager/csdmMotionPattern.h" #include "CSD/Manager/csdmNode.h" @@ -31,38 +15,57 @@ #include "CSD/Manager/csdmSceneObserver.h" #include "CSD/Manager/csdmSubjectBase.h" #include "CSD/Platform/csdTexList.h" - -#include "SWA/Camera/Camera.h" +#include "Hedgehog/Base/Container/hhVector.h" +#include "Hedgehog/Base/System/hhAllocator.h" +#include "Hedgehog/Base/Thread/hhHolder.h" +#include "Hedgehog/Base/Thread/hhHolderBase.h" +#include "Hedgehog/Base/Thread/hhSynchronizedObject.h" +#include "Hedgehog/Base/Thread/hhSynchronizedPtr.h" +#include "Hedgehog/Base/Type/detail/hhStringHolder.h" +#include "Hedgehog/Base/Type/hhSharedString.h" +#include "Hedgehog/Base/hhObject.h" +#include "Hedgehog/Database/System/hhDatabaseData.h" +#include "Hedgehog/Math/Vector2.h" +#include "Hedgehog/MirageCore/Renderable/hhRenderable.h" +#include "Hedgehog/Universe/Engine/hhMessageActor.h" +#include "Hedgehog/Universe/Engine/hhMessageProcess.h" +#include "Hedgehog/Universe/Engine/hhUpdateInfo.h" +#include "Hedgehog/Universe/Engine/hhUpdateUnit.h" +#include "Hedgehog/Universe/Thread/hhParallelJob.h" #include "SWA/CSD/CsdDatabaseWrapper.h" #include "SWA/CSD/CsdProject.h" #include "SWA/CSD/CsdTexListMirage.h" #include "SWA/CSD/GameObjectCSD.h" +#include "SWA/Camera/Camera.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/Player/Character/EvilSonic/Hud/EvilHudGuide.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/Application.h" +#include "SWA/System/ApplicationD3D9.h" +#include "SWA/System/ApplicationDocument.h" +#include "SWA/System/ApplicationXenon.h" +#include "SWA/System/Game.h" +#include "SWA/System/GameDocument.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/GameMode/Title/TitleMenu.h" +#include "SWA/System/GameMode/Title/TitleStateBase.h" #include "SWA/System/GameObject.h" #include "SWA/System/InputState.h" #include "SWA/System/PadState.h" +#include "SWA/System/World.h" +#include "boost/smart_ptr/make_shared_object.h" +#include "boost/smart_ptr/shared_ptr.h" diff --git a/UnleashedRecomp/api/SWA.inl b/UnleashedRecomp/api/SWA.inl index 3c6261f..22f1117 100644 --- a/UnleashedRecomp/api/SWA.inl +++ b/UnleashedRecomp/api/SWA.inl @@ -4,13 +4,33 @@ #include #include -#define SWA__CONCAT2(x, y) x##y -#define SWA_CONCAT2(x, y) _CONCAT(x, y) +#define SWA_CONCAT2(x, y) x##y +#define SWA_CONCAT(x, y) SWA_CONCAT2(x, y) #define SWA_INSERT_PADDING(length) \ - uint8_t SWA_CONCAT2(pad, __LINE__)[length] + uint8_t SWA_CONCAT(pad, __LINE__)[length] + +#define SWA_ASSERT_OFFSETOF(type, field, offset) \ + static inline swa_assert_offsetof SWA_CONCAT(_, __COUNTER__) + +#define SWA_ASSERT_SIZEOF(type, size) \ + static inline swa_assert_sizeof SWA_CONCAT(_, __COUNTER__) #define SWA_VIRTUAL_FUNCTION(returnType, virtualIndex, ...) \ GuestToHostFunction(*(be*)(g_memory.Translate(*(be*)(this) + (4 * virtualIndex))), __VA_ARGS__) -struct swa_null_ctor {}; +struct swa_null_ctor +{ +}; + +template +struct swa_assert_offsetof +{ + static_assert(TActual == TExpected, "offsetof assertion failed"); +}; + +template +struct swa_assert_sizeof +{ + static_assert(TActual == TExpected, "sizeof assertion failed"); +};