From 6fc10fc2683e82dc6c0552507f1700214019a514 Mon Sep 17 00:00:00 2001 From: Warmist Date: Wed, 5 Sep 2012 21:52:54 +0300 Subject: [PATCH] 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