Hi, I'm trying to make a lua executor but it seems to crash as soon as i try to run anything.
Code:
enum LuaInterfaceType
{
LUAINTERFACE_CLIENT = 0,
LUAINTERFACE_SERVER = 1,
LUAINTERFACE_MENU = 2
};
class CLuaShared
{
public:
virtual void padding00() = 0;
virtual void* padding01() = 0;
virtual void* padding02() = 0;
virtual void* padding03() = 0;
virtual void* padding04() = 0;
virtual void* padding05() = 0;
virtual DWORD GetLuaInterface(LuaInterfaceType type) = 0;
};
typedef void* (*CreateInterfaceFn)(const char* Name, int* ReturnCode);
// Lua function prototypes.
typedef int(__cdecl* _luaL_loadstring)(void* state, const char* s);
_luaL_loadstring lua_ls = NULL;
typedef int(__cdecl* _lua_pcall)(void* state, int nargs, int nresults, int errfunc);
_lua_pcall lua_pcall = NULL;
void ExecuteLua(string code) {
HMODULE luaShared = GetModuleHandleA("lua_shared.dll");
if (!luaShared) return console.AddLog("[error] Could not get lua_shared.dll");
CreateInterfaceFn CreateInterface = (CreateInterfaceFn)GetProcAddress(luaShared, "CreateInterface");
if (!CreateInterface) return console.AddLog("[error] Could not get CreateInterface from lua_shared.dll");
CLuaShared* ILuaShared = (CLuaShared*)CreateInterface("LUASHARED003", NULL);
if (!ILuaShared) return console.AddLog("[error] Could not get LUASHARED003 from CLuaShared");
DWORD CLuaInterface = ILuaShared->GetLuaInterface(LUAINTERFACE_CLIENT);
if (!CLuaInterface) return console.AddLog("[error] Could not get LUAINTERFACE_CLIENT from CLuaInterface");
DWORD pGLuaState = *(DWORD*)(CLuaInterface + 0x4);
if (!pGLuaState) return console.AddLog("[error] Could not get pGLuaState from CLuaInterface");
lua_pcall = (_lua_pcall)GetProcAddress(luaShared, "lua_pcall");
if (!lua_pcall) return console.AddLog("[error] Could not get lua_pcall from lua_shared.dll");
lua_ls = (_luaL_loadstring)GetProcAddress(luaShared, "luaL_loadstring");
if (!lua_ls) return console.AddLog("[error] Could not get lua_ls from lua_shared.dll");
lua_ls((void*)pGLuaState, code.c_str());
lua_pcall((void*)pGLuaState, 0, 0, 0);
}
now whenever i try to execute anything via ExecuteLua and a console window if I do a simple print('1') it does it, but if I try again it crashes and anything longer crashes aswell. Does anyone know why?