Skip to content

Commit 1db1b17

Browse files
committed
Fix deep in game crash when using RegisterInputListener from an observer
1 parent b0ca824 commit 1db1b17

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/scripting/FunctionOverride.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "FunctionOverride.h"
44
#include "Scripting.h"
5+
#include <reverse/StrongReference.h>
56

67

78
static FunctionOverride* s_pOverride = nullptr;
@@ -35,13 +36,13 @@ bool FunctionOverride::HookRunPureScriptFunction(RED4ext::CClassFunction* apFunc
3536

3637
auto state = itor->second.pScripting->GetState();
3738

38-
if (apContext->context18)
39+
auto pContext = apContext->GetContext();
40+
if (pContext)
3941
{
40-
RED4ext::CStackType self;
41-
self.type = reinterpret_cast<RED4ext::IScriptable*>(apContext->context18)->classType;
42-
self.value = apContext->context18;
42+
const auto handle = RED4ext::Handle<RED4ext::IScriptable>(pContext);
43+
auto obj = sol::make_object(state.Get(), StrongReference(state, handle));
4344

44-
args.push_back(Scripting::ToLua(state, self));
45+
args.push_back(obj);
4546
}
4647

4748
for (auto* p : apFunction->params)
@@ -208,7 +209,7 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
208209
}
209210
else
210211
{
211-
self.type = ((RED4ext::IScriptable*)apFrame->context)->classType;
212+
self.type = apFrame->context->classType;
212213
self.value = apFrame->context;
213214
}
214215

@@ -222,7 +223,10 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
222223

223224
auto state = context.pScripting->GetState();
224225

225-
args.push_back(Scripting::ToLua(state, self)); // Push self
226+
const auto handle = RED4ext::Handle<RED4ext::IScriptable>((RED4ext::IScriptable*)self.value);
227+
auto obj = sol::make_object(state.Get(), StrongReference(state, handle));
228+
229+
args.push_back(obj);
226230

227231
// Nasty way of popping all args
228232
for (auto& pArg : apFunction->params)

0 commit comments

Comments
 (0)