From fd8b52d4cc277c86e78c5ee32b8d81c06f77a27c Mon Sep 17 00:00:00 2001 From: psiberx Date: Sat, 20 Jul 2024 14:51:25 +0300 Subject: [PATCH 1/5] Change resource path placeholder --- src/reverse/TweakDB/ResourcesList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reverse/TweakDB/ResourcesList.cpp b/src/reverse/TweakDB/ResourcesList.cpp index e23229b6..980cba3f 100644 --- a/src/reverse/TweakDB/ResourcesList.cpp +++ b/src/reverse/TweakDB/ResourcesList.cpp @@ -100,7 +100,7 @@ bool ResourcesList::IsInitialized() const const std::string& ResourcesList::Resolve(uint64_t aHash) { - static std::string defaultName = "ERROR_UNKNOWN_RESOURCE"; + static std::string defaultName = "UNRESOLVED_RESOURCE_PATH"; const auto it = m_resourcesByHash.find(aHash); From 08f89cb4177bb33547665424e13826100c34d415 Mon Sep 17 00:00:00 2001 From: psiberx Date: Sat, 20 Jul 2024 14:51:48 +0300 Subject: [PATCH 2/5] Fix variants for handles --- src/reverse/RTTIMapper.cpp | 2 +- src/reverse/StrongReference.cpp | 7 +++++++ src/reverse/StrongReference.h | 2 ++ src/reverse/Type.h | 1 + src/reverse/WeakReference.cpp | 7 +++++++ src/reverse/WeakReference.h | 2 ++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/reverse/RTTIMapper.cpp b/src/reverse/RTTIMapper.cpp index 4d0b908e..5ff1481d 100644 --- a/src/reverse/RTTIMapper.cpp +++ b/src/reverse/RTTIMapper.cpp @@ -56,7 +56,7 @@ void RTTIMapper::RegisterSimpleTypes(sol::state& aLuaState, sol::table& aLuaGlob aLuaGlobal["ToVariant"] = sol::overload( [](const Type& aInstance, sol::this_state aState) -> sol::object { - const auto* pType = aInstance.GetType(); + auto* pType = aInstance.GetValueType(); auto* pValue = aInstance.GetValuePtr(); if (!pType || !pValue) diff --git a/src/reverse/StrongReference.cpp b/src/reverse/StrongReference.cpp index 76f109b9..d6666722 100644 --- a/src/reverse/StrongReference.cpp +++ b/src/reverse/StrongReference.cpp @@ -10,6 +10,7 @@ static RTTILocator s_sIScriptableType{RED4ext::FNV1a64("IScriptable")}; StrongReference::StrongReference(const TiltedPhoques::Lockable::Ref& aView, RED4ext::Handle aStrongHandle) : ClassType(aView, nullptr) , m_strongHandle(std::move(aStrongHandle)) + , m_pHandleType(nullptr) { if (m_strongHandle) { @@ -21,6 +22,7 @@ StrongReference::StrongReference( const TiltedPhoques::Lockable::Ref& aView, RED4ext::Handle aStrongHandle, RED4ext::CRTTIHandleType* apStrongHandleType) : ClassType(aView, nullptr) , m_strongHandle(std::move(aStrongHandle)) + , m_pHandleType(apStrongHandleType) { if (m_strongHandle) { @@ -49,3 +51,8 @@ RED4ext::ScriptInstance StrongReference::GetValuePtr() const { return const_cast*>(&m_strongHandle); } + +RED4ext::CBaseRTTIType* StrongReference::GetValueType() const +{ + return m_pHandleType; +} diff --git a/src/reverse/StrongReference.h b/src/reverse/StrongReference.h index 219011ae..1833ba78 100644 --- a/src/reverse/StrongReference.h +++ b/src/reverse/StrongReference.h @@ -13,10 +13,12 @@ struct StrongReference : ClassType protected: RED4ext::ScriptInstance GetHandle() const override; RED4ext::ScriptInstance GetValuePtr() const override; + RED4ext::CBaseRTTIType* GetValueType() const override; private: friend struct Scripting; friend struct TweakDB; RED4ext::Handle m_strongHandle; + RED4ext::CRTTIHandleType* m_pHandleType; }; diff --git a/src/reverse/Type.h b/src/reverse/Type.h index 2d42ee90..bd17c644 100644 --- a/src/reverse/Type.h +++ b/src/reverse/Type.h @@ -17,6 +17,7 @@ struct Type RED4ext::CBaseRTTIType* GetType() const { return m_pType; } virtual RED4ext::ScriptInstance GetHandle() const { return nullptr; } + virtual RED4ext::CBaseRTTIType* GetValueType() const { return m_pType; } virtual RED4ext::ScriptInstance GetValuePtr() const { return nullptr; } sol::object Index(const std::string& acName, sol::this_environment aThisEnv); diff --git a/src/reverse/WeakReference.cpp b/src/reverse/WeakReference.cpp index b4ba8d83..f808c966 100644 --- a/src/reverse/WeakReference.cpp +++ b/src/reverse/WeakReference.cpp @@ -10,6 +10,7 @@ static RTTILocator s_sIScriptableType{RED4ext::FNV1a64("IScriptable")}; WeakReference::WeakReference(const TiltedPhoques::Lockable::Ref& aView, RED4ext::WeakHandle aWeakHandle) : ClassType(aView, nullptr) , m_weakHandle(std::move(aWeakHandle)) + , m_pHandleType(nullptr) { const auto ref = m_weakHandle.Lock(); if (ref) @@ -23,6 +24,7 @@ WeakReference::WeakReference( RED4ext::CRTTIWeakHandleType* apWeakHandleType) : ClassType(aView, nullptr) , m_weakHandle(std::move(aWeakHandle)) + , m_pHandleType(apWeakHandleType) { const auto ref = m_weakHandle.Lock(); if (ref) @@ -58,3 +60,8 @@ RED4ext::ScriptInstance WeakReference::GetValuePtr() const { return const_cast*>(&m_weakHandle); } + +RED4ext::CBaseRTTIType* WeakReference::GetValueType() const +{ + return m_pHandleType; +} diff --git a/src/reverse/WeakReference.h b/src/reverse/WeakReference.h index 71a4e294..c190848b 100644 --- a/src/reverse/WeakReference.h +++ b/src/reverse/WeakReference.h @@ -13,10 +13,12 @@ struct WeakReference : ClassType protected: RED4ext::ScriptInstance GetHandle() const override; RED4ext::ScriptInstance GetValuePtr() const override; + RED4ext::CBaseRTTIType* GetValueType() const override; private: friend struct Scripting; friend struct TweakDB; RED4ext::WeakHandle m_weakHandle; + RED4ext::CRTTIWeakHandleType* m_pHandleType; }; From a1ee031f607894aadc40de98ba5d0a5a5ce91fbd Mon Sep 17 00:00:00 2001 From: psiberx Date: Sat, 20 Jul 2024 14:51:57 +0300 Subject: [PATCH 3/5] Register global functions using sanitized name --- src/reverse/RTTIMapper.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/reverse/RTTIMapper.cpp b/src/reverse/RTTIMapper.cpp index 5ff1481d..d06c195a 100644 --- a/src/reverse/RTTIMapper.cpp +++ b/src/reverse/RTTIMapper.cpp @@ -199,6 +199,14 @@ void RTTIMapper::RegisterDirectGlobals(sol::table& aLuaGlobal, RED4ext::CRTTISys if (!cIsClassFunc && !cIsOperatorFunc) { aLuaGlobal[cShortName] = RTTIHelper::Get().ResolveFunction(cShortName); + + std::string sanitizedName = cShortName; + SanitizeName(sanitizedName); + + if (sanitizedName != cShortName) + { + aLuaGlobal[sanitizedName] = aLuaGlobal[cShortName]; + } } } }); From f9bdd993c3641f22c2636d9d66fd8aeafb3fe404 Mon Sep 17 00:00:00 2001 From: psiberx Date: Sat, 20 Jul 2024 14:52:06 +0300 Subject: [PATCH 4/5] Support latest SDK --- src/reverse/RTTIExtender.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/reverse/RTTIExtender.cpp b/src/reverse/RTTIExtender.cpp index eeb8afa8..3d97d9dc 100644 --- a/src/reverse/RTTIExtender.cpp +++ b/src/reverse/RTTIExtender.cpp @@ -1,6 +1,5 @@ #include "RTTIExtender.h" -#include #include #include #include @@ -204,9 +203,9 @@ struct TEMP_Spawner RED4ext::DynArray> spawnedEntities; RED4ext::DynArray pendingEntities; RED4ext::DynArray unk30; - uint8_t unk40 = 0; // most likely a mutex - RED4ext::SharedMutex entitiesMtx; // used in DespawnEntity - RED4ext::SharedMutex pendingEntitiesMtx; // used in SpawnEntity + uint8_t unk40 = 0; // most likely a mutex + RED4ext::SharedSpinLock entitiesMtx; // used in DespawnEntity + RED4ext::SharedSpinLock pendingEntitiesMtx; // used in SpawnEntity uintptr_t unk48 = 0; uintptr_t unk50 = 0; uintptr_t unk58 = 0; From 13402ac1ff53abfac257a70dbfff5ae49ef79d00 Mon Sep 17 00:00:00 2001 From: psiberx Date: Sat, 20 Jul 2024 15:11:15 +0300 Subject: [PATCH 5/5] Update SDK --- vendor/RED4ext.SDK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/RED4ext.SDK b/vendor/RED4ext.SDK index 3cc51227..109d7fb0 160000 --- a/vendor/RED4ext.SDK +++ b/vendor/RED4ext.SDK @@ -1 +1 @@ -Subproject commit 3cc51227e860429313b9b36e37d48a3065e16d6f +Subproject commit 109d7fb0044f86b90d6ccc71f2c30c8a5b6ca208