Пример #1
0
 private static void InitializeMods()
 {
     Log("Beginning Gadget Mod Initialization");
     foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos())
     {
         if (!mod.Mod.Enabled)
         {
             continue;
         }
         if (mod.Attribute.Dependencies.All(x => GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).Select(y => y.Attribute.Name).Contains(x) || GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).Select(y => y.Mod.GetPreviousModNames()).Any(y => y.Contains(x))))
         {
             bool            compatible        = true;
             string[][]      splitDependencies = mod.Attribute.Dependencies.Select(x => x.Split(' ')).Where(x => x.Length == 2).ToArray();
             GadgetModInfo[] dependencies      = splitDependencies.Select(x => GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).FirstOrDefault(y => y.Attribute.Name.Equals(x[0])) ?? GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).First(y => y.Mod.GetPreviousModNames().Contains(x[0]))).ToArray();
             for (int i = 0; i < dependencies.Length; i++)
             {
                 int[] currentVersionNums = dependencies[i].Mod.GetModVersionString().Split('.').Select(x => int.Parse(x)).ToArray();
                 int[] targetVersionNums  = splitDependencies[i][1].TrimStart('v').Split('.').Select(x => int.Parse(x)).ToArray();
                 VersionSpecificity versionSpecificity = (VersionSpecificity)targetVersionNums.Length;
                 if (!((versionSpecificity == VersionSpecificity.MAJOR && currentVersionNums[0] == targetVersionNums[0] && (currentVersionNums[1] > targetVersionNums[1] || (currentVersionNums[1] == targetVersionNums[1] && (currentVersionNums[2] > targetVersionNums[2] || (currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]))))) ||
                       (versionSpecificity == VersionSpecificity.MINOR && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && (currentVersionNums[2] > targetVersionNums[2] || (currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]))) ||
                       (versionSpecificity == VersionSpecificity.NONBREAKING && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]) ||
                       (versionSpecificity == VersionSpecificity.BUGFIX && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] == targetVersionNums[3])))
                 {
                     compatible = false;
                     break;
                 }
             }
             if (compatible)
             {
                 Log("Initializing Gadget Mod '" + mod.Attribute.Name + "'");
                 try
                 {
                     Registry.modRegistering = mod.Mod.ModID;
                     mod.Mod.Initialize();
                 }
                 catch (Exception e)
                 {
                     Log("Exception Loading Gadget Mod '" + mod.Attribute.Name + "':" + Environment.NewLine + e.ToString());
                 }
                 finally
                 {
                     Registry.modRegistering = -1;
                 }
             }
             else
             {
                 GadgetMods.SetEnabled(mod, false);
                 Log("Aborted loading Gadget Mod '" + mod.Attribute.Name + "' because although all required dependencies are available, they are of incompatible versions. " + mod.Attribute.Name + "'s dependencies are as follows: {" + mod.Attribute.Dependencies.Aggregate(string.Empty, (x, y) => x + ", " + y) + "}");
             }
         }
         else
         {
             GadgetMods.SetEnabled(mod, false);
             Log("Aborted loading Gadget Mod '" + mod.Attribute.Name + "' because it is missing required dependencies. " + mod.Attribute.Name + "'s dependencies are as follows: {" + mod.Attribute.Dependencies.Aggregate(string.Empty, (x, y) => x + ", " + y) + "}");
         }
     }
     GadgetCoreConfig.Update();
     Log("Gadget Mod Initialization Complete");
 }
Пример #2
0
        internal void EnableButton()
        {
            ModMenuEntry entry = modEntries[modIndex];

            if (gadgetIndex >= 0)
            {
                bool enabled = !entry.Gadgets[gadgetIndex].Gadget.Enabled;
                Gadgets.SetEnabled(entry.Gadgets[gadgetIndex], enabled);
            }
            else if (entry.Type == ModMenuEntryType.GADGET)
            {
                bool enabled = !GadgetMods.GetModByName(entry.Name).Enabled;
                GadgetMods.SetEnabled(entry.Name, enabled);
            }
            else
            {
                if (!File.Exists(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile()))
                {
                    File.Create(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile()).Dispose();
                }
                string   fileText  = File.ReadAllText(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile());
                string[] fileLines = File.ReadAllLines(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile());
                if (fileLines.Any(x => x.Equals(entry.Name)))
                {
                    File.WriteAllLines(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile(), fileLines.Where(x => !x.Equals(entry.Name)).ToArray());
                }
                else
                {
                    File.WriteAllText(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile(), fileText + Environment.NewLine + entry.Name);
                }
                if (modsToToggle.Contains(entry.Name))
                {
                    modsToToggle.Remove(entry.Name);
                }
                else
                {
                    modsToToggle.Add(entry.Name);
                }
            }
            Rebuild();
            UpdateRestartNeeded();
        }
Пример #3
0
 internal void EnableButton()
 {
     if (modIndex < GadgetMods.CountMods())
     {
         bool enabled = !GadgetMods.GetModInfo(modIndex).Mod.Enabled;
         GadgetMods.SetEnabled(modIndex, enabled);
         enableButton.GetComponentInChildren <Text>().text = enabled ? "Disable Gadget" : "Enable Gadget";
         toggle.GetComponentInChildren <Text>().color      = enabled ? new Color(1f, 1f, 1f, 1f) : new Color(1f, 1f, 1f, 0.5f);
         if (enabled)
         {
             if (!File.Exists(UMFData.DisabledModsFile))
             {
                 File.Create(UMFData.DisabledModsFile).Dispose();
             }
             File.WriteAllLines(UMFData.DisabledModsFile, File.ReadAllLines(UMFData.DisabledModsFile).Where(x => x != GadgetMods.GetModInfo(modIndex).UMFName).ToArray());
             enableUMFButton.GetComponentInChildren <Text>().text = "Disable Mod";
         }
     }
     UpdateRestartNeeded();
 }
Пример #4
0
        internal void EnableUMFButton()
        {
            if (!File.Exists(UMFData.DisabledModsFile))
            {
                File.Create(UMFData.DisabledModsFile).Dispose();
            }
            string fileText = File.ReadAllText(UMFData.DisabledModsFile);

            string[] fileLines = File.ReadAllLines(UMFData.DisabledModsFile);
            if (modIndex < GadgetMods.CountMods())
            {
                if (fileLines.Any(x => x.Equals(GadgetMods.GetModInfo(modIndex).UMFName)))
                {
                    File.WriteAllLines(UMFData.DisabledModsFile, fileLines.Where(x => !x.Equals(GadgetMods.GetModInfo(modIndex).UMFName)).ToArray());
                    enableButton.GetComponentInChildren <Text>().text    = GadgetMods.GetModInfo(modIndex).Mod.Enabled ? "Disable Gadget" : "Enable Gadget";
                    enableUMFButton.GetComponentInChildren <Text>().text = "Disable Mod";
                    toggle.GetComponentInChildren <Text>().color         = GadgetMods.GetModInfo(modIndex).Mod.Enabled ? new Color(1f, 1f, 1f, 1f) : new Color(1f, 1f, 1f, 0.5f);
                }
                else
                {
                    File.WriteAllText(UMFData.DisabledModsFile, fileText + Environment.NewLine + GadgetMods.GetModInfo(modIndex).UMFName);
                    GadgetMods.SetEnabled(modIndex, false);
                    enableButton.GetComponentInChildren <Text>().text    = "Enable Gadget";
                    enableUMFButton.GetComponentInChildren <Text>().text = "Enable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 0.5f);
                }
            }
            else if (modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count)
            {
                if (fileLines.Any(x => x.Equals(GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()])))
                {
                    File.WriteAllLines(UMFData.DisabledModsFile, fileLines.Where(x => !x.Equals(GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()])).ToArray());
                    enableUMFButton.GetComponentInChildren <Text>().text = "Disable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 1f);
                }
                else
                {
                    File.WriteAllText(UMFData.DisabledModsFile, fileText + Environment.NewLine + GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()]);
                    enableUMFButton.GetComponentInChildren <Text>().text = "Enable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 0.5f);
                }
            }
            else if (modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count)
            {
                if (fileLines.Any(x => x.Equals(GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count])))
                {
                    File.WriteAllLines(UMFData.DisabledModsFile, fileLines.Where(x => !x.Equals(GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count])).ToArray());
                    enableUMFButton.GetComponentInChildren <Text>().text = "Disable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 1f);
                }
                else
                {
                    File.WriteAllText(UMFData.DisabledModsFile, fileText + Environment.NewLine + GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count]);
                    enableUMFButton.GetComponentInChildren <Text>().text = "Enable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 0.5f);
                }
            }
            else
            {
                if (fileLines.Any(x => x.Equals(GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count])))
                {
                    File.WriteAllLines(UMFData.DisabledModsFile, fileLines.Where(x => !x.Equals(GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count])).ToArray());
                    enableUMFButton.GetComponentInChildren <Text>().text = "Disable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 1f);
                }
                else
                {
                    File.WriteAllText(UMFData.DisabledModsFile, fileText + Environment.NewLine + GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count]);
                    enableUMFButton.GetComponentInChildren <Text>().text = "Enable Mod";
                    toggle.GetComponentInChildren <Text>().color         = new Color(1f, 1f, 1f, 0.5f);
                }
            }
            UpdateRestartNeeded();
        }