Hello, i try to create a new lua function in 3.3.5a but i dont found the offset for the lua_state, can you pls help me ?
source
PHP Code:
#include <windows.h>
extern "C" {
#include "lua/src/lua.h"
#include "lua/src/lualib.h"
#include "lua/src/lauxlib.h"
}
int lua_Test (lua_State *L) {
MessageBox(NULL, "Call Function", "Testing", MB_OK | MB_ICONEXCLAMATION);
int numberOfArgs = lua_gettop(L);
lua_Number n = 42;
lua_pushnumber(L, n);
return 1;
}
void registerLua () {
MessageBox(NULL, "Load registerLua", "Testing", MB_OK | MB_ICONEXCLAMATION);
// 0x00803b70 == lua_pushcclosure; Credits: berserk85
// 0x00804070 == lua_setfield; Credits: berserk85
// 0x00D3F78C == lua_State
lua_State *state = (lua_State*)(*(void **)0x00D3F78C); //< OFFSET need !!!
unsigned char * pCodeCave = (unsigned char *)0x005E7367; // replace before use
DWORD old;
VirtualProtect((LPVOID)pCodeCave, 5, PAGE_EXECUTE_READWRITE, &old);
*(byte *)pCodeCave = 0xe9;
*(int *)(pCodeCave + 1) = (int)lua_Test - (int)pCodeCave - 5;
VirtualProtect((LPVOID)pCodeCave, 5, old, NULL);
lua_pushcclosure(state, (lua_CFunction)(pCodeCave), 0);
lua_setfield(state, -10002, "test");
}
BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD reason, LPVOID reserved) {
MessageBox(NULL, "START", "Testing", MB_OK | MB_ICONEXCLAMATION);
if (reason == DLL_PROCESS_ATTACH) {
// patch TLS to be able to access data from WoW's main thread
_asm {
mov eax, dword ptr fs:[0x2c]
mov eax, dword ptr ds:[eax]
add eax, 8 // current TLS
mov ebx, dword ptr ds:[0x012705b0]
mov ebx, dword ptr ds:[eax + 0x00002d94] // WoW's main thread TLS
mov [eax], ebx // Perform patch
}
registerLua();
}
return TRUE;
}
//Orginal from http://www.ownedcore.com/forums/worl..._register.html
current lua_state (0x00D3F78C) from http://www.ownedcore.com/forums/worl...ml#post1917706