diff --git a/plugins/Dfusion/luafiles/adv_tools/init.lua b/plugins/Dfusion/luafiles/adv_tools/init.lua index 5504f32bc..566484f01 100644 --- a/plugins/Dfusion/luafiles/adv_tools/init.lua +++ b/plugins/Dfusion/luafiles/adv_tools/init.lua @@ -18,7 +18,7 @@ function adv_tools.reincarnate(swap_soul) --only for adventurer i guess for i=#events-1,0,-1 do -- reverse search because almost always it will be last entry if df.history_event_hist_figure_diedst:is_instance(events[i]) then --print("is instance:"..i) - if events[i].hfid==hist_fig.id then + if events[i].victim==hist_fig.id then --print("Is same id:"..i) trg_hist_fig=events[i].slayer if trg_hist_fig then @@ -29,12 +29,12 @@ function adv_tools.reincarnate(swap_soul) --only for adventurer i guess end end if trg_hist_fig ==nil then - error("Slayer not found") + qerror("Slayer not found") end local trg_unit=trg_hist_fig.unit_id if trg_unit==nil then - error("Unit id not found!") + qerror("Unit id not found!") end local trg_unit_final=df.unit.find(trg_unit) diff --git a/plugins/Dfusion/luafiles/buildingpatterns.lua b/plugins/Dfusion/luafiles/buildingpatterns.lua deleted file mode 100644 index 310c543cb..000000000 --- a/plugins/Dfusion/luafiles/buildingpatterns.lua +++ /dev/null @@ -1,24 +0,0 @@ -ptr_building={} -ptr_building.RTI={off=0,rtype=DWORD} -ptr_building.xs={off=4,rtype=DWORD} -ptr_building.ys={off=6,rtype=DWORD} -ptr_building.zs={off=8,rtype=DWORD} -ptr_building.xe={off=12,rtype=DWORD} -ptr_building.ye={off=16,rtype=DWORD} -ptr_building.ze={off=20,rtype=DWORD} -ptr_building.flags={off=24,rtype=ptt_dfflag.new(4)} -ptr_building.materials={off=28,rtype=DWORD} -ptr_building.builditems={off=228,rtype=ptr_vector} -function ptr_building.getname(self,RTI) - if RTI == nil then - return string.sub(RTTI_GetName(self.RTI),5,-3) - else - return string.sub(RTTI_GetName(RTI),5,-3) - end -end -ptr_subbuilding={} -ptr_subbuilding["building_trapst"]={} -ptr_subbuilding["building_trapst"].state={off=250,rtype=DWORD} -- atleast lever has this -ptr_subbuilding["building_doorst"]={} -ptr_subbuilding["building_doorst"].flg={off=248,rtype=WORD} --maybe flags? -ptr_subbuilding["building_doorst"].state={off=250,rtype=DWORD} diff --git a/plugins/Dfusion/luafiles/editor.lua b/plugins/Dfusion/luafiles/editor.lua deleted file mode 100644 index 06b07ce5e..000000000 --- a/plugins/Dfusion/luafiles/editor.lua +++ /dev/null @@ -1,150 +0,0 @@ -function getTypename(object) - local tbl - local ret={} - if getmetatable(object)~=nil then - local tbl=getmetatable(object) - for k,v in pairs(xtypes) do - if v==tbl then - return k - end - end - for k,v in pairs(xtypes.containers) do - if v==tbl then - return k - end - end - end - if object.name~= nil then - return object.name - end - return "?" -end -function getFields(object) - local tbl - local ret={} - if getmetatable(object)==xtypes["struct-type"].wrap then - tbl=rawget(object,"mtype") - elseif getmetatable(object)==xtypes["struct-type"] then - tbl=object - else - error("Not an class_type or a class_object") - end - for k,v in pairs(tbl.types) do - table.insert(ret,{k,v[2],getTypename(v[1])}) - --ret[v[2]]=k - --print(string.format("%s %x",k,v[2])) - end - table.sort(ret,function (a,b) return a[2]>b[2] end) - return ret -end -function editField(tbl,field,typename) - if EditType[typename] ~= nil then - EditType[typename](tbl[field]) - else - print("Cur value:"..tostring(tbl[field])) - val=getline("Enter newvalue:") - tbl[field]=val - end -end -EditType={} -EditType["df-flagarray"]=function(trg) - local fields=rawget(trg,"mtype").index.names - print("Flag count:"..trg.size) - print("Name count:"..#fields) - for i=0,#fields do - print(string.format("%3d %20s %s",i,fields[i],tostring(trg[i-1]))) - end - number=getline("enter flag id to flip:") - number=tonumber(number) - if number then - trg[fields[number]]= not trg[fields[number]] - end -end -EditType["enum-type"]=function(trg) - local fields=rawget(trg,"mtype").names - local typename=getTypename(rawget(trg,"mtype").etype) - for k,v in pairs(fields) do - print(string.format("%3d %s",k,v)) - end - local cval=trg:get() - if fields[cval]~= nil then - print(string.format("Current value:%d (%s)",cval,fields[cval])) - else - print(string.format("Current value:%d",cval)) - end - number=getline("enter new value:") - number=tonumber(number) - if number then - trg:set(number) - end -end -EditType["static-array"]=function(trg) - local item_type=rawget(trg,"mtype").item_type - local typename=getTypename(item_type) - number=getline(string.format("Select item (max %d, item-type '%s'):",trg.size,typename)) - number=tonumber(number) - if number then - EditType[typename](trg[number]) - 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) - for k,v in pairs(fields) do - print(string.format("%4d %25s %s",k,v[1],v[3])) - end - number=getline("Choose field to edit:") - number=tonumber(number) - if number then - local v=fields[number] - editField(trg,v[1],v[3]) - end -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()) - else - print("Cur value:"..tostring(trg:deref())) - val=getline("Enter newvalue:") - trg:setref(val) - end -end - -function EditDF() - local i=1 - local tbl={} - for k,v in pairs(rawget(df,"types")) do - print(string.format("%4d %25s %s",i,k,getTypename(v))) - tbl[i]={k,getTypename(v)} - i=i+1 - end - number=dfhack.lineedit("select item to edit (q to quit):") - if number and tonumber(number) then - local entry=tbl[tonumber(number)] - if entry==nil then - return - end - editField(df,entry[1],entry[2]) - --[=[ - if EditType[entry[2]] ~= nil then - EditType[entry[2]](df[entry[1]]) - else - print("Cur value:"..tostring(df[entry[1]])) - val=getline("Enter newvalue:") - df[entry[1]]=val - end - --]=] - end -end -function EditObject(obj) - EditType[getTypename(obj)](obj) -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/itempatterns.lua b/plugins/Dfusion/luafiles/itempatterns.lua deleted file mode 100644 index da62c26d2..000000000 --- a/plugins/Dfusion/luafiles/itempatterns.lua +++ /dev/null @@ -1,62 +0,0 @@ ---dofile("patterns2.lua") moved to common.lua -ptr_item={} -ptr_item.RTI={off=0,rtype=DWORD} -ptr_item.x={off=4,rtype=WORD} -ptr_item.y={off=6,rtype=WORD} -ptr_item.z={off=8,rtype=WORD} -ptr_item.ref={off=0x28,rtype=ptr_vector} - -ptr_item.mat={off=0x78,rtype=WORD} -ptr_item.submat={off=0x7A,rtype=WORD} -ptr_item.submat2={off=0x7C,rtype=DWORD} -ptr_item.legendid={off=0x80,rtype=DWORD} -- i don't remember writing this... -ptr_item.decorations={off=0x90,rtype=ptr_vector} -ptr_item.flags={off=0xC,rtype=ptt_dfflag.new(8)} -ptr_item.ptr_covering={off=0x64,rtype=DWORD} -ptr_item.stack={off=0x58,rtype=WORD} -function ptr_item.getname(self,RTI) - if RTI == nil then - return string.sub(RTTI_GetName(self.RTI),5,-3) - else - return string.sub(RTTI_GetName(RTI),5,-3) - end -end -ptr_subitems={} -ptr_subitems["item_slabst"]={} -ptr_subitems["item_slabst"].msgptr={off=0xA0,rtype=ptt_dfstring} -ptr_subitems["item_slabst"].signtype={off=0xC0,rtype=DWORD} - -ptr_subitems["item_fisthst"]={} -ptr_subitems["item_fisthst"].fisthtype={off=0x78,rtype=WORD} - -ptr_subitems["item_eggst"]={} -ptr_subitems["item_eggst"].race={off=0x78,rtype=DWORD} -ptr_subitems["item_eggst"].isfertile={off=0xa0,rtype=DWORD} --0 or 1 -ptr_subitems["item_eggst"].hatchtime={off=0xa4,rtype=DWORD} - -ptr_decoration_gen={} -ptr_decoration_gen.RTI={off=0,rtype=DWORD} -ptr_decoration_gen.material={off=0x04,rtype=WORD} -- same for all? -ptr_decoration_gen.submat={off=0x08,rtype=DWORD} -function ptr_decoration_gen.getname(self,RTI) - if RTI == nil then - return string.sub(RTTI_GetName(self.RTI),21,-5) - else - return string.sub(RTTI_GetName(RTI),21,-5) - end -end -ptr_decoration={} -ptr_decoration["covered"]={} -ptr_decoration["covered"].material={off=0x04,rtype=WORD} -ptr_decoration["covered"].submat={off=0x08,rtype=DWORD} -ptr_decoration["art_image"]={} -ptr_decoration["art_image"].material={off=0x04,rtype=WORD} -ptr_decoration["art_image"].submat={off=0x08,rtype=DWORD} -ptr_decoration["art_image"].image={off=0x24,rtype=DWORD} -ptr_decoration["bands"]={} -ptr_decoration["bands"].material={off=0x04,rtype=WORD} -ptr_decoration["bands"].submat={off=0x08,rtype=DWORD} -ptr_cover={} --covering of various types (blood, water, etc) -ptr_cover.mat={off=0,rtype=WORD} -ptr_cover.submat={off=4,rtype=DWORD} -ptr_cover.state={off=8,rtype=WORD} \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/patterns.lua b/plugins/Dfusion/luafiles/patterns.lua deleted file mode 100644 index 34aa0c274..000000000 --- a/plugins/Dfusion/luafiles/patterns.lua +++ /dev/null @@ -1,248 +0,0 @@ -ptt_dfstring={} -if WINDOWS then - ptt_dfstring.ptr={off=0,rtype=DWORD} - ptt_dfstring.size={off=16,rtype=DWORD} - ptt_dfstring.alloc={off=20,rtype=DWORD} - - function ptt_dfstring:getval() - --print(string.format("GETTING FROM:%x",self.__offset)) - if self.size<16 then - --print(string.format("GETTING FROM:%x",self.__offset)) - return string.sub(engine.peekstr(self.__offset),1,self.size) - else - --print(string.format("GETTING FROM:%x",self.ptr)) - return string.sub(engine.peekstr(self.ptr),1,self.size) - end - end - function ptt_dfstring:setval(newstring) - local offset=self.__offset - local strl=string.len(newstring) - if strl<16 then - --print(string.format("GETTING FROM:%x",self.__offset)) - - engine.poked(offset+ptt_dfstring.size.off,strl) - engine.poked(offset+ptt_dfstring.alloc.off,15) - engine.pokestr(offset,newstring) - - else - local loc - if engine.peekd(offset+ptt_dfstring.alloc.off) > strl then - loc=engine.peekd(offset) - print("Will fit:"..loc.." len:"..strl) - else - loc=Allocate(strl+1) - engine.poked(offset+ptt_dfstring.alloc.off,strl) - print("Will not fit:"..loc.." len:"..strl) - end - --print(string.format("GETTING FROM:%x",self.ptr)) - engine.poked(self.__offset+ptt_dfstring.size.off,strl) - engine.pokestr(loc,newstring) - engine.poked(self.__offset,loc) - end - end -else - --ptt_dfstring.ptr={off=0,rtype=DWORD} - function ptt_dfstring:getval() - return engine.peekstr_stl(self.__offset) - end -end ---if(COMPATMODE) then ---ptr_vector={} ---ptr_vector.st={off=4,rtype=DWORD} ---ptr_vector.en={off=8,rtype=DWORD} ---else -ptr_vector={} -ptr_vector.st={off=0,rtype=DWORD} -ptr_vector.en={off=4,rtype=DWORD} -ptr_vector.alloc={off=8,rtype=DWORD} ---end -function ptr_vector:clone(settype) - local ret={} - for k,v in pairs(self) do - ret[k]=v - end - ret.type=settype - return ret -end -function ptr_vector:size() - return (self.en-self.st)/engine.sizeof(self.type) -end -ptr_vector.type=DWORD -function ptr_vector:getval(num) - if self.st==0 then return error("Vector empty.") end - --print("Wants:"..num.." size:"..self:size()) - if num>=self:size() then error("Index out of bounds in vector.") end - return engine.peek(self.st+engine.sizeof(self.type)*num,self.type) -end -function ptr_vector:setval(num,val) - return engine.poke(self.st+engine.sizeof(self.type)*num,self.type,val) -end -function ptr_vector:append(val) - if self.alloc - self.en > 0 then - local num=self:size() - self.en=self.en+engine.sizeof(self.type) - self:setval(val,num) - else - error("larger than allocated arrays not implemented yet") - local num=self:size() - local ptr=Allocate(num*2) - - end -end -ptt_dfflag={} -function ptt_dfflag.flip(self,num) --flip one bit in flags - local of=math.floor (num/8); - - self[of]=bit.bxor(self[of],bit.lshift(1,num%8)) -end - -function ptt_dfflag.get(self,num) -- get one bit in flags - local of=math.floor (num/8); - - if bit.band(self[of],bit.lshift(1,num%8))~=0 then - return true - else - return false - end -end -function ptt_dfflag.set(self,num,val) --set to on or off one bit in flags - if (self:get(num)~=val) then - self:flip(num) - end -end -function ptt_dfflag.new(size) -- create new flag pattern of size(in bytes) - local ret={} - for i=0,size-1 do - ret[i]={off=i,rtype=BYTE}; - end - ret.flip=ptt_dfflag.flip --change to metatable stuff... - ret.get=ptt_dfflag.get - ret.set=ptt_dfflag.set - return ret; -end ---[[ - Creature: - 0 name (df_string) 28 - 28 nick (df_string) 56 - 56 surname- namearray(7*dword(4)) 84 ... - 140 race (dword) 144 - 224 flags - 264 civ (dword) - 252 ID - 592 following ID - 904 bleed vector? hurt vector or sth... - 0x790 legends id? - 2128 known names? or knowledge? - flags: - 0 Can the dwarf move or are they waiting for their movement timer - 1 Dead (might also be set for incoming/leaving critters that are alive) - 2 Currently in mood - 3 Had a mood - 4 "marauder" -- wide class of invader/inside creature attackers - 5 Drowning - 6 Active merchant - 7 "forest" (used for units no longer linked to merchant/diplomacy, they just try to leave mostly) - 8 Left (left the map) - 9 Rider - 10 Incoming - 11 Diplomat - 12 Zombie - 13 Skeleton - 14 Can swap tiles during movement (prevents multiple swaps) - 15 On the ground (can be conscious) - 16 Projectile - 17 Active invader (for organized ones) - 18 Hidden in ambush - 19 Invader origin (could be inactive and fleeing) - 20 Will flee if invasion turns around - 21 Active marauder/invader moving inward - 22 Marauder resident/invader moving in all the way - 23 Check against flows next time you get a chance - 24 Ridden - 25 Caged - 26 Tame - 27 Chained - 28 Royal guard - 29 Fortress guard - 30 Suppress wield for beatings/etc - 31 Is an important historical figure - 32 swiming - -]]-- -ptr_Creature={} -local posoff=0 --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=0,rtype=ptt_dfflag.new(10)} -ptr_Creature.name={off=0,rtype=ptt_dfstring} -ptr_Creature.ID={off=252,rtype=DWORD} --ok i guess -ptr_Creature.followID={off=592,rtype=DWORD} --ok -ptr_Creature.race={off=140,rtype=DWORD} --ok -ptr_Creature.civ={off=264,rtype=DWORD} -ptr_Creature.legends={off=344,rtype=ptr_vector} --ok -ptr_Creature.hurt1={off=0x308,rtype=ptr_vector:clone(BYTE)} --byte vector... -ptr_Creature.hurt2={off=0x338,rtype=ptr_vector} -ptr_Creature.wounds={off=0x388,rtype=ptr_vector} -ptr_Creature.itemlist1={off=0x1D0,rtype=ptr_vector} -ptr_Creature.itemlist2={off=0x288,rtype=ptr_vector} -ptr_Creature.bloodlvl={off=0x490,rtype=DWORD} -ptr_Creature.bleedlvl={off=0x494,rtype=DWORD} - -ptr_CrGloss={} -ptr_CrGloss.token={off=0,rtype=ptt_dfstring} -ptr_CrGloss.castes={off=296,rtype=ptr_vector} - -ptr_CrCaste={} -ptr_CrCaste.name={off=0,rtype=ptt_dfstring} -ptr_CrCaste.flags_ptr={off=0x5A0,rtype=DWORD} --size 17? ---[=[ - Flags: - 57 - is sentient (allows setting labours) ---]=] -ptr_LEntry={} -- all size 256 -ptr_LEntry.name={off=36,rtype=ptt_dfstring} -ptr_LEntry.id1={off=160,rtype=DWORD} -ptr_LEntry.id2={off=164,rtype=DWORD} -ptr_LEntry.somlist={off=220,rtype=DWORD} - -ptr_dfname={} -for i=0,6 do -ptr_dfname[i]={off=i*4,rtype=DWORD} -end ---[[ - Site docs: - 0x38 name struct todo... - 0x78 type: - 0 - mountain halls (yours) - 1 - dark fort - 2 - cave - 3 - mountain hall (other) - 4 - forest - 5 - hamlet - 6 - imp location - 7 - lair - 8 - fort - 9 - camp - 0x7a some sort of id? - 0x84 some vec (ids) - 0x94 some other vec (ids) - 0xa4 some vec (prts) - 0x118 ptr to sth - - 0x14c ptr to mapdata -]]-- - - -ptr_site={} -ptr_site.type={off=0x78,rtype=WORD} -ptr_site.id={off=0x7a,rtype=DWORD} -ptr_site.name={off=0x38,rtype=ptr_dfname} -ptr_site.flagptr={off=0x118,rtype=DWORD} - -ptr_legends2={} -ptr_legends2.id={off=0,rtype=DWORD} -ptr_legends2.follow={off=0x18,rtype=DWORD} - -ptr_material={} -ptr_material.token={off=0,rtype=ptt_dfstring} diff --git a/plugins/Dfusion/luafiles/patterns2.lua b/plugins/Dfusion/luafiles/patterns2.lua deleted file mode 100644 index 09a3b0db8..000000000 --- a/plugins/Dfusion/luafiles/patterns2.lua +++ /dev/null @@ -1,29 +0,0 @@ -ptr_COL={} -- complete object locator... -ptr_COL.sig={off=0,rtype=DWORD} -ptr_COL.offset={off=4,rtype=DWORD} --offset of this vtable in the complete class -ptr_COL.cdoffset={off=8,rtype=DWORD} -- constructor displacement -ptr_COL.typePointer={off=12,rtype=DWORD} -ptr_COL.hierarchyPointer={off=16,rtype=DWORD} - -ptr_RTTI_Type={} -ptr_RTTI_Type.vftPointer={off=0,rtype=DWORD} -ptr_RTTI_Type.name={off=8,rtype=STD_STRING} - -function RTTI_GetName(vtable) - local COLoff=engine.peek(vtable-4,DWORD) - --print(string.format("Look:%x vtable:%x",vtable,engine.peek(vtable-4,DWORD))) - COL=engine.peek(COLoff,ptr_COL) - --print(string.format("COL:%x Typeptr:%x Type:%s",COLoff,COL.typePointer,engine.peek(COL.typePointer,ptr_RTTI_Type.name))) - return engine.peek(COL.typePointer,ptr_RTTI_Type.name) -end -ptr_RTTI_Hierarchy={} -ptr_RTTI_Hierarchy.sig={off=0,rtype=DWORD} -ptr_RTTI_Hierarchy.attributes={off=4,rtype=DWORD} -ptr_RTTI_Hierarchy.numBaseClasses={off=8,rtype=DWORD} -ptr_RTTI_Hierarchy.ptrBases={off=12,rtype=DWORD} - -ptr_RTTI_BaseClass={} -ptr_RTTI_BaseClass.typePointer={off=0,rtype=DWORD} -ptr_RTTI_BaseClass.numContained={off=4,rtype=DWORD} ---todo PMD ---todo flags \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/xml_struct.lua b/plugins/Dfusion/luafiles/xml_struct.lua deleted file mode 100644 index 8d0801be3..000000000 --- a/plugins/Dfusion/luafiles/xml_struct.lua +++ /dev/null @@ -1,151 +0,0 @@ -if types ~= nil then - return -end -dofile("dfusion/xml_types.lua") - -function parseTree(t) - for k,v in ipairs(t) do - if v.xarg~=nil and v.xarg["type-name"]~=nil and v.label=="ld:global-type" then - local name=v.xarg["type-name"]; - if(types[name]==nil) then - - --for kk,vv in pairs(v.xarg) do - -- print("\t"..kk.." "..tostring(vv)) - --end - types[name]=makeType(v) - --print("found "..name.." or type:"..v.xarg.meta or v.xarg.base) - - else - types[name]=makeType(v,types[name]) - end - end - end -end -function parseTreeGlobals(t) - local glob={} - --print("Parsing global-objects") - for k,v in ipairs(t) do - if v.xarg~=nil and v.label=="ld:global-object" then - local name=v.xarg["name"]; - --print("Parsing:"..name) - local subitem=v[1] - if subitem==nil then - error("Global-object subitem is nil:"..name) - end - local ret=makeType(subitem) - if ret==nil then - error("Make global returned nil!") - end - glob[name]=ret - end - end - --print("Printing globals:") - --for k,v in pairs(glob) do - -- print(k) - --end - return glob -end -function findAndParse(tname) - --if types[tname]==nil then types[tname]={} end - -- [=[ - for k,v in ipairs(main_tree) do - local name=v.xarg["type-name"]; - if v.xarg~=nil and v.xarg["type-name"]~=nil and v.label=="ld:global-type" then - - if(name ==tname) then - --print("Parsing:"..name) - --for kk,vv in pairs(v.xarg) do - -- print("\t"..kk.." "..tostring(vv)) - --end - types[name]=makeType(v,types[name]) - end - --print("found "..name.." or type:"..v.xarg.meta or v.xarg.base) - end - end - --]=] -end -df={} -df.types=rawget(df,"types") or {} --temporary measure for debug -local df_meta={} -function df_meta:__index(key) - local addr=VersionInfo.getAddress(key) - local vartype=rawget(df,"types")[key]; - if addr==0 then - error("No such global address exist") - elseif vartype==nil then - error("No such global type exist") - else - return type_read(vartype,addr) - end -end -function df_meta:__newindex(key,val) - local addr=VersionInfo.getAddress(key) - local vartype=rawget(df,"types")[key]; - if addr==0 then - error("No such global address exist") - elseif vartype==nil then - error("No such global type exist") - else - return type_write(vartype,addr,val) - end -end -setmetatable(df,df_meta) --------------------------------- -types=types or {} -dofile("dfusion/patterns/xml_angavrilov.lua") --- [=[ -main_tree=parseXmlFile("dfusion/patterns/supplementary.xml")[1] -parseTree(main_tree) -main_tree=parseXmlFile("dfusion/patterns/codegen.out.xml")[1] -parseTree(main_tree) -rawset(df,"types",parseTreeGlobals(main_tree)) ---]=] ---[=[labels={} -for k,v in ipairs(t) do - labels[v.label]=labels[v.label] or {meta={}} - if v.label=="ld:global-type" and v.xarg~=nil and v.xarg.meta ~=nil then - labels[v.label].meta[v.xarg.meta]=1 - end -end -for k,v in pairs(labels) do - print(k) - if v.meta~=nil then - for kk,vv in pairs(v.meta) do - print("=="..kk) - end - end -end--]=] -function addressOf(var,key) - if key== nil then - local addr=rawget(var,"ptr") - return addr - else - local meta=getmetatable(var) - if meta== nil then - error("Failed to get address, no metatable") - end - if meta.__address == nil then - error("Failed to get address, no __address function") - end - return meta.__address(var,key) - end -end -function printGlobals() - print("Globals:") - for k,v in pairs(rawget(df,"types")) do - print(k) - end -end -function printFields(object) - local tbl - if getmetatable(object)==xtypes["struct-type"].wrap then - tbl=rawget(object,"mtype") - elseif getmetatable(object)==xtypes["struct-type"] then - tbl=object - else - error("Not an class_type or a class_object") - end - for k,v in pairs(tbl.types) do - print(string.format("%s %x",k,v[2])) - end -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/xml_types.lua b/plugins/Dfusion/luafiles/xml_types.lua deleted file mode 100644 index cced4be2c..000000000 --- a/plugins/Dfusion/luafiles/xml_types.lua +++ /dev/null @@ -1,734 +0,0 @@ --- otherwise you just maintain alignment granularity in addition to size for all fields, --- round up current offset to field alignment, --- assign structs the max alignment of any field, and round up struct size to its alignment -function type_read(valtype,address) - if valtype.issimple then - --print("Simple read:"..tostring(valtype.ctype)) - return engine.peek(address,valtype.ctype) - else - return valtype:makewrap(address) - end -end -function type_write(valtype,address,val) - if valtype.issimple then - engine.poke(address,valtype.ctype,val) - else - engine.poke(address,DWORD,rawget(val,"ptr")) - end -end -function first_of_type(node,labelname) - for k,v in ipairs(node) do - if type(v)=="table" and v.label==labelname then - return v - end - end -end -xtypes={} -- list of all types prototypes (e.g. enum-type -> announcement_type) --- type must have size, new and makewrap (that makes a wrapper around ptr) -if WINDOWS then - dofile("dfusion/xml_types_windows.lua") -elseif LINUX then - dofile("dfusion/xml_types_linux.lua") -end - -function padAddress(curoff,typetoadd) --return new offset to place things... Maybe linux is different? - --windows -> sizeof(x)==alignof(x) - --[=[ - - if sizetoadd>8 then sizetoadd=8 end - if(math.mod(curoff,sizetoadd)==0) then - return curoff - else - return curoff+(sizetoadd-math.mod(curoff,sizetoadd)) - end - --]=] - if typetoadd==nil or typetoadd.__align==nil then - return curoff - else - - if(math.mod(curoff,typetoadd.__align)==0) then - return curoff - else - if PRINT_PADS then - print("padding off:"..curoff.." with align:"..typetoadd.__align.." pad="..(typetoadd.__align-math.mod(curoff,typetoadd.__align))) - end - return curoff+(typetoadd.__align-math.mod(curoff,typetoadd.__align)) - end - end -end - - -local sarr={} -sarr.__index=sarr -function sarr.new(node,obj) - local o=obj or {} - setmetatable(o,sarr) - --print("Making array.") - o.count=tonumber(node.xarg.count) - --print("got count:"..o.count) - o.item_type=makeType(first_of_type(node,"ld:item")) - o.__align=o.item_type.__align or 4 - o.size=o.count*o.item_type.size - --print("got subtypesize:"..o.item_type.size) - return o -end -function sarr:makewrap(address) - local o={} - o.mtype=self - o.ptr=address - setmetatable(o,self.wrap) - return o -end -sarr.wrap={} -function sarr.wrap:__index(key) - if key=="size" then - return rawget(self,"mtype").count - end - local num=tonumber(key) - local mtype=rawget(self,"mtype") - if num~=nil and num"..v.xarg.meta.." ttype:"..v.label) - local ttype=makeType(v) - if ttype.size==0 then error("Field with 0 size! type="..node.xarg["type-name"].."."..name) end - if ttype.size-math.ceil(ttype.size) ~= 0 then error("Field with real offset! type="..node.xarg["type-name"].."."..name) end - --for k,v in pairs(ttype) do - -- print(k..tostring(v)) - --end - - local off=padAddress(o.size,ttype) - --[=[if PRINT_PADS then - - if ttype.__align then - print(name.." "..ttype.__align .. " off:"..off.." "..math.mod(off,ttype.__align)) - - end - if off~=o.size then - print("var:"..name.." size:"..ttype.size) - end - end]=] - --print("var:"..name.." ->"..tostring(off).. " :"..ttype.size) - if isunion then - if ttype.size > o.size then - o.size=ttype.size - end - o.types[name]={ttype,0} - else - o.size=off - o.types[name]={ttype,o.size}--+o.baseoffset - o.size=o.size+ttype.size - end - if firsttype== nil then - firsttype=o.types[name][1] - end - - end - end - if isunion then - o.__align=0 - for k,v in pairs(o.types) do - if v[1].__align~= nil and v[1].__align>o.__align then - o.__align=v[1].__align - end - end - else - if o.base[1]~= nil then - o.__align=o.base[1].__align - elseif firsttype~= nil then - o.__align=firsttype.__align - --if o.__align~=nil then - --print("\t\t setting align to:"..(o.__align or "")) - --else - --o.__align=4 - --print("\t\t NIL ALIGNMENT!") - --end - end - end - - return o -end - -type_class.wrap={} -function type_class.wrap:__address(key) - local myptr=rawget(self,"ptr") - local mytype=rawget(self,"mtype") - if mytype.types[key] ~= nil then - return myptr+mytype.types[key][2] - else - error("No such field exists") - end -end -function type_class.wrap:__index(key) - local myptr=rawget(self,"ptr") - local mytype=rawget(self,"mtype") - if mytype.types[key] ~= nil then - return type_read(mytype.types[key][1],myptr+mytype.types[key][2]) - else - error("No such field exists") - end -end -function type_class.wrap:__newindex(key,value) - local myptr=rawget(self,"ptr") - local mytype=rawget(self,"mtype") - if mytype.types[key] ~= nil then - return type_write(mytype.types[key][1],myptr+mytype.types[key][2],value) - else - error("No such field exists") - end -end -function type_class:makewrap(ptr) - local o={} - o.ptr=ptr - o.mtype=self - setmetatable(o,self.wrap) - return o -end -xtypes["struct-type"]=type_class -xtypes["class-type"]=type_class -local type_pointer={} -type_pointer.__index=type_pointer -function type_pointer.new(node,obj) - local o=obj or {} - setmetatable(o,type_pointer) - local subnode=first_of_type(node,"ld:item") - if subnode~=nil then - o.ptype=makeType(subnode,nil,true) - end - - o.size=4 - o.__align=4 - return o -end -type_pointer.wrap={} -type_pointer.wrap.__index=type_pointer.wrap -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) -end -function type_pointer.wrap:deref() - local myptr=rawget(self,"ptr") - local mytype=rawget(self,"mtype") - return type_read(mytype.ptype,engine.peekd(myptr)) -end -function type_pointer.wrap:setref(val) - local myptr=rawget(self,"ptr") - 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 - o.mtype=self - setmetatable(o,self.wrap) - return o -end -xtypes["pointer"]=type_pointer --------------------------------------------- ---stl-vector (beginptr,endptr,allocptr) ---df-flagarray (ptr,size) -xtypes.containers=xtypes.containers or {} -local dfarr={} -dfarr.__index=dfarr -function dfarr.new(node,obj) - local o=obj or {} - 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) - local o={} - o.mtype=self - o.ptr=address - setmetatable(o,self.wrap) - 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=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"..tostring(v)) - end - error("Node parser not found: "..label) - end - --[=[ - if getSimpleType(node)~=nil then - return getSimpleType(node) - end - print("Trying to make:"..node.xarg.meta) - if xtypes[node.xarg.meta]~=nil then - return xtypes[node.xarg.meta].new(node,obj) - end - - if node.xarg.meta=="global" then - --print(node.xarg["type-name"]) - - if types[node.xarg["type-name"]]== nil then - error("type:"..node.xarg["type-name"].." should already be ready") - end - return types[node.xarg["type-name"]] - end - ]=] - --[=[for k,v in pairs(node) do - print(k.."=>"..tostring(v)) - if type(v)=="table" then - for kk,vv in pairs(v) do - print("\t"..kk.."=>"..tostring(vv)) - end - end - end]=] - -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/xml_types_windows.lua b/plugins/Dfusion/luafiles/xml_types_windows.lua deleted file mode 100644 index 90bc80312..000000000 --- a/plugins/Dfusion/luafiles/xml_types_windows.lua +++ /dev/null @@ -1,159 +0,0 @@ -xtypes.containers=xtypes.containers or {} -local stl_vec={} ---[=[ - (make-instance 'pointer :name $start) - (make-instance 'pointer :name $end) - (make-instance 'pointer :name $block-end) - (make-instance 'padding :name $pad :size 4 :alignment 4) ---]=] -stl_vec.__index=stl_vec - -function stl_vec.new(node,obj) - local o=obj or {} - - o.size=16 - o.__align=4 - local titem=first_of_type(node,"ld:item") - if titem~=nil then - o.item_type=makeType(titem) - else - o.item_type=getSimpleType("uint32_t") - end - setmetatable(o,stl_vec) - return o -end -function stl_vec:makewrap(address) - local o=obj or {} - o.mtype=self - o.ptr=address - setmetatable(o,self.wrap) - return o -end -stl_vec.wrap={} -function stl_vec.wrap:__index(key) - local num=tonumber(key) - local mtype=rawget(self,"mtype") - local ptr=rawget(self,"ptr") - local p_begin=engine.peek(ptr,DWORD) - local p_end=engine.peek(ptr+4,DWORD) - local size=(p_end-p_begin)/mtype.item_type.size - if key=="size" then - return size - end - - --allocend=type_read(ptr+8,DWORD) - if num~=nil and num