Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Is there a template or a tutorial for adding new binpatches to DFHack?  (Read 1725 times)

flarn2006

  • Bay Watcher
    • View Profile

What's the easiest way to add a custom binpatch to DFHack? I assume I'd create some kind of script or plugin. Is there a tutorial to do this somewhere? And would I be able to have it search for surrounding bytes as well, so it will probably still work even if the addresses change?

The reason I'm asking is because I found the bytes to change to remove the constraints from values in the advanced map parameters menu, and I'd like to make that easy to apply using DFHack, so I don't need to do it in Cheat Engine every time.

In case anyone's interested, here's the relative addresses of the instructions (in RAM, not the EXE) in v0.40.24, as given by CE:

  • "Dwarf Fortress.exe"+1AA882 (mov [eax],ecx)
  • "Dwarf Fortress.exe"+1AA862 (mov [eax],ecx)
  • "Dwarf Fortress.exe"+1AA83A (mov [ecx],eax)
  • "Dwarf Fortress.exe"+1AA846 (mov [eax],esi)

To disable the constraints, just replace all those instructions with NOP's. They're all two-byte instructions, so for those unfamiliar with assembly, just write the bytes "90 90" at each of those locations.

EDIT: The wiki says that the binpatches can be found in the "hack/patches" directory, but there's no "patches" directory in the "hack" directory.

Also, here's the list of offsets to patch in the EXE file if you want to make this permanent.
Code: [Select]
001A9C3A: replace 89 with 90
001A9C3B: replace 01 with 90
001A9C46: replace 89 with 90
001A9C47: replace 30 with 90
001A9C62: replace 89 with 90
001A9C63: replace 08 with 90
001A9C82: replace 89 with 90
001A9C83: replace 08 with 90
« Last Edit: May 27, 2015, 03:41:29 am by flarn2006 »
Logged

mifki

  • Bay Watcher
  • works secretly...
    • View Profile
    • mifki

I may be wrong, but probably there's no binpatches anymore because all the bug either have been fixed, or not patches not ported to 0.40.
I can see that data structures of the advances worldgen screen are not available in dfhack, so maybe better to work on this, so that parameters could be changed just in memory without need for binpatches?

flarn2006

  • Bay Watcher
    • View Profile

The binpatches I found actually let you set the parameters beyond the limits given using the existing UI. No need to design a separate UI to set them to otherwise-impossible values if there's an otherwise perfectly good one built in.

I assume I need to create the "patches" folder, but what should I put in it? The "binpatch" command is still recognized as a valid command (and binpatch.exe is there) so it's not like the functionality was removed from dfhack.
Logged

scamtank

  • Bay Watcher
    • View Profile

You don't have any older DFHack versions floating around? Anyway, there's this big wall of explanation and then a thing like this at the end (this one's the 40.24 weapon rack fix):

Code: [Select]
Dwarf Fortress.exe
005BF984: 8B 89
005BF985: 8C C1
005BF986: 24 90
005BF987: 80 90
005BF988: 00 90
005BF989: 00 90
005BF98A: 00 90
005BFA61: 8B 89
005BFA62: 8C C1
005BFA63: 24 90
005BFA64: 80 90
005BFA65: 00 90
005BFA66: 00 90
005BFA67: 00 90

Save the mess as a .dif file and put it in \hack\patches\v0.40.24 SDL. Now binpatch can grasp it.
Logged

flarn2006

  • Bay Watcher
    • View Profile

Oh, so there's no way to have it search for surrounding bytes to make it (mostly) version-independent?

What type of addresses are those though? Are they absolute memory addresses, or is it the number that would go after "Dwarf Fortress.exe+" in Cheat Engine?
Logged

scamtank

  • Bay Watcher
    • View Profile

Uh, absolute. Just like the ones you tacked on the end of the OP.

And if binpatch "knew" what it was doing, it wouldn't have required someone to trudge through the .exe with a hex editor to find where the old haunts had jumped to.
Logged

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile

Oh, so there's no way to have it search for surrounding bytes to make it (mostly) version-independent?

What type of addresses are those though? Are they absolute memory addresses, or is it the number that would go after "Dwarf Fortress.exe+" in Cheat Engine?
There is a way. Do not be discouraged. Find it!

Spoiler (click to show/hide)

flarn2006

  • Bay Watcher
    • View Profile

Thanks for your help; I got it to work.

Code: [Select]
Dwarf Fortress.exe
001A9C3A: 89 90
001A9C3B: 01 90
001A9C46: 89 90
001A9C47: 30 90
001A9C62: 89 90
001A9C63: 08 90
001A9C82: 89 90
001A9C83: 08 90

Put that in hack/patches/v0.40.24 SDL/noparamlimits.dif, and type "binpatch apply noparamlimits".

I might look at the version-independent stuff later, but this will do for now.
Logged

scamtank

  • Bay Watcher
    • View Profile

Just out of morbid curiosity, what is this even for? I can't think of any kind of option in advanced worldgen where I could imagine going "if only this limiter wasn't keeping me down!"
Logged

megahelmet

  • Bay Watcher
  • *casts* Meteo!!
    • View Profile

Time to generate pocket worlds with 10,000 Volcanoes.

I want an embark with no less than three volcanoes on it.
Logged
Pylons on fire can stay, its awesome.

expwnent

  • Bay Watcher
    • View Profile

Looks handy.
Logged