From 183a6e9c35fae1c81fd4be2785dfe86791b8a8d0 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:44:43 +0200 Subject: [PATCH] VScript: add CSquirrelVM::ExecuteFunction() Executes script code by function handle. --- .../languages/squirrel_re/vsquirrel.cpp | 19 +++++++++++++++++-- src/vscript/languages/squirrel_re/vsquirrel.h | 8 +++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/vscript/languages/squirrel_re/vsquirrel.cpp b/src/vscript/languages/squirrel_re/vsquirrel.cpp index a7b6fb3d..90e4f23a 100644 --- a/src/vscript/languages/squirrel_re/vsquirrel.cpp +++ b/src/vscript/languages/squirrel_re/vsquirrel.cpp @@ -106,9 +106,24 @@ SQRESULT CSquirrelVM::RegisterConstant(const SQChar* name, SQInteger value) // Input : *name - // Output : true on success, false otherwise //--------------------------------------------------------------------------------- -bool CSquirrelVM::ExecuteCodeCallback(const SQChar* const callbackName) +bool CSquirrelVM::ExecuteCodeCallback(const SQChar* const name) { - return CSquirrelVM__ExecuteCodeCallback(this, callbackName); + return CSquirrelVM__ExecuteCodeCallback(this, name); +} + +//--------------------------------------------------------------------------------- +// Purpose: executes a function by handle +// Input : hFunction - +// *pArgs - +// nArgs - +// *pReturn - +// hScope - +// Output : SCRIPT_DONE on success, SCRIPT_ERROR otherwise +//--------------------------------------------------------------------------------- +ScriptStatus_t CSquirrelVM::ExecuteFunction(HSCRIPT hFunction, void** pArgs, unsigned int nArgs, void* pReturn, HSCRIPT hScope) +{ + // NOTE: pArgs and pReturn are most likely of type 'ScriptVariant_t', needs to be reversed. + return CSquirrelVM__ExecuteFunction(this, hFunction, pArgs, nArgs, pReturn, hScope); } //--------------------------------------------------------------------------------- diff --git a/src/vscript/languages/squirrel_re/vsquirrel.h b/src/vscript/languages/squirrel_re/vsquirrel.h index 6928195a..b9c312a9 100644 --- a/src/vscript/languages/squirrel_re/vsquirrel.h +++ b/src/vscript/languages/squirrel_re/vsquirrel.h @@ -25,12 +25,14 @@ public: SQRESULT RegisterFunction(const SQChar* scriptname, const SQChar* nativename, const SQChar* helpstring, const SQChar* returntype, const SQChar* parameters, void* functor); SQRESULT RegisterConstant(const SQChar* name, SQInteger value); - bool ExecuteCodeCallback(const SQChar* const callbackName); + bool ExecuteCodeCallback(const SQChar* const name); FORCEINLINE HSQUIRRELVM GetVM() const { return m_hVM; } FORCEINLINE SQCONTEXT GetContext() const { return m_iContext; } FORCEINLINE eDLL_T GetNativeContext() const { return (eDLL_T)GetContext(); } + ScriptStatus_t ExecuteFunction(HSCRIPT hFunction, void** pArgs, unsigned int nArgs, void* pReturn, HSCRIPT hScope); + private: bool unk_00; SQChar pad0[7]; @@ -78,7 +80,9 @@ inline bool(*CSquirrelVM__PrecompileClientScripts)(CSquirrelVM* vm, SQCONTEXT co #ifndef CLIENT_DLL inline bool(*CSquirrelVM__PrecompileServerScripts)(CSquirrelVM* vm, SQCONTEXT context, char** scriptArray, int scriptCount); #endif +inline ScriptStatus_t(*CSquirrelVM__ExecuteFunction)(CSquirrelVM* s, HSCRIPT hFunction, void** pArgs, unsigned int nArgs, void* pReturn, HSCRIPT hScope); inline bool(*CSquirrelVM__ExecuteCodeCallback)(CSquirrelVM* s, const SQChar* callbackName); + inline bool(*CSquirrelVM__ThrowError)(CSquirrelVM* vm, HSQUIRRELVM v); #ifndef CLIENT_DLL @@ -136,6 +140,7 @@ class VSquirrel : public IDetour #ifndef DEDICATED LogFunAdr("CSquirrelVM::PrecompileClientScripts", CSquirrelVM__PrecompileClientScripts); #endif // !DEDICATED + LogFunAdr("CSquirrelVM::ExecuteFunction", CSquirrelVM__ExecuteFunction); LogFunAdr("CSquirrelVM::ExecuteCodeCallback", CSquirrelVM__ExecuteCodeCallback); LogFunAdr("CSquirrelVM::ThrowError", CSquirrelVM__ThrowError); } @@ -155,6 +160,7 @@ class VSquirrel : public IDetour // cl/ui scripts.rson compiling g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 44 0F B6 F0 48 85 DB").FollowNearCallSelf().GetPtr(CSquirrelVM__PrecompileClientScripts); #endif + g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 83 FB 5C").FollowNearCallSelf().GetPtr(CSquirrelVM__ExecuteFunction); g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? C6 47 1C 01").FollowNearCallSelf().GetPtr(CSquirrelVM__ExecuteCodeCallback); g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? BB ?? ?? ?? ?? 8B C3").FollowNearCallSelf().GetPtr(CSquirrelVM__ThrowError); }