public static bool NeededImmunitiesNow(ImmunityHandler __instance, ref List <ImmunityInfo> __result)
        {
            List <ImmunityInfo> tmpNeededImmunitiesNow = getTmpNeededImmunitiesNow(); //Added

            tmpNeededImmunitiesNow.Clear();                                           //Changed to tmpNeededImmunitiesNow
            List <Hediff> hediffs = __instance.pawn.health.hediffSet.hediffs;

            for (int i = 0; i < hediffs.Count; i++)
            {
                Hediff hediff;
                try
                {
                    hediff = hediffs[i];
                } catch (ArgumentOutOfRangeException)
                {
                    break;
                }
                if (hediff != null && hediff.def != null && hediff.def.PossibleToDevelopImmunityNaturally())
                {
                    //Changed to tmpNeededImmunitiesNow
                    tmpNeededImmunitiesNow.Add(new ImmunityInfo
                    {
                        immunity = hediff.def,
                        source   = hediff.def
                    });
                }
            }
            //Changed to tmpNeededImmunitiesNow
            __result = tmpNeededImmunitiesNow;
            return(false);
        }
 public Pawn_HealthTracker_CantHeal(Pawn pawn) : base(pawn)
 {
     this.pawn                = pawn;
     hediffSet                = new HediffSet(pawn);
     capacities               = new PawnCapacitiesHandler(pawn);
     summaryHealth            = new SummaryHealthHandler(pawn);
     surgeryBills             = new BillStack(pawn);
     immunity                 = new ImmunityHandler(pawn);
     beCarriedByCaravanIfSick = pawn.RaceProps.Humanlike;
 }
 private static void TryAddImmunityRecord2(ImmunityHandler __instance, HediffDef def, HediffDef source)
 {
     //can remove if transpiled
     if (def.CompProps <HediffCompProperties_Immunizable>() != null && !__instance.ImmunityRecordExists(def))
     {
         immunityList(__instance).Add(new ImmunityRecord
         {
             hediffDef = def,
             source    = source
         });
     }
 }
            static void Postfix([NotNull] ImmunityHandler __instance, [CanBeNull] List <ImmunityRecord> ___immunityList)
            {
                if (Scribe.mode == LoadSaveMode.PostLoadInit)
                {
                    if (___immunityList == null)
                    {
                        return;
                    }
                    for (int i = ___immunityList.Count - 1; i >= 0; i--)
                    {
                        var imR = ___immunityList[i];


                        if (imR?.hediffDef == null) //remove all null immunity record or records with null hediffDefs
                        {
                            ___immunityList.RemoveAt(i);
                        }
                    }
                }
            }
        public static bool ImmunityHandlerTick(ImmunityHandler __instance)
        {
            List <ImmunityInfo> list = __instance.NeededImmunitiesNow();

            for (int i = 0; i < list.Count; i++)
            {
                __instance.TryAddImmunityRecord(list[i].immunity, list[i].source);
            }
            lock (__instance)
            {
                List <ImmunityRecord> newImmunityList = new List <ImmunityRecord>(__instance.immunityList);
                for (int j = 0; j < __instance.immunityList.Count; j++)
                {
                    ImmunityRecord immunityRecord   = newImmunityList[j];
                    Hediff         firstHediffOfDef = __instance.pawn.health.hediffSet.GetFirstHediffOfDef(immunityRecord.hediffDef);
                    immunityRecord.ImmunityTick(__instance.pawn, firstHediffOfDef != null, firstHediffOfDef);
                }
                for (int num = newImmunityList.Count - 1; num >= 0; num--)
                {
                    if (newImmunityList[num].immunity <= 0f)
                    {
                        bool flag = false;
                        for (int k = 0; k < list.Count; k++)
                        {
                            if (list[k].immunity == newImmunityList[num].hediffDef)
                            {
                                flag = true;
                                break;
                            }
                        }

                        if (!flag)
                        {
                            newImmunityList.RemoveAt(num);
                        }
                    }
                }
                __instance.immunityList = newImmunityList;
            }
            return(false);
        }