From d81186c2084f8e1fc675daa7ad98a85c64faaf22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 9 Sep 2021 22:37:42 +0200 Subject: [PATCH] cheatsheet: Add sead::DynamicCast --- Cheatsheet.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Cheatsheet.md b/Cheatsheet.md index 8e2f1517..65576975 100644 --- a/Cheatsheet.md +++ b/Cheatsheet.md @@ -369,6 +369,32 @@ item = buffer[i]; --- +#### RTTI (Runtime Type Info) + +##### sead::DynamicCast + +```cpp +some_ptr = ...; +x = __ldar(...); // usually a guard variable, but the variable is not always named +another_ptr = some_ptr; +if ( (x & 1) == 0 && _cxa_guard_acquire_0(...)) // the same guard variable +{ + ... = &...; + _cxa_guard_release_0(...); // the same guard variable +} +if ( another_ptr && another_ptr->checkDerivedRuntimeTypeInfo(another_ptr, ...) ) +{ + // code that uses another_ptr +} +``` +⬇️ +```cpp +if (auto* another_ptr = sead::DynamicCast(some_ptr)) + ... +``` + +T is a derived type that should be related to the type of the original pointer. + ### agl agl is one of Nintendo's in-house graphics libraries.