Edit PawnKindDefs to Spawn With Specific Trait(s)

Started by xXDzepniXx, January 15, 2021, 05:59:43 PM

Previous topic - Next topic

xXDzepniXx

I've been looking through the PawnKindDefs trying to find a way to spawn a pawn with specific traits, I had noticed the tag <disallowedTraits> but there doesn't seem to exist the opposite of <disallowedTraits> for whitelisting/forcing traits for certain pawns. When trying something like <requiredTraits> the error at the start of the game is (from my understanding) the tag <requiredTraits> is not defined under PawnKindDef. So, is there a way to whitelist/force traits for specific pawns, or is there only a tag for blacklisting traits?

RawCode

i hope you want to understand how to solve this issue and similar issues in future, not just get fast solution.

in such case, you should open game "sources" with dnspy and check how pawns get traits, start from PawnGenerator.cs


xXDzepniXx

#2
Quote from: RawCode on January 18, 2021, 07:24:11 PM
i hope you want to understand how to solve this issue and similar issues in future, not just get fast solution.

in such case, you should open game "sources" with dnspy and check how pawns get traits, start from PawnGenerator.cs
I'm pretty much just hoping it's an easier solution, or to get one at all. I'll check this out and see, but judging it's in a .cs file, I'm guessing there isn't a tag that forces/whitelists traits as simple as the <disallowTraits> tag.

Edit: Can you be more descriptive on the statement "open game 'sources'"?

RawCode

well

// Token: 0x04002E0D RID: 11789
public List<TraitEntry> forcedTraits = null;

// Token: 0x04002E0E RID: 11790
public List<TraitEntry> disallowedTraits = null;


main part is "with dnspy" you can google for more info.

xXDzepniXx

Quote from: RawCode on January 21, 2021, 02:37:45 AM
well

// Token: 0x04002E0D RID: 11789
public List<TraitEntry> forcedTraits = null;

// Token: 0x04002E0E RID: 11790
public List<TraitEntry> disallowedTraits = null;


main part is "with dnspy" you can google for more info.
No I mean, where did you get this? What did you open with dnspy to get this? Where is that file located in the RimWorld directory?

RawCode

did you downloaded dnspy and read it's manual fully?

xXDzepniXx

#6
Quote from: RawCode on January 23, 2021, 08:58:46 AM
did you downloaded dnspy and read it's manual fully?

I don't understand what I'm supposed to gather from that as to what file(s) I need to look through. I've worked with IDA and Ollydbg (although not very proficient) before, this isn't too different, I'm just asking for the file(s) in the RimWorld directory that you are telling me to look through. I don't know which file(s) you are talking about that are in the RimWorld directory, what are those file(s)?

Edit: Also, yes, I read the manual on Github and I'll be using it when I'm editing the file(s), if I end up editing them.



xXDzepniXx

Well, what I can gather from finding PawnGenerator and PawnKindDef is that PawnKinfDef does not have a forcedTraits field. When a pawn is generated, the GenerateTraits method within PawnGenerator does look to see if there are any forced traits, but only checks within the BackStory class, and more specifically, forcedTraits method within the BackStory class. It does not look anywhere else. So, there doesn't exist a way to simply add forced traits onto a PawnKindDef like there is to simply blacklist traits through <disallowedTraits>.

So, from what I can understand, there is two options: either 'call' the BackStory class within PawnKindDef and fill in the field BackStory.forcedTraits and that being applied to the PawnKindDef and not to the BackStory, or create a field like forcedTraits within PawnKindDef and edit the PawnKindDef class to recognize that field and appropriately whitelist traits.

Kind of silly there's a very simple way to blacklist traits, but no simple way to whitelist traits..

Alenerel

What about custom scenarios where you can force all pawns to have a specific trait with even a chance of getting it.

xXDzepniXx

#11
Quote from: Alenerel on January 23, 2021, 07:03:23 PM
What about custom scenarios where you can force all pawns to have a specific trait with even a chance of getting it.

That's exactly what I do not want, though. I want very specific pawns to have or not have certain traits. Say, for example, the pawn defName Empire_Common_Laborer, you can find that in Royalty\Defs\PawnKinds\PawnKinds_Empire.xml, they cannot have the trait Nudist and must be able to perform work tasks ManualDumb, ManualSkilled, Cleaning, Hauling, Mining, Firefighting. This is just to show that every time this specific pawn is spawned/generated in the world/map, they will never have the Nudist trait, and will always be able to perform the said work tasks.

The scenario editor forces traits on every pawn. So, the mentioned pawn would never have the Nudist trait and would also spawn with the forced trait. This is not what I want.

And to just mention the issue again, there does not exist a simple way to whitelist in the .xml file through a field like <forcedTraits> just like there is a field to blacklist traits through <disallowedTraits>. If you look through the PawnKindDef class file within Assembly-CSharp.dll, you'll see there is no field pertaining to forcing traits. <forcedTraits> exists only within scenario editor, under BackStory class file.

RawCode

check how exactly scenario affects pawn generation
check is scenario can have custom implementation class
play with custom scenario class

xXDzepniXx

Quote from: RawCode on January 25, 2021, 03:02:36 AM
check how exactly scenario affects pawn generation
check is scenario can have custom implementation class
play with custom scenario class
How would I check and see if scenario can have a custom class implemented?

Undeadbanana

I think you're looking for Xpath patching, it's in the RimWorld Modding tutorial wiki. It'll let you do what you're looking for.