Bay 12 Games Forum

Dwarf Fortress => DF Modding => Utilities and 3rd Party Applications => Topic started by: flarn2006 on May 27, 2015, 12:47:30 am

Title: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: flarn2006 on May 27, 2015, 12:47:30 am
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:


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
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: mifki on May 27, 2015, 01:22:28 am
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?
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: flarn2006 on May 27, 2015, 03:30:04 am
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.
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: scamtank on May 27, 2015, 06:34:44 am
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.
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: flarn2006 on May 27, 2015, 11:49:50 pm
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?
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: scamtank on May 28, 2015, 05:43:02 am
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.
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: Warmist on May 28, 2015, 05:49:59 am
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)
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: flarn2006 on June 03, 2015, 04:16:31 pm
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.
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: scamtank on June 03, 2015, 06:20:25 pm
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!"
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: megahelmet on June 08, 2015, 01:38:36 am
Time to generate pocket worlds with 10,000 Volcanoes.

I want an embark with no less than three volcanoes on it.
Title: Re: Is there a template or a tutorial for adding new binpatches to DFHack?
Post by: expwnent on June 13, 2015, 04:12:15 am
Looks handy.