From 090aac75b6768eee0918f807d1064fb7d1ff2a92 Mon Sep 17 00:00:00 2001 From: Fuzzy2319 Date: Thu, 5 Mar 2026 20:25:04 +0100 Subject: [PATCH 1/2] update:rtti for mods --- include/prim/seadRuntimeTypeInfo.h | 125 ++++++++++++++++++++++++++++- include/seadVersion.h | 7 ++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/include/prim/seadRuntimeTypeInfo.h b/include/prim/seadRuntimeTypeInfo.h index 8d722579..4d4c5433 100644 --- a/include/prim/seadRuntimeTypeInfo.h +++ b/include/prim/seadRuntimeTypeInfo.h @@ -50,7 +50,7 @@ inline bool IsDerivedFrom(const Type* obj) } /// If the object is a DerivedType or any type that derives from (i.e. inherits) DerivedType, -/// this returns obj casted to DerivedType* -- otherwise this returns nullptr. +/// this returns obj cast to DerivedType* -- otherwise this returns nullptr. /// /// @note This is similar to C++'s dynamic_cast or LLVM's dyn_cast but only works with types /// that use the sead RTTI mechanism. @@ -65,32 +65,39 @@ inline DerivedType* DynamicCast(Type* obj) } // namespace sead +#if SEAD_TARGET == SEAD_TARGET_DECOMP #if SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_RETURNS_INSTANCE + #define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE(CLASS) \ virtual const CLASS* checkDerivedRuntimeTypeInfo( \ const sead::RuntimeTypeInfo::Interface* typeInfo) const \ { \ return checkDerivedRuntimeTypeInfoStatic(typeInfo) ? this : nullptr; \ } + #define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE(CLASS) \ const CLASS* checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ const override \ { \ return checkDerivedRuntimeTypeInfoStatic(typeInfo) ? this : nullptr; \ } + #else + #define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE(CLASS) \ virtual bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ const \ { \ return checkDerivedRuntimeTypeInfoStatic(typeInfo); \ } + #define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE(CLASS) \ bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ const override \ { \ return checkDerivedRuntimeTypeInfoStatic(typeInfo); \ } + #endif /// Use this macro to declare sead RTTI machinery for a base class. @@ -147,4 +154,120 @@ public: return getRuntimeTypeInfoStatic(); \ } +#elif SEAD_TARGET == SEAD_TARGET_MOD +#if SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_RETURNS_INSTANCE + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE(CLASS) \ + virtual const CLASS* checkDerivedRuntimeTypeInfo( \ + const sead::RuntimeTypeInfo::Interface* typeInfo) const; + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE(CLASS) \ + const CLASS* checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ + const override; + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE_CUSTOM(CLASS) \ + virtual const CLASS* checkDerivedRuntimeTypeInfo( \ + const sead::RuntimeTypeInfo::Interface* typeInfo) const \ + { \ + return checkDerivedRuntimeTypeInfoStatic(typeInfo) ? this : nullptr; \ + } + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS) \ + const CLASS* checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ + const override \ + { \ + return checkDerivedRuntimeTypeInfoStatic(typeInfo) ? this : nullptr; \ + } + +#else + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE(CLASS) \ + virtual bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ + const; + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE(CLASS) \ + bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ + const override; + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE_CUSTOM(CLASS) \ + virtual bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ + const \ + { \ + return checkDerivedRuntimeTypeInfoStatic(typeInfo); \ + } + +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS) \ + bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ + const override \ + { \ + return checkDerivedRuntimeTypeInfoStatic(typeInfo); \ + } + +#endif + +#define SEAD_RTTI_BASE(CLASS) \ +public: \ + SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE(CLASS) \ + \ + virtual const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfo() const; + +#define SEAD_RTTI_OVERRIDE(CLASS, BASE) \ +public: \ + SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE(CLASS) \ + \ + const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfo() const override; + +#define SEAD_RTTI_BASE_CUSTOM(CLASS) \ +public: \ + static const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfoStatic() \ + { \ + static const sead::RuntimeTypeInfo::Root typeInfo; \ + return &typeInfo; \ + } \ + \ + static bool checkDerivedRuntimeTypeInfoStatic( \ + const sead::RuntimeTypeInfo::Interface* typeInfo) \ + { \ + const sead::RuntimeTypeInfo::Interface* clsTypeInfo = CLASS::getRuntimeTypeInfoStatic(); \ + return typeInfo == clsTypeInfo; \ + } \ + \ + SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_BASE_CUSTOM(CLASS) \ + \ + virtual const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfo() const \ + { \ + return getRuntimeTypeInfoStatic(); \ + } + +/// Use this macro to declare sead RTTI machinery for a derived class. +/// @param CLASS The name of the class. +/// @param BASE The name of the base class of CLASS. +#define SEAD_RTTI_OVERRIDE_CUSTOM(CLASS, BASE) \ +public: \ + static const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfoStatic() \ + { \ + static const sead::RuntimeTypeInfo::Derive typeInfo; \ + return &typeInfo; \ + } \ + \ + static bool checkDerivedRuntimeTypeInfoStatic( \ + const sead::RuntimeTypeInfo::Interface* typeInfo) \ + \ + { \ + const sead::RuntimeTypeInfo::Interface* clsTypeInfo = CLASS::getRuntimeTypeInfoStatic(); \ + if (typeInfo == clsTypeInfo) \ + return true; \ + \ + return BASE::checkDerivedRuntimeTypeInfoStatic(typeInfo); \ + } \ + \ + SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS) \ + \ + const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfo() const override \ + { \ + return getRuntimeTypeInfoStatic(); \ + } + +#endif + #endif // SEAD_RUNTIMETYPEINFO_H_ diff --git a/include/seadVersion.h b/include/seadVersion.h index 4d0cc607..c221643d 100644 --- a/include/seadVersion.h +++ b/include/seadVersion.h @@ -1,5 +1,12 @@ #pragma once +#define SEAD_TARGET_DECOMP 1 +#define SEAD_TARGET_MOD 2 + +#ifndef SEAD_TARGET +#define SEAD_TARGET SEAD_TARGET_DECOMP +#endif + #define SEAD_VERSION_BOTW 1 #define SEAD_VERSION_SMO 2 #define SEAD_VERSION_SPL3 3 From da10fef2d04727c946d9dcda2f1660ca63ff1625 Mon Sep 17 00:00:00 2001 From: Fuzzy2319 Date: Thu, 5 Mar 2026 21:13:18 +0100 Subject: [PATCH 2/2] fix:rtti when using SEAD_RTTI_OVERRIDE_CUSTOM on a class with SEAD_RTTI_BASE --- include/prim/seadRuntimeTypeInfo.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/prim/seadRuntimeTypeInfo.h b/include/prim/seadRuntimeTypeInfo.h index 4d4c5433..d2e07d05 100644 --- a/include/prim/seadRuntimeTypeInfo.h +++ b/include/prim/seadRuntimeTypeInfo.h @@ -172,11 +172,14 @@ public: return checkDerivedRuntimeTypeInfoStatic(typeInfo) ? this : nullptr; \ } -#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS) \ +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS, BASE) \ const CLASS* checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ const override \ { \ - return checkDerivedRuntimeTypeInfoStatic(typeInfo) ? this : nullptr; \ + return (checkDerivedRuntimeTypeInfoStatic(typeInfo) || \ + this->BASE::checkDerivedRuntimeTypeInfo(typeInfo)) ? \ + this : \ + nullptr; \ } #else @@ -196,11 +199,12 @@ public: return checkDerivedRuntimeTypeInfoStatic(typeInfo); \ } -#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS) \ +#define SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS, BASE) \ bool checkDerivedRuntimeTypeInfo(const sead::RuntimeTypeInfo::Interface* typeInfo) \ const override \ { \ - return checkDerivedRuntimeTypeInfoStatic(typeInfo); \ + return checkDerivedRuntimeTypeInfoStatic(typeInfo) || \ + this->BASE::checkDerivedRuntimeTypeInfo(typeInfo); \ } #endif @@ -255,13 +259,10 @@ public: \ { \ const sead::RuntimeTypeInfo::Interface* clsTypeInfo = CLASS::getRuntimeTypeInfoStatic(); \ - if (typeInfo == clsTypeInfo) \ - return true; \ - \ - return BASE::checkDerivedRuntimeTypeInfoStatic(typeInfo); \ + return typeInfo == clsTypeInfo; \ } \ \ - SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS) \ + SEAD_RTTI_CHECKDERIVEDRUNTIMETYPEINFO_OVERRIDE_CUSTOM(CLASS, BASE) \ \ const sead::RuntimeTypeInfo::Interface* getRuntimeTypeInfo() const override \ { \