rheirman / WhatTheHack

Mechanoid hacking
16 stars 18 forks source link

NRE in RimWorld.Planet.TrySatisfyPawnNeeds #47

Open NoirFry opened 4 years ago

NoirFry commented 4 years ago

NRE here because hacked mechaniods have no Psychic tracker

private void TrySatisfyPawnNeeds(Pawn pawn)
{
    ...
    Pawn_PsychicEntropyTracker psychicEntropy = pawn.psychicEntropy;
    if (psychicEntropy.Psylink != null)
    {
        TryGainPsyfocus(psychicEntropy);
    }
}

I added this:

if (pawn.psychicEntropy == null)
    pawn.psychicEntropy = new Pawn_PsychicEntropyTracker(pawn);

after this:

public static class PawnComponentsUtility_AddAndRemoveDynamicComponents
{    
    static void Postfix(Pawn pawn)
    {
        if (flagIsCreatureMine && flagIsCreatureDraftable)
        {
            //If everything goes well, add drafter to the pawn 
            pawn.drafter = new Pawn_DraftController(pawn);
            ...
NoirFry commented 4 years ago

In PR #49 i added

pawn.psychicEntropy = new Pawn_PsychicEntropyTracker(pawn);

in Recipe_HackMechanoid.PostSuccessfulApply. This will create pawn.psychicEntropy when a mechanoid is hacked. But now that i think about, it won't add it to already hacked mechanoids. So if you have already hacked mechanoids before this fix - they will still throw errors in caravans. You need to delete/rehack/... them.

So maybe add addition check in PawnComponentsUtility_AddAndRemoveDynamicComponents as i did in the first place when open this issue ?