#include "stdafx.h"
typedef int (__cdecl* luaL_loadstring_t)(lua_State *L, const char *s);
typedef int (__cdecl* lua_pcall_t)(lua_State* L, int nargs, int nresults, int errfunc);
typedef const char* (__cdecl* lua_tolstring_t)(lua_State *L, int idx, size_t *len);
typedef int (__thiscall* runData_t)(PaydayLua*, int, const char*);
luaL_loadstring_t pluaL_loadstring = (luaL_loadstring_t) 0x007BBC40;
lua_pcall_t plua_pcall = (lua_pcall_t) 0x007ACA10;
lua_tolstring_t plua_tolstring = (lua_tolstring_t) 0x007A6680;
_luaL_loadfile loadfile = (_luaL_loadfile)0x007BB9A0;
runData_t prunData = NULL;
void exec(lua_State* L, char* s)
{
gApp.AddToLogFileA("p.log", "Executing buffer...");
if(L == NULL)
{
gApp.AddToLogFileA("p.log", "L is NULL");
return;
}
//Load
int r1 = pluaL_loadstring(L, s);
if(r1 != 0)
{
if( LUA_ERRSYNTAX == r1 )
{
gApp.AddToLogFileA( "p.log", "Error loading Lua code into buffer with name (Syntax Error)[%s]", plua_tolstring(L, -1, NULL));
}
else if( LUA_ERRMEM == r1 )
{
gApp.AddToLogFileA( "p.log", "Error loading Lua code into buffer with name (Memory Allocation Error)[%s]", plua_tolstring(L, -1, NULL));
}
else
{
gApp.AddToLogFileA( "p.log", "Error loading Lua code into buffer with name (%i)", r1 );
}
return;
}
gApp.AddToLogFileA("p.log", "Load Success!");
//Call
int r2 = plua_pcall(L, 0, LUA_MULTRET, 0);
if(r2 != 0)
{
if( LUA_ERRRUN == r2 )
{
gApp.AddToLogFileA( "p.log", "Error calling Lua code (Runtime Error)[%s]", plua_tolstring(L, -1, NULL));
}
else if( LUA_ERRMEM == r2 )
{
gApp.AddToLogFileA( "p.log", "Error calling Lua code (Memory Allocation Error)[%s]", plua_tolstring(L, -1, NULL));
}
else if( LUA_ERRERR == r2 )
{
gApp.AddToLogFileA( "p.log", "Error calling Lua code (Error while running error handler)[%s]", plua_tolstring(L, -1, NULL));
}
else
{
gApp.AddToLogFileA( "p.log", "Error calling Lua code (%i)", r2 );
}
return;
}
gApp.AddToLogFileA("p.log", "Call Success!");
}
int __fastcall new_runData(PaydayLua* pthis, void* _EDX, int a2, const char* desc)
{
if(!_stricmp(desc, "update") && pthis->state)
{
if(GetAsyncKeyState(VK_INSERT) & 1)
{
exec(pthis->state, "print(\"s0beit rulz da moon\")");
}
}
return prunData(pthis, a2, desc);
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
if(dwReason == DLL_PROCESS_ATTACH)
{
gApp.BaseUponModule(hModule);
gApp.AddToLogFileA("p.log", "PAYDAY 2 LUA HACK INITIALIZE");
prunData = (runData_t) DetourFunction((BYTE*)0x759A10, (BYTE*)new_runData);
}
return TRUE;
}