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.menu=adv_tools.menu or MakeMenu()
--TODO make every tool generic (work for both modes)
function adv_tools.ressurect()
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
end
end
print("Creature not found!")
--print("Creature not found!")
return nil
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)
local ptr=engine.getmod('General_Space')
if ptr==nil then
@ -512,14 +536,6 @@ function Allocate(size)
engine.poked(ptr,curptr)
return curptr-size+ptr
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/patterns2.lua")
dofile("dfusion/itempatterns.lua")

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

@ -1,20 +1,28 @@
tools={}
tools.menu=MakeMenu()
function tools.setrace()
function tools.setrace(name)
RaceTable=BuildNameTable()
print("Your current race is:"..GetRaceToken(df.global.ui.race_id))
print("Type new race's token name in full caps (q to quit):")
repeat
entry=getline()
if entry=="q" then
return
local id
if name == nil then
print("Type new race's token name in full caps (q to quit):")
repeat
entry=getline()
if entry=="q" then
return
end
id=RaceTable[entry]
until id~=nil
else
id=RaceTable[name]
if id==nil then
error("Name not found!")
end
id=RaceTable[entry]
until id~=nil
end
df.global.ui.race_id=id
end
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
if names ==nil then
ids={}
@ -63,23 +71,7 @@ function tools.embark()
end
end
tools.menu:add("Embark anywhere",tools.embark)
function tools.getlegendsid(croff)
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)
function tools.getCreatureId(vector) --redo it to getcreature by name
tnames={}
rnames={}
--[[print("vector1 size:"..vector:size())
@ -137,22 +129,25 @@ function tools.change_adv()
end
tools.menu:add("Change Adventurer",tools.change_adv)
function tools.MakeFollow()
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff,ptr_vector)
indx=tools.getCreatureId(vector)
print(string.format("current creature:%x",vector:getval(indx)))
function tools.MakeFollow(unit,trgunit)
trgid=engine.peek(vector:getval(0)+ptr_Creature.ID.off,DWORD)
lfollow=engine.peek(vector:getval(indx)+ptr_Creature.followID.off,DWORD)
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
else
engine.poke(vector:getval(indx)+ptr_Creature.followID.off,DWORD,trgid)
if unit == nil then
unit=getCreature()
end
if unit== nil then
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
tools.menu:add("Make creature follow",tools.MakeFollow)