Petr Mrázek 2012-03-24 17:10:19 +01:00
commit 3331bc31f6
6 changed files with 26 additions and 23 deletions

@ -20,6 +20,7 @@
#include "functioncall.h" #include "functioncall.h"
#include "lua_FunctionCall.h" #include "lua_FunctionCall.h"
#include "lua_Offsets.h" #include "lua_Offsets.h"
#include "DataDefs.h"
using std::vector; using std::vector;
using std::string; using std::string;
@ -45,6 +46,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
{ {
lua::state st=lua::glua::Get(); lua::state st=lua::glua::Get();
//maybe remake it to run automaticaly //maybe remake it to run automaticaly
DFHack::AttachDFGlobals(st);
lua::RegisterConsole(st); lua::RegisterConsole(st);
lua::RegisterProcess(st); lua::RegisterProcess(st);
lua::RegisterHexsearch(st); lua::RegisterHexsearch(st);

@ -371,12 +371,12 @@ function GetRaceToken(p) --actually gets token...
end end
function BuildNameTable() function BuildNameTable()
local rtbl={} local rtbl={}
local vec=df.world.raws.creatures.all local vec=df.global.world.raws.creatures.all
--print(string.format("Vector start:%x",vec.st)) --print(string.format("Vector start:%x",vec.st))
--print(string.format("Vector end:%x",vec.en)) --print(string.format("Vector end:%x",vec.en))
--print("Creature count:"..vec.size) --print("Creature count:"..vec.size)
for k,v in iter(vec) do for k=0,#vec-1 do
local name=v:deref().creature_id local name=vec[k].creature_id
--print(k.." "..tostring(name)) --print(k.." "..tostring(name))
rtbl[name]=k rtbl[name]=k
end end
@ -468,29 +468,29 @@ function ParseNames(path)
return ret return ret
end end
function getSelectedUnit() function getSelectedUnit()
local unit_indx=df.ui_selected_unit local unit_indx=df.global.ui_selected_unit
if unit_indx<df.world.units.other[0].size then if unit_indx<#df.global.world.units.other[0]-1 then
return df.world.units.other[0][unit_indx]:deref() return df.global.world.units.other[0][unit_indx]
else else
return nil return nil
end end
end end
function getxyz() -- this will return pointers x,y and z coordinates. function getxyz() -- this will return pointers x,y and z coordinates.
local x=df.cursor.x local x=df.global.cursor.x
local y=df.cursor.y local y=df.global.cursor.y
local z=df.cursor.z local z=df.global.cursor.z
return x,y,z -- return the coords return x,y,z -- return the coords
end end
function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord
--local x,y,z=getxyz() --get 'X' coords --local x,y,z=getxyz() --get 'X' coords
local vector=df.world.units.all -- load all creatures local vector=df.global.world.units.all -- load all creatures
for i = 0, vector.size-1 do -- look into all creatures offsets for i = 0, #vector-1 do -- look into all creatures offsets
local curpos=vector[i]:deref().pos --get its coordinates local curpos=vector[i].pos --get its coordinates
local cx=curpos.x local cx=curpos.x
local cy=curpos.y local cy=curpos.y
local cz=curpos.z local cz=curpos.z
if cx==x and cy==y and cz==z then --compare them if cx==x and cy==y and cz==z then --compare them
return vector[i]:deref() --return index return vector[i] --return index
end end
end end
print("Creature not found!") print("Creature not found!")

@ -42,7 +42,7 @@ function embark(names)
count=MakeTable(modpos,modsize,names) --just remake tables count=MakeTable(modpos,modsize,names) --just remake tables
else else
tofind=addressOf(df.ui,"race_id") _,tofind=df.sizeof(df.global.ui:_field("race_id"))
loc=offsets.find(stoff,0x0f,0xb7,0x0d,DWORD_,tofind) --MOVZX ECX,WORD PTR[] loc=offsets.find(stoff,0x0f,0xb7,0x0d,DWORD_,tofind) --MOVZX ECX,WORD PTR[]

@ -1,7 +1,7 @@
function friendship_in.patch() function friendship_in.patch()
UpdateRanges() UpdateRanges()
pos=GetTextRegion().start pos=GetTextRegion().start
local crace=addressOf(df.ui,"race_id")--VersionInfo.getGroup("Creatures"):getAddress("current_race") local _,crace=df.sizeof(df.global.ui:_field("race_id"))
hits={} hits={}
i=1 i=1
repeat repeat

@ -57,7 +57,7 @@ dofile("dfusion/common.lua")
dofile("dfusion/utils.lua") dofile("dfusion/utils.lua")
dofile("dfusion/offsets_misc.lua") dofile("dfusion/offsets_misc.lua")
dofile("dfusion/editor.lua") dofile("dfusion/editor.lua")
dofile("dfusion/xml_struct.lua") --dofile("dfusion/xml_struct.lua")
unlockDF() unlockDF()
plugins={} plugins={}
table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"}) table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"})

@ -2,7 +2,7 @@ tools={}
tools.menu=MakeMenu() tools.menu=MakeMenu()
function tools.setrace() function tools.setrace()
RaceTable=BuildNameTable() RaceTable=BuildNameTable()
print("Your current race is:"..GetRaceToken(df.ui.race_id)) print("Your current race is:"..GetRaceToken(df.global.ui.race_id))
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,7 +11,7 @@ function tools.setrace()
end end
id=RaceTable[entry] id=RaceTable[entry]
until id~=nil until id~=nil
df.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) --TODO make pattern...
@ -32,15 +32,15 @@ function tools.GiveSentience(names) --TODO make pattern...
end end
end end
for _,id in pairs(ids) do for _,id in pairs(ids) do
local races=df.world.raws.creatures.all local races=df.global.world.raws.creatures.all
local castes=races[id]:deref().caste local castes=races[id].caste
print(string.format("Caste count:%i",castes.size)) print(string.format("Caste count:%i",castes.size))
for i =0,castes.size-1 do for i =0,#castes-1 do
print("Caste name:"..castes[i]:deref().caste_id.."...") print("Caste name:"..castes[i].caste_id.."...")
local flags=castes[i]:deref().flags local flags=castes[i].flags
--print(string.format("%x",flagoffset)) --print(string.format("%x",flagoffset))
if flags.CAN_SPEAK then if flags.CAN_SPEAK then
print("\tis sentient.") print("\tis sentient.")