diff --git a/src/reverse/RTTIHelper.cpp b/src/reverse/RTTIHelper.cpp index 97f703de..dfa3758c 100644 --- a/src/reverse/RTTIHelper.cpp +++ b/src/reverse/RTTIHelper.cpp @@ -118,6 +118,7 @@ void RTTIHelper::AddFunctionAlias(const std::string& acAliasClassName, const std bool RTTIHelper::IsFunctionAlias(RED4ext::CBaseFunction* apFunc) { static const auto s_cTweakDBInterfaceHash = RED4ext::FNV1a("gamedataTweakDBInterface"); + static const auto s_cTDBIDHelperHash = RED4ext::FNV1a("gamedataTDBIDHelper"); if (m_extendedFunctions.contains(kGlobalHash)) { @@ -131,9 +132,9 @@ bool RTTIHelper::IsFunctionAlias(RED4ext::CBaseFunction* apFunc) { const auto cClassHash = apFunc->GetParent()->name.hash; - // TweakDBInterface is special. - // All of its methods are non-static, but they can only be used as static ones. - if (cClassHash == s_cTweakDBInterfaceHash) + // TweakDBInterface and TDBID classes are special. + // All of their methods are non-static, but they can only be used as static ones. + if (cClassHash == s_cTweakDBInterfaceHash || cClassHash == s_cTDBIDHelperHash) return true; if (m_extendedFunctions.contains(cClassHash)) diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index bdcbb6ac..d1181f32 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -946,102 +946,16 @@ RED4ext::CStackType Scripting::ToRED(sol::object aObject, RED4ext::CBaseRTTIType return result; } -void Scripting::ToRED(sol::object aObject, RED4ext::CStackType* apType) +void Scripting::ToRED(sol::object aObject, RED4ext::CStackType* apRet) { - const bool hasData = aObject != sol::nil; + static thread_local TiltedPhoques::ScratchAllocator s_scratchMemory(1 << 13); - if (apType->type) - { - if (apType->type == s_stringType) - { - std::string str; - if (hasData) - { - sol::state_view v(aObject.lua_state()); - str = v["tostring"](aObject); - } - RED4ext::CString value(str.c_str()); - *static_cast(apType->value) = value; - } - else if (apType->type->GetType() == RED4ext::ERTTIType::Handle) - { - if (aObject.is()) - { - auto* pSubType = static_cast(apType->type)->parent; - auto* pType = static_cast(aObject.as()->m_pType); - if (pType && pType->IsA(pSubType)) - { - if (hasData) - *static_cast*>(apType->value) = - RED4ext::Handle(aObject.as().m_strongHandle); - else - *static_cast*>(apType->value) = - RED4ext::Handle(); - } - } - else if (aObject.is()) - { - auto* pSubType = static_cast(apType->type)->parent; - auto* pType = static_cast(aObject.as()->m_pType); - if (pType && pType->IsA(pSubType)) - { - if (hasData) - *static_cast*>(apType->value) = - RED4ext::Handle(aObject.as().m_weakHandle); - else - *static_cast*>(apType->value) = - RED4ext::Handle(); - } - } - } - else if (apType->type->GetType() == RED4ext::ERTTIType::WeakHandle) - { - if (aObject.is()) - { - auto* pSubType = static_cast(apType->type)->parent; - auto* pType = static_cast(aObject.as()->m_pType); - if (pType && pType->IsA(pSubType)) - { - if (hasData) - *static_cast*>(apType->value) = - RED4ext::WeakHandle(aObject.as().m_weakHandle); - else - *static_cast*>(apType->value) = - RED4ext::WeakHandle(); - } - } - else if (aObject.is()) // Handle Implicit Cast - { - auto* pSubType = static_cast(apType->type)->parent; - auto* pType = static_cast(aObject.as()->m_pType); - if (pType && pType->IsA(pSubType)) - { - if (hasData) - *static_cast*>(apType->value) = - RED4ext::WeakHandle(aObject.as().m_strongHandle); - else - *static_cast*>(apType->value) = - RED4ext::WeakHandle(); - } - } - } - else if (apType->type->GetType() == RED4ext::ERTTIType::Array) - { - //TODO: Support arrays - } - else if (apType->type->GetType() == RED4ext::ERTTIType::ScriptReference) - { - if (aObject.is()) - { - auto* pClassRef = aObject.as(); - auto* pScriptRef = static_cast*>(apType->value); - pScriptRef->innerType = pClassRef->m_pType; - pScriptRef->ref = pClassRef->GetHandle(); - } - } - else - { - Converter::ToRED(aObject, apType); - } - } + auto result = ToRED(aObject, apRet->type, &s_scratchMemory); + + apRet->type->Assign(apRet->value, result.value); + + if (apRet->type->GetType() != RED4ext::ERTTIType::Class) + apRet->type->Destroy(result.value); + + s_scratchMemory.Reset(); }