Skip to content

Commit

Permalink
Merge pull request #864 from psiberx/master
Browse files Browse the repository at this point in the history
Patch 2.0 fixes
  • Loading branch information
maximegmd authored Sep 28, 2023
2 parents 21eb4b3 + c14240e commit d885114
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/scripting/FunctionOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,13 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,

const bool isScriptRef = pArg->type->GetType() == RED4ext::ERTTIType::ScriptReference;

// Exception here we need to allocate the inner object as well
if (isScriptRef)
// Determines if script ref was created from rvalue and other side expects us to copy it.
// If true, we must allocate the memory for the value and initialize our own script ref.
// If false, we don't have to initialize anything on our side and pInstance will be filled
// with a pointer to the original value.
const bool isTemporary = (apFrame->paramFlags >> apFrame->currentParam) & 1;

if (isScriptRef && isTemporary)
{
auto* pInnerType = static_cast<RED4ext::CRTTIScriptReferenceType*>(pType)->innerType;
auto* pScriptRef = static_cast<RED4ext::ScriptRef<void>*>(pInstance);
Expand Down Expand Up @@ -310,7 +315,7 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
}

// Release inner values
if (isScriptRef)
if (isScriptRef && isTemporary)
{
auto* pScriptRef = static_cast<RED4ext::ScriptRef<void>*>(pInstance);
pScriptRef->innerType->Destruct(pScriptRef->ref);
Expand Down
3 changes: 3 additions & 0 deletions src/scripting/LuaVM_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ uint64_t LuaVM::HookTweakDBLoad(uintptr_t aThis, uintptr_t aParam)
{
const auto ret = s_vm->m_realTweakDBLoad(aThis, aParam);

// Disable changes tracking added to TweakDB in patch 2.0 and causing instability.
RED4ext::TweakDB::Get()->unk160 = 0;

s_vm->PostInitializeTweakDB();

return ret;
Expand Down

0 comments on commit d885114

Please sign in to comment.