From e84841e94fad28f9a8c124171c099a52e9e303da Mon Sep 17 00:00:00 2001 From: Warmist Date: Mon, 12 Dec 2011 20:25:37 +0200 Subject: [PATCH] Added autorunning initcustom.lua (for place to put private scripts) autorunning save files, and friendship_civ (still buggy) --- .../luafiles/friendship_civ/compile.bat | 1 + .../luafiles/friendship_civ/friendship_c.asm | 41 ++++++++ .../luafiles/friendship_civ/friendship_c.o | Bin 0 -> 462 bytes .../Dfusion/luafiles/friendship_civ/init.lua | 89 ++++++++++++++++++ .../luafiles/friendship_civ/plugin.lua | 57 +++++++++++ plugins/Dfusion/luafiles/init.lua | 8 ++ 6 files changed, 196 insertions(+) create mode 100644 plugins/Dfusion/luafiles/friendship_civ/compile.bat create mode 100644 plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm create mode 100644 plugins/Dfusion/luafiles/friendship_civ/friendship_c.o create mode 100644 plugins/Dfusion/luafiles/friendship_civ/init.lua create mode 100644 plugins/Dfusion/luafiles/friendship_civ/plugin.lua diff --git a/plugins/Dfusion/luafiles/friendship_civ/compile.bat b/plugins/Dfusion/luafiles/friendship_civ/compile.bat new file mode 100644 index 000000000..64d4d4440 --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/compile.bat @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..b2b49ee78 --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm @@ -0,0 +1,41 @@ +.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 new file mode 100644 index 0000000000000000000000000000000000000000..d85134682ac1e464b944b3e3403babe96a43a8b6 GIT binary patch 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- literal 0 HcmV?d00001 diff --git a/plugins/Dfusion/luafiles/friendship_civ/init.lua b/plugins/Dfusion/luafiles/friendship_civ/init.lua new file mode 100644 index 000000000..5390829de --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/init.lua @@ -0,0 +1,89 @@ +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 new file mode 100644 index 000000000..12f334fcf --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/plugin.lua @@ -0,0 +1,57 @@ +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 index d07c1ce3f..76630ff4f 100644 --- a/plugins/Dfusion/luafiles/init.lua +++ b/plugins/Dfusion/luafiles/init.lua @@ -49,6 +49,7 @@ table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"}) table.insert(plugins,{"items","A collection of item hacking tools"}) table.insert(plugins,{"offsets","Find all offsets"}) table.insert(plugins,{"friendship","Multi race fort enabler"}) +table.insert(plugins,{"friendship_civ","Multi civ fort enabler"}) table.insert(plugins,{"embark","Multi race embark"}) table.insert(plugins,{"adv_tools","some tools for (mainly) advneturer hacking"}) table.insert(plugins,{"tools","some misc tools"}) @@ -57,6 +58,13 @@ table.insert(plugins,{"migrants","multi race imigrations"}) table.insert(plugins,{"onfunction","run lua on some df function"}) loadall(plugins) dofile_silent("dfusion/initcustom.lua") + +print("Locating saves...") +local str=engine.peekstr(0x1447A40+offsets.base()) +print("Current region:"..str) +str="data/save/"..str.."/dfusion/init.lua" +dofile_silent(str) + if not INIT then mainmenu(plugins) end