From 8e68b50ed7460dd2f13367f10302c8fab45bd80f Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 21 Aug 2011 01:46:16 +0300 Subject: [PATCH] Linux tinkerings, moved few offsets and part of creature pattern into memory.xml model --- plugins/Dfusion/luafiles/common.lua | 4 +- plugins/Dfusion/luafiles/onfunction/init.lua | 57 ++++++++++++++++ .../Dfusion/luafiles/onfunction/plugin.lua | 66 ++----------------- plugins/Dfusion/luafiles/patterns.lua | 7 +- plugins/Dfusion/src/lua_Misc.cpp | 4 +- 5 files changed, 72 insertions(+), 66 deletions(-) create mode 100644 plugins/Dfusion/luafiles/onfunction/init.lua diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua index 798d19c58..83794fb44 100644 --- a/plugins/Dfusion/luafiles/common.lua +++ b/plugins/Dfusion/luafiles/common.lua @@ -438,7 +438,7 @@ function ParseNames(path) end function getxyz() -- this will return pointers x,y and z coordinates. - local off=offsets.getEx("Xpointer") -- lets find where in memory its being held + local off=VersionInfo.getGroup("Position"):getAddress("cursor_xyz") -- lets find where in memory its being held -- now lets read them (they are double words (or unsigned longs or 4 bits each) and go in sucesion local x=engine.peekd(off) local y=engine.peekd(off+4) --next is 4 from start @@ -448,7 +448,7 @@ function getxyz() -- this will return pointers x,y and z coordinates. end function GetCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord --local x,y,z=getxyz() --get 'X' coords - local vector=engine.peek(offsets.getEx("AdvCreatureVec"),ptr_vector) -- load all creatures + local vector=engine.peek(VersionInfo.getGroup("Creatures"):getAddress("vector"),ptr_vector) -- load all creatures for i = 0, vector:size()-1 do -- look into all creatures offsets local curoff=vector:getval(i) -- get i-th creatures offset local cx=engine.peek(curoff,ptr_Creature.x) --get its coordinates diff --git a/plugins/Dfusion/luafiles/onfunction/init.lua b/plugins/Dfusion/luafiles/onfunction/init.lua new file mode 100644 index 000000000..5adb73036 --- /dev/null +++ b/plugins/Dfusion/luafiles/onfunction/init.lua @@ -0,0 +1,57 @@ +onfunction=onfunction or {} +function onfunction.install() + ModData=engine.installMod("dfusion/onfunction/functions.o","functions",4) + modpos=ModData.pos + modsize=ModData.size + onfunction.pos=modpos + trgpos=engine.getpushvalue() + print(string.format("Function installed in:%x function to call is: %x",modpos,trgpos)) + local firstpos=modpos+engine.FindMarker(ModData,"function") + engine.poked(firstpos,trgpos-firstpos-4) --call Lua-Onfunction + onfunction.fpos=modpos+engine.FindMarker(ModData,"function3") + engine.poked(modpos+engine.FindMarker(ModData,"function2"),modpos+modsize) + engine.poked(onfunction.fpos,modpos+modsize) + SetExecute(modpos) + onfunction.calls={} + onfunction.functions={} + onfunction.names={} +end +function OnFunction(values) + --[=[print("Onfunction called!") + print("Data:") + for k,v in pairs(values) do + print(string.format("%s=%x",k,v)) + end + print("stack:") + for i=0,3 do + print(string.format("%d %x",i,engine.peekd(values.esp+i*4))) + end + --]=] + if onfunction.functions[values.ret] ~=nil then + onfunction.functions[values.ret](values) + end + + return onfunction.calls[values.ret] --returns real function to call +end +function onfunction.patch(addr) + + if(engine.peekb(addr)~=0xe8) then + error("Incorrect address, not a function call") + else + + onfunction.calls[addr+5]=addr+engine.peekd(addr+1)+5 --adds real function to call + engine.poked(addr+1,engine.getmod("functions")-addr-5) + end +end +function onfunction.AddFunction(addr,name) + onfunction.patch(addr) + onfunction.names[name]=addr+5 +end +function onfunction.SetCallback(name,func) + if onfunction.names[name]==nil then + error("No such function:"..name) + else + onfunction.functions[onfunction.names[name]]=func + end +end + diff --git a/plugins/Dfusion/luafiles/onfunction/plugin.lua b/plugins/Dfusion/luafiles/onfunction/plugin.lua index 8813b0c8b..d3e4d3c16 100644 --- a/plugins/Dfusion/luafiles/onfunction/plugin.lua +++ b/plugins/Dfusion/luafiles/onfunction/plugin.lua @@ -1,59 +1,3 @@ -onfunction=onfunction or {} -function onfunction.install() - ModData=engine.installMod("dfusion/onfunction/functions.o","functions",4) - modpos=ModData.pos - modsize=ModData.size - onfunction.pos=modpos - trgpos=engine.getpushvalue() - print(string.format("Function installed in:%x function to call is: %x",modpos,trgpos)) - local firstpos=modpos+engine.FindMarker(ModData,"function") - engine.poked(firstpos,trgpos-firstpos-4) --call Lua-Onfunction - onfunction.fpos=modpos+engine.FindMarker(ModData,"function3") - engine.poked(modpos+engine.FindMarker(ModData,"function2"),modpos+modsize) - engine.poked(onfunction.fpos,modpos+modsize) - SetExecute(modpos) - onfunction.calls={} - onfunction.functions={} - onfunction.names={} -end -function OnFunction(values) - --[=[print("Onfunction called!") - print("Data:") - for k,v in pairs(values) do - print(string.format("%s=%x",k,v)) - end - print("stack:") - for i=0,3 do - print(string.format("%d %x",i,engine.peekd(values.esp+i*4))) - end - --]=] - if onfunction.functions[values.ret] ~=nil then - onfunction.functions[values.ret](values) - end - - return onfunction.calls[values.ret] --returns real function to call -end -function onfunction.patch(addr) - - if(engine.peekb(addr)~=0xe8) then - error("Incorrect address, not a function call") - else - - onfunction.calls[addr+5]=addr+engine.peekd(addr+1)+5 --adds real function to call - engine.poked(addr+1,engine.getmod("functions")-addr-5) - end -end -function onfunction.AddFunction(addr,name) - onfunction.patch(addr) - onfunction.names[name]=addr+5 -end -function onfunction.SetCallback(name,func) - if onfunction.names[name]==nil then - error("No such function:"..name) - else - onfunction.functions[onfunction.names[name]]=func - end -end mypos=engine.getmod("functions") function DeathMsg(values) name=engine.peek(values.edi,ptt_dfstring) @@ -64,7 +8,11 @@ if mypos then --onfunction.patch(0x189dd6+offsets.base()) else onfunction.install() - onfunction.AddFunction(0x55499D+offsets.base(),"Move") --on creature move found with "watch mem=xcoord" - onfunction.AddFunction(0x275933+offsets.base(),"Die") --on creature death? found by watching dead flag then stepping until new function + if WINDOWS then + onfunction.AddFunction(0x55499D+offsets.base(),"Move") --on creature move found with "watch mem=xcoord" + onfunction.AddFunction(0x275933+offsets.base(),"Die") --on creature death? found by watching dead flag then stepping until new function + else + + end onfunction.SetCallback("Die",DeathMsg) -end \ No newline at end of file +end diff --git a/plugins/Dfusion/luafiles/patterns.lua b/plugins/Dfusion/luafiles/patterns.lua index f4ac43650..baffe09eb 100644 --- a/plugins/Dfusion/luafiles/patterns.lua +++ b/plugins/Dfusion/luafiles/patterns.lua @@ -169,9 +169,10 @@ end ]]-- ptr_Creature={} -ptr_Creature.x={off=144,rtype=WORD} --ok -ptr_Creature.y={off=146,rtype=WORD} --ok -ptr_Creature.z={off=148,rtype=WORD} --ok +local posoff=VersionInfo.getGroup("Creatures"):getGroup("creature"):getOffset("position") +ptr_Creature.x={off=posoff,rtype=WORD} --ok +ptr_Creature.y={off=posoff+2,rtype=WORD} --ok +ptr_Creature.z={off=posoff+4,rtype=WORD} --ok ptr_Creature.flags={off=224,rtype=ptt_dfflag.new(10)} ptr_Creature.name={off=0,rtype=ptt_dfstring} ptr_Creature.ID={off=252,rtype=DWORD} --ok i guess diff --git a/plugins/Dfusion/src/lua_Misc.cpp b/plugins/Dfusion/src/lua_Misc.cpp index 5ac4bd73b..be1de4a24 100644 --- a/plugins/Dfusion/src/lua_Misc.cpp +++ b/plugins/Dfusion/src/lua_Misc.cpp @@ -129,7 +129,7 @@ static int GetMod(lua_State *L) st.push(pos); return 1; } -static size_t __stdcall PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t edi,uint32_t esi,uint32_t esp,uint32_t ebp) +static size_t __attribute__((stdcall)) PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t edi,uint32_t esi,uint32_t esp,uint32_t ebp) { lua::state st=lua::glua::Get(); st.getglobal("OnFunction"); @@ -184,4 +184,4 @@ void lua::RegisterMisc(lua::state &st) } lua::RegFunctionsLocal(st, lua_misc_func); st.setglobal("engine"); -} \ No newline at end of file +}