Beispiel #1
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();
 }
Beispiel #2
0
 internal void Start()
 {
     for (int i = 0; i < GadgetMods.CountMods(); i++)
     {
         wasEnabled[i]    = GadgetMods.GetModInfo(i).Mod.Enabled;
         wasUMFEnabled[i] = true;
     }
     for (int i = 0; i < GadgetCore.nonGadgetMods.Count; i++)
     {
         wasUMFEnabled[GadgetMods.CountMods() + i] = true;
     }
     for (int i = 0; i < GadgetCore.disabledMods.Count; i++)
     {
         wasUMFEnabled[GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + i] = false;
     }
     for (int i = 0; i < GadgetCore.incompatibleMods.Count; i++)
     {
         wasUMFEnabled[GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + i] = false;
     }
     StartCoroutine(WatchForRestartNeeded());
 }
Beispiel #3
0
        internal void UnpackButton()
        {
            string mod;

            if (modIndex < GadgetMods.CountMods())
            {
                mod = Directory.GetFiles(UMFData.ModsPath, GadgetMods.GetModInfo(modIndex).UMFName + "*.zip").FirstOrDefault();
            }
            else if (modIndex < GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + GadgetCore.incompatibleMods.Count)
            {
                mod = Directory.GetFiles(UMFData.ModsPath, (modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count ? GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()] : modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count] : GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count]) + "*.zip").FirstOrDefault();
            }
            else
            {
                mod = GadgetCore.packedMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count - GadgetCore.incompatibleMods.Count];
            }
            if (!string.IsNullOrEmpty(mod) && ZipUtils.UnpackModFile(mod))
            {
                unpackButton.interactable = false;
                unpackedMods.Add(mod);
            }
        }
Beispiel #4
0
 public void UpdateInfo(Toggle toggle, int modIndex)
 {
     try
     {
         if (GadgetModConfigs.IsConfigMenuOpen(this.modIndex))
         {
             GadgetModConfigs.CloseConfigMenu(this.modIndex);
         }
         if (!File.Exists(UMFData.DisabledModsFile))
         {
             File.Create(UMFData.DisabledModsFile).Dispose();
         }
         this.toggle   = toggle;
         this.modIndex = modIndex;
         string[] disabledMods = File.ReadAllLines(UMFData.DisabledModsFile).Where(x => !string.IsNullOrEmpty(x)).ToArray();
         if (modIndex < GadgetMods.CountMods())
         {
             GadgetModInfo mod = GadgetMods.GetModInfo(modIndex);
             unpackButton.gameObject.SetActive(Directory.GetFiles(UMFData.ModsPath, mod.UMFName + "*.zip").Length > 0);
             enableUMFButton.interactable = !GadgetCore.dependencies.Any(x => !disabledMods.Contains(x.Key) && x.Value.Any(d => { string[] split = d.Split(' '); return(split[split.Length - 2].Equals(mod.UMFName)); }));
             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))))
             {
                 enableButton.interactable = 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])))
                     {
                         enableButton.interactable = false;
                         break;
                     }
                 }
             }
             else
             {
                 enableButton.interactable = false;
             }
             configButton.interactable = GadgetModConfigs.GetConfigMenuObject(modIndex) != null;
             enableButton.GetComponentInChildren <Text>().text    = mod.Mod.Enabled ? "Disable Gadget" : "Enable Gadget";
             enableUMFButton.GetComponentInChildren <Text>().text = File.ReadAllLines(UMFData.DisabledModsFile).Any(x => x.Equals(mod.UMFName)) ? "Enable Mod" : "Disable Mod";
             string desc       = mod.Mod.GetModDescription();
             bool   isDescNull = desc == null;
             bool   isModInfo  = false;
             if (string.IsNullOrEmpty(desc))
             {
                 try
                 {
                     desc = File.ReadAllText(UMFData.ModInfosPath + "/" + mod.UMFName + "_v" + UMFMod.GetModVersion(mod.UMFName) + "_ModInfo.txt");
                 }
                 catch (Exception) { }
                 finally
                 {
                     if (string.IsNullOrEmpty(desc) || desc == "A UMF Mod(umodframework.com) for Roguelands")
                     {
                         desc = "This mod does not have a description, or a ModInfo file." + Environment.NewLine + (isDescNull ? "You should suggest to the mod author that they add a description." : "");
                     }
                     else
                     {
                         isModInfo = true;
                     }
                 }
             }
             descText.text =
                 mod.Attribute.Name + " v" + UMFMod.GetModVersion(mod.UMFName).ToString() + (mod.Mod.Enabled ? " (Enabled)" : " (Disabled)") + Environment.NewLine +
                 "UMF Mod: " + mod.UMFName + Environment.NewLine +
                 (GadgetCore.dependencies.ContainsKey(mod.UMFName) ? ("Dependencies: " + GadgetCore.dependencies[mod.UMFName].Aggregate((x, y) => x + ", " + y) + Environment.NewLine) : "") +
                 "Required on clients: " + (mod.Attribute.RequiredOnClients ? "Yes" : "No") + Environment.NewLine +
                 (isModInfo ? "UMF Mod Info: " : "Description: ") + UMFMod.GetModDescription(mod.UMFName) + Environment.NewLine + Environment.NewLine + desc;
         }
         else if (modIndex < GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + GadgetCore.incompatibleMods.Count)
         {
             bool enabled = !File.ReadAllLines(UMFData.DisabledModsFile).Any(x => x.Equals(modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count ? GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()] : modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count] : GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count]));
             enableButton.GetComponentInChildren <Text>().text    = modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count >= 0 && modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? "Disabled" : "Not Gadget";
             enableUMFButton.GetComponentInChildren <Text>().text = enabled ? "Disable Mod" : "Enable Mod";
             string mod = modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count ? GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()] : modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count] : GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count];
             unpackButton.gameObject.SetActive(Directory.GetFiles(UMFData.ModsPath, mod + "*.zip").Length > 0);
             if (modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count && GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()].Equals("GadgetCore"))
             {
                 enableUMFButton.interactable = false;
             }
             else
             {
                 enableUMFButton.interactable = !GadgetCore.dependencies.Any(x => !disabledMods.Contains(x.Key) && x.Value.Any(d => { string[] split = d.Split(' '); return(split[split.Length - 2].Equals(mod)); }));
             }
             enableButton.interactable = false;
             configButton.interactable = GadgetModConfigs.GetConfigMenuObject(modIndex) != null;
             string desc = null;
             try
             {
                 desc = File.ReadAllText(UMFData.ModInfosPath + "/" + mod + "_v" + UMFMod.GetModVersion(mod) + "_ModInfo.txt");
             }
             catch (Exception) { }
             finally
             {
                 if (string.IsNullOrEmpty(desc) || desc == "A UMF Mod(umodframework.com) for Roguelands")
                 {
                     desc = "This mod does not have a ModInfo file.";
                 }
                 descText.text =
                     mod + " v" + UMFMod.GetModVersion(mod).ToString() + (enabled ? " (Enabled)" : " (Disabled)") + Environment.NewLine +
                     (GadgetCore.dependencies.ContainsKey(mod) ? ("Dependencies: " + GadgetCore.dependencies[mod].Aggregate((x, y) => x + ", " + y) + Environment.NewLine) : "") +
                     "UMF Mod Info: " + UMFMod.GetModDescription(mod) + Environment.NewLine + Environment.NewLine + desc;
             }
         }
         else
         {
             string mod = GadgetCore.packedMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count - GadgetCore.incompatibleMods.Count];
             enableButton.interactable    = false;
             enableUMFButton.interactable = false;
             configButton.interactable    = false;
             unpackButton.interactable    = !unpackedMods.Contains(mod);
             unpackButton.gameObject.SetActive(true);
             descText.text = Path.GetFileName(mod) + Environment.NewLine + Environment.NewLine + "This mod is still packed in its .zip, and needs to be unpacked to run!";
         }
     }
     catch (Exception e)
     {
         descText.text = "An error occured while populating the info panel for this mod! Check GadgetCore.log for details.";
         GadgetCore.Log("An error occured while populating the info panel for the mod with the index " + modIndex + ": " + e.ToString());
     }
 }
Beispiel #5
0
 private bool IsRestartNeeded()
 {
     if (!File.Exists(UMFData.DisabledModsFile))
     {
         File.Create(UMFData.DisabledModsFile).Dispose();
     }
     if (unpackedMods.Count > 0)
     {
         return(true);
     }
     string[] disabledMods = File.ReadAllLines(UMFData.DisabledModsFile).Where(x => !string.IsNullOrEmpty(x)).ToArray();
     for (int i = 0; i < GadgetMods.CountMods(); i++)
     {
         if (wasEnabled.ContainsKey(i))
         {
             if (wasEnabled[i] != GadgetMods.GetModInfo(i).Mod.Enabled)
             {
                 return(true);
             }
         }
         if (wasUMFEnabled.ContainsKey(i))
         {
             if (wasUMFEnabled[i] != !disabledMods.Contains(GadgetMods.GetModInfo(i).UMFName))
             {
                 return(true);
             }
         }
         if (originalConfig.ContainsKey(i))
         {
             if (!originalConfig[i].Equals(File.ReadAllText(UMFData.ConfigsPath + "/" + GadgetMods.GetModInfo(modIndex).UMFName + ".ini")))
             {
                 return(true);
             }
         }
     }
     for (int i = 0; i < GadgetCore.nonGadgetMods.Count; i++)
     {
         if (wasUMFEnabled.ContainsKey(GadgetMods.CountMods() + i))
         {
             if (wasUMFEnabled[GadgetMods.CountMods() + i] != !disabledMods.Contains(GadgetCore.nonGadgetMods[i]))
             {
                 return(true);
             }
         }
         if (originalConfig.ContainsKey(GadgetMods.CountMods() + i))
         {
             if (!originalConfig[GadgetMods.CountMods() + i].Equals(File.ReadAllText(UMFData.ConfigsPath + "/" + GadgetCore.nonGadgetMods[i] + ".ini")))
             {
                 return(true);
             }
         }
     }
     for (int i = 0; i < GadgetCore.disabledMods.Count; i++)
     {
         if (wasUMFEnabled.ContainsKey(GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + i))
         {
             if (wasUMFEnabled[GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + i] != !disabledMods.Contains(GadgetCore.disabledMods[i]))
             {
                 return(true);
             }
         }
         if (originalConfig.ContainsKey(GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + i))
         {
             if (!originalConfig[GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + i].Equals(File.ReadAllText(UMFData.ConfigsPath + "/" + GadgetCore.disabledMods[i] + ".ini")))
             {
                 return(true);
             }
         }
     }
     for (int i = 0; i < GadgetCore.incompatibleMods.Count; i++)
     {
         if (wasUMFEnabled.ContainsKey(GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + i))
         {
             if (wasUMFEnabled[GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + i] != !disabledMods.Contains(GadgetCore.incompatibleMods[i]))
             {
                 return(true);
             }
         }
         if (originalConfig.ContainsKey(GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + i))
         {
             if (!originalConfig[GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + i].Equals(File.ReadAllText(UMFData.ConfigsPath + "/" + GadgetCore.incompatibleMods[i] + ".ini")))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #6
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();
        }
        private static void BuildModMenu()
        {
            ModMenu = new GameObject("MODMENU");
            ModMenu.SetActive(false);
            ModMenuBackButtonBeam      = UnityEngine.Object.Instantiate(InstanceTracker.Menuu.menuOptions.transform.Find("beamm").gameObject, ModMenu.transform);
            ModMenuBackButtonBeam.name = "beamm";
            ModMenuBackButtonBeam.transform.localScale = new Vector3(30, 0, 1);
            ModMenuBackButtonBeam.transform.position   = new Vector3(0, -13.5f, 1);
            ModMenuBackButtonHolder      = UnityEngine.Object.Instantiate(InstanceTracker.Menuu.menuOptions.transform.Find("BUTTONHOLDER").gameObject, ModMenu.transform);
            ModMenuBackButtonHolder.name = "BUTTONHOLDER";
            ModMenuBackButtonHolder.transform.position = new Vector3(0, -13.5f, 0);
            ModMenuBackButtonHolder.GetComponent <Animation>().RemoveClip("bbbac2");
            ModMenuBackButtonHolder.GetComponent <Animation>().AddClip(BuildModMenuButtonAnimClip(true), "bbbac2");
            ModMenuBackButtonHolder.GetComponent <Animation>().clip = ModMenuBackButtonHolder.GetComponent <Animation>().GetClip("bbbac2");
            ModMenuCanvas = new GameObject("Mod Menu Canvas", typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster), typeof(CanvasGroup)).GetComponent <Canvas>();
            ModMenuCanvas.GetComponent <CanvasGroup>().alpha          = 0;
            ModMenuCanvas.GetComponent <CanvasGroup>().interactable   = false;
            ModMenuCanvas.GetComponent <CanvasGroup>().blocksRaycasts = false;
            ModMenuCanvas.GetComponent <RectTransform>().pivot        = new Vector2(0.5f, 0.5f);
            ModMenuCanvas.renderMode   = RenderMode.ScreenSpaceOverlay;
            ModMenuCanvas.pixelPerfect = true;
            CanvasScaler scaler = ModMenuCanvas.GetComponent <CanvasScaler>();

            scaler.scaleFactor                        = 2;
            scaler.referencePixelsPerUnit             = 100;
            ModConfigMenuText                         = UnityEngine.Object.Instantiate(InstanceTracker.Menuu.menuOptions.transform.Find("txt0").gameObject, ModMenu.transform);
            ModConfigMenuText.name                    = "txt0";
            ModConfigMenuText.transform.localPosition = new Vector3(0, 14, -1);
            Array.ForEach(ModConfigMenuText.GetComponentsInChildren <TextMesh>(), x => { x.text = "MOD CONFIG MENU"; x.anchor = TextAnchor.UpperCenter; });
            GameObject restartRequiredText = UnityEngine.Object.Instantiate(ModConfigMenuText, ModMenu.transform);

            restartRequiredText.SetActive(false);
            restartRequiredText.name = "Restart Required Text";
            restartRequiredText.transform.localPosition = new Vector3(0, -10.5f, -1);
            restartRequiredText.transform.localScale   *= 0.75f;
            Array.ForEach(restartRequiredText.GetComponentsInChildren <TextMesh>(), x => { x.text = "Restart Required!"; x.anchor = TextAnchor.UpperCenter; });
            ModMenuPanel = new GameObject("Panel", typeof(RectTransform)).GetComponent <RectTransform>();
            ModMenuPanel.SetParent(ModMenuCanvas.transform);
            ModMenuPanel.anchorMin = new Vector2(0.15f, 0.15f);
            ModMenuPanel.anchorMax = new Vector2(0.85f, 0.85f);
            ModMenuPanel.offsetMin = Vector2.zero;
            ModMenuPanel.offsetMax = Vector2.zero;
            ModConfigMenus         = new GameObject("Mod Config Menus", typeof(RectTransform)).GetComponent <RectTransform>();
            ModConfigMenus.SetParent(ModMenuCanvas.transform);
            ModConfigMenus.anchorMin = new Vector2(0.15f, 0.15f);
            ModConfigMenus.anchorMax = new Vector2(0.85f, 0.85f);
            ModConfigMenus.offsetMin = Vector2.zero;
            ModConfigMenus.offsetMax = Vector2.zero;
            Image background = new GameObject("Background", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <Image>();

            background.transform.SetParent(ModMenuPanel);
            background.rectTransform.anchorMin = new Vector2(0f, 0f);
            background.rectTransform.anchorMax = new Vector2(01f, 1f);
            background.rectTransform.offsetMin = Vector2.zero;
            background.rectTransform.offsetMax = Vector2.zero;
            background.type       = Image.Type.Sliced;
            background.fillCenter = true;
            Texture2D boxTex = GadgetCoreAPI.LoadTexture2D("boxsprite.png");

            boxTex.filterMode = FilterMode.Point;
            Texture2D boxMaskTex = GadgetCoreAPI.LoadTexture2D("boxmask.png");

            boxMaskTex.filterMode = FilterMode.Point;
            Texture2D barTex = GadgetCoreAPI.LoadTexture2D("barsprite.png");

            barTex.filterMode = FilterMode.Point;
            BoxSprite         = Sprite.Create(boxTex, new Rect(0, 0, boxTex.width, boxTex.height), new Vector2(0.5f, 0.5f), 100, 1, SpriteMeshType.Tight, new Vector4(15, 15, 15, 15));
            BoxMask           = Sprite.Create(boxMaskTex, new Rect(0, 0, boxMaskTex.width, boxMaskTex.height), new Vector2(0.5f, 0.5f), 100, 1, SpriteMeshType.Tight, new Vector4(15, 15, 15, 15));
            BarSprite         = Sprite.Create(barTex, new Rect(0, 0, barTex.width, barTex.height), new Vector2(0.5f, 0.5f), 100, 1, SpriteMeshType.Tight, new Vector4(1, 1, 1, 1));
            background.sprite = BoxSprite;

            EventSystem           eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule)).GetComponent <EventSystem>();
            StandaloneInputModule inputModule = eventSystem.GetComponent <StandaloneInputModule>();

            inputModule.horizontalAxis = "Horizontal1";
            inputModule.verticalAxis   = "Vertical1";
            inputModule.submitButton   = "Jump";
            inputModule.cancelButton   = "Cancel";

            GadgetModConfigs.BuildConfigMenus(ModConfigMenus);

            ModMenuDescPanel = new GameObject("Mod Desc Panel", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(ModDescPanelController), typeof(ScrollRect)).GetComponent <ModDescPanelController>();
            ModMenuDescPanel.GetComponent <RectTransform>().SetParent(ModMenuPanel);
            ModMenuDescPanel.GetComponent <RectTransform>().anchorMin = new Vector2(0.4f, 0.25f);
            ModMenuDescPanel.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 1f);
            ModMenuDescPanel.GetComponent <RectTransform>().offsetMin = new Vector2(0, 5);
            ModMenuDescPanel.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            ModMenuDescPanel.GetComponent <Image>().sprite            = BoxSprite;
            ModMenuDescPanel.GetComponent <Image>().type       = Image.Type.Sliced;
            ModMenuDescPanel.GetComponent <Image>().fillCenter = true;
            Mask modMenuDescPanelMask = new GameObject("Mask", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Mask)).GetComponent <Mask>();

            modMenuDescPanelMask.GetComponent <RectTransform>().SetParent(ModMenuDescPanel.transform);
            modMenuDescPanelMask.GetComponent <RectTransform>().anchorMin = new Vector2(0f, 0f);
            modMenuDescPanelMask.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 1f);
            modMenuDescPanelMask.GetComponent <RectTransform>().offsetMin = Vector2.zero;
            modMenuDescPanelMask.GetComponent <RectTransform>().offsetMax = Vector2.zero;
            modMenuDescPanelMask.GetComponent <Image>().sprite            = BoxMask;
            modMenuDescPanelMask.GetComponent <Image>().type       = Image.Type.Sliced;
            modMenuDescPanelMask.GetComponent <Image>().fillCenter = true;
            modMenuDescPanelMask.showMaskGraphic = false;
            RectTransform modMenuDescViewport = new GameObject("Viewport", typeof(RectTransform)).GetComponent <RectTransform>();

            modMenuDescViewport.SetParent(modMenuDescPanelMask.transform);
            modMenuDescViewport.anchorMin = new Vector2(0f, 0f);
            modMenuDescViewport.anchorMax = new Vector2(1f, 1f);
            modMenuDescViewport.offsetMin = new Vector2(10, 10);
            modMenuDescViewport.offsetMax = new Vector2(-10, -10);
            Text modMenuDescText = new GameObject("Description", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text), typeof(ContentSizeFitter)).GetComponent <Text>();

            modMenuDescText.rectTransform.SetParent(modMenuDescViewport);
            modMenuDescText.rectTransform.anchorMin = new Vector2(0f, 0f);
            modMenuDescText.rectTransform.anchorMax = new Vector2(1f, 1f);
            modMenuDescText.rectTransform.offsetMin = Vector2.zero;
            modMenuDescText.rectTransform.offsetMax = Vector2.zero;
            modMenuDescText.rectTransform.pivot     = new Vector2(0.5f, 1f);
            modMenuDescText.font               = ModConfigMenuText.GetComponent <TextMesh>().font;
            modMenuDescText.fontSize           = 12;
            modMenuDescText.horizontalOverflow = HorizontalWrapMode.Wrap;
            modMenuDescText.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            ModMenuDescPanel.GetComponent <ScrollRect>().content           = modMenuDescText.rectTransform;
            ModMenuDescPanel.GetComponent <ScrollRect>().horizontal        = false;
            ModMenuDescPanel.GetComponent <ScrollRect>().scrollSensitivity = 5;
            ModMenuDescPanel.GetComponent <ScrollRect>().viewport          = modMenuDescViewport;
            ModMenuDescPanel.descText            = modMenuDescText;
            ModMenuDescPanel.restartRequiredText = restartRequiredText;
            Image modMenuButtonPanel = new GameObject("Button Panel", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <Image>();

            modMenuButtonPanel.GetComponent <RectTransform>().SetParent(ModMenuPanel);
            modMenuButtonPanel.GetComponent <RectTransform>().anchorMin = new Vector2(0.4f, 0f);
            modMenuButtonPanel.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 0.25f);
            modMenuButtonPanel.GetComponent <RectTransform>().offsetMin = new Vector2(0, 10);
            modMenuButtonPanel.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -5);
            modMenuButtonPanel.GetComponent <Image>().sprite            = BoxSprite;
            modMenuButtonPanel.GetComponent <Image>().type       = Image.Type.Sliced;
            modMenuButtonPanel.GetComponent <Image>().fillCenter = true;
            ModMenuDescPanel.configButton = new GameObject("Config Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();
            ModMenuDescPanel.configButton.GetComponent <RectTransform>().SetParent(modMenuButtonPanel.transform);
            ModMenuDescPanel.configButton.GetComponent <RectTransform>().anchorMin = new Vector2(2f / 3f, 0f);
            ModMenuDescPanel.configButton.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 1f);
            ModMenuDescPanel.configButton.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            ModMenuDescPanel.configButton.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            ModMenuDescPanel.configButton.GetComponent <Image>().sprite            = BoxSprite;
            ModMenuDescPanel.configButton.GetComponent <Image>().type       = Image.Type.Sliced;
            ModMenuDescPanel.configButton.GetComponent <Image>().fillCenter = true;
            ModMenuDescPanel.configButton.targetGraphic = ModMenuDescPanel.configButton.GetComponent <Image>();
            ModMenuDescPanel.configButton.onClick.AddListener(ModMenuDescPanel.ConfigButton);
            Text configButtonText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            configButtonText.rectTransform.SetParent(ModMenuDescPanel.configButton.transform);
            configButtonText.rectTransform.anchorMin = new Vector2(0f, 0f);
            configButtonText.rectTransform.anchorMax = new Vector2(1f, 1f);
            configButtonText.rectTransform.offsetMin = Vector2.zero;
            configButtonText.rectTransform.offsetMax = Vector2.zero;
            configButtonText.alignment       = TextAnchor.MiddleCenter;
            configButtonText.font            = modMenuDescText.font;
            configButtonText.fontSize        = 12;
            configButtonText.text            = "Configure";
            ModMenuDescPanel.umfConfigButton = new GameObject("UMF Config Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();
            ModMenuDescPanel.umfConfigButton.GetComponent <RectTransform>().SetParent(ModMenuCanvas.transform);
            ModMenuDescPanel.umfConfigButton.GetComponent <RectTransform>().anchorMin = new Vector2(0.025f, 0.4f);
            ModMenuDescPanel.umfConfigButton.GetComponent <RectTransform>().anchorMax = new Vector2(0.125f, 0.6f);
            ModMenuDescPanel.umfConfigButton.GetComponent <RectTransform>().offsetMin = new Vector2(0, 0);
            ModMenuDescPanel.umfConfigButton.GetComponent <RectTransform>().offsetMax = new Vector2(0, 0);
            ModMenuDescPanel.umfConfigButton.GetComponent <Image>().sprite            = BoxSprite;
            ModMenuDescPanel.umfConfigButton.GetComponent <Image>().type       = Image.Type.Sliced;
            ModMenuDescPanel.umfConfigButton.GetComponent <Image>().fillCenter = true;
            ModMenuDescPanel.umfConfigButton.targetGraphic = ModMenuDescPanel.umfConfigButton.GetComponent <Image>();
            ModMenuDescPanel.umfConfigButton.onClick.AddListener(ModMenuDescPanel.UMFConfigButton);
            Text umfConfigButtonText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            umfConfigButtonText.rectTransform.SetParent(ModMenuDescPanel.umfConfigButton.transform);
            umfConfigButtonText.rectTransform.anchorMin = new Vector2(0f, 0f);
            umfConfigButtonText.rectTransform.anchorMax = new Vector2(1f, 1f);
            umfConfigButtonText.rectTransform.offsetMin = Vector2.zero;
            umfConfigButtonText.rectTransform.offsetMax = Vector2.zero;
            umfConfigButtonText.alignment = TextAnchor.MiddleCenter;
            umfConfigButtonText.font      = modMenuDescText.font;
            umfConfigButtonText.fontSize  = 12;
            umfConfigButtonText.text      = "Configure UMF";
            Button configReloadButton = new GameObject("Config Reload Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();

            configReloadButton.GetComponent <RectTransform>().SetParent(ModMenuCanvas.transform);
            configReloadButton.GetComponent <RectTransform>().anchorMin = new Vector2(0.875f, 0.4f);
            configReloadButton.GetComponent <RectTransform>().anchorMax = new Vector2(0.975f, 0.6f);
            configReloadButton.GetComponent <RectTransform>().offsetMin = new Vector2(0, 0);
            configReloadButton.GetComponent <RectTransform>().offsetMax = new Vector2(0, 0);
            configReloadButton.GetComponent <Image>().sprite            = BoxSprite;
            configReloadButton.GetComponent <Image>().type       = Image.Type.Sliced;
            configReloadButton.GetComponent <Image>().fillCenter = true;
            configReloadButton.targetGraphic = configReloadButton.GetComponent <Image>();
            configReloadButton.onClick.AddListener(() =>
            {
                foreach (string mod in UMFData.ModNames)
                {
                    UMFGUI.SendCommand("cfgReload " + mod);
                }
                GadgetModConfigs.ResetAllConfigMenus();
            });
            Text configReloadButtonText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            configReloadButtonText.rectTransform.SetParent(configReloadButton.transform);
            configReloadButtonText.rectTransform.anchorMin = new Vector2(0f, 0f);
            configReloadButtonText.rectTransform.anchorMax = new Vector2(1f, 1f);
            configReloadButtonText.rectTransform.offsetMin = Vector2.zero;
            configReloadButtonText.rectTransform.offsetMax = Vector2.zero;
            configReloadButtonText.alignment = TextAnchor.MiddleCenter;
            configReloadButtonText.font      = modMenuDescText.font;
            configReloadButtonText.fontSize  = 12;
            configReloadButtonText.text      = "Reload Configs";
            ModMenuDescPanel.enableUMFButton = new GameObject("Enable UMF Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();
            ModMenuDescPanel.enableUMFButton.GetComponent <RectTransform>().SetParent(modMenuButtonPanel.transform);
            ModMenuDescPanel.enableUMFButton.GetComponent <RectTransform>().anchorMin = new Vector2(1f / 3f, 0f);
            ModMenuDescPanel.enableUMFButton.GetComponent <RectTransform>().anchorMax = new Vector2(2f / 3f, 1f);
            ModMenuDescPanel.enableUMFButton.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            ModMenuDescPanel.enableUMFButton.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            ModMenuDescPanel.enableUMFButton.GetComponent <Image>().sprite            = BoxSprite;
            ModMenuDescPanel.enableUMFButton.GetComponent <Image>().type       = Image.Type.Sliced;
            ModMenuDescPanel.enableUMFButton.GetComponent <Image>().fillCenter = true;
            ModMenuDescPanel.enableUMFButton.targetGraphic = ModMenuDescPanel.enableUMFButton.GetComponent <Image>();
            ModMenuDescPanel.enableUMFButton.onClick.AddListener(ModMenuDescPanel.EnableUMFButton);
            Text enableUMFButtonText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            enableUMFButtonText.rectTransform.SetParent(ModMenuDescPanel.enableUMFButton.transform);
            enableUMFButtonText.rectTransform.anchorMin = new Vector2(0f, 0f);
            enableUMFButtonText.rectTransform.anchorMax = new Vector2(1f, 1f);
            enableUMFButtonText.rectTransform.offsetMin = Vector2.zero;
            enableUMFButtonText.rectTransform.offsetMax = Vector2.zero;
            enableUMFButtonText.alignment = TextAnchor.MiddleCenter;
            enableUMFButtonText.font      = modMenuDescText.font;
            enableUMFButtonText.material  = configButtonText.font.material;
            enableUMFButtonText.fontSize  = 12;
            enableUMFButtonText.text      = "Enable Mod";
            ModMenuDescPanel.enableButton = new GameObject("Enable UMF Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();
            ModMenuDescPanel.enableButton.GetComponent <RectTransform>().SetParent(modMenuButtonPanel.transform);
            ModMenuDescPanel.enableButton.GetComponent <RectTransform>().anchorMin = new Vector2(0f, 0f);
            ModMenuDescPanel.enableButton.GetComponent <RectTransform>().anchorMax = new Vector2(1f / 3f, 1f);
            ModMenuDescPanel.enableButton.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            ModMenuDescPanel.enableButton.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            ModMenuDescPanel.enableButton.GetComponent <Image>().sprite            = BoxSprite;
            ModMenuDescPanel.enableButton.GetComponent <Image>().type       = Image.Type.Sliced;
            ModMenuDescPanel.enableButton.GetComponent <Image>().fillCenter = true;
            ModMenuDescPanel.enableButton.targetGraphic = ModMenuDescPanel.enableButton.GetComponent <Image>();
            ModMenuDescPanel.enableButton.onClick.AddListener(ModMenuDescPanel.EnableButton);
            Text enableButtonText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            enableButtonText.rectTransform.SetParent(ModMenuDescPanel.enableButton.transform);
            enableButtonText.rectTransform.anchorMin = new Vector2(0f, 0f);
            enableButtonText.rectTransform.anchorMax = new Vector2(1f, 1f);
            enableButtonText.rectTransform.offsetMin = Vector2.zero;
            enableButtonText.rectTransform.offsetMax = Vector2.zero;
            enableButtonText.alignment    = TextAnchor.MiddleCenter;
            enableButtonText.font         = modMenuDescText.font;
            enableButtonText.fontSize     = 12;
            enableButtonText.text         = "Enable Gadget";
            ModMenuDescPanel.unpackButton = new GameObject("Unpack Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();
            ModMenuDescPanel.unpackButton.GetComponent <RectTransform>().SetParent(modMenuButtonPanel.transform);
            ModMenuDescPanel.unpackButton.GetComponent <RectTransform>().anchorMin = new Vector2(2f / 3f, 1f);
            ModMenuDescPanel.unpackButton.GetComponent <RectTransform>().anchorMax = new Vector2(1, 2f);
            ModMenuDescPanel.unpackButton.GetComponent <RectTransform>().offsetMin = new Vector2(10, 20);
            ModMenuDescPanel.unpackButton.GetComponent <RectTransform>().offsetMax = new Vector2(-10, 0);
            ModMenuDescPanel.unpackButton.GetComponent <Image>().sprite            = BoxSprite;
            ModMenuDescPanel.unpackButton.GetComponent <Image>().type       = Image.Type.Sliced;
            ModMenuDescPanel.unpackButton.GetComponent <Image>().fillCenter = true;
            ModMenuDescPanel.unpackButton.targetGraphic = ModMenuDescPanel.unpackButton.GetComponent <Image>();
            ModMenuDescPanel.unpackButton.onClick.AddListener(ModMenuDescPanel.UnpackButton);
            Text unpackButtonText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            unpackButtonText.rectTransform.SetParent(ModMenuDescPanel.unpackButton.transform);
            unpackButtonText.rectTransform.anchorMin = new Vector2(0f, 0f);
            unpackButtonText.rectTransform.anchorMax = new Vector2(1f, 1f);
            unpackButtonText.rectTransform.offsetMin = Vector2.zero;
            unpackButtonText.rectTransform.offsetMax = Vector2.zero;
            unpackButtonText.alignment = TextAnchor.MiddleCenter;
            unpackButtonText.font      = modMenuDescText.font;
            unpackButtonText.fontSize  = 12;
            unpackButtonText.text      = "Unpack Mod";

            GadgetModInfo[] gadgetMods           = GadgetMods.ListAllModInfos();
            string[]        allMods              = gadgetMods.Select(x => x.Attribute.Name).Concat(GadgetCore.nonGadgetMods).Concat(GadgetCore.disabledMods).Concat(GadgetCore.incompatibleMods).Concat(GadgetCore.packedMods).ToArray();
            int             gadgetModCount       = GadgetMods.CountMods();
            int             normalModCount       = GadgetCore.nonGadgetMods.Count;
            int             disabledModCount     = GadgetCore.disabledMods.Count;
            int             incompatibleModCount = GadgetCore.incompatibleMods.Count;
            ScrollRect      modListScrollView    = new GameObject("Scroll View", typeof(RectTransform), typeof(ScrollRect), typeof(CanvasRenderer), typeof(Image)).GetComponent <ScrollRect>();

            modListScrollView.GetComponent <RectTransform>().SetParent(ModMenuPanel);
            modListScrollView.GetComponent <RectTransform>().anchorMin = new Vector2(0f, 0f);
            modListScrollView.GetComponent <RectTransform>().anchorMax = new Vector2(0.3f, 1f);
            modListScrollView.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            modListScrollView.GetComponent <RectTransform>().offsetMax = new Vector2(0, -10);
            modListScrollView.GetComponent <Image>().sprite            = BoxSprite;
            modListScrollView.GetComponent <Image>().type       = Image.Type.Sliced;
            modListScrollView.GetComponent <Image>().fillCenter = true;
            Mask modListScrollViewMask = new GameObject("Mask", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Mask)).GetComponent <Mask>();

            modListScrollViewMask.GetComponent <RectTransform>().SetParent(modListScrollView.transform);
            modListScrollViewMask.GetComponent <RectTransform>().anchorMin = new Vector2(0f, 0f);
            modListScrollViewMask.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 1f);
            modListScrollViewMask.GetComponent <RectTransform>().offsetMin = Vector2.zero;
            modListScrollViewMask.GetComponent <RectTransform>().offsetMax = Vector2.zero;
            modListScrollViewMask.GetComponent <Image>().sprite            = BoxMask;
            modListScrollViewMask.GetComponent <Image>().type       = Image.Type.Sliced;
            modListScrollViewMask.GetComponent <Image>().fillCenter = true;
            modListScrollViewMask.showMaskGraphic = false;
            RectTransform modListViewport = new GameObject("Viewport", typeof(RectTransform)).GetComponent <RectTransform>();

            modListViewport.SetParent(modListScrollViewMask.transform);
            modListViewport.anchorMin = new Vector2(0f, 0f);
            modListViewport.anchorMax = new Vector2(1f, 1f);
            modListViewport.offsetMin = new Vector2(10, 10);
            modListViewport.offsetMax = new Vector2(-10, -10);
            RectTransform modList = new GameObject("ModList", typeof(RectTransform), typeof(ToggleGroup)).GetComponent <RectTransform>();

            modList.SetParent(modListViewport);
            modList.anchorMin = new Vector2(0f, allMods.Length <= 6 ? 0f : (1f - (allMods.Length / 6f)));
            modList.anchorMax = new Vector2(1f, 1f);
            modList.offsetMin = Vector2.zero;
            modList.offsetMax = Vector2.zero;
            Scrollbar modListScrollBar = new GameObject("Scrollbar", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Scrollbar)).GetComponent <Scrollbar>();

            modListScrollBar.GetComponent <RectTransform>().SetParent(modListScrollView.transform);
            modListScrollBar.GetComponent <RectTransform>().anchorMin = new Vector2(1f, 0f);
            modListScrollBar.GetComponent <RectTransform>().anchorMax = new Vector2(1.25f, 1f);
            modListScrollBar.GetComponent <RectTransform>().offsetMin = Vector2.zero;
            modListScrollBar.GetComponent <RectTransform>().offsetMax = Vector2.zero;
            modListScrollBar.GetComponent <Image>().sprite            = BoxSprite;
            modListScrollBar.GetComponent <Image>().type       = Image.Type.Sliced;
            modListScrollBar.GetComponent <Image>().fillCenter = true;
            RectTransform modListScrollBarHandle = new GameObject("Handle", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <RectTransform>();

            modListScrollBarHandle.SetParent(modListScrollBar.transform);
            modListScrollBarHandle.anchorMin = new Vector2(0.05f, 0.05f);
            modListScrollBarHandle.anchorMax = new Vector2(0.95f, 0.95f);
            modListScrollBarHandle.offsetMin = Vector2.zero;
            modListScrollBarHandle.offsetMax = Vector2.zero;
            modListScrollBarHandle.GetComponent <Image>().sprite     = BoxSprite;
            modListScrollBarHandle.GetComponent <Image>().type       = Image.Type.Sliced;
            modListScrollBarHandle.GetComponent <Image>().fillCenter = true;
            modListScrollBar.targetGraphic = modListScrollBarHandle.GetComponent <Image>();
            modListScrollBar.handleRect    = modListScrollBarHandle;
            modListScrollBar.direction     = Scrollbar.Direction.BottomToTop;
            if (allMods.Length <= 5)
            {
                modListScrollBar.interactable = false;
            }
            modListScrollView.content           = modList;
            modListScrollView.horizontal        = false;
            modListScrollView.scrollSensitivity = 5;
            modListScrollView.movementType      = ScrollRect.MovementType.Clamped;
            modListScrollView.viewport          = modListViewport;
            modListScrollView.verticalScrollbar = modListScrollBar;
            float  entryHeight = allMods.Length <= 6 ? (1f / 6f) : (1f / allMods.Length);
            Toggle firstToggle = null;

            for (int i = 0; i < allMods.Length; i++)
            {
                RectTransform modEntry = new GameObject("Mod Entry: " + allMods[i], typeof(RectTransform), typeof(Toggle), typeof(CanvasRenderer), typeof(Image), typeof(Mask)).GetComponent <RectTransform>();
                modEntry.SetParent(modList);
                modEntry.anchorMin = new Vector2(0f, 1 - ((i + 1) * entryHeight));
                modEntry.anchorMax = new Vector2(1f, 1 - (i * entryHeight));
                modEntry.offsetMin = Vector2.zero;
                modEntry.offsetMax = Vector2.zero;
                Toggle modToggle   = modEntry.GetComponent <Toggle>();
                Image  modSelected = new GameObject("Selected", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <Image>();
                modSelected.rectTransform.SetParent(modEntry);
                modSelected.rectTransform.anchorMin = new Vector2(0f, 0f);
                modSelected.rectTransform.anchorMax = new Vector2(1f, 1f);
                modSelected.rectTransform.offsetMin = Vector2.zero;
                modSelected.rectTransform.offsetMax = Vector2.zero;
                modSelected.sprite = BoxSprite;
                modSelected.type   = Image.Type.Sliced;
                modSelected.color  = i < gadgetModCount ? new Color(1f, 1f, 0.25f, 1f) : i >= gadgetModCount + normalModCount + disabledModCount + incompatibleModCount ? new Color(0.5f, 0.5f, 0.5f, 1f) : i >= gadgetModCount + normalModCount + disabledModCount ? new Color(1f, 0f, 0f, 1f) : i >= gadgetModCount + normalModCount ? new Color(0.25f, 0.25f, 0.25f, 1f) : new Color(1f, 1f, 1f, 1f);
                Text modLabel = new GameObject("Label", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();
                modLabel.rectTransform.SetParent(modEntry);
                modLabel.rectTransform.anchorMin = new Vector2(0f, 0f);
                modLabel.rectTransform.anchorMax = new Vector2(1f, 1f);
                modLabel.rectTransform.offsetMin = new Vector2(10, 10);
                modLabel.rectTransform.offsetMax = new Vector2(-10, -10);
                modLabel.font               = ModConfigMenuText.GetComponent <TextMesh>().font;
                modLabel.fontSize           = 12;
                modLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
                modLabel.verticalOverflow   = VerticalWrapMode.Overflow;
                modLabel.alignment          = TextAnchor.MiddleLeft;
                modLabel.text               = (i < gadgetModCount + normalModCount + disabledModCount + incompatibleModCount ? allMods[i] : Path.GetFileNameWithoutExtension(allMods[i])) + Environment.NewLine + (i < gadgetModCount ? ("Gadget Mod (" + GadgetMods.GetModInfo(allMods[i]).UMFName + ")") : (i < gadgetModCount + normalModCount ? "Non-Gadget Mod" : i < gadgetModCount + normalModCount + disabledModCount ? "Disabled" : i < gadgetModCount + normalModCount + disabledModCount + incompatibleModCount ? "Incompatible" : "Packed Mod"));
                if ((i < gadgetModCount && !gadgetMods[i].Mod.Enabled) || i >= gadgetModCount + GadgetCore.nonGadgetMods.Count)
                {
                    modLabel.color = new Color(1f, 1f, 1f, 0.5f);
                }
                modToggle.GetComponent <Image>().sprite = BoxSprite;
                modToggle.GetComponent <Image>().type   = Image.Type.Sliced;
                modToggle.GetComponent <Image>().color  = i < gadgetModCount ? new Color(1f, 1f, 0.25f, 0.25f) : i >= gadgetModCount + normalModCount + disabledModCount + incompatibleModCount ? new Color(0.5f, 0.5f, 0.5f, 0.25f) : i >= gadgetModCount + normalModCount + disabledModCount ? new Color(1f, 0f, 0f, 0.25f) : i >= gadgetModCount + normalModCount ? new Color(0.25f, 0.25f, 0.25f, 0.25f) : new Color(1f, 1f, 1f, 0.25f);
                modToggle.transition       = Selectable.Transition.None;
                modToggle.isOn             = i == 0;
                modToggle.toggleTransition = Toggle.ToggleTransition.None;
                modToggle.graphic          = modSelected;
                modToggle.group            = modList.GetComponent <ToggleGroup>();
                int toggleIndex = i;
                if (i == 0)
                {
                    firstToggle = modToggle;
                }
                modToggle.onValueChanged.AddListener((toggled) => { if (toggled)
                                                                    {
                                                                        ModMenuDescPanel.UpdateInfo(modToggle, toggleIndex);
                                                                    }
                                                     });
            }

            if (allMods.Length > 0)
            {
                ModMenuDescPanel.UpdateInfo(firstToggle, 0);
            }
        }
Beispiel #8
0
        private static void LoadModAssemblies()
        {
            Log("Identifying Gadget Mods");
            nonGadgetMods    = new List <string>();
            disabledMods     = new List <string>();
            incompatibleMods = new List <string>();
            List <string> libNames     = Directory.GetFiles(UMFData.LibrariesPath).Select(x => Path.GetFileNameWithoutExtension(x)).ToList();
            List <string> verifiedMods = new List <string>();
            List <string> verifiedLibs = new List <string>();

            foreach (string modName in UMFData.ModNames)
            {
                if (libNames.Contains(modName))
                {
                    verifiedLibs.Add(modName);
                }
                else
                {
                    verifiedMods.Add(modName);
                }
            }
            GadgetCoreAPI.ModNames = new System.Collections.ObjectModel.ReadOnlyCollection <string>(verifiedMods);
            GadgetCoreAPI.LibNames = new System.Collections.ObjectModel.ReadOnlyCollection <string>(verifiedLibs);
            List <string> modNames = verifiedMods;

            int[] currentVersionNums = GadgetCoreAPI.VERSION.Split('.').Select(x => int.Parse(x)).ToArray();
            if (currentVersionNums.Length != 4)
            {
                Array.Resize(ref currentVersionNums, 4);
            }
            for (int i = 0; i < modNames.Count; i++)
            {
                Assembly assembly = UMFMod.GetMod(modNames[i]);
                if (assembly != null)
                {
                    bool foundGadgetMod = false;
                    foreach (Type type in assembly.GetTypes())
                    {
                        GadgetModAttribute attribute = (GadgetModAttribute)type.GetCustomAttributes(typeof(GadgetModAttribute), true).FirstOrDefault();
                        if (attribute != null && type.IsSubclassOf(typeof(GadgetMod)))
                        {
                            foundGadgetMod = true;
                            int[] targetVersionNums = attribute.TargetGCVersion.Split('.').Select(x => int.Parse(x)).ToArray();
                            if (targetVersionNums.Length != 4)
                            {
                                Array.Resize(ref targetVersionNums, 4);
                            }
                            if ((attribute.GadgetVersionSpecificity == 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]))))) ||
                                (attribute.GadgetVersionSpecificity == VersionSpecificity.MINOR && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && (currentVersionNums[2] > targetVersionNums[2] || (currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]))) ||
                                (attribute.GadgetVersionSpecificity == VersionSpecificity.NONBREAKING && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]) ||
                                (attribute.GadgetVersionSpecificity == VersionSpecificity.BUGFIX && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] == targetVersionNums[3]))
                            {
                                GadgetMod mod = null;
                                try
                                {
                                    mod = Activator.CreateInstance(type) as GadgetMod;
                                    if (mod != null)
                                    {
                                        Log("Found Gadget Mod to load: " + attribute.Name + ", in assembly: {" + assembly.FullName + "}");
                                        GadgetMods.RegisterMod(new GadgetModInfo(mod, assembly, attribute, modNames[i]));
                                    }
                                }
                                catch (Exception) { }
                                finally
                                {
                                    if (mod == null)
                                    {
                                        Log("Found Gadget Mod without a parameterless constructor: " + attribute.Name + ", in assembly: {" + assembly.FullName + "}");
                                    }
                                }
                            }
                            else
                            {
                                incompatibleMods.Add(assembly.GetName().Name);
                                int rD = (int)attribute.GadgetVersionSpecificity;
                                Log("Found Gadget Mod with an incompatible version: " + attribute.Name + ", in assembly: {" + assembly.FullName + "}. Requires version: " + new string(attribute.TargetGCVersion.TakeWhile(x => (x == '.' ? --rD : rD) > 0).ToArray()));
                            }
                        }
                    }
                    if (!foundGadgetMod)
                    {
                        nonGadgetMods.Add(modNames[i]);
                    }
                }
                else
                {
                    disabledMods.Add(modNames[i]);
                }
            }
            GadgetMods.SortMods();
            if (!Directory.Exists(Path.Combine(UMFData.ModsPath, "PackedMods")))
            {
                Directory.CreateDirectory(Path.Combine(UMFData.ModsPath, "PackedMods"));
            }
            packedMods = Directory.GetFiles(UMFData.ModsPath, "*.zip").Where(x => !UMFData.Mods.Select(y => y.GetName().Name).Any(y => y == Path.GetFileNameWithoutExtension(x).Split('_')[0])).Union(Directory.GetFiles(Path.Combine(UMFData.ModsPath, "PackedMods"), "*.zip").Where(x => !UMFData.Mods.Select(y => y.GetName().Name).Any(y => y == Path.GetFileNameWithoutExtension(x).Split('_')[0]))).ToList();

            dependencies = new Dictionary <string, List <string> >();
            Assembly[] allMods = GadgetMods.ListAllModInfos().Select(x => x.Assembly).Concat(nonGadgetMods.Select(x => UMFMod.GetMod(x))).Concat(incompatibleMods.Select(x => UMFMod.GetMod(x))).ToArray();
            for (int i = 0; i < allMods.Length; i++)
            {
                Assembly      mod          = allMods[i];
                List <string> dependencies = new List <string>();
                if (i < GadgetMods.CountMods())
                {
                    GadgetModInfo gadgetMod = GadgetMods.GetModInfo(i);
                    int           rD        = (int)gadgetMod.Attribute.GadgetVersionSpecificity;
                    dependencies.Add("GadgetCore v" + new string(gadgetMod.Attribute.TargetGCVersion.TakeWhile(x => (x == '.' ? --rD : rD) > 0).ToArray()));
                }
                dependencies.AddRange(mod.GetReferencedAssemblies().Where(x => !x.Name.Equals("GadgetCore") && allMods.Select(a => a.GetName().Name).Contains(x.Name)).Select(x => x.Name + " v" + x.Version));
                if (dependencies.Count > 0)
                {
                    GadgetCore.dependencies.Add(mod.GetName().Name, dependencies.ToList());
                }
            }
            foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos())
            {
                foreach (string dependency in mod.Attribute.Dependencies)
                {
                    string[] splitDependency = dependency.Split(' ');
                    if (!dependencies[mod.UMFName].Select(x => { string[] split = x.Split(' '); return(string.Join("", split.Take(split.Length - 1).ToArray())); }).Contains(string.Join("", splitDependency.Take(splitDependency.Length - 1).ToArray())))
                    {
                        dependencies[mod.UMFName].Add(dependency);
                    }
                }
            }

            Log("Finished Identifying Gadget Mods, to load: " + GadgetMods.CountMods());
        }