Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3] 4 5

Author Topic: Relationships Utility  (Read 17453 times)

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Relationships Utility
« Reply #30 on: April 04, 2012, 08:58:35 am »

This interests me greatly, actually.  I've been extremely interested in memory diving.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #31 on: April 08, 2012, 03:00:01 pm »

Been playing with this again, any more info upcoming?
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #32 on: April 09, 2012, 02:00:29 am »

I've been extraordinarily busy and haven't had the time to finish the second part of the tutorial, but it's coming.  Thanks for the nudges, it gives me a bit more incentive to get back to work on it.  :)

I'm planning on investigating the DFHack C++ API for this too, when I find the time and energy.  If I do get around to that, I'll also probably be adding a DFHack utility to erase pregnancies and start them, unless that sort of thing already exists in another utility.
Logged
Through pain, I find wisdom.

caddybear

  • Bay Watcher
  • Elf Supporter
    • View Profile
Re: Relationships Utility
« Reply #33 on: April 09, 2012, 03:23:30 am »

Damn those pregnancies.
Logged
And then did ARMOK say, the east is the holiest of directions, and thou shouldst not stand there lest thou be strucketh down by my holiest of beards. And then did the dorfs did say, we shall build from the west, for more do we fear the beard of ARMOK than the strike of the elephant.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #34 on: April 09, 2012, 04:19:51 am »

That'd be a cool God-style power to have. I'm still interested in the power of being able to look up DF structures and do pretty much anything when I've got the hang of it. I'm going to try a few test things once I understand what I'm doing: changing a creatures actual... creature type, changing maybe a map tile into something else, things like that.
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Relationships Utility
« Reply #35 on: April 09, 2012, 11:12:49 am »

I've been extraordinarily busy and haven't had the time to finish the second part of the tutorial, but it's coming.  Thanks for the nudges, it gives me a bit more incentive to get back to work on it.  :)

I'm planning on investigating the DFHack C++ API for this too, when I find the time and energy.  If I do get around to that, I'll also probably be adding a DFHack utility to erase pregnancies and start them, unless that sort of thing already exists in another utility.

There exists two of those. One is 'catsplosion' (c++) gives all the cats pregnancy. And other is 'tools.empregnate(unit)' (lua) gives target unit pregnancy. If you want to do something please take a look at both (especially the c++ one). Here are the links: Lua and i suggest joining the dfhack irc channel:Somewhere here because i can't currently find c++ code (could be it was not ported over to new api)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #36 on: April 14, 2012, 06:43:56 pm »

Apologies again for not following through with this yet.  I'm currently working on the second part of the tutorial, which I plan to have up in a couple of days at the latest.  I originally performed this in .31.25 and some things were moved around in .34.x so I'm having to spend a little time perfecting things.

Also, thanks for the links Warmist, I'll definitely take a look at those and see about integrating them into tools too.  I took some time looking at the C++ API for DFHack, and it looks like it shouldn't be overly difficult to do this in DFHack, so I'm definitely going to work on a tool sooner than later.
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #37 on: April 17, 2012, 01:46:45 pm »

Didn't realise you'd posted! Waiting and brute forcing... ;P
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

caddybear

  • Bay Watcher
  • Elf Supporter
    • View Profile
Re: Relationships Utility
« Reply #38 on: April 17, 2012, 02:25:39 pm »

Thanks, even if you don't come through with it, real life and all.
Logged
And then did ARMOK say, the east is the holiest of directions, and thou shouldst not stand there lest thou be strucketh down by my holiest of beards. And then did the dorfs did say, we shall build from the west, for more do we fear the beard of ARMOK than the strike of the elephant.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #39 on: April 19, 2012, 09:01:39 pm »

So, I've spent a lot of time trying to adapt this to .34.x and I'm not having a lot of success with it.  :-\  Either I'm doing something not quite right, or something has changed significantly in .34 regarding historical figure relationships such that this doesn't work anymore.  I'm going to keep fooling around with it when I have a minute, but if I can't figure it out I can show how I did this for .31.25 at least.

I'm hoping that writing a DFHack plugin for this will get around the problem, since I'm probably just doing something wrong that DFHack abstracts away.
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #40 on: April 24, 2012, 12:53:59 pm »

Well, still interested in the possible power of a DF Hack plugin.
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #41 on: May 10, 2012, 12:33:16 am »

Hacking Relationships, Part 2

Profuse apologies for this being so, so late, but I managed to figure out what I was doing wrong and have prepared part 2 as I promised long ago!  The programmers among you will probably find some of this a bit of a bore, or find errors in my reasoning, terminology or methodology.  If so, do let me know.

If you've been following up to this point, you should be able to find a creature's historical figure entry in memory.  I believe I may have misled you in part 1, as the way the historical figure entries look is different in .34 and I got a bit confused.  I'll fix it soon.  Anyway, below is what a real historical figure entry looks like:



In this picture, you can see all of Victim A and Victim B's historical figure entries.  You'll have to search for these like I explained in part 1, and they may not be consecutive!  There are two values I've highlighted, because they're important.

The value highlighted in red is the creature's Historical Figure ID.  This is the value that the game needs to identify a historical figure, and is how it links them together.

The value highlighted in green is part of an STL Vector that stores pointers to Historical Figure Links.  There are actually a few details about this that you might find interesting, but aren't extremely important for what we're doing.  I'll go into it anyway for those who care:

An STL Vector is a special type of array that has some code to automatically manage its location in memory as it grows.  For our purposes, what we care about are the three pointers that are used to store a vector.  You can see these as the three 4-byte values in sequence.  The first two pointers point to the beginning of the vector, and the last points to the end.  You can tell how many elements are in a vector by subtracting the start from the end and dividingy by the size of the element.  In this case, Victim A has two links: subtracting the values gives 8, and each entry is 4-bytes long (the size of a 32-bit pointer).

Anyway, you'll need to follow this pointer to get to the historical figure links.  To follow the pointer, you're going to have to juggle the numbers a bit because of endianness.  The reason the values are jumbled has to do with the processor's architecture, but that need not detain us at this juncture.  All you need to know is that the pointer is stored in reverse in memory.  So, while you see:

E0 8E D8 1D

What you really want is:

1D D8 8E E0

Just reverse the order of the bytes (not the characters of the hex values themselves!) and you get the pointer you're looking for.  You can follow this pointer by hitting the second button in the hex editor window (circled in red below) and entering the pointer.  I recommend opening a second hex editor window for this purpose.  Here's an example of what I get by following this pointer:



Highlighted in green are the two pointers to the actual links themselves.  Right now, there's no real way to just add new entries, only replace existing ones.  By following either of these pointers, you will arrive at the link itself, which looks something like the screen below:



There's only two parts to the link that we care about (there might be more to it, but I haven't deciphered the rest and it doesn't matter anyway).  The first part, highlighted in green, is the Link Type.  This is a pointer to... something.  I hate to admit that I actually don't know what this points to.  Regardless, this is what determines whether you see Deity, Object of Worship, Lover, Spouse, Child, or whatever else in the relationships screen.

The second part, highlighted in red, is the Historical Figure ID.  Remember this?  Yep, it's the value from before that we got from the historical figure structure.  So, just to fool around, let's try changing that to the value for Victim A's historical figure: 8C 00 00 00 (remember this will be different for you!).

You can see on the left that I changed the old historical figure ID to be that for Victim A: 8C 00 00 00.  If you go to the relationships screen for Victim A, you'll see he worships himself!  That's not quite what we're aiming for, so let's change that to Victim B.  To do that, just change the value to Victim B's historical figure ID.  For me, that's: 8D 00 00 00.  How convenient!  Don't expect it to be so convenient for you though, especially for running games.



Ah, that's more like it.  We're just one step away from what we need: changing the type to that of a spouse, not a thing to worship (joke however you will).  Unfortunately, I'm stuck at this point at the moment.  In existing games, what I've done is look up the value for the type for the type of the relationship I was interested in, where it already existed.  That is, if in a game I already had some married dwarves and wanted to marry more, I'd just look up the value for the type for the married dwarves by following the pointers, then go and set it for the dwarves I was interested in.

A word of warning: You can change the Historical Figure ID while viewing the relationships page.  If it's a bad value, nothing goes awry and the game just ignores it.  However, changing the Type while viewing the relationships page will crash the game!  Furthermore, changing the Type to something that's not valid will also promptly crash the game!  This is because you're changing pointers, and the game tries to reference it, gets garbage and the OS terminates the program to protect the rest of the running software.  Changing it to a good value is fine, but a bad one is a no-no.

Regardless, now that you know 90% of what to do to set what shows up on the relationships page, there's one more piece of the puzzle to actually have dwarves be considered married for the purposes of producing children.  This seems to be something most people want to avoid these days, but in case you're interested, you need to set the value of the Spouse ID in the original creature struct.  This is actually much easier to do, but I haven't pinned down the location for .34.x yet, so I'll have to show you how to do this in Part 3!

I know, I'm sorry for being a tease.  With what I've given you so far though, you should have some idea of how this stuff is stored in memory and can probably do a bit of exploring yourself.

Part 3 will contain at the very least how to set the Spouse ID, but I also plan to include how to find the type you're looking for.  That's something I never did the hard way for .31.25, so it's new ground for me too.  As a bonus, I'll show you how to cancel pregnancies, cause a dwarf to give birth immediately, or steal pregnancies from other dwarves!

Part 3 should be up in a few weeks at the rate I'm working on this.  :)  A plugin to do this automatically should follow within the decade.  :P
Logged
Through pain, I find wisdom.

Trapezohedron

  • Bay Watcher
  • No longer exists here.
    • View Profile
Re: Relationships Utility
« Reply #42 on: May 10, 2012, 01:23:25 am »

This is most interesting. Please post more, and take your time.

Also, you might want to put links on the OP, and revise the OP a bit.
Logged
Thank you for all the fish. It was a good run.

expwnent

  • Bay Watcher
    • View Profile
Re: Relationships Utility
« Reply #43 on: May 10, 2012, 05:22:12 pm »

Looks very interesting. I've been meaning to do some science on what traits are hereditary. This will make things easier.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #44 on: May 10, 2012, 05:40:39 pm »

This is most interesting. Please post more, and take your time.

Also, you might want to put links on the OP, and revise the OP a bit.

Thanks.  I do intend to organize this a bit better once it's complete.  I need to clean up something in the first part, and I could probably rewrite part of the second part to make it more clear what I'm doing and why in regards to the pointers and such.

And yes, in the time it took me to write that, I could have already revised my first post and put in the links to the two parts. :)
Logged
Through pain, I find wisdom.
Pages: 1 2 [3] 4 5