2
2
3
3
#include " FunctionOverride.h"
4
4
#include " Scripting.h"
5
+ #include < reverse/StrongReference.h>
5
6
6
7
7
8
static FunctionOverride* s_pOverride = nullptr ;
@@ -35,13 +36,13 @@ bool FunctionOverride::HookRunPureScriptFunction(RED4ext::CClassFunction* apFunc
35
36
36
37
auto state = itor->second .pScripting ->GetState ();
37
38
38
- if (apContext->context18 )
39
+ auto pContext = apContext->GetContext ();
40
+ if (pContext)
39
41
{
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));
43
44
44
- args.push_back (Scripting::ToLua (state, self) );
45
+ args.push_back (obj );
45
46
}
46
47
47
48
for (auto * p : apFunction->params )
@@ -208,7 +209,7 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
208
209
}
209
210
else
210
211
{
211
- self.type = ((RED4ext::IScriptable*) apFrame->context ) ->classType ;
212
+ self.type = apFrame->context ->classType ;
212
213
self.value = apFrame->context ;
213
214
}
214
215
@@ -222,7 +223,10 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
222
223
223
224
auto state = context.pScripting ->GetState ();
224
225
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);
226
230
227
231
// Nasty way of popping all args
228
232
for (auto & pArg : apFunction->params )
0 commit comments