Started move to new system. Temp disabled non-working plugins.

develop
Warmist 2012-03-17 15:05:48 +02:00
parent dea215d0b9
commit fd48c59aba
8 changed files with 98 additions and 58 deletions

@ -359,33 +359,19 @@ function findVectors()
end
function GetRaceToken(p) --actually gets token...
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)
local crgloss=engine.peek(off,ptr_CrGloss)
--print("Peek ok")
return crgloss.token:getval()
local vec=df.world.raws.creatures.alphabetic
return vec[p]:deref().creature_id
end
function BuildNameTable()
local rtbl={}
local vec=engine.peek(offsets.getEx('CreatureGloss'),ptr_vector)
local vec=df.world.raws.creatures.alphabetic
--print(string.format("Vector start:%x",vec.st))
--print(string.format("Vector end:%x",vec.en))
--local i=0
for p=0,vec:size()-1 do
local off=vec:getval(p)
--print("First member:"..off)
local name=engine.peek(off,ptt_dfstring)
--print("Loading:"..p.."="..name:getval())
rtbl[name:getval()]=p
--i=i+1
--if i>100 then
-- io.stdin:read()
-- i=0
--end
--print("Creature count:"..vec.size)
for k,v in iter(vec) do
local name=v:deref().creature_id
--print(k.." "..tostring(name))
rtbl[name]=k
end
return rtbl;
end

@ -43,7 +43,7 @@ function embark(names)
tofind=addressOf(df.ui,"race_id")
loc=offsets.find(stoff,0xa1,DWORD_,tofind)
loc=offsets.find(stoff,0x0f,0xb7,0x0d,DWORD_,tofind) --MOVZX ECX,WORD PTR[]
print("found:"..loc)

@ -36,20 +36,25 @@ function mainmenu(t1)
q=tonumber(q)
if q~=nil then
if q>=1 and q<=#t1 then
dofile("dfusion/"..t1[q][1].."/plugin.lua")
if t1[q][3]==nil then
dofile("dfusion/"..t1[q][1].."/plugin.lua")
else
t1[q][3]()
end
end
end
end
end
dofile("dfusion/common.lua")
dofile("dfusion/utils.lua")
dofile("dfusion/offsets_misc.lua")
dofile("dfusion/editor.lua")
types=nil
dofile("dfusion/xml_struct.lua")
unlockDF()
plugins={}
table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"})
table.insert(plugins,{"embark","Multi race embark"})
--[=[table.insert(plugins,{"embark","Multi race embark"})
table.insert(plugins,{"items","A collection of item hacking tools"})
table.insert(plugins,{"offsets","Find all offsets"})
table.insert(plugins,{"friendship","Multi race fort enabler"})
@ -58,7 +63,8 @@ table.insert(plugins,{"adv_tools","some tools for (mainly) advneturer hacking"})
table.insert(plugins,{"tools","some misc tools"})
table.insert(plugins,{"triggers","a function calling plug (discontinued...)"})
table.insert(plugins,{"migrants","multi race imigrations"})
table.insert(plugins,{"onfunction","run lua on some df function"})
table.insert(plugins,{"onfunction","run lua on some df function"})--]=]
table.insert(plugins,{"editor","edit internals of df",EditDF})
loadall(plugins)
dofile_silent("dfusion/initcustom.lua")

@ -2,13 +2,16 @@ tools={}
tools.menu=MakeMenu()
function tools.setrace()
RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again
print("Your current race is:"..GetRaceToken(engine.peekw(offsets.getEx('CurrentRace'))))
print("Type new race's token name in full caps:")
print("Your current race is:"..GetRaceToken(df.ui.race_id))
print("Type new race's token name in full caps (q to quit):")
repeat
entry=io.stdin:read()
id=RaceTable[entry]
entry=io.stdin:read()
if entry=="q" then
return
end
id=RaceTable[entry]
until id~=nil
engine.pokew(offsets.getEx('CurrentRace'),id)
df.ui.race_id=id
end
tools.menu:add("Set current race",tools.setrace)
function tools.GiveSentience(names) --TODO make pattern...

@ -27,11 +27,6 @@ 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 name=="world" then
PRINT_PADS=1
else
PRINT_PADS=nil
end
if(types[name]==nil) then
--for kk,vv in pairs(v.xarg) do

@ -63,10 +63,10 @@ function sarr.new(node,obj)
--print("Making array.")
o.count=tonumber(node.xarg.count)
--print("got count:"..o.count)
o.ctype=makeType(first_of_type(node,"ld:item"))
o.__align=o.ctype.__align or 4
o.size=o.count*o.ctype.size
--print("got subtypesize:"..o.ctype.size)
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)
@ -84,7 +84,7 @@ function sarr.wrap:__index(key)
local num=tonumber(key)
local mtype=rawget(self,"mtype")
if num~=nil and num<mtype.count then
return type_read(mtype.ctype,num*mtype.ctype.size+rawget(self,"ptr"))
return type_read(mtype.item_type,num*mtype.item_type.size+rawget(self,"ptr"))
else
error("invalid key to static-array")
end
@ -92,7 +92,7 @@ end
function sarr.wrap:__newindex(key,val)
local num=tonumber(key)
if num~=nil and num<rawget(self,"mtype").count then
return type_write(mtype.ctype,num*mtype.ctype.size+rawget(self,"ptr"),val)
return type_write(mtype.item_type,num*mtype.item_type.size+rawget(self,"ptr"),val)
else
error("invalid key to static-array")
end
@ -116,6 +116,7 @@ simpletypes["stl-string"]={STD_STRING,28,4}
function getSimpleType(typename,obj)
if simpletypes[typename] == nil then return end
local o=obj or {}
o.name=typename
o.ctype=simpletypes[typename][1]
o.size=simpletypes[typename][2]
o.__align=simpletypes[typename][3]
@ -127,19 +128,39 @@ type_enum.__index=type_enum
function type_enum.new(node,obj)
local o=obj or {}
setmetatable(o,type_enum)
o.names={}
for k,v in pairs(node) do
if type(v)=="table" and v.xarg~=nil then
--print("\t"..k.." "..v.xarg.name)
o[k-1]=v.xarg.name
o.names[k-1]=v.xarg.name
end
end
local btype=node.xarg["base-type"] or "uint32_t"
--print(btype.." t="..convertType(btype))
o.type=getSimpleType(btype) -- should be simple type
o.size=o.type.size
o.__align=o.type.__align
o.etype=getSimpleType(btype) -- should be simple type
o.size=o.etype.size
o.__align=o.etype.__align
return o
end
function type_enum:makewrap(address)
local o={}
o.mtype=self
o.ptr=address
setmetatable(o,self.wrap)
return o
end
type_enum.wrap={}
type_enum.wrap.__index=type_enum.wrap
type_enum.wrap.set=function (tbl,val)
local mtype=rawget(tbl,"mtype")
local ptr=rawget(tbl,"ptr")
type_write(mtype.etype,ptr,val)
end
type_enum.wrap.get=function (tbl)
local mtype=rawget(tbl,"mtype")
local ptr=rawget(tbl,"ptr")
return type_read(mtype.etype,ptr)
end
xtypes["enum-type"]=type_enum
local type_bitfield={} --bitfield can be accessed by number (bf[1]=true) or by name bf.DO_MEGA=true
@ -281,7 +302,7 @@ function type_class.new(node,obj)
--end
local off=padAddress(o.size,ttype)
if PRINT_PADS then
--[=[if PRINT_PADS then
if ttype.__align then
print(name.." "..ttype.__align .. " off:"..off.." "..math.mod(off,ttype.__align))
@ -290,7 +311,7 @@ function type_class.new(node,obj)
if off~=o.size then
print("var:"..name.." size:"..ttype.size)
end
end
end]=]
--print("var:"..name.." ->"..tostring(off).. " :"..ttype.size)
if isunion then
if ttype.size > o.size then
@ -320,12 +341,12 @@ function type_class.new(node,obj)
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 ""))
--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
end
@ -398,6 +419,11 @@ function type_pointer.wrap:deref()
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:makewrap(ptr)
local o={}
o.ptr=ptr
@ -502,7 +528,7 @@ function bytes_pad.new(node,obj)
setmetatable(o,bytes_pad)
o.size=tonumber(node.xarg.size)
if node.xarg.alignment~=nil then
print("Aligned bytes!")
--print("Aligned bytes!")
o.__align=tonumber(node.xarg.alignment)
end
return o

@ -7,6 +7,7 @@ local stl_vec={}
(make-instance 'padding :name $pad :size 4 :alignment 4)
--]=]
stl_vec.__index=stl_vec
function stl_vec.new(node,obj)
local o=obj or {}
@ -44,16 +45,28 @@ 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 df-flagarray")
error("invalid key to stl vector")
end
end
function stl_vec.wrap:__newindex(key,val)
local num=tonumber(key)
error("TODO make __index for stl_vec")
error("TODO make __newindex for stl_vec")
if num~=nil and num<rawget(self,"mtype").count then
return type_write(mtype.item_type,num*mtype.item_type.size+rawget(self,"ptr"),val)
else
error("invalid key to static-array")
error("invalid key to stl vector")
end
end
function stl_vec.wrap.__next(tbl,key)
--print("next with:"..tostring(key))
if key==nil then
return 0,tbl[0]
else
if key<tbl.size-1 then
return key+1,tbl[key+1]
else
return nil
end
end
end
xtypes.containers["stl-vector"]=stl_vec
@ -105,6 +118,17 @@ function stl_vec_bit.wrap:__newindex(key,val)
error("invalid key to static-array")
end
end
function stl_vec_bit.wrap:__next(tbl,key)
if key==nil then
return 0,self[0]
else
if key+1<self.size then
return key+1,self[key+1]
else
return nil
end
end
end
xtypes.containers["stl-bit-vector"]=stl_vec_bit
local stl_deque={}

@ -3,7 +3,7 @@ int lua::Hexsearch::find(lua_State *L)
{
lua::state st(L);
void * pos=p->FindNext();
st.push(pos);
st.push(reinterpret_cast<size_t>(pos));
return 1;
}
int lua::Hexsearch::findall(lua_State *L)
@ -14,7 +14,7 @@ int lua::Hexsearch::findall(lua_State *L)
for(unsigned i=0;i<pos.size();i++)
{
st.push(i+1);
st.push(pos[i]);
st.push(reinterpret_cast<size_t>(pos[i]));
st.settable();
}
return 1;