Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 2.0 fixes #864

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading