From dd8ef7139065de77cef536485836008bca60cb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 7 Nov 2020 16:50:18 +0100 Subject: [PATCH] ksys/gdt: Add flag value getters to Manager --- src/KingSystem/GameData/gdtManager.h | 52 ++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/KingSystem/GameData/gdtManager.h b/src/KingSystem/GameData/gdtManager.h index cd90061d..eb9098f2 100644 --- a/src/KingSystem/GameData/gdtManager.h +++ b/src/KingSystem/GameData/gdtManager.h @@ -101,8 +101,8 @@ public: const TriggerParamRef& mRef; }; - Proxy getParam() const { return Proxy(*this, false); } - Proxy getParam1() const { return Proxy(*this, true); } + Proxy get() const { return Proxy(*this, false); } + Proxy get1() const { return Proxy(*this, true); } void setBuffers(TriggerParam** param1, TriggerParam** param) { mParam1 = param1; @@ -172,7 +172,7 @@ public: FlagHandle NAME(const sead::SafeString& name) const { \ const auto prefix = mCurrentFlagHandlePrefix; \ const auto hash = sead::HashCRC32::calcStringHash(name); \ - return makeFlagHandle(prefix, mParam.getParam1().getBuffer()->GET_IDX_NAME(hash)); \ + return makeFlagHandle(prefix, mParam.get1().getBuffer()->GET_IDX_NAME(hash)); \ } GDT_GET_HANDLE_(getBoolHandle, TriggerParam::getBoolIdx) @@ -197,6 +197,24 @@ public: #undef GDT_GET_HANDLE_ +#define GDT_GET_(NAME, T) \ + void NAME(FlagHandle handle, T* value, bool debug = false) { \ + unwrapHandle(handle, debug, \ + [&](u32 idx, TriggerParamRef& ref) { ref.get().NAME(value, idx); }); \ + } + + GDT_GET_(getBool, bool) + GDT_GET_(getS32, s32) + GDT_GET_(getF32, f32) + GDT_GET_(getStr, char const*) + GDT_GET_(getStr64, char const*) + GDT_GET_(getStr256, char const*) + GDT_GET_(getVec2f, sead::Vector2f) + GDT_GET_(getVec3f, sead::Vector3f) + GDT_GET_(getVec4f, sead::Vector4f) + +#undef GDT_GET_ + void init(sead::Heap* heap, sead::Framework* framework); void addReinitCallback(ReinitSignal::Slot& slot); @@ -216,6 +234,9 @@ private: _400 = 0x400, _800 = 0x800, _1000 = 0x1000, + _2000 = 0x2000, + _4000 = 0x4000, + _8000 = 0x8000, }; enum class ResetFlag { @@ -246,6 +267,31 @@ private: return FlagHandle(idx | (prefix << 24)); } + /// Extracts a flag index out of a FlagHandle and passes it to the specified callable. + /// fn must be callable with a u32 + template + void unwrapHandle(FlagHandle handle, const Fn& fn) { + u32 idx = static_cast(handle); + bool is_valid_idx = mBitFlags.isOff(BitFlag::_8000); + is_valid_idx &= handle != InvalidHandle; + if (!is_valid_idx) { + if (idx >> 24 != mCurrentFlagHandlePrefix) + return; + idx &= 0xFFFFFF; + } + fn(idx); + } + + /// Extracts a flag index out of a FlagHandle and passes it to the specified callable. + /// fn must be callable with a u32 + TriggerParamRef& + template + void unwrapHandle(FlagHandle handle, bool debug, const Fn& fn) { + if (debug) + unwrapHandle(handle, [&](u32 idx) { fn(idx, getParamBypassPerm()); }); + else + unwrapHandle(handle, [&](u32 idx) { fn(idx, getParam()); }); + } + void loadGameData(const sead::SafeString& path); void loadShopGameDataInfo(const sead::SafeString& path); void unloadResources();