Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 24 25 [26] 27 28 ... 38

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

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #375 on: July 13, 2011, 07:33:39 am »

uhh darius you have a goof with the adventure tools
Code: [Select]
function adv_tools.ressurect()
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff,ptr_vector)
indx=GetCreatureAtPos(getxyz())
if indx<0 then indx=0 end
--print(string.format("%x",vector:getval(indx)))
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,0) --ALIVE
    flg:set(39,0) -- leave body yet again
    flg:set(37,0) -- something todo with wounds- lets you walk again.
    engine.poke(vector:getval(indx),ptr_Creature.flags,flg)
end

the flags are following the 1,0 coding where as the dfflag follows the true or false triggers.
what this leads to is the utility not knowing what to do and making all flag commands flip than set accordingly.
Code: [Select]
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
the fix here would be to go through adventure tools and rewrite all the 0 and 1 to true and false.

Code: [Select]
function adv_tools.ressurect()
myoff=offsets.getEx("AdvCreatureVec")
vector=engine.peek(myoff,ptr_vector)
indx=GetCreatureAtPos(getxyz())
if indx<0 then indx=0 end
--print(string.format("%x",vector:getval(indx)))
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.
    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
which I did to save time in doing so.
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

The Master

  • Bay Watcher
  • A respectable sort of psychopath
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #376 on: July 13, 2011, 04:36:13 pm »

Spoiler (click to show/hide)
Rum's rough guide to Dfusion
if you can't do anything of these things then type out the first error you see and either Darius or I/me will answer.
if you excuse me I need to rest my wrist for writing up this "'non-developer' guide."
sorry, but what...? I barely understood ANY of that! try to fix your typos.
« Last Edit: July 13, 2011, 04:38:58 pm by The Master »
Logged
Holy jesus I thought I was ready but nothing could have prepared me for this
Hush, little Asea, don't you cry.
If he notices we'll surely die!
You. Made. Asea. CRY.

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #377 on: July 13, 2011, 08:56:33 pm »

you mean the typos in the readme sections or the grammar errors that I might have missed while typing?
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 v3.8
« Reply #378 on: July 15, 2011, 04:29:58 am »

This project is now officially open source (in github)
Logged

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFusion - a lua based plugin system v3.8
« Reply #379 on: July 15, 2011, 04:46:08 am »

This project is now officially open source (in github)
Now THAT is awesome. I'll see what could be done about putting this into the new dfhack as a plugin when I'm done with what I'm working on right now (adding a thread-safe console)

EDIT: hmm... I don't know where I'd start either. This will need some serious research :)

Hmm.. let me explain stuff better. The new dfhack basically lives inside DF. A dfhack plugin can stop DF and take complete control over it. This means full access to everything, as long as you can find it (have the offset) and describe its layout in C++ types (the actual layout of objects can be left to the compiler). All this is done in sync with DF and it's thread-safe, so you can be *SURE* you'll never, ever break things because of some timing problem. You can use malloc/free/new/delete on DF's memory, because it's also your memory.

This new dfhack has a few extra bits:
A (in the near future thread-safe) console you can type in commands exported by the plugins.
It listens for the zoom hotkeys of DF and can invoke commands by name when the player pushes those hotkeys - this is F1-F8 and Shift+F1 - Shift-F8. Commands can be assigned to them using the in-game hotkey menu.
The plugins can have a function that's run after DF completes every game step.

DFusion (or some kind of similar LUA thing) would be a DFHack plugin, exporting various commands, so they can be invoked by the console or from the hotkeys. Some parts of DFusion would need tweaking, some don't really make sense - this needs research. If you're OK with it though :)
« Last Edit: July 15, 2011, 06:14:36 am by peterix »
Logged

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #380 on: July 15, 2011, 07:35:11 am »

This project is now officially open source (in github)
Now THAT is awesome. I'll see what could be done about putting this into the new dfhack as a plugin when I'm done with what I'm working on right now (adding a thread-safe console)

EDIT: hmm... I don't know where I'd start either. This will need some serious research :)

Hmm.. let me explain stuff better. The new dfhack basically lives inside DF. A dfhack plugin can stop DF and take complete control over it. This means full access to everything, as long as you can find it (have the offset) and describe its layout in C++ types (the actual layout of objects can be left to the compiler). All this is done in sync with DF and it's thread-safe, so you can be *SURE* you'll never, ever break things because of some timing problem. You can use malloc/free/new/delete on DF's memory, because it's also your memory.

This new dfhack has a few extra bits:
A (in the near future thread-safe) console you can type in commands exported by the plugins.
It listens for the zoom hotkeys of DF and can invoke commands by name when the player pushes those hotkeys - this is F1-F8 and Shift+F1 - Shift-F8. Commands can be assigned to them using the in-game hotkey menu.
The plugins can have a function that's run after DF completes every game step.

DFusion (or some kind of similar LUA thing) would be a DFHack plugin, exporting various commands, so they can be invoked by the console or from the hotkeys. Some parts of DFusion would need tweaking, some don't really make sense - this needs research. If you're OK with it though :)

I'll try to make it more tidy in few days to come. There is a lot of stuff that need to be rewriten (e.g. Lune- lua-cpp object inteface, functional - useless not working and depending on debuger, Debuger- could be removed mostly used for allocate (which is not needed in DFHack) and so on...)

Straight DFusion to DFhack plugin transformation would need some way to search memory. Been using 0x517A5D hexsearch.h (although writen in C it takes care of lot of stuff). Afaik DFHack already has memory modification tools. Also Offset manager could be discarded an DFHack's internal used and so on.

I could try to fork DFHack and implement some sort of Lua interface for some of functions, but I'm not sure which to fork (there are a lot of forks :) )
Logged

thatkid

  • Bay Watcher
  • <Servibot> thatkid, swag percentiles: 94
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #381 on: July 16, 2011, 01:17:20 pm »

Uh, hey.
When I run DFusion in Wine, the following comes up: http://img801.imageshack.us/img801/8826/dfusionwine1.png
I'm not running an adventurer at the moment, so I can't get another screenshot but I get a similar error message when I try to switch companions.
Logged
Fame is a vapor. The only earthly certainty is oblivion.

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v3.6
« Reply #382 on: July 16, 2011, 01:41:50 pm »

:-[
i forgot to fix += somewhere in code before releasing.

Change self.en+=engine.sizeof(self.type) into self.en=self.en+engine.sizeof(self.type) in patterns.lua for now...
yeah that was address a couple of pages ago.
here's darius fix on it.
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

thatkid

  • Bay Watcher
  • <Servibot> thatkid, swag percentiles: 94
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #383 on: July 16, 2011, 03:47:38 pm »

Thanks :D
It works now, though it can't find the thread. This is likely a problem with WINE and the fact that I'm running DF outside of WINE as opposed to an issue with DFusion.
Logged
Fame is a vapor. The only earthly certainty is oblivion.

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #384 on: July 16, 2011, 04:01:35 pm »

Thanks :D
It works now, though it can't find the thread. This is likely a problem with WINE and the fact that I'm running DF outside of WINE as opposed to an issue with DFusion.
nah this issue was a DFusion one given I had it too and I'm not running on a mac.
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

thatkid

  • Bay Watcher
  • <Servibot> thatkid, swag percentiles: 94
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #385 on: July 16, 2011, 04:02:40 pm »

Thanks :D
It works now, though it can't find the thread. This is likely a problem with WINE and the fact that I'm running DF outside of WINE as opposed to an issue with DFusion.
nah this issue was a DFusion one given I had it too and I'm not running on a mac.
No, I meant the original issue is solved thanks to the info you provided. DFusion can't find DF now though, and that's probably a problem with wine
Logged
Fame is a vapor. The only earthly certainty is oblivion.

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #386 on: July 20, 2011, 03:18:01 pm »

oh I just found out that pets can be brought back to life if they where abandon/retired killed and won't be killed again once you return to the same fortress in adventurer mode if you travel around.
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

babies

  • Escaped Lunatic
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #387 on: July 29, 2011, 02:35:30 am »

I just found this healing script in a much older thread by rumrusher.

Spoiler (click to show/hide)

In a way that even a simple idiot like me could follow, how do I implement this using DFusion?
Logged

Rumrusher

  • Bay Watcher
  • current project : searching...
    • View Profile
Re: DFusion - a lua based plugin system v3.8
« Reply #388 on: July 29, 2011, 10:55:25 am »

first take the function title,
copy it and scroll down to the part where it shows

if not(FILE) then -- if not in script mode

look at how the commands for the other functions are and try to recreate the same line for that function.



Take the line of code where it say "makes them breathe" and "gives them sight" 
paste that in the same spot in the original adv_tool resurrect
for all I did was take the original and added some missing flags due to people tend to suffocate or come out blind when I revive them.
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 v3.8
« Reply #389 on: August 04, 2011, 04:50:41 pm »

DFusion is dead. Long live DFusion! :D

Just a quick note that currently i'm stopping development of dfusion and resuming it as DFHack plugin. Future holds very awesome things, currently it's only +- working port of dfusion. For those who can compile and know how to use CMAKE n friends: code is here.  For others i'll release it sometime later. Maybe when linux support is minimal because now only thing thats better is OnTick function that is called every <some> tick (each tick was too lagy).

Edit: oh and remembered another plus of moving into DFhack- now memory lookups are way faster but not safe (could crash program- before returned 0)
« Last Edit: August 04, 2011, 04:56:26 pm by darius »
Logged
Pages: 1 ... 24 25 [26] 27 28 ... 38