Petr Mrázek 2012-03-18 13:14:00 +01:00
commit a8a540eeb8
7 changed files with 103 additions and 17 deletions

@ -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

@ -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())

@ -1,7 +1,9 @@
DWARF:1
ELF:0
ELF:0
DWARF:0
DWARF:0
HUMAN:0
HUMAN:0
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

@ -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)

@ -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

@ -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)

@ -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},