#include "lua_Offsets.h" #include #include //TODO make a seperate module with peeks/pokes and page permisions (linux/windows spec) //TODO maybe remove alltogether- use DFHack::Process instead? template T engine_peek(size_t offset) { return *(reinterpret_cast(offset)); } template void engine_poke(size_t offset,T val) { *(reinterpret_cast(offset))=val; } void peekarb(size_t offset, void *mem,size_t size) { memcpy(mem,(void*)offset,size); } void peekstr(size_t offset, char* buf, size_t maxsize) { strncpy(buf,(char*)offset,maxsize); } void pokearb(size_t offset, void *mem,size_t size) { memcpy((void*)offset,mem,size); } void pokestr(size_t offset, char* buf, size_t maxsize) { strncpy((char*)offset,buf,maxsize); } //// lua stuff here static int lua_peekb(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_peekw(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_peekd(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_peekq(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_peekfloat(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_peekdouble(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_peekarb(lua_State *L) { lua::state st(L); size_t size=st.as(2); void *p=st.newuserdata(size); peekarb(st.as(1),p,size); return 1; } static int lua_peekstr(lua_State *L) { lua::state st(L); char *buf; buf=new char[256]; peekstr(st.as(1),buf,256); std::string tstr(buf); st.push(tstr); delete [] buf; return 1; } static int lua_peekstr2(lua_State *L) { lua::state st(L); st.push(engine_peek(st.as(1))); return 1; } static int lua_pokeb(lua_State *L) { lua::state st(L); engine_poke(st.as(1),st.as(2)); return 0; } static int lua_pokew(lua_State *L) { lua::state st(L); engine_poke(st.as(1),st.as(2)); return 0; } static int lua_poked(lua_State *L) { lua::state st(L); engine_poke(st.as(1),st.as(2)); return 0; } static int lua_pokeq(lua_State *L) { lua::state st(L); engine_poke(st.as(1),st.as(2)); return 0; } static int lua_pokefloat(lua_State *L) { lua::state st(L); engine_poke(st.as(1),st.as(2)); return 0; } static int lua_pokedouble(lua_State *L) { lua::state st(L); engine_poke(st.as(1),st.as(2)); return 0; } static int lua_pokearb(lua_State *L) { lua::state st(L); void *p=(void *)lua_touserdata(L, 2);//st.as(2); size_t size=st.as(3); pokearb(st.as(1),p,size); return 0; } static int lua_pokestr(lua_State *L) { lua::state st(L); std::string trg=st.as(2); pokestr(st.as(1),(char*)trg.c_str(),trg.size()); return 0; } static int lua_pokestr2(lua_State *L) { lua::state st(L); std::string trg=st.as(2); engine_poke(st.as(1),trg); return 0; } const luaL_Reg lua_engine_func[]= { {"peekb",lua_peekb}, {"peekw",lua_peekw}, {"peekd",lua_peekd}, {"peekq",lua_peekq}, {"peekfloat",lua_peekfloat}, {"peekdouble",lua_peekdouble}, {"peekarb",lua_peekarb}, {"peekstr",lua_peekstr}, {"peekstr2",lua_peekstr2}, {"pokeb",lua_pokeb}, {"pokew",lua_pokew}, {"poked",lua_poked}, {"pokeq",lua_pokeq}, {"pokefloat",lua_pokefloat}, {"pokedouble",lua_pokedouble}, {"pokearb",lua_pokearb}, {"pokestr",lua_pokestr}, {"pokestr2",lua_pokestr2}, {NULL,NULL} }; void lua::RegisterEngine(lua::state &st) { st.getglobal("engine"); if(st.is()) { st.pop(); st.newtable(); } lua::RegFunctionsLocal(st,lua_engine_func); st.setglobal("engine"); }