From 27bdc9f2df02ccd566eddc5fe1ffa2a09d7e6143 Mon Sep 17 00:00:00 2001 From: Warmist Date: Thu, 23 Aug 2012 21:38:38 +0300 Subject: [PATCH 001/158] Start gutting dfusion. --- plugins/Dfusion/readme.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/Dfusion/readme.txt b/plugins/Dfusion/readme.txt index c40ac3707..df3b85b1f 100644 --- a/plugins/Dfusion/readme.txt +++ b/plugins/Dfusion/readme.txt @@ -10,3 +10,5 @@ Similar to dfusion but not interactive. To be used with hotkeys (later will have Also dfuse/dfusion runs an init script located at 'save directory/dfusion/init.lua'. And 'initcustom.lua' if it exists More info http://dwarffortresswiki.org/index.php/Utility:DFusion + +a \ No newline at end of file From 90021b4e5e8451e1505f1344b4862a05cbe9711a Mon Sep 17 00:00:00 2001 From: Warmist Date: Thu, 30 Aug 2012 20:41:10 +0300 Subject: [PATCH 002/158] simple_embark/plugin.lua sanitized --- plugins/Dfusion/luafiles/init.lua | 11 +++-------- .../Dfusion/luafiles/simple_embark/plugin.lua | 16 ++++++++++++---- plugins/Dfusion/readme.txt | 2 -- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/plugins/Dfusion/luafiles/init.lua b/plugins/Dfusion/luafiles/init.lua index 19f63d603..c8eebcd23 100644 --- a/plugins/Dfusion/luafiles/init.lua +++ b/plugins/Dfusion/luafiles/init.lua @@ -1,11 +1,7 @@ -function err(msg) --make local maybe... - print(msg) - print(debug.traceback()) -end function dofile(filename) --safer dofile, with traceback (very usefull) f,perr=loadfile(filename) if f~=nil then - return xpcall(f,err) + return safecall(f) else print(perr) end @@ -13,7 +9,7 @@ end function dofile_silent(filename) --safer dofile, with traceback, no file not found error f,perr=loadfile(filename) if f~=nil then - return xpcall(f,err) + return safecall(f) else if(string.sub(perr,1,11)~="cannot open") then --ugly hack print(perr) @@ -26,7 +22,6 @@ function loadall(t1) --loads all non interactive plugin parts, so that later the end end function mainmenu(t1) - while true do print("No. Name Desc") for k,v in pairs(t1) do @@ -58,7 +53,7 @@ dofile("dfusion/common.lua") dofile("dfusion/utils.lua") dofile("dfusion/offsets_misc.lua") dofile("dfusion/editor.lua") ---dofile("dfusion/xml_struct.lua") + unlockDF() plugins={} table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"}) diff --git a/plugins/Dfusion/luafiles/simple_embark/plugin.lua b/plugins/Dfusion/luafiles/simple_embark/plugin.lua index c64aa7e68..f4f594e8d 100644 --- a/plugins/Dfusion/luafiles/simple_embark/plugin.lua +++ b/plugins/Dfusion/luafiles/simple_embark/plugin.lua @@ -1,10 +1,18 @@ function simple_embark(num) -stoff=VersionInfo.getAddress('start_dwarf_count') -print("Starting dwarves found:"..engine.peekd(stoff)) -engine.poked(stoff,num) + local stoff=dfhack.internal.getAddress('start_dwarf_count') + print("Starting dwarves found:"..df.reinterpret_cast('int32_t', stoff).value) + local tmp_val=df.new('int32_t') + local size,pos=tmp_val:sizeof() + tmp_val.value=num + local ret=dfhack.internal.patchMemory(stoff,tmp_val,size) + if ret then + print("Success!") + else + qerror("Failed to patch in number") + end end if not(FILE) then -print("Type in new ammount:") +print("Type in new ammount (more than 6, less than 15000):") repeat ans=tonumber(io.read()) if ans==nil or not(ans<=15000 and ans>0) then diff --git a/plugins/Dfusion/readme.txt b/plugins/Dfusion/readme.txt index df3b85b1f..c40ac3707 100644 --- a/plugins/Dfusion/readme.txt +++ b/plugins/Dfusion/readme.txt @@ -10,5 +10,3 @@ Similar to dfusion but not interactive. To be used with hotkeys (later will have Also dfuse/dfusion runs an init script located at 'save directory/dfusion/init.lua'. And 'initcustom.lua' if it exists More info http://dwarffortresswiki.org/index.php/Utility:DFusion - -a \ No newline at end of file From f8744e2ec259cdb72c77e6095cf2e7e329ba081d Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 31 Aug 2012 23:46:33 +0300 Subject: [PATCH 003/158] Experimental stuff editor (can and will crash DF ) --- scripts/gui/gm-Items.lua | 181 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 scripts/gui/gm-Items.lua diff --git a/scripts/gui/gm-Items.lua b/scripts/gui/gm-Items.lua new file mode 100644 index 000000000..82a1da154 --- /dev/null +++ b/scripts/gui/gm-Items.lua @@ -0,0 +1,181 @@ +-- Interface powered item editor. +-- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay) +local gui = require 'gui' + +if dfhack.gui.getCurFocus() ~= 'item' then + qerror("This script requires the item view.") +end + +TextInputDialog = defclass(TextInputDialog, gui.FramedScreen) + +function TextInputDialog:init(prompt) + self.frame_style=GREY_LINE_FRAME + self.frame_title=prompt + self.input="" + return self +end +function TextInputDialog:onRenderBody(dc) + dc:seek(1,1):string(self.input, COLOR_WHITE):newline() +end + +local MODE_BROWSE=0 +local MODE_EDIT=1 +local item_screen={ + frame_style = gui.GREY_LINE_FRAME, + frame_title = "GameMaster's editor", + stack={}, + item_count=0, + mode=MODE_BROWSE, + + keys={}, + insertNew=function(self) + --[=[local trg=self:currentTarget() -- not sure if possible... + if trg.target and trg.target._kind and trg.target._kind=="container" then + local thing=df.new('general_ref_contained_itemst') + trg.target:insert('#',trg.keys[trg.selected]) + end]=] + end, + deleteSelected=function(self) + local trg=self:currentTarget() + if trg.target and trg.target._kind and trg.target._kind=="container" then + trg.target:erase(trg.keys[trg.selected]) + end + end, + currentTarget=function(self) + return self.stack[#self.stack] + end, + changeSelected = function (self,delta) + local trg=self:currentTarget() + if trg.item_count <= 1 then return end + trg.selected = 1 + (trg.selected + delta - 1) % trg.item_count + end, + editSelected = function(self) + local trg=self:currentTarget() + if trg.target and trg.target._kind and trg.target._kind=="bitfield" then + trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]] + else + --print(type(trg.target[trg.keys[trg.selected]]),trg.target[trg.keys[trg.selected]]._kind or "") + local trg_type=type(trg.target[trg.keys[trg.selected]]) + if trg_type=='number' or trg_type=='string' then --ugly TODO: add metatable get selected + self.mode=MODE_EDIT + self.input=tostring(trg.target[trg.keys[trg.selected]]) + elseif trg_type=='userdata' then + self:pushTarget(trg.target[trg.keys[trg.selected]]) + --local screen = mkinstance(gui.FramedScreen,item_screen):init(trg.target[trg.keys[trg.selected]]) -- does not work + --screen:show() + else + print("Unknow type:"..trg_type) + print("Subtype:"..tostring(trg.target[trg.keys[trg.selected]]._kind)) + end + end + end, + cancelEdit = function(self) + self.mode=MODE_BROWSE + self.input="" + end, + commitEdit = function(self) + local trg=self:currentTarget() + self.mode=MODE_BROWSE + if type(trg.target[trg.keys[trg.selected]])=='number' then + trg.target[trg.keys[trg.selected]]=tonumber(self.input) + elseif type(trg.target[trg.keys[trg.selected]])=='string' then + trg.target[trg.keys[trg.selected]]=self.input + end + end, + onRenderBody = function(self, dc) + local trg=self:currentTarget() + dc:seek(2,1):string(tostring(trg.target), COLOR_RED) + local offset=2 + local page_offset=0 + local current_item=1 + local t_col + if math.floor(trg.selected / (self.frame_height-offset-2)) >0 then + page_offset=math.floor(trg.selected / (self.frame_height-offset-2))*(self.frame_height-offset-2)-1 + end + for k,v in pairs(trg.target) do + + if current_item==trg.selected then + t_col=COLOR_LIGHTGREEN + else + t_col=COLOR_GRAY + end + + if current_item-page_offset > 0 then + local y_pos=current_item-page_offset+offset + dc:seek(2,y_pos):string(tostring(k),t_col) + + if self.mode==MODE_EDIT and current_item==trg.selected then + dc:seek(20,y_pos):string(self.input..'_',COLOR_GREEN) + else + dc:seek(20,y_pos):string(tostring(v),t_col) + end + end + current_item=current_item+1 + end + end, + + onInput = function(self,keys) + if self.mode==MODE_BROWSE then + if keys.LEAVESCREEN then + self:popTarget() + elseif keys.CURSOR_UP then + self:changeSelected(-1) + elseif keys.CURSOR_DOWN then + self:changeSelected(1) + elseif keys.CURSOR_UP_FAST then + self:changeSelected(-10) + elseif keys.CURSOR_DOWN_FAST then + self:changeSelected(10) + elseif keys.SELECT then + self:editSelected() + elseif keys.CUSTOM_ALT_E then + --self:specialEditor() + local screen = mkinstance(TextInputDialog):init("Input new coordinates") + screen:show() + elseif keys.CUSTOM_ALT_I then --insert + self:insertNew() + elseif keys.CUSTOM_ALT_D then --delete + self:deleteSelected() + end + elseif self.mode==MODE_EDIT then + if keys.LEAVESCREEN then + self:cancelEdit() + elseif keys.SELECT then + self:commitEdit() + elseif keys._STRING then + if keys._STRING==0 then + self.input=string.sub(self.input,1,-2) + else + self.input=self.input.. string.char(keys._STRING) + end + end + end + end, + pushTarget=function(self,target_to_push) + local new_tbl={} + new_tbl.target=target_to_push + new_tbl.keys={} + new_tbl.selected=1 + for k,v in pairs(target_to_push) do + table.insert(new_tbl.keys,k) + end + new_tbl.item_count=#new_tbl.keys + table.insert(self.stack,new_tbl) + end, + popTarget=function(self) + table.remove(self.stack) --removes last element + if #self.stack==0 then + self:dismiss() + end + end, + init = function(self,item_to_edit) + self:pushTarget(item_to_edit) + self.frame_width,self.frame_height=dfhack.screen.getWindowSize() + return self + end + } + + + +local screen = mkinstance(gui.FramedScreen,item_screen):init(dfhack.gui.getCurViewscreen().item) +screen:show() \ No newline at end of file From af155db3beca208cf1f842246db342db09bdc5cc Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 01:22:51 +0300 Subject: [PATCH 004/158] Added whole bunch of editable things (units, jobs, flows) --- scripts/gui/gm-Items.lua | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/gui/gm-Items.lua b/scripts/gui/gm-Items.lua index 82a1da154..839d3158a 100644 --- a/scripts/gui/gm-Items.lua +++ b/scripts/gui/gm-Items.lua @@ -2,8 +2,27 @@ -- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay) local gui = require 'gui' -if dfhack.gui.getCurFocus() ~= 'item' then - qerror("This script requires the item view.") +local my_trg +if dfhack.gui.getCurFocus() == 'item' then + my_trg=dfhack.gui.getCurViewscreen().item +elseif dfhack.gui.getCurFocus() == 'joblist' then + local t_screen=dfhack.gui.getCurViewscreen() + my_trg=t_screen.jobs[t_screen.cursor_pos] +elseif dfhack.gui.getCurFocus() == 'createquota' then + local t_screen=dfhack.gui.getCurViewscreen() + my_trg=t_screen.orders[t_screen.sel_idx] +elseif dfhack.gui.getCurFocus() == 'dwarfmode/LookAround/Flow' then + local t_look=df.global.ui_look_list.items[df.global.ui_look_cursor] + my_trg=t_look.flow + +elseif dfhack.gui.getSelectedUnit(true) then + my_trg=dfhack.gui.getSelectedUnit(true) +elseif dfhack.gui.getSelectedItem(true) then + my_trg=dfhack.gui.getSelectedItem(true) +elseif dfhack.gui.getSelectedJob(true) then + my_trg=dfhack.gui.getSelectedJob(true) +else + qerror("No valid target found") end TextInputDialog = defclass(TextInputDialog, gui.FramedScreen) @@ -177,5 +196,5 @@ local item_screen={ -local screen = mkinstance(gui.FramedScreen,item_screen):init(dfhack.gui.getCurViewscreen().item) +local screen = mkinstance(gui.FramedScreen,item_screen):init(my_trg) screen:show() \ No newline at end of file From c9c587af9aeae439313f64b23d40a862672726e2 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 01:27:01 +0300 Subject: [PATCH 005/158] small fix for boolean values --- scripts/gui/gm-Items.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/gui/gm-Items.lua b/scripts/gui/gm-Items.lua index 839d3158a..34e744ee2 100644 --- a/scripts/gui/gm-Items.lua +++ b/scripts/gui/gm-Items.lua @@ -78,6 +78,8 @@ local item_screen={ if trg_type=='number' or trg_type=='string' then --ugly TODO: add metatable get selected self.mode=MODE_EDIT self.input=tostring(trg.target[trg.keys[trg.selected]]) + elseif trg_type=='boolean' then + trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]] elseif trg_type=='userdata' then self:pushTarget(trg.target[trg.keys[trg.selected]]) --local screen = mkinstance(gui.FramedScreen,item_screen):init(trg.target[trg.keys[trg.selected]]) -- does not work From d784d4bc40e2b0b0d91513a22a3c22f5e042d59c Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 10:05:31 +0300 Subject: [PATCH 006/158] Static code segment search for memscan.lua --- library/lua/memscan.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua index 970f821c2..521f7c7e8 100644 --- a/library/lua/memscan.lua +++ b/library/lua/memscan.lua @@ -195,6 +195,36 @@ function MemoryArea:delete() for k,v in pairs(self) do self[k] = nil end end +-- Static code segment search +local function find_code_segment() + local code_start, code_end + + for i,mem in ipairs(dfhack.internal.getMemRanges()) do + if code_end then + if mem.start_addr == code_end and mem.read and not mem.write then + code_end = mem.end_addr + else + break + end + elseif mem.read and not mem.write + and (string.match(mem.name,'/dwarfort%.exe$') + or string.match(mem.name,'/Dwarf_Fortress$') + or string.match(mem.name,'Dwarf Fortress%.exe')) + then + code_start = mem.start_addr + code_end = mem.end_addr + end + end + + return code_start,code_end +end + +function get_code_segment() + local s, e = find_code_segment() + if s and e then + return ms.MemoryArea.new(s, e) + end +end -- Static data segment search local function find_data_segment() From 7cabf1b8435779c74ed498745920b8edbbacdd15 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 10:13:08 +0300 Subject: [PATCH 007/158] Small bug fix --- library/lua/memscan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua index 521f7c7e8..af2fe7435 100644 --- a/library/lua/memscan.lua +++ b/library/lua/memscan.lua @@ -222,7 +222,7 @@ end function get_code_segment() local s, e = find_code_segment() if s and e then - return ms.MemoryArea.new(s, e) + return MemoryArea.new(s, e) end end -- Static data segment search From 532839a4d5fd37fdbd52edd9cf5f7661f8232bdb Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 10:54:45 +0300 Subject: [PATCH 008/158] Embark anywhere ported --- library/lua/memscan.lua | 13 +++++++++++++ plugins/Dfusion/luafiles/simple_embark/plugin.lua | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua index af2fe7435..85ed5624a 100644 --- a/library/lua/memscan.lua +++ b/library/lua/memscan.lua @@ -225,6 +225,19 @@ function get_code_segment() return MemoryArea.new(s, e) end end +function get_code_segments() + local ret={} + for i,mem in ipairs(dfhack.internal.getMemRanges()) do + if mem.read and not mem.write + and (string.match(mem.name,'/dwarfort%.exe$') + or string.match(mem.name,'/Dwarf_Fortress$') + or string.match(mem.name,'Dwarf Fortress%.exe')) + then + table.insert(ret,MemoryArea.new(mem.start_addr,mem.end_addr)) + end + end + return ret +end -- Static data segment search local function find_data_segment() diff --git a/plugins/Dfusion/luafiles/simple_embark/plugin.lua b/plugins/Dfusion/luafiles/simple_embark/plugin.lua index f4f594e8d..abc3530c2 100644 --- a/plugins/Dfusion/luafiles/simple_embark/plugin.lua +++ b/plugins/Dfusion/luafiles/simple_embark/plugin.lua @@ -12,7 +12,7 @@ function simple_embark(num) end end if not(FILE) then -print("Type in new ammount (more than 6, less than 15000):") +print("Type in new amount (more than 6, less than 15000):") repeat ans=tonumber(io.read()) if ans==nil or not(ans<=15000 and ans>0) then From 5b60dc296a1e039c0fb0084f63f07a3825ab0ad8 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 21:53:52 +0300 Subject: [PATCH 009/158] Renamed editor and added example keybinding --- dfhack.init-example | 3 +++ scripts/gui/{gm-Items.lua => gm-editor.lua} | 0 2 files changed, 3 insertions(+) rename scripts/gui/{gm-Items.lua => gm-editor.lua} (100%) diff --git a/dfhack.init-example b/dfhack.init-example index d3a28b9b0..a9de146c2 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -52,6 +52,9 @@ keybinding add Alt-R@dwarfmode/QueryBuilding/Some gui/room-list.work # interface for the liquids plugin keybinding add Alt-L@dwarfmode/LookAround gui/liquids +# interface for universal game master's editor +keybinding add Alt-Shift-E gui/gm-editor + ################### # UI logic tweaks # ################### diff --git a/scripts/gui/gm-Items.lua b/scripts/gui/gm-editor.lua similarity index 100% rename from scripts/gui/gm-Items.lua rename to scripts/gui/gm-editor.lua From 2574bb1e3d277627f1855ec78e59c4a4ace5e7dd Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 1 Sep 2012 21:58:01 +0300 Subject: [PATCH 010/158] embark anywhere upgrade. --- plugins/Dfusion/luafiles/tools/init.lua | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/plugins/Dfusion/luafiles/tools/init.lua b/plugins/Dfusion/luafiles/tools/init.lua index e3a4607cf..b9978d020 100644 --- a/plugins/Dfusion/luafiles/tools/init.lua +++ b/plugins/Dfusion/luafiles/tools/init.lua @@ -1,3 +1,4 @@ +local ms=require "memscan" tools={} tools.menu=MakeMenu() function tools.setrace(name) @@ -60,14 +61,31 @@ function tools.GiveSentience(names) end end tools.menu:add("Give Sentience",tools.GiveSentience) -function tools.embark() - off=offsets.find(0,0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04) - if off~=0 then - engine.pokeb(off+5,0x90) - engine.pokeb(off+6,0x90) - print("Found and patched") +function embark() --windows only? + local seg=ms.get_code_segments() + printall(seg) + local idx,off + for k,v in ipairs(seg) do + idx,off=v.uint8_t:find_one{0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04} + if idx then + break + end + end + + if idx then + local tmp_val=df.new('uint8_t',2) + tmp_val[0]=0x90 + tmp_val[1]=0x90 + local size,pos=tmp_val:sizeof() + local ret=dfhack.internal.patchMemory(off+5,pos,size*2) + if ret then + print("Found and patched:",off+5) + else + print("Patching failed at:",off+5) + end + tmp_val:delete() else - print("not found") + qerror("Offset for embark patch not found!") end end tools.menu:add("Embark anywhere",tools.embark) From 6fc10fc2683e82dc6c0552507f1700214019a514 Mon Sep 17 00:00:00 2001 From: Warmist Date: Wed, 5 Sep 2012 21:52:54 +0300 Subject: [PATCH 011/158] Fixed embark anywhere to use more sane code segment search --- library/lua/memscan.lua | 41 ++++++------------------- plugins/Dfusion/luafiles/tools/init.lua | 12 ++------ 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua index 85ed5624a..ba3efd708 100644 --- a/library/lua/memscan.lua +++ b/library/lua/memscan.lua @@ -196,48 +196,25 @@ function MemoryArea:delete() end -- Static code segment search -local function find_code_segment() - local code_start, code_end + +function get_code_segment() + local cstart, cend for i,mem in ipairs(dfhack.internal.getMemRanges()) do - if code_end then - if mem.start_addr == code_end and mem.read and not mem.write then - code_end = mem.end_addr - else - break - end - elseif mem.read and not mem.write + if mem.read and mem.execute and (string.match(mem.name,'/dwarfort%.exe$') or string.match(mem.name,'/Dwarf_Fortress$') or string.match(mem.name,'Dwarf Fortress%.exe')) then - code_start = mem.start_addr - code_end = mem.end_addr + cstart = mem.start_addr + cend = mem.end_addr end end - - return code_start,code_end -end - -function get_code_segment() - local s, e = find_code_segment() - if s and e then - return MemoryArea.new(s, e) + if cstart and cend then + return MemoryArea.new(cstart, cend) end end -function get_code_segments() - local ret={} - for i,mem in ipairs(dfhack.internal.getMemRanges()) do - if mem.read and not mem.write - and (string.match(mem.name,'/dwarfort%.exe$') - or string.match(mem.name,'/Dwarf_Fortress$') - or string.match(mem.name,'Dwarf Fortress%.exe')) - then - table.insert(ret,MemoryArea.new(mem.start_addr,mem.end_addr)) - end - end - return ret -end + -- Static data segment search local function find_data_segment() diff --git a/plugins/Dfusion/luafiles/tools/init.lua b/plugins/Dfusion/luafiles/tools/init.lua index b9978d020..7052715bc 100644 --- a/plugins/Dfusion/luafiles/tools/init.lua +++ b/plugins/Dfusion/luafiles/tools/init.lua @@ -61,17 +61,11 @@ function tools.GiveSentience(names) end end tools.menu:add("Give Sentience",tools.GiveSentience) -function embark() --windows only? - local seg=ms.get_code_segments() - printall(seg) +function tools.embark() --windows only? + local seg=ms.get_code_segment() local idx,off - for k,v in ipairs(seg) do - idx,off=v.uint8_t:find_one{0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04} - if idx then - break - end - end + idx,off=seg.uint8_t:find_one{0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04} if idx then local tmp_val=df.new('uint8_t',2) tmp_val[0]=0x90 From 85fc3384dd82f959be5fa0a8bedca995f674c67e Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 7 Sep 2012 17:25:39 +0300 Subject: [PATCH 012/158] Little cleanup and update to gm-editor --- .../luafiles/patterns/supplementary.xml | 7 --- .../luafiles/patterns/xml_angavrilov.lua | 55 ------------------- scripts/gui/gm-editor.lua | 24 ++++++-- 3 files changed, 19 insertions(+), 67 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/patterns/supplementary.xml delete mode 100644 plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua diff --git a/plugins/Dfusion/luafiles/patterns/supplementary.xml b/plugins/Dfusion/luafiles/patterns/supplementary.xml deleted file mode 100644 index e341a1368..000000000 --- a/plugins/Dfusion/luafiles/patterns/supplementary.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua b/plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua deleted file mode 100644 index dbd3ad692..000000000 --- a/plugins/Dfusion/luafiles/patterns/xml_angavrilov.lua +++ /dev/null @@ -1,55 +0,0 @@ - -function parseargs(s) - local arg = {} - string.gsub(s, "([%w%-]+)=([\"'])(.-)%2", function (w, _, a) - arg[w] = a - end) - return arg -end - -function collect(s) - local stack = {} - local top = {} - table.insert(stack, top) - local ni,c,label,xarg, empty - local i, j = 1, 1 - while true do - ni,j,c,label,xarg, empty = string.find(s, "<(%/?)([%w:%-]+)(.-)(%/?)>", i) - if not ni then break end - local text = string.sub(s, i, ni-1) - if not string.find(text, "^%s*$") then - table.insert(top, text) - end - if empty == "/" then -- empty element tag - table.insert(top, {label=label, xarg=parseargs(xarg), empty=1}) - elseif c == "" then -- start tag - top = {label=label, xarg=parseargs(xarg)} - table.insert(stack, top) -- new level - else -- end tag - local toclose = table.remove(stack) -- remove top - top = stack[#stack] - if #stack < 1 then - error("nothing to close with "..label) - end - if toclose.label ~= label then - error("trying to close "..toclose.label.." with "..label) - end - table.insert(top, toclose) - end - i = j+1 - end - local text = string.sub(s, i) - if not string.find(text, "^%s*$") then - table.insert(stack[#stack], text) - end - if #stack > 1 then - error("unclosed "..stack[#stack].label) - end - return stack[1] -end - -function parseXmlFile(path) - local f, e = io.open(path, "r") - local xml = f:read("*a") - return collect(xml) -end \ No newline at end of file diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index 34e744ee2..d95cb652b 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -1,6 +1,7 @@ -- Interface powered item editor. -- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay) local gui = require 'gui' +local dialog = require 'gui.dialogs' local my_trg if dfhack.gui.getCurFocus() == 'item' then @@ -47,12 +48,25 @@ local item_screen={ mode=MODE_BROWSE, keys={}, - insertNew=function(self) - --[=[local trg=self:currentTarget() -- not sure if possible... + + insertNew=function(self,typename) + local tp=typename + if typename== nil then + dialog.showInputPrompt("Class type","Input class type\n:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self)) + return + end + local ntype=df[tp] + if ntype== nil then + dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED) + return + end + + local trg=self:currentTarget() if trg.target and trg.target._kind and trg.target._kind=="container" then - local thing=df.new('general_ref_contained_itemst') - trg.target:insert('#',trg.keys[trg.selected]) - end]=] + local thing=ntype:new() + dfhack.call_with_finalizer(1,false,df.delete,thing,trg.target.insert,trg.target,'#',thing) + + end end, deleteSelected=function(self) local trg=self:currentTarget() From 4f9732bfdae5e09ab0f7d3f2825e77e4c76c2dab Mon Sep 17 00:00:00 2001 From: Warmist Date: Sat, 15 Sep 2012 15:44:15 +0300 Subject: [PATCH 013/158] Useless files removed, small bugfix --- plugins/Dfusion/luafiles/adv_tools/init.lua | 6 +- plugins/Dfusion/luafiles/buildingpatterns.lua | 24 - plugins/Dfusion/luafiles/editor.lua | 150 ---- plugins/Dfusion/luafiles/itempatterns.lua | 62 -- plugins/Dfusion/luafiles/patterns.lua | 248 ------ plugins/Dfusion/luafiles/patterns2.lua | 29 - plugins/Dfusion/luafiles/xml_struct.lua | 151 ---- plugins/Dfusion/luafiles/xml_types.lua | 734 ------------------ .../Dfusion/luafiles/xml_types_windows.lua | 159 ---- 9 files changed, 3 insertions(+), 1560 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/buildingpatterns.lua delete mode 100644 plugins/Dfusion/luafiles/editor.lua delete mode 100644 plugins/Dfusion/luafiles/itempatterns.lua delete mode 100644 plugins/Dfusion/luafiles/patterns.lua delete mode 100644 plugins/Dfusion/luafiles/patterns2.lua delete mode 100644 plugins/Dfusion/luafiles/xml_struct.lua delete mode 100644 plugins/Dfusion/luafiles/xml_types.lua delete mode 100644 plugins/Dfusion/luafiles/xml_types_windows.lua 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 Date: Sat, 15 Sep 2012 18:05:53 +0300 Subject: [PATCH 014/158] Removed unused triggers folder --- plugins/Dfusion/luafiles/triggers/compile.bat | 1 - .../Dfusion/luafiles/triggers/functions.lua | 20 ---- .../luafiles/triggers/functions_menu.lua | 12 -- plugins/Dfusion/luafiles/triggers/plugin.lua | 107 ------------------ .../Dfusion/luafiles/triggers/triggers.asm | 68 ----------- plugins/Dfusion/luafiles/triggers/triggers.o | Bin 720 -> 0 bytes .../luafiles/triggers/universalfunc.asm | 14 --- 7 files changed, 222 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/triggers/compile.bat delete mode 100644 plugins/Dfusion/luafiles/triggers/functions.lua delete mode 100644 plugins/Dfusion/luafiles/triggers/functions_menu.lua delete mode 100644 plugins/Dfusion/luafiles/triggers/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/triggers/triggers.asm delete mode 100644 plugins/Dfusion/luafiles/triggers/triggers.o delete mode 100644 plugins/Dfusion/luafiles/triggers/universalfunc.asm diff --git a/plugins/Dfusion/luafiles/triggers/compile.bat b/plugins/Dfusion/luafiles/triggers/compile.bat deleted file mode 100644 index 3b0fec1a2..000000000 --- a/plugins/Dfusion/luafiles/triggers/compile.bat +++ /dev/null @@ -1 +0,0 @@ -as -anl --32 -o triggers.o triggers.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/triggers/functions.lua b/plugins/Dfusion/luafiles/triggers/functions.lua deleted file mode 100644 index e6c3a62c9..000000000 --- a/plugins/Dfusion/luafiles/triggers/functions.lua +++ /dev/null @@ -1,20 +0,0 @@ -function func.Find_Print() - pos=offsets.find(offsets.base(),0x73,0x02,0x8b,0xce,0x53,0x6a,0x01,0x6a,0x06,CALL) -- a hack for now... - return engine.peekd(pos+10)+pos+14-offsets.base() -end -function func.PrintMessage(msg,color1,color2) - func.f_print_pos= func.f_print_pos or func.Find_Print() - print(string.format("Print @:%x",func.f_print_pos)) - debuger.suspend() - d=NewCallTable() -- make a call table - t=Allocate(string.len(msg)) - engine.pokestr(t,msg) - --print(string.format("Message location:%x",t)) - d["ECX"]=t --set ecx to message location - d["STACK5"]=color1 -- push to stack color1 - d["STACK4"]=color2 -- push to stack color2 - d["STACK3"]=0 -- this is usually 0 maybe a struct pointing to location of this message? - PushFunction(func.f_print_pos+offsets.base(),d) -- prep to call function - -- was 0x27F030 - debuger.resume() -end diff --git a/plugins/Dfusion/luafiles/triggers/functions_menu.lua b/plugins/Dfusion/luafiles/triggers/functions_menu.lua deleted file mode 100644 index 3256c6117..000000000 --- a/plugins/Dfusion/luafiles/triggers/functions_menu.lua +++ /dev/null @@ -1,12 +0,0 @@ -func={} -dofile("dfusion/triggers/functions.lua") -func.menu=MakeMenu() -function func.PrintMessage_() - print("Type a message:") - msg=io.stdin:read() - func.PrintMessage(msg,6,1) -end -if not(FILE) then -- if not in script mode - func.menu:add("Print message",func.PrintMessage_) - func.menu:display() -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/triggers/plugin.lua b/plugins/Dfusion/luafiles/triggers/plugin.lua deleted file mode 100644 index e8f31eac1..000000000 --- a/plugins/Dfusion/luafiles/triggers/plugin.lua +++ /dev/null @@ -1,107 +0,0 @@ -if FILE then - return -end -callinfo={} -callinfo.regs={} -callinfo.regs["EAX"]=0 -callinfo.regs["EBX"]=1 -callinfo.regs["ECX"]=2 -callinfo.regs["EDX"]=3 -callinfo.regs["ESI"]=4 -callinfo.regs["EDI"]=5 -callinfo.regs["STACK1"]=6 -callinfo.regs["STACK2"]=7 -callinfo.regs["STACK3"]=8 -callinfo.regs["STACK4"]=9 -callinfo.regs["STACK5"]=10 - -mypos=engine.getmod("triggers_main") - -function GetCount() - return engine.peek(0,triggers.count) -end -function SetCount(val) - engine.poke(0,triggers.count,val) -end -function NewCallTable(tbl) - ret=tbl or {} - for k,v in pairs(callinfo.regs) do - ret[k]=0 - end - return ret -end -function PushFunction(off,data) - local i=GetCount() - engine.poked(triggers.table.off+i*44,off) -- add function to table - engine.poked(triggers.data.off+0,data["EAX"]) --set register data... - engine.poked(triggers.data.off+4,data["EBX"]) - engine.poked(triggers.data.off+8,data["ECX"]) - engine.poked(triggers.data.off+12,data["EDX"]) - engine.poked(triggers.data.off+16,data["ESI"]) - engine.poked(triggers.data.off+20,data["EDI"]) - engine.poked(triggers.data.off+24,data["STACK1"]) - engine.poked(triggers.data.off+28,data["STACK2"]) - engine.poked(triggers.data.off+32,data["STACK3"]) - engine.poked(triggers.data.off+36,data["STACK4"]) - engine.poked(triggers.data.off+40,data["STACK5"]) - SetCount(i+1) -end -function loadTriggers() - if triggers then return end - triggers={} - p=engine.getmod("triggerdata") - triggers.count={off=engine.peekd(p),rtype=DWORD} - triggers.table={off=engine.peekd(p+4),rtype=DWORD} - triggers.ret={off=engine.peekd(p+8),rtype=DWORD} - triggers.data={off=engine.peekd(p+12),rtype=DWORD} -end -if mypos then - loadTriggers() - dofile("dfusion/triggers/functions_menu.lua") - --return -else - triggers={} - - off=0x56D345+offsets.base() - print(string.format("Function start %x",off)) - ModData=engine.installMod("dfusion/triggers/triggers.o","triggers_main") - print("installed") - modpos=ModData.pos - modsize=ModData.size - fdata=engine.newmod("function_body",256) - - - engine.poked(modpos+engine.FindMarker(ModData,"trigercount"),modpos+modsize) -- count of functions - engine.poked(modpos+engine.FindMarker(ModData,"f_loc"),modpos+modsize+4) -- function table start - engine.poked(modpos+engine.FindMarker(ModData,"f_data"),fdata) -- function data start - - engine.poked(modpos+engine.FindMarker(ModData,"saveplace31"),modpos+modsize+260) -- save function loc - engine.poked(modpos+engine.FindMarker(ModData,"saveplace32"),modpos+modsize+260) -- save function loc - engine.poked(modpos+engine.FindMarker(ModData,"saveplace33"),modpos+modsize+260) -- save function loc - engine.poked(modpos+engine.FindMarker(ModData,"saveplace"),modpos+modsize+256) -- save function loc - engine.poked(modpos+engine.FindMarker(ModData,"trigcount2"),modpos+modsize) -- count of functions (for zeroing) - engine.poked(modpos+engine.FindMarker(ModData,"saveplace2"),modpos+modsize+256) -- save function loc - engine.poked(modpos+engine.FindMarker(ModData,"results"),modpos+modsize+256) --overwrite function call with results - - triggers.count={off=modpos+modsize,rtype=DWORD} - triggers.table={off=modpos+modsize+4,rtype=DWORD} - triggers.ret={off=modpos+modsize+256,rtype=DWORD} - triggers.data={off=fdata,rtype=DWORD} - pp=Allocate(4*4) - engine.poked(pp,triggers.count.off) - engine.poked(pp+4,triggers.table.off) - engine.poked(pp+8,triggers.ret.off) - engine.poked(pp+12,triggers.data.off) - engine.newmod("triggerdata",0,pp) - function pokeCall(off) - engine.pokeb(off,0xe8) - --b=engine.peekb(off+1) - engine.poked(off+1,modpos-off-5) - --engine.pokeb(off+5,b) - end - print(string.format("Mod @:%x",modpos)) - dat=engine.peekarb(off,5) - engine.pokearb(modpos,dat,5) - pokeCall(off) -end - diff --git a/plugins/Dfusion/luafiles/triggers/triggers.asm b/plugins/Dfusion/luafiles/triggers/triggers.asm deleted file mode 100644 index 58b9e5f61..000000000 --- a/plugins/Dfusion/luafiles/triggers/triggers.asm +++ /dev/null @@ -1,68 +0,0 @@ -.intel_syntax -nop #5 nops for instruction thats replaced by call -nop -nop -nop -nop -pushad -pushfd -saveplace31: -mov [0xDEADBEEF], esp -trigercount: -mov eax, [0xDEADBEEF] #mov count of triggers. -f_loc: -mov esi, 0xdeadbeef #mov location of functions. -f_data: -mov ebx, 0xDEADBEEF #mov a start of function data -test eax,eax -jz lend -lstart: -dec eax -push ebx -push eax - -mov eax,[esi+eax*4] -saveplace: -mov [0xDEADBEEF],eax #save function for later -pop eax -push eax -mov edx,44 -mul edx -add eax,ebx -#stack preparation -mov ebx,[eax+24] -push ebx -mov ebx,[eax+28] -push ebx -mov ebx,[eax+32] -push ebx -mov ebx,[eax+36] -push ebx -mov ebx,[eax+40] -push ebx -mov ebx,[eax+4] -mov ecx,[eax+8] -mov edx,[eax+12] -mov esi,[eax+16] -mov edi,[eax+20] -mov eax,[eax] -saveplace2: -call [0xdeadbeef] #same save loc -results: -mov [0xDEADBEEF],eax #get result -saveplace33: -mov esp, [0xDEADBEEF] -add esp, -8 -pop eax -pop ebx -cmp eax,0 -jnz lstart -lend: -xor eax,eax -trigcount2: -mov dword ptr [0xDEADBEEF], eax # zero triggers -saveplace32: -mov esp, [0xDEADBEEF] -popfd -popad -ret diff --git a/plugins/Dfusion/luafiles/triggers/triggers.o b/plugins/Dfusion/luafiles/triggers/triggers.o deleted file mode 100644 index 5a47daa69bb4ac4f86773a23f66d5a73c8b6d7b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 720 zcmeZaWM%*X5k?>evsfARN>VFIz-$Q70i=46_#mbNgF%8`N@7VOnm9Vwfx+N_UQ%%} zx;Q$&0jO>Q2qetuRDHj1?Y)H{Vjqau4I)|(l!SQ%2XwQvEe3HT0(R*DjrjhE@kV!q zL~wV63=k^-u?i4t05MCq2S;}RPj`VpcZEnd!+%kbF0j^au<^}Dendn!|6nLxWq1Hd zcy8k12@~|vGILU)4*d6@fgznSEioG=faGu%Ae$YCfkDT>1{N0plDu${wD_F-WFSun zNdyvP;&73i)VvfRhoKB1Qe2W)1Pp!!xCoHJAOpl|C?X(UG+d-8wYW5=q?iE|9|-pt z0(ogDBDO$Y1&W9VkXH*AL5_QnIn0c0KoS)o$2${HiW#I34IsxkD1~8D69N=3PAp3; n$Vp62H8x}@DauSwElSQW%_~8OBUnZVrm- Date: Sun, 16 Sep 2012 13:20:55 +0300 Subject: [PATCH 015/158] More useless stuff removed --- plugins/Dfusion/luafiles/items/plugin.lua | 212 ---------------------- plugins/Dfusion/luafiles/tools/init.lua | 2 + 2 files changed, 2 insertions(+), 212 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/items/plugin.lua diff --git a/plugins/Dfusion/luafiles/items/plugin.lua b/plugins/Dfusion/luafiles/items/plugin.lua deleted file mode 100644 index 8b92785bd..000000000 --- a/plugins/Dfusion/luafiles/items/plugin.lua +++ /dev/null @@ -1,212 +0,0 @@ -items={} --> first lets make a menu table -items.menu=MakeMenu() - - -function items.dest() - myoff=offsets.getEx("Items") -- first find out where "item vector" is - vector=engine.peek(myoff,ptr_vector) -- get list of items - for i=0,vector:size()-1 do --look at each item - flg=engine.peek(vector:getval(i),ptr_item.flags) - flg:set(17,1) - engine.poke(vector:getval(i),ptr_item.flags,flg) - end -end -function items.eggs() - myoff=offsets.getEx("Items") -- first find out where "item vector" is - vector=engine.peek(myoff,ptr_vector) -- get list of items - for i=0,vector:size()-1 do --look at each item - rti=engine.peek(vector:getval(i),ptr_item.RTI) - if ptr_item.getname(nil,rti)=="item_eggst" then - egg=engine.peek(vector:getval(i),ptr_subitems["item_eggst"]) - egg.isfertile=1 - egg.hatchtime=0xffffff - --egg.race=123 -- change race for fun times - engine.poke(vector:getval(i),ptr_subitems["item_eggst"],egg) - end - end -end -function editFlags(offset) - while true do - flags=engine.peek(offset,ptr_item.flags) - for i=0,8*8-1 do - if flags:get(i) then - print(i.." is true") - else - print(i.." is false") - end - end - print(" enter number to switch flag or not a number to quit:") - q=tonumber(io.stdin:read()) - if q==nil then return end - flags:flip(q) - engine.poke(offset,ptr_item.flags,flags) - end -end -function editCovering(offset) - off=engine.peek(offset,ptr_item.ptr_covering) - if off == 0 then - print("No coverings found.") - end - vec=engine.peek(off,ptr_vector) - print("Covering list:") - for i=0,vec:size()-1 do - cov=engine.peek(vec:getval(i),ptr_cover) - print(string.format("%d. mat=%d submat=%d state=%d",i,cov.mat,cov.submat,cov.state)) - end - print("To edit type number:") - q=tonumber(io.stdin:read()) - if q==nil then return end - if q>=vec:size() or q<0 then return end - off=vec:getval(q) - cov=engine.peek(off,ptr_cover) - print("Enter mat:") - q=tonumber(io.stdin:read()) - if q==nil then q=0xffff end - print("Enter submat:") - v=tonumber(io.stdin:read()) - if v==nil then v=0xffff end - print("Enter state:") - y=tonumber(io.stdin:read()) - if y==nil then y=0 end - cov.mat=q - cov.submat=v - cov.state=y - engine.poke(off,ptr_cover,cov) -end -function editMaterial(offset) - print("Mat id 0 to 18 is in normal materials (inorganic, amber etc...) after that creature mat (with submat2 being race)") - print("from 219 with submat2=0xffffffff (type not a number) it reads legends id, from 419 submat2 means plant id") - print("Probably submat is not used :? ") - mat=engine.peek(offset,ptr_item.mat) - submat=engine.peek(offset,ptr_item.submat) - submat2=engine.peek(offset,ptr_item.submat2) - lid=engine.peek(offset,ptr_item.legendid) - print(string.format("Now is mat=%d, submat=%d submat2=%d legend id=%d",mat,submat,submat2,lid)) - print("Enter mat:") - q=tonumber(io.stdin:read()) - if q==nil then return end - print("Enter submat:") - v=tonumber(io.stdin:read()) - if v==nil then v=0xffff end - print("Enter submat2:") - z=tonumber(io.stdin:read()) - if z==nil then z=0xffffffff end - print("Enter legendid:") - y=tonumber(io.stdin:read()) - if y==nil then y=0xffffffff end - engine.poke(offset,ptr_item.mat,q) - engine.poke(offset,ptr_item.submat,v) - engine.poke(offset,ptr_item.legendid,y) - engine.poke(offset,ptr_item.submat2,z) - print("Done") -end -function items.select() - myoff=offsets.getEx("Items") - vector=engine.peek(myoff,ptr_vector) - tx,ty,tz=getxyz() - T={} - for i=0,vector:size()-1 do --this finds all item offsets that are on pointer - itoff=vector:getval(i) - x=engine.peek(itoff,ptr_item.x) - y=engine.peek(itoff,ptr_item.y) - z=engine.peek(itoff,ptr_item.z) - if x==tx and y==ty and z==tz then - table.insert(T,itoff) - end - end - print("Items under cursor:") - i=1 - for _,v in pairs(T) do - RTI=engine.peek(v,ptr_item.RTI) - print(i..". "..ptr_item.getname(nil,RTI)) - i=i+1 - end - print("Type number to edit or 'q' to exit") - while true do - q=io.stdin:read() - if q=='q' then return end - if tonumber(q) ~=nil and tonumber(q) Date: Sun, 23 Sep 2012 23:22:14 +0300 Subject: [PATCH 016/158] gm-editor fixes and improvements --- scripts/gui/gm-editor.lua | 341 +++++++++++++++++++------------------- 1 file changed, 172 insertions(+), 169 deletions(-) diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index d95cb652b..44345b3e8 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -1,5 +1,4 @@ -- Interface powered item editor. --- TODO use this: MechanismList = defclass(MechanismList, guidm.MenuOverlay) local gui = require 'gui' local dialog = require 'gui.dialogs' @@ -40,177 +39,181 @@ end local MODE_BROWSE=0 local MODE_EDIT=1 -local item_screen={ +GmEditorUi = defclass(GmEditorUi, gui.FramedScreen) +GmEditorUi.ATTRS={ frame_style = gui.GREY_LINE_FRAME, frame_title = "GameMaster's editor", - stack={}, - item_count=0, - mode=MODE_BROWSE, - - keys={}, - - insertNew=function(self,typename) - local tp=typename - if typename== nil then - dialog.showInputPrompt("Class type","Input class type\n:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self)) - return - end - local ntype=df[tp] - if ntype== nil then - dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED) - return - end - - local trg=self:currentTarget() - if trg.target and trg.target._kind and trg.target._kind=="container" then - local thing=ntype:new() - dfhack.call_with_finalizer(1,false,df.delete,thing,trg.target.insert,trg.target,'#',thing) - - end - end, - deleteSelected=function(self) - local trg=self:currentTarget() - if trg.target and trg.target._kind and trg.target._kind=="container" then - trg.target:erase(trg.keys[trg.selected]) - end - end, - currentTarget=function(self) - return self.stack[#self.stack] - end, - changeSelected = function (self,delta) - local trg=self:currentTarget() - if trg.item_count <= 1 then return end - trg.selected = 1 + (trg.selected + delta - 1) % trg.item_count - end, - editSelected = function(self) - local trg=self:currentTarget() - if trg.target and trg.target._kind and trg.target._kind=="bitfield" then - trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]] - else - --print(type(trg.target[trg.keys[trg.selected]]),trg.target[trg.keys[trg.selected]]._kind or "") - local trg_type=type(trg.target[trg.keys[trg.selected]]) - if trg_type=='number' or trg_type=='string' then --ugly TODO: add metatable get selected - self.mode=MODE_EDIT - self.input=tostring(trg.target[trg.keys[trg.selected]]) - elseif trg_type=='boolean' then - trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]] - elseif trg_type=='userdata' then - self:pushTarget(trg.target[trg.keys[trg.selected]]) - --local screen = mkinstance(gui.FramedScreen,item_screen):init(trg.target[trg.keys[trg.selected]]) -- does not work - --screen:show() - else - print("Unknow type:"..trg_type) - print("Subtype:"..tostring(trg.target[trg.keys[trg.selected]]._kind)) - end - end - end, - cancelEdit = function(self) - self.mode=MODE_BROWSE - self.input="" - end, - commitEdit = function(self) - local trg=self:currentTarget() - self.mode=MODE_BROWSE - if type(trg.target[trg.keys[trg.selected]])=='number' then - trg.target[trg.keys[trg.selected]]=tonumber(self.input) - elseif type(trg.target[trg.keys[trg.selected]])=='string' then - trg.target[trg.keys[trg.selected]]=self.input - end - end, - onRenderBody = function(self, dc) - local trg=self:currentTarget() - dc:seek(2,1):string(tostring(trg.target), COLOR_RED) - local offset=2 - local page_offset=0 - local current_item=1 - local t_col - if math.floor(trg.selected / (self.frame_height-offset-2)) >0 then - page_offset=math.floor(trg.selected / (self.frame_height-offset-2))*(self.frame_height-offset-2)-1 - end - for k,v in pairs(trg.target) do - - if current_item==trg.selected then - t_col=COLOR_LIGHTGREEN - else - t_col=COLOR_GRAY - end - - if current_item-page_offset > 0 then - local y_pos=current_item-page_offset+offset - dc:seek(2,y_pos):string(tostring(k),t_col) - - if self.mode==MODE_EDIT and current_item==trg.selected then - dc:seek(20,y_pos):string(self.input..'_',COLOR_GREEN) - else - dc:seek(20,y_pos):string(tostring(v),t_col) - end - end - current_item=current_item+1 - end - end, - - onInput = function(self,keys) - if self.mode==MODE_BROWSE then - if keys.LEAVESCREEN then - self:popTarget() - elseif keys.CURSOR_UP then - self:changeSelected(-1) - elseif keys.CURSOR_DOWN then - self:changeSelected(1) - elseif keys.CURSOR_UP_FAST then - self:changeSelected(-10) - elseif keys.CURSOR_DOWN_FAST then - self:changeSelected(10) - elseif keys.SELECT then - self:editSelected() - elseif keys.CUSTOM_ALT_E then - --self:specialEditor() - local screen = mkinstance(TextInputDialog):init("Input new coordinates") - screen:show() - elseif keys.CUSTOM_ALT_I then --insert - self:insertNew() - elseif keys.CUSTOM_ALT_D then --delete - self:deleteSelected() - end - elseif self.mode==MODE_EDIT then - if keys.LEAVESCREEN then - self:cancelEdit() - elseif keys.SELECT then - self:commitEdit() - elseif keys._STRING then - if keys._STRING==0 then - self.input=string.sub(self.input,1,-2) - else - self.input=self.input.. string.char(keys._STRING) - end - end - end - end, - pushTarget=function(self,target_to_push) - local new_tbl={} - new_tbl.target=target_to_push - new_tbl.keys={} - new_tbl.selected=1 - for k,v in pairs(target_to_push) do - table.insert(new_tbl.keys,k) - end - new_tbl.item_count=#new_tbl.keys - table.insert(self.stack,new_tbl) - end, - popTarget=function(self) - table.remove(self.stack) --removes last element - if #self.stack==0 then - self:dismiss() - end - end, - init = function(self,item_to_edit) - self:pushTarget(item_to_edit) - self.frame_width,self.frame_height=dfhack.screen.getWindowSize() - return self - end } +function GmEditorUi:init(args) + self.stack={} + self.item_count=0 + self.mode=MODE_BROWSE + self.keys={} + self:pushTarget(args.target) + + return self +end +function GmEditorUi:insertNew(typename) + local tp=typename + if typename== nil then + dialog.showInputPrompt("Class type","Input class type:",COLOR_WHITE,"",dfhack.curry(self.insertNew,self)) + return + end + local ntype=df[tp] + if ntype== nil then + dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED) + return + end + + local trg=self:currentTarget() + if trg.target and trg.target._kind and trg.target._kind=="container" then + local thing=ntype:new() + dfhack.call_with_finalizer(1,false,df.delete,thing,trg.target.insert,trg.target,'#',thing) + + end +end +function GmEditorUi:deleteSelected() + local trg=self:currentTarget() + if trg.target and trg.target._kind and trg.target._kind=="container" then + trg.target:erase(trg.keys[trg.selected]) + end +end +function GmEditorUi:currentTarget() + return self.stack[#self.stack] +end +function GmEditorUi:changeSelected(delta) + local trg=self:currentTarget() + if trg.item_count <= 1 then return end + trg.selected = 1 + (trg.selected + delta - 1) % trg.item_count +end +function GmEditorUi:editSelected() + local trg=self:currentTarget() + if trg.target and trg.target._kind and trg.target._kind=="bitfield" then + trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]] + else + --print(type(trg.target[trg.keys[trg.selected]]),trg.target[trg.keys[trg.selected]]._kind or "") + local trg_type=type(trg.target[trg.keys[trg.selected]]) + if trg_type=='number' or trg_type=='string' then --ugly TODO: add metatable get selected + self.mode=MODE_EDIT + self.input=tostring(trg.target[trg.keys[trg.selected]]) + elseif trg_type=='boolean' then + trg.target[trg.keys[trg.selected]]= not trg.target[trg.keys[trg.selected]] + elseif trg_type=='userdata' then + self:pushTarget(trg.target[trg.keys[trg.selected]]) + --local screen = mkinstance(gui.FramedScreen,GmEditorUi):init(trg.target[trg.keys[trg.selected]]) -- does not work + --screen:show() + else + print("Unknow type:"..trg_type) + print("Subtype:"..tostring(trg.target[trg.keys[trg.selected]]._kind)) + end + end +end +function GmEditorUi:cancelEdit() + self.mode=MODE_BROWSE + self.input="" +end +function GmEditorUi:commitEdit() + local trg=self:currentTarget() + self.mode=MODE_BROWSE + if type(trg.target[trg.keys[trg.selected]])=='number' then + trg.target[trg.keys[trg.selected]]=tonumber(self.input) + elseif type(trg.target[trg.keys[trg.selected]])=='string' then + trg.target[trg.keys[trg.selected]]=self.input + end +end +function GmEditorUi:onRenderBody( dc) + local trg=self:currentTarget() + dc:seek(2,1):string(tostring(trg.target), COLOR_RED) + local offset=2 + local page_offset=0 + local current_item=1 + local t_col + local width,height=self:getWindowSize() + local window_height=height-offset-2 + local cursor_window=math.floor(trg.selected / window_height) + if cursor_window>0 then + page_offset=cursor_window*window_height-1 + end + for k,v in pairs(trg.target) do + + if current_item==trg.selected then + t_col=COLOR_LIGHTGREEN + else + t_col=COLOR_GRAY + end + + if current_item-page_offset > 0 then + local y_pos=current_item-page_offset+offset + dc:seek(2,y_pos):string(tostring(k),t_col) + + if self.mode==MODE_EDIT and current_item==trg.selected then + dc:seek(20,y_pos):string(self.input..'_',COLOR_GREEN) + else + dc:seek(20,y_pos):string(tostring(v),t_col) + end + if y_pos+3>height then + break + end + end + current_item=current_item+1 + + end +end + function GmEditorUi:onInput(keys) + if self.mode==MODE_BROWSE then + if keys.LEAVESCREEN then + self:popTarget() + elseif keys.CURSOR_UP then + self:changeSelected(-1) + elseif keys.CURSOR_DOWN then + self:changeSelected(1) + elseif keys.CURSOR_UP_FAST then + self:changeSelected(-10) + elseif keys.CURSOR_DOWN_FAST then + self:changeSelected(10) + elseif keys.SELECT then + self:editSelected() + elseif keys.CUSTOM_ALT_E then + --self:specialEditor() + local screen = mkinstance(TextInputDialog):init("Input new coordinates") + screen:show() + elseif keys.CUSTOM_ALT_I then --insert + self:insertNew() + elseif keys.CUSTOM_ALT_D then --delete + self:deleteSelected() + end + elseif self.mode==MODE_EDIT then + if keys.LEAVESCREEN then + self:cancelEdit() + elseif keys.SELECT then + self:commitEdit() + elseif keys._STRING then + if keys._STRING==0 then + self.input=string.sub(self.input,1,-2) + else + self.input=self.input.. string.char(keys._STRING) + end + end + end +end +function GmEditorUi:pushTarget(target_to_push) + local new_tbl={} + new_tbl.target=target_to_push + new_tbl.keys={} + new_tbl.selected=1 + for k,v in pairs(target_to_push) do + table.insert(new_tbl.keys,k) + end + new_tbl.item_count=#new_tbl.keys + table.insert(self.stack,new_tbl) +end +function GmEditorUi:popTarget() + table.remove(self.stack) --removes last element + if #self.stack==0 then + self:dismiss() + end +end +local screen = GmEditorUi{target=my_trg} - -local screen = mkinstance(gui.FramedScreen,item_screen):init(my_trg) screen:show() \ No newline at end of file From 39df1e0eceef0e6eafcb47f6274b26557f02ef61 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 23 Sep 2012 23:23:12 +0300 Subject: [PATCH 017/158] Removed unused stuff from editor --- scripts/gui/gm-editor.lua | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index 44345b3e8..a86a9f4a8 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -25,18 +25,6 @@ else qerror("No valid target found") end -TextInputDialog = defclass(TextInputDialog, gui.FramedScreen) - -function TextInputDialog:init(prompt) - self.frame_style=GREY_LINE_FRAME - self.frame_title=prompt - self.input="" - return self -end -function TextInputDialog:onRenderBody(dc) - dc:seek(1,1):string(self.input, COLOR_WHITE):newline() -end - local MODE_BROWSE=0 local MODE_EDIT=1 GmEditorUi = defclass(GmEditorUi, gui.FramedScreen) @@ -175,8 +163,6 @@ end self:editSelected() elseif keys.CUSTOM_ALT_E then --self:specialEditor() - local screen = mkinstance(TextInputDialog):init("Input new coordinates") - screen:show() elseif keys.CUSTOM_ALT_I then --insert self:insertNew() elseif keys.CUSTOM_ALT_D then --delete From 28354715fff082194499fabe7a02a37b72a53d71 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 23 Sep 2012 23:45:19 +0300 Subject: [PATCH 018/158] Editor with dialog mode (no without switching from/to console to edit anything!) --- scripts/gui/gm-editor.lua | 67 +++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index a86a9f4a8..309663bdf 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -1,30 +1,34 @@ -- Interface powered item editor. local gui = require 'gui' local dialog = require 'gui.dialogs' +local args={...} +function getTargetFromScreens() + local my_trg + if dfhack.gui.getCurFocus() == 'item' then + my_trg=dfhack.gui.getCurViewscreen().item + elseif dfhack.gui.getCurFocus() == 'joblist' then + local t_screen=dfhack.gui.getCurViewscreen() + my_trg=t_screen.jobs[t_screen.cursor_pos] + elseif dfhack.gui.getCurFocus() == 'createquota' then + local t_screen=dfhack.gui.getCurViewscreen() + my_trg=t_screen.orders[t_screen.sel_idx] + elseif dfhack.gui.getCurFocus() == 'dwarfmode/LookAround/Flow' then + local t_look=df.global.ui_look_list.items[df.global.ui_look_cursor] + my_trg=t_look.flow -local my_trg -if dfhack.gui.getCurFocus() == 'item' then - my_trg=dfhack.gui.getCurViewscreen().item -elseif dfhack.gui.getCurFocus() == 'joblist' then - local t_screen=dfhack.gui.getCurViewscreen() - my_trg=t_screen.jobs[t_screen.cursor_pos] -elseif dfhack.gui.getCurFocus() == 'createquota' then - local t_screen=dfhack.gui.getCurViewscreen() - my_trg=t_screen.orders[t_screen.sel_idx] -elseif dfhack.gui.getCurFocus() == 'dwarfmode/LookAround/Flow' then - local t_look=df.global.ui_look_list.items[df.global.ui_look_cursor] - my_trg=t_look.flow - -elseif dfhack.gui.getSelectedUnit(true) then - my_trg=dfhack.gui.getSelectedUnit(true) -elseif dfhack.gui.getSelectedItem(true) then - my_trg=dfhack.gui.getSelectedItem(true) -elseif dfhack.gui.getSelectedJob(true) then - my_trg=dfhack.gui.getSelectedJob(true) -else - qerror("No valid target found") + elseif dfhack.gui.getSelectedUnit(true) then + my_trg=dfhack.gui.getSelectedUnit(true) + elseif dfhack.gui.getSelectedItem(true) then + my_trg=dfhack.gui.getSelectedItem(true) + elseif dfhack.gui.getSelectedJob(true) then + my_trg=dfhack.gui.getSelectedJob(true) + else + qerror("No valid target found") + end + return my_trg end + local MODE_BROWSE=0 local MODE_EDIT=1 GmEditorUi = defclass(GmEditorUi, gui.FramedScreen) @@ -199,7 +203,22 @@ function GmEditorUi:popTarget() self:dismiss() end end +function show_editor(trg) + local screen = GmEditorUi{target=trg} + screen:show() +end +if #args~=0 then + if args[1]=="dialog" then + function thunk(entry) + local t=load("return "..entry)() + show_editor(t) + end + dialog.showInputPrompt("Gm Editor", "Object to edit:", COLOR_GRAY, "",thunk) + else + local t=load("return "..args[1])() + show_editor(t) + end +else + show_editor(getTargetFromScreens()) +end -local screen = GmEditorUi{target=my_trg} - -screen:show() \ No newline at end of file From bd2f3a9998c72d85d663da44fbdb30702b3e0c6d Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 25 Sep 2012 00:24:37 +0300 Subject: [PATCH 019/158] Moved lua out of dfusion. Now lua is a script. supports --file (or -f) flag, usage: lua or lua --file or just "lua" for interactive interpreter. --- plugins/Dfusion/dfusion.cpp | 62 ------------------------------------- scripts/lua.lua | 10 ++++++ 2 files changed, 10 insertions(+), 62 deletions(-) create mode 100644 scripts/lua.lua diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index 78c3fa8d1..6c698f58a 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -33,8 +33,6 @@ DFHACK_PLUGIN("dfusion") command_result dfusion (color_ostream &out, std::vector ¶meters); command_result dfuse (color_ostream &out, std::vector ¶meters); -command_result lua_run (color_ostream &out, std::vector ¶meters); -command_result lua_run_file (color_ostream &out, std::vector ¶meters); DFhackCExport const char * plugin_name ( void ) { @@ -65,8 +63,6 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector ' to run instead.",lua_run,true)); - commands.push_back(PluginCommand("runlua", "Run non-interactive interpreter. Use 'runlua ' to run .",lua_run_file,false)); mymutex=new tthread::mutex; return CR_OK; } @@ -107,64 +103,6 @@ DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c ) mymutex->unlock(); return CR_OK; } -command_result lua_run_file (color_ostream &out, std::vector ¶meters) -{ - if(parameters.size()==0) - { - out.printerr("runlua without file to run!"); - return CR_FAILURE; - } - return lua_run(out,parameters); -} -command_result lua_run (color_ostream &out, std::vector ¶meters) -{ - if (!parameters.empty()) - { - if (parameters[0] == "--core-context") - { - Lua::InterpreterLoop(out, Lua::Core::State, "core lua"); - return CR_OK; - } - else if (parameters[0] == "--core-reload") - { - CoreSuspender suspend; - - for (size_t i = 1; i < parameters.size(); i++) - { - lua_getglobal(Lua::Core::State, "reload"); - lua_pushstring(Lua::Core::State, parameters[i].c_str()); - Lua::SafeCall(out, Lua::Core::State, 1, 0); - } - - return CR_OK; - } - } - - mymutex->lock(); - lua::state s=lua::glua::Get(); - - if(parameters.size()>0) - { - try{ - s.loadfile(parameters[0]); //load file - for(size_t i=1;iunlock(); - return CR_OK; -} void RunDfusion(color_ostream &out, std::vector ¶meters) { mymutex->lock(); diff --git a/scripts/lua.lua b/scripts/lua.lua new file mode 100644 index 000000000..c2033b7e6 --- /dev/null +++ b/scripts/lua.lua @@ -0,0 +1,10 @@ +local args={...} +if args[1]=="--file" or args[1]=="-f" then + local f=loadfile (args[2]) + dfhack.pcall(f,table.unpack(args,3)) +elseif args[1]~=nil then + local f=load(args[1],'=(lua command)', 't',) + dfhack.pcall(f,table.unpack(args,2)) +else + dfhack.interpreter("lua","lua.history") +end \ No newline at end of file From cc5df57e53bf89b8cce51353c0a8b4f048d23679 Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 25 Sep 2012 10:24:45 +0300 Subject: [PATCH 020/158] Little error fixed in lua script --- scripts/lua.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lua.lua b/scripts/lua.lua index c2033b7e6..497498e86 100644 --- a/scripts/lua.lua +++ b/scripts/lua.lua @@ -3,7 +3,7 @@ if args[1]=="--file" or args[1]=="-f" then local f=loadfile (args[2]) dfhack.pcall(f,table.unpack(args,3)) elseif args[1]~=nil then - local f=load(args[1],'=(lua command)', 't',) + local f=load(args[1],'=(lua command)', 't') dfhack.pcall(f,table.unpack(args,2)) else dfhack.interpreter("lua","lua.history") From 0bee8c360e1ad76ea68352e5d1806f79f910cd66 Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 25 Sep 2012 10:25:47 +0300 Subject: [PATCH 021/158] Reaction hooks experimentation. --- plugins/CMakeLists.txt | 1 + plugins/lua/reactionhooks.lua | 13 ++ plugins/reactionhooks.cpp | 319 ++++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+) create mode 100644 plugins/lua/reactionhooks.lua create mode 100644 plugins/reactionhooks.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 0b0ad0461..4d4f7493f 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -123,6 +123,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(steam-engine steam-engine.cpp) DFHACK_PLUGIN(power-meter power-meter.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(siege-engine siege-engine.cpp LINK_LIBRARIES lua) + DFHACK_PLUGIN(reactionhooks reactionhooks.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(add-spatter add-spatter.cpp) # not yet. busy with other crud again... #DFHACK_PLUGIN(versionosd versionosd.cpp) diff --git a/plugins/lua/reactionhooks.lua b/plugins/lua/reactionhooks.lua new file mode 100644 index 000000000..5f3622e2f --- /dev/null +++ b/plugins/lua/reactionhooks.lua @@ -0,0 +1,13 @@ +local _ENV = mkmodule('plugins.reactionhooks') + +--[[ + + Native events: + + * onReactionComplete(burrow) + +--]] + +rawset_default(_ENV, dfhack.reactionhooks) + +return _ENV \ No newline at end of file diff --git a/plugins/reactionhooks.cpp b/plugins/reactionhooks.cpp new file mode 100644 index 000000000..4041b99a5 --- /dev/null +++ b/plugins/reactionhooks.cpp @@ -0,0 +1,319 @@ +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "df/item_liquid_miscst.h" +#include "df/item_constructed.h" +#include "df/builtin_mats.h" +#include "df/world.h" +#include "df/job.h" +#include "df/job_item.h" +#include "df/job_item_ref.h" +#include "df/ui.h" +#include "df/report.h" +#include "df/reaction.h" +#include "df/reaction_reagent_itemst.h" +#include "df/reaction_product_itemst.h" +#include "df/matter_state.h" +#include "df/contaminant.h" + +#include "MiscUtils.h" +#include "LuaTools.h" + +using std::vector; +using std::string; +using std::stack; +using namespace DFHack; +using namespace df::enums; + +using df::global::gps; +using df::global::world; +using df::global::ui; + +typedef df::reaction_product_itemst item_product; + +DFHACK_PLUGIN("reactionhooks"); + +struct ReagentSource { + int idx; + df::reaction_reagent *reagent; + + ReagentSource() : idx(-1), reagent(NULL) {} +}; + +struct MaterialSource : ReagentSource { + bool product; + std::string product_name; + + int mat_type, mat_index; + + MaterialSource() : product(false), mat_type(-1), mat_index(-1) {} +}; + +struct ProductInfo { + df::reaction *react; + item_product *product; + + MaterialSource material; + + bool isValid() { + return (material.mat_type >= 0 || material.reagent); + } +}; + +struct ReactionInfo { + df::reaction *react; + + std::vector products; +}; + +static std::map reactions; +static std::map products; + +static ReactionInfo *find_reaction(const std::string &name) +{ + auto it = reactions.find(name); + return (it != reactions.end()) ? &it->second : NULL; +} + +static bool is_lua_hook(const std::string &name) +{ + return name.size() > 9 && memcmp(name.data(), "LUA_HOOK_", 9) == 0; +} + +static void find_material(int *type, int *index, df::item *input, MaterialSource &mat) +{ + if (input && mat.reagent) + { + MaterialInfo info(input); + + if (mat.product) + { + if (!info.findProduct(info, mat.product_name)) + { + color_ostream_proxy out(Core::getInstance().getConsole()); + out.printerr("Cannot find product '%s'\n", mat.product_name.c_str()); + } + } + + *type = info.type; + *index = info.index; + } + else + { + *type = mat.mat_type; + *index = mat.mat_index; + } +} + + +/* + * Hooks + */ + +typedef std::map > item_table; + +static void index_items(item_table &table, df::job *job, ReactionInfo *info) +{ + for (int i = job->items.size()-1; i >= 0; i--) + { + auto iref = job->items[i]; + if (iref->job_item_idx < 0) continue; + auto iitem = job->job_items[iref->job_item_idx]; + + if (iitem->contains.empty()) + { + table[iitem->reagent_index].push_back(iref->item); + } + else + { + std::vector contents; + Items::getContainedItems(iref->item, &contents); + + for (int j = contents.size()-1; j >= 0; j--) + { + for (int k = iitem->contains.size()-1; k >= 0; k--) + { + int ridx = iitem->contains[k]; + auto reag = info->react->reagents[ridx]; + + if (reag->matchesChild(contents[j], info->react, iitem->reaction_id)) + table[ridx].push_back(contents[j]); + } + } + } + } +} + +df::item* find_item(ReagentSource &info, item_table &table) +{ + if (!info.reagent) + return NULL; + if (table[info.idx].empty()) + return NULL; + return table[info.idx].back(); +} + + + +df::item* find_item( + ReagentSource &info, + std::vector *in_reag, + std::vector *in_items +) { + if (!info.reagent) + return NULL; + for (int i = in_items->size(); i >= 0; i--) + if ((*in_reag)[i] == info.reagent) + return (*in_items)[i]; + return NULL; +} + +static void handle_reaction_done(color_ostream &out, df::unit *unit, std::vector *in_items, std::vector *out_items,bool *call_native){}; + +DEFINE_LUA_EVENT_4(onReactionComplete, handle_reaction_done, df::unit *, std::vector *,std::vector *,bool *); + + +DFHACK_PLUGIN_LUA_EVENTS { + DFHACK_LUA_EVENT(onReactionComplete), + DFHACK_LUA_END +}; + +struct product_hook : item_product { + typedef item_product interpose_base; + + DEFINE_VMETHOD_INTERPOSE( + void, produce, + (df::unit *unit, std::vector *out_items, + std::vector *in_reag, + std::vector *in_items, + int32_t quantity, int16_t skill, + df::historical_entity *entity, df::world_site *site) + ) { + if (auto product = products[this]) + { + color_ostream_proxy out(Core::getInstance().getConsole()); + bool call_native=true; + onReactionComplete(out,unit,in_items,out_items,&call_native); + if(!call_native) + return; + } + + INTERPOSE_NEXT(produce)(unit, out_items, in_reag, in_items, quantity, skill, entity, site); + } +}; + +IMPLEMENT_VMETHOD_INTERPOSE(product_hook, produce); + + + + + +/* + * Scan raws for matching reactions. + */ + + +static void parse_product( + color_ostream &out, ProductInfo &info, df::reaction *react, item_product *prod + ) { + info.react = react; + info.product = prod; + info.material.mat_type = prod->mat_type; + info.material.mat_index = prod->mat_index; +} + +static bool find_reactions(color_ostream &out) +{ + reactions.clear(); + + auto &rlist = world->raws.reactions; + + for (size_t i = 0; i < rlist.size(); i++) + { + if (!is_lua_hook(rlist[i]->code)) + continue; + reactions[rlist[i]->code].react = rlist[i]; + } + + for (auto it = reactions.begin(); it != reactions.end(); ++it) + { + auto &prod = it->second.react->products; + auto &out_prod = it->second.products; + + for (size_t i = 0; i < prod.size(); i++) + { + auto itprod = strict_virtual_cast(prod[i]); + if (!itprod) continue; + + out_prod.push_back(ProductInfo()); + parse_product(out, out_prod.back(), it->second.react, itprod); + } + + for (size_t i = 0; i < prod.size(); i++) + { + if (out_prod[i].isValid()) + products[out_prod[i].product] = &out_prod[i]; + } + } + + return !products.empty(); +} + +static void enable_hooks(bool enable) +{ + INTERPOSE_HOOK(product_hook, produce).apply(enable); +} + +DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) +{ + switch (event) { + case SC_WORLD_LOADED: + if (find_reactions(out)) + { + out.print("Detected reaction hooks - enabling plugin.\n"); + enable_hooks(true); + } + else + enable_hooks(false); + break; + case SC_WORLD_UNLOADED: + enable_hooks(false); + reactions.clear(); + products.clear(); + break; + default: + break; + } + + return CR_OK; +} + +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +{ + if (Core::getInstance().isWorldLoaded()) + plugin_onstatechange(out, SC_WORLD_LOADED); + + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + enable_hooks(false); + return CR_OK; +} From ddc83a0a72edb7c23abe8f08daa4750ead3dc5ea Mon Sep 17 00:00:00 2001 From: Warmist Date: Tue, 25 Sep 2012 11:30:38 +0300 Subject: [PATCH 022/158] Another dfusion nuking (not much left :) ) --- plugins/Dfusion/dfusion.cpp | 11 +- plugins/Dfusion/include/functioncall.h | 26 --- plugins/Dfusion/include/lua_FunctionCall.h | 14 -- plugins/Dfusion/include/lua_Misc.h | 1 - plugins/Dfusion/include/lua_Offsets.h | 13 -- plugins/Dfusion/include/lua_VersionInfo.h | 12 -- plugins/Dfusion/src/functioncall.cpp | 121 ------------- plugins/Dfusion/src/lua_FunctionCall.cpp | 39 ----- plugins/Dfusion/src/lua_Misc.cpp | 99 +---------- plugins/Dfusion/src/lua_Offsets.cpp | 190 --------------------- plugins/Dfusion/src/lua_VersionInfo.cpp | 115 ------------- 11 files changed, 5 insertions(+), 636 deletions(-) delete mode 100644 plugins/Dfusion/include/functioncall.h delete mode 100644 plugins/Dfusion/include/lua_FunctionCall.h delete mode 100644 plugins/Dfusion/include/lua_Offsets.h delete mode 100644 plugins/Dfusion/include/lua_VersionInfo.h delete mode 100644 plugins/Dfusion/src/functioncall.cpp delete mode 100644 plugins/Dfusion/src/lua_FunctionCall.cpp delete mode 100644 plugins/Dfusion/src/lua_Offsets.cpp delete mode 100644 plugins/Dfusion/src/lua_VersionInfo.cpp diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index 6c698f58a..0f49e860d 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -14,10 +14,8 @@ #include "lua_Process.h" #include "lua_Hexsearch.h" #include "lua_Misc.h" -#include "lua_VersionInfo.h" -#include "functioncall.h" -#include "lua_FunctionCall.h" -#include "lua_Offsets.h" + + #include "DataDefs.h" #include "LuaTools.h" @@ -43,15 +41,12 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector -using std::vector; -using std::size_t; -class FunctionCaller -{ -public: - enum callconv - { - STD_CALL, //__stdcall - all in stack - FAST_CALL, //__fastcall - as much in registers as fits - THIS_CALL, //__thiscall - eax ptr to this, rest in stack - CDECL_CALL //__cdecl - same as stdcall but no stack realign - }; - - FunctionCaller(size_t base):base_(base){}; - - int CallFunction(size_t func_ptr,callconv conv,const vector &arguments); - -private: - int CallF(size_t count,callconv conv,void* f,const vector &arguments); - size_t base_; -}; - -#endif //FUNCTIONCALL__H \ No newline at end of file diff --git a/plugins/Dfusion/include/lua_FunctionCall.h b/plugins/Dfusion/include/lua_FunctionCall.h deleted file mode 100644 index bc1af5685..000000000 --- a/plugins/Dfusion/include/lua_FunctionCall.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef LUA_FUNCTIONCALL__H -#define LUA_FUNCTIONCALL__H - -#include "luamain.h" -#include "functioncall.h" - -namespace lua -{ - - -void RegisterFunctionCall(lua::state &st); - -} -#endif \ No newline at end of file diff --git a/plugins/Dfusion/include/lua_Misc.h b/plugins/Dfusion/include/lua_Misc.h index b39d60214..ff4611456 100644 --- a/plugins/Dfusion/include/lua_Misc.h +++ b/plugins/Dfusion/include/lua_Misc.h @@ -7,7 +7,6 @@ #include #include "luamain.h" #include "OutFile.h" -#include "functioncall.h" #include "LuaTools.h" namespace lua diff --git a/plugins/Dfusion/include/lua_Offsets.h b/plugins/Dfusion/include/lua_Offsets.h deleted file mode 100644 index 8d6a94b95..000000000 --- a/plugins/Dfusion/include/lua_Offsets.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef LUA_OFFSETS_H -#define LUA_OFFSETS_H -#include "luamain.h" - -namespace lua -{ - -void RegisterEngine(lua::state &st); - -} - - -#endif \ No newline at end of file diff --git a/plugins/Dfusion/include/lua_VersionInfo.h b/plugins/Dfusion/include/lua_VersionInfo.h deleted file mode 100644 index a4d7ed658..000000000 --- a/plugins/Dfusion/include/lua_VersionInfo.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LUA_VERSIONINFO_H -#define LUA_VERSIONINFO_H -#include "Core.h" -#include -#include "luamain.h" -namespace lua -{ - -void RegisterVersionInfo(lua::state &st); - -} -#endif diff --git a/plugins/Dfusion/src/functioncall.cpp b/plugins/Dfusion/src/functioncall.cpp deleted file mode 100644 index b6c38c928..000000000 --- a/plugins/Dfusion/src/functioncall.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "functioncall.h" - -#ifdef LINUX_BUILD -#define __F_TDEF(CONV,CONV_,tag) typedef int(__attribute__ ( (CONV_) ) *F_TYPE##CONV##tag) -#else -#define __F_TDEF(CONV,CONV_,tag) typedef int(__ ## CONV_ *F_TYPE##CONV##tag) -#endif - -#define __F_T(CONV,tag) F_TYPE##CONV##tag -#define __F_TYPEDEFS(CONV,CONV_) __F_TDEF(CONV,CONV_,1)(int);\ - __F_TDEF(CONV,CONV_,2)(int,int);\ - __F_TDEF(CONV,CONV_,3)(int,int,int);\ - __F_TDEF(CONV,CONV_,4)(int,int,int,int);\ - __F_TDEF(CONV,CONV_,5)(int,int,int,int,int);\ - __F_TDEF(CONV,CONV_,6)(int,int,int,int,int,int);\ - __F_TDEF(CONV,CONV_,7)(int,int,int,int,int,int,int) - - -#define __FCALL(CONV,CONV_) if(conv==CONV)\ - { \ - if(count==1)\ - ret= (reinterpret_cast<__F_T(CONV,1)>(f))\ - (arguments[0]);\ - else if(count==2)\ - ret= (reinterpret_cast<__F_T(CONV,2)>(f))\ - (arguments[0],arguments[1]);\ - else if(count==3)\ - ret= (reinterpret_cast<__F_T(CONV,3)>(f))\ - (arguments[0],arguments[1],arguments[2]);\ - else if(count==4)\ - ret= (reinterpret_cast<__F_T(CONV,4)>(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3]);\ - else if(count==5)\ - ret= (reinterpret_cast<__F_T(CONV,5)>(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4]);\ - else if(count==6)\ - ret= (reinterpret_cast<__F_T(CONV,6)>(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]);\ - else if(count==7)\ - ret= (reinterpret_cast<__F_T(CONV,7)>(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);\ - } - -#define __FCALLEX(CONV,CONV_) if(conv==CONV)\ - { if(count==1) {__F_T(CONV,1) tmp_F=reinterpret_cast<__F_T(CONV,1)>(f); return tmp_F(arguments[0]);}\ - else if(count==2){__F_T(CONV,2) tmp_F=reinterpret_cast<__F_T(CONV,2)>(f); return tmp_F(arguments[0],arguments[1]);}\ - else if(count==3){__F_T(CONV,3) tmp_F=reinterpret_cast<__F_T(CONV,3)>(f); return tmp_F(arguments[0],arguments[1],arguments[2]);}\ - else if(count==4){__F_T(CONV,4) tmp_F=reinterpret_cast<__F_T(CONV,4)>(f); return tmp_F(arguments[0],arguments[1],arguments[2],arguments[3]);}\ - else if(count==5){__F_T(CONV,5) tmp_F=reinterpret_cast<__F_T(CONV,5)>(f); return tmp_F(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4]);}\ - else if(count==6){__F_T(CONV,6) tmp_F=reinterpret_cast<__F_T(CONV,6)>(f); return tmp_F(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]);}\ - else if(count==7){__F_T(CONV,7) tmp_F=reinterpret_cast<__F_T(CONV,7)>(f); return tmp_F(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);}\ - } - /*else if(count==8)\ - ret= (reinterpret_cast<__F_T(CONV,8)>(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7]);\ - else if(count==9)\ - ret= (reinterpret_cast(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8]);\ - else if(count==10)\ - ret= (reinterpret_cast(f))\ - (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9]);}*/ - - -/*int FunctionCaller::CallF(size_t count,callconv conv,void* f,const vector &arguments)//more complex but not more error safe -{ - __F_TYPEDEFS(STD_CALL,__stdcall); - __F_TYPEDEFS(FAST_CALL,__fastcall); - __F_TYPEDEFS(THIS_CALL,__thiscall); - __F_TYPEDEFS(CDECL_CALL,__cdecl); - { - __FCALLEX(STD_CALL,__stdcall); - __FCALLEX(FAST_CALL,__fastcall); - __FCALLEX(THIS_CALL,__thiscall); - __FCALLEX(CDECL_CALL,__cdecl); - } -}*/ -int FunctionCaller::CallFunction(size_t func_ptr,callconv conv,const vector &arguments) -{ - //nasty nasty code... -#ifdef LINUX_BUILD //quick fix - if(conv==THIS_CALL) - conv=STD_CALL; -#endif - void* f= reinterpret_cast(func_ptr+base_); - size_t count=arguments.size(); - if(count==0) - return (reinterpret_cast(f))(); //does not matter how we call it... - int ret=0; - //typedefs - __F_TYPEDEFS(STD_CALL,stdcall); - __F_TYPEDEFS(FAST_CALL,fastcall); - __F_TYPEDEFS(THIS_CALL,thiscall); - __F_TYPEDEFS(CDECL_CALL,cdecl); - //calls - __FCALL(STD_CALL,stdcall); - __FCALL(FAST_CALL,fastcall); - __FCALL(THIS_CALL,thiscall); - __FCALL(CDECL_CALL,cdecl); - return -1; //incorect type. Should probably throw... - //return CallF(count,conv,f,arguments); - /*//testing part{ worked some time ago..., put where DFHack::Core is accesible - c->Suspend(); - FunctionCaller caller(c->p->getBase()); - std::vector args; - args.push_back((size_t)"Hello world"); - args.push_back(4); - args.push_back(4); - args.push_back(0); - dfprint mprint=(dfprint)(0x27F030+c->p->getBase()); - mprint("Hello world",4,4,0); - //caller.CallFunction((0x27F030),FunctionCaller::THIS_CALL,args); - c->Resume(); - return CR_OK; - //}end testing*/ -} -#undef __FCALL -#undef __FCALLEX -#undef __F_TYPEDEFS -#undef __F_T diff --git a/plugins/Dfusion/src/lua_FunctionCall.cpp b/plugins/Dfusion/src/lua_FunctionCall.cpp deleted file mode 100644 index a537edbb5..000000000 --- a/plugins/Dfusion/src/lua_FunctionCall.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "lua_FunctionCall.h" -using namespace lua; -int lua_FunctionCall(lua_State *L) -{ - lua::state st(L); - FunctionCaller cl(0); - size_t ptr=st.as(1); - int callconv=st.as(2); - vector arguments; - for(int i=3;i(i)); - int ret=cl.CallFunction(ptr,(FunctionCaller::callconv)callconv,arguments); - st.push(ret); - return 1;// dunno if len is needed... -} - -const luaL_Reg lua_functioncall_func[]= -{ - {"call",lua_FunctionCall}, - {NULL,NULL} -}; - -#define __ADDCONST(name) st.push(::FunctionCaller:: name); st.setglobal(#name) -void lua::RegisterFunctionCall(lua::state &st) -{ - st.getglobal("FunctionCall"); - if(st.is()) - { - st.pop(); - st.newtable(); - } - __ADDCONST(STD_CALL); - __ADDCONST(FAST_CALL); - __ADDCONST(THIS_CALL); - __ADDCONST(CDECL_CALL); - lua::RegFunctionsLocal(st, lua_functioncall_func); - st.setglobal("FunctionCall"); -} -#undef __ADDCONST \ No newline at end of file diff --git a/plugins/Dfusion/src/lua_Misc.cpp b/plugins/Dfusion/src/lua_Misc.cpp index b58efc7ac..6a06781fd 100644 --- a/plugins/Dfusion/src/lua_Misc.cpp +++ b/plugins/Dfusion/src/lua_Misc.cpp @@ -129,111 +129,16 @@ static int GetMod(lua_State *L) st.push(pos); return 1; } -static int lua_malloc(lua_State *L) -{ - lua::state st(L); - size_t size=st.as(1); - size_t pos=reinterpret_cast(malloc(size)); - st.push(pos); - return 1; -} -static int lua_malloc_free(lua_State *L) -{ - lua::state st(L); - size_t ptr=st.as(1); - free(reinterpret_cast(ptr)); - return 0; -} -#ifdef LINUX_BUILD -static size_t __attribute__((stdcall)) PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t edi,uint32_t esi,uint32_t esp,uint32_t ebp) -#else -static size_t __stdcall PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t edi,uint32_t esi,uint32_t esp,uint32_t ebp) -#endif -{ - lua::state st=lua::glua::Get(); - st.getglobal("OnFunction"); - if(st.is()) - return 0; - st.newtable(); - st.push(eax); - st.setfield("eax"); - st.push(ebx); - st.setfield("ebx"); - st.push(ecx); - st.setfield("ecx"); - st.push(edx); - st.setfield("edx"); - st.push(edi); - st.setfield("edi"); - st.push(esi); - st.setfield("esi"); - st.push(esp+12); - st.setfield("esp"); - st.push(ebp); - st.setfield("ebp"); - st.push(ret); - st.setfield("ret"); - DFHack::Lua::SafeCall(DFHack::Core::getInstance().getConsole(),st,1,1); - return st.as(); -} -static int Get_PushValue(lua_State *L) -{ - lua::state st(L); - st.push((uint32_t)&PushValue); - return 1; -} -static int Call_Df(lua_State *L) -{ - lua::state st(L); - FunctionCaller f(0); - std::vector args; - size_t ptr; - FunctionCaller::callconv conv; - ptr=st.as(1); - conv=(FunctionCaller::callconv)st.as(2); - for(size_t j=3;j<=st.gettop();j++) - args.push_back(st.as(j)); - st.push(f.CallFunction(ptr,conv,args)); - return 1; -} -static int Suspend_Df(lua_State *L) -{ - lua::state st(L); - DFHack::Core::getInstance().Suspend(); - return 0; -} -static int Resume_Df(lua_State *L) -{ - lua::state st(L); - DFHack::Core::getInstance().Resume(); - return 0; -} -static int Cast(lua_State *L) -{ - lua::state st(L); - if(DFHack::Lua::IsDFObject(st,1)!=DFHack::Lua::OBJ_TYPE) - st.error("First argument must be df type!"); - if(!st.is(2)) //todo maybe lightuserdata? - st.error("Second argument must be pointer as a number!"); - st.getfield("_identity",1); - DFHack::Lua::PushDFObject(st,(DFHack::type_identity*)lua_touserdata(st,-1),(void*)st.as(2)); - return 1; -} + + const luaL_Reg lua_misc_func[]= { - {"alloc",lua_malloc}, - {"free",lua_malloc_free}, {"loadmod",LoadMod}, {"getmod",GetMod}, {"loadobj",LoadObj}, {"loadobjsymbols",LoadObjSymbols}, {"findmarker",FindMarker}, {"newmod",NewMod}, - {"getpushvalue",Get_PushValue}, - {"calldf",Call_Df}, - {"suspend",Suspend_Df}, - {"resume",Resume_Df}, - {"cast",Cast}, {NULL,NULL} }; void lua::RegisterMisc(lua::state &st) diff --git a/plugins/Dfusion/src/lua_Offsets.cpp b/plugins/Dfusion/src/lua_Offsets.cpp deleted file mode 100644 index 4d66e67e7..000000000 --- a/plugins/Dfusion/src/lua_Offsets.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "lua_Offsets.h" -#include -#include -//TODO make a seperate module with peeks/pokes and page permisions (linux/windows spec) -//TODO maybe remove alltogether- use DFHack::Process instead? -template -T engine_peek(size_t offset) -{ - return *(reinterpret_cast(offset)); -} -template -void engine_poke(size_t offset,T val) -{ - *(reinterpret_cast(offset))=val; -} - -void peekarb(size_t offset, void *mem,size_t size) -{ - memcpy(mem,(void*)offset,size); -} -void peekstr(size_t offset, char* buf, size_t maxsize) -{ - strncpy(buf,(char*)offset,maxsize); -} -void pokearb(size_t offset, void *mem,size_t size) -{ - memcpy((void*)offset,mem,size); -} -void pokestr(size_t offset, char* buf, size_t maxsize) -{ - strncpy((char*)offset,buf,maxsize); -} - -//// lua stuff here -static int lua_peekb(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_peekw(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_peekd(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_peekq(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_peekfloat(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_peekdouble(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_peekarb(lua_State *L) -{ - lua::state st(L); - size_t size=st.as(2); - void *p=st.newuserdata(size); - peekarb(st.as(1),p,size); - return 1; -} -static int lua_peekstr(lua_State *L) -{ - lua::state st(L); - char *buf; - buf=new char[256]; - peekstr(st.as(1),buf,256); - std::string tstr(buf); - st.push(tstr); - delete [] buf; - return 1; -} -static int lua_peekstr2(lua_State *L) -{ - lua::state st(L); - st.push(engine_peek(st.as(1))); - return 1; -} -static int lua_pokeb(lua_State *L) -{ - lua::state st(L); - engine_poke(st.as(1),st.as(2)); - return 0; -} -static int lua_pokew(lua_State *L) -{ - lua::state st(L); - engine_poke(st.as(1),st.as(2)); - return 0; -} -static int lua_poked(lua_State *L) -{ - lua::state st(L); - engine_poke(st.as(1),st.as(2)); - return 0; -} -static int lua_pokeq(lua_State *L) -{ - lua::state st(L); - engine_poke(st.as(1),st.as(2)); - return 0; -} -static int lua_pokefloat(lua_State *L) -{ - lua::state st(L); - engine_poke(st.as(1),st.as(2)); - return 0; -} -static int lua_pokedouble(lua_State *L) -{ - lua::state st(L); - engine_poke(st.as(1),st.as(2)); - return 0; -} -static int lua_pokearb(lua_State *L) -{ - lua::state st(L); - void *p=(void *)lua_touserdata(L, 2);//st.as(2); - size_t size=st.as(3); - pokearb(st.as(1),p,size); - return 0; -} -static int lua_pokestr(lua_State *L) -{ - lua::state st(L); - std::string trg=st.as(2); - pokestr(st.as(1),(char*)trg.c_str(),trg.size()); - return 0; -} -static int lua_pokestr2(lua_State *L) -{ - lua::state st(L); - std::string trg=st.as(2); - engine_poke(st.as(1),trg); - return 0; -} -const luaL_Reg lua_engine_func[]= -{ - {"peekb",lua_peekb}, - {"peekw",lua_peekw}, - {"peekd",lua_peekd}, - {"peekq",lua_peekq}, - {"peekfloat",lua_peekfloat}, - {"peekdouble",lua_peekdouble}, - - {"peekarb",lua_peekarb}, - {"peekstr",lua_peekstr}, - {"peekstr2",lua_peekstr2}, - - {"pokeb",lua_pokeb}, - {"pokew",lua_pokew}, - {"poked",lua_poked}, - {"pokeq",lua_pokeq}, - {"pokefloat",lua_pokefloat}, - {"pokedouble",lua_pokedouble}, - - {"pokearb",lua_pokearb}, - {"pokestr",lua_pokestr}, - {"pokestr2",lua_pokestr2}, - {NULL,NULL} -}; - -void lua::RegisterEngine(lua::state &st) -{ - st.getglobal("engine"); - if(st.is()) - { - st.pop(); - st.newtable(); - } - lua::RegFunctionsLocal(st,lua_engine_func); - st.setglobal("engine"); -} diff --git a/plugins/Dfusion/src/lua_VersionInfo.cpp b/plugins/Dfusion/src/lua_VersionInfo.cpp deleted file mode 100644 index 9f5cd17e7..000000000 --- a/plugins/Dfusion/src/lua_VersionInfo.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "lua_VersionInfo.h" - -#define VI_FUNC(name) int lua_VI_ ## name (lua_State *L){\ - lua::state s(L);\ - DFHack::VersionInfo* vif=DFHack::Core::getInstance().vinfo; -#define END_VI_FUNC } - -VI_FUNC(getBase) -//int lua_VI_getBase(lua_State *L) - s.push(vif->getBase()); - return 1; -END_VI_FUNC - -VI_FUNC(setBase) - uint32_t val=s.as(1); - vif->setBase(val); - return 0; -END_VI_FUNC -VI_FUNC(rebaseTo) - uint32_t val=s.as(1); - vif->rebaseTo(val); - return 0; -END_VI_FUNC -VI_FUNC(addMD5) - std::string val=s.as(1); - vif->addMD5(val); - return 0; -END_VI_FUNC -VI_FUNC(hasMD5) - std::string val=s.as(1); - s.push(vif->hasMD5(val)); - return 1; -END_VI_FUNC - -VI_FUNC(addPE) - uint32_t val=s.as(1); - vif->addPE(val); - return 0; -END_VI_FUNC - -VI_FUNC(hasPE) - uint32_t val=s.as(1); - s.push(vif->hasPE(val)); - return 1; -END_VI_FUNC - -VI_FUNC(setVersion) - std::string val=s.as(1); - vif->setVersion(val); - return 0; -END_VI_FUNC - -VI_FUNC(getVersion) - s.push(vif->getVersion()); - return 1; -END_VI_FUNC - -VI_FUNC(setAddress) - std::string key=s.as(1); - uint32_t val=s.as(2); - vif->setAddress(key,val); - return 0; -END_VI_FUNC - -VI_FUNC(getAddress) - std::string key=s.as(1); - - s.push(vif->getAddress(key)); - return 1; -END_VI_FUNC - -VI_FUNC(setOS) - unsigned os=s.as(1); - vif->setOS((DFHack::OSType)os); - return 0; -END_VI_FUNC - -VI_FUNC(getOS) - s.push(vif->getOS()); - return 1; -END_VI_FUNC -#undef VI_FUNC -#undef END_VI_FUNC -#define VI_FUNC(name) {#name,lua_VI_ ## name} -const luaL_Reg lua_vinfo_func[]= -{ - VI_FUNC(getBase), - VI_FUNC(setBase), - VI_FUNC(rebaseTo), - VI_FUNC(addMD5), - VI_FUNC(hasMD5), - VI_FUNC(addPE), - VI_FUNC(hasPE), - VI_FUNC(setVersion), - VI_FUNC(getVersion), - VI_FUNC(setAddress), - VI_FUNC(getAddress), - VI_FUNC(setOS), - VI_FUNC(getOS), - {NULL,NULL} -}; -#undef VI_FUNC -void lua::RegisterVersionInfo(lua::state &st) -{ - - st.getglobal("VersionInfo"); - if(st.is()) - { - st.pop(); - st.newtable(); - } - - lua::RegFunctionsLocal(st, lua_vinfo_func); - st.setglobal("VersionInfo"); -} From 923ea3f4b0a2c435399dd967d4736e2ec626344f Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 7 Oct 2012 20:44:18 +0300 Subject: [PATCH 023/158] Reactionhooks more usefull and gm-editor minor tweaks (e.g. search in containers) --- library/include/LuaTools.h | 15 +++++++++++++++ plugins/reactionhooks.cpp | 9 ++++++--- scripts/gui/gm-editor.lua | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h index 3330e23e7..e956a65d5 100644 --- a/library/include/LuaTools.h +++ b/library/include/LuaTools.h @@ -472,3 +472,18 @@ namespace DFHack {namespace Lua { name##_event.invoke(out, 5); \ } \ } + +#define DEFINE_LUA_EVENT_6(name, handler, arg_type1, arg_type2, arg_type3, arg_type4, arg_type5,arg_type6) \ + static DFHack::Lua::Notification name##_event(df::wrap_function(handler, true)); \ + void name(color_ostream &out, arg_type1 arg1, arg_type2 arg2, arg_type3 arg3, arg_type4 arg4,arg_type5 arg5, arg_type6 arg6) { \ + handler(out, arg1, arg2, arg3, arg4, arg5, arg6); \ + if (auto state = name##_event.state_if_count()) { \ + DFHack::Lua::Push(state, arg1); \ + DFHack::Lua::Push(state, arg2); \ + DFHack::Lua::Push(state, arg3); \ + DFHack::Lua::Push(state, arg4); \ + DFHack::Lua::Push(state, arg5); \ + DFHack::Lua::Push(state, arg6); \ + name##_event.invoke(out, 6); \ + } \ +} \ No newline at end of file diff --git a/plugins/reactionhooks.cpp b/plugins/reactionhooks.cpp index 4041b99a5..d70fb9ea1 100644 --- a/plugins/reactionhooks.cpp +++ b/plugins/reactionhooks.cpp @@ -184,9 +184,10 @@ df::item* find_item( return NULL; } -static void handle_reaction_done(color_ostream &out, df::unit *unit, std::vector *in_items, std::vector *out_items,bool *call_native){}; +static void handle_reaction_done(color_ostream &out,df::reaction*, df::unit *unit, std::vector *in_items,std::vector *in_reag + , std::vector *out_items,bool *call_native){}; -DEFINE_LUA_EVENT_4(onReactionComplete, handle_reaction_done, df::unit *, std::vector *,std::vector *,bool *); +DEFINE_LUA_EVENT_6(onReactionComplete, handle_reaction_done,df::reaction*, df::unit *, std::vector *,std::vector *,std::vector *,bool *); DFHACK_PLUGIN_LUA_EVENTS { @@ -207,9 +208,11 @@ struct product_hook : item_product { ) { if (auto product = products[this]) { + df::reaction* this_reaction=product->react; + CoreSuspendClaimer suspend; color_ostream_proxy out(Core::getInstance().getConsole()); bool call_native=true; - onReactionComplete(out,unit,in_items,out_items,&call_native); + onReactionComplete(out,this_reaction,unit,in_items,in_reag,out_items,&call_native); if(!call_native) return; } diff --git a/scripts/gui/gm-editor.lua b/scripts/gui/gm-editor.lua index 309663bdf..6999f1d8c 100644 --- a/scripts/gui/gm-editor.lua +++ b/scripts/gui/gm-editor.lua @@ -45,6 +45,25 @@ function GmEditorUi:init(args) return self end +function GmEditorUi:find(test) + local trg=self:currentTarget() + if trg.target and trg.target._kind and trg.target._kind=="container" then + if test== nil then + dialog.showInputPrompt("Test function","Input function that tests(k,v as argument):",COLOR_WHITE,"",dfhack.curry(self.find,self)) + return + end + local e,what=load("return function(k,v) return "..test.." end") + if e==nil then + dialog.showMessage("Error!","function failed to compile\n"..what,COLOR_RED) + end + for k,v in pairs(trg.target) do + if e()(k,v)==true then + self:pushTarget(v) + return + end + end + end +end function GmEditorUi:insertNew(typename) local tp=typename if typename== nil then @@ -165,6 +184,8 @@ end self:changeSelected(10) elseif keys.SELECT then self:editSelected() + elseif keys.CUSTOM_ALT_F then + self:find() elseif keys.CUSTOM_ALT_E then --self:specialEditor() elseif keys.CUSTOM_ALT_I then --insert From 49476818c466118508d2fe37bd8820a766e5a6c5 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 7 Oct 2012 20:45:14 +0300 Subject: [PATCH 024/158] Dfusion rebuild start (lua script side plugins) --- library/xml | 2 +- plugins/Dfusion/CMakeLists.txt | 2 +- plugins/Dfusion/dfusion.cpp | 148 ++++++--------------- plugins/Dfusion/luafiles/common.lua | 6 +- plugins/Dfusion/luafiles/embark/a.out | 0 plugins/Dfusion/luafiles/embark/embark.asm | 6 +- plugins/Dfusion/luafiles/embark/embark.o | Bin 348 -> 369 bytes plugins/Dfusion/src/OutFile.cpp | 18 +-- 8 files changed, 57 insertions(+), 125 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/embark/a.out diff --git a/library/xml b/library/xml index a914f3b75..8a78bfa21 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit a914f3b7558335d53c0ac93f6e7267906a33cd29 +Subproject commit 8a78bfa218817765b0a80431e0cf25435ffb2179 diff --git a/plugins/Dfusion/CMakeLists.txt b/plugins/Dfusion/CMakeLists.txt index 65587201b..51f2e3bee 100644 --- a/plugins/Dfusion/CMakeLists.txt +++ b/plugins/Dfusion/CMakeLists.txt @@ -1,5 +1,5 @@ include_directories(include) -include_directories("${dfhack_SOURCE_DIR}/library/depends/tthread") + FILE(GLOB DFUSION_CPPS src/*.c*) set( DFUSION_CPPS_ALL diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index 0f49e860d..daacc0b26 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -6,16 +6,11 @@ #include #include - -#include "tinythread.h" - - #include "luamain.h" #include "lua_Process.h" #include "lua_Hexsearch.h" #include "lua_Misc.h" - #include "DataDefs.h" #include "LuaTools.h" @@ -23,112 +18,51 @@ using std::vector; using std::string; using namespace DFHack; -static tthread::mutex* mymutex=0; -static tthread::thread* thread_dfusion=0; -uint64_t timeLast=0; -DFHACK_PLUGIN("dfusion") -command_result dfusion (color_ostream &out, std::vector ¶meters); -command_result dfuse (color_ostream &out, std::vector ¶meters); +DFHACK_PLUGIN("dfusion") -DFhackCExport const char * plugin_name ( void ) +static int loadObjectFile(lua_State* L) { - return "dfusion"; + std::string path; + + path=luaL_checkstring(L,1); + + OutFile::File f(path); + lua_newtable(L); + int table_pos=lua_gettop(L); + size_t size=f.GetTextSize(); + Lua::Push(L,size); + lua_setfield(L,table_pos,"data_size"); + char* buf=new char[size]; + f.GetText(buf); + + //Lua::PushDFObject(L,DFHack::,buf); + //Lua::Push(L,buf); + lua_pushlightuserdata(L,buf); + lua_setfield(L,table_pos,"data"); + OutFile::vSymbol& symbols=f.GetSymbols(); + lua_newtable(L); + for(size_t i=0;i &commands) +DFHACK_PLUGIN_LUA_COMMANDS { + DFHACK_LUA_COMMAND(loadObjectFile), + DFHACK_LUA_END +}; +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - lua::state st=lua::glua::Get(); - - //maybe remake it to run automatically - Lua::Open(out, st); - - lua::RegisterProcess(st); - lua::RegisterHexsearch(st); - lua::RegisterMisc(st); - - #ifdef LINUX_BUILD - st.push(1); - st.setglobal("LINUX"); - #else - st.push(1); - st.setglobal("WINDOWS"); - #endif - - commands.push_back(PluginCommand("dfusion","Run dfusion system (interactive i.e. can input further commands).",dfusion,true)); - commands.push_back(PluginCommand("dfuse","Init dfusion system (not interactive).",dfuse,false)); - mymutex=new tthread::mutex; return CR_OK; -} - -DFhackCExport command_result plugin_shutdown ( Core * c ) -{ - -// shutdown stuff - if(thread_dfusion) - delete thread_dfusion; - delete mymutex; - return CR_OK; -} - -DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c ) -{ - uint64_t time2 = GetTimeMs64(); - uint64_t delta = time2-timeLast; - if(delta<100) - return CR_OK; - timeLast = time2; - mymutex->lock(); - lua::state s=lua::glua::Get(); - s.getglobal("OnTick"); - if(s.is()) - { - try{ - s.pcall(); - } - catch(lua::exception &e) - { - c->getConsole().printerr("Error OnTick:%s\n",e.what()); - c->getConsole().printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); - c->getConsole().msleep(1000); - } - } - s.settop(0); - mymutex->unlock(); - return CR_OK; -} -void RunDfusion(color_ostream &out, std::vector ¶meters) -{ - mymutex->lock(); - lua::state s=lua::glua::Get(); - try{ - s.loadfile("dfusion/init.lua"); //load script - for(size_t i=0;iunlock(); -} -command_result dfuse(color_ostream &out, std::vector ¶meters) -{ - lua::state s=lua::glua::Get(); - s.push(1); - s.setglobal("INIT"); - RunDfusion(out,parameters); - return CR_OK; -} -command_result dfusion (color_ostream &out, std::vector ¶meters) -{ - lua::state s=lua::glua::Get(); - s.push(); - s.setglobal("INIT"); - RunDfusion(out,parameters); - return CR_OK; -} +} \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua index 7e621c4ea..a6781b385 100644 --- a/plugins/Dfusion/luafiles/common.lua +++ b/plugins/Dfusion/luafiles/common.lua @@ -541,8 +541,4 @@ function Allocate(size) curptr=curptr+size engine.poked(ptr,curptr) return curptr-size+ptr -end -dofile("dfusion/patterns.lua") -dofile("dfusion/patterns2.lua") -dofile("dfusion/itempatterns.lua") -dofile("dfusion/buildingpatterns.lua") \ No newline at end of file +end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/embark/a.out b/plugins/Dfusion/luafiles/embark/a.out deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/Dfusion/luafiles/embark/embark.asm b/plugins/Dfusion/luafiles/embark/embark.asm index 644459ce5..d2fa91081 100644 --- a/plugins/Dfusion/luafiles/embark/embark.asm +++ b/plugins/Dfusion/luafiles/embark/embark.asm @@ -1,7 +1,7 @@ .intel_syntax -mov eax , [esp+0x1C] -caste: +mov eax , [esp+0x1C] # loop counter +mark_caste: movsx ecx, word ptr[eax*2+0xdeadbeef] -race: +mark_race: movzx eax,word ptr [eax*2+0xDEADBEEF] ret diff --git a/plugins/Dfusion/luafiles/embark/embark.o b/plugins/Dfusion/luafiles/embark/embark.o index 1c9c837c840eead962d5364f774aa47869b08db2..87f5bbd68f5c8d0aaf6f81485f653a440145a952 100644 GIT binary patch delta 59 ycmcb^^pR=832_D>V1Z&rAk796VBnv4zfw{X$jD7B%8pM?EG|ifFpCnCQyBnH+YLDY delta 38 ocmey!bcboe3Gw8_;*wMb1_l-&W&~n3hN8seRECN7D_KB70MFV8=l}o! diff --git a/plugins/Dfusion/src/OutFile.cpp b/plugins/Dfusion/src/OutFile.cpp index 2d8399b03..5617175f8 100644 --- a/plugins/Dfusion/src/OutFile.cpp +++ b/plugins/Dfusion/src/OutFile.cpp @@ -1,19 +1,21 @@ #include "OutFile.h" +#include using namespace OutFile; File::File(std::string path) { //mystream.exceptions ( std::fstream::eofbit | std::fstream::failbit | std::fstream::badbit ); mystream.open(path.c_str(),std::fstream::binary|std::ios::in|std::ios::out); - mystream.read((char*)&myhead,sizeof(myhead)); - for(unsigned i=0;i Date: Wed, 17 Oct 2012 19:33:20 +0300 Subject: [PATCH 025/158] Just companion orders tool --- scripts/gui/companion-order.lua | 398 ++++++++++++++++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 scripts/gui/companion-order.lua diff --git a/scripts/gui/companion-order.lua b/scripts/gui/companion-order.lua new file mode 100644 index 000000000..6b6a79aa2 --- /dev/null +++ b/scripts/gui/companion-order.lua @@ -0,0 +1,398 @@ + +local gui = require 'gui' +local dlg = require 'gui.dialogs' + +local cursor=xyz2pos(df.global.cursor.x,df.global.cursor.y,df.global.cursor.z) +local permited_equips={} + +permited_equips[df.item_backpackst]="UPPERBODY" +permited_equips[df.item_flaskst]="UPPERBODY" +permited_equips[df.item_armorst]="UPPERBODY" +permited_equips[df.item_shoesst]="STANCE" +permited_equips[df.item_glovesst]="GRASP" +permited_equips[df.item_helmst]="HEAD" +permited_equips[df.item_pantsst]="LOWERBODY" +function DoesHaveSubtype(item) + if df.item_backpackst:is_instance(item) or df.item_flaskst:is_instance(item) then + return false + end + return true +end +function CheckCursor(p) + if p.x==-30000 then + dlg.showMessage( + 'Companion orders', + 'You must have a cursor on some tile!', COLOR_LIGHTRED + ) + return false + end + return true +end +function GetCaste(race_id,caste_id) + local race=df.creature_raw.find(race_id) + return race.caste[caste_id] +end + +function EnumBodyEquipable(race_id,caste_id) + local caste=GetCaste(race_id,caste_id) + local bps=caste.body_info.body_parts + local ret={} + for k,v in pairs(bps) do + ret[k]={bp=v,layers={[0]={size=0,permit=0},[1]={size=0,permit=0},[2]={size=0,permit=0},[3]={size=0,permit=0} } } + end + return ret +end +function ReadCurrentEquiped(body_equip,unit) + for k,v in pairs(unit.inventory) do + if v.mode==2 then + local bpid=v.body_part_id + if DoesHaveSubtype(v.item) then + local sb=v.item.subtype.props + local trg=body_equip[bpid] + local trg_layer=trg.layers[sb.layer] + + if trg_layer.permit==0 then + trg_layer.permit=sb.layer_permit + else + if trg_layer.permit>sb.layer_permit then + trg_layer.permit=sb.layer_permit + end + end + trg_layer.size=trg_layer.size+sb.layer_size + end + end + end +end +function LayeringPermits(body_part,item) + if not DoesHaveSubtype(item) then + return true + end + local sb=item.subtype.props + local trg_layer=body_part.layers[sb.layer] + if math.min(trg_layer.permit ,sb.layer_permit)0 and #items>0 do + if(dfhack.items.moveToInventory(items[#items],v,1,grasps[#grasps])) then + table.remove(grasps) + end + table.remove(items) + end + local backpack=GetBackpack(v) + if backpack then + while #items>0 do + dfhack.items.moveToContainer(items[#items],backpack) + table.remove(items) + end + end + end + return true +end}, +{name="unequip",f=function (unit_list) + --remove and drop all the stuff (todo maybe a gui too?) + for k,v in pairs(unit_list) do + while #v.inventory ~=0 do + dfhack.items.moveToGround(v.inventory[0].item,v.pos) + end + end + return true +end}, +--[=[ +{name="roam not working :<",f=function (unit_list,pos,dist) --does not work + if not CheckCursor(pos) then + return false + end + dist=dist or 5 + for k,v in pairs(unit_list) do + v.idle_area:assign(pos) + v.idle_area_threshold=dist + end + return true +end}, +--]=] +{name="wait",f=function (unit_list) + for k,v in pairs(unit_list) do + v.relations.group_leader_id=-1 + end + return true +end}, +{name="follow",f=function (unit_list) + local adv=df.global.world.units.active[0] + for k,v in pairs(unit_list) do + v.relations.group_leader_id=adv.id + end + return true +end}, +{name="leave",f=function (unit_list) + local adv=df.global.world.units.active[0] + local t_nem=dfhack.units.getNemesis(adv) + for k,v in pairs(unit_list) do + + v.relations.group_leader_id=-1 + local u_nem=dfhack.units.getNemesis(v) + if u_nem then + u_nem.group_leader_id=-1 + end + if t_nem and u_nem then + for k,v in pairs(t_nem.companions) do + if v==u_nem.id then + t_nem.companions:erase(k) + break + end + end + end + end + return true +end}, +} +local cheats={} +--[[ todo: add cheats...]]-- +function getCompanions(unit) + unit=unit or df.global.world.units.active[0] + local t_nem=dfhack.units.getNemesis(unit) + if t_nem==nil then + qerror("Invalid unit! No nemesis record") + end + local ret={} + for k,v in pairs(t_nem.companions) do + local u=df.nemesis_record.find(v) + if u.unit then + table.insert(ret,u.unit) + end + end + return ret +end + + +CompanionUi=defclass(CompanionUi,gui.FramedScreen) +CompanionUi.ATTRS{ + frame_title = "Companions", +} +function CompanionUi:init(args) + self.unit_list=args.unit_list + self.selected={} + for i=0,26 do + self.selected[i]=true + end +end +function CompanionUi:GetSelectedUnits() + local ret={} + for k,v in pairs(self.unit_list) do + if self.selected[k] then + table.insert(ret,v) + end + end + return ret +end +function CompanionUi:onInput(keys) + + + if keys.LEAVESCREEN then + self:dismiss() + elseif keys._STRING then + local s=keys._STRING + if s==string.byte('*') then + local v=self.selected[1] or false + for i=0,26 do + + self.selected[i]=not v + end + end + if s>=string.byte('a') and s<=string.byte('z') then + local idx=s-string.byte('a')+1 + if self.selected[idx] then + self.selected[idx]=false + else + self.selected[idx]=true + end + end + if s>=string.byte('A') and s<=string.byte('Z') then + local idx=s-string.byte('A')+1 + if orders[idx] and orders[idx].f then + if orders[idx].f(self:GetSelectedUnits(),cursor) then + self:dismiss() + end + end + --do order + end + end +end +function CompanionUi:onRenderBody( dc) + --list widget goes here... + local char_a=string.byte('a')-1 + dc:newline(1):string("*. All") + for k,v in ipairs(self.unit_list) do + if self.selected[k] then + dc:pen(COLOR_GREEN) + else + dc:pen(COLOR_GREY) + end + dc:newline(1):string(string.char(k+char_a)..". "):string(dfhack.TranslateName(v.name)); + end + dc:pen(COLOR_GREY) + local w,h=self:getWindowSize() + local char_A=string.byte('A')-1 + for k,v in ipairs(orders) do + dc:seek(w/2,k):string(string.char(k+char_A)..". "):string(v.name); + end +end +local screen=CompanionUi{unit_list=getCompanions()} +screen:show() \ No newline at end of file From da92fb9a1c8dfd373ac9c0781729fe722009fdcb Mon Sep 17 00:00:00 2001 From: Warmist Date: Wed, 17 Oct 2012 21:43:44 +0300 Subject: [PATCH 026/158] Start of dfusion module. Fixed small error in memscan.lua and start of custom embark command. --- library/lua/memscan.lua | 2 +- plugins/Dfusion/luafiles/embark/init.lua | 25 ++++ plugins/lua/dfusion.lua | 163 +++++++++++++++++++++++ 3 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 plugins/lua/dfusion.lua diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua index ba3efd708..6796b3563 100644 --- a/library/lua/memscan.lua +++ b/library/lua/memscan.lua @@ -24,7 +24,7 @@ function CheckedArray:__len() return self.count end function CheckedArray:__index(idx) - if type(idx) == number then + if type(idx) == "number" then if idx >= self.count then error('Index out of bounds: '..tostring(idx)) end diff --git a/plugins/Dfusion/luafiles/embark/init.lua b/plugins/Dfusion/luafiles/embark/init.lua index 529c2d1e5..aa8f2822d 100644 --- a/plugins/Dfusion/luafiles/embark/init.lua +++ b/plugins/Dfusion/luafiles/embark/init.lua @@ -1,3 +1,28 @@ +local dfu=require("dfusion") +local ms=require("memscan") + +CustomEmbark=defclass(CustomEmbark,dfu.BinaryPlugin) +CustomEmbark.ATTRS{filename="dfusion/embark/embark.o",name="CustomEmbark",race_caste_data=DEFAULT_NIL} +function CustomEmbark:install() + local stoff=dfhack.internal.getAddress('start_dwarf_count') + if stoff==nil then + error("address for start_dwarf_count not found!") + end + local _,race_id_offset=df.sizeof(df.global.ui:_field("race_id")) + local needle={0x0f,0xb7,0x0d} --movzx,... + add_dword(needle,race_id_offset) -- ...word ptr[] + local mem=ms.get_code_segment() + local trg_offset=mem.uint8_t.find(needle,stoff)--maybe endoff=stoff+bignumber + if trg_offset==nil then + error("address for race_load not found") + end + needle={0x83,0xc8,0xff} -- or eax, 0xFF + local caste_offset=mem.uint8_t.find(needle,trg_offset) + if caste_offset==nil or caste_offset-stoff>1000 then + error("Caste change code not found or found too far!") + end + +end function MakeTable(modpos,modsize,names) count=0 castes={} diff --git a/plugins/lua/dfusion.lua b/plugins/lua/dfusion.lua new file mode 100644 index 000000000..06128d29b --- /dev/null +++ b/plugins/lua/dfusion.lua @@ -0,0 +1,163 @@ +-- Stuff used by dfusion +local _ENV = mkmodule('plugins.dfusion') + +local ms=require("memscan") + +local marker={0xDE,0xAD,0xBE,0xEF} +patches={} +-- A reversable binary patch +BinaryPatch=defclass(BinaryPatch) +BinaryPatch.ATTRS {pre_data=DEFAULT_NIL,data=DEFAULT_NIL,address=DEFAULT_NIL,name=DEFAULT_NIL} +function BinaryPatch:init(args) + self.is_applied=false + if args.pre_data==nil or args.data==nil or args.address==nil or args.name==nil then + error("Invalid parameters to binary patch") + end + if patches[self.name]~=nil then + error("Patch already exist") + end + self.max_val=0 + for k,v in pairs(args.pre_data) do + if type(k)~="number" then + error("non number key in pre_data") + end + if self.max_val Date: Sun, 21 Oct 2012 13:42:55 +0300 Subject: [PATCH 027/158] More work on dfusion. Embark anywhere script separated. --- plugins/Dfusion/dfusion.cpp | 20 ++++ plugins/Dfusion/luafiles/embark/init.lua | 137 ++++++++--------------- plugins/devel/CMakeLists.txt | 1 - plugins/lua/dfusion.lua | 113 ++++++++++++------- scripts/dfusion.lua | 2 + scripts/embark.lua | 53 +++++++++ 6 files changed, 196 insertions(+), 130 deletions(-) create mode 100644 scripts/dfusion.lua create mode 100644 scripts/embark.lua diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index daacc0b26..4507f9a15 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -58,8 +58,28 @@ static int loadObjectFile(lua_State* L) lua_setfield(L,table_pos,"symbols"); return 1; } +static int markAsExecutable(lua_State* L) +{ + unsigned addr=luaL_checkunsigned(L,1); + std::vector ranges; + DFHack::Core::getInstance().p->getMemRanges(ranges); + for(size_t i=0;isetPermisions(ranges[i],newperm); + return 0; + } + } + lua_pushlstring(L,"Memory range not found",23); + lua_error(L); + return 0; +} DFHACK_PLUGIN_LUA_COMMANDS { DFHACK_LUA_COMMAND(loadObjectFile), + DFHACK_LUA_COMMAND(markAsExecutable), DFHACK_LUA_END }; DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) diff --git a/plugins/Dfusion/luafiles/embark/init.lua b/plugins/Dfusion/luafiles/embark/init.lua index aa8f2822d..76be00c72 100644 --- a/plugins/Dfusion/luafiles/embark/init.lua +++ b/plugins/Dfusion/luafiles/embark/init.lua @@ -1,108 +1,69 @@ -local dfu=require("dfusion") +local dfu=require("plugins.dfusion") local ms=require("memscan") - +local MAX_RACES=100 CustomEmbark=defclass(CustomEmbark,dfu.BinaryPlugin) CustomEmbark.ATTRS{filename="dfusion/embark/embark.o",name="CustomEmbark",race_caste_data=DEFAULT_NIL} function CustomEmbark:install() local stoff=dfhack.internal.getAddress('start_dwarf_count') + if #self.race_caste_data<7 then + error("caste and race count must be bigger than 6") + end + if #self.race_caste_data>MAX_RACES then + error("caste and race count must be less then "..MAX_RACES) + end if stoff==nil then error("address for start_dwarf_count not found!") end local _,race_id_offset=df.sizeof(df.global.ui:_field("race_id")) - local needle={0x0f,0xb7,0x0d} --movzx,... - add_dword(needle,race_id_offset) -- ...word ptr[] + print(string.format("start=%08x",stoff)) + local needle={0x0f,0xb7,0x0d} --movzx eax,dword ptr [race_id] + local tmp_table=dfu.dwordToTable(race_id_offset) + for k,v in ipairs(tmp_table) do + table.insert(needle,v) + end + local mem=ms.get_code_segment() - local trg_offset=mem.uint8_t.find(needle,stoff)--maybe endoff=stoff+bignumber + print(mem.uint8_t:addr2idx(stoff)) + print(mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff))) + local _,trg_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff),nil)--maybe endoff=stoff+bignumber if trg_offset==nil then error("address for race_load not found") end + local call_data={0x90,0x90} + local _,data_offset=df.sizeof(self.data) + dfu.concatTables(call_data,dfu.makeCall(trg_offset+2,data_offset)) + self.call_patch=dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} needle={0x83,0xc8,0xff} -- or eax, 0xFF - local caste_offset=mem.uint8_t.find(needle,trg_offset) + local _,caste_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(trg_offset),nil) if caste_offset==nil or caste_offset-stoff>1000 then error("Caste change code not found or found too far!") end + self.disable_castes=dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} + self.disable_castes:apply() + self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} + self.dwarfcount:apply() + local caste_array=self:allocate("caste_array","uint16_t",#self.race_caste_data) + local race_array=self:allocate("race_array","uint16_t",#self.race_caste_data) + for k,v in ipairs(self.race_caste_data) do + caste_array[k-1]=v[2] + race_array[k-1]=v[1] + end + local race_array_off,caste_array_off + local _ + _,race_array_off=df.sizeof(race_array) + _,caste_array_off=df.sizeof(caste_array) + self:set_marker_dword("race",caste_array_off) --hehe... mixed them up i guess... + self:set_marker_dword("caste",race_array_off) + + self:move_to_df() + self.call_patch:apply() + self.installed=true end -function MakeTable(modpos,modsize,names) - count=0 - castes={} - --print("Making table") - for _,line in pairs(names) do - --print("Line:"..line) - tpos=string.find(line,":") - if tpos~=nil then - --print("Was line:"..line) - table.insert(castes,tonumber(string.sub(line,tpos+1))) - line=string.sub(line,1,tpos-1) - --print("IS line:"..line) - else - table.insert(castes,-1) - end - if RaceTable[line] == nil then - error("Failure, "..line.." not found!") - end - --print("adding:"..line.." id:"..RaceTable[line]) - engine.pokew(modpos+modsize+count*2,RaceTable[line]) -- add race - count = count + 1 - end - i=0 - for _,caste in pairs(castes) do - - engine.pokew(modpos+modsize+count*2+i*2,caste) -- add caste - i= i+1 - end - - engine.poked(stoff,count) - return count -end -function embark(names) - RaceTable=RaceTable or BuildNameTable() - mypos=engine.getmod('Embark') - stoff=VersionInfo.getAddress('start_dwarf_count') - if mypos then --if mod already loaded - print("Mod already loaded @:"..mypos.." just updating") - modpos=mypos - _,modsize=engine.loadobj('dfusion/embark/embark.o') - - count=MakeTable(modpos,modsize,names) --just remake tables - else - - _,tofind=df.sizeof(df.global.ui:_field("race_id")) - - loc=offsets.find(stoff,0x0f,0xb7,0x0d,DWORD_,tofind) --MOVZX ECX,WORD PTR[] - - print(string.format("found:%x",loc)) - if((loc~=0)and(loc-stoff<1000)) then - loc2=offsets.find(loc,0x83,0xc8,0xff) -- or eax, ffffff (for caste) - if loc2== 0 then - error ("Location for caste nulling not found!") - end - engine.pokeb(loc2,0x90) - engine.pokeb(loc2+1,0x90) - engine.pokeb(loc2+2,0x90) - ModData=engine.installMod("dfusion/embark/embark.o","Embark",256) - modpos=ModData.pos - modsize=ModData.size - local castepos=modpos+engine.FindMarker(ModData,"caste") - local racepos=modpos+engine.FindMarker(ModData,"race") - count=MakeTable(modpos,modsize,names) - engine.poked(castepos,modpos+modsize) --fix array start for race - engine.poked(racepos,modpos+modsize+count*2) --fix array start for caste - print("sucess loading mod @:"..modpos) - -- build race vector after module. - - - --finaly poke in the call! - engine.pokeb(loc,0x90) - engine.pokeb(loc+1,0x90) - engine.pokeb(loc+2,0xe8) - engine.poked(loc+3,modpos-loc-7) - --engine.pokeb(loc+5,0x90) - - SetExecute(modpos) - else - error("did not find patch location, failing...") - end - - end +function CustomEmbark:uninstall() + if self.installed then + self.call_patch:remove() + self.disable_castes:remove() + self.dwarfcount:remove() + end end \ No newline at end of file diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index f126ae53b..134d5cb67 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -18,7 +18,6 @@ DFHACK_PLUGIN(stripcaged stripcaged.cpp) DFHACK_PLUGIN(rprobe rprobe.cpp) DFHACK_PLUGIN(nestboxes nestboxes.cpp) DFHACK_PLUGIN(vshook vshook.cpp) -DFHACK_PLUGIN(steam-engine steam-engine.cpp) IF(UNIX) DFHACK_PLUGIN(ref-index ref-index.cpp) ENDIF() diff --git a/plugins/lua/dfusion.lua b/plugins/lua/dfusion.lua index 06128d29b..46f28f78e 100644 --- a/plugins/lua/dfusion.lua +++ b/plugins/lua/dfusion.lua @@ -4,8 +4,23 @@ local _ENV = mkmodule('plugins.dfusion') local ms=require("memscan") local marker={0xDE,0xAD,0xBE,0xEF} -patches={} +--utility functions +function dwordToTable(dword) + local b={bit32.extract(dword,0,8),bit32.extract(dword,8,8),bit32.extract(dword,16,8),bit32.extract(dword,24,8)} + return b +end +function concatTables(t1,t2) + for k,v in pairs(t2) do + table.insert(t1,v) + end +end +function makeCall(from,to) + local ret={0xe8} + concatTables(ret,dwordToTable(to-from-5)) + return ret +end -- A reversable binary patch +patches={} BinaryPatch=defclass(BinaryPatch) BinaryPatch.ATTRS {pre_data=DEFAULT_NIL,data=DEFAULT_NIL,address=DEFAULT_NIL,name=DEFAULT_NIL} function BinaryPatch:init(args) @@ -16,19 +31,8 @@ function BinaryPatch:init(args) if patches[self.name]~=nil then error("Patch already exist") end - self.max_val=0 - for k,v in pairs(args.pre_data) do - if type(k)~="number" then - error("non number key in pre_data") - end - if self.max_val Date: Sun, 21 Oct 2012 13:46:12 +0300 Subject: [PATCH 028/158] Small error fix --- plugins/lua/dfusion.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lua/dfusion.lua b/plugins/lua/dfusion.lua index 46f28f78e..ac9a20868 100644 --- a/plugins/lua/dfusion.lua +++ b/plugins/lua/dfusion.lua @@ -52,7 +52,7 @@ function BinaryPatch:test() end function BinaryPatch:apply() if not self:test() then - error(string.format("pre-data for binary patch does not match expected") + error(string.format("pre-data for binary patch does not match expected")) end local post_buf=df.new('uint8_t',#self.pre_data) From dfa3a520fd2e7243413d5dc38d253fd17e072c1e Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Sun, 21 Oct 2012 16:34:13 -0500 Subject: [PATCH 029/158] sync structures --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index b9b2e8c6d..e06438924 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit b9b2e8c6d2141f13966ed965b3f3ffe924e527db +Subproject commit e06438924929a8ecab751c0c233dad5767e91f7e From 209d593f2173e70085fe287d7635c03d66b94cd2 Mon Sep 17 00:00:00 2001 From: Warmist Date: Thu, 1 Nov 2012 16:00:00 +0200 Subject: [PATCH 030/158] Another day, another commit. --- plugins/Dfusion/luafiles/embark/init.lua | 146 +++++++++++++--------- plugins/lua/dfusion.lua | 19 ++- plugins/lua/dfusion/embark.lua | 148 +++++++++++++++++++++++ plugins/lua/dfusion/embark.o | Bin 0 -> 369 bytes scripts/dfusion.lua | 40 ++++++ 5 files changed, 289 insertions(+), 64 deletions(-) create mode 100644 plugins/lua/dfusion/embark.lua create mode 100644 plugins/lua/dfusion/embark.o diff --git a/plugins/Dfusion/luafiles/embark/init.lua b/plugins/Dfusion/luafiles/embark/init.lua index 76be00c72..b7795d049 100644 --- a/plugins/Dfusion/luafiles/embark/init.lua +++ b/plugins/Dfusion/luafiles/embark/init.lua @@ -2,68 +2,94 @@ local dfu=require("plugins.dfusion") local ms=require("memscan") local MAX_RACES=100 CustomEmbark=defclass(CustomEmbark,dfu.BinaryPlugin) -CustomEmbark.ATTRS{filename="dfusion/embark/embark.o",name="CustomEmbark",race_caste_data=DEFAULT_NIL} -function CustomEmbark:install() - local stoff=dfhack.internal.getAddress('start_dwarf_count') - if #self.race_caste_data<7 then - error("caste and race count must be bigger than 6") +local myos=dfhack.getOSType() +if myos=="windows" then + + CustomEmbark.ATTRS{filename="dfusion/embark/embark.o",name="CustomEmbark",race_caste_data=DEFAULT_NIL} + CustomEmbark.class_status="valid, not installed" + function CustomEmbark:install() + local stoff=dfhack.internal.getAddress('start_dwarf_count') + + if #self.race_caste_data<7 then + error("caste and race count must be bigger than 6") + end + if #self.race_caste_data>MAX_RACES then + error("caste and race count must be less then "..MAX_RACES) + end + if stoff==nil then + error("address for start_dwarf_count not found!") + end + local _,race_id_offset=df.sizeof(df.global.ui:_field("race_id")) + print(string.format("start=%08x",stoff)) + local needle={0x0f,0xb7,0x0d} --movzx eax,dword ptr [race_id] + local tmp_table=dfu.dwordToTable(race_id_offset) + for k,v in ipairs(tmp_table) do + table.insert(needle,v) + end + + local mem=ms.get_code_segment() + print(mem.uint8_t:addr2idx(stoff)) + print(mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff))) + local _,trg_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff),nil)--maybe endoff=stoff+bignumber + if trg_offset==nil then + error("address for race_load not found") + end + local call_data={0x90,0x90} + local _,data_offset=df.sizeof(self.data) + dfu.concatTables(call_data,dfu.makeCall(trg_offset+2,data_offset)) + self.call_patch=dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} + needle={0x83,0xc8,0xff} -- or eax, 0xFF + local _,caste_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(trg_offset),nil) + if caste_offset==nil or caste_offset-stoff>1000 then + error("Caste change code not found or found too far!") + end + + self.disable_castes=dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} + self.disable_castes:apply() + self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} + self.dwarfcount:apply() + local caste_array=self:allocate("caste_array","uint16_t",#self.race_caste_data) + local race_array=self:allocate("race_array","uint16_t",#self.race_caste_data) + self:setEmbarkParty(self.race_caste_data) + for k,v in ipairs(self.race_caste_data) do + caste_array[k-1]=v[2] + race_array[k-1]=v[1] + end + local race_array_off,caste_array_off + local _ + _,race_array_off=df.sizeof(race_array) + _,caste_array_off=df.sizeof(caste_array) + self:set_marker_dword("race",caste_array_off) --hehe... mixed them up i guess... + self:set_marker_dword("caste",race_array_off) + + self:move_to_df() + self.call_patch:apply() + self.installed=true end - if #self.race_caste_data>MAX_RACES then - error("caste and race count must be less then "..MAX_RACES) + function CustomEmbark:setEmbarkParty(racesAndCastes) + self.race_caste_data=racesAndCastes + if self.dwarfcount== nil then + self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} + self.dwarfcount:apply() + else + self.dwarfcount:repatch(dfu.dwordToTable(#self.race_caste_data)) + end + end - if stoff==nil then - error("address for start_dwarf_count not found!") + function CustomEmbark:status() + if self.installed then + return "valid, installed" + else + return "valid, not installed" + end end - local _,race_id_offset=df.sizeof(df.global.ui:_field("race_id")) - print(string.format("start=%08x",stoff)) - local needle={0x0f,0xb7,0x0d} --movzx eax,dword ptr [race_id] - local tmp_table=dfu.dwordToTable(race_id_offset) - for k,v in ipairs(tmp_table) do - table.insert(needle,v) - end - - local mem=ms.get_code_segment() - print(mem.uint8_t:addr2idx(stoff)) - print(mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff))) - local _,trg_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff),nil)--maybe endoff=stoff+bignumber - if trg_offset==nil then - error("address for race_load not found") - end - local call_data={0x90,0x90} - local _,data_offset=df.sizeof(self.data) - dfu.concatTables(call_data,dfu.makeCall(trg_offset+2,data_offset)) - self.call_patch=dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} - needle={0x83,0xc8,0xff} -- or eax, 0xFF - local _,caste_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(trg_offset),nil) - if caste_offset==nil or caste_offset-stoff>1000 then - error("Caste change code not found or found too far!") - end - - self.disable_castes=dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} - self.disable_castes:apply() - self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} - self.dwarfcount:apply() - local caste_array=self:allocate("caste_array","uint16_t",#self.race_caste_data) - local race_array=self:allocate("race_array","uint16_t",#self.race_caste_data) - for k,v in ipairs(self.race_caste_data) do - caste_array[k-1]=v[2] - race_array[k-1]=v[1] - end - local race_array_off,caste_array_off - local _ - _,race_array_off=df.sizeof(race_array) - _,caste_array_off=df.sizeof(caste_array) - self:set_marker_dword("race",caste_array_off) --hehe... mixed them up i guess... - self:set_marker_dword("caste",race_array_off) - - self:move_to_df() - self.call_patch:apply() - self.installed=true -end -function CustomEmbark:uninstall() - if self.installed then - self.call_patch:remove() - self.disable_castes:remove() - self.dwarfcount:remove() + function CustomEmbark:uninstall() + if self.installed then + self.call_patch:remove() + self.disable_castes:remove() + self.dwarfcount:remove() + end end +else + CustomEmbark.class_status="invalid, os not supported" end \ No newline at end of file diff --git a/plugins/lua/dfusion.lua b/plugins/lua/dfusion.lua index ac9a20868..053c486cf 100644 --- a/plugins/lua/dfusion.lua +++ b/plugins/lua/dfusion.lua @@ -107,6 +107,7 @@ end -- A binary hack (obj file) loader/manager -- has to have: a way to get offsets for marked areas (for post load modification) or some way to do that pre-load -- page managing (including excecute/write flags for DEP and the like) +-- TODO plugin state enum, a way to modify post install (could include repatching code...) plugins=plugins or {} BinaryPlugin=defclass(BinaryPlugin) BinaryPlugin.ATTRS {filename=DEFAULT_NIL,reloc_table={},name=DEFAULT_NIL} @@ -115,14 +116,21 @@ function BinaryPlugin:init(args) end function BinaryPlugin:postinit(args) if self.name==nil then error("Not a valid plugin name!") end - --if plugins[args.name]==nil then + if plugins[args.name]==nil then plugins[self.name]=self - --else - -- error("Trying to create a same plugin") - --end + else + error("Trying to create a same plugin") + end self.allocated_object={} self:load() end +function BinaryPlugin:get_or_alloc(name,typename,arrsize) + if self.allocated_object[name]~=nil then + return self.allocated_object[name] + else + return self:allocate(name,typename,arrsize) + end +end function BinaryPlugin:allocate(name,typename,arrsize) local trg if df[typename]==nil then @@ -182,6 +190,9 @@ function BinaryPlugin:print_data() end print(out) end +function BinaryPlugin:status() + return "invalid, base class only!" +end function BinaryPlugin:__gc() for k,v in pairs(self.allocated_object) do df.delete(v) diff --git a/plugins/lua/dfusion/embark.lua b/plugins/lua/dfusion/embark.lua new file mode 100644 index 000000000..a674a96d3 --- /dev/null +++ b/plugins/lua/dfusion/embark.lua @@ -0,0 +1,148 @@ +local _ENV = mkmodule('plugins.dfusion.embark') +local dfu=require("plugins.dfusion") +local ms=require("memscan") +local MAX_RACES=100 +CustomEmbark=defclass(CustomEmbark,dfu.BinaryPlugin) +CustomEmbark.name="CustomEmbark" +local myos=dfhack.getOSType() +if myos=="windows" then + CustomEmbark.ATTRS{filename="hack/lua/plugins/dfusion/embark.o",name="CustomEmbark",race_caste_data=DEFAULT_NIL} + CustomEmbark.class_status="valid, not installed" + function CustomEmbark:install() + local stoff=dfhack.internal.getAddress('start_dwarf_count') + + if #self.race_caste_data<7 then + error("caste and race count must be bigger than 6") + end + if #self.race_caste_data>MAX_RACES then + error("caste and race count must be less then "..MAX_RACES) + end + if stoff==nil then + error("address for start_dwarf_count not found!") + end + local _,race_id_offset=df.sizeof(df.global.ui:_field("race_id")) + print(string.format("start=%08x",stoff)) + local needle={0x0f,0xb7,0x0d} --movzx eax,dword ptr [race_id] + local tmp_table=dfu.dwordToTable(race_id_offset) + for k,v in ipairs(tmp_table) do + table.insert(needle,v) + end + + local mem=ms.get_code_segment() + print(mem.uint8_t:addr2idx(stoff)) + print(mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff))) + local _,trg_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff),nil)--maybe endoff=stoff+bignumber + if trg_offset==nil then + error("address for race_load not found") + end + local call_data={0x90,0x90} + local _,data_offset=df.sizeof(self.data) + dfu.concatTables(call_data,dfu.makeCall(trg_offset+2,data_offset)) + self.call_patch=dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} + needle={0x83,0xc8,0xff} -- or eax, 0xFF + local _,caste_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(trg_offset),nil) + if caste_offset==nil or caste_offset-stoff>1000 then + error("Caste change code not found or found too far!") + end + + self.disable_castes=dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} + self.disable_castes:apply() + + + self:setEmbarkParty(self.race_caste_data) + local caste_array=self:get_or_alloc("caste_array","uint16_t",MAX_RACES) + local race_array=self:get_or_alloc("race_array","uint16_t",MAX_RACES) + + local race_array_off,caste_array_off + local _ + _,race_array_off=df.sizeof(race_array) + _,caste_array_off=df.sizeof(caste_array) + self:set_marker_dword("race",caste_array_off) --hehe... mixed them up i guess... + self:set_marker_dword("caste",race_array_off) + + self:move_to_df() + self.call_patch:apply() + self.installed=true + end + function CustomEmbark:setEmbarkParty(racesAndCastes) + local stoff=dfhack.internal.getAddress('start_dwarf_count') + if #racesAndCastes<7 then + error("caste and race count must be bigger than 6") + end + if #racesAndCastes>MAX_RACES then + error("caste and race count must be less then "..MAX_RACES) + end + + self.race_caste_data=racesAndCastes + if self.dwarfcount== nil then + self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} + self.dwarfcount:apply() + else + self.dwarfcount:repatch(dfu.dwordToTable(#self.race_caste_data)) + end + local caste_array=self:get_or_alloc("caste_array","uint16_t",MAX_RACES) + local race_array=self:get_or_alloc("race_array","uint16_t",MAX_RACES) + for k,v in ipairs(self.race_caste_data) do + caste_array[k-1]=v[2] + race_array[k-1]=v[1] + end + end + function CustomEmbark:status() + if self.installed then + return "valid, installed" + else + return "valid, not installed" + end + end + function CustomEmbark:uninstall() + if self.installed then + self.call_patch:remove() + self.disable_castes:remove() + self.dwarfcount:remove() + end + end + function CustomEmbark:edit() + local data=self.race_caste_data or {} + print(string.format("Old race count:%d",#data)) + local endthis=false + print("current:") + while(not endthis) do + print(" # RaceId Race name Caste num") + for k,v in pairs(data) do + local name=df.creature_raw.find(v[1]).creature_id or "" + print(string.format("%3d. %6d %20s %d",k,v[1],name,v[2])) + end + print("a- add, r-remove, c-cancel, s-save and update") + local choice=io.stdin:read() + if choice=='a' then + print("Enter new race then caste ids:") + local race=tonumber(io.stdin:read()) + local caste=tonumber(io.stdin:read()) + if race and caste then + table.insert(data,{race,caste}) + else + print("input parse error") + end + elseif choice=='r' then + print("enter number to remove:") + local num_rem=tonumber(io.stdin:read()) + if num_rem~=nil then + table.remove(data,num_rem) + end + elseif choice=='c' then + endthis=true + elseif choice=='s' then + endthis=true + if self.installed then + self:setEmbarkParty(data) + else + self.race_caste_data=data + self:install() + end + end + end + end +else + CustomEmbark.class_status="invalid, os not supported" +end +return _ENV \ No newline at end of file diff --git a/plugins/lua/dfusion/embark.o b/plugins/lua/dfusion/embark.o new file mode 100644 index 0000000000000000000000000000000000000000..87f5bbd68f5c8d0aaf6f81485f653a440145a952 GIT binary patch literal 369 zcmeZaWM%+?B|yvtX0bBrm84dbfY}g20!Z~B@j*-l27?5>l*E!mG;wsU1B1Z Date: Fri, 2 Nov 2012 00:28:16 +0200 Subject: [PATCH 031/158] New way of doing things! Now using a class for menus, also no (non script) way to use bin-plugins. --- plugins/Dfusion/luafiles/adv_tools/init.lua | 133 -------------------- plugins/Dfusion/luafiles/common.lua | 32 +---- plugins/lua/dfusion.lua | 35 ++++++ plugins/lua/dfusion/adv_tools.lua | 52 ++++++++ scripts/dfusion.lua | 47 ++----- 5 files changed, 96 insertions(+), 203 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/adv_tools/init.lua create mode 100644 plugins/lua/dfusion/adv_tools.lua diff --git a/plugins/Dfusion/luafiles/adv_tools/init.lua b/plugins/Dfusion/luafiles/adv_tools/init.lua deleted file mode 100644 index 566484f01..000000000 --- a/plugins/Dfusion/luafiles/adv_tools/init.lua +++ /dev/null @@ -1,133 +0,0 @@ -adv_tools= {} -adv_tools.menu=MakeMenu() ---TODO make every tool generic (work for both modes) -function adv_tools.reincarnate(swap_soul) --only for adventurer i guess - if swap_soul==nil then - swap_soul=true - end - local adv=df.global.world.units.active[0] - if adv.flags1.dead==false then - error("You are not dead (yet)!") - end - local hist_fig=getNemesis(adv).figure - if hist_fig==nil then - error("No historical figure for adventurer...") - end - local events=df.global.world.history.events - local trg_hist_fig - 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].victim==hist_fig.id then - --print("Is same id:"..i) - trg_hist_fig=events[i].slayer - if trg_hist_fig then - trg_hist_fig=df.historical_figure.find(trg_hist_fig) - end - break - end - end - end - if trg_hist_fig ==nil then - qerror("Slayer not found") - end - - local trg_unit=trg_hist_fig.unit_id - if trg_unit==nil then - qerror("Unit id not found!") - end - local trg_unit_final=df.unit.find(trg_unit) - - tools.change_adv(trg_unit_final) - if swap_soul then --actually add a soul... - t_soul=adv.status.current_soul - adv.status.current_soul=df.NULL - adv.status.souls:resize(0) - trg_unit_final.status.current_soul=t_soul - trg_unit_final.status.souls:insert(#trg_unit_final.status.souls,t_soul) - end -end -adv_tools.menu:add("Reincarnate",adv_tools.reincarnate) -function adv_tools.ressurect() - - v2=engine.peek(vector:getval(indx),ptr_Creature.hurt1) - for i=0,v2:size()-1 do - v2:setval(i,0) - end - v2=engine.peek(vector:getval(indx),ptr_Creature.hurt2) - v2.type=DWORD - for i=0,v2:size()-1 do - v2:setval(i,0) - end - engine.poke(vector:getval(indx),ptr_Creature.bloodlvl,60000) --give blood - engine.poke(vector:getval(indx),ptr_Creature.bleedlvl,0) --stop some bleeding... - local flg=engine.peek(vector:getval(indx),ptr_Creature.flags) - flg:set(1,false) --ALIVE - flg:set(39,false) -- leave body yet again - flg:set(37,false) -- something todo with wounds- lets you walk again. - flg:set(58,true) -- makes them able to breathe - flg:set(61,true) -- gives them sight - engine.poke(vector:getval(indx),ptr_Creature.flags,flg) -end - -function adv_tools.wagonmode() --by rumrusher - --first three lines same as before (because we will need an offset of creature at location x,y,z) - myoff=offsets.getEx("AdvCreatureVec") - vector=engine.peek(myoff,ptr_vector) - indx=GetCreatureAtPos(getxyz()) - --indx=0 - --print(string.format("%x",vector:getval(indx))) - flg=engine.peek(vector:getval(indx),ptr_Creature.flags) --get flags - flg:set(1,false) - flg:set(74,false) - engine.poke(vector:getval(indx),ptr_Creature.flags,flg) - print("To stay normal press y, else hit Enter turn Wagon mode on.") - r=io.stdin:read() -- repeat for it too work... also creature will be dead. - if r== "y" then - flg=engine.peek(vector:getval(indx),ptr_Creature.flags) - flg:set(1,false) - engine.poke(vector:getval(indx),ptr_Creature.flags,flg) - else - flg=engine.peek(vector:getval(indx),ptr_Creature.flags) - flg:set(1,false) - flg:flip(74) - engine.poke(vector:getval(indx),ptr_Creature.flags,flg) - end -end -function selectall() - local retvec={} --return vector (or a list) - myoff=offsets.getEx("AdvCreatureVec") - vector=engine.peek(myoff,ptr_vector) --standart start - for i=0,vector:size()-1 do --check all creatures - local off - off=vector:getval(i) - local flags=engine.peek(off,ptr_Creature.flags) - if flags:get(1)==true then --if dead ... - table.insert(retvec,off)--... add it to return vector - end - end - return retvec --return the "return vector" :) -end -function adv_tools.hostilate() - vector=engine.peek(offsets.getEx("AdvCreatureVec"),ptr_vector) - id=GetCreatureAtPos(getxyz()) - print(string.format("Vec:%d cr:%d",vector:size(),id)) - off=vector:getval(id) - crciv=engine.peek(vector:getval(id),ptr_Creature.civ) - curciv=engine.peek(vector:getval(0),ptr_Creature.civ) - - if curciv==crciv then - print("Friendly-making enemy") - engine.poke(off,ptr_Creature.civ,-1) - flg=engine.peek(off,ptr_Creature.flags) - flg:set(17,true) - engine.poke(off,ptr_Creature.flags,flg) - else - print("Enemy- making friendly") - engine.poke(off,ptr_Creature.civ,curciv) - flg=engine.peek(off,ptr_Creature.flags) - flg:set(17,false) - flg:set(19,false) - engine.poke(off,ptr_Creature.flags,flg) - end -end diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua index a6781b385..bdf3a2bc8 100644 --- a/plugins/Dfusion/luafiles/common.lua +++ b/plugins/Dfusion/luafiles/common.lua @@ -242,37 +242,7 @@ function engine.installMod(file,name,bonussize) return T end -it_menu={} -it_menu.__index=it_menu -function it_menu:add(name,func) - table.insert(self.items,{func,name}) -end -function it_menu:display() - print("Select choice (q exits):") - for p,c in pairs(self.items) do - print(string.format("%3d).%s",p,c[2])) - end - local ans - repeat - local r - r=getline("") - if r==nil then return end - if r=='q' then return end - ans=tonumber(r) - - if ans==nil or not(ans<=#self.items and ans>0) then - print("incorrect choice") - end - - until ans~=nil and (ans<=#self.items and ans>0) - self.items[ans][1]() -end -function MakeMenu() - local ret={} - ret.items={} - setmetatable(ret,it_menu) - return ret -end + function PrintPattern(loadedpattern) for k,v in pairs(loadedpattern) do diff --git a/plugins/lua/dfusion.lua b/plugins/lua/dfusion.lua index 053c486cf..c7bd9bef3 100644 --- a/plugins/lua/dfusion.lua +++ b/plugins/lua/dfusion.lua @@ -202,4 +202,39 @@ function BinaryPlugin:__gc() end self.data:delete() end +-- a Menu for some stuff. Maybe add a posibility of it working as a gui, or a gui adaptor? +-- Todo add hints, and parse them to make a "smart" choice of parameters to pass +SimpleMenu=defclass(SimpleMenu) +SimpleMenu.ATTRS{title=DEFAULT_NIL} +function SimpleMenu:init(args) + self.items={} +end +function SimpleMenu:add(name,entry,hints) + table.insert(self.items,{entry,name,hints}) +end +function SimpleMenu:display() + print("Select choice (q exits):") + for p,c in pairs(self.items) do + print(string.format("%3d).%s",p,c[2])) + end + local ans + repeat + local r + r=io.stdin:read() + if r==nil then return end + if r=='q' then return end + ans=tonumber(r) + + if ans==nil or not(ans<=#self.items and ans>0) then + print("Invalid choice.") + end + + until ans~=nil and (ans<=#self.items and ans>0) + if type(self.items[ans][1])=="function" then + self.items[ans][1]() + else + self.items[ans][1]:display() + end +end + return _ENV \ No newline at end of file diff --git a/plugins/lua/dfusion/adv_tools.lua b/plugins/lua/dfusion/adv_tools.lua new file mode 100644 index 000000000..4440a4b2f --- /dev/null +++ b/plugins/lua/dfusion/adv_tools.lua @@ -0,0 +1,52 @@ +local _ENV = mkmodule('plugins.dfusion.adv_tools') +local dfu=require("plugins.dfusion") +menu=dfu.SimpleMenu() +function Reincarnate(trg_unit,swap_soul) --only for adventurer i guess + if swap_soul==nil then + swap_soul=true + end + local adv=trg_unit or df.global.world.units.active[0] + if adv.flags1.dead==false then + qerror("You are not dead (yet)!") + end + local hist_fig=getNemesis(adv).figure + if hist_fig==nil then + qerror("No historical figure for adventurer...") + end + local events=df.global.world.history.events + local trg_hist_fig + 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].victim==hist_fig.id then + --print("Is same id:"..i) + trg_hist_fig=events[i].slayer + if trg_hist_fig then + trg_hist_fig=df.historical_figure.find(trg_hist_fig) + end + break + end + end + end + if trg_hist_fig ==nil then + qerror("Slayer not found") + end + + local trg_unit=trg_hist_fig.unit_id + if trg_unit==nil then + qerror("Unit id not found!") + end + local trg_unit_final=df.unit.find(trg_unit) + + tools.change_adv(trg_unit_final) + if swap_soul then --actually add a soul... + t_soul=adv.status.current_soul + adv.status.current_soul=df.NULL + adv.status.souls:resize(0) + trg_unit_final.status.current_soul=t_soul + trg_unit_final.status.souls:insert(#trg_unit_final.status.souls,t_soul) + end +end +menu:add("Reincarnate",Reincarnate,{{df.unit,"optional"}})-- bool, optional + +return _ENV \ No newline at end of file diff --git a/scripts/dfusion.lua b/scripts/dfusion.lua index 63a530454..4fee0438e 100644 --- a/scripts/dfusion.lua +++ b/scripts/dfusion.lua @@ -1,42 +1,11 @@ --- a binary hack/plugin collection for df +-- a collection of misc lua scripts local dfu=require("plugins.dfusion") local myos=dfhack.getOSType() - ---some imports go here -local plugins={ - require("plugins.dfusion.embark").CustomEmbark -} ---show a table of all the statuses -function status(plug) - if dfu.plugins[plug.name]==nil then - return plug.class_status - else - return dfu.plugins[plug.name]:status() - end +args={...} +mainmenu=dfu.SimpleMenu() +function runsave() + print("doing file:"..df.global.world.cur_savegame.save_dir) end -function printPlugs() - local endthis=false - print("current:") - while(not endthis) do - for k,v in pairs(plugins) do - if v then - print(string.format("%2d. %15s-%s",k,v.name,status(v))) - end - end - print("e-edit and load, u-unload,c-cancel and then number to manipulate:") - local choice=io.stdin:read() - local num=tonumber(io.stdin:read()) - if num then - local plg=dfu.plugins[plugins[num].name] or plugins[num]() - if choice=='e' then - plg:edit() - elseif choice=='u' then - plg:uninstall() - elseif choice=='c' then - endthis=true - end - end - end -end - -printPlugs() \ No newline at end of file +mainmenu:add("Run save script",runsave) +mainmenu:add("Adventurer tools",require("plugins.dfusion.adv_tools").menu) +mainmenu:display() \ No newline at end of file From 296d1cf090745c9bb667ddb8d30395ad431d13ef Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 2 Nov 2012 00:50:20 +0200 Subject: [PATCH 032/158] More scripts for dfusion. Only fixes left, and updating bin-plugins (friendship and migrants(??)) --- plugins/lua/dfusion/adv_tools.lua | 68 ++++++++++++- plugins/lua/dfusion/tools.lua | 164 ++++++++++++++++++++++++++++++ scripts/dfusion.lua | 5 +- 3 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 plugins/lua/dfusion/tools.lua diff --git a/plugins/lua/dfusion/adv_tools.lua b/plugins/lua/dfusion/adv_tools.lua index 4440a4b2f..31e83b234 100644 --- a/plugins/lua/dfusion/adv_tools.lua +++ b/plugins/lua/dfusion/adv_tools.lua @@ -48,5 +48,69 @@ function Reincarnate(trg_unit,swap_soul) --only for adventurer i guess end end menu:add("Reincarnate",Reincarnate,{{df.unit,"optional"}})-- bool, optional - -return _ENV \ No newline at end of file +function change_adv(unit,nemesis) + if nemesis==nil then + nemesis=true --default value is nemesis switch too. + end + if unit==nil then + unit=getCreatureAtPointer() + end + if unit==nil then + error("Invalid unit!") + end + local other=df.global.world.units.active + local unit_indx + for k,v in pairs(other) do + if v==unit then + unit_indx=k + break + end + end + if unit_indx==nil then + error("Unit not found in array?!") --should not happen + end + other[unit_indx]=other[0] + other[0]=unit + if nemesis then --basicly copied from advtools plugin... + local nem=getNemesis(unit) + local other_nem=getNemesis(other[unit_indx]) + if other_nem then + other_nem.flags[0]=false + other_nem.flags[1]=true + end + if nem then + nem.flags[0]=true + nem.flags[2]=true + for k,v in pairs(df.global.world.nemesis.all) do + if v.id==nem.id then + df.global.ui_advmode.player_id=k + end + end + else + error("Current unit does not have nemesis record, further working not guaranteed") + end + end +end +menu:add("Change adventurer",change_adv) +function log_pos() + local adv=df.global.world.units.active[0] + + local wmap=df.global.world.map + local sub_pos={x=adv.pos.x,y=adv.pos.y,z=adv.pos.z} + local region_pos={x=wmap.region_x,y=wmap.region_y,z=wmap.region_z} + local pos={x=sub_pos.x+region_pos.x*48,y=sub_pos.y+region_pos.y*48,z=sub_pos.z+region_pos.z} + local state + if adv.flags1.dead then + state="dead" + else + state="live n kicking" + end + local message=string.format("%s %s at pos={%d,%d,%d} region={%d,%d,%d}",dfhack.TranslateName(adv.name),state,pos.x,pos.y,pos.z,region_pos.x,region_pos.y,region_pos.z) + print(message) + local path="deaths_"..df.global.world.cur_savegame.save_dir..".txt" + local f=io.open(path,"a") + f:write(message) + f:close() +end +menu:add("Log adventurers position",log_pos) +return _ENV diff --git a/plugins/lua/dfusion/tools.lua b/plugins/lua/dfusion/tools.lua new file mode 100644 index 000000000..9ddfb8e45 --- /dev/null +++ b/plugins/lua/dfusion/tools.lua @@ -0,0 +1,164 @@ +local _ENV = mkmodule('plugins.dfusion.tools') +local dfu=require("plugins.dfusion") +local ms=require "memscan" +menu=dfu.SimpleMenu() +function setrace(name) --TODO FIX + RaceTable=BuildNameTable() + 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):") + 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 + end + df.global.ui.race_id=id +end +menu:add("Set current race",setrace) +function GiveSentience(names) --TODO FIX + RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again + if names ==nil then + ids={} + print("Type race's token name in full caps to give sentience to:") + repeat + entry=getline() + id=RaceTable[entry] + until id~=nil + table.insert(ids,id) + else + ids={} + for _,name in pairs(names) do + id=RaceTable[name] + table.insert(ids,id) + end + end + for _,id in pairs(ids) do + local races=df.global.world.raws.creatures.all + + local castes=races[id].caste + print(string.format("Caste count:%i",castes.size)) + for i =0,#castes-1 do + + print("Caste name:"..castes[i].caste_id.."...") + + local flags=castes[i].flags + --print(string.format("%x",flagoffset)) + if flags.CAN_SPEAK then + print("\tis sentient.") + else + print("\tnon sentient. Allocating IQ...") + flags.CAN_SPEAK=true + end + end + end +end +menu:add("Give Sentience",GiveSentience) +function MakeFollow(unit,trgunit) + if unit == nil then + unit=dfhack.gui.getSelectedUnit() + end + if unit== nil then + error("Invalid creature") + end + if trgunit==nil then + trgunit=df.global.world.units.active[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 +menu:add("Make creature follow",MakeFollow) +function project(unit,trg) --TODO add to menu? + if unit==nil then + unit=getCreatureAtPointer() + end + + if unit==nil then + error("Failed to project unit. Unit not selected/valid") + end + -- todo: add projectile to world, point to unit, add flag to unit, add gen-ref to projectile. + local p=df.proj_unitst:new() + local startpos={x=unit.pos.x,y=unit.pos.y,z=unit.pos.z} + p.origin_pos=startpos + p.target_pos=trg + p.cur_pos=startpos + p.prev_pos=startpos + p.unit=unit + --- wtf stuff + p.unk14=100 + p.unk16=-1 + p.unk23=-1 + p.fall_delay=5 + p.fall_counter=5 + p.collided=true + -- end wtf + local citem=df.global.world.proj_list + local maxid=1 + local newlink=df.proj_list_link:new() + newlink.item=p + while citem.item~= nil do + if citem.item.id>maxid then maxid=citem.item.id end + if citem.next ~= nil then + citem=citem.next + else + break + end + end + p.id=maxid+1 + newlink.prev=citem + citem.next=newlink + local proj_ref=df.general_ref_projectile:new() + proj_ref.projectile_id=p.id + unit.refs:insert(#unit.refs,proj_ref) + unit.flags1.projectile=true +end +function empregnate(unit) + if unit==nil then + unit=getSelectedUnit() + end + + if unit==nil then + unit=getCreatureAtPos(getxyz()) + end + + if unit==nil then + error("Failed to empregnate. Unit not selected/valid") + end + if unit.curse then + unit.curse.add_tags2.STERILE=false + end + local genes = unit.appearance.genes + if unit.relations.pregnancy_ptr == nil then + print("creating preg ptr.") + if false then + print(string.format("%x %x",df.sizeof(unit.relations:_field("pregnancy_ptr")))) + return + end + unit.relations.pregnancy_ptr = { new = true, assign = genes } + end + local ngenes = unit.relations.pregnancy_ptr + if #ngenes.appearance ~= #genes.appearance or #ngenes.colors ~= #genes.colors then + print("Array sizes incorrect, fixing.") + ngenes:assign(genes); + end + print("Setting preg timer.") + unit.relations.pregnancy_timer=10 + unit.relations.pregnancy_mystery=1 +end +menu:add("Empregnate",empregnate) +return _ENV \ No newline at end of file diff --git a/scripts/dfusion.lua b/scripts/dfusion.lua index 4fee0438e..79f9fd953 100644 --- a/scripts/dfusion.lua +++ b/scripts/dfusion.lua @@ -4,8 +4,11 @@ local myos=dfhack.getOSType() args={...} mainmenu=dfu.SimpleMenu() function runsave() - print("doing file:"..df.global.world.cur_savegame.save_dir) + local path=string.format("data/save/%s/dfhack.lua",df.global.world.cur_savegame.save_dir) + print("doing file:"..path) + loadfile(path)() end mainmenu:add("Run save script",runsave) mainmenu:add("Adventurer tools",require("plugins.dfusion.adv_tools").menu) +mainmenu:add("Misc tools",require("plugins.dfusion.tools").menu) mainmenu:display() \ No newline at end of file From 5295be5fdbe4ef7e40e174ddfab86253d6d154bd Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 2 Nov 2012 20:28:08 +0200 Subject: [PATCH 033/158] More work done. Only bin-plugs left (and docs) --- plugins/lua/dfusion/adv_tools.lua | 2 +- plugins/lua/dfusion/tools.lua | 41 +++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/plugins/lua/dfusion/adv_tools.lua b/plugins/lua/dfusion/adv_tools.lua index 31e83b234..6e95d2117 100644 --- a/plugins/lua/dfusion/adv_tools.lua +++ b/plugins/lua/dfusion/adv_tools.lua @@ -87,7 +87,7 @@ function change_adv(unit,nemesis) end end else - error("Current unit does not have nemesis record, further working not guaranteed") + qerror("Current unit does not have nemesis record, further working not guaranteed") end end end diff --git a/plugins/lua/dfusion/tools.lua b/plugins/lua/dfusion/tools.lua index 9ddfb8e45..e577a9418 100644 --- a/plugins/lua/dfusion/tools.lua +++ b/plugins/lua/dfusion/tools.lua @@ -2,14 +2,31 @@ local _ENV = mkmodule('plugins.dfusion.tools') local dfu=require("plugins.dfusion") local ms=require "memscan" menu=dfu.SimpleMenu() -function setrace(name) --TODO FIX - RaceTable=BuildNameTable() - print("Your current race is:"..GetRaceToken(df.global.ui.race_id)) +RaceNames={} +function build_race_names() + if #RaceNames~=0 then + return RaceNames + else + for k,v in pairs(df.global.world.raws.creatures.all) do + RaceNames[v.creature_id]=k + end + dfhack.onStateChange.invalidate_races=function(change_id) --todo does this work? + if change_id==SC_WORLD_UNLOADED then + dfhack.onStateChange.invalidate_races=nil + RaceNames={} + end + end + return RaceNames + end +end +function setrace(name) + local RaceTable=build_race_names() + print("Your current race is:"..df.global.world.raws.creatures.all[df.global.ui.race_id].creature_id) local id if name == nil then print("Type new race's token name in full caps (q to quit):") repeat - entry=getline() + local entry=io.stdin:read() if entry=="q" then return end @@ -24,16 +41,20 @@ function setrace(name) --TODO FIX df.global.ui.race_id=id end menu:add("Set current race",setrace) -function GiveSentience(names) --TODO FIX - RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again +function GiveSentience(names) + local RaceTable=build_race_names() --slow.If loaded don't load again + local id,ids if names ==nil then ids={} print("Type race's token name in full caps to give sentience to:") repeat - entry=getline() + id=io.stdin:read() id=RaceTable[entry] - until id~=nil - table.insert(ids,id) + if id~=nil then + table.insert(ids,id) + end + until id==nil + else ids={} for _,name in pairs(names) do @@ -45,7 +66,7 @@ function GiveSentience(names) --TODO FIX local races=df.global.world.raws.creatures.all local castes=races[id].caste - print(string.format("Caste count:%i",castes.size)) + print(string.format("Caste count:%i",#castes)) for i =0,#castes-1 do print("Caste name:"..castes[i].caste_id.."...") From 86e4a42bdda70a47338969aba2b8ade42800294f Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 2 Nov 2012 20:59:05 +0200 Subject: [PATCH 034/158] Small fix due to vmethod change --- plugins/reactionhooks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/reactionhooks.cpp b/plugins/reactionhooks.cpp index d70fb9ea1..ba0f8742d 100644 --- a/plugins/reactionhooks.cpp +++ b/plugins/reactionhooks.cpp @@ -203,7 +203,7 @@ struct product_hook : item_product { (df::unit *unit, std::vector *out_items, std::vector *in_reag, std::vector *in_items, - int32_t quantity, int16_t skill, + int32_t quantity, df::job_skill skill, df::historical_entity *entity, df::world_site *site) ) { if (auto product = products[this]) From e887c60e93c819dc3b803457dbb6b3c3c7300731 Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 2 Nov 2012 21:00:35 +0200 Subject: [PATCH 035/158] Removed unused buffers. --- plugins/devel/memview.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/devel/memview.cpp b/plugins/devel/memview.cpp index 757b475dd..29b8403f8 100644 --- a/plugins/devel/memview.cpp +++ b/plugins/devel/memview.cpp @@ -168,8 +168,6 @@ command_result memview (color_ostream &out, vector & parameters) else memdata.refresh=0; - - uint8_t *buf,*lbuf; memdata.buf=new uint8_t[memdata.len]; memdata.lbuf=new uint8_t[memdata.len]; Core::getInstance().p->getMemRanges(memdata.ranges); From a7bf526f41216f6e43c942c21907dbd46fe8f44f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 8 Nov 2012 21:27:56 +0400 Subject: [PATCH 036/158] Make workflow consider squad-assigned items busy. --- NEWS | 1 + plugins/workflow.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f2237cab9..32181f16a 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ DFHack future - properly considers minecarts assigned to routes busy. - code for deducing job outputs rewritten in lua for flexibility. - logic fix: collecting webs produces silk, and ungathered webs are not thread. + - items assigned to squads are considered busy, even if not in inventory. New Fix Armory plugin: Together with a couple of binary patches and the gui/assign-rack script, this plugin makes weapon racks, armor stands, chests and cabinets in diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index d46daed44..5347d4671 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -1004,6 +1004,12 @@ static bool isRouteVehicle(df::item *item) return vehicle && vehicle->route_id >= 0; } +static bool isAssignedSquad(df::item *item) +{ + auto &vec = ui->equipment.items_assigned[item->getType()]; + return binsearch_index(vec, &df::item::id, item->id) >= 0; +} + static void map_job_items(color_ostream &out) { for (size_t i = 0; i < constraints.size(); i++) @@ -1117,8 +1123,10 @@ static void map_job_items(color_ostream &out) item->isAssignedToStockpile() || isRouteVehicle(item) || itemInRealJob(item) || - itemBusy(item)) + itemBusy(item) || + isAssignedSquad(item)) { + is_invalid = true; cv->item_inuse++; } else From eb936c4ce07bb16684de0157a2ab5bbdf74fc4ca Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 10 Nov 2012 17:06:54 +0400 Subject: [PATCH 037/158] Support milking and shearing in workflow. --- NEWS | 1 + library/modules/Job.cpp | 2 +- library/modules/Materials.cpp | 2 ++ library/xml | 2 +- plugins/lua/workflow.lua | 23 +++++++++++++++++------ plugins/workflow.cpp | 4 +++- scripts/gui/workflow.lua | 2 +- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 32181f16a..51321be95 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,7 @@ DFHack future - code for deducing job outputs rewritten in lua for flexibility. - logic fix: collecting webs produces silk, and ungathered webs are not thread. - items assigned to squads are considered busy, even if not in inventory. + - shearing and milking jobs are supported, but only with generic MILK or YARN outputs. New Fix Armory plugin: Together with a couple of binary patches and the gui/assign-rack script, this plugin makes weapon racks, armor stands, chests and cabinets in diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index def3b4192..757000885 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -75,7 +75,7 @@ df::job *DFHack::Job::cloneJobStruct(df::job *job) { df::general_ref *ref = pnew->references[i]; - if (virtual_cast(ref)) + if (virtual_cast(ref)) vector_erase_at(pnew->references, i); else pnew->references[i] = ref->clone(); diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 7c06aeb4c..4da484ade 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -425,6 +425,8 @@ bool MaterialInfo::matches(const df::dfhack_material_category &cat) TEST(glass, IS_GLASS); if (cat.bits.clay && linear_index(material->reaction_product.id, std::string("FIRED_MAT")) >= 0) return true; + if (cat.bits.milk && linear_index(material->reaction_product.id, std::string("CHEESE_MAT")) >= 0) + return true; return false; } diff --git a/library/xml b/library/xml index 4ab899319..02e0e0d7b 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 4ab899319014d950214714a48cd3049a4beb5eb5 +Subproject commit 02e0e0d7b9a7ef708a621ef5511a24bf8657b4a2 diff --git a/plugins/lua/workflow.lua b/plugins/lua/workflow.lua index 4c011b24c..c3dbe20d9 100644 --- a/plugins/lua/workflow.lua +++ b/plugins/lua/workflow.lua @@ -301,15 +301,26 @@ function listWeakenedConstraints(outputs) local mask = cons.mat_mask if (cons.mat_type or -1) >= 0 then cons.mat_mask = nil + local info = dfhack.matinfo.decode(cons) + if info then + for i,flag in ipairs(df.dfhack_material_category) do + if flag and flag ~= 'wood2' and info:matches{[flag]=true} then + mask = mask or {} + mask[flag] = true + end + end + end end register(cons) if mask then - table.insert(generic, { - item_type = cons.item_type, - item_subtype = cons.item_subtype, - is_craft = cons.is_craft, - mat_mask = mask - }) + for k,v in pairs(mask) do + table.insert(generic, { + item_type = cons.item_type, + item_subtype = cons.item_subtype, + is_craft = cons.is_craft, + mat_mask = { [k] = v } + }) + end end table.insert(anymat, { item_type = cons.item_type, diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index 5347d4671..c89d87333 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -377,7 +377,9 @@ static bool isSupportedJob(df::job *job) Job::getHolder(job) && (!job->job_items.empty() || job->job_type == job_type::CollectClay || - job->job_type == job_type::CollectSand); + job->job_type == job_type::CollectSand || + job->job_type == job_type::MilkCreature || + job->job_type == job_type::ShearCreature); } static bool isOptionEnabled(unsigned flag) diff --git a/scripts/gui/workflow.lua b/scripts/gui/workflow.lua index 8dc958062..366e3ec91 100644 --- a/scripts/gui/workflow.lua +++ b/scripts/gui/workflow.lua @@ -306,7 +306,7 @@ function JobConstraints:onNewConstraint() end dlg.showListPrompt( - 'Job Outputs', + 'New limit', 'Select one of the possible outputs:', COLOR_WHITE, choices, From 56ef33ea0e5c6236239b4af43f00cb182c181987 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 10 Nov 2012 17:33:05 +0400 Subject: [PATCH 038/158] Support building steam engines on top of brooks without any down stairs. --- library/include/TileTypes.h | 6 ++++++ library/xml | 2 +- plugins/steam-engine.cpp | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/library/include/TileTypes.h b/library/include/TileTypes.h index d21fb3c17..48c10146a 100644 --- a/library/include/TileTypes.h +++ b/library/include/TileTypes.h @@ -203,6 +203,12 @@ namespace DFHack return ENUM_ATTR(tiletype_shape, passable_flow, tileShape(tiletype)); } + inline + bool FlowPassableDown(df::tiletype tiletype) + { + return ENUM_ATTR(tiletype_shape, passable_flow_down, tileShape(tiletype)); + } + inline bool isWalkable(df::tiletype tiletype) { diff --git a/library/xml b/library/xml index 02e0e0d7b..4b2124957 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 02e0e0d7b9a7ef708a621ef5511a24bf8657b4a2 +Subproject commit 4b2124957e282683480eaf05922e63c353364ec1 diff --git a/plugins/steam-engine.cpp b/plugins/steam-engine.cpp index d884191e5..60f38ef83 100644 --- a/plugins/steam-engine.cpp +++ b/plugins/steam-engine.cpp @@ -320,7 +320,7 @@ struct workshop_hook : df::building_workshopst { for (int y = y1; y <= y2; y++) { auto ptile = Maps::getTileType(x,y,z); - if (!ptile || !LowPassable(*ptile)) + if (!ptile || !FlowPassableDown(*ptile)) continue; auto pltile = Maps::getTileType(x,y,z-1); @@ -891,7 +891,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(dwarfmode_hook, feed); * Scan raws for matching workshop buildings. */ -static bool find_engines() +static bool find_engines(color_ostream &out) { engines.clear(); @@ -943,6 +943,8 @@ static bool find_engines() if (!ws.gear_tiles.empty()) engines.push_back(ws); + else + out.printerr("%s has no gear tiles - ignoring.\n", wslist[i]->code.c_str()); } return !engines.empty(); @@ -973,7 +975,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan { switch (event) { case SC_WORLD_LOADED: - if (find_engines()) + if (find_engines(out)) { out.print("Detected steam engine workshops - enabling plugin.\n"); enable_hooks(true); From f86371cfc3114dc08963cb3d0a521ca3660ac5ad Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 10 Nov 2012 18:06:41 +0400 Subject: [PATCH 039/158] Try blocking any use of stockpiles for squad stuff in fix-armory. --- plugins/fix-armory.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/fix-armory.cpp b/plugins/fix-armory.cpp index b937d40e8..99e5fd500 100644 --- a/plugins/fix-armory.cpp +++ b/plugins/fix-armory.cpp @@ -132,6 +132,9 @@ DFhackCExport command_result plugin_shutdown (color_ostream &out) * grace period during which the items can be instantly picked up again. */ +// Completely block the use of stockpiles +#define NO_STOCKPILES + // Check if the item is assigned to any use controlled by the military tab static bool is_assigned_item(df::item *item) { @@ -143,19 +146,6 @@ static bool is_assigned_item(df::item *item) if (idx < 0) return false; - // Exclude weapons used by miners, wood cutters etc - switch (type) { - case item_type::WEAPON: - // the game code also checks this for ammo, funnily enough - // maybe it's not just for weapons?.. - if (binsearch_index(ui->equipment.work_weapons, item->id) >= 0) - return false; - break; - - default: - break; - } - return true; } @@ -328,6 +318,16 @@ template struct armory_hook : Item { */ DEFINE_VMETHOD_INTERPOSE(bool, isCollected, ()) { +#ifdef NO_STOCKPILES + /* + * Completely block any items assigned to a squad from being stored + * in stockpiles. The reason is that I still observe haulers running + * around with bins to pick them up for some reason. There could be + * some unaccounted race conditions involved. + */ + if (is_assigned_item(this)) + return false; +#else // Block stockpiling of items in the armory. if (is_in_armory(this)) return false; @@ -354,6 +354,7 @@ template struct armory_hook : Item { return false; } } +#endif // Call the original vmethod return INTERPOSE_NEXT(isCollected)(); From f1d4eac70016ced41cb5e383e65763187a84b191 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 11 Nov 2012 11:58:43 +0200 Subject: [PATCH 040/158] Pre-class remove --- .../luafiles/friendship/friendship.asm | 10 +- .../Dfusion/luafiles/friendship/friendship.o | Bin 722 -> 854 bytes plugins/lua/dfusion/embark.lua | 2 + plugins/lua/dfusion/friendship.lua | 111 ++++++++++++++++++ plugins/lua/dfusion/friendship.o | Bin 0 -> 854 bytes plugins/lua/dfusion/srcs/compile.bat | 1 + plugins/lua/dfusion/srcs/embark.asm | 7 ++ plugins/lua/dfusion/srcs/friendship.asm | 106 +++++++++++++++++ 8 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 plugins/lua/dfusion/friendship.lua create mode 100644 plugins/lua/dfusion/friendship.o create mode 100644 plugins/lua/dfusion/srcs/compile.bat create mode 100644 plugins/lua/dfusion/srcs/embark.asm create mode 100644 plugins/lua/dfusion/srcs/friendship.asm diff --git a/plugins/Dfusion/luafiles/friendship/friendship.asm b/plugins/Dfusion/luafiles/friendship/friendship.asm index e56fe7f49..b649e38de 100644 --- a/plugins/Dfusion/luafiles/friendship/friendship.asm +++ b/plugins/Dfusion/luafiles/friendship/friendship.asm @@ -66,8 +66,10 @@ mov eax, [edi+0x8c] #jmp compare compare: push ecx +mark_racepointer: mov ebx,0xDEADBEEF #write a pointer to the list of allowed races -mov ecx,2000 #write a number of allowed races +mark_racecount: +mov ecx,0xDEADBEEF #write a number of allowed races loop1: cmp word[ebx+ecx*2],ax jz endok @@ -92,11 +94,13 @@ endfinal: pop ebx pop eax -mov [0xFEEDBEEF],eax #write a pointer to safe location (usually after this) +mark_safeloc1: +mov [0xDEADBEEF],eax #write a pointer to safe location (usually after this) pop eax pushfd inc eax #skip one instruction popfd push eax -mov eax,[0xFEEDBEEF] #write a pointer to safe location (same as above) +mark_safeloc2: +mov eax,[0xDEADBEEF] #write a pointer to safe location (same as above) ret diff --git a/plugins/Dfusion/luafiles/friendship/friendship.o b/plugins/Dfusion/luafiles/friendship/friendship.o index f956de3e0a6fce74f63feb2c41a1d07b7a441ec4..c801562dbc1bc9ab11c74929ef422aff7629dcb5 100644 GIT binary patch delta 177 zcmcb_dX0_Ohmn~91VR`Y7$i6H3Ny02-?#SOWEDnbp0)QP<~Ym^SO^vfX1pm4QpWMtiq_w^Y&lF9EZ693*Ya1`)_hEMAX_RACES then + error("race count must be less then "..MAX_RACES) + end + local rarr=self:allocate("race_array",'uint16_t',MAX_RACES) + local _,rarr_offset=df.sizeof(rarr) + self:set_marker_dword("racepointer",rarr_offset) + self:set_races(rarr) + self:set_marker_dword("racecount",#self.race_data) + local safe_loc=self:allocate("safe_loc",'uint32_t',1) + local _1,safe_loc_offset=df.sizeof(safe_loc) + self:set_marker_dword("safeloc1",safe_loc_offset) + self:set_marker_dword("safeloc2",safe_loc_offset) + local addr=self:move_to_df() + self:patchCalls(addr) + self.installed=true + end +return _ENV \ No newline at end of file diff --git a/plugins/lua/dfusion/friendship.o b/plugins/lua/dfusion/friendship.o new file mode 100644 index 0000000000000000000000000000000000000000..c801562dbc1bc9ab11c74929ef422aff7629dcb5 GIT binary patch literal 854 zcmeZaWM%+?5JmI3a0tG+rTticRPp<-2Hyv+Iu@eM4F|GH&Y3hXYaMV#5$~(mYI_Z_29q%3=HXvX^Gh|0jPLZZb3;>4g&)x zkPi%c1~!JG)O2T%WIVEn3rHj%S;Pq>l8z!00OXY;i?{}RGBDJmh`0bn+L1*ZfgFZl zxJX)JCeSqu4C~<{$@#ejiAAXly>JnbJPQ!_p@@hAd6VHHIr;eohCtp7xJYVVN`5ww zw-Q+-Ei*4MXB%7u$Y4+b;vFa=MnK*nxCnBp1cewgBPd;>0^}6Q1e9V1DMSOvsS%X+ uv8izYisvR4WycpKCZ`tUXXcfp79j+Z^GoweAl%}_wA7sZWJ4655d#3LE~Ebd literal 0 HcmV?d00001 diff --git a/plugins/lua/dfusion/srcs/compile.bat b/plugins/lua/dfusion/srcs/compile.bat new file mode 100644 index 000000000..e084949f4 --- /dev/null +++ b/plugins/lua/dfusion/srcs/compile.bat @@ -0,0 +1 @@ +as -anl --32 -o friendship.o friendship.asm \ No newline at end of file diff --git a/plugins/lua/dfusion/srcs/embark.asm b/plugins/lua/dfusion/srcs/embark.asm new file mode 100644 index 000000000..d2fa91081 --- /dev/null +++ b/plugins/lua/dfusion/srcs/embark.asm @@ -0,0 +1,7 @@ +.intel_syntax +mov eax , [esp+0x1C] # loop counter +mark_caste: +movsx ecx, word ptr[eax*2+0xdeadbeef] +mark_race: +movzx eax,word ptr [eax*2+0xDEADBEEF] +ret diff --git a/plugins/lua/dfusion/srcs/friendship.asm b/plugins/lua/dfusion/srcs/friendship.asm new file mode 100644 index 000000000..b649e38de --- /dev/null +++ b/plugins/lua/dfusion/srcs/friendship.asm @@ -0,0 +1,106 @@ +.intel_syntax +push eax +mov eax,[esp+0x04] +push ebx +pushfd +mov eax,[eax] # get a byte after the call this procedure to analyze what register holds cr ptr +jmptbl: +cmp al,0x81 +jz regC +cmp al,0x82 +jz regD +cmp al,0x83 +jz regB +cmp al,0x85 +jz regBP +cmp al,0x86 +jz regESI +cmp al,0x87 +jz regEDI +cmp al,0x88 +jz regA +cmp al,0x8A +jz regD +cmp al,0x8B +jz regB +cmp al,0x8D +jz regBP +cmp al,0x8E +jz regESI +cmp al,0x8F +jz regEDI +cmp al,0x90 +jz regA +cmp al,0x91 +jz regC +cmp al,0x93 +jz regB +cmp al,0x95 +jz regBP +cmp al,0x96 +jz regESI +cmp al,0x97 +jz regEDI +jmp fail +regA: +mov eax, [esp+0x8] +mov eax, [eax+0x8c] +jmp compare +regC: +mov eax, [ecx+0x8c] +jmp compare +regB: +mov eax, [ebx+0x8c] +jmp compare +regD: +mov eax, [edx+0x8c] +jmp compare +regBP: +mov eax, [ebp+0x8c] +jmp compare +regESI: +mov eax, [esi+0x8c] +jmp compare +regEDI: +mov eax, [edi+0x8c] +#jmp compare +compare: +push ecx +mark_racepointer: +mov ebx,0xDEADBEEF #write a pointer to the list of allowed races +mark_racecount: +mov ecx,0xDEADBEEF #write a number of allowed races +loop1: +cmp word[ebx+ecx*2],ax +jz endok +dec ecx +cmp ecx ,-1 +jnz loop1 +pop ecx +popfd +jmp fail +endok: +pop ecx +popfd +cmp eax,eax +jmp endfinal +fail: + +xor ebx,ebx +xor eax,eax +inc eax +cmp eax,ebx +endfinal: + +pop ebx +pop eax +mark_safeloc1: +mov [0xDEADBEEF],eax #write a pointer to safe location (usually after this) +pop eax +pushfd +inc eax #skip one instruction +popfd +push eax +mark_safeloc2: +mov eax,[0xDEADBEEF] #write a pointer to safe location (same as above) +ret From 33f674eee2ce40b5528b5ef6b4f4681867299829 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 11 Nov 2012 12:33:54 +0200 Subject: [PATCH 041/158] Removed dfusion lua files. Updated plugins. --- plugins/Dfusion/CMakeLists.txt | 3 - plugins/Dfusion/luafiles/adv_tools/plugin.lua | 3 - plugins/Dfusion/luafiles/common.lua | 514 ------------------ plugins/Dfusion/luafiles/embark/build.bat | 1 - plugins/Dfusion/luafiles/embark/embark.asm | 7 - plugins/Dfusion/luafiles/embark/embark.o | Bin 369 -> 0 bytes plugins/Dfusion/luafiles/embark/init.lua | 95 ---- plugins/Dfusion/luafiles/embark/plugin.lua | 5 - plugins/Dfusion/luafiles/embark/races.txt | 9 - .../Dfusion/luafiles/friendship/compile.bat | 1 - .../luafiles/friendship/friendship.asm | 106 ---- .../Dfusion/luafiles/friendship/friendship.o | Bin 854 -> 0 bytes plugins/Dfusion/luafiles/friendship/init.lua | 45 -- .../Dfusion/luafiles/friendship/install.lua | 35 -- plugins/Dfusion/luafiles/friendship/patch.lua | 57 -- .../Dfusion/luafiles/friendship/plugin.lua | 18 - plugins/Dfusion/luafiles/friendship/races.txt | 8 - .../luafiles/friendship_civ/compile.bat | 1 - .../luafiles/friendship_civ/friendship_c.asm | 41 -- .../luafiles/friendship_civ/friendship_c.o | Bin 462 -> 0 bytes .../Dfusion/luafiles/friendship_civ/init.lua | 89 --- .../luafiles/friendship_civ/plugin.lua | 57 -- plugins/Dfusion/luafiles/init.lua | 92 ---- plugins/Dfusion/luafiles/migrants/compile.bat | 1 - plugins/Dfusion/luafiles/migrants/init.lua | 62 --- .../Dfusion/luafiles/migrants/migrants.asm | 20 - plugins/Dfusion/luafiles/migrants/migrants.o | Bin 336 -> 0 bytes plugins/Dfusion/luafiles/migrants/plugin.lua | 5 - plugins/Dfusion/luafiles/migrants/races.txt | 29 - plugins/Dfusion/luafiles/offsets/plugin.lua | 2 - plugins/Dfusion/luafiles/offsets_misc.lua | 48 -- .../Dfusion/luafiles/simple_embark/plugin.lua | 23 - plugins/Dfusion/luafiles/tools/init.lua | 511 ----------------- plugins/Dfusion/luafiles/tools/plugin.lua | 8 - plugins/Dfusion/luafiles/utils.lua | 1 - plugins/lua/dfusion/embark.lua | 92 ++-- plugins/lua/dfusion/friendship.lua | 5 +- 37 files changed, 36 insertions(+), 1958 deletions(-) delete mode 100644 plugins/Dfusion/luafiles/adv_tools/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/common.lua delete mode 100644 plugins/Dfusion/luafiles/embark/build.bat delete mode 100644 plugins/Dfusion/luafiles/embark/embark.asm delete mode 100644 plugins/Dfusion/luafiles/embark/embark.o delete mode 100644 plugins/Dfusion/luafiles/embark/init.lua delete mode 100644 plugins/Dfusion/luafiles/embark/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/embark/races.txt delete mode 100644 plugins/Dfusion/luafiles/friendship/compile.bat delete mode 100644 plugins/Dfusion/luafiles/friendship/friendship.asm delete mode 100644 plugins/Dfusion/luafiles/friendship/friendship.o delete mode 100644 plugins/Dfusion/luafiles/friendship/init.lua delete mode 100644 plugins/Dfusion/luafiles/friendship/install.lua delete mode 100644 plugins/Dfusion/luafiles/friendship/patch.lua delete mode 100644 plugins/Dfusion/luafiles/friendship/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/friendship/races.txt delete mode 100644 plugins/Dfusion/luafiles/friendship_civ/compile.bat delete mode 100644 plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm delete mode 100644 plugins/Dfusion/luafiles/friendship_civ/friendship_c.o delete mode 100644 plugins/Dfusion/luafiles/friendship_civ/init.lua delete mode 100644 plugins/Dfusion/luafiles/friendship_civ/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/init.lua delete mode 100644 plugins/Dfusion/luafiles/migrants/compile.bat delete mode 100644 plugins/Dfusion/luafiles/migrants/init.lua delete mode 100644 plugins/Dfusion/luafiles/migrants/migrants.asm delete mode 100644 plugins/Dfusion/luafiles/migrants/migrants.o delete mode 100644 plugins/Dfusion/luafiles/migrants/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/migrants/races.txt delete mode 100644 plugins/Dfusion/luafiles/offsets/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/offsets_misc.lua delete mode 100644 plugins/Dfusion/luafiles/simple_embark/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/tools/init.lua delete mode 100644 plugins/Dfusion/luafiles/tools/plugin.lua delete mode 100644 plugins/Dfusion/luafiles/utils.lua diff --git a/plugins/Dfusion/CMakeLists.txt b/plugins/Dfusion/CMakeLists.txt index 51f2e3bee..6cfe9eb40 100644 --- a/plugins/Dfusion/CMakeLists.txt +++ b/plugins/Dfusion/CMakeLists.txt @@ -9,6 +9,3 @@ set( FILE(GLOB DFUSION_HS include/*) SET_SOURCE_FILES_PROPERTIES( ${DFUSION_HS} PROPERTIES HEADER_FILE_ONLY TRUE ) DFHACK_PLUGIN(dfusion ${DFUSION_CPPS_ALL} ${DFUSION_HS} LINK_LIBRARIES lua dfhack-tinythread) - -# installs into DF root -install(DIRECTORY luafiles/ DESTINATION dfusion) \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/adv_tools/plugin.lua b/plugins/Dfusion/luafiles/adv_tools/plugin.lua deleted file mode 100644 index cdd81e06f..000000000 --- a/plugins/Dfusion/luafiles/adv_tools/plugin.lua +++ /dev/null @@ -1,3 +0,0 @@ -if not(FILE) then - adv_tools.menu:display() -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua deleted file mode 100644 index bdf3a2bc8..000000000 --- a/plugins/Dfusion/luafiles/common.lua +++ /dev/null @@ -1,514 +0,0 @@ -dofile("dfusion/offsets_misc.lua") -STD_STRING=0 -DWORD=1 -WORD=2 -BYTE=3 -QWORD=4 -DOUBLE=5 -FLOAT=6 - -getline=function (inp) -return dfhack.lineedit(inp or "") -end -io.stdin=nil - -function printd(...) - if DEBUG then - print(...) - end -end -function GetTextRegion() - if __TEXT ~=nil then --Chache this, not going to change. - return __TEXT - end - - ranges__=Process.getMemRanges() - --print("Ranges:"..#ranges__) - for k,v in pairs(ranges__) do - for k2,v2 in pairs(v) do - --print(string.format("%d %s->%s",k,tostring(k2),tostring(v2))) - end - --local num - --flgs="" - --if(v["read"])then flgs=flgs..'r' end - --if(v["write"])then flgs=flgs..'w' end - --if(v["execute"]) then flgs=flgs..'e' end - --if num>=100 then - --print(string.format("%d %x->%x %s %s",k,v["start"],v["end"],v.name or "",flgs)) - --end - local pos=string.find(v.name,"Dwarf Fortress.exe") or string.find(v.name,"libs/Dwarf_Fortress") - if(pos~=nil) and v["execute"] then - __TEXT=v; - return v; - end - end - error(".Text region not found!") -end -function UpdateRanges() - ranges__=Process.getMemRanges() -end -function GetRegionIn(pos) - ranges__=ranges__ or Process.getMemRanges() - for k,v in pairs(ranges__) do - if pos>=v.start and pos%s",k,tostring(k2),tostring(v2))) - --end - --local num - --num=0 - --if(v["read"])then num=num+1 end - --if(v["write"])then num=num+10 end - --if(v["execute"]) then num=num+100 end - --print(string.format("%d %x->%x %s %x",k,v["start"],v["end"],v.name,pos)) - if pos>=v.start then --This is a hack to counter .text region suddenly shrinking. - if cr~=nil then - if v.start < cr.start then -- find region that start is closest - cr=v - end - else - cr=v - end - end - end - return cr -end -function ValidOffset(pos) - ranges__=ranges__ or Process.getMemRanges() - return GetRegionIn(pos)~=nil -end -function unlockDF() - local reg=GetTextRegion() - reg["write"]=true - Process.setPermisions(reg,reg) -end -function lockDF() - local reg=GetTextRegion() - reg["write"]=false - Process.setPermisions(reg,reg) -end -function SetExecute(pos) - UpdateRanges() - local reg=GetRegionIn(pos) - reg.execute=true - reg["write"]=true - Process.setPermisions(reg,reg) -- TODO maybe make a page with only execute permisions or sth -end --- engine bindings -engine=engine or {} ---[=[ use default peek/pokes for now -engine.peekd=Process.readDWord -engine.poked=Process.writeDWord -engine.peekb=Process.readByte -engine.pokeb=Process.writeByte -engine.peekw=Process.readWord -engine.pokew=Process.writeWord -engine.peekstr_stl=Process.readSTLString -engine.pokestr_stl=Process.writeSTLString -engine.peekstr=Process.readCString ---engine.pokestr=Process.readCString -engine.peekarb=Process.read -engine.pokearb=Process.write ---]=] - -function engine.peek(offset,rtype) - if type(rtype)=="table" then - if rtype.off ==nil then - return engine.peekpattern(offset,rtype) - else - return engine.peek(rtype.off+offset,rtype.rtype) - end - end - if rtype==STD_STRING then - return engine.peekstr2(offset) - elseif rtype==DWORD then - return engine.peekd(offset) - elseif rtype==WORD then - return engine.peekw(offset) - elseif rtype==BYTE then - return engine.peekb(offset) - elseif rtype==QWORD then - return engine.peekq(offset) - elseif rtype==FLOAT then - return engine.peekfloat(offset) - elseif rtype==DOUBLE then - return engine.peekdouble(offset) - else - error("Invalid peek type") - return - end -end -function engine.poke(offset,rtype,val) - if type(rtype)=="table" then - if rtype.off ==nil then - return engine.pokepattern(offset,rtype,val) - else - return engine.poke(rtype.off+offset,rtype.rtype,val) - end - end - if rtype==STD_STRING then - return engine.pokestr2(offset,val) - elseif rtype==DWORD then - return engine.poked(offset,val) - elseif rtype==WORD then - return engine.pokew(offset,val) - elseif rtype==BYTE then - return engine.pokeb(offset,val) - elseif rtype==QWORD then - return engine.pokeq(offset,val) - elseif rtype==FLOAT then - return engine.pokefloat(offset,val) - elseif rtype==DOUBLE then - return engine.pokedouble(offset,val) - else - error("Invalid poke type:"..tostring(rtype)) - return - end -end -function engine.sizeof(rtype) - if rtype==STD_STRING then - error("String has no constant size") - return - elseif rtype==DWORD then - return 4; - elseif rtype==WORD then - return 2; - elseif rtype==BYTE then - return 1; - else - error("Invalid sizeof type") - return - end -end -function engine.peekpattern(offset,pattern) - local ret={} - for k,v in pairs(pattern) do - --print("k:"..k.." v:"..type(v)) - if type(v)=="table" then - ret[k]=engine.peek(offset+v.off,v.rtype) - --print(k.." peeked:"..offset+v.off) - else - ret[k]=v - end - end - ret.__offset=offset - return ret -end -function engine.pokepattern(offset,pattern,val) - for k,v in pairs(pattern) do - --print("k:"..k.." v:"..type(v)) - if type(v)=="table" then - engine.poke(offset+v.off,v.rtype,val[k]) - end - end -end - -function engine.LoadModData(file) - local T2={} - T2.symbols={} - T2.data,T2.size=engine.loadobj(file) - data,modsize=engine.loadobj(file) - local T=engine.loadobjsymbols(file) - for k,v in pairs(T) do - - if v.pos~=0 then - T2.symbols[v.name]=v.pos - end - end - return T2 -end -function engine.FindMarkerCall(moddata,name) - if moddata.symbols[name] ~=nil then - return moddata.symbols[name]+1 - end -end -function engine.FindMarker(moddata,name) - if moddata.symbols[name] ~=nil then - return engine.findmarker(0xDEADBEEF,moddata.data,moddata.size,moddata.symbols[name]) - end -end -function engine.installMod(file,name,bonussize) - local T=engine.LoadModData(file) - local modpos,modsize=engine.loadmod(file,name,bonussize) - T.pos=modpos - return T -end - - - -function PrintPattern(loadedpattern) - for k,v in pairs(loadedpattern) do - if type(v)== "string" then - print(k.." "..v) - else - print(string.format("%s %d inhex:%x",k,v,v)) - end - end -end - -function printPattern(pattern) - local i=0; - local names={} - names[STD_STRING]="std_string (STD_STRING)" - names[DWORD]= "Double word (DWORD)" - names[WORD]= "Word (WORD)" - names[STD_STRING]="Byte (BYTE)" - ret={} - for k,v in pairs(pattern) do - if type(v)=="table" and v.off~=nil then - - if names[v.rtype]~=nil then - lname=names[v.rtype] - else - if type(v.rtype)=="table" then - lname="Table (prob subpattern)" - else - lname="Other" - end - end - print(string.format("%d. %s is %s with offset %x",i,k,lname,v.off)) - table.insert(ret,k) - else - print(string.format("%d. %s",i,k)) - end - i=i+1 - end - return ret; -end -function editPattern(offset,pattern,name) - if type(pattern[name].rtype)=="table" then - if pattern[name].rtype.setval~=nil then - print(string.format("%x",offset+pattern[name].off)) - local t=engine.peek(offset+pattern[name].off,pattern[name].rtype) - print("Value is now:"..t:getval()) - print("Enter new value:") - val=io.stdin:read() - t:setval(val) - else - ModPattern(offset+pattern[name].off,pattern[name].rtype) - end - return - end - val=engine.peek(offset,pattern[name]) - print("Value is now:"..val) - print("Enter new value:") - if pattern[name].rtype==STD_STRING then - val=io.stdin:read() - else - val=tonumber(io.stdin:read()) - end - engine.poke(offset,pattern[name],val) -end -function ModPattern(itemoffset,pattern) - print("Select what to edit:") - nm=printPattern(pattern) - q=tonumber(io.stdin:read()) - if q~=nil and q<#nm then - editPattern(itemoffset,pattern,nm[q+1]) - end -end - -function findVectors() - if __VECTORS ~=nil then --chache - return __VECTORS - end - local text=GetTextRegion() - local h=hexsearch(text.start,text["end"],0x8b,ANYBYTE,ANYDWORD,0x8b,ANYBYTE,ANYDWORD,0x2b) - local pos=h:findall() - local T={} - for k,v in pairs(pos) do - local loc1,loc2 - loc1=engine.peekd(v+2) - loc2=engine.peekd(v+8) - --print(string.format("%x - %x=%x",loc1,loc2,loc1-loc2)) - if(loc1-loc2==4) then - if T[loc1-4]~=nil then - T[loc1-4]=T[loc1-4]+1 - else - T[loc1-4]=1 - end - end - end - __VECTORS=T - return T -end - -function GetRaceToken(p) --actually gets token... - local vec=df.global.world.raws.creatures.all - return vec[p].creature_id -end -function BuildNameTable() - local rtbl={} - local vec=df.global.world.raws.creatures.all - --print(string.format("Vector start:%x",vec.st)) - --print(string.format("Vector end:%x",vec.en)) - --print("Creature count:"..vec.size) - for k=0,#vec-1 do - local name=vec[k].creature_id - --print(k.." "..tostring(name)) - rtbl[name]=k - end - return rtbl; -end -function BuildMaterialTable() - local rtbl={} - local vec=engine.peek(offsets.getEx('Materials'),ptr_vector) - --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 - end - return rtbl; -end -function BuildWordTables() - local names={} - local rnames={} - local vector=engine.peek(offsets.getEx('WordVec'),ptr_vector) -for i =0,vector:size()-1 do - local off=vector:getval(i) - local n=engine.peekstr(off) - names[i]=n - rnames[n]=i -end - return names,rnames -end -function ParseScript(file) - - io.input(file) - f="" - first=0 - nobraces=0 - function updFunction() - if f~="" then - first=0 - if nobraces==0 then - f=f.."}" - end - nobraces=0 - print("Doing:"..f) - assert(loadstring(f))() - - f="" - end - end - while true do - - local line = io.read("*line") - if line == nil then break end - if string.sub(line,1,2)==">>" then - updFunction() - if string.find(line,"%b()") then - f=string.sub(line,3) - nobraces=1 - else - f=string.sub(line,3).."{" - end - --print(string.sub(line,3)..) - else - if first~=0 then - f=f.."," - else - first=1 - end - f=f..string.format('%q',line) - - end - - end - updFunction() -end -function ParseNames(path) - local ret={} - local ff=io.open(path) - for n in ff:lines() do - table.insert(ret,n) - end - return ret -end -function getSelectedUnit() - if df.global.ui.main.mode~=23 then - return nil - end - local unit_indx=df.global.ui_selected_unit - if unit_indx<#df.global.world.units.active-1 then - return df.global.world.units.active[unit_indx] - else - return nil - end -end -function getxyz() -- this will return pointers x,y and z coordinates. - local x=df.global.cursor.x - local y=df.global.cursor.y - local z=df.global.cursor.z - return x,y,z -- return the coords -end -function getCreatureAtPos(x,y,z) -- gets the creature index @ x,y,z coord - --local x,y,z=getxyz() --get 'X' coords - local vector=df.global.world.units.all -- load all creatures - for i = 0, #vector-1 do -- look into all creatures offsets - local curpos=vector[i].pos --get its coordinates - local cx=curpos.x - local cy=curpos.y - local cz=curpos.z - if cx==x and cy==y and cz==z then --compare them - return vector[i] --return index - end - end - --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 df.general_ref_is_nemesisst:is_instance(v) then - return v.nemesis_id - end - end -end -function getNemesis(unit) - local id=getNemesisId(unit) - if id then - return df.nemesis_record.find(id) - end -end -function Allocate(size) - local ptr=engine.getmod('General_Space') - if ptr==nil then - ptr=engine.newmod("General_Space",4096) -- some time later maybe make some more space - engine.poked(ptr,4) - end - - local curptr=engine.peekd(ptr) - curptr=curptr+size - engine.poked(ptr,curptr) - return curptr-size+ptr -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/embark/build.bat b/plugins/Dfusion/luafiles/embark/build.bat deleted file mode 100644 index 51eeb8140..000000000 --- a/plugins/Dfusion/luafiles/embark/build.bat +++ /dev/null @@ -1 +0,0 @@ -as -a --32 -o embark.o embark.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/embark/embark.asm b/plugins/Dfusion/luafiles/embark/embark.asm deleted file mode 100644 index d2fa91081..000000000 --- a/plugins/Dfusion/luafiles/embark/embark.asm +++ /dev/null @@ -1,7 +0,0 @@ -.intel_syntax -mov eax , [esp+0x1C] # loop counter -mark_caste: -movsx ecx, word ptr[eax*2+0xdeadbeef] -mark_race: -movzx eax,word ptr [eax*2+0xDEADBEEF] -ret diff --git a/plugins/Dfusion/luafiles/embark/embark.o b/plugins/Dfusion/luafiles/embark/embark.o deleted file mode 100644 index 87f5bbd68f5c8d0aaf6f81485f653a440145a952..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 369 zcmeZaWM%+?B|yvtX0bBrm84dbfY}g20!Z~B@j*-l27?5>l*E!mG;wsU1B1ZMAX_RACES then - error("caste and race count must be less then "..MAX_RACES) - end - if stoff==nil then - error("address for start_dwarf_count not found!") - end - local _,race_id_offset=df.sizeof(df.global.ui:_field("race_id")) - print(string.format("start=%08x",stoff)) - local needle={0x0f,0xb7,0x0d} --movzx eax,dword ptr [race_id] - local tmp_table=dfu.dwordToTable(race_id_offset) - for k,v in ipairs(tmp_table) do - table.insert(needle,v) - end - - local mem=ms.get_code_segment() - print(mem.uint8_t:addr2idx(stoff)) - print(mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff))) - local _,trg_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(stoff),nil)--maybe endoff=stoff+bignumber - if trg_offset==nil then - error("address for race_load not found") - end - local call_data={0x90,0x90} - local _,data_offset=df.sizeof(self.data) - dfu.concatTables(call_data,dfu.makeCall(trg_offset+2,data_offset)) - self.call_patch=dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} - needle={0x83,0xc8,0xff} -- or eax, 0xFF - local _,caste_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(trg_offset),nil) - if caste_offset==nil or caste_offset-stoff>1000 then - error("Caste change code not found or found too far!") - end - - self.disable_castes=dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} - self.disable_castes:apply() - self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} - self.dwarfcount:apply() - local caste_array=self:allocate("caste_array","uint16_t",#self.race_caste_data) - local race_array=self:allocate("race_array","uint16_t",#self.race_caste_data) - self:setEmbarkParty(self.race_caste_data) - for k,v in ipairs(self.race_caste_data) do - caste_array[k-1]=v[2] - race_array[k-1]=v[1] - end - local race_array_off,caste_array_off - local _ - _,race_array_off=df.sizeof(race_array) - _,caste_array_off=df.sizeof(caste_array) - self:set_marker_dword("race",caste_array_off) --hehe... mixed them up i guess... - self:set_marker_dword("caste",race_array_off) - - self:move_to_df() - self.call_patch:apply() - self.installed=true - end - function CustomEmbark:setEmbarkParty(racesAndCastes) - self.race_caste_data=racesAndCastes - if self.dwarfcount== nil then - self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} - self.dwarfcount:apply() - else - self.dwarfcount:repatch(dfu.dwordToTable(#self.race_caste_data)) - end - - end - function CustomEmbark:status() - if self.installed then - return "valid, installed" - else - return "valid, not installed" - end - end - function CustomEmbark:uninstall() - if self.installed then - self.call_patch:remove() - self.disable_castes:remove() - self.dwarfcount:remove() - end - end -else - CustomEmbark.class_status="invalid, os not supported" -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/embark/plugin.lua b/plugins/Dfusion/luafiles/embark/plugin.lua deleted file mode 100644 index 039000656..000000000 --- a/plugins/Dfusion/luafiles/embark/plugin.lua +++ /dev/null @@ -1,5 +0,0 @@ - -if not(FILE)then - names=ParseNames("dfusion/embark/races.txt")--io.open("plugins/embark/races.txt"):lines() - embark(names) -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/embark/races.txt b/plugins/Dfusion/luafiles/embark/races.txt deleted file mode 100644 index 376928866..000000000 --- a/plugins/Dfusion/luafiles/embark/races.txt +++ /dev/null @@ -1,9 +0,0 @@ -ANT_MAN:0 -ANT_MAN:0 -ANT_MAN:0 -ANT_MAN:1 -ANT_MAN:1 -ANT_MAN:0 -ANT_MAN:0 -ANT_MAN:2 -ANT_MAN:3 \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship/compile.bat b/plugins/Dfusion/luafiles/friendship/compile.bat deleted file mode 100644 index e084949f4..000000000 --- a/plugins/Dfusion/luafiles/friendship/compile.bat +++ /dev/null @@ -1 +0,0 @@ -as -anl --32 -o friendship.o friendship.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship/friendship.asm b/plugins/Dfusion/luafiles/friendship/friendship.asm deleted file mode 100644 index b649e38de..000000000 --- a/plugins/Dfusion/luafiles/friendship/friendship.asm +++ /dev/null @@ -1,106 +0,0 @@ -.intel_syntax -push eax -mov eax,[esp+0x04] -push ebx -pushfd -mov eax,[eax] # get a byte after the call this procedure to analyze what register holds cr ptr -jmptbl: -cmp al,0x81 -jz regC -cmp al,0x82 -jz regD -cmp al,0x83 -jz regB -cmp al,0x85 -jz regBP -cmp al,0x86 -jz regESI -cmp al,0x87 -jz regEDI -cmp al,0x88 -jz regA -cmp al,0x8A -jz regD -cmp al,0x8B -jz regB -cmp al,0x8D -jz regBP -cmp al,0x8E -jz regESI -cmp al,0x8F -jz regEDI -cmp al,0x90 -jz regA -cmp al,0x91 -jz regC -cmp al,0x93 -jz regB -cmp al,0x95 -jz regBP -cmp al,0x96 -jz regESI -cmp al,0x97 -jz regEDI -jmp fail -regA: -mov eax, [esp+0x8] -mov eax, [eax+0x8c] -jmp compare -regC: -mov eax, [ecx+0x8c] -jmp compare -regB: -mov eax, [ebx+0x8c] -jmp compare -regD: -mov eax, [edx+0x8c] -jmp compare -regBP: -mov eax, [ebp+0x8c] -jmp compare -regESI: -mov eax, [esi+0x8c] -jmp compare -regEDI: -mov eax, [edi+0x8c] -#jmp compare -compare: -push ecx -mark_racepointer: -mov ebx,0xDEADBEEF #write a pointer to the list of allowed races -mark_racecount: -mov ecx,0xDEADBEEF #write a number of allowed races -loop1: -cmp word[ebx+ecx*2],ax -jz endok -dec ecx -cmp ecx ,-1 -jnz loop1 -pop ecx -popfd -jmp fail -endok: -pop ecx -popfd -cmp eax,eax -jmp endfinal -fail: - -xor ebx,ebx -xor eax,eax -inc eax -cmp eax,ebx -endfinal: - -pop ebx -pop eax -mark_safeloc1: -mov [0xDEADBEEF],eax #write a pointer to safe location (usually after this) -pop eax -pushfd -inc eax #skip one instruction -popfd -push eax -mark_safeloc2: -mov eax,[0xDEADBEEF] #write a pointer to safe location (same as above) -ret diff --git a/plugins/Dfusion/luafiles/friendship/friendship.o b/plugins/Dfusion/luafiles/friendship/friendship.o deleted file mode 100644 index c801562dbc1bc9ab11c74929ef422aff7629dcb5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 854 zcmeZaWM%+?5JmI3a0tG+rTticRPp<-2Hyv+Iu@eM4F|GH&Y3hXYaMV#5$~(mYI_Z_29q%3=HXvX^Gh|0jPLZZb3;>4g&)x zkPi%c1~!JG)O2T%WIVEn3rHj%S;Pq>l8z!00OXY;i?{}RGBDJmh`0bn+L1*ZfgFZl zxJX)JCeSqu4C~<{$@#ejiAAXly>JnbJPQ!_p@@hAd6VHHIr;eohCtp7xJYVVN`5ww zw-Q+-Ei*4MXB%7u$Y4+b;vFa=MnK*nxCnBp1cewgBPd;>0^}6Q1e9V1DMSOvsS%X+ uv8izYisvR4WycpKCZ`tUXXcfp79j+Z^GoweAl%}_wA7sZWJ4655d#3LE~Ebd diff --git a/plugins/Dfusion/luafiles/friendship/init.lua b/plugins/Dfusion/luafiles/friendship/init.lua deleted file mode 100644 index 0fc3219e4..000000000 --- a/plugins/Dfusion/luafiles/friendship/init.lua +++ /dev/null @@ -1,45 +0,0 @@ -function analyzeF(off) - pos=offsets.find(off,0x39,ANYBYTE,0x8c,00,00,00) - print(string.format("Compare at:%x",pos)) - if pos ==0 then - return 0 - end - if(pos-off>0x100) then - print(string.format("Distance to cmp:%x",pos-off)) - pos =offsets.find(off,CALL) - print(string.format("Distance to call:%x",pos-off)) - return 0 - --return analyzeF(pos) - else - return pos - end -end -function minEx(list) - local imin=list[1] - for _,v in ipairs(list) do - if imin> v and v~=0 then - imin=v - end - end - return imin -end -function signDword(dw) - if(dw>0xFFFFFFFF) then - return dw-0xFFFFFFFF - end - return dw -end ---[[ - Warning: not all mov's are acounted for. Found one: mov EAX,WORD PTR[EBP+1EF4] WTF?? - Two more compares are missing. There are calls instead (same function) -]]-- - -friendship_in={} -dofile("dfusion/friendship/install.lua") -dofile("dfusion/friendship/patch.lua") - -function friendship(names) - friendship_in.install(names) - friendship_in.patch() -end - diff --git a/plugins/Dfusion/luafiles/friendship/install.lua b/plugins/Dfusion/luafiles/friendship/install.lua deleted file mode 100644 index 251d2fb3a..000000000 --- a/plugins/Dfusion/luafiles/friendship/install.lua +++ /dev/null @@ -1,35 +0,0 @@ - -function friendship_in.install(names) -RaceTable=RaceTable or BuildNameTable() -mypos=engine.getmod("Friendship") -if mypos then - modpos=mypos - _,modsize=engine.loadobj("dfusion/friendship/friendship.o") - _=nil -else - modpos,modsize=engine.loadmod("dfusion/friendship/friendship.o","Friendship",1024) - print(string.format("Loaded module @:%x",modpos)) -end -count=0 -for _,v in pairs(names) do - if RaceTable[v] == nil then - --print("Failure, "..v.." not found!") - error("Failure, "..v.." not found!") - --break --maybe some indication of failure? and cleanup? - end - engine.pokew(modpos+modsize+count*2+4+2,RaceTable[v]) -- for some reason it compiled strangely - -- cmp word[ebx+ecx*2],ax -> cmp word[ebx+ecx*2+2],ax - count = count + 1 -end -engine.poked(modpos+0x8f,modpos+modsize+4) -- set ptr to creatures -engine.poked(modpos+0x94,count) -- set count of creatures -engine.poked(modpos+0xb9,modpos+modsize) -- set safe location -engine.poked(modpos+0xc3,modpos+modsize) -- set safe location -SetExecute(modpos) -end -function pokeCall(off) - engine.pokeb(off,0xe8) - b=engine.peekb(off+1) - engine.poked(off+1,modpos-off-5) - engine.pokeb(off+5,b) -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship/patch.lua b/plugins/Dfusion/luafiles/friendship/patch.lua deleted file mode 100644 index 247766db1..000000000 --- a/plugins/Dfusion/luafiles/friendship/patch.lua +++ /dev/null @@ -1,57 +0,0 @@ -function friendship_in.patch() - UpdateRanges() - pos=GetTextRegion().start - local _,crace=df.sizeof(df.global.ui:_field("race_id")) - hits={} - i=1 - repeat - --todo make something better/smarter... - pos1=offsets.find(pos+7,0x0f,0xBF,ANYBYTE,DWORD_,crace) -- movsx - pos2=offsets.find(pos+7,0x66,0xa1,DWORD_,crace) -- mov ax,[ptr] - pos3=offsets.find(pos+7,0xa1,DWORD_,crace) -- mov eax,[ptr] - pos4=offsets.find(pos+7,0x66,0x8b,ANYBYTE,DWORD_,crace) -- mov ANYREG,[ptr] - --pos5=offsets.find(pos+7,0x66,0x8b,0x15,DWORD_,crace) -- mov dx,[ptr] - pos=minEx{pos1,pos2,pos3,pos4} - if pos ~=0 then - hits[i]=pos - i=i+1 - print(string.format("Found at %x",pos)) - end - until pos==0 - print("=======================================") - for _,p in pairs(hits) do - myp=p - repeat - - --print(string.format("Analyzing %x...",p)) - --TODO read offset from memory.xml - pos1=offsets.find(myp,0x39,ANYBYTE,0x8c,00,00,00) -- compare [reg+08c] (creature race) with any reg - pos2=offsets.find(myp,0x3b,ANYBYTE,0x8c,00,00,00) -- compare any reg with [reg+08c] (creature race) - pos=minEx{pos1,pos2} - if pos ~=0 then - - if(pos-p>250) then - --this here does not work yet... - --[[pos =offsets.find(p,CALL) - print(string.format("Distance to call:%x",pos-p)) - print(string.format("Call: %x",signDword(engine.peekd(pos+1)+pos))) - pos=analyzeF(signDword(signDword(engine.peekd(pos+1)+pos))) - - print(string.format("Cmp @:%x",pos))]]-- - print(string.format("skipping %x... Cmp too far away (dist=%i)",p,pos-p)) - else - --print(string.format("Found at %x, simple compare",pos)) - --print(string.format("Distance =%x",pos-p)) - --patch compares - - pokeCall(pos) - end - else - break - end - myp=myp+pos+6 - if myp-p >250 then break end - until false - - end -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship/plugin.lua b/plugins/Dfusion/luafiles/friendship/plugin.lua deleted file mode 100644 index 695ddf05e..000000000 --- a/plugins/Dfusion/luafiles/friendship/plugin.lua +++ /dev/null @@ -1,18 +0,0 @@ -if not(FILE) then - --sanity test - --print("race num:"..engine.peekw(offsets.getEx("CurrentRace"))) - --print(string.format("%x vs %x",offsets.getEx("CurrentRace"),VersionInfo.getGroup("Creatures"):getAddress("current_race"))) - print("Race num:"..df.global.ui.race_id) - print("Your current race is:"..GetRaceToken(df.global.ui.race_id)) - print("If this is wrong please type 'q'") - if(getline()=='q') then - return - end - -end - -if not(FILE) then - names=ParseNames("dfusion/friendship/races.txt")--io.open("plugins/friendship/races.txt"):lines() - friendship_in.install(names) - friendship_in.patch() -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship/races.txt b/plugins/Dfusion/luafiles/friendship/races.txt deleted file mode 100644 index e4ed7c5a6..000000000 --- a/plugins/Dfusion/luafiles/friendship/races.txt +++ /dev/null @@ -1,8 +0,0 @@ -DWARF -GOBLIN -ELF -HUMAN -KOBOLD -GREMLIN -TIGERMAN -ANT_MAN \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship_civ/compile.bat b/plugins/Dfusion/luafiles/friendship_civ/compile.bat deleted file mode 100644 index 64d4d4440..000000000 --- a/plugins/Dfusion/luafiles/friendship_civ/compile.bat +++ /dev/null @@ -1 +0,0 @@ -as -anl --32 -o friendship_c.o friendship_c.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm deleted file mode 100644 index b2b49ee78..000000000 --- a/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm +++ /dev/null @@ -1,41 +0,0 @@ -.intel_syntax -eaxpart: -push eax -push ecx -jmp compare -ecxpart: -push eax -push ecx -mov eax,ecx - -compare: -push ebx -mov ebx,0xDEADBEEF #write a pointer to the list of allowed civs -mov ecx,2000 #write a number of allowed civs -loop1: -cmp [ebx+ecx*4],eax -jnz endok -dec ecx -cmp ecx ,-1 -jnz loop1 - -pop ebx - -jmp fail - -endok: -pop ebx - -cmp eax,eax -jmp endfinal -fail: - -xor ecx,ecx -xor eax,eax -inc eax -cmp eax,ebx -endfinal: - -pop ecx -pop eax -ret \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship_civ/friendship_c.o b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.o deleted file mode 100644 index d85134682ac1e464b944b3e3403babe96a43a8b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 462 zcmeZaWM%+?JwVJ4X0bBrm84dbfY}hj07&&9@j*-l27?5>l*E!mG;wsU1B1Z1OTR|HW{tKy@S5H5q~QSv z%NvmqhxO7jb5fxO{rk_rkj|Kvm<QhwOUcg$@)Y4BX^ELRKn{Z%Tm+~lEi*4MM;9)F9Ficrm>EG~ ai3*TIkqIcp3{r>&kV6m@U)a=uTn_-GKtCM- diff --git a/plugins/Dfusion/luafiles/friendship_civ/init.lua b/plugins/Dfusion/luafiles/friendship_civ/init.lua deleted file mode 100644 index 5390829de..000000000 --- a/plugins/Dfusion/luafiles/friendship_civ/init.lua +++ /dev/null @@ -1,89 +0,0 @@ -friendship_civ={} -function friendship_civ.init() - friendship_civ.count=0x0f - friendship_civ.firsttime=true - local mypos=engine.getmod("Friendship_civ") - local modpos=0 - if mypos then - modpos=mypos - _,modsize=engine.loadobj("dfusion/friendship_civ/friendship_c.o") - _=nil - friendship_civ.firsttime=false - else - modpos,modsize=engine.loadmod("dfusion/friendship_civ/friendship_c.o","Friendship_civ",1024) - print(string.format("Loaded module @:%x",modpos)) - end - friendship_civ.modpos=modpos - friendship_civ.modsize=modsize -end -function friendship_civ.install(civs) - friendship_civ.init() - local count=0 - for _,v in pairs(civs) do - engine.poked(friendship_civ.modpos+friendship_civ.modsize+count*4,v) -- for some reason it compiled strangely - -- cmp word[ebx+ecx*2],ax -> cmp word[ebx+ecx*2+2],ax - count = count + 1 - end - engine.poked(friendship_civ.modpos+0x0a,friendship_civ.modpos+friendship_civ.modsize) -- set ptr to civ ids - engine.poked(friendship_civ.modpos+friendship_civ.count,count-1) -- set count of civs - SetExecute(friendship_civ.modpos) - - if(friendship_civ.firsttime) then - friendship_civ.patch() - end -end -function friendship_civ.getcivs() - if(friendship_civ.firsttime==nil)then - return nil - end - friendship_civ.init() - local count=engine.peekd(friendship_civ.modpos+friendship_civ.count)+1 - local ret={} - for i=0, count-1 do - table.insert(ret,engine.peekd(friendship_civ.modpos+friendship_civ.modsize+i*4)) - end - return ret -end -function friendship_civ.addciv(civ) --if called with nil add current civ :) - if civ==nil then - local cciv=engine.peekd(VersionInfo.getGroup("Creatures"):getAddress("current_civ")) - friendship_civ.install({cciv}) - return - end - local oldcivs=friendship_civ.getcivs() - oldcivs=oldcivs or {} - if type(civ)=="table" then - for k,v in ipairs(civ) do - table.insert(oldcivs,v) - end - else - table.insert(oldcivs,civ) - end - friendship_civ.install(oldcivs) -end -function friendship_civ.patch_call(off,iseax) - local calltrg=friendship_civ.modpos - if not iseax then - calltrg=calltrg+4 - end - engine.pokeb(off,0xe8) --this is a call - engine.poked(off+1,calltrg-off-5) --offset to call to (relative) - engine.pokeb(off+5,0x90) --nop -end -function friendship_civ.patch() - --UpdateRanges() - local civloc= VersionInfo.getGroup("Creatures"):getAddress("current_civ") - local pos1=offsets.findall(0,0x3B,0x05,DWORD_,civloc) --eax - for k,v in pairs(pos1) do print(string.format("%d %x",k,v)) end - local pos2=offsets.findall(0,0x3B,0x0D,DWORD_,civloc) --ecx - for k,v in pairs(pos2) do print(string.format("%d %x",k,v)) end - - for k,v in pairs(pos1) do - print(string.format("Patching eax compare %d: %x",k,v)) - friendship_civ.patch_call(v,true) - end - for k,v in pairs(pos2) do - print(string.format("Patching ecx compare %d: %x",k,v)) - friendship_civ.patch_call(v,false) - end -end diff --git a/plugins/Dfusion/luafiles/friendship_civ/plugin.lua b/plugins/Dfusion/luafiles/friendship_civ/plugin.lua deleted file mode 100644 index 12f334fcf..000000000 --- a/plugins/Dfusion/luafiles/friendship_civ/plugin.lua +++ /dev/null @@ -1,57 +0,0 @@ -fc_ui={} -fc_ui.menu=MakeMenu() -function fc_ui.get() - local mycivs=friendship_civ.getcivs() - if mycivs~= nil then - print(" Currently friendly civs:") - for k,v in pairs(mycivs) do - print(string.format("%d. %d",k,v)) - end - else - print(" Plugin no yet activated.") - end -end -function fc_ui.add() - print("Type in civ id to add (leave empty to add current, q cancels):") - local r - while r==nil and r~='q' do - r=io.stdin:read() - if r=="" then - r=nil - break - end - if r~='q' then r=tonumber(r) else - return - end - end - friendship_civ.addciv(r) -end -function fc_ui.remove() - local mycivs=friendship_civ.getcivs() - if mycivs~= nil then - print(" Currently friendly civs:") - for k,v in pairs(mycivs) do - print(string.format("%d. %d",k,v)) - end - else - print(" Plugin no yet activated, nothing to remove.") - return - end - print("Type in civ id to remove( q cancels):") - local r - while r==nil and r~='q' do - r=io.stdin:read() - if r~='q' then - r=tonumber(r) - if r>#mycivs then r=nil end - else - return - end - end - table.remove(mycivs,r) - friendship_civ.install(mycivs) -end -fc_ui.menu:add("Add civ",fc_ui.add) -fc_ui.menu:add("Get civs",fc_ui.get) -fc_ui.menu:add("Remove civ",fc_ui.remove) -fc_ui.menu:display() \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/init.lua b/plugins/Dfusion/luafiles/init.lua deleted file mode 100644 index c8eebcd23..000000000 --- a/plugins/Dfusion/luafiles/init.lua +++ /dev/null @@ -1,92 +0,0 @@ -function dofile(filename) --safer dofile, with traceback (very usefull) - f,perr=loadfile(filename) - if f~=nil then - return safecall(f) - else - print(perr) - end -end -function dofile_silent(filename) --safer dofile, with traceback, no file not found error - f,perr=loadfile(filename) - if f~=nil then - return safecall(f) - else - if(string.sub(perr,1,11)~="cannot open") then --ugly hack - print(perr) - end - end -end -function loadall(t1) --loads all non interactive plugin parts, so that later they could be used - for k,v in pairs(t1) do - dofile_silent("dfusion/"..v[1].."/init.lua") - end -end -function mainmenu(t1) - while true do - print("No. Name Desc") - for k,v in pairs(t1) do - print(string.format("%3d %15s %s",k,v[1],v[2])) - end - local q=dfhack.lineedit("Select plugin to run (q to quit):") - if q=='q' then return end - q=tonumber(q) - if q~=nil then - if q>=1 and q<=#t1 then - if t1[q][3]==nil then - dofile("dfusion/"..t1[q][1].."/plugin.lua") - else - t1[q][3]() - end - end - end - end -end -function RunSaved() - print("Locating saves...") - local str=df.global.world.cur_savegame.save_dir - print("Current region:"..str) - str="data/save/"..str.."/dfusion/init.lua" - print("Trying to run:"..str) - dofile_silent(str) -end -dofile("dfusion/common.lua") -dofile("dfusion/utils.lua") -dofile("dfusion/offsets_misc.lua") -dofile("dfusion/editor.lua") - -unlockDF() -plugins={} -table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"}) -table.insert(plugins,{"tools","some misc tools"}) -table.insert(plugins,{"embark","Multi race embark"}) -table.insert(plugins,{"friendship","Multi race fort enabler"}) ---[=[table.insert(plugins,{"items","A collection of item hacking tools"}) -table.insert(plugins,{"offsets","Find all offsets"}) - -table.insert(plugins,{"friendship_civ","Multi civ fort enabler"}) - - -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,{"editor","edit internals of df",EditDF}) -table.insert(plugins,{"saves","run current worlds's init.lua",RunSaved}) -table.insert(plugins,{"adv_tools","some tools for (mainly) adventurer hacking"}) -loadall(plugins) -dofile_silent("dfusion/initcustom.lua") - -local args={...} - - -local f,err=load(table.concat(args,' ')) -if f then - f() -else - dfhack.printerr(err) -end - -if not INIT then -mainmenu(plugins) -end - diff --git a/plugins/Dfusion/luafiles/migrants/compile.bat b/plugins/Dfusion/luafiles/migrants/compile.bat deleted file mode 100644 index 4d226851d..000000000 --- a/plugins/Dfusion/luafiles/migrants/compile.bat +++ /dev/null @@ -1 +0,0 @@ -as -anl --32 -o migrants.o migrants.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/migrants/init.lua b/plugins/Dfusion/luafiles/migrants/init.lua deleted file mode 100644 index 6fb315923..000000000 --- a/plugins/Dfusion/luafiles/migrants/init.lua +++ /dev/null @@ -1,62 +0,0 @@ ---install part -function migrants(names) -RaceTable=RaceTable or BuildNameTable() -mypos=engine.getmod("Migrants") -if mypos then - print("Migrant mod is running already @:"..mypos) - modpos=mypos - _,modsize=engine.loadobj("dfusion/migrants/migrants.o") - count=0 - for _,v in pairs(names) do - if RaceTable[v] == nil then - print("Failure, "..v.." not found!") - break --maybe some indication of failure? and cleanup? - end - engine.pokew(modpos+modsize+count*2+4,RaceTable[v]) - count = count + 1 - end - seedpos=modpos+modsize - engine.poked(seedpos,math.random(1234567)) -- seed the generator :) - engine.poked(modpos+0x1c,count) --max size for div - -else - modpos,modsize=engine.loadmod("dfusion/migrants/migrants.o","Migrants",400) - print(string.format("Loaded module @:%x",modpos)) - count=0 - for _,v in pairs(names) do - if RaceTable[v] == nil then - print("Failure, "..v.." not found!") - break --maybe some indication of failure? and cleanup? - end - engine.pokew(modpos+modsize+count*2+4,RaceTable[v]) - - count = count + 1 - end - - seedpos=modpos+modsize - engine.poked(modpos+0x04,seedpos) - engine.poked(modpos+0x15,seedpos) - - engine.poked(seedpos,math.random(1234567)) -- seed the generator :) - engine.poked(modpos+0x1c,count) --max size for div - - engine.poked(modpos+0x26,seedpos+4) --start of array - - --patch part - --pos=62873C+DF - -- pattern: A1,DWORD_,"CURRENTRACE",56,89,ANYBYTE,ANYBYTE,34,e8 - _,raceoff=df.sizeof(df.global.ui:_field('race_id')) - pos=offsets.find(offsets.base(),0xa1,DWORD_,raceoff,0x56,0x89,ANYBYTE,ANYBYTE,0x34,0xe8) - function pokeCall(off) - engine.pokeb(off,0xe8) - engine.poked(off+1,modpos-off-5) - end - if pos~=0 then - print(string.format("Found @:%x",pos)) - pokeCall(pos) - else - print("Not found patch location!!!") - end - end - -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/migrants/migrants.asm b/plugins/Dfusion/luafiles/migrants/migrants.asm deleted file mode 100644 index 646497665..000000000 --- a/plugins/Dfusion/luafiles/migrants/migrants.asm +++ /dev/null @@ -1,20 +0,0 @@ -.intel_syntax -pushfd -push ebx -push edx -mov eax,[0xdeadbeef] # get old seed -mov ebx,1103515245 -#mul 1103515245 -mul ebx -add eax,12345 -mov [0xdeadbeef],eax #put seed back...thus generation rnd is complete - -xor edx,edx -mov ebx,2000 #put size of array here -div ebx #why oh why there is no div const? compiler prob makes some xor/add magic -movzx eax,word ptr[0xdeadbeef+edx*2] -pop edx -pop ebx - -popfd -ret diff --git a/plugins/Dfusion/luafiles/migrants/migrants.o b/plugins/Dfusion/luafiles/migrants/migrants.o deleted file mode 100644 index 30b5b14f03cd8e110b91123e0631f8e0b3378ed0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 336 zcmeZaWM%+?JwVI>X0bBrm84dbfY}hj07&&9@j*-l27?5>l*E!mG;wsU1B1Zh*T58Y}8WPdP$)nF)LK=uPD#F#;bp#c^k F9{~H9FI)fs diff --git a/plugins/Dfusion/luafiles/migrants/plugin.lua b/plugins/Dfusion/luafiles/migrants/plugin.lua deleted file mode 100644 index 651e4900c..000000000 --- a/plugins/Dfusion/luafiles/migrants/plugin.lua +++ /dev/null @@ -1,5 +0,0 @@ - -if not(FILE) then - names=ParseNames("dfusion/migrants/races.txt")--io.open("plugins/migrants/races.txt"):lines() - migrants(names) -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/migrants/races.txt b/plugins/Dfusion/luafiles/migrants/races.txt deleted file mode 100644 index 9a3fa6cf6..000000000 --- a/plugins/Dfusion/luafiles/migrants/races.txt +++ /dev/null @@ -1,29 +0,0 @@ -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -ELF -HUMAN -DWARF -GREMLIN -KOBOLD -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -DWARF -ELF -HUMAN -DWARF -GREMLIN -KOBOLD -DEMON_13 \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/offsets/plugin.lua b/plugins/Dfusion/luafiles/offsets/plugin.lua deleted file mode 100644 index b9e2fc441..000000000 --- a/plugins/Dfusion/luafiles/offsets/plugin.lua +++ /dev/null @@ -1,2 +0,0 @@ -offsets.searchoffsets() -offsets.save() \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/offsets_misc.lua b/plugins/Dfusion/luafiles/offsets_misc.lua deleted file mode 100644 index 8bca50000..000000000 --- a/plugins/Dfusion/luafiles/offsets_misc.lua +++ /dev/null @@ -1,48 +0,0 @@ -offsets=offsets or {} -function offsets.find(startoffset,...) - -- [=[ - if startoffset== 0 then - local text=GetTextRegion() - --print("searching in:"..text.name) - startoffset=text.start - endadr=text["end"] - else - local reg=GetRegionIn(startoffset) - --print("searching in:"..reg.name) - if reg==nil then - print(string.format("Warning: memory range for search @:%x not found!",startoffset)) - return 0 - end - endadr=reg["end"] - end - --]=] - --print(string.format("Searching (%x->%x)",startoffset,endadr)) - local h=hexsearch(startoffset,endadr,...) - local pos=h:find() - h=nil - return pos -end -function offsets.findall(startoffset,...) - local endadr; - if startoffset== 0 then - local text=GetTextRegion() - --print("searching in:"..text.name) - startoffset=text.start - endadr=text["end"] - else - local reg=GetRegionIn(startoffset) - --print("searching in:"..reg.name) - endadr=reg["end"] - end - local h=hexsearch(startoffset,endadr,...) - local pos=h:findall() - h=nil - return pos -end -function offsets.base() - return Process.getBase() -end -function offsets.getvectors() - return findVectors() -end -ADDRESS=ANYDWORD \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/simple_embark/plugin.lua b/plugins/Dfusion/luafiles/simple_embark/plugin.lua deleted file mode 100644 index abc3530c2..000000000 --- a/plugins/Dfusion/luafiles/simple_embark/plugin.lua +++ /dev/null @@ -1,23 +0,0 @@ -function simple_embark(num) - local stoff=dfhack.internal.getAddress('start_dwarf_count') - print("Starting dwarves found:"..df.reinterpret_cast('int32_t', stoff).value) - local tmp_val=df.new('int32_t') - local size,pos=tmp_val:sizeof() - tmp_val.value=num - local ret=dfhack.internal.patchMemory(stoff,tmp_val,size) - if ret then - print("Success!") - else - qerror("Failed to patch in number") - end -end -if not(FILE) then -print("Type in new amount (more than 6, less than 15000):") - repeat - ans=tonumber(io.read()) - if ans==nil or not(ans<=15000 and ans>0) then - print("incorrect choice") - end - until ans~=nil and (ans<=15000 and ans>0) - simple_embark(ans) -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/tools/init.lua b/plugins/Dfusion/luafiles/tools/init.lua deleted file mode 100644 index a8c787ffb..000000000 --- a/plugins/Dfusion/luafiles/tools/init.lua +++ /dev/null @@ -1,511 +0,0 @@ -local ms=require "memscan" -tools={} -tools.menu=MakeMenu() -function tools.setrace(name) - RaceTable=BuildNameTable() - 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):") - 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 - end - df.global.ui.race_id=id -end -tools.menu:add("Set current race",tools.setrace) -function tools.GiveSentience(names) - RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again - if names ==nil then - ids={} - print("Type race's token name in full caps to give sentience to:") - repeat - entry=getline() - id=RaceTable[entry] - until id~=nil - table.insert(ids,id) - else - ids={} - for _,name in pairs(names) do - id=RaceTable[name] - table.insert(ids,id) - end - end - for _,id in pairs(ids) do - local races=df.global.world.raws.creatures.all - - local castes=races[id].caste - print(string.format("Caste count:%i",castes.size)) - for i =0,#castes-1 do - - print("Caste name:"..castes[i].caste_id.."...") - - local flags=castes[i].flags - --print(string.format("%x",flagoffset)) - if flags.CAN_SPEAK then - print("\tis sentient.") - else - print("\tnon sentient. Allocating IQ...") - flags.CAN_SPEAK=true - end - end - end -end -tools.menu:add("Give Sentience",tools.GiveSentience) -function tools.embark() --windows only? - local seg=ms.get_code_segment() - local idx,off - - idx,off=seg.uint8_t:find_one{0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04} - if idx then - local tmp_val=df.new('uint8_t',2) - tmp_val[0]=0x90 - tmp_val[1]=0x90 - local size,pos=tmp_val:sizeof() - local ret=dfhack.internal.patchMemory(off+5,pos,size*2) - if ret then - print("Found and patched:",off+5) - else - print("Patching failed at:",off+5) - end - tmp_val:delete() - else - qerror("Offset for embark patch not found!") - end -end -if WINDOWS then -tools.menu:add("Embark anywhere",tools.embark) -end -function tools.getCreatureId(vector) --redo it to getcreature by name/id or something - tnames={} - rnames={} - --[[print("vector1 size:"..vector:size()) - print("vector2 size:"..vector2:size())]]-- - for i=0,vector:size()-1 do - --print(string.format("%x",vector:getval(i))) - - local name=engine.peek(vector:getval(i),ptt_dfstring):getval() - local lid= tools.getlegendsid(vector:getval(i)) - if lid ~=0 then - print(i..")*Creature Name:"..name.." race="..engine.peekw(vector:getval(i)+ptr_Creature.race.off).." legendid="..lid) - else - print(i..") Creature Name:"..name.." race="..engine.peekw(vector:getval(i)+ptr_Creature.race.off)) - end - if name ~="" and name~=nil then - tnames[i]=name - rnames[name]=i - end - end - print("=====================================") - print("type in name or number:") - r=getline() - if tonumber(r) ==nil then - indx=rnames[r] - if indx==nil then return end - else - r=tonumber(r) - if rLOVE), q to quit:") - names={} - repeat - w=getline(); - - if rwords[w]~=nil then - table.insert(names,w) - print("--added--") - end - - until w=='q' - end - - tnames={} - for _,v in pairs(names) do - if rwords[v] ~=nil then - table.insert(tnames,rwords[v]) --get word numbers - end - end - - local offsites=engine.peekd(offsets.getEx("SiteData"))+0x120 - snames={" pfort"," dfort"," cave","mohall","forest","hamlet","imploc"," lair"," fort"," camp"} - vector=engine.peek(offsites,ptr_vector) - print("Number of sites:"..vector:size()) - print("List of hits:") - for i =0,vector:size()-1 do - off=vector:getval(i) - - good=true - r="" - hits=0 - sname=engine.peek(off,ptr_site.name) - for k=0,6 do - vnum=sname[k]--engine.peekd(off+0x38+k*4) - tgood=false - - if vnum~=0xFFFFFFFF then - --print(string.format("%x",vnum)) - if names[vnum]~=nil then - r=r..names[vnum].." " - end - for _,v in pairs(tnames) do - if vnum==v then - tgood=true - --print("Match") - hits=hits+1 - break - end - end - if not tgood then - good=false - end - end - end - - if(good) and (hits>0)then - --if true then - --print("=====================") - typ=engine.peek(off,ptr_site.type)--engine.peekw(off+0x78) - flg=engine.peekd(engine.peek(off,ptr_site.flagptr)) - --flg=engine.peekd(off+224) - --flg2=engine.peekw(off) - --tv=engine.peek(off+0x84,ptr_vector) - --tv2=engine.peek(off+0xA4,ptr_vector) - - print(string.format("%d)%s off=%x type=%s\t flags=%x",i,r,off,snames[typ+1],flg)) - - if i%100==99 then - r=getline() - end - - end - end - print("Type which to change (q cancels):") - repeat - r=getline() - n=tonumber(r) - if(r=='q') then return end - until n~=nil - return vector:getval(n) -end -function tools.changesite(names) - off=tools.getsite(names) - snames={"Mountain halls (yours)","Dark fort","Cave","Mountain hall (NPC)","Forest retreat","Hamlet","Important location","Lair","Fort","Camp"} - - print("Type in the site type (q cancels):") - for k,v in pairs(snames) do - print((k-1).."->"..v) - end - repeat - r=getline() - n2=tonumber(r) - if(r=='q') then return end - until n2~=nil - --off=vector:getval(n) - print(string.format("%x->%d",off,n2)) - engine.poke(off,ptr_site.type,n2) -end -function tools.project(unit,trg) - if unit==nil then - unit=getCreatureAtPointer() - end - - if unit==nil then - error("Failed to project unit. Unit not selected/valid") - end - -- todo: add projectile to world, point to unit, add flag to unit, add gen-ref to projectile. - local p=df.proj_unitst:new() - local startpos={x=unit.pos.x,y=unit.pos.y,z=unit.pos.z} - p.origin_pos=startpos - p.target_pos=trg - p.cur_pos=startpos - p.prev_pos=startpos - p.unit=unit - --- wtf stuff - p.unk14=100 - p.unk16=-1 - p.unk23=-1 - p.fall_delay=5 - p.fall_counter=5 - p.collided=true - -- end wtf - local citem=df.global.world.proj_list - local maxid=1 - local newlink=df.proj_list_link:new() - newlink.item=p - while citem.item~= nil do - if citem.item.id>maxid then maxid=citem.item.id end - if citem.next ~= nil then - citem=citem.next - else - break - end - end - p.id=maxid+1 - newlink.prev=citem - citem.next=newlink - - local proj_ref=df.general_ref_projectile:new() - proj_ref.projectile_id=p.id - unit.refs:insert(#unit.refs,proj_ref) - unit.flags1.projectile=true -end -function tools.empregnate(unit) - if unit==nil then - unit=getSelectedUnit() - end - - if unit==nil then - unit=getCreatureAtPos(getxyz()) - end - - if unit==nil then - error("Failed to empregnate. Unit not selected/valid") - end - if unit.curse then - unit.curse.add_tags2.STERILE=false - end - local genes = unit.appearance.genes - if unit.relations.pregnancy_ptr == nil then - print("creating preg ptr.") - if false then - print(string.format("%x %x",df.sizeof(unit.relations:_field("pregnancy_ptr")))) - return - end - unit.relations.pregnancy_ptr = { new = true, assign = genes } - end - local ngenes = unit.relations.pregnancy_ptr - if #ngenes.appearance ~= #genes.appearance or #ngenes.colors ~= #genes.colors then - print("Array sizes incorrect, fixing.") - ngenes:assign(genes); - end - print("Setting preg timer.") - unit.relations.pregnancy_timer=10 - unit.relations.pregnancy_mystery=1 -end -tools.menu:add("Empregnate",tools.empregnate) -function tools.changeflags(names) - myflag_pattern=ptt_dfflag.new(3*8) - off=tools.getsite(names) - offflgs=engine.peek(off,ptr_site.flagptr) - q='' - print(string.format("Site offset %x flags offset %x",off,offflgs)) - repeat - print("flags:") - - --off=vector:getval(n) - flg=engine.peek(offflgs,myflag_pattern) - r="" - for i=0,3*8-1 do - if flg:get(i)==1 then - r=r.."x" - else - r=r.."o" - end - if i%8==7 then - print(i-7 .."->"..r) - r="" - end - end - print("Type number to flip, or 'q' to quit.") - q=getline() - n2=tonumber(q) - if n2~=nil then - - flg:flip(n2) - engine.poke(offflgs,myflag_pattern,flg) - end - until q=='q' -end -function tools.hostilate() - vector=engine.peek(offsets.getEx("CreatureVec"),ptr_vector) - id=engine.peekd(offsets.getEx("CreaturePtr")) - print(string.format("Vec:%d cr:%d",vector:size(),id)) - off=vector:getval(id) - crciv=engine.peek(off,ptr_Creature.civ) - print("Creatures civ:"..crciv) - curciv=engine.peekd(offsets.getEx("CurrentRace")-12) - print("My civ:"..curciv) - if curciv==crciv then - print("Friendly-making enemy") - engine.poke(off,ptr_Creature.civ,-1) - flg=engine.peek(off,ptr_Creature.flags) - flg:set(17,0) - print("flag 51:"..tostring(flg:get(51))) - engine.poke(off,ptr_Creature.flags,flg) - else - print("Enemy- making friendly") - engine.poke(off,ptr_Creature.civ,curciv) - flg=engine.peek(off,ptr_Creature.flags) - flg:set(17,1) - flg:set(19,0) - engine.poke(off,ptr_Creature.flags,flg) - end -end -function tools.mouseBlock() - local xs,ys,zs - xs,ys,zs=getxyz() - xs=math.floor(xs/16) - ys=math.floor(ys/16) - print("Mouse block is:"..xs.." "..ys.." "..zs) -end -function tools.fixwarp() - local mapoffset=offsets.getEx("WorldData")--0x131C128+offsets.base() - local x=engine.peek(mapoffset+24,DWORD) - local y=engine.peek(mapoffset+28,DWORD) - local z=engine.peek(mapoffset+32,DWORD) - --vec=engine.peek(mapoffset,ptr_vector) - - print("Blocks loaded:"..x.." "..y.." "..z) - print("Select type:") - print("1. All (SLOW)") - print("2. range (x0 x1 y0 y1 z0 z1)") - print("3. One block around pointer") - print("anything else- quit") - q=getline() - n2=tonumber(q) - if n2==nil then return end - if n2>3 or n2<1 then return end - local xs,xe,ys,ye,zs,ze - if n2==1 then - xs=0 - xe=x-1 - ys=0 - ye=y-1 - zs=0 - ze=z-1 - elseif n2==2 then - print("enter x0:") - xs=tonumber(getline()) - print("enter x1:") - xe=tonumber(getline()) - print("enter y0:") - ys=tonumber(getline()) - print("enter y1:") - ye=tonumber(getline()) - print("enter z0:") - zs=tonumber(getline()) - print("enter z1:") - ze=tonumber(getline()) - function clamp(t,vmin,vmax) - if t> vmax then return vmax end - if t< vmin then return vmin end - return t - end - xs=clamp(xs,0,x-1) - ys=clamp(ys,0,y-1) - zs=clamp(zs,0,z-1) - xe=clamp(xe,xs,x-1) - ye=clamp(ye,ys,y-1) - ze=clamp(ze,zs,z-1) - else - xs,ys,zs=getxyz() - xs=math.floor(xs/16) - ys=math.floor(ys/16) - xe=xs - ye=ys - ze=zs - end - local xblocks=engine.peek(mapoffset,DWORD) - local flg=bit.bnot(bit.lshift(1,3)) - for xx=xs,xe do - local yblocks=engine.peek(xblocks+xx*4,DWORD) - for yy=ys,ye do - local zblocks=engine.peek(yblocks+yy*4,DWORD) - for zz=zs,ze do - local myblock=engine.peek(zblocks+zz*4,DWORD) - if myblock~=0 then - for i=0,255 do - local ff=engine.peek(myblock+0x67c+i*4,DWORD) - ff=bit.band(ff,flg) --set 14 flag to 1 - engine.poke(myblock+0x67c+i*4,DWORD,ff) - end - end - end - print("Blocks done:"..xx.." "..yy) - end - end -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/tools/plugin.lua b/plugins/Dfusion/luafiles/tools/plugin.lua deleted file mode 100644 index 8eaefd44d..000000000 --- a/plugins/Dfusion/luafiles/tools/plugin.lua +++ /dev/null @@ -1,8 +0,0 @@ -if not(FILE) then - --tools.menu:add("Change site type",tools.changesite) - --tools.menu:add("Change site flags",tools.changeflags) - --tools.menu:add("Hostilate creature",tools.hostilate) - --tools.menu:add("Print current mouse block",tools.mouseBlock) - - tools.menu:display() -end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/utils.lua b/plugins/Dfusion/luafiles/utils.lua deleted file mode 100644 index d481f5cfc..000000000 --- a/plugins/Dfusion/luafiles/utils.lua +++ /dev/null @@ -1 +0,0 @@ -function findVectorsSized(size) local ret={} local text=GetTextRegion() for k,v in pairs(offsets.getvectors()) do if GetRegionIn2(k)~=nil then --if v>4 then local tv=engine.peek(k,ptr_vector) if tv:size() == size then print(string.format("%x is size %d",k,size)) table.insert(ret,k) end end end return ret end function findMaterial(mattype,matname) --currently only stones local tbl=BuildMaterialTable() return tbl[matname] end function iter(tbl) if getmetatable(tbl) ~=nil then if getmetatable(tbl).__next~= nil then return getmetatable(tbl).__next,tbl else return getmetatable(tbl).__pairs(tbl) or pairs(tbl) end else return pairs(tbl) end end \ No newline at end of file diff --git a/plugins/lua/dfusion/embark.lua b/plugins/lua/dfusion/embark.lua index 578c0b903..6e5df4eef 100644 --- a/plugins/lua/dfusion/embark.lua +++ b/plugins/lua/dfusion/embark.lua @@ -3,22 +3,34 @@ local dfu=require("plugins.dfusion") local ms=require("memscan") local MAX_RACES=100 CustomEmbark=defclass(CustomEmbark,dfu.BinaryPlugin) -CustomEmbark.name="CustomEmbark" - -print(t) local myos=dfhack.getOSType() if myos=="windows" then CustomEmbark.ATTRS{filename="hack/lua/plugins/dfusion/embark.o",name="CustomEmbark",race_caste_data=DEFAULT_NIL} - CustomEmbark.class_status="valid, not installed" - function CustomEmbark:install() - local stoff=dfhack.internal.getAddress('start_dwarf_count') - - if #self.race_caste_data<7 then + function CustomEmbark:parseRaces(races) + if #races<7 then error("caste and race count must be bigger than 6") end - if #self.race_caste_data>MAX_RACES then + if #races>MAX_RACES then error("caste and race count must be less then "..MAX_RACES) end + local n_to_id=require("plugins.dfusion.tools").build_race_names() + + local ids={} + for k,v in pairs(races) do + local race=v[1] or v + ids[k]={} + ids[k][1]=n_to_id[race] + if ids[k][1]==nil then qerror(race.." not found!") end + ids[k][2]=v[2] or -1 + end + self.race_caste_data=ids + end + function CustomEmbark:install(race_caste_data) + local stoff=dfhack.internal.getAddress('start_dwarf_count') + if race_caste_data~=nil then + self:parseRaces(race_caste_data) + end + if stoff==nil then error("address for start_dwarf_count not found!") end @@ -40,14 +52,14 @@ if myos=="windows" then local call_data={0x90,0x90} local _,data_offset=df.sizeof(self.data) dfu.concatTables(call_data,dfu.makeCall(trg_offset+2,data_offset)) - self.call_patch=dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} + self.call_patch=self.call_patch or dfu.BinaryPatch{pre_data=needle,data=call_data,address=trg_offset,name="custom_embark_call_patch"} needle={0x83,0xc8,0xff} -- or eax, 0xFF local _,caste_offset=mem.uint8_t:find(needle,mem.uint8_t:addr2idx(trg_offset),nil) if caste_offset==nil or caste_offset-stoff>1000 then error("Caste change code not found or found too far!") end - self.disable_castes=dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} + self.disable_castes=self.disable_castes or dfu.BinaryPatch{pre_data={0x83,0xc8,0xff},data={0x90,0x90,0x90},address=caste_offset,name="custom_embark_caste_disable"} self.disable_castes:apply() @@ -66,16 +78,11 @@ if myos=="windows" then self.call_patch:apply() self.installed=true end + function CustomEmbark:setEmbarkParty(racesAndCastes) local stoff=dfhack.internal.getAddress('start_dwarf_count') - if #racesAndCastes<7 then - error("caste and race count must be bigger than 6") - end - if #racesAndCastes>MAX_RACES then - error("caste and race count must be less then "..MAX_RACES) - end - self.race_caste_data=racesAndCastes + if self.dwarfcount== nil then self.dwarfcount=dfu.BinaryPatch{pre_data=dfu.dwordToTable(7),data=dfu.dwordToTable(#self.race_caste_data),address=stoff,name="custom_embark_embarkcount"} self.dwarfcount:apply() @@ -84,8 +91,9 @@ if myos=="windows" then end local caste_array=self:get_or_alloc("caste_array","uint16_t",MAX_RACES) local race_array=self:get_or_alloc("race_array","uint16_t",MAX_RACES) + for k,v in ipairs(self.race_caste_data) do - caste_array[k-1]=v[2] + caste_array[k-1]=v[2] or -1 race_array[k-1]=v[1] end end @@ -103,48 +111,14 @@ if myos=="windows" then self.dwarfcount:remove() end end - function CustomEmbark:edit() - local data=self.race_caste_data or {} - print(string.format("Old race count:%d",#data)) - local endthis=false - print("current:") - while(not endthis) do - print(" # RaceId Race name Caste num") - for k,v in pairs(data) do - local name=df.creature_raw.find(v[1]).creature_id or "" - print(string.format("%3d. %6d %20s %d",k,v[1],name,v[2])) - end - print("a- add, r-remove, c-cancel, s-save and update") - local choice=io.stdin:read() - if choice=='a' then - print("Enter new race then caste ids:") - local race=tonumber(io.stdin:read()) - local caste=tonumber(io.stdin:read()) - if race and caste then - table.insert(data,{race,caste}) - else - print("input parse error") - end - elseif choice=='r' then - print("enter number to remove:") - local num_rem=tonumber(io.stdin:read()) - if num_rem~=nil then - table.remove(data,num_rem) - end - elseif choice=='c' then - endthis=true - elseif choice=='s' then - endthis=true - if self.installed then - self:setEmbarkParty(data) - else - self.race_caste_data=data - self:install() - end - end + function CustomEmbark:unload() + self:uninstall() + if Embark~=nil then + Embark=nil end end + Embark=Embark or CustomEmbark() else - CustomEmbark.class_status="invalid, os not supported" + CustomEmbark.status=function() return"invalid, os not supported" end end return _ENV \ No newline at end of file diff --git a/plugins/lua/dfusion/friendship.lua b/plugins/lua/dfusion/friendship.lua index 70a1ceea4..93a370c86 100644 --- a/plugins/lua/dfusion/friendship.lua +++ b/plugins/lua/dfusion/friendship.lua @@ -35,7 +35,7 @@ function FriendshipRainbow:find_all() dfu.concatTables(locations,self:find_one(code,{0x0f,0xbf,reg},crace)) --movsx reg,[ptr] dfu.concatTables(locations,self:find_one(code,{0x66,0x8b,reg},crace)) --mov reg,[ptr] end - printall(locations) + return self:filter_locations(code,locations) end function FriendshipRainbow:filter_locations(codesg,locations) @@ -107,5 +107,6 @@ function FriendshipRainbow:install(races) local addr=self:move_to_df() self:patchCalls(addr) self.installed=true - end +end +Friendship=Friendship or FriendshipRainbow() return _ENV \ No newline at end of file From 856c9ebd4b7bfb09a57576cb73763c1ead00baa1 Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 11 Nov 2012 12:39:49 +0200 Subject: [PATCH 042/158] Added save specific scripts to lua interpreter script, also better error reporting. --- scripts/lua.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/lua.lua b/scripts/lua.lua index 497498e86..556962347 100644 --- a/scripts/lua.lua +++ b/scripts/lua.lua @@ -1,9 +1,26 @@ local args={...} if args[1]=="--file" or args[1]=="-f" then - local f=loadfile (args[2]) + local f,err=loadfile (args[2]) + if f==nil then + qerror(err) + end + dfhack.pcall(f,table.unpack(args,3)) +elseif args[1]=="--save" or args[1]=="-s" then + if df.global.world.cur_savegame.save_dir=="" then + qerror("Savefile not loaded") + end + local fname=args[2] or "dfhack.lua" + fname=string.format("data/save/%s/%s",df.global.world.cur_savegame.save_dir,fname) + local f,err=loadfile (fname) + if f==nil then + qerror(err) + end dfhack.pcall(f,table.unpack(args,3)) elseif args[1]~=nil then - local f=load(args[1],'=(lua command)', 't') + local f,err=load(args[1],'=(lua command)', 't') + if f==nil then + qerror(err) + end dfhack.pcall(f,table.unpack(args,2)) else dfhack.interpreter("lua","lua.history") From d5c31942b50accc840026182100c48928d76641f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 11 Nov 2012 10:58:05 +0400 Subject: [PATCH 043/158] Add a way to only count locally-made items in workflow. --- Readme.html | 661 ++++++++++++++++++++++----------------- Readme.rst | 82 ++++- dfhack.init-example | 23 +- plugins/lua/workflow.lua | 11 +- plugins/workflow.cpp | 95 ++++-- scripts/gui/workflow.lua | 11 +- 6 files changed, 550 insertions(+), 333 deletions(-) diff --git a/Readme.html b/Readme.html index cd073459c..16f3aed5a 100644 --- a/Readme.html +++ b/Readme.html @@ -337,197 +337,201 @@ access DF memory and allow for easier development of new tools.

  • Introduction
  • Getting DFHack
  • Compatibility
  • -
  • Installation/Removal
  • -
  • Using DFHack