diff options
| author | Warmist | 2012-03-18 12:24:28 +0200 |
|---|---|---|
| committer | Warmist | 2012-03-18 12:24:28 +0200 |
| commit | 3383aa7f6dda8ecbcdb69d1dbe0e1292f9da7185 (patch) | |
| tree | 427a11282e2c6f3a0589633900b0c4940afd948f /plugins/Dfusion | |
| parent | 5367d2811099b5cbb0bedee7719321bf202ef3b7 (diff) | |
| download | dfhack-3383aa7f6dda8ecbcdb69d1dbe0e1292f9da7185.tar.gz dfhack-3383aa7f6dda8ecbcdb69d1dbe0e1292f9da7185.tar.bz2 dfhack-3383aa7f6dda8ecbcdb69d1dbe0e1292f9da7185.tar.xz | |
New pointer, setup pointer and df-array. ALso new tool, empregnate.
Diffstat (limited to 'plugins/Dfusion')
| -rw-r--r-- | plugins/Dfusion/luafiles/common.lua | 9 | ||||
| -rw-r--r-- | plugins/Dfusion/luafiles/editor.lua | 5 | ||||
| -rw-r--r-- | plugins/Dfusion/luafiles/embark/races.txt | 16 | ||||
| -rw-r--r-- | plugins/Dfusion/luafiles/tools/init.lua | 30 | ||||
| -rw-r--r-- | plugins/Dfusion/luafiles/xml_types.lua | 41 | ||||
| -rw-r--r-- | plugins/Dfusion/luafiles/xml_types_windows.lua | 2 | ||||
| -rw-r--r-- | plugins/Dfusion/src/lua_Misc.cpp | 17 |
7 files changed, 103 insertions, 17 deletions
diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua index 85758102..9a800467 100644 --- a/plugins/Dfusion/luafiles/common.lua +++ b/plugins/Dfusion/luafiles/common.lua @@ -467,7 +467,14 @@ function ParseNames(path) end return ret end - +function getSelectedUnit() + local unit_indx=df.ui_selected_unit + if unit_indx<df.world.units.other[0].size then + return df.world.units.other[0][unit_indx]:deref() + else + return nil + end +end function getxyz() -- this will return pointers x,y and z coordinates. 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 diff --git a/plugins/Dfusion/luafiles/editor.lua b/plugins/Dfusion/luafiles/editor.lua index 53d2c5b0..1f004b2d 100644 --- a/plugins/Dfusion/luafiles/editor.lua +++ b/plugins/Dfusion/luafiles/editor.lua @@ -88,6 +88,7 @@ EditType["static-array"]=function(trg) end end EditType["stl-vector"]=EditType["static-array"] +EditType["df-array"]=EditType["static-array"] EditType["struct-type"]=function(trg) local mtype=rawget(trg,"mtype") local fields=getFields(trg) @@ -104,6 +105,10 @@ end EditType["pointer"]=function(trg) local mtype=rawget(trg,"mtype").ptype local typename=getTypename(mtype) + if(trg:tonumber()==0) then + print("pointer points to nowhere!") + return + end print("Auto dereferencing pointer! type:"..typename) if EditType[typename] ~= nil then EditType[typename](trg:deref()) diff --git a/plugins/Dfusion/luafiles/embark/races.txt b/plugins/Dfusion/luafiles/embark/races.txt index 52f475bf..37692886 100644 --- a/plugins/Dfusion/luafiles/embark/races.txt +++ b/plugins/Dfusion/luafiles/embark/races.txt @@ -1,7 +1,9 @@ -DWARF:1 -ELF:0 -ELF:0 -DWARF:0 -DWARF:0 -HUMAN:0 -HUMAN:0
\ No newline at end of file +ANT_MAN:0 +ANT_MAN:0 +ANT_MAN:0 +ANT_MAN:1 +ANT_MAN:1 +ANT_MAN:0 +ANT_MAN:0 +ANT_MAN:2 +ANT_MAN:3
\ No newline at end of file diff --git a/plugins/Dfusion/luafiles/tools/init.lua b/plugins/Dfusion/luafiles/tools/init.lua index 8381b1d0..a12a0148 100644 --- a/plugins/Dfusion/luafiles/tools/init.lua +++ b/plugins/Dfusion/luafiles/tools/init.lua @@ -260,6 +260,36 @@ function tools.changesite(names) print(string.format("%x->%d",off,n2)) engine.poke(off,ptr_site.type,n2) end +function tools.empregnate(unit) + if unit==nil then + unit=getSelectedUnit() + end + if unit==nil then + error("Failed to empregnate. Unit not selected/valide") + end + local arr1=unit.appearance.unk_51c + local arr2=unit.appearance.unk_51c + local created=false + if unit.relations.pregnancy_ptr:tonumber()==0 then + print("creating preg ptr.") + unit.relations.pregnancy_ptr:newref() + created=true + end + local tarr1=unit.relations.pregnancy_ptr:deref().anon_1 + local tarr2=unit.relations.pregnancy_ptr:deref().anon_2 + if created or tarr1.size~= arr1.size then + print("Setting up arr1") + initType(tarr1,arr1.size) + end + if created or tarr2.size~= arr2.size then + print("Setting up arr1") + initType(tarr2,arr2.size) + end + print("Setting preg timer.") + unit.relations.pregnancy_timer=10 + unit.relations.pregnancy_mystery=1 +end +tools.menu:add("Empregnate",tools.empregnate) function tools.changeflags(names) myflag_pattern=ptt_dfflag.new(3*8) off=tools.getsite(names) diff --git a/plugins/Dfusion/luafiles/xml_types.lua b/plugins/Dfusion/luafiles/xml_types.lua index b3fa6723..eff9b20a 100644 --- a/plugins/Dfusion/luafiles/xml_types.lua +++ b/plugins/Dfusion/luafiles/xml_types.lua @@ -418,6 +418,13 @@ function type_pointer.wrap:tonumber() local myptr=rawget(self,"ptr") return engine.peekd(myptr)--type_read(DWORD,myptr) end +function type_pointer.wrap:__setup(trg) + if trg~= nil then + self:fromnumber(trg) + else + self:fromnumber(0) + end +end function type_pointer.wrap:fromnumber(num) local myptr=rawget(self,"ptr") return engine.poked(myptr,num)--type_write(DWORD,myptr,num) @@ -432,6 +439,13 @@ function type_pointer.wrap:setref(val) local mytype=rawget(self,"mtype") return type_write(mytype.ptype,engine.peekd(myptr),val) end +function type_pointer.wrap:newref(val) + local myptr=rawget(self,"ptr") + local mytype=rawget(self,"mtype") + local ptr=engine.alloc(mytype.ptype.size) + self:fromnumber(ptr) + return ptr +end function type_pointer:makewrap(ptr) local o={} o.ptr=ptr @@ -451,6 +465,7 @@ function dfarr.new(node,obj) setmetatable(o,dfarr) o.size=8 o.__align=4 + o.item_type=makeType(first_of_type(node,"ld:item")) return o end function dfarr:makewrap(address) @@ -461,24 +476,34 @@ function dfarr:makewrap(address) return o end dfarr.wrap={} +function dfarr.wrap:__setup(size) + local mtype=rawget(self,"mtype") + engine.pokew(rawget(self,"ptr")+4,size) + local newptr=engine.alloc(size*mtype.item_type.size) + engine.poked(rawget(self,"ptr"),newptr) +end function dfarr.wrap:__index(key) local num=tonumber(key) local mtype=rawget(self,"mtype") - local size=type_read(rawget(self,"ptr")+4,DWORD) - error("TODO make __index for dfarray") + local size=engine.peekw(rawget(self,"ptr")+4) + if key=="size" then + return size + end + local item_start=engine.peekd(rawget(self,"ptr")) if num~=nil and num<sizethen then - return type_read(mtype.ctype,num*mtype.ctype.size+rawget(self,"ptr")) + return type_read(mtype.item_type,num*mtype.item_type.size+item_start) else - error("invalid key to df-flagarray") + error("invalid key to df-array") end end function dfarr.wrap:__newindex(key,val) local num=tonumber(key) - error("TODO make __index for dfarray") - if num~=nil and num<rawget(self,"mtype").count then - return type_write(mtype.ctype,num*mtype.ctype.size+rawget(self,"ptr"),val) + local size=engine.peekw(rawget(self,"ptr")+4) + local item_start=engine.peekd(rawget(self,"ptr")) + if num~=nil and num<size then + return type_write(mtype.item_type,num*mtype.item_type.size+item_start,val) else - error("invalid key to static-array") + error("invalid key to df-array") end end diff --git a/plugins/Dfusion/luafiles/xml_types_windows.lua b/plugins/Dfusion/luafiles/xml_types_windows.lua index b1a64a47..90bc8031 100644 --- a/plugins/Dfusion/luafiles/xml_types_windows.lua +++ b/plugins/Dfusion/luafiles/xml_types_windows.lua @@ -45,7 +45,7 @@ function stl_vec.wrap:__index(key) if num~=nil and num<size then return type_read(mtype.item_type,num*mtype.item_type.size+p_begin) else - error("invalid key to stl vector") + error(string.format("Invalid key: %s max: %d",key,size)) end end function stl_vec.wrap:__newindex(key,val) diff --git a/plugins/Dfusion/src/lua_Misc.cpp b/plugins/Dfusion/src/lua_Misc.cpp index 5eb95786..194b9a6e 100644 --- a/plugins/Dfusion/src/lua_Misc.cpp +++ b/plugins/Dfusion/src/lua_Misc.cpp @@ -129,6 +129,21 @@ static int GetMod(lua_State *L) st.push(pos); return 1; } +static int lua_malloc(lua_State *L) +{ + lua::state st(L); + size_t size=st.as<size_t>(1); + size_t pos=reinterpret_cast<size_t>(malloc(size)); + st.push(pos); + return 1; +} +static int lua_malloc_free(lua_State *L) +{ + lua::state st(L); + size_t ptr=st.as<size_t>(1); + free(reinterpret_cast<void*>(ptr)); + return 0; +} #ifdef LINUX_BUILD 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) #else @@ -197,6 +212,8 @@ static int Resume_Df(lua_State *L) } const luaL_Reg lua_misc_func[]= { + {"alloc",lua_malloc}, + {"free",lua_malloc_free}, {"loadmod",LoadMod}, {"getmod",GetMod}, {"loadobj",LoadObj}, |
