Added autorunning initcustom.lua (for place to put private scripts) autorunning save files, and friendship_civ (still buggy)

develop
Warmist 2011-12-12 20:25:37 +02:00
parent 9b48d4946e
commit e84841e94f
6 changed files with 196 additions and 0 deletions

@ -0,0 +1 @@
as -anl --32 -o friendship_c.o 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

@ -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

@ -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()

@ -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,{"items","A collection of item hacking tools"})
table.insert(plugins,{"offsets","Find all offsets"}) table.insert(plugins,{"offsets","Find all offsets"})
table.insert(plugins,{"friendship","Multi race fort enabler"}) 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,{"embark","Multi race embark"})
table.insert(plugins,{"adv_tools","some tools for (mainly) advneturer hacking"}) table.insert(plugins,{"adv_tools","some tools for (mainly) advneturer hacking"})
table.insert(plugins,{"tools","some misc tools"}) 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"}) table.insert(plugins,{"onfunction","run lua on some df function"})
loadall(plugins) loadall(plugins)
dofile_silent("dfusion/initcustom.lua") 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 if not INIT then
mainmenu(plugins) mainmenu(plugins)
end end