public IEnumerable <BioEnergy> GetMaterialsInProcessing()
        {
            foreach (EmModuleSaveData savedItem in _materials.Values)
            {
                var techTypeID = (TechType)savedItem.ItemID;

                GameObject prefab = CraftData.GetPrefabForTechType(techTypeID);

                if (prefab == null)
                {
                    QuickLogger.Warning($"Unable to find prefab for TechType '{techTypeID}'");
                    continue;
                }

                var gameObject = GameObject.Instantiate(prefab);

                Pickupable pickupable = gameObject.GetComponent <Pickupable>();

                if (pickupable == null)
                {
                    QuickLogger.Warning($"Unable to find Pickupable component for item '{techTypeID.AsString()}'");
                    continue;
                }

                pickupable.Pickup(false);

                yield return(new BioEnergy(pickupable, savedItem.RemainingCharge));
            }
        }
Esempio n. 2
0
        protected void CreateIngredients(IEnumerable <TechType> parts, List <Ingredient> partsList)
        {
            if (parts == null)
            {
                return;
            }

            foreach (TechType part in parts)
            {
                if (part == TechType.None)
                {
                    QuickLogger.Warning($"Parts list for '{this.ClassID}' contained an unidentified TechType");
                    continue;
                }

                Ingredient priorIngredient = partsList.Find(i => i.techType == part);

                if (priorIngredient != null)
                {
                    priorIngredient.amount++;
                }
                else
                {
                    partsList.Add(new Ingredient(part, 1));
                }
            }
        }
        private void InitializeUpgradeHandlers()
        {
            QuickLogger.Debug($"UpgradeManager adding new UpgradeHandlers from external mods");
            // First, register upgrades from other mods.
            foreach (KeyValuePair <CreateUpgradeHandler, string> pair in HandlerCreators)
            {
                CreateUpgradeHandler upgradeHandlerCreator = pair.Key;
                string         assemblyName = pair.Value;
                UpgradeHandler upgrade      = upgradeHandlerCreator.Invoke(Cyclops);

                if (upgrade == null)
                {
                    QuickLogger.Warning($"UpgradeHandler from '{assemblyName}' was null");
                }
                else if (!KnownsUpgradeModules.ContainsKey(upgrade.TechType))
                {
                    upgrade.RegisterSelf(KnownsUpgradeModules);
                }
                else
                {
                    QuickLogger.Warning($"Duplicate UpgradeHandler for '{upgrade.TechType.AsString()}' from '{assemblyName}' was blocked");
                }
            }

            // Next, if no external mod has provided an UpgradeHandler for the vanilla upgrades, they will be added here.
            // This is to allow other mods to provide new functionality to the original upgrades.

            QuickLogger.Debug($"UpgradeManager adding default UpgradeHandlers for unmanaged vanilla upgrades");

            for (int i = 0; i < vanillaUpgrades.OriginalUpgradeIDs.Count; i++)
            {
                TechType upgradeID = vanillaUpgrades.OriginalUpgradeIDs[i];
                if (!KnownsUpgradeModules.ContainsKey(upgradeID))
                {
                    UpgradeHandler vanillaUpgrade = vanillaUpgrades.CreateUpgradeHandler(upgradeID, Cyclops);
                    vanillaUpgrade.RegisterSelf(KnownsUpgradeModules);
                }
            }

            upgradeHandlers = new UpgradeHandler[KnownsUpgradeModules.Count];

            int u = 0;

            foreach (UpgradeHandler upgrade in KnownsUpgradeModules.Values)
            {
                upgradeHandlers[u++] = upgrade;
            }

            QuickLogger.Debug("Attaching events to Engine Room Upgrade Console");

            if (engineRoomUpgradeConsole == null)
            {
                engineRoomUpgradeConsole = Cyclops.upgradeConsole.modules;
            }

            AttachEquipmentEvents(ref engineRoomUpgradeConsole);

            initialized       = true;
            TooLateToRegister = true;
        }
Esempio n. 4
0
        private static IEnumerable <IParsedPluginPack> GetAllPacks(string folderLocation)
        {
            // Check all folders
            foreach (string pluginFolder in Directory.GetDirectories(folderLocation))
            {
                // Find the CustomBatteriesPack.txt file
                string pluginDataFilePath = Path.Combine(pluginFolder, PluginFileName);
                string plugingFolderName  = new DirectoryInfo(Path.GetDirectoryName(pluginDataFilePath)).Name;

                if (!File.Exists(pluginDataFilePath))
                {
                    QuickLogger.Warning($"Plugin packs folder '{plugingFolderName}' did not contain a file named '{PluginFileName}'");
                    continue;
                }

                QuickLogger.Info($"Reading plugin pack '{plugingFolderName}'");

                string text = File.ReadAllText(pluginDataFilePath, Encoding.UTF8);

                var plugin = new EmTextPluginPack();

                bool readCorrectly = plugin.FromString(text);

                if (!readCorrectly)
                {
                    QuickLogger.Warning($"Pack file in '{pluginFolder}' contained errors and could not be read");
                    continue;
                }

                plugin.PluginPackFolder = pluginFolder;

                yield return(plugin);
            }
        }
        public void PrePassValidation()
        {
            //  Use the ToSet function as a copy constructor - this way we can iterate across the
            //      temp structure, but change the permanent one in the case of duplicates
            foreach (CustomCraftEntry item in this.ParsedEntries)
            {
                if (!item.PassesPreValidation(item.Origin))
                {
                    continue;
                }

                if (this.UniqueEntries.ContainsKey(item.ID))
                {
                    QuickLogger.Warning($"Duplicate entry for {this.TypeName} '{item.ID}' in {item.Origin} was already added by another working file. Kept first one. Discarded duplicate.");
                }
                else
                {
                    // All checks passed
                    this.UniqueEntries.Add(item.ID, item);
                }
            }

            if (this.ParsedEntries.Count > 0)
            {
                QuickLogger.Info($"{this.UniqueEntries.Count} of {this.ParsedEntries.Count} {this.TypeName} entries staged for patching");
            }
        }
        internal void Initialize <TVehicle>(ref TVehicle vehicle) where TVehicle : Vehicle
        {
            QuickLogger.Debug("Initialized vehicle");
            ParentVehicle = vehicle;

            IsSeamoth = vehicle is SeaMoth;
            IsExosuit = vehicle is Exosuit;

            if (this.UpgradeModules == null)
            {
                QuickLogger.Warning("Initialize Vehicle - UpgradeModules missing", true);
                return;
            }

            if (this.DmgOnImpact == null)
            {
                QuickLogger.Warning("Initialize Vehicle - DealDamageOnImpact missing", true);
                return;
            }

            if (this.LifeMix == null)
            {
                QuickLogger.Warning("Initialize Vehicle - LiveMixin missing", true);
                return;
            }
        }
        private static int ParseEntries <T, T2>(string serializedData, IDictionary <string, T> parsedItems)
            where T : EmPropertyCollection, ICraftingTab
            where T2 : EmPropertyCollectionList <T>, new()
        {
            T2 list = new T2();

            Assert.AreEqual(typeof(T), list.ItemType);

            bool successfullyParsed = list.Deserialize(serializedData);

            if (!successfullyParsed)
            {
                return(-1); // Error case
            }
            if (list.Count == 0)
            {
                return(0); // No entries
            }
            int unique = 0;

            foreach (T item in list)
            {
                if (parsedItems.ContainsKey(item.TabID))
                {
                    QuickLogger.Warning($"Duplicate entry for '{item.TabID}' in '{list.Key}' was already added by another working file. Kept first one. Discarded duplicate.");
                }
                else
                {
                    parsedItems.Add(item.TabID, item);
                    unique++;
                }
            }

            return(unique++); // Return the number of unique entries added in this list
        }
        internal void LoadFromFile()
        {
            string fileLocation = this.DefaultFileLocation();

            if (!File.Exists(fileLocation))
            {
                QuickLogger.Warning("Mod config file not found. Writing default file.");
                SaveToFile();
                return;
            }

            string text = File.ReadAllText(fileLocation, Encoding.UTF8);

            if (!text.StartsWith(versionLine))
            {
                QuickLogger.Warning("Mod config file was out of date. Writing default file.");
                SaveToFile();
                return;
            }

            bool readCorrectly = base.FromString(text);

            if (!readCorrectly || !hasValidData)
            {
                QuickLogger.Warning("Mod config file contained error. Writing default file.");
                SaveToFile();
                return;
            }
        }
Esempio n. 9
0
        public static void PatchTextPacks()
        {
            string pluginPacksFolder = Path.Combine(CbCore.ExecutingFolder, "Packs");

            if (!Directory.Exists(pluginPacksFolder))
            {
                QuickLogger.Warning("'Packs' folder was not found. Folder will be created. No text plugins were patched.");
                Directory.CreateDirectory(pluginPacksFolder);
                return;
            }

            var customPacks = new List <TextPluginPack>();

            foreach (IParsedPluginPack pluginPack in GetAllPacks(pluginPacksFolder))
            {
                customPacks.Add(new TextPluginPack(pluginPack));
            }

            if (customPacks.Count == 0)
            {
                QuickLogger.Info("No plugin files were found in the 'Packs' folder. No text plugins were patched.");
                return;
            }

            foreach (TextPluginPack customPack in customPacks)
            {
                customPack.Patch();
            }
        }
        public void HandleUpgrades()
        {
            if (!initialized)
            {
                InitializeUpgradeHandlers();
            }

            QuickLogger.Debug($"UpgradeManager clearing cyclops upgrades");

            // Turn off all upgrades and clear all values
            for (int i = 0; i < upgradeHandlers.Length; i++)
            {
                UpgradeHandler upgradeType = upgradeHandlers[i];

                if (upgradeType.HasUpgrade)
                {
                    QuickLogger.Debug($"UpgradeManager clearing {upgradeType.TechType.AsString()}");
                }

                upgradeType.UpgradesCleared(); // UpgradeHandler event
            }

            bool foundUpgrades = false;

            // Go through all slots and check what upgrades are available
            QuickLogger.Debug($"UpgradeManager checking upgrade slots");
            foreach (UpgradeSlot upgradeSlot in this.UpgradeSlots)
            {
                TechType techTypeInSlot = upgradeSlot.GetTechTypeInSlot();

                if (techTypeInSlot == TechType.None)
                {
                    continue;
                }

                foundUpgrades = true;

                if (KnownsUpgradeModules.TryGetValue(techTypeInSlot, out UpgradeHandler handler))
                {
                    QuickLogger.Debug($"UpgradeManager counting cyclops upgrade '{techTypeInSlot.AsString()}'");
                    handler.UpgradeCounted(upgradeSlot); // UpgradeHandler event
                }
                else
                {
                    QuickLogger.Warning($"UpgradeManager encountered unmanaged cyclops upgrade '{techTypeInSlot.AsString()}'");
                }
            }

            for (int i = 0; i < upgradeHandlers.Length; i++)
            {
                upgradeHandlers[i].UpgradesFinished(); // UpgradeHandler event
            }
            // If any upgrades were found, play the sound to alert the player
            if (foundUpgrades)
            {
                Cyclops.slotModSFX?.Play();
                PdaOverlayManager.RemapItems();
            }
        }
Esempio n. 11
0
        protected override bool ValidFabricator()
        {
            if (!this.ParentTabPath.StartsWith(this.ParentFabricator.ItemID))
            {
                QuickLogger.Warning($"Inner {this.Key} for {this.ParentFabricator.Key} from {this.Origin} appears to have a {ParentTabPathKey} for another fabricator '{this.ParentTabPath}'");
                return(false);
            }

            return(true);
        }
Esempio n. 12
0
        public static bool HasDataInRange <T>(this T property, float minValue, float maxValue) where T : EmProperty <float>
        {
            if (!property.HasValue || property.Value < minValue || property.Value > maxValue)
            {
                QuickLogger.Warning($"Value for '{property.Key}' was invalid or out of range.");
                return(false);
            }

            return(true);
        }
Esempio n. 13
0
        public static bool HasData <T>(this T property) where T : EmProperty
        {
            if (!property.HasValue)
            {
                QuickLogger.Warning($"Value for '{property.Key}' was invalid or out of range.");
                return(false);
            }

            return(true);
        }
        internal static void RegisterChargerCreator(CreateCyclopsCharger createEvent, string name)
        {
            if (CyclopsChargerCreators.Find(c => c.Creator == createEvent || c.ChargerName == name) != null)
            {
                QuickLogger.Warning($"Duplicate CyclopsChargerCreator '{name}' was blocked");
                return;
            }

            QuickLogger.Info($"Received CyclopsChargerCreator '{name}'");
            CyclopsChargerCreators.Add(new ChargerCreator(createEvent, name));
        }
        internal static void RegisterAuxManagerCreator(CreateAuxCyclopsManager createEvent, string typeName)
        {
            if (AuxManagerCreators.ContainsKey(typeName))
            {
                QuickLogger.Warning($"Block duplicate AuxManagerCreator '{typeName}'");
                return;
            }

            QuickLogger.Info($"Received AuxManagerCreator '{typeName}'");
            AuxManagerCreators.Add(typeName, createEvent);
        }
        internal static void RegisterStatusIconCreator(CyclopsStatusIconCreator creatorEvent, string name)
        {
            if (StatusIconCreators.Find(s => s.Creator == creatorEvent || s.StatusIconName == name) != null)
            {
                QuickLogger.Warning($"Duplicate CyclopsStatusIconCreator '{name}' was blocked");
                return;
            }

            QuickLogger.Info($"Received CyclopsStatusIconCreator '{name}'");
            StatusIconCreators.Add(new StatusIconCreator(creatorEvent, name));
        }
Esempio n. 17
0
        internal static void RegisterHandlerCreator(CreateUpgradeHandler createEvent, string assemblyName)
        {
            if (HandlerCreators.ContainsKey(createEvent))
            {
                QuickLogger.Warning($"Duplicate UpgradeHandlerCreator blocked from {assemblyName}");
                return;
            }

            QuickLogger.Info($"Received UpgradeHandlerCreator from {assemblyName}");
            HandlerCreators.Add(createEvent, assemblyName);
        }
Esempio n. 18
0
        internal static void RegisterHandlerCreator(TechType techType, CreateIconOverlay createEvent, string assemblyName)
        {
            if (OverlayCreators.ContainsKey(techType))
            {
                QuickLogger.Warning($"PdaOverlayManager blocked duplicate IconOverlayCreator from {assemblyName}");
                return;
            }

            QuickLogger.Info($"PdaOverlayManager received IconOverlayCreator from {assemblyName}");
            OverlayCreators.Add(techType, createEvent);
        }
 internal void Initialize()
 {
     try
     {
         LoadFromFile();
     }
     catch (Exception ex)
     {
         QuickLogger.Warning($"[MoreCyclopsUpgrades] Error loading {EmNuclearConfig.ConfigKey}: " + ex.ToString());
         WriteConfigFile();
     }
 }
        internal void InitializeChargers()
        {
            QuickLogger.Debug("ChargeManager Initializing CyclopsChargers from external mods");

            // First, register chargers from other mods.
            for (int i = 0; i < CyclopsChargerCreators.Count; i++)
            {
                ChargerCreator chargerTemplate = CyclopsChargerCreators[i];
                QuickLogger.Debug($"ChargeManager creating charger '{chargerTemplate.ChargerName}'");
                CyclopsCharger charger = chargerTemplate.Creator.Invoke(Cyclops);

                if (charger == null)
                {
                    QuickLogger.Warning($"CyclopsCharger '{chargerTemplate.ChargerName}' was null");
                }
                else if (!KnownChargers.ContainsKey(chargerTemplate.ChargerName))
                {
                    KnownChargers.Add(chargerTemplate.ChargerName, charger);
                    QuickLogger.Debug($"Created CyclopsCharger '{chargerTemplate.ChargerName}'");
                }
                else
                {
                    QuickLogger.Warning($"Duplicate CyclopsCharger '{chargerTemplate.ChargerName}' was blocked");
                }
            }

            this.Chargers = new CyclopsCharger[KnownChargers.Count];

            int c = 0;

            foreach (CyclopsCharger charger in KnownChargers.Values)
            {
                this.Chargers[c++] = charger;
            }

            totalChargers = c;
            QuickLogger.Debug($"ChargeManager has '{totalChargers}' CyclopsChargers from external mods");

            initialized       = true;
            TooLateToRegister = true;

            requiresVanillaCharging = totalChargers == 0 || CyclopsManager.GetManager(Cyclops).Upgrade.VanillaUpgrades.IsUsingVanillaUpgrade(TechType.CyclopsThermalReactorModule);

            if (requiresVanillaCharging)
            {
                QuickLogger.Info("Vanilla thermal reactor charging enabled");
            }
            else
            {
                QuickLogger.Info("Vanilla thermal reactor charging overridden by mod");
            }
        }
        internal void InitializeChargers()
        {
            TooLateToRegister = true;
            QuickLogger.Debug("ChargeManager Initializing CyclopsChargers from external mods");

            // First, register chargers from other mods.
            for (int i = 0; i < CyclopsChargerCreators.Count; i++)
            {
                ChargerCreator chargerTemplate = CyclopsChargerCreators[i];
                QuickLogger.Debug($"ChargeManager creating charger '{chargerTemplate.ChargerName}'");
                CyclopsCharger charger = chargerTemplate.Creator.Invoke(Cyclops);

                if (charger == null)
                {
                    QuickLogger.Warning($"CyclopsCharger '{chargerTemplate.ChargerName}' was null");
                }
                else if (!KnownChargers.ContainsKey(chargerTemplate.ChargerName))
                {
                    KnownChargers.Add(chargerTemplate.ChargerName, charger);
                    CyclopsHUDManager.StatusIcons.Add(charger);
                    QuickLogger.Debug($"Created CyclopsCharger '{chargerTemplate.ChargerName}'");
                }
                else
                {
                    QuickLogger.Warning($"Duplicate CyclopsCharger '{chargerTemplate.ChargerName}' was blocked");
                }
            }

            // Check if an external mod has a different upgrade handler for the original CyclopsThermalReactorModule.
            bool requiresVanillaCharging = CyclopsManager.GetManager(ref Cyclops).Upgrade.VanillaUpgrades.IsUsingVanillaUpgrade(TechType.CyclopsThermalReactorModule);

            if (requiresVanillaCharging)
            {
                QuickLogger.Debug("Vanilla thermal reactor charging handled internally");
                var vanillaThermalCharger = new VanillaThermalChargeManager(Cyclops);
                KnownChargers.Add(nameof(VanillaThermalChargeManager), vanillaThermalCharger);
                CyclopsHUDManager.StatusIcons.Add(vanillaThermalCharger);
                MCUServices.Register.PdaIconOverlay(TechType.CyclopsThermalReactorModule,
                                                    (uGUI_ItemIcon icon, InventoryItem upgradeModule) => new VanillaThermalPdaOverlay(icon, upgradeModule));
            }

            this.Chargers = new CyclopsCharger[KnownChargers.Count];

            int c = 0;

            foreach (CyclopsCharger charger in KnownChargers.Values)
            {
                this.Chargers[c++] = charger;
            }

            initialized = true;
        }
        private static int DeserializeFile(string workingFilePath)
        {
            string fileName = Path.GetFileName(workingFilePath);

            string serializedData = File.ReadAllText(workingFilePath, Encoding.UTF8);

            if (string.IsNullOrEmpty(serializedData))
            {
                QuickLogger.Warning($"File '{fileName}' contained no text");
                return(0);
            }

            if (EmProperty.CheckKey(serializedData, out string key))
            {
                int check = -2;
                if (PackagesLookup.TryGetValue(key, out IParsingPackage package))
                {
                    check = package.ParseEntries(serializedData, OriginFile.GetOriginFile(fileName));
                }
                else
                {
                    QuickLogger.Warning($"Unknown primary key '{key}' detected in file '{fileName}'");
                    return(0);
                }

                switch (check)
                {
                case -2:
                    QuickLogger.Error($"Unexpected error when attempting to parse file '{fileName}'");
                    break;

                case -1:
                    QuickLogger.Warning($"Unable to parse file '{fileName}'");
                    break;

                case 0:
                    QuickLogger.Warning($"File '{fileName}' was parsed but no entries were found");
                    break;

                default:
                    QuickLogger.Debug($"{check} entries parsed from file '{fileName}'");
                    return(check);
                }
            }
            else
            {
                QuickLogger.Warning($"Could not identify primary key in file '{fileName}'");
            }

            return(0);
        }
Esempio n. 23
0
        internal static void Postfix(CyclopsSonarCreatureDetector.EntityData entityData, CyclopsSonarDisplay __instance)
        {
            if (entityData.entityType != CyclopsSonarDisplay.EntityType.Creature)
            {
                return;
            }

            if (entityData.attackCyclops == null)
            {
                return;
            }

            SubRoot cyclops = __instance?.noiseManager?.subRoot;

            if (cyclops == null)
            {
                QuickLogger.Error("Unable to find Cyclops SubRoot in CyclopsSonarDisplay parent", true);
                return;
            }

            // Did we just detect an aggressive creature on sonar?
            if (!entityData.attackCyclops.IsAggressiveTowardsCyclops(cyclops.gameObject))
            {
                return;
            }

            // Yes, both auto-defense zappers can be activated at the same time
            var defenser = MCUServices.Find.AuxCyclopsManager <AutoDefenser>(cyclops);

            if (defenser != null)
            {
                defenser.Zap(entityData);
            }
            else
            {
                QuickLogger.Warning("Unable to find AutoDefenser AuxCyclopsManager", true);
            }

            var defenserMk2 = MCUServices.Find.AuxCyclopsManager <AutoDefenserMk2>(cyclops);

            if (defenserMk2 != null)
            {
                defenserMk2.Zap(entityData);
            }
            else
            {
                QuickLogger.Warning("Unable to find AutoDefenserMk2 AuxCyclopsManager", true);
            }
        }
Esempio n. 24
0
        private void EnhanceCyNukeReactors()
        {
            QuickLogger.Debug($"Handling CyNukeEnhancer at {this.HighestValue}");

            if (this.ChargeManager != null)
            {
                for (int r = 0; r < this.ChargeManager.CyNukeReactors.Count; r++)
                {
                    this.ChargeManager.CyNukeReactors[r]?.UpdateUpgradeLevel(this.HighestValue);
                }
            }
            else
            {
                QuickLogger.Warning("CyNukeChargeManager still not found!");
            }
        }
Esempio n. 25
0
        internal static void Postfix(CyclopsSonarDisplay __instance)
        {
            SubRoot cyclops = __instance?.noiseManager?.subRoot;

            if (cyclops == null)
            {
                QuickLogger.Error("Unable to find Cyclops SubRoot in CyclopsSonarDisplay parent", true);
                return;
            }

            foreach (CyclopsSonarDisplay.EntityPing entity in __instance.entitysOnSonar)
            {
                CyclopsHUDSonarPing ping = entity?.ping?.GetComponent <CyclopsHUDSonarPing>();

                if (ping == null)
                {
                    continue;
                }

                // Are there any aggressive creatures on sonar?
                if (ping.currentColor != ping.aggressiveColor)
                {
                    return;
                }

                // Yes, both auto-defense zappers can be activated at the same time
                var defenser = MCUServices.Find.AuxCyclopsManager <AutoDefenser>(cyclops);
                if (defenser != null)
                {
                    defenser.Zap();
                }
                else
                {
                    QuickLogger.Warning("Unable to find AutoDefenser AuxCyclopsManager", true);
                }

                var defenserMk2 = MCUServices.Find.AuxCyclopsManager <AutoDefenserMk2>(cyclops);
                if (defenserMk2 != null)
                {
                    defenserMk2.Zap();
                }
                else
                {
                    QuickLogger.Warning("Unable to find AutoDefenserMk2 AuxCyclopsManager", true);
                }
            }
        }
Esempio n. 26
0
        public void OnProtoDeserializeObjectTree(ProtobufSerializer serializer)
        {
            if (SaveData.Load())
            {
                // Because the items here aren't being serialized with everything else normally,
                // I've used custom save data to handle whatever gets left in these slots.

                QuickLogger.Debug("Loading save data");
                // The following is a recreation of the essential parts of the Equipment.ResponseEquipment method.
                for (int s = 0; s < SlotHelper.SlotNames.Length; s++)
                {
                    string slot = SlotHelper.SlotNames[s];
                    // These slots need to be added before we can add items to them
                    this.Modules.AddSlot(slot);

                    EmModuleSaveData savedModule = SaveData.GetModuleInSlot(slot);

                    if (savedModule.ItemID == 0) // (int)TechType.None
                    {
                        continue;                // Nothing here
                    }
                    var           techtype    = (TechType)savedModule.ItemID;
                    InventoryItem spanwedItem = CyclopsUpgrade.SpawnCyclopsModule(techtype);

                    if (spanwedItem == null)
                    {
                        QuickLogger.Warning($"Unknown upgrade module '{techtype.AsString()}' could not be spamned in from save data");
                        continue;
                    }

                    QuickLogger.Debug($"Spawned in {techtype.AsString()} from save data");

                    if (savedModule.RemainingCharge > 0f) // Modules without batteries are stored with a -1 value for charge
                    {
                        spanwedItem.item.GetComponent <Battery>().charge = savedModule.RemainingCharge;
                    }

                    this.Modules.AddItem(slot, spanwedItem, true);
                }
            }
            else
            {
                UnlockDefaultModuleSlots();
            }
        }
        public void PulseShield()
        {
            if (!this.HasUpgrade)
            {
                return;
            }

            if (!this.HasShieldModule)
            {
                return;
            }

            if (this.IsOnCooldown)
            {
                return;
            }

            UpdateCooldown();

            if (GameModeUtils.RequiresPower())
            {
                float originalCost = Cyclops.shieldPowerCost;
                Cyclops.shieldPowerCost = originalCost * ShieldCostModifier;

                Cyclops.powerRelay.ConsumeEnergy(Cyclops.shieldPowerCost, out float amountConsumed);

                Cyclops.shieldPowerCost = originalCost;
            }

            LavaLarva[] leaches = Cyclops.gameObject.GetComponentsInChildren <LavaLarva>();

            if (leaches == null)
            {
                QuickLogger.Warning("GetComponentsInChildren<LavaLarva>() returned null");
                return;
            }

            for (int i = 0; i < leaches.Length; i++)
            {
                leaches[i].GetComponent <LiveMixin>().TakeDamage(1f, default(Vector3), DamageType.Electrical, null);
            }
        }
        private void LoadFromFile()
        {
            if (!File.Exists(ConfigFile))
            {
                QuickLogger.Message("Mod config file not found. Writing default file.");
                WriteConfigFile();
                return;
            }

            string text = File.ReadAllText(ConfigFile, Encoding.UTF8);

            bool readCorrectly = this.FromString(text);

            if (!readCorrectly || !this.HasValue)
            {
                QuickLogger.Warning("Mod config file contained error. Writing default file.");
                WriteConfigFile();
                return;
            }
        }
        public void SendToSMLHelper()
        {
            int successCount = 0;

            foreach (CustomCraftEntry item in this.UniqueEntries.Values)
            {
                if (!item.PassedSecondValidation)
                {
                    QuickLogger.Warning($"Entry for '{item.ID}' from file '{item.Origin}' failed secondary checks for duplicate IDs. It will not be patched.");
                }
                else if (item.SendToSMLHelper())
                {
                    successCount++;
                }
            }

            if (this.UniqueEntries.Count > 0)
            {
                QuickLogger.Info($"{successCount} of {this.UniqueEntries.Count} {this.TypeName} entries were patched");
            }
        }
        private static T CreateNewAuxManager <T>(CyclopsManager mgr, string auxManagerName)
            where T : class, IAuxCyclopsManager
        {
            QuickLogger.Debug($"Started creating new IAuxCyclopsManager '{auxManagerName}'");
            if (AuxManagerCreators.TryGetValue(auxManagerName, out CreateAuxCyclopsManager creator))
            {
                IAuxCyclopsManager auxMgr = creator.Invoke(mgr.Cyclops);
                if (auxMgr != null || !auxMgr.Initialize(mgr.Cyclops))
                {
                    QuickLogger.Debug($"Created new IAuxCyclopsManager '{auxManagerName}'");
                    mgr.AuxiliaryManagers.Add(auxManagerName, auxMgr);
                    return((T)auxMgr);
                }
                else
                {
                    QuickLogger.Error($"Failed in creating IAuxCyclopsManager '{auxManagerName}'");
                }
            }

            QuickLogger.Warning($"Did not find creator method for IAuxCyclopsManager '{auxManagerName}'");
            return(null);
        }