Skip to content

Commit

Permalink
Trying to fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Apr 4, 2024
1 parent 86efd9e commit f525b13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions source/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ llua_getstack func_lua_getstack;
llua_getinfo func_lua_getinfo;
llua_pushstring func_lua_pushstring;
llua_setfield func_lua_setfield;
luaL_loadbuffer func_luaL_loadbuffer;
GMOD_LoadBinaryModule func_GMOD_LoadBinaryModule;

TInitLuaLibraries func_InitLuaLibraries;
Expand Down Expand Up @@ -142,6 +143,9 @@ void Symbols_Init()
func_lua_setfield = (llua_setfield)FindFunction(lua_shared_loader.GetModule(), lua_setfieldSym);
CheckFunction(func_lua_setfield, "lua_setfield");

func_luaL_loadbuffer = (luaL_loadbuffer)FindFunction(lua_shared_loader.GetModule(), luaL_loadbufferSym);
CheckFunction(func_luaL_loadbuffer, "luaL_loadbuffer");

func_GMOD_LoadBinaryModule = (GMOD_LoadBinaryModule)FindFunction(lua_shared_loader.GetModule(), GMOD_LoadBinaryModuleSym);
CheckFunction(func_GMOD_LoadBinaryModule, "GMOD_LoadBinaryModule");

Expand Down
4 changes: 4 additions & 0 deletions source/detours.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ typedef const char* (*llua_setfield)(lua_State*, int, const char*);
extern llua_setfield func_lua_setfield;
const Symbol lua_setfieldSym = Symbol::FromName("lua_setfield");

typedef int (*luaL_loadbuffer)(lua_State*, const char*, size_t, const char*);
extern luaL_loadbuffer func_luaL_loadbuffer;
const Symbol luaL_loadbufferSym = Symbol::FromName("luaL_loadbuffer");

typedef const char* (*GMOD_LoadBinaryModule)(lua_State*, const char*);
extern GMOD_LoadBinaryModule func_GMOD_LoadBinaryModule;
const Symbol GMOD_LoadBinaryModuleSym = Symbol::FromName("GMOD_LoadBinaryModule");
Expand Down
9 changes: 4 additions & 5 deletions source/lua_ILuaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,19 @@ void HandleError(ILuaInterface* LUA, int result, const char* pFile)
void RunString(ILuaThread* thread, const char* str, const char* pFile)
{
ILuaInterface* LUA = thread->IFace;
/*if (setjmp(thread->jumpBuffer) == 0)
if (setjmp(thread->jumpBuffer) == 0)
{
int result = func_luaL_loadstring(LUA->GetState(), str);
int result = func_luaL_loadbuffer(LUA->GetState(), str, strlen(str), pFile);
HandleError(LUA, result, pFile);
}
else
{
HandleError(LUA, -1, pFile); // Could crash if the Lua Panic wan't created by pcall or loadstring.
}*/
}

if (setjmp(thread->jumpBuffer) == 0)
{
int result = LUA->RunString(pFile, "", str, true, true) ? 0 : 1;
//int result = func_lua_pcall(LUA->GetState(), 0, 0, 0); // ToDo: Find out why it sometimes crashes :< (lj_BC_TGETS)
int result = func_lua_pcall(LUA->GetState(), 0, 0, 0); // ToDo: Find out why it sometimes crashes :< (lj_BC_TGETS)
HandleError(LUA, result, pFile);
}
else
Expand Down

0 comments on commit f525b13

Please sign in to comment.