diff --git a/src/reverse/RTTIMapper.cpp b/src/reverse/RTTIMapper.cpp index c7922083..57963a57 100644 --- a/src/reverse/RTTIMapper.cpp +++ b/src/reverse/RTTIMapper.cpp @@ -33,6 +33,7 @@ void RTTIMapper::Register() RegisterSimpleTypes(luaState, luaGlobal); RegisterDirectTypes(luaState, luaGlobal, pRtti); + RegisterDirectGlobals(luaGlobal, pRtti); RegisterScriptAliases(luaGlobal, pRtti); RegisterSpecialAccessors(luaState, luaGlobal); } @@ -120,6 +121,26 @@ void RTTIMapper::RegisterDirectTypes(sol::state& aLuaState, sol::table& aLuaGlob }); } +void RTTIMapper::RegisterDirectGlobals(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti) +{ + apRtti->funcs.for_each([&aLuaGlobal](RED4ext::CName aOrigName, RED4ext::CGlobalFunction* apFunc) { + const std::string cShortName = apFunc->shortName.ToString(); + const FuncFlags cFlags = *(FuncFlags*)(&apFunc->flags); + + if (aLuaGlobal[cShortName] == sol::nil && !cFlags.isExec) + { + const std::string cFullName = apFunc->fullName.ToString(); + const auto cIsClassFunc = cFullName.find("::") != std::string::npos; + const auto cIsOperatorFunc = cShortName.find(";") != std::string::npos; + + if (!cIsClassFunc && !cIsOperatorFunc) + { + aLuaGlobal[cShortName] = RTTIHelper::Get().ResolveFunction(cShortName); + } + } + }); +} + void RTTIMapper::RegisterScriptAliases(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti) { apRtti->scriptToNative.for_each([&aLuaGlobal](RED4ext::CName aScriptName, RED4ext::CName aNativeName) { diff --git a/src/reverse/RTTIMapper.h b/src/reverse/RTTIMapper.h index 557cb61b..f3164437 100644 --- a/src/reverse/RTTIMapper.h +++ b/src/reverse/RTTIMapper.h @@ -13,8 +13,31 @@ struct RTTIMapper private: + struct FuncFlags + { + uint32_t isNative : 1; // 00 + uint32_t isStatic : 1; // 01 + uint32_t isFinal : 1; // 02 + uint32_t isEvent : 1; // 03 + uint32_t isExec : 1; // 04 + uint32_t isUndefinedBody : 1; // 05 Unconfirmed (unset for scripted funcs without body) + uint32_t isTimer : 1; // 06 Unconfirmed + uint32_t isPrivate : 1; // 07 + uint32_t isProtected : 1; // 08 + uint32_t isPublic : 1; // 09 + uint32_t b11 : 1; // 0A + uint32_t b12 : 1; // 0B + uint32_t b13 : 1; // 0C + uint32_t isConst : 1; // 0D + uint32_t isQuest : 1; // 0E + uint32_t isThreadsafe : 1; // 0F + uint32_t b16 : 16; + }; + RED4EXT_ASSERT_SIZE(FuncFlags, 0x4); + void RegisterSimpleTypes(sol::state& aLuaState, sol::table& aLuaGlobal); void RegisterDirectTypes(sol::state& aLuaState, sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti); + void RegisterDirectGlobals(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti); void RegisterScriptAliases(sol::table& aLuaGlobal, RED4ext::CRTTISystem* apRtti); void RegisterSpecialAccessors(sol::state& aLuaState, sol::table& aLuaGlobal);