private void InjectVarious()
        {
            // Get the generic for furniture
            ThingDef minifiedFurniture = DefDatabase <ThingDef> .GetNamed("MinifiedFurniture");

            // traverse through our filters
            foreach (MiniaturisationDef miniaturisationDef in DefDatabase <MiniaturisationDef> .AllDefsListForReading)
            {
                // check if the mod exists or ignore
                if (Find_Extensions.ModByName(miniaturisationDef.requiredMod) == null)
                {
#if DEBUG
                    Log.Message("Miniaturisation :: Skipping " + miniaturisationDef.requiredMod);
#endif
                    continue;
                }

                // This list contains the defNames of the mod
                List <string> filter = miniaturisationDef.targetsDefNames;
                Log.Message("Miniaturisation :: Found " + miniaturisationDef.requiredMod + " (" + filter.Count + ")");

                IEnumerable <ThingDef> list = DefDatabase <ThingDef> .AllDefs.Where(def => filter.Contains(def.defName));

                for (int i = 0; i < list.Count(); i++)
                {
                    ThingDef thing = list.ElementAt(i);
#if DEBUG
                    Log.Message("> " + thing.defName);
#endif
                    // add the minifiedDef is it isn't there
                    if (thing.minifiedDef == null)
                    {
                        thing.minifiedDef = minifiedFurniture;
                        thing.minifiedDef.installBlueprintDef = NewBlueprintDef_Thing(thing);

                        DefDatabase <ThingDef> .Add(thing.minifiedDef.installBlueprintDef);
                    }
                }
            }
        }
Example #2
0
        // Validate ModHelperDefs, CCL load order, CCL versioning
        public override bool Validate()
        {
            // Hopefully...
            var stringBuilder = new StringBuilder();
            var rVal          = true;

            CCL_Log.CaptureBegin(stringBuilder);

            // Limit one ModHelperDef per mod
            // Create the ordered list by inserting dummies for mods which don't have one
            var allMods = LoadedModManager.LoadedMods.ToList();

            // Find Core and CCL in the mod order
            coreModIndex = -1;
            cclModIndex  = -1;
            for (int i = 0; i < allMods.Count; ++i)
            {
                LoadedMod mod = allMods[i];
                if (mod.name == "Core")
                {
                    coreModIndex = i;
                }
                if (mod.name == Controller.Data.UnityObjectName)
                {
                    cclModIndex = i;
                }
            }
            if (coreModIndex == -1)
            {
                LongEventHandler.ExecuteWhenFinished(ShowLoadOrderWindow);
                stringBuilder.AppendLine("\tUnable to find 'Core' in mod load order!");
                //rVal = false; // Don't throw as an error, will be caught special
            }
            else if (coreModIndex != 0)
            {
                LongEventHandler.ExecuteWhenFinished(ShowLoadOrderWindow);
                stringBuilder.AppendLine("\t'Core' must be first in mod load order!");
                //rVal = false; // Don't throw as an error, will be caught special
            }
            if (cclModIndex == -1)
            {
                LongEventHandler.ExecuteWhenFinished(ShowLoadOrderWindow);
                stringBuilder.Append("\tUnable to find '");
                stringBuilder.Append(Controller.Data.UnityObjectName);
                stringBuilder.AppendLine("' in mod load order!");
                //rVal = false; // Don't throw as an error, will be caught special
            }
            else if (cclModIndex != 1)
            {
                LongEventHandler.ExecuteWhenFinished(ShowLoadOrderWindow);
                stringBuilder.Append("\t'");
                stringBuilder.Append(Controller.Data.UnityObjectName);
                stringBuilder.AppendLine("' must be second in mod load order, immediately after 'Core'! :: Current position is #" + (cclModIndex + 1).ToString());
                //rVal = false; // Don't throw as an error, will be caught special
            }
            if (rVal)
            {
                for (int i = 0; i < allMods.Count; i++)
                {
                    var modHelperDef  = (ModHelperDef)null;
                    var mod           = allMods[i];
                    var modHelperDefs = Find_Extensions.DefListOfTypeForMod <ModHelperDef>(mod);
                    if (!modHelperDefs.NullOrEmpty())
                    {
                        if (modHelperDefs.Count > 1)
                        {
                            stringBuilder.Append("\t" + mod.name);
                            CCL_Log.AppendSectionNewLine(ref stringBuilder, "Multiple ModHelperDefs detected");
                            rVal = false;
                        }
                        else
                        {
                            // Validate the def
                            modHelperDef = modHelperDefs.First();
                            if (!modHelperDef.IsValid)
                            {
                                // Don't do anything special with broken mods
                                stringBuilder.Append("\t" + mod.name);
                                CCL_Log.AppendSectionNewLine(ref stringBuilder, "ModHelperDef is invalid");
                                rVal = false;
                            }
                            else if (!modHelperDef.dummy)
                            {
                                // Don't show validation message for dummy defs
                                stringBuilder.Append("\t" + mod.name);
                                CCL_Log.AppendSection(ref stringBuilder, "ModHelperDef");
                                CCL_Log.AppendSectionNewLine(ref stringBuilder, "Passed validation, requesting v" + modHelperDef.minCCLVersion);
                            }
                        }
                    }
                    else if (rVal == true)
                    {
                        // Doesn't exist, create a dummy for logging but only
                        // create if we're not just checking for remaining errors
                        modHelperDef               = new ModHelperDef();
                        modHelperDef.defName       = mod.name + "_ModHelperDef";
                        modHelperDef.minCCLVersion = Version.Minimum.ToString();
                        modHelperDef.ModName       = mod.name;
                        modHelperDef.Verbosity     = Verbosity.NonFatalErrors;
                        modHelperDef.dummy         = true;
                    }
                    if (rVal == true)
                    {
                        // No errors, def is valid or a dummy
                        // Associate the def with the mod (the dictionary is to go the other way)
                        modHelperDef.mod = mod;
                        // Insert it into it's ordered place in the lists
                        Controller.Data.Mods.Insert(i, mod);
                        Controller.Data.ModHelperDefs.Insert(i, modHelperDef);
                        // Add a dictionary entry
                        Controller.Data.DictModHelperDefs.Add(mod, modHelperDef);
                    }
                }
                // Should now be a complete pair of lists in mod load order
                // as well as a dictionary of mods and their defs

#if DEVELOPER
                //Dump ordered list of mods and their defs
                string dump = "Mod load order:\n";
                for (int i = 0; i < Controller.Data.Mods.Count; i++)
                {
                    dump += "\t[" + i + "] - " + Controller.Data.Mods[i].name + " - " + Controller.Data.ModHelperDefs[i].defName + (Controller.Data.ModHelperDefs[i].dummy ? " - dummy" : "") + "\n";
                }
                CCL_Log.Write(dump);
#endif
                if (rVal)
                {
                    LoadedMod    CCL_Mod       = Controller.Data.Mods[cclModIndex];
                    ModHelperDef CCL_HelperDef = Find_Extensions.ModHelperDefForMod(CCL_Mod);

                    // Validate xml version with assembly version
                    var vc = Version.Compare(CCL_HelperDef.minCCLVersion);
                    if (vc != Version.VersionCompare.ExactMatch)
                    {
                        stringBuilder.AppendLine("\tModHelperDef version mismatch for Community Core Library!");
                        rVal = false;
                    }

                    // CCL rank is #2 in load order and def version matches library
                    Controller.Data.cclMod       = CCL_Mod;
                    Controller.Data.cclHelperDef = CCL_HelperDef;
                }
            }

            // Should be all good or up until the first error encountered
            CCL_Log.CaptureEnd(
                stringBuilder,
                rVal ? "Validated" : "Errors during validation"
                );
            strReturn = stringBuilder.ToString();

            // Return true if all mods OK, false if any failed validation
            State = rVal ? SubControllerState.Validated : SubControllerState.ValidationError;
            return(rVal);
        }
Example #3
0
        // Validate ...research...?
        public override bool                Validate()
        {
            // Hopefully...
            var stringBuilder = new StringBuilder();
            var rVal          = true;

            CCL_Log.CaptureBegin(stringBuilder);

            var AdvancedResearchDefs = Controller.Data.AdvancedResearchDefs;

            // Make sure the hidden research exists
            if (CommunityCoreLibrary.Research.Locker == null)
            {
                CCL_Log.Trace(Verbosity.FatalErrors, "Missing research locker!");
                rVal = false;
            }

            // Validate each advanced research def
            for (int index = AdvancedResearchDefs.Count - 1; index >= 0; index--)
            {
                var advancedResearchDef = AdvancedResearchDefs[index];

                if (!advancedResearchDef.IsValid())
                {
                    // Remove projects with errors from list of usable projects
                    AdvancedResearchDefs.Remove(advancedResearchDef);
                    rVal = false;
                    continue;
                }

                if (advancedResearchDef.IsLockedOut())
                {
                    // Remove locked out projects
                    CCL_Log.TraceMod(
                        advancedResearchDef,
                        Verbosity.Warnings,
                        "Def is locked out by one or more research prerequisites");
                    AdvancedResearchDefs.Remove(advancedResearchDef);
                    continue;
                }
            }

#if DEBUG
            if (rVal == true)
            {
                var allMods = Controller.Data.Mods;
                foreach (var mod in allMods)
                {
                    if (!Find_Extensions.DefListOfTypeForMod <AdvancedResearchDef>(mod).NullOrEmpty())
                    {
                        CCL_Log.TraceMod(
                            mod,
                            Verbosity.Validation,
                            "Passed validation"
                            );
                    }
                }
            }
#endif

            // Should be empty or a laundry list
            CCL_Log.CaptureEnd(
                stringBuilder,
                rVal ? "Validated" : "Errors during validation"
                );
            strReturn = stringBuilder.ToString();

            // Return true if all mods OK, false if any failed validation
            State = rVal ? SubControllerState.Validated : SubControllerState.ValidationError;
            return(rVal);
        }