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 17451 times)

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #15 on: March 24, 2012, 05:35:12 pm »

Then that would be very useful, along with a suggested memory editor, as I don't have one currently.
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.

NobodyPro

  • Bay Watcher
    • View Profile
Re: Relationships Utility
« Reply #16 on: March 24, 2012, 06:20:58 pm »

Ooh, instructions please!
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Relationships Utility
« Reply #17 on: March 24, 2012, 06:56:59 pm »

I'd adore some instructions here and a quick rundown of how to use a memory editor.  That's been about the only thing stopping me from really abusing plugin ideas - lack of understanding on memory hacking.

Coincidentally, if this works as intended, you could realistically create warrior nuns, who are "married" to a deity and then assigned to a squad.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #18 on: March 25, 2012, 02:28:32 am »

Ok, cool, I'll whip up a little tutorial when I get a chance then.  :D

And yeah, that should be possible Girlinhat.  I can't promise that the game will behave correctly forever if you do do that, such as crashing when a dwarf tries to get pregnant or something, but it should work from what I understand.  Would be funny if the dwarf got pregnant and had the baby naturally.  Blessed by her god!  It might even list the god as the parent... I know it's possible to set a relationship up that way manually.

I've tested marrying two dwarves this way, and the game hasn't crashed from it, and the relationship preserves when you save / load, so it should be fine from what I've seen.  I noticed the female had a miscarriage though, which I've never actually had happen before.  I don't think that's related, since she's in the militia, but it might be.

Anyway, tutorial forthcoming tomorrow if I can find the time!
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #19 on: March 29, 2012, 11:32:27 am »

Would you mind telling me if you expect to be able to get a tut. up in the next week or so? No pressure, but if you don't think you can then I might as well throw myself in at the deep end and try and learn manually. :D
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 #20 on: March 29, 2012, 12:11:39 pm »

I'd planned on getting something up this afternoon, but I'm notoriously bad at judging time frames for this sort of thing.  If you're interested in trying this out the hard way, here's my advice:

I used tsearch to do the memory manipulation.  Here's a link to it: http://www.timsvault.com/cheattools/tsearch.htm

The next bit of information you'll find helpful is the reverse engineered datastructures at df-structures: https://github.com/angavrilov/df-structures

Using the hex editor in tsearch, you can edit values while the game is running and see what happens.  By following the structure formats in the datastructures in the df-structures link, you might be able to figure some of it out.

More specifically, there are at least two lists of creatures: the creatures list itself and a historical figures list.  Inside the historical figures list entry for a dwarf, there is a pointer to another list of historical figures that are linked to it (gods and relatives, for example).  By following that pointer, you get to a list in memory of more pointers.  Each of those pointers then goes to a small datastructure detailing the type of link and the historical figure ID that it references.  You can then change the type and historical figure ID to do anything you want (warning: don't change these while on the dwarf's relationships page or you'll get a crash!  Change it while doing something else, then go to the relationships page!).

The easiest way to find a dwarf's entry is to search for their nickname in the hex editor.  You might come across a bunch of mentions of the dwarf before you find their creature entry this way, but when you do find it, it should be easy to recognize it in the future.  For example, you'll likely see a bunch of FF FF FF FF values right after their name.  In all of the cases where I did this search, the general creatures list came before the historical figures list (which has much smaller entries).

That probably didn't help as much as I'd hoped, but I'm planning on the tutorial having very detailed instructions (and pictures!) to help show you how to find these values, how to follow the pointers and how to safely edit the values.  A utility to handle all of this would be better, but I really don't think I'll have time to figure out DFHack well enough to do that any time soon.  Maybe someone with more time will be able to do that based on the instructions I provide here.
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #21 on: March 29, 2012, 01:48:44 pm »

Unfortunately I can only find the guy that I'm looking at's description and stuff. Not sure exactly what in ASCII I'm looking for to signify the relations pointers.

EDIT: After some looking through the units data structure I can see the relations, the lay out of data and pointers. Not really sure I understand it though I dare say I'd get it eventually (it's not that new to me), main issue is I still can't find the unit's actual historical entry in memory... anything specific I should be looking for? You say they have FFFFFF after their name... for you maybe, not for me!
« Last Edit: March 29, 2012, 02:05:12 pm by EmperorJon »
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 #22 on: March 29, 2012, 02:43:22 pm »

Ah, sorry, I should have specified that this is what you'd see in the hex values.  So, search for his nickname, then look at the corresponding hex values for it.  You should see a bunch of values like 20 2C 31 21 corresponding to the actual text, then a bunch of 00 00 or FF FF values filling out the rest of the name part of the structure.  If you look at the df-structures stuff you should be able to sort of figure out what the hex values mean and how they correspond to the actual name struct itself.

Anyway, as far as the historical figure entry, it should be fairly short and have the same sort of name structure as the main creature entry.  You will probably want to cross reference with the df-structures stuff to get a feel for how it's laid out.  In addition to finding the pointer to the actual links, you'll want to find the historical figure ID, which is also in that struct along with the creature's actual ID.

Hopefully I'll be able to give some better help and some visual aids when I get the actual tutorial up.

I actually need to verify this will work in .34.x.  I'm pretty sure it will, but all of my work has been in .31.25 and some of the structs have been adjusted a bit to allow for new things like curses.  The actual mechanics shouldn't have changed though.
Logged
Through pain, I find wisdom.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #23 on: March 30, 2012, 01:17:49 am »

Part one of the tutorial, as promised!  I'll get the rest of it up as soon as I can.

Before starting, you'll need a copy of TSearch.  You can grab it at: http://www.timsvault.com/cheattools/tsearch.htm

Hacking Relationships

In this tutorial, I'll be giving out a pretty basic overview of how you can hack some things in Dwarf Fortress, and give you specific instructions on how to change some things about dwarf relationships.  To start out, I genned a new world in .34.06 and embarked without fiddling with anything.  Here's my happy little dwarves, blissfully unaware that an unseen force will soon be meddling with their affairs.  This



Looking through my unit list, I've got 5 girls and 2 boys.  I picked out two suitable victims for some relationship hacking.  Although you can pick two of the same gender, I opted to avoid that territory by just picking a male and female.  For this technique, I nickname the victims to make finding them in memory easier.  Just for giggles, I nicknamed them Victim A and Victim B respectively.  Here's a couple of screenshots of their current relationships.




The important thing is that there is already a relationship link that can be hijacked (in this case, we'll be overwriting deity links), and the two aren't already lovers or married (would that even be possible when embarking?).

Anyway, fire up TSearch.  You should see a screen like the one below:



Once TSearch is up and running, hit the Open Process button and select Dwarf Fortress from the process list.  You won't see much change in the interface, but TSearch will now have attached to Dwarf Fortress and you can begin hacking away at stuff.  There is a search function for finding changing values in memory (works like the cheat generators in some console emulators), but we won't be touching that in this tutorial.

Instead, hit the Hex Editor button, which will open up a new sub window allowing you to view the entire process now in memory.  A sample of how it looks for me is shown below.  The two buttons shown below circled in green are going to be very handy.  The first lets you search for either a text string or a hex value, where the second will continue the search if you've got one running.

So, we're going to need to gather a bit of information about our two dwarves.  To do that, we'll need to find them in memory!  There is a science to this based on memory offsets, but I just use the art of searching for them instead.  To get started, let's search for our first victim, Victim A.  Hit the first search button in the hex window, and enter the dwarf's name like so:



When you hit Find Next, you should with some luck see something akin to this:



This is your dwarf's creature entry.  If you don't see this after the first search, hit the find next button to keep looking.  If you've got a game in progress already, there may be some logs or the like that you may have to wade through first.  Once you've found the creature entry, you should recognize it by it looking similar to that screen shot.  The slew of FFs in the hex view should help recognize it.

This isn't actually what we're looking for though!  What we need is the creature's historical figure entry, which at least in all of my searches comes after the creature entry.  So, hit the search next button again until you see an entry like this what's shown below.  It will look a lot like the previous screen, but the entry is much shorter.  You can tell because another dwarf's name will be shown shortly after the one you're looking for.



Congratulations, you've just found the historical figure entry for your first victim.  There are a number of pointers in this structure that lead to lists of several things, but what we're interested in is the list of links to other historical figures.  That is how the game keeps track of lovers, spouses, parents / children, deities, and supposedly apprentices in the latest version.

These are stored in an STL Vector.  Or, the vector stores pointers to them anyway.  The image below shows where you can find the pointer you need to trace, highlighted in the green box on the left.  You can open several hex editor windows by hitting the Hex Editor button, which can be tremendously useful when chasing pointers.  You can also jump to an address by hitting the button encircled by red below.



If you don't understand how I got that memory address from the highlighted value, I'll explain all of that in part two along with an explanation on how to actually change these things.  Unfortunately, it's quite late here and this is taking longer than I expected, so I'll have to split that into part two.  Coming tomorrow, I expect.

Stay tuned for part 2!

Sorry for being a tease.  I figured if I got this up tonight it would help keep me motivated to post the rest.  :)
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #24 on: March 30, 2012, 10:55:03 am »

Aha! That clears things up quite a bit, I was looking for their name in hex directly followed by FFs, I've seen a situation of the name popping up similar to this before. Now I just need to work out how far along I have to go to find the correct data I want to manipulate. Will report back my findings. ;)

EDIT: Yeah, no idea, hehe. I'm just not quite sure how the datastructure works. I can read through the file happily and see where it's talking about the relations, but have no idea how to work out how many values through it is and even if I could I don't know the unit id of the target unit... no idea where that's given!

EDIT2: More importantly I'm attempting a test now and don't know how to actually change values. It's really odd, the help just says "Enter a new value", and I do... and it changes, but not in memory eg. refresh and it reverts. It obviously doesn't run in real time, so how do I say "Ok, I stopped the program and made my changes, no replace the memory with these new values I've tinkered with"
« Last Edit: March 30, 2012, 02:15:15 pm by EmperorJon »
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 #25 on: April 03, 2012, 11:32:03 am »

I haven't forgotten about this. :)  Just ran into a bit of a hiccup applying this to a fort, and realized something that I thought was a constant was not.  I'm trying to work out how to calculate or locate the value needed for any given run of the game now.

To answer your questions, the easiest way to actually view specific values that occur at an offset from the start of a creature entry is to find the base address of the creature entry and add the offset.  To do that... search for the creature entry itself, then go back to the first character of their real name, not their nick name.  So, you should see something like this:

Code: [Select]
. . . . .  U r i s t . . . . .
V i c t i m . . . . . . . . .

The real start of the creature struct begins at the address of the U in Urist.  So, click on that character, and you'll see an address show up in the lower left corner of the hex screen.  Now, find the offset of the value you want in df-structures, or wherever else you find it, then use Windows calculator to add the hex values together (or the calculator of your choice).  Once you've done that, just scroll with the keyboard until you get to that memory address.  That will point you to the actual value (remember endianness, but this only really matters for pointers).

I don't remember the offset to the unit ID off hand, but I know you can use that technique to locate it.

To answer your second question, I've never had problems with adjusting values in the hex editor and having them take effect immediately in game.  My recommendation is to just pause Dwarf Fortress when fooling around with these things, then unpause it when you're done.  A word of warning about this: changing pointer values can cause crashes if the game isn't paused, and can cause crashes even if it is paused under some circumstances.  An example is actually changing relationship links: if you change the pointer value for the relationship type while viewing the creature's relationships screen, it will crash the game.

When I get the second part of the tutorial up, I'll show you precisely where the unit ID and historical figure ID are stored in the historical figure entry for the dwarf, how to follow the pointer to the historical figure links, and how to change them to new historical figure IDs or changing the types of the link.
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #26 on: April 03, 2012, 05:30:49 pm »

Thanks, clears something up...
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 #27 on: April 03, 2012, 06:25:05 pm »

You are doing this all wrong...

Either in c++ using DFHack: world->units->all[id]->relations (and there bunch of ids and other vectors)
Or DFHack/luawrapper: df.global.world.units.all[id].relations (again all the stuff)
you can get what fields there are (in lua) by:
Code: [Select]
unit=df.global.world.units.all[id]
for k,v in pairs(unit.relations) do
  print(k.."="..tostring(v)) --prints name and type(+pointer)
end
hope that helps and saves some time :)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: Relationships Utility
« Reply #28 on: April 03, 2012, 06:38:30 pm »

Yes, I know doing this in DFHack would be simpler, but I haven't had time to familiarize myself with its API, and there were some requests to show a more direct way of doing this.  It's debatable if this tutorial will actually teach anyone anything applicable outside of doing exactly what I write, but I'm willing to try anyway.  And I find it fun to poke around like this in the game directly, which a few others probably would too.  It's definitely more work and is error prone, but it's fun.

Actually though, I was unaware that DFHack had a C++ API.  If that's true, then I'm going to look into it sooner than later.  I was putting it off because I thought it only supported the scripting language API (Lua apparently).
Logged
Through pain, I find wisdom.

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Relationships Utility
« Reply #29 on: April 04, 2012, 07:54:23 am »

Ok, just a few short things as I'm still not sure I understand...
Code: [Select]
<bitfield-type type-name='unit_flags1' base-type='uint32_t'>
        <flag-bit name='move_state'
                  comment='Can the dwarf move or are they waiting for their movement timer'/>
        <flag-bit name='dead'
                  comment='Dead (might also be set for incoming/leaving critters that are alive)'/>
        <flag-bit name='has_mood' comment='Currently in mood'/>
        <flag-bit name='had_mood' comment='Had a mood already'/>

        <flag-bit name='marauder' comment='wide class of invader/inside creature attackers'/>
        <flag-bit name='drowning' comment='Is currently drowning'/>
        <flag-bit name='merchant' comment='An active merchant'/>
        <flag-bit name='forest'
                  comment='used for units no longer linked to merchant/diplomacy, they just try to leave mostly'/>

        <flag-bit name='left' comment='left the map'/>
        <flag-bit name='rider' comment='Is riding an another creature'/>
        <flag-bit name='incoming'/>
        <flag-bit name='diplomat'/>

        <flag-bit name='zombie'/>
        <flag-bit name='skeleton'/>
        <flag-bit name='can_swap' comment='Can swap tiles during movement (prevents multiple swaps)'/>
        <flag-bit name='on_ground' comment='The creature is laying on the floor, can be conscious'/>

        <flag-bit name='projectile' comment='Launched into the air? Funny.'/>
        <flag-bit name='active_invader' comment='Active invader (for organized ones)'/>
        <flag-bit name='hidden_in_ambush'/>
        <flag-bit name='invader_origin' comment='Invader origin (could be inactive and fleeing)'/>

        <flag-bit name='coward' comment='Will flee if invasion turns around'/>
        <flag-bit name='hidden_ambusher' comment='Active marauder/invader moving inward?'/>
        <flag-bit name='invades' comment='Marauder resident/invader moving in all the way'/>
        <flag-bit name='check_flows' comment='Check against flows next time you get a chance'/>

        <flag-bit name='ridden'/>
        <flag-bit name='caged'/>
        <flag-bit name='tame'/>
        <flag-bit name='chained'/>

        <flag-bit name='royal_guard'/>
        <flag-bit name='fortress_guard'/>
        <flag-bit name='suppress_wield'/>
        <flag-bit name='important_historical_figure' comment='Is an important historical figure'/>
    </bitfield-type>

Here's the first section of the unit bit. So I'm not understanding correctly. Are all these bits are directly after the name? And yet you say it starts from the name, so they would be IN the name... I'm not sure how I should work out the offset. Obviously each 4 bits will be one hex value, not sure where to get an offset from, as I'm not exactly sure where I should be starting... or finishing. Get what I mean? Say I wanted to put the DEAD flag on, for example...
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.
Pages: 1 [2] 3 4 5