Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Help with basic memory hacking  (Read 1094 times)

Moriabbey

  • Escaped Lunatic
    • View Profile
Help with basic memory hacking
« on: October 01, 2018, 09:54:37 pm »

Hi all,
I'm in a college assembly programming class, and for a project I thought it'd be fun to do some Dwarf Fortress memory hacking. I figured, DFhack has been around for years, it's well-documented, surely it can't be too hard to go over their code and figure out enough to make something with basic functionality.
Unfortunately, I've spent most of the weekend doing just that, and I don't feel any closer to really understanding or being able to do anything. So, does anyone have any experience memory hacking without DFHack? Or, do you know any good resources for doing it? I don't need to be able to do anything spectacular, just reading some basic map information from memory would probably be fine for now.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Help with basic memory hacking
« Reply #1 on: October 02, 2018, 09:45:06 am »

What exactly are you trying to do?  Write a program that manipulates DF's memory directly like DFHack does?  If so then the hardest part is probably going to be injecting your code the way DFHack does.  DFHack does that by DLL injection (on Windows anyway), if I remember right, where it ships with a special version of the SDL DLL.  You replace the existing version with that one, and DF will load the new DLL and execute DFHack's code alongside the SDL code it needs.  This is necessary because of memory protection, since otherwise any attempt by your program to edit memory in DF would end up with the OS killing your program.

An alternative you can look at is how memory editing tools and cheat engines do it.  I believe they launch other programs as a child process so that they can share memory safely, but I've never tried this before so I don't know how it works exactly.

If you just want to fool around with editing DF's memory to see things happen in game, you can use memory editing tools to bypass the code injection headaches.  From there, it's a matter of locating the correct data structures in memory, which can be a challenge in and of itself, but searching for known values like dwarf nicknames will help.  The data structure layouts used by DFHack, accessible here: df-structures will help a lot once you get to that point if you have a good grasp on how data is laid out in memory.
Logged
Through pain, I find wisdom.