From 148afde4ebb33272b329bb6fd84f786c7cfdac41 Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 9 Aug 2011 11:00:20 +0300 Subject: [PATCH 1/3] finnaly fixed the VersionInfo. Should work now. --- plugins/Dfusion/src/lua_VersionInfo.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/Dfusion/src/lua_VersionInfo.cpp b/plugins/Dfusion/src/lua_VersionInfo.cpp index 9ee67c53e..8f909d686 100644 --- a/plugins/Dfusion/src/lua_VersionInfo.cpp +++ b/plugins/Dfusion/src/lua_VersionInfo.cpp @@ -38,10 +38,11 @@ int OffsetGroup::getGroup(lua_State *L) { lua::state st(L); DFHack::OffsetGroup* t= p->getGroup(st.as(2)); - st.getglobal("OffsetGroup"); + st.getglobal("OffsetGroup"); st.getfield("new"); + st.getglobal("OffsetGroup"); st.pushlightuserdata(t); - st.pcall(1,1); + st.pcall(2,1); return 1; } int OffsetGroup::getSafeOffset(lua_State *L) @@ -88,10 +89,11 @@ int OffsetGroup::getParent(lua_State *L) { lua::state st(L); DFHack::OffsetGroup* t= p->getParent(); - st.getglobal("OffsetGroup"); + st.getglobal("OffsetGroup"); st.getfield("new"); + st.getglobal("OffsetGroup"); st.pushlightuserdata(t); - st.pcall(1,1); + st.pcall(2,1); return 1; } } @@ -324,21 +326,23 @@ static int __lua_getHexValue(lua_State *S) static int __lua_getGroup(lua_State *S) { lua::state st(S); - DFHack::OffsetGroup* t= DFHack::Core::getInstance().vinfo->getGroup(st.as(2)); + DFHack::OffsetGroup* t= DFHack::Core::getInstance().vinfo->getGroup(st.as(1)); st.getglobal("OffsetGroup"); st.getfield("new"); + st.getglobal("OffsetGroup"); st.pushlightuserdata(t); - st.pcall(1,1); + st.pcall(2,1); return 1; } static int __lua_getParent(lua_State *S) { lua::state st(S); DFHack::OffsetGroup* t= DFHack::Core::getInstance().vinfo->getParent(); - st.getglobal("OffsetGroup"); + st.getglobal("OffsetGroup"); st.getfield("new"); + st.getglobal("OffsetGroup"); st.pushlightuserdata(t); - st.pcall(1,1); + st.pcall(2,1); return 1; } static int __lua_getSafeOffset(lua_State *S) From a94ba4392c4ee0b7b301392339ca1e8417df689b Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 9 Aug 2011 11:31:51 +0300 Subject: [PATCH 2/3] small fixes to VersionInfo wrapper, added Current_Race in Memory.xml to new version and ported friendship plugin to memory.xml model --- Memory.xml | 1 + plugins/Dfusion/dfusion.cpp | 8 ++++---- plugins/Dfusion/luafiles/common.lua | 4 +++- plugins/Dfusion/luafiles/friendship/patch.lua | 2 +- plugins/Dfusion/luafiles/friendship/plugin.lua | 13 +++++++++---- plugins/Dfusion/src/lua_VersionInfo.cpp | 16 ++++++++-------- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Memory.xml b/Memory.xml index c7a59ca94..7126413b5 100644 --- a/Memory.xml +++ b/Memory.xml @@ -2263,6 +2263,7 @@
+
diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index 2a013328d..512292777 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -77,7 +77,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) catch(lua::exception &e) { c->con.printerr("Error OnTick:%s\n",e.what()); - c->con.printerr("%s",lua::DebugDump(lua::glua::Get()).c_str()); + c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); c->con.msleep(1000); } } @@ -104,7 +104,7 @@ void InterpreterLoop(Core* c) catch(lua::exception &e) { con.printerr("Error:%s\n",e.what()); - c->con.printerr("%s",lua::DebugDump(lua::glua::Get()).c_str()); + c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); s.settop(0); } con.lineedit(">>",curline); @@ -125,7 +125,7 @@ DFhackCExport command_result lua_run (Core * c, vector & parameters) catch(lua::exception &e) { con.printerr("Error:%s\n",e.what()); - c->con.printerr("%s",lua::DebugDump(lua::glua::Get()).c_str()); + c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); } } else @@ -150,7 +150,7 @@ DFhackCExport command_result dfusion (Core * c, vector & parameters) catch(lua::exception &e) { con.printerr("Error:%s\n",e.what()); - c->con.printerr("%s",lua::DebugDump(lua::glua::Get()).c_str()); + c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); } s.settop(0);// clean up mymutex->unlock(); diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua index 21e89fe20..912862d56 100644 --- a/plugins/Dfusion/luafiles/common.lua +++ b/plugins/Dfusion/luafiles/common.lua @@ -321,7 +321,9 @@ function findVectors() end function GetRaceToken(p) --actually gets token... - local vec=engine.peek(offsets.getEx('CreatureGloss'),ptr_vector) + print(string.format("%x vs %x",offsets.getEx('CreatureGloss'),VersionInfo.getGroup("Materials"):getAddress("creature_type_vector"))) + --local vec=engine.peek(offsets.getEx('CreatureGloss'),ptr_vector) + local vec=engine.peek(VersionInfo.getGroup("Materials"):getAddress("creature_type_vector"),ptr_vector) --print("Vector ok") local off=vec:getval(p) --print("Offset:"..off) diff --git a/plugins/Dfusion/luafiles/friendship/patch.lua b/plugins/Dfusion/luafiles/friendship/patch.lua index b11ad41da..6707e4155 100644 --- a/plugins/Dfusion/luafiles/friendship/patch.lua +++ b/plugins/Dfusion/luafiles/friendship/patch.lua @@ -1,6 +1,6 @@ function friendship_in.patch() pos=GetTextRegion().start - local crace=offsets.getEx("CurrentRace") + local crace=add_race --offsets.getEx("CurrentRace") hits={} i=1 repeat diff --git a/plugins/Dfusion/luafiles/friendship/plugin.lua b/plugins/Dfusion/luafiles/friendship/plugin.lua index 2a317afe0..e820a0ccd 100644 --- a/plugins/Dfusion/luafiles/friendship/plugin.lua +++ b/plugins/Dfusion/luafiles/friendship/plugin.lua @@ -40,10 +40,15 @@ end Two more compares are missing. There are calls instead (same function) ]]-- if not(FILE) then -print("race num:"..engine.peekw(offsets.getEx("CurrentRace"))) -print("Your current race is:"..GetRaceToken(engine.peekw(offsets.getEx('CurrentRace')))) -print("If this is wrong please quit now (by ctrl+c)") -io.stdin:read() +--print("race num:"..engine.peekw(offsets.getEx("CurrentRace"))) +--print(string.format("%x vs %x",offsets.getEx("CurrentRace"),VersionInfo.getGroup("Creatures"):getAddress("current_race"))) +add_race=VersionInfo.getGroup("Creatures"):getAddress("current_race") +print("Race num:"..engine.peekw(add_race)) +print("Your current race is:"..GetRaceToken(engine.peekw(add_race))) +print("If this is wrong please type 'q'") +if(io.stdin:read()=='q') then + return +end end friendship_in={} dofile("dfusion/friendship/install.lua") diff --git a/plugins/Dfusion/src/lua_VersionInfo.cpp b/plugins/Dfusion/src/lua_VersionInfo.cpp index 8f909d686..538de7360 100644 --- a/plugins/Dfusion/src/lua_VersionInfo.cpp +++ b/plugins/Dfusion/src/lua_VersionInfo.cpp @@ -9,35 +9,35 @@ OffsetGroup::OffsetGroup(lua_State *L,int id):tblid(id) int OffsetGroup::getOffset(lua_State *L) { lua::state st(L); - int32_t ret=p->getOffset(st.as(2)); + int32_t ret=p->getOffset(st.as(1)); st.push(ret); return 1; } int OffsetGroup::getAddress(lua_State *L) { lua::state st(L); - uint32_t ret=p->getAddress(st.as(2)); + uint32_t ret=p->getAddress(st.as(1)); st.push(ret); return 1; } int OffsetGroup::getHexValue(lua_State *L) { lua::state st(L); - uint32_t ret=p->getHexValue(st.as(2)); + uint32_t ret=p->getHexValue(st.as(1)); st.push(ret); return 1; } int OffsetGroup::getString(lua_State *L) { lua::state st(L); - std::string ret=p->getString(st.as(2)); + std::string ret=p->getString(st.as(1)); st.push(ret); return 1; } int OffsetGroup::getGroup(lua_State *L) { lua::state st(L); - DFHack::OffsetGroup* t= p->getGroup(st.as(2)); + DFHack::OffsetGroup* t= p->getGroup(st.as(1)); st.getglobal("OffsetGroup"); st.getfield("new"); st.getglobal("OffsetGroup"); @@ -49,7 +49,7 @@ int OffsetGroup::getSafeOffset(lua_State *L) { lua::state st(L); int32_t out; - bool ret=p->getSafeOffset(st.as(2),out); + bool ret=p->getSafeOffset(st.as(1),out); st.push(ret); st.push(out); return 2; @@ -58,7 +58,7 @@ int OffsetGroup::getSafeAddress(lua_State *L) { lua::state st(L); uint32_t out; - bool ret=p->getSafeAddress(st.as(2),out); + bool ret=p->getSafeAddress(st.as(1),out); st.push(ret); st.push(out); return 2; @@ -67,7 +67,7 @@ int OffsetGroup::PrintOffsets(lua_State *L) { lua::state st(L); std::string output; - output=p->PrintOffsets(st.as(2)); + output=p->PrintOffsets(st.as(1)); st.push(output); return 1; } From 3f6f33fb94f896f8e1f1a32f10f8eeddde1bba14 Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 9 Aug 2011 11:37:59 +0300 Subject: [PATCH 3/3] Embark plugin to memory.xml model --- plugins/Dfusion/luafiles/embark/plugin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Dfusion/luafiles/embark/plugin.lua b/plugins/Dfusion/luafiles/embark/plugin.lua index d9bd4ffb5..db65da78c 100644 --- a/plugins/Dfusion/luafiles/embark/plugin.lua +++ b/plugins/Dfusion/luafiles/embark/plugin.lua @@ -41,7 +41,7 @@ function embark(names) count=MakeTable(modpos,modsize,names) --just remake tables else - tofind=offsets.getEx('CurrentRace') + tofind=VersionInfo.getGroup("Creatures"):getAddress("current_race")--offsets.getEx('CurrentRace') loc=offsets.find(stoff,0xa1,DWORD_,tofind)