Started rework lua files to be more hotkey friendly and adv/fort mode independant.

develop
Warmist 2012-04-03 23:16:29 +03:00
parent 3a0bd73315
commit 6d4ef1fd38
4 changed files with 66 additions and 53 deletions

@ -1,5 +1,6 @@
adv_tools=adv_tools or {} adv_tools=adv_tools or {}
adv_tools.menu=adv_tools.menu or MakeMenu() adv_tools.menu=adv_tools.menu or MakeMenu()
--TODO make every tool generic (work for both modes)
function adv_tools.ressurect() function adv_tools.ressurect()
v2=engine.peek(vector:getval(indx),ptr_Creature.hurt1) v2=engine.peek(vector:getval(indx),ptr_Creature.hurt1)

@ -496,10 +496,34 @@ function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord
return vector[i] --return index return vector[i] --return index
end end
end end
print("Creature not found!") --print("Creature not found!")
return nil return nil
end end
function getCreatureAtPointer()
return getCreatureAtPos(getxyz())
end
function getCreature()
local unit=getSelectedUnit()
if unit==nil then
unit=getCreatureAtPointer()
end
--any other selection methods...
return unit
end
function getNemesisId(unit)
for k,v in pairs(unit.refs) do
if tostring(v._type)=="<type: general_ref_is_nemesisst>" then
return v.nemesis_id
end
end
end
function getNemesis(unit)
local id=getNemesisId(unit)
if id then
return df.global.world.nemesis.all[id]
end
end
function Allocate(size) function Allocate(size)
local ptr=engine.getmod('General_Space') local ptr=engine.getmod('General_Space')
if ptr==nil then if ptr==nil then
@ -512,14 +536,6 @@ function Allocate(size)
engine.poked(ptr,curptr) engine.poked(ptr,curptr)
return curptr-size+ptr return curptr-size+ptr
end end
function initType(object,...)
local m=getmetatable(object)
if m~=nil and m.__setup~=nil then
m.__setup(object,...)
else
error("This object does not have __setup function")
end
end
dofile("dfusion/patterns.lua") dofile("dfusion/patterns.lua")
dofile("dfusion/patterns2.lua") dofile("dfusion/patterns2.lua")
dofile("dfusion/itempatterns.lua") dofile("dfusion/itempatterns.lua")

@ -1,7 +1,7 @@
offsets=offsets or {} offsets=offsets or {}
function offsets.find(startoffset,...) function offsets.find(startoffset,...)
local endadr=GetTextRegion()["end"]; -- [=[
--[=[if startoffset== 0 then if startoffset== 0 then
local text=GetTextRegion() local text=GetTextRegion()
--print("searching in:"..text.name) --print("searching in:"..text.name)
startoffset=text.start startoffset=text.start
@ -14,7 +14,8 @@ function offsets.find(startoffset,...)
return 0 return 0
end end
endadr=reg["end"] endadr=reg["end"]
end--]=] end
--]=]
--print(string.format("Searching (%x->%x)",startoffset,endadr)) --print(string.format("Searching (%x->%x)",startoffset,endadr))
local h=hexsearch(startoffset,endadr,...) local h=hexsearch(startoffset,endadr,...)
local pos=h:find() local pos=h:find()

@ -1,8 +1,10 @@
tools={} tools={}
tools.menu=MakeMenu() tools.menu=MakeMenu()
function tools.setrace() function tools.setrace(name)
RaceTable=BuildNameTable() RaceTable=BuildNameTable()
print("Your current race is:"..GetRaceToken(df.global.ui.race_id)) print("Your current race is:"..GetRaceToken(df.global.ui.race_id))
local id
if name == nil then
print("Type new race's token name in full caps (q to quit):") print("Type new race's token name in full caps (q to quit):")
repeat repeat
entry=getline() entry=getline()
@ -11,10 +13,16 @@ function tools.setrace()
end end
id=RaceTable[entry] id=RaceTable[entry]
until id~=nil until id~=nil
else
id=RaceTable[name]
if id==nil then
error("Name not found!")
end
end
df.global.ui.race_id=id df.global.ui.race_id=id
end end
tools.menu:add("Set current race",tools.setrace) tools.menu:add("Set current race",tools.setrace)
function tools.GiveSentience(names) --TODO make pattern... function tools.GiveSentience(names)
RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again
if names ==nil then if names ==nil then
ids={} ids={}
@ -63,23 +71,7 @@ function tools.embark()
end end
end end
tools.menu:add("Embark anywhere",tools.embark) tools.menu:add("Embark anywhere",tools.embark)
function tools.getlegendsid(croff) function tools.getCreatureId(vector) --redo it to getcreature by name
local vec=engine.peek(croff,ptr_Creature.legends)
if vec:size()==0 then
return 0
end
for i =0,vector:size()-1 do
--if engine.peekd(vec:getval(i))~=0 then
-- print(string.format("%x",engine.peekd(vec:getval(i))-offsets.base()))
--end
if(engine.peekd(vec:getval(i))==offsets.getEx("vtableLegends")) then --easy to get.. just copy from player's-base
return engine.peekd(vec:getval(i)+4)
end
end
return 0
end
function tools.getCreatureId(vector)
tnames={} tnames={}
rnames={} rnames={}
--[[print("vector1 size:"..vector:size()) --[[print("vector1 size:"..vector:size())
@ -137,22 +129,25 @@ function tools.change_adv()
end end
tools.menu:add("Change Adventurer",tools.change_adv) tools.menu:add("Change Adventurer",tools.change_adv)
function tools.MakeFollow() function tools.MakeFollow(unit,trgunit)
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff,ptr_vector)
indx=tools.getCreatureId(vector)
print(string.format("current creature:%x",vector:getval(indx)))
trgid=engine.peek(vector:getval(0)+ptr_Creature.ID.off,DWORD) if unit == nil then
lfollow=engine.peek(vector:getval(indx)+ptr_Creature.followID.off,DWORD) unit=getCreature()
if lfollow ~=0xFFFFFFFF then
print("Already following, unfollow? y/N")
r=getline()
if r== "y" then
engine.poke(vector:getval(indx)+ptr_Creature.followID.off,DWORD,0)
end end
else if unit== nil then
engine.poke(vector:getval(indx)+ptr_Creature.followID.off,DWORD,trgid) error("Invalid creature")
end
if trgunit==nil then
trgunit=df.global.world.units.other[0][0]
end
unit.relations.group_leader_id=trgunit.id
local u_nem=getNemesis(unit)
local t_nem=getNemesis(trgunit)
if u_nem then
u_nem.group_leader_id=t_nem.id
end
if t_nem and u_nem then
t_nem.companions:insert(#t_nem.companions,u_nem.id)
end end
end end
tools.menu:add("Make creature follow",tools.MakeFollow) tools.menu:add("Make creature follow",tools.MakeFollow)