Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 7 8 [9] 10 11 ... 38

Author Topic: DFusion - a lua based plugin system (integrated into DFHack)  (Read 152102 times)

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.1
« Reply #120 on: December 12, 2010, 08:03:15 am »

Site research:
Found sitelist. Found site type (thus can change type of any and all sites). Unfortunately just changing the type of site is not enough to prevent item scatter.
Edit: Found flags... one for hidden three for caves n stuff one for hamlet ticks... none for "do not scatter shit around" :/
« Last Edit: December 12, 2010, 06:50:49 pm by darius »
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.1
« Reply #121 on: December 14, 2010, 02:30:43 am »

So these will make any land mass sleep friendly? Having a custom non town-hot spot I could park my men with out worry of them dying from a cave creature is awesome that and to retire there and start up another character is a nice bonus. I mean if I can figure out all the kinks from race changing healing then I could set up a hospital/ base of operation near a lair and go with that.
Hey does the fort tile spawn knights?

edit: jump on to working on a revive/zombify/ghost adv_tool so far I just copied and pasted the make creature follow tool(learn how to add in functions to the list with proper names) just that now I can't seem to get the peek to work. From checking the patterns file there a 'flag' command and a following ID but do I have to add in a "Ghost ID/flag" to the pattern's file or should the peek do that for me?
« Last Edit: December 14, 2010, 06:09:54 am by Rumrusher »
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.1
« Reply #122 on: December 14, 2010, 12:53:20 pm »

well the flags are a bit special case. Creature flags take up 4 (or more) bytes and indvidual bits are flags
Code: [Select]
in memory:
here starts the flags
   v
xxxyyyy...
so getting a byte with peek will only get you a sum of flags. Getting individual flag is a bit different. I'll write the code for that soon.
Edit:
add this in patterns.lua at the top. This is a universal (changeable size) pattern for  flag manipulation.
Code: [Select]
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 1
else
return 0
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
local ret={}
for i=0,size-1 do
ret[i]={off=i,rtype=BYTE};
end
ret.flip=ptt_dfflag.flip
ret.get=ptt_dfflag.get
ret.set=ptt_dfflag.set
return ret;
end
then somewhere after "ptr_Creature={}" add
Code: [Select]
ptr_Creature.flags={off=224,rtype=ptt_dfflag.new(10)}-- not sure if its 10 or more...
Using this now becomes very simple if you have creature offset (with get creature at pos or similar):
Code: [Select]
myoff=offsets.getEx("AdvCreatureVec") -- first find out where "Adventurer creature vector" is
vector=engine.peek(myoff+16,ptr_vector) -- +16 is a little fix...
tval=vector:getval(0) -- get offset of player
flg=engine.peek(tval,ptr_Creature.flags) --get flags
flg:flip(76) -- 76 is ghostliness flag. Other flags (from older versions :1-> dead, 2->insane,3->artifact made,4->merchant and so on...)
engine.poke(tval,ptr_Creature.flags,flg) --save flags
« Last Edit: December 14, 2010, 01:29:31 pm by darius »
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.1
« Reply #123 on: December 14, 2010, 01:41:05 pm »

well the flags are a bit special case. Creature flags take up 4 (or more) bytes and indvidual bits are flags
Code: [Select]
in memory:
here starts the flags
   v
xxxyyyy...
so getting a byte with peek will only get you a sum of flags. Getting individual flag is a bit different. I'll write the code for that soon.
also I Almost understand what you did in the adv_tools from staring hard enough what I don't get is from realizing all of it goes back to pattens.lua and the creature section (which has a list of numbers and some with "(D Word)" next to it) from what I got from digging round common state these might mean 1 byte 2 byte and 3 byte, which leads to the biggest puzzle with this. Could I swap only the flags of a creature? That and could I find some way to force a pointer(or auto select the next body in line) in DF and allow the user to change to the nearest body around. the latter major hurdle is from not knowing if adding a number(with title to it so the program can connect) between the creature section in the pattern.lua will work and I can test to see which number has the right flag.

I also want to thank you for all of this I wouldn't be getting my hands slightly dirty if it wasn't for this.
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.1
« Reply #124 on: December 14, 2010, 02:12:03 pm »

Yeah my on todo list is resume tutorial in patterns.lua and other undocumented stuff. Later still release all source code (maybe when engine does not change much...). As for patterns they are quite simple:

  • first there is line sth={} this means make a new lua table named sth
  • then are are multiple lines sth.x={off=<number>, rtype=<type>} this means that when reading a pattern value x can be found at offset <number> from the start and is a <type>. Type can be:
    • STD_STRING- means that engine.peekstr/pokestr will be used and x will be a string
    • BYTE/WORD/DWORD - a number that takes up 1/2/4 bytes.
    • other pattern - means that x will be an object of that type. Theoretically you could recurse into infinity by setting rtype=sth, but that would crash the program
This system makes it possible to load anything without disturbing things you don't want to mess with. Simple example:
Code: [Select]
z=engine.peek(someoffset, ptt_vector)
--what this means is read data from someoffset using pattern ptt_vector. That in turn means:
--read someoffset+0 with size DWORD (4bytes) and save it to z.st (because ptt_vector.st={off=0,rtype=DWORD})
--and read someoffset+4 with size DWORD and save it to z.en (ptt_vector.en={off=4,rtype=DWORD})
Patterns can also have functions, those are left unchanged (and copied to end object).
Code: [Select]
function ptr_vector:size() -- the ':' means ptr_vector.size(self)
return (self.en-self.st)/engine.sizeof(self.type)
end
-- so this in turn makes z(loaded before) have function z:size()
-- if you make a lua helper function
function print_all(t)
for k,v in pairs(t) do
 print(tostring(k).."=>"..tostring(v))
end
end
--and use it:
print_all(z)
-- you should get everything what is in that object.
Also all code that does that sits in common.lua. See engine.peekpattern/pokepattern.
Edit: and why does hacking DF go so smooth when programing my own game is so slow...
« Last Edit: December 14, 2010, 02:15:56 pm by darius »
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.1
« Reply #125 on: December 14, 2010, 03:01:59 pm »

Maybe writing a sentence when you first learn it is harder than deciphering it.
76 ghostliness = noclip excuse me as I foam in the mouth over the adventure mode discovery...
« Last Edit: December 14, 2010, 04:17:42 pm by Rumrusher »
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #126 on: December 14, 2010, 03:17:01 pm »

Maybe writing a sentence when you first learn it is harder than deciphering it.

Maybe true. I have another hypothesis: less interaction/encouragement and a goal to make something more impressive than DF (that is near impossible).

Also updated Dfusion. Now we have site type changer (very... ugly... unwieldy... and so on...) and adv. tools has ghostifier (thx Rumrusher for the idea).
Edit: funfact- if you change the site type to 0 (your embark point) you can try to reclaim it. But it crashed when i tried that. Also changing into hamlet makes buildings when you visit next time.
« Last Edit: December 14, 2010, 03:18:40 pm by darius »
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #127 on: December 14, 2010, 04:22:58 pm »

I was figuring out how to bring back the spirit of a dead person (just got the tracking fix but fail to chain more than one flag switch) then the entire adv_tools got lock out.
well at least now I can test out creating undead companions who may or may not kill you and the ability to noclip through walls in the new version.

edit: I found out that 8 will kill things dead and removes them from the field(which means no way to bring back), and 50 puts them to sleep literally, so it's a nice feature for wanting to have either a power nap in game or curing your companions of their drowsiness. so far from what I know re-dying in arena mode won't cause a crash. that and trying to convert it into a hovel also.
hey do you know what flag is zombie/skeleton?

here's a close code for revival... sadly this is for talking to the dead buddies who kick it too soon.
Code: [Select]
function adv_tools.notdead()
--this will revive a dead soul from the grave... chances of it following you not so much
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff+16,ptr_vector)
indx=GetCreatureAtPos(getxyz())
flg=engine.peek(vector:getval(indx),ptr_Creature.flags) --get flags
flg:flip(1,76) -- this will turn off the dead flag while turning on Ghostliness
engine.poke(vector:getval(indx),ptr_Creature.flags,flg) --save flags
end
if my idea correct one could swap the body with a demon model and swap back, or if I'm wrong should swap back to the human model as a dead demon and swap back.
 
« Last Edit: December 14, 2010, 11:43:37 pm by Rumrusher »
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #128 on: December 15, 2010, 06:12:16 am »

Damn i need program in more error messages.
Code: [Select]
flg:flip(1,76)
does not work as you think it would
Code: [Select]
flg:flip(1)
flg:flip(76)
would work
but i think this would be better yet:
Code: [Select]
flg:set(1,0) --not dead
flg:set(76,1) -- is ghost
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #129 on: December 15, 2010, 07:10:46 am »

hey I got a silly idea if you create a fort, then use turn the site into a hamlet, then dump a companion there will the companion become the inn keeper of the place making it save for sleeping or do we have to add the "is resident" flag on(I still couldn't find the Zombie/skeleton flags but found the 'wagon' 74 flag)?
70
also thanks for the quick fix.

edit:new discovery today
if a creature that was classed as a pet dies from abandonment when revived they will have all limbs non damaged.
so this might mean there is hope for a full revival with out the harsh effects of death.

edit: well after checking the wiki it's 12 and 13 which are the zombie and skeleton flags.
Hmm I got a working zombie revival but the kicker is that In adventurer mode harming the same creature twice will lead to a crash as found out again from having my awesome BogeyHuman go nuts after the zombie orc who body was turn into a bag little while after his death (made by his killer the bogeyhuman)
Code: [Select]
function adv_tools.undead()
--this will revive a dead soul from the grave as a somewhat zombie... chances of it following you not so much
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff+16,ptr_vector)
indx=GetCreatureAtPos(getxyz())
flg=engine.peek(vector:getval(indx),ptr_Creature.flags) --get flags
flg:set(1,0)
flg:set(12,1) --note this person is now part live mostly part dead to fully rez further test on bringing back body parts will be needed.
engine.poke(vector:getval(indx),ptr_Creature.flags,flg) --save flags
end


been testing something I wonder would this code scan all creatures in the area then select them?
it's for a zombie mod I'm pitching in for.
Code: [Select]
function tools.selectall(vector)

tnames={}
rnames={}
--[[print("vector1 size:"..vector:size())
print("vector2 size:"..vector2:size())]]--
for i=0,vector:size() do
--print(string.format("%x",vector:getval(i)))

local name=engine.peek(vector:getval(i),ptt_dfstring):getval()
tnames[i]=name
rnames[name]=i
end
end
indx=rnames[r]
if indx==nil then return
end
end
return indx
end
function tools.zombiemode()
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff+16,ptr_vector)
indx=tools.selectall(vector)
lzombie=engine.peek(vector:getval(indx))
flg=engine.peek(vector:getval(indx),ptr_Creature.flags)
if ~=flg:(1,1) then
flg:set(1,0)
flg:set(12,1)
flg:set(17,1)
end
end
engine.poke(vector:getval(indx),ptr_Creature.flags,flg) --save flags
end
end
I kinda got a little 'End' happy here.
« Last Edit: December 18, 2010, 02:48:49 am by Rumrusher »
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #130 on: December 21, 2010, 06:58:05 pm »

What do you mean scan them and select them? Do you mean scan them (check if they have some flag) and then select them (form a list of them?) if so this should do the trick:
Code: [Select]
function selectall()
  local retvec={} --return vector (or a list)
  myoff=offsets.getEx("AdvCreatureVec")
  vector=engine.peek(myoff+16,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) then  --if dead ...
        tables.insert(retvec,off)--... add it to return vector
     end
  end
  return retvec --return the "return vector" :)
end
and then using it:
Code: [Select]
deadthings=selectall()
for _,v in pairs(deadthings) do
  flg=engine.peek(v,ptr_Creature.flags)
  flg:set(1,0)
  flg:set(12,1)
  engine.poke(v,ptr_Creature.flags)
end
things like these make me wish that it would be possible to trigger lua scripts from DF (e.g. drop an idol-> a slave zombie army, throw a coin-> summon a golem, eat some creature flesh-> turn into a ghost :) )
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #131 on: December 21, 2010, 08:47:43 pm »

sweet thanks.

wait so do you have "dead things" separate or do I have to shove it into a function.
because I just added these two and it didn't work.
« Last Edit: December 22, 2010, 07:17:10 am by Rumrusher »
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #132 on: December 22, 2010, 08:12:42 am »

deadthins is a list thats returned by selectall() (weell maybe a better name would be more informative e.g. selectdead() )
you could try (full function now) :
Code: [Select]
function tools.zombiemode()
 
for _,v in pairs(selectall()) do
  flg=engine.peek(v,ptr_Creature.flags)
  flg:set(1,0)
  flg:set(12,1)
  engine.poke(v,ptr_Creature.flags)
end
 
end
Oh and sorry that it did not work (i am not in university and can't test it)
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v2.2
« Reply #133 on: December 26, 2010, 04:19:00 pm »

I was testing the Site changer and found that you best not over lap a hamlet over a abandon fort or you will end up with the game returning the land to before you embark on it and lose the ability to rest and retire let alone travel out. So pretty much with that in mind it's pretty easy to set up a Hamlet near a lair for saving/retiring and proper roof over your head. That and picking a house with out a owner(s) means you can sleep with out fear of being kick out when you wake up.
so any research on sites recently?
Logged
I thought I would I had never hear my daughter's escapades from some boy...
DAMN YOU RUMRUSHER!!!!!!!!
"body swapping and YOU!"
Adventure in baby making!Adv Homes

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v2.3
« Reply #134 on: December 27, 2010, 07:56:23 pm »

No not really. I could make site flag editing easier, but as far as i tried it does nothing good (although fun things like setting shops happens sometimes...)

Edit: here. Updated. Using it is simple, select site (just as awkwardly as site changer) and then you can flip the flags by typing its number. Maybe some flag could change if items are scattered or not, but i think i tried them all.
« Last Edit: December 27, 2010, 08:36:30 pm by darius »
Logged
Pages: 1 ... 7 8 [9] 10 11 ... 38