Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Question about standalone apps (Therapist, DFHack)  (Read 426 times)

Vndetta

  • Bay Watcher
    • View Profile
Question about standalone apps (Therapist, DFHack)
« on: June 29, 2012, 09:19:20 pm »

Alrighty, here goes. I apologize profusely in advance!

How, generally, do standalone programs like Dwarf Therapist actually work? I essentially need to know where in the game data these esteemed programmers are telling their program to look for the information of a currently-running-in-the-background game. I feel like if I knew where it was pulling the info from I could get to working on the "how".

I've looked all around and had trouble coming up with an answer; I am not very familiar with GitHub and so far haven't seen a full-on "packaged" source code that would be understandable enough to pick apart and find out. There's tons of info about modifying raws and creating reactions and such but this seems to be something entirely different.

Anyway, if anyone can provide any information on this or point me in the right direction I'd be so grateful. In case anyone is wondering, I have noticed two things I'd like to do - 1) Code something in the Dwarf-Therapist-vein that can see dwarf preferences and 2) Code something for Adventure Mode that can display and hopefully interact with the player's inventory, GUI-style.
« Last Edit: June 29, 2012, 09:24:23 pm by Vndetta »
Logged

Hugo_The_Dwarf

  • Bay Watcher
  • Modding Mentor
    • View Profile
    • Regeneration: Forced Evolution
Re: Worst vague question ever!
« Reply #1 on: June 29, 2012, 09:21:45 pm »

you should post this question in the DFhack thread, they should help you out there, unless an esteemed member that has great know how in this walks by and notices this.

http://www.bay12forums.com/smf/index.php?topic=91166.0
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: Worst vague question ever!
« Reply #2 on: June 29, 2012, 09:24:30 pm »

Yeah, DFhack is the way to do if you're starting out. It has access to most of the data in DF already, and has a more or less easy to use API.
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Question about standalone apps (Therapist, DFHack)
« Reply #3 on: June 29, 2012, 10:32:39 pm »

Dwarf Therapist and DFHack use two completely different methods of getting at Dwarf Fortress's data.

Dwarf Therapist uses OpenProcess() and ReadProcessMemory()/WriteProcessMemory() to peek/poke Dwarf Fortress's memory as if it were a debugger. While it can be safer, it's also much slower and it requires you to know the offset of each individual field within each structure you want to access.

DFHack, on the other hand, loads itself into Dwarf Fortress by pretending to be SDL.dll (and similar tricks on Linux/OSX). It has the advantages of speed and versatility (everything within Dwarf Fortress is accessible through global variables, assigning new values takes effect immediately, allocating new memory is trivial, and you can even execute some parts of DF's code arbitrarily) while being slightly more dangerous - just like any normal program, attempting to access invalid memory can and will crash the game itself, so you have to be careful about what you do.
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.