Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Is there a way to read the SIEGE tag somewhere using DFHack or other methods?  (Read 861 times)

PMental

  • Escaped Lunatic
    • View Profile

Hi,
First post here.

I'm currently working on a game addon where I will need to know when a siege/invasion ends. When the SIEGE tag disappears more or less.

I've searched this forum, looked through game files, DFHack etc, and I just can't find it anywhere.

Does anyone have a clue how this could be found (for a running game) via script/DFHack/other hack etc?
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions

In theory, any status reported by the game can also be detected by DFHack - it's just a matter of knowing how the game performs the check and then duplicating that check in DFHack.

In the case of the "SIEGE" indicator, you need to iterate across df.global.ui.invasions and examine each record until you find one with civ_id != -1 and flags.active == true and flags.siege == true.
I figured this out by opening the 64-bit Windows version of v0.47.04 in IDA Freeware 7.0, running some scripts to import the structure definitions and locate the globals, then searching for the code that displays the " SIEGE " indicator.
« Last Edit: September 23, 2020, 04:15:27 pm by Quietust »
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.

PMental

  • Escaped Lunatic
    • View Profile

Thanks a lot!

I now have a working LUA-script that returns true or false based on those variables and with the few test saves I have it seems to work so far at least.

If you don't mind, could you expand a bit on these parts:

I figured this out by opening the 64-bit Windows version of v0.47.04 in IDA Freeware 7.0, running some scripts to import the structure definitions and locate the globals, then searching for the code that displays the " SIEGE " indicator.

I downloaded the software, opened the df exe and looked around, but while I can search, I don't see much to relate it back to dfhack which I'm guessing is the lack of said structure definitions.
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions

Thanks a lot!

I now have a working LUA-script that returns true or false based on those variables and with the few test saves I have it seems to work so far at least.

If you don't mind, could you expand a bit on these parts:

I figured this out by opening the 64-bit Windows version of v0.47.04 in IDA Freeware 7.0, running some scripts to import the structure definitions and locate the globals, then searching for the code that displays the " SIEGE " indicator.

I downloaded the software, opened the df exe and looked around, but while I can search, I don't see much to relate it back to dfhack which I'm guessing is the lack of said structure definitions.

The structure definitions are all found in the DFHack/df-structures GitHub repository. You'll need a suitable version of Perl in order to make proper use of them, as mentioned in the DFHack build instructions.

There are also several important scripts in the DFHack/df_misc repository, some of which require Ruby and the metasm module:
  • dump_df_globals.rb - run it against the Dwarf Fortress EXE with the "--idc" output to produce a bunch of "MakeName(...);" lines, which you then copy/paste into IDA's "File -> Script command" window. This will assign labels to all of the global variables.
  • codegen_c_hdr.pl - copy into the "df-structures" repository, run codegen.pl, then run codegen_c_hdr.pl codegen\codegen.out.xml codegen_win64.h, and finally feed that into IDA's "File -> Load File -> Parse C header file".
  • ms_rtti64.idc - just feed this directly into IDA's "File -> Script file" and wait a minute or so. This will identify all of the virtual classes used in DF (such as building and item subtypes) and make it a bit easier to find some things.
Note that the version of codegen_c_hdr.pl in the repository doesn't actually work right now, since it hasn't been kept up-to-date with updates to the structures XML format. I'll see if I can remedy that in the near future.

Of course, once you've done those setup tasks, there's still the matter of learning how to locate relevant code and figure out what it's doing, but entire books could be written on such topics and I don't have the time to do that right now.
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.

PMental

  • Escaped Lunatic
    • View Profile

Awesome thanks, may come in handy in the future.
Logged