From 8fd9863e1a3156e20c3e811e5339bacd796d378d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 10 Nov 2020 02:38:49 +0100 Subject: [PATCH] ksys/gdt: Fix "no check, force" setters for vector flags And add the other setters to the CSV. --- data/uking_functions.csv | 47 ++++++----- src/KingSystem/GameData/gdtManager.h | 121 ++++++++++++++++++--------- 2 files changed, 107 insertions(+), 61 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index a0aa839c..88e4568f 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -11003,7 +11003,7 @@ 0x00000071001ab258,sub_71001AB258,856, 0x00000071001ab5b0,sub_71001AB5B0,344, 0x00000071001ab708,sub_71001AB708,384, -0x00000071001ab888,GameDataMgr::setS32ByIdx,196, +0x00000071001ab888,GameDataMgr::setS32ByIdx,196,_ZN4ksys3gdt7Manager6setS32EiNS0_10FlagHandleE 0x00000071001ab94c,sub_71001AB94C,324, 0x00000071001aba90,sub_71001ABA90,316, 0x00000071001abbcc,sub_71001ABBCC,56, @@ -39388,7 +39388,7 @@ 0x0000007100678954,MotorcycleMgr::init,468, 0x0000007100678b28,MotorcycleMgr::clampMotorcycleEnergy,172, 0x0000007100678e80,MotorcycleMgr::updateSpawnMotorcycle,1664, -0x0000007100679500,GameDataMgr::setFloatByIter,196, +0x0000007100679500,GameDataMgr::setFloatByIter,196,_ZN4ksys3gdt7Manager6setF32EfNS0_10FlagHandleE 0x00000071006795c4,MotorcycleMgr::checkUsableForSoundEffectAndMarker,308, 0x00000071006796f8,MotorcycleMgr::hasHavokQueryStarted,16, 0x0000007100679708,MotorcycleMgr::x_1,904, @@ -39550,7 +39550,7 @@ 0x0000007100683698,sub_7100683698,56, 0x00000071006836d0,WolfLinkMgr::postCalc,672, 0x0000007100683970,sub_7100683970,428, -0x0000007100683b1c,GameDataMgr::setVec3ByIdx,196, +0x0000007100683b1c,GameDataMgr::setVec3ByIdx,196,_ZN4ksys3gdt7Manager8setVec3fERKN4sead7Vector3IfEENS0_10FlagHandleE 0x0000007100683be0,sub_7100683BE0,48, 0x0000007100683c10,sub_7100683C10,92, 0x0000007100683c6c,sinitWolfLinkFlags,476, @@ -53006,24 +53006,29 @@ 0x00000071008ff4a8,sub_71008FF4A8,84, 0x00000071008ff4fc,sub_71008FF4FC,272, 0x00000071008ff60c,sub_71008FF60C,308, -0x00000071008ff740,GameDataMgr::setBoolByIdx,236, -0x00000071008ff82c,GameDataMgr::setS32ByIdxForce,236, -0x00000071008ff918,GameDataMgr::setFloatByIdx,236, -0x00000071008ffa04,GameDataMgr::x,236, -0x00000071008ffbb4,sub_71008FFBB4,236, -0x00000071008ffca0,GameDataMgr::setString64ByIdx,196, -0x00000071008ffd64,GameDataMgr::setString256ByIdx,236, -0x00000071008fff14,sub_71008FFF14,240, -0x0000007100900004,sub_7100900004,252, -0x00000071009001d0,sub_71009001D0,252, -0x00000071009002cc,GameDataMgr::x_0,208, -0x000000710090039c,GameDataMgr::__auto2,216, -0x0000007100900474,sub_7100900474,252, -0x0000007100900570,GameDataMgr::__auto0,208, -0x0000007100900640,sub_7100900640,252, -0x000000710090073c,sub_710090073C,208, -0x000000710090080c,sub_710090080C,252, -0x00000071009009d8,sub_71009009D8,264, +0x00000071008ff740,GameDataMgr::setBoolByIdx,236,_ZN4ksys3gdt7Manager19setBoolNoCheckForceEbNS0_10FlagHandleE +0x00000071008ff82c,GameDataMgr::setS32ByIdxForce,236,_ZN4ksys3gdt7Manager18setS32NoCheckForceEiNS0_10FlagHandleE +0x00000071008ff918,GameDataMgr::setFloatByIdx,236,_ZN4ksys3gdt7Manager18setF32NoCheckForceEfNS0_10FlagHandleE +0x00000071008ffa04,GameDataMgr::x,236,_ZN4ksys3gdt7Manager18setStrNoCheckForceEPKcNS0_10FlagHandleE +0x00000071008ffaf0,_ZN4ksys3gdt7Manager6setStrEPKcNS0_10FlagHandleE,0xc4,_ZN4ksys3gdt7Manager6setStrEPKcNS0_10FlagHandleE +0x00000071008ffbb4,sub_71008FFBB4,236,_ZN4ksys3gdt7Manager20setStr64NoCheckForceEPKcNS0_10FlagHandleE +0x00000071008ffca0,GameDataMgr::setString64ByIdx,196,_ZN4ksys3gdt7Manager8setStr64EPKcNS0_10FlagHandleE +0x00000071008ffd64,GameDataMgr::setString256ByIdx,236,_ZN4ksys3gdt7Manager21setStr256NoCheckForceEPKcNS0_10FlagHandleE +0x00000071008ffe50,_ZN4ksys3gdt7Manager9setStr256EPKcNS0_10FlagHandleE,0xc4,_ZN4ksys3gdt7Manager9setStr256EPKcNS0_10FlagHandleE +0x00000071008fff14,sub_71008FFF14,240,_ZN4ksys3gdt7Manager20setVec3fNoCheckForceEN4sead7Vector3IfEENS0_10FlagHandleE +0x0000007100900004,sub_7100900004,252,_ZN4ksys3gdt7Manager19setBoolNoCheckForceEbNS0_10FlagHandleEi +0x0000007100900100,_ZN4ksys3gdt7Manager7setBoolEbNS0_10FlagHandleEi,0xd0,_ZN4ksys3gdt7Manager7setBoolEbNS0_10FlagHandleEi +0x00000071009001d0,sub_71009001D0,252,_ZN4ksys3gdt7Manager18setS32NoCheckForceEiNS0_10FlagHandleEi +0x00000071009002cc,GameDataMgr::x_0,208,_ZN4ksys3gdt7Manager6setS32EiNS0_10FlagHandleEi +0x000000710090039c,GameDataMgr::__auto2,216,_ZN4ksys3gdt7Manager6setF32EfNS0_10FlagHandleEi +0x0000007100900474,sub_7100900474,252,_ZN4ksys3gdt7Manager20setStr64NoCheckForceEPKcNS0_10FlagHandleEi +0x0000007100900570,GameDataMgr::__auto0,208,_ZN4ksys3gdt7Manager8setStr64EPKcNS0_10FlagHandleEi +0x0000007100900640,sub_7100900640,252,_ZN4ksys3gdt7Manager21setStr256NoCheckForceEPKcNS0_10FlagHandleEi +0x000000710090073c,sub_710090073C,208,_ZN4ksys3gdt7Manager9setStr256EPKcNS0_10FlagHandleEi +0x000000710090080c,sub_710090080C,252,_ZN4ksys3gdt7Manager20setVec2fNoCheckForceEN4sead7Vector2IfEENS0_10FlagHandleEi +0x0000007100900908,_ZN4ksys3gdt7Manager8setVec2fERKN4sead7Vector2IfEENS0_10FlagHandleEi,0xd0,_ZN4ksys3gdt7Manager8setVec2fERKN4sead7Vector2IfEENS0_10FlagHandleEi +0x00000071009009d8,sub_71009009D8,264,_ZN4ksys3gdt7Manager20setVec3fNoCheckForceEN4sead7Vector3IfEENS0_10FlagHandleEi +0x0000007100900ae0,_ZN4ksys3gdt7Manager8setVec3fERKN4sead7Vector3IfEENS0_10FlagHandleEi,0xd0,_ZN4ksys3gdt7Manager8setVec3fERKN4sead7Vector3IfEENS0_10FlagHandleEi 0x0000007100900bb0,sub_7100900BB0,92, 0x0000007100900c0c,sub_7100900C0C,60, 0x0000007100900c48,getFlagInt,60, diff --git a/src/KingSystem/GameData/gdtManager.h b/src/KingSystem/GameData/gdtManager.h index 12635d11..6a14dba2 100644 --- a/src/KingSystem/GameData/gdtManager.h +++ b/src/KingSystem/GameData/gdtManager.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "KingSystem/GameData/gdtTriggerParam.h" #include "KingSystem/Resource/resHandle.h" #include "KingSystem/System/KingEditor.h" @@ -20,6 +21,36 @@ class MethodTreeMgr; namespace ksys::gdt { +namespace detail { + +template +struct SetterTraits { + static constexpr bool isVectorType() { + return std::is_same_v || std::is_same_v || + std::is_same_v; + } + + static constexpr bool isStringType() { return std::is_same_v; } + + static constexpr bool isInlineType() { + return std::is_same_v || std::is_same_v || std::is_same_v || + isStringType(); + } + + using ArgType = std::conditional_t; + using WrapperArgType = std::conditional_t; + using NoCheckForceArgType = T; + + static ArgType convertValue(WrapperArgType v) { + if constexpr (isStringType()) + return v.cstr(); + else + return v; + } +}; + +} // namespace detail + enum class FlagHandle : u32 {}; constexpr FlagHandle InvalidHandle = FlagHandle(-1); @@ -235,22 +266,27 @@ public: #undef GDT_GET_ -#define GDT_SET_(NAME, T, WRAPPER_T, WRAPPER_VALUE) \ +#define GDT_SET_(NAME, TRAITS) \ /* Setters (by handle) */ \ - KSYS_ALWAYS_INLINE bool NAME(T value, FlagHandle handle, bool debug, bool force) { \ + KSYS_ALWAYS_INLINE bool NAME(TRAITS::ArgType value, FlagHandle handle, bool debug, \ + bool force) { \ if (mBitFlags.isOn(BitFlag::_40000)) \ return false; \ return unwrapHandle(handle, debug, [&](u32 idx, TriggerParamRef& ref) { \ return ref.get().NAME(value, idx, force); \ }); \ } \ - bool NAME(T value, FlagHandle handle) { return NAME(value, handle, false, false); } \ - bool NAME##NoCheck(T value, FlagHandle handle) { return NAME(value, handle, true, false); } \ - bool NAME##NoCheckForce(T value, FlagHandle handle) { \ + bool NAME(TRAITS::ArgType value, FlagHandle handle) { \ + return NAME(value, handle, false, false); \ + } \ + bool NAME##NoCheck(TRAITS::ArgType value, FlagHandle handle) { \ + return NAME(value, handle, true, false); \ + } \ + bool NAME##NoCheckForce(TRAITS::NoCheckForceArgType value, FlagHandle handle) { \ return NAME(value, handle, true, true); \ } \ /* Setters for arrays (by handle) */ \ - KSYS_ALWAYS_INLINE bool NAME(T value, FlagHandle handle, bool debug, bool force, \ + KSYS_ALWAYS_INLINE bool NAME(TRAITS::ArgType value, FlagHandle handle, bool debug, bool force, \ s32 sub_idx) { \ if (mBitFlags.isOn(BitFlag::_40000)) \ return false; \ @@ -258,93 +294,98 @@ public: return ref.get().NAME(value, idx, sub_idx, force); \ }); \ } \ - bool NAME(T value, FlagHandle handle, s32 sub_idx) { \ + bool NAME(TRAITS::ArgType value, FlagHandle handle, s32 sub_idx) { \ return NAME(value, handle, false, false, sub_idx); \ } \ - bool NAME##NoCheck(T value, FlagHandle handle, s32 sub_idx) { \ + bool NAME##NoCheck(TRAITS::ArgType value, FlagHandle handle, s32 sub_idx) { \ return NAME(value, handle, true, false, sub_idx); \ } \ - bool NAME##NoCheckForce(T value, FlagHandle handle, s32 sub_idx) { \ + bool NAME##NoCheckForce(TRAITS::NoCheckForceArgType value, FlagHandle handle, s32 sub_idx) { \ return NAME(value, handle, true, true, sub_idx); \ } \ /* Setters (by name) */ \ - KSYS_ALWAYS_INLINE bool NAME(T value, const sead::SafeString& name, bool debug, bool force) { \ + KSYS_ALWAYS_INLINE bool NAME(TRAITS::ArgType value, const sead::SafeString& name, bool debug, \ + bool force) { \ if (mBitFlags.isOn(BitFlag::_40000)) \ return false; \ auto& ref = debug ? getParamBypassPerm() : getParam(); \ return ref.get().NAME(value, name, force); \ } \ - [[gnu::noinline]] bool NAME(T value, const sead::SafeString& name) { \ + [[gnu::noinline]] bool NAME(TRAITS::ArgType value, const sead::SafeString& name) { \ return NAME(value, name, false, false); \ } \ - [[gnu::noinline]] bool NAME##NoCheck(T value, const sead::SafeString& name) { \ + [[gnu::noinline]] bool NAME##NoCheck(TRAITS::ArgType value, const sead::SafeString& name) { \ return NAME(value, name, true, false); \ } \ - [[gnu::noinline]] bool NAME##NoCheckForce(T value, const sead::SafeString& name) { \ + [[gnu::noinline]] bool NAME##NoCheckForce(TRAITS::NoCheckForceArgType value, \ + const sead::SafeString& name) { \ return NAME(value, name, true, true); \ } \ /* Setters for arrays (by name) */ \ - KSYS_ALWAYS_INLINE bool NAME(T value, const sead::SafeString& name, bool debug, bool force, \ - s32 sub_idx) { \ + KSYS_ALWAYS_INLINE bool NAME(TRAITS::ArgType value, const sead::SafeString& name, bool debug, \ + bool force, s32 sub_idx) { \ if (mBitFlags.isOn(BitFlag::_40000)) \ return false; \ auto& ref = debug ? getParamBypassPerm() : getParam(); \ return ref.get().NAME(value, name, sub_idx, force); \ } \ - [[gnu::noinline]] bool NAME(T value, const sead::SafeString& name, s32 sub_idx) { \ + [[gnu::noinline]] bool NAME(TRAITS::ArgType value, const sead::SafeString& name, \ + s32 sub_idx) { \ return NAME(value, name, false, false, sub_idx); \ } \ - [[gnu::noinline]] bool NAME##NoCheck(T value, const sead::SafeString& name, s32 sub_idx) { \ + [[gnu::noinline]] bool NAME##NoCheck(TRAITS::ArgType value, const sead::SafeString& name, \ + s32 sub_idx) { \ return NAME(value, name, true, false, sub_idx); \ } \ - [[gnu::noinline]] bool NAME##NoCheckForce(T value, const sead::SafeString& name, \ - s32 sub_idx) { \ + [[gnu::noinline]] bool NAME##NoCheckForce(TRAITS::NoCheckForceArgType value, \ + const sead::SafeString& name, s32 sub_idx) { \ return NAME(value, name, true, true, sub_idx); \ } \ \ - bool NAME(WRAPPER_T value, FlagHandle handle, bool debug) { \ + bool NAME(TRAITS::WrapperArgType value, FlagHandle handle, bool debug) { \ if (debug) { \ setBool(true, "IsChangedByDebug"); \ mBitFlags.set(BitFlag::_800); \ - return NAME##NoCheckForce(WRAPPER_VALUE, handle); \ + return NAME##NoCheckForce(TRAITS::convertValue(value), handle); \ } \ - return NAME(WRAPPER_VALUE, handle); \ + return NAME(TRAITS::convertValue(value), handle); \ } \ - bool NAME(WRAPPER_T value, const sead::SafeString& name, bool debug) { \ + bool NAME(TRAITS::WrapperArgType value, const sead::SafeString& name, bool debug) { \ if (debug) { \ setBool(true, "IsChangedByDebug"); \ mBitFlags.set(BitFlag::_800); \ - return NAME##NoCheckForce(WRAPPER_VALUE, name); \ + return NAME##NoCheckForce(TRAITS::convertValue(value), name); \ } \ - return NAME(WRAPPER_VALUE, name); \ + return NAME(TRAITS::convertValue(value), name); \ } \ \ - bool NAME(WRAPPER_T value, FlagHandle handle, bool debug, s32 sub_idx) { \ + bool NAME(TRAITS::WrapperArgType value, FlagHandle handle, bool debug, s32 sub_idx) { \ if (debug) { \ setBool(true, "IsChangedByDebug"); \ mBitFlags.set(BitFlag::_800); \ - return NAME##NoCheckForce(WRAPPER_VALUE, handle, sub_idx); \ + return NAME##NoCheckForce(TRAITS::convertValue(value), handle, sub_idx); \ } \ - return NAME(WRAPPER_VALUE, handle, sub_idx); \ + return NAME(TRAITS::convertValue(value), handle, sub_idx); \ } \ - bool NAME(WRAPPER_T value, const sead::SafeString& name, bool debug, s32 sub_idx) { \ + bool NAME(TRAITS::WrapperArgType value, const sead::SafeString& name, bool debug, \ + s32 sub_idx) { \ if (debug) { \ setBool(true, "IsChangedByDebug"); \ mBitFlags.set(BitFlag::_800); \ - return NAME##NoCheckForce(WRAPPER_VALUE, name, sub_idx); \ + return NAME##NoCheckForce(TRAITS::convertValue(value), name, sub_idx); \ } \ - return NAME(WRAPPER_VALUE, name, sub_idx); \ + return NAME(TRAITS::convertValue(value), name, sub_idx); \ } - GDT_SET_(setBool, bool, bool, value) - GDT_SET_(setS32, s32, s32, value) - GDT_SET_(setF32, f32, f32, value) - GDT_SET_(setStr, char const*, const sead::SafeString&, value.cstr()) - GDT_SET_(setStr64, char const*, const sead::SafeString&, value.cstr()) - GDT_SET_(setStr256, char const*, const sead::SafeString&, value.cstr()) - GDT_SET_(setVec2f, const sead::Vector2f&, const sead::Vector2f&, value) - GDT_SET_(setVec3f, const sead::Vector3f&, const sead::Vector3f&, value) - GDT_SET_(setVec4f, const sead::Vector4f&, const sead::Vector4f&, value) + GDT_SET_(setBool, detail::SetterTraits) + GDT_SET_(setS32, detail::SetterTraits) + GDT_SET_(setF32, detail::SetterTraits) + GDT_SET_(setStr, detail::SetterTraits) + GDT_SET_(setStr64, detail::SetterTraits) + GDT_SET_(setStr256, detail::SetterTraits) + GDT_SET_(setVec2f, detail::SetterTraits) + GDT_SET_(setVec3f, detail::SetterTraits) + GDT_SET_(setVec4f, detail::SetterTraits) #undef GDT_SET_