Example #1
0
        private static void ChangeDefLabels()
        {
            // Go through every appropriate def that has a label
            var changeableDefTypes = GenDefDatabase.AllDefTypesWithDatabases().Where(t => ShouldChangeDefTypeLabel(t)).ToList();

            for (int i = 0; i < changeableDefTypes.Count; i++)
            {
                var curDefs = GenDefDatabase.GetAllDefsInDatabaseForDef(changeableDefTypes[i]).ToList();
                for (int j = 0; j < curDefs.Count; j++)
                {
                    var curDef = curDefs[j];
                    if (!curDef.label.NullOrEmpty())
                    {
                        // Update the def's label
                        AdjustLabel(ref curDef.label);

                        // If the def is a ThingDef...
                        if (curDef is ThingDef tDef)
                        {
                            // If the ThingDef is a stuff item
                            if (tDef.stuffProps is StuffProperties stuffProps)
                            {
                                // Update the stuff adjective if there is one
                                if (!stuffProps.stuffAdjective.NullOrEmpty())
                                {
                                    AdjustLabel(ref stuffProps.stuffAdjective);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private static void BindDefsFor(Type type)
 {
     FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public);
     for (int i = 0; i < fields.Length; i++)
     {
         FieldInfo fieldInfo = fields[i];
         Type      fieldType = fieldInfo.FieldType;
         if (!typeof(Def).IsAssignableFrom(fieldType))
         {
             Log.Error(fieldType + " is not a Def.", false);
         }
         else if (fieldType == typeof(SoundDef))
         {
             SoundDef soundDef = SoundDef.Named(fieldInfo.Name);
             if (soundDef.isUndefined && !DefOfHelper.earlyTry)
             {
                 Log.Error("Could not find SoundDef named " + fieldInfo.Name, false);
             }
             fieldInfo.SetValue(null, soundDef);
         }
         else
         {
             Def def = GenDefDatabase.GetDef(fieldType, fieldInfo.Name, !DefOfHelper.earlyTry);
             fieldInfo.SetValue(null, def);
         }
     }
 }
Example #3
0
 private static void BindDefsFor(Type type)
 {
     FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public);
     foreach (FieldInfo fieldInfo in fields)
     {
         Type fieldType = fieldInfo.FieldType;
         if (!typeof(Def).IsAssignableFrom(fieldType))
         {
             Log.Error(fieldType + " is not a Def.");
         }
         else if (fieldType == typeof(SoundDef))
         {
             SoundDef soundDef = SoundDef.Named(fieldInfo.Name);
             if (soundDef.isUndefined && !earlyTry)
             {
                 Log.Error("Could not find SoundDef named " + fieldInfo.Name);
             }
             fieldInfo.SetValue(null, soundDef);
         }
         else
         {
             Def def = GenDefDatabase.GetDef(fieldType, fieldInfo.Name, !earlyTry);
             fieldInfo.SetValue(null, def);
         }
     }
 }
        public static Dictionary <string, DefInfo> CollectDefInfos()
        {
            var dict = new Dictionary <string, DefInfo>();

            int TypeHash(Type type) => GenText.StableStringHash(type.FullName);

            dict["ThingComp"]            = GetDefInfo(Sync.thingCompTypes, TypeHash);
            dict["Designator"]           = GetDefInfo(Sync.designatorTypes, TypeHash);
            dict["WorldObjectComp"]      = GetDefInfo(Sync.worldObjectCompTypes, TypeHash);
            dict["IStoreSettingsParent"] = GetDefInfo(Sync.storageParents, TypeHash);
            dict["IPlantToGrowSettable"] = GetDefInfo(Sync.plantToGrowSettables, TypeHash);

            foreach (var defType in GenTypes.AllLeafSubclasses(typeof(Def)))
            {
                if (defType.Assembly != typeof(Game).Assembly)
                {
                    continue;
                }
                if (IgnoredVanillaDefTypes.Contains(defType))
                {
                    continue;
                }

                var defs = GenDefDatabase.GetAllDefsInDatabaseForDef(defType);
                dict.Add(defType.Name, GetDefInfo(defs, d => GenText.StableStringHash(d.defName)));
            }

            return(dict);
        }
Example #5
0
        public bool RequirementIsMeet()
        {
            Def def = GenDefDatabase.GetDef(defType, defName);

            if (condition == Condition.built)
            {
                return(ConditionEvaluator.EvaluateBuilt(def));
            }
            if (condition == Condition.notbuilt)
            {
                return(!ConditionEvaluator.EvaluateBuilt(def));
            }
            if (condition == Condition.researched)
            {
                return(ConditionEvaluator.EvaluateResearched(def));
            }
            if (condition == Condition.notresearched)
            {
                return(!ConditionEvaluator.EvaluateResearched(def));
            }
            if (condition == Condition.powered)
            {
                return(ConditionEvaluator.EvaluatePowered(def));
            }
            if (condition == Condition.notpowered)
            {
                return(!ConditionEvaluator.EvaluatePowered(def));
            }

            return(false);
        }
Example #6
0
 private static void BindDefsFor(Type type)
 {
     FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public);
     foreach (FieldInfo fieldInfo in fields)
     {
         Type fieldType = fieldInfo.FieldType;
         if (!typeof(Def).IsAssignableFrom(fieldType))
         {
             Log.Error(fieldType + " is not a Def.");
             continue;
         }
         MayRequireAttribute mayRequireAttribute = fieldInfo.TryGetAttribute <MayRequireAttribute>();
         bool              flag = (mayRequireAttribute == null || ModsConfig.IsActive(mayRequireAttribute.modId)) && !earlyTry;
         string            text = fieldInfo.Name;
         DefAliasAttribute defAliasAttribute = fieldInfo.TryGetAttribute <DefAliasAttribute>();
         if (defAliasAttribute != null)
         {
             text = defAliasAttribute.defName;
         }
         if (fieldType == typeof(SoundDef))
         {
             SoundDef soundDef = SoundDef.Named(text);
             if (soundDef.isUndefined && flag)
             {
                 Log.Error("Could not find SoundDef named " + text);
             }
             fieldInfo.SetValue(null, soundDef);
         }
         else
         {
             Def def = GenDefDatabase.GetDef(fieldType, text, flag);
             fieldInfo.SetValue(null, def);
         }
     }
 }
        public static void ResolveCollisions()
        {
            var seenHashes   = new HashSet <ushort>();
            var defsToRehash = new List <Def>();

            foreach (Type current in GenDefDatabase.AllDefTypesWithDatabases())
            {
                var type              = typeof(DefDatabase <>).MakeGenericType(current);
                var property          = type.GetProperty("AllDefs");
                var getMethod         = property.GetGetMethod();
                var allDefsInDatabase = (IEnumerable)getMethod.Invoke(null, null);
                defsToRehash.Clear();
                foreach (Def def in allDefsInDatabase)
                {
                    if (seenHashes.Contains(def.shortHash))
                    {
                        defsToRehash.Add(def);
                    }
                    else
                    {
                        seenHashes.Add(def.shortHash);
                    }
                }
                defsToRehash.SortBy(d => d.defName);
                for (int i = 0; i < defsToRehash.Count; i++)
                {
                    var def = defsToRehash[i];
                    def.shortHash = 0;
                    InjectedDefHasher.GiveShortHasToDef(def);
                    Log.Message(def.defName + " " + def.shortHash);
                }
                seenHashes.Clear();
            }
        }
Example #8
0
        private static void FixIndices() // this method fixes Tynan's bug with index assigning where modded defs derived from vanilla would get repeating indices
                                         // thus breaking some logic, i.e terrain wealth calculation was broken when adding mods with modded terrain def types
        {
            Dictionary <Type, HashSet <int> > idsByDefTypes = new Dictionary <Type, HashSet <int> >();

            foreach (Type item in typeof(Def).AllSubclasses())
            {
                if (item != typeof(BuildableDef))
                {
                    var defsList = GenDefDatabase.GetAllDefsInDatabaseForDef(item).ToList();
                    foreach (var def in defsList)
                    {
                        if (!idsByDefTypes.TryGetValue(item, out var list))
                        {
                            idsByDefTypes[item] = list = new HashSet <int>();
                        }
                        if (list.Contains(def.index))
                        {
                            def.index = (ushort)(list.Max() + 1);
                        }
                        if (!list.Add(def.index))
                        {
                            Log.Error("Failed to assign non duplicate index to " + def + " - " + def.index);
                        }
                    }
                }
            }
        }
Example #9
0
 private static void BindDefsFor(Type type)
 {
     FieldInfo[] fields = type.GetFields();
     for (int i = 0; i < fields.Length; i++)
     {
         FieldInfo fieldInfo = fields[i];
         Type      fieldType = fieldInfo.FieldType;
         if (!typeof(Def).IsAssignableFrom(fieldType))
         {
             Log.Error(fieldType + " is not a Def.");
         }
         else if (fieldType == typeof(SoundDef))
         {
             if (!DefOfHelper.earlyTry)
             {
                 fieldInfo.SetValue(null, SoundDef.Named(fieldInfo.Name));
             }
         }
         else
         {
             Def def = GenDefDatabase.GetDef(fieldType, fieldInfo.Name, !DefOfHelper.earlyTry);
             fieldInfo.SetValue(null, def);
         }
     }
 }
Example #10
0
 public static void EntryAction()
 {
     Log.Message(
         GenDefDatabase.GetAllDefsInDatabaseForDef(typeof(TerrainDef))
         .Select(def => $"{def.modContentPack?.Name} {def} {def.shortHash} {def.index}")
         .Join(delimiter: "\n")
         );
 }
        public static void Postfix(Type defType, string defName, bool forDefInjections, ref string __result)
        {
            if (GenDefDatabase.GetDefSilentFail(defType, defName, false) == null)
            {
                string newName = string.Empty;
                //    Log.Message(string.Format("Checking for replacement for {0} Type: {1}", defName, defType));
                if (defType == typeof(ThingDef))
                {
                    /*
                     * if (defName.Contains("ChaosDeamon_"))
                     * {
                     *  if (defName.Contains("Corpse_"))
                     *  {
                     *      newName = Regex.Replace(defName, "Corpse_ChaosDeamon_", "Corpse_OG_Chaos_Deamon_");
                     *  }
                     *  else
                     *      newName = Regex.Replace(defName, "ChaosDeamon_", "OG_Chaos_Deamon_");
                     * }
                     */

                    if (defName == "HempFabric")
                    {
                        newName = "HempCloth";
                    }
                }
                if (defType == typeof(FactionDef))
                {
                }
                if (defType == typeof(PawnKindDef))
                {
                }
                if (defType == typeof(ResearchProjectDef))
                {
                }
                if (defType == typeof(HediffDef))
                {
                }
                if (defType == typeof(BodyDef))
                {
                }
                if (defType == typeof(ScenarioDef))
                {
                }
                if (!newName.NullOrEmpty())
                {
                    __result = newName;
                }
                if (defName == __result)
                {
                    //    Log.Warning(string.Format("AMA No replacement found for: {0} T:{1}", defName, defType));
                }
                else
                {
                    //    Log.Message(string.Format("Replacement found: {0} T:{1}", __result, defType));
                }
            }
        }
        public static void BackCompatibleDefName_Postfix(Type defType, string defName, bool forDefInjections, ref string __result)
        {
            if (GenDefDatabase.GetDefSilentFail(defType, defName, false) == null)
            {
                //    Log.Message(string.Format("Checking for replacement for {0} Type: {1}", defName, defType));
                if (defType == typeof(ThingDef))
                {
                }
                if (defType == typeof(FactionDef))
                {
                }
                if (defType == typeof(PawnKindDef))
                {
                }
                if (defType == typeof(ResearchProjectDef))
                {
                }
                if (defType == typeof(HediffDef))
                {
                    if (defName.Contains("RRY_Hediff_Unblooded"))
                    {
                        __result = "HMS_Hediff_Unblooded";
                    }
                    if (defName.Contains("RRY_Hediff_BloodedUM"))
                    {
                        __result = "HMS_Hediff_BloodedUM";
                    }
                    if (defName == ("RRY_Hediff_BloodedM"))
                    {
                        __result = "HMS_Hediff_BloodedM";
                    }
                    else if (defName.Contains("RRY_Hediff_BloodedM"))
                    {
                        // Taking a string
                        String str = defName;

                        String[] spearator = { "_" };
                        Int32    count     = 3;

                        // using the method
                        String[] strlist = str.Split(spearator, count,
                                                     StringSplitOptions.RemoveEmptyEntries);
                        __result = DefDatabase <HediffDef> .AllDefs.Where(x => x.defName.Contains(strlist[2])).First().defName;
                    }
                }
                if (defName == __result)
                {
                    Log.Warning(string.Format("RRY No replacement found for: {0} T:{1}", defName, defType));
                }
                else
                {
                    //    Log.Message(string.Format("Replacement found: {0} T:{1}", __result, defType));
                }
            }
        }
 public virtual IEnumerable <T> Options()
 {
     if (typeof(T).IsEnum)
     {
         return(Enum.GetValues(typeof(T)).OfType <T>());
     }
     if (typeof(Def).IsAssignableFrom(typeof(T)))
     {
         return(GenDefDatabase.GetAllDefsInDatabaseForDef(typeof(T)).Cast <T>());
     }
     throw new NotImplementedException();
 }
 public static void RemoveDefaultFacialStuff(Pawn pawn, Dictionary <string, ThingComp> compLookup, HashSet <string> savedComps)
 {
     // If the pawn was saved when facial stuff was not enabled, but it was enabled when they load the pawn,
     // then the pawn will end up with random facial stuff settings, possibly including facial hair.  This post-load action clears
     // out as much of those random settings as possible.
     if (!savedComps.Contains("FacialStuff.CompFace"))
     {
         if (compLookup.TryGetValue("FacialStuff.CompFace", out ThingComp c))
         {
             ReflectionUtil.InvokeActionMethod(c, "InitializeCompFace");
             object pawnFace = ReflectionUtil.GetPropertyValue <object>(c, "PawnFace");
             if (pawnFace == null)
             {
                 //Logger.Debug("Couldn't get the PawnFace value from the comp with class " + c.GetType().FullName);
                 return;
             }
             Type beardDefType = ReflectionUtil.TypeByName("FacialStuff.Defs.BeardDef");
             if (beardDefType == null)
             {
                 //Logger.Debug("Didn't find the beard definition type");
             }
             else
             {
                 Def defaultBeardDef = GenDefDatabase.GetDef(beardDefType, "Beard_Shaved", false);
                 if (defaultBeardDef == null)
                 {
                     //Logger.Debug("Didn't find the default beard definition");
                 }
                 else
                 {
                     ReflectionUtil.SetFieldValue(pawnFace, "_beardDef", defaultBeardDef);
                 }
             }
             Type stacheDefType = ReflectionUtil.TypeByName("FacialStuff.Defs.MoustacheDef");
             if (stacheDefType == null)
             {
                 //Logger.Debug("Didn't find the moustache definition type");
             }
             else
             {
                 Def defaultStacheDef = GenDefDatabase.GetDef(stacheDefType, "Shaved", false);
                 if (defaultStacheDef == null)
                 {
                     //Logger.Debug("Didn't find the default moustache definition");
                 }
                 else
                 {
                     ReflectionUtil.SetFieldValue(pawnFace, "_moustacheDef", defaultStacheDef);
                 }
             }
         }
     }
 }
        private static HashSet <string> UpdateAnimalList(string factionDefName, HashSet <string> currentAnimals)
        {
            var additions =
                $@"{GenFilePaths.ConfigFolderPath}{Path.DirectorySeparatorChar}AnimalHusbandryRaids_{factionDefName}.additions";
            var deletions =
                $@"{GenFilePaths.ConfigFolderPath}{Path.DirectorySeparatorChar}AnimalHusbandryRaids_{factionDefName}.deletions";

            try
            {
                if (!File.Exists(additions))
                {
                    File.Create(additions).Dispose();
                }

                if (!File.Exists(deletions))
                {
                    File.Create(deletions).Dispose();
                }

                var animalsToAdd = File.ReadAllLines(additions).ToList();
                currentAnimals.AddRange(animalsToAdd);
                var animalsToRemove = File.ReadAllLines(deletions).ToList();
                foreach (var animalToRemove in animalsToRemove)
                {
                    currentAnimals.Remove(animalToRemove);
                }

                WriteDebug(
                    $"The following animals was found: {currentAnimals.ToCommaList()}, have added {animalsToAdd.ToCommaList()} and removed {animalsToRemove.ToCommaList()}");
            }
            catch (Exception exception)
            {
                WriteDebug($"Failed to create files, {exception}.");
            }

            var returnValue = new HashSet <string>();

            foreach (var animalDef in currentAnimals)
            {
                if (GenDefDatabase.GetDefSilentFail(typeof(ThingDef), animalDef) == null)
                {
                    continue;
                }

                WriteDebug($"Adding, {animalDef} as possible animal.");

                returnValue.Add(animalDef);
            }

            return(returnValue);
        }
Example #16
0
        public override Thing CreateThing(bool useOriginalID = false, int stackCount = 0, bool needPirate = false)
        {
            //useOriginalID не используется.

            var   def      = (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), DefName);
            var   stuffDef = !string.IsNullOrEmpty(StuffName) ? (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), StuffName) : null;
            Thing thing    = !string.IsNullOrEmpty(StuffName)
                ? ThingMaker.MakeThing(def, stuffDef)
                : ThingMaker.MakeThing(def);

            thing.stackCount = stackCount > 0 ? stackCount : Count;

            if (HitPoints > 0)
            {
                thing.HitPoints = HitPoints;
            }

            SetFaction(thing, isColonist && !needPirate);

            CompQuality compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null)
            {
                compQuality.SetQuality((QualityCategory)Quality, ArtGenerationContext.Outsider);
            }

            if (WornByCorpse)
            {
                Apparel thingA = thing as Apparel;
                if (thingA != null)
                {
                    typeof(Apparel)
                    .GetField("wornByCorpseInt", BindingFlags.Instance | BindingFlags.NonPublic)
                    .SetValue(thingA, true);
                }
            }

            thing.Rotation = new Rot4(Rotation);

            Plant thingP = thing as Plant;

            if (thingP != null)
            {
                thingP.Growth = Growth;
            }

            thing.Position = Position.Get();

            return(thing);
        }
Example #17
0
 public override void ExposeData()
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         this.tmpDefName = ((this.def == null) ? null : this.def.defName);
         this.tmpDefType = ((this.def == null) ? null : this.def.GetType());
     }
     Scribe_Values.Look <string>(ref this.tmpDefName, "defName", null, false);
     Scribe_Values.Look <Type>(ref this.tmpDefType, "defType", null, false);
     if (Scribe.mode == LoadSaveMode.LoadingVars && this.tmpDefName != null)
     {
         this.def = GenDefDatabase.GetDef(this.tmpDefType, this.tmpDefName, true);
     }
 }
Example #18
0
 public override void ExposeData()
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         tmpDefName = ((def != null) ? def.defName : null);
         tmpDefType = ((def != null) ? def.GetType() : null);
     }
     Scribe_Values.Look(ref tmpDefName, "defName");
     Scribe_Values.Look(ref tmpDefType, "defType");
     if (Scribe.mode == LoadSaveMode.LoadingVars && tmpDefName != null)
     {
         def = GenDefDatabase.GetDef(tmpDefType, BackCompatibility.BackCompatibleDefName(tmpDefType, tmpDefName));
     }
 }
Example #19
0
        public override string BackCompatibleDefName(Type defType, string defName, bool forDefInjections = false, XmlNode node = null)
        {
            if (GenDefDatabase.GetDefSilentFail(defType, defName, false) == null)
            {
                if (defType == typeof(TraitDef) || defType == typeof(ThoughtDef))
                {
                    var def = GenDefDatabase.GetDefSilentFail(defType, "GAT_" + defName, false);

                    if (def != null)
                    {
                        return(def.defName);
                    }
                }
            }
            return(null);
        }
        public static void GenerateDescForHediffList(ref StringBuilder builder, List <HediffInfo> hediffs)
        {
            var hediffsNonNull = hediffs?.Where(h => h.def != null);

            if (hediffsNonNull != null)
            {
                if (hediffsNonNull.Any())
                {
                    builder.AppendLine("QE_GenomeSequencerDescription_Hediffs".Translate());

                    //sort hediffs in alphabetical order
                    var ordered = hediffsNonNull.OrderBy(h => h.def.LabelCap);

                    //loop through hediffs and add line to StringBuilder for each
                    foreach (HediffInfo h in ordered)
                    {
                        if (h.part != null)
                        {
                            builder.AppendLine("    " + h.def.LabelCap + " [" + h.part.LabelCap + "]");

                            //Psychic Awakening compatibility
                            if (h.psychicAwakeningPowersKnownDefNames != null && h.psychicAwakeningPowersKnownDefNames?.Count > 0)
                            {
                                foreach (string defName in h.psychicAwakeningPowersKnownDefNames.OrderBy(a => a))
                                {
                                    var psychicPowerDef = GenDefDatabase.GetDef(PsychicAwakeningCompat.PsychicPowerDefType, defName, false);

                                    if (psychicPowerDef != null)
                                    {
                                        builder.AppendLine("        " + psychicPowerDef.LabelCap);
                                    }
                                    else
                                    {
                                        builder.AppendLine("        " + defName);
                                    }
                                }
                            }
                        }
                        else
                        {
                            builder.AppendLine("    " + h.def.LabelCap);
                        }
                    }
                }
            }
        }
Example #21
0
        public static void PatchAndroids(Harmony harmony)
        {
            //patch the drawOverviewTab, so we can pass info about the current pawn displayed to the medicalcaresetter
            harmony.Patch(typeof(HealthCardUtility).GetMethod("DrawOverviewTab", BindingFlags.NonPublic | BindingFlags.Static), new HarmonyMethod(typeof(DrawOverviewTab).GetMethod("_Prefix")), new HarmonyMethod(typeof(DrawOverviewTab).GetMethod("_Postfix")));

            //unpatch the medical care select button, we'll take over that for andoirdtiers

            /*var androidMedCareSelectPatch = AccessTools.Inner(AccessTools.TypeByName("MOARANDROIDS.MedicalCareUtility_Patch"), "MedicalCareSelectButton_Patch").GetMethod("Listener", BindingFlags.Static);
             * harmony.Unpatch(typeof(MedicalCareUtility).GetMethod("MedicalCareSelectButton"),androidMedCareSelectPatch);
             */
            harmony.Unpatch(typeof(MedicalCareUtility).GetMethod("MedicalCareSelectButton"), HarmonyPatchType.Prefix, "rimworld.rwmods.androidtiers");

            //get android flesh type
            AndroidFlesh = (FleshTypeDef)GenDefDatabase.GetDef(typeof(FleshTypeDef), "AndroidTier", true);

            //create android-only med list and store
            androidMedList = new List <ModMedicine>();
            humanMedList   = new List <ModMedicine>();

            for (int i = 0; i < medList.Count; i++)
            {
                //always add no care and no medicine
                if (i == 0)
                {
                    androidMedList.Add(medList[i]);
                    humanMedList.Add(medList[i]);
                }
                else if (i == 1)
                {
                    humanMedList.Add(medList[i]);
                    //change no medicine texture for androids
                    androidMedList.Add(new ModMedicine((MedicalCareCategory)1, 0, ContentFinder <Texture2D> .Get("Things/Misc/ATPP_OnlyDocVisit", true)));
                }
                else
                {
                    if (IsAndroidMedicine(medList[i]))
                    {
                        androidMedList.Add(medList[i]);
                    }
                    else
                    {
                        humanMedList.Add(medList[i]);
                    }
                }
            }
        }
        public static void BackCompatibleDefName_Postfix(Type defType, string defName, ref string __result)
        {
            if (GenDefDatabase.GetDefSilentFail(defType, defName, false) == null)
            {
                if (defType == typeof(ThingDef))
                {
                    __result = "PerfectlyGenericItem";
                }

                /*
                 * if (defType == typeof(FactionDef) && PGISettings.Instance.replaceFactions)
                 * {
                 *  __result = "OutlanderRough";
                 * }
                 */
            }
        }
Example #23
0
 public static void BackCompatibleDefName_Postfix(Type defType, string defName, bool forDefInjections, ref string __result)
 {
     if (GenDefDatabase.GetDefSilentFail(defType, defName, false) == null)
     {
         string newName = string.Empty;
         //    Log.Message(string.Format("Checking for replacement for {0} Type: {1}", defName, defType));
         if (defType == typeof(ThingDef))
         {
         }
         if (defType == typeof(FactionDef))
         {
             if (defName == "TyranidFaction")
             {
                 newName = "OG_Tyranid_Faction";
             }
         }
         if (defType == typeof(PawnKindDef))
         {
         }
         if (defType == typeof(ResearchProjectDef))
         {
         }
         if (defType == typeof(HediffDef))
         {
         }
         if (defType == typeof(BodyDef))
         {
         }
         if (defType == typeof(ScenarioDef))
         {
         }
         if (!newName.NullOrEmpty())
         {
             __result = newName;
         }
         if (defName == __result)
         {
             //    Log.Warning(string.Format("AMA No replacement found for: {0} T:{1}", defName, defType));
         }
         else
         {
             //    Log.Message(string.Format("Replacement found: {0} T:{1}", __result, defType));
         }
     }
 }
Example #24
0
        public Thing CreateThing()
        {
            var   def      = (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), DefName);
            var   stuffDef = !string.IsNullOrEmpty(StuffName) ? (ThingDef)GenDefDatabase.GetDef(typeof(ThingDef), StuffName) : null;
            Thing thing    = !string.IsNullOrEmpty(StuffName)
                ? ThingMaker.MakeThing(def, stuffDef)
                : ThingMaker.MakeThing(def);

            thing.stackCount = Count;

            if (HitPoints > 0)
            {
                thing.HitPoints = HitPoints;
            }

            CompQuality compQuality = thing.TryGetComp <CompQuality>();

            if (compQuality != null)
            {
                compQuality.SetQuality((QualityCategory)Quality, ArtGenerationContext.Outsider);
            }

            if (WornByCorpse)
            {
                Apparel thingA = thing as Apparel;
                if (thingA != null)
                {
                    typeof(Apparel)
                    .GetField("wornByCorpseInt", BindingFlags.Instance | BindingFlags.NonPublic)
                    .SetValue(thingA, true);
                }
            }

            thing.Rotation = new Rot4(Rotation);

            Plant thingP = thing as Plant;

            if (thingP != null)
            {
                thingP.Growth = Growth;
            }

            return(thing);
        }
Example #25
0
        static void PathAvoidDesignatorSyncWorker(SyncWorker sw, ref Designator designator)
        {
            Def def = null;

            if (sw.isWriting)
            {
                def = (Def)PathAvoidDefField.GetValue(designator);

                sw.Write(def.defName);
            }
            else
            {
                string defName = sw.Read <string>();

                def = GenDefDatabase.GetDef(PathAvoidDefType, defName, false);

                designator = (Designator)Activator.CreateInstance(Designator_PathAvoidType, new object[] { def });
            }
        }
Example #26
0
        private static List <string> UpdateAnimalList(string factionDefName, List <string> currentAnimals)
        {
            string additions = $@"{GenFilePaths.ConfigFolderPath}{Path.DirectorySeparatorChar}AnimalHusbandryRaids_{factionDefName}.additions";
            string deletions = $@"{GenFilePaths.ConfigFolderPath}{Path.DirectorySeparatorChar}AnimalHusbandryRaids_{factionDefName}.deletions";

            try
            {
                if (!File.Exists(additions))
                {
                    File.Create(additions).Dispose();
                }
                if (!File.Exists(deletions))
                {
                    File.Create(deletions).Dispose();
                }
                var animalsToAdd = File.ReadAllLines(additions).ToList();
                currentAnimals.AddRange(animalsToAdd);
                var animalsToRemove = File.ReadAllLines(deletions).ToList();
                foreach (string animalToRemove in animalsToRemove)
                {
                    currentAnimals.Remove(animalToRemove);
                }
                //if (Prefs.DevMode) Log.Message($"[AnimalHusbandryRaids] The following animals was found: {currentAnimals.ToCommaList()}, have added {animalsToAdd.ToCommaList()} and removed {animalsToRemove.ToCommaList()}");
            }
            catch (Exception exception)
            {
                if (Prefs.DevMode)
                {
                    Log.Message($"[AnimalHusbandryRaids] Failed to create files, {exception.ToString()}.");
                }
            }

            var returnValue = new List <string>();

            foreach (string animalDef in currentAnimals)
            {
                if (GenDefDatabase.GetDefSilentFail(typeof(ThingDef), animalDef) != null)
                {
                    returnValue.Add(animalDef);
                }
            }
            return(returnValue);
        }
Example #27
0
        public static object Parse(this FieldInfo fieldInfo, string value)
        {
            object val;

            try
            {
                if (fieldInfo.FieldType.IsSubclassOf(typeof(Def)))
                {
                    val = GenDefDatabase.GetDef(fieldInfo.FieldType, value);
                }
                else
                {
                    val = ParseHelper.FromString(value, fieldInfo.FieldType);
                }
                return(val);
            }
            catch (Exception e)
            {
                throw new Exception("Researchable Stat Upgrades :: Exception parsing string: " + e);
            }
        }
Example #28
0
        public static void DumpDefTypes()
        {
            foreach (var defType in GenTypes.AllLeafSubclasses(typeof(Def)))
            {
                if (defType.Assembly != typeof(Game).Assembly)
                {
                    continue;
                }
                if (Multiplayer.IgnoredVanillaDefTypes.Contains(defType))
                {
                    continue;
                }

                Log.Warning($"== {defType.Name} ==");
                Log.Message(
                    GenDefDatabase.GetAllDefsInDatabaseForDef(defType)
                    .Select(def => $"{def.defName}")
                    .Join(delimiter: "\n")
                    );
            }
        }
Example #29
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (!CanGetThing(pawn, t, forced))
            {
                return(null);
            }

            //plan count and dests
            HaulExplicitlyPosting posting = HaulExplicitly.GetManager(t.Map).PostingWithItem(t);

            if (posting == null)
            {
                return(null);
            }
            int            space_request        = AmountPawnWantsToPickUp(pawn, t, posting);
            var            destInfo             = DeliverableDestinations.For(t, pawn, posting);
            List <IntVec3> dests                = destInfo.RequestSpaceForItemAmount(space_request);
            int            dest_space_available = destInfo.FreeSpaceInCells(dests);
            var            count                = Math.Min(space_request, dest_space_available);

            if (count < 1)
            {
                return(null);
            }

            //make job
            JobDef JobDefOfHaulExplicitly =
                (JobDef)(GenDefDatabase.GetDef(typeof(JobDef), "HaulExplicitlyHaul"));
            Job job = new Job(JobDefOfHaulExplicitly, t, dests.First());

            //((JobDriver_HaulExplicitly)job.GetCachedDriver(pawn)).init();
            job.count        = count;
            job.targetQueueA = new List <LocalTargetInfo>(
                new LocalTargetInfo[] { new IntVec3(posting.id, dest_space_available, 0) });
            job.targetQueueB = new List <LocalTargetInfo>(dests.Skip(1).Take(dests.Count - 1)
                                                          .Select(c => new LocalTargetInfo(c)));
            job.haulOpportunisticDuplicates = true;
            return(job);
        }
Example #30
0
        private static IEnumerable <Def> EnumerateAllDefs()
        {
            bool fast = false;

            if (fast)
            {
                foreach (var mod in LoadedModManager.RunningModsListForReading)
                {
                    if (mod == null)
                    {
                        continue;
                    }

                    foreach (var def in mod.AllDefs)
                    {
                        yield return(def);
                    }
                }

                foreach (var def in LoadedModManager.PatchedDefsForReading)
                {
                    yield return(def);
                }
            }
            else
            {
                foreach (var type in GenDefDatabase.AllDefTypesWithDatabases())
                {
                    foreach (var def in (IEnumerable)GenGeneric.GetStaticPropertyOnGenericType(typeof(DefDatabase <>), type, "AllDefs"))
                    {
                        var finalDef = def as Def;
                        yield return(finalDef);
                    }
                }
            }
        }