Ludeon Forums

RimWorld => Mods => Help => Topic started by: xXDzepniXx on January 15, 2021, 05:59:43 PM

Title: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 15, 2021, 05:59:43 PM
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?
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: 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

Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 19, 2021, 02:46:28 PM
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'"?
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: 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.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 21, 2021, 02:38:54 PM
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?
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: RawCode on January 23, 2021, 08:58:46 AM
did you downloaded dnspy and read it's manual fully?
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 23, 2021, 03:01:04 PM
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.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: Canute on January 23, 2021, 03:38:15 PM
not sure but did you took at
https://rimworldwiki.com/wiki/Modding_Tutorials/Decompiling_source_code

https://ludeon.com/forums/index.php?topic=37618.0
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 23, 2021, 04:33:48 PM
Quote from: Canute on January 23, 2021, 03:38:15 PM
not sure but did you took at
https://rimworldwiki.com/wiki/Modding_Tutorials/Decompiling_source_code

https://ludeon.com/forums/index.php?topic=37618.0

Thank you! I'll start looking through the files.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 23, 2021, 05:37:13 PM
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..
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: 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.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 23, 2021, 07:48:43 PM
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.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: 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
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 25, 2021, 01:26:48 PM
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?
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: Undeadbanana on January 26, 2021, 05:03:28 AM
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.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: xXDzepniXx on January 26, 2021, 06:10:18 PM
Quote from: Undeadbanana on January 26, 2021, 05:03:28 AM
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.
Can you tell me what you had in mind on how that would look like? I'm looking through guides on Xpathing but I don't see it being actually useful in what I want. So, yea, I'm just confused about what you're exactly thinking on this.
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: qux on July 03, 2021, 07:55:36 PM
HI, someone find the solution ?
Title: Re: Edit PawnKindDefs to Spawn With Specific Trait(s)
Post by: RawCode on July 04, 2021, 05:33:30 AM
solution is known from very beginning - injecting into pawngenerator

issue - people want to mod, but at same time, do not want to learn.