internal void RequestModList(NetworkMessageInfo info) { if (Network.isServer) { SendRequiredModList(GadgetMods.ListAllModInfos().Where(x => x.Mod.Enabled && x.Attribute.RequiredOnClients).Select(x => x.Attribute.Name + ":" + x.Mod.GetModVersionString()).Aggregate(new StringBuilder(), (x, y) => { if (x.Length > 0) { x.Append(","); } x.Append(y); return(x); }).ToString(), info); } else { GadgetCore.Log("Host is requesting local mod list. Sending..."); GadgetNetwork.connectTime = Time.realtimeSinceStartup; if (view == null) { view = GetComponent <NetworkView>(); } view.RPC("SendRequiredModList", RPCMode.Server, GadgetMods.ListAllModInfos().Where(x => x.Mod.Enabled && x.Attribute.RequiredOnClients).Select(x => x.Attribute.Name + ":" + x.Mod.GetModVersionString()).Aggregate(new StringBuilder(), (x, y) => { if (x.Length > 0) { x.Append(","); } x.Append(y); return(x); }).ToString()); } }
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"); }
public static void Prefix(GameScript __instance) { InstanceTracker.GameScript = __instance; GadgetCore.GenerateSpriteSheet(); GadgetUtils.SafeCopyTexture(__instance.TileManager.GetComponent <ChunkWorld>().Texture, 0, 0, 0, 0, 128, 128, GadgetCoreAPI.spriteSheet, 0, 0, 0, 0); __instance.TileManager.GetComponent <ChunkWorld>().Texture = GadgetCoreAPI.spriteSheet; __instance.WallManager.GetComponent <ChunkWorld>().Texture = GadgetCoreAPI.spriteSheet; foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos()) { __instance.gameObject.AddComponent <GadgetModHookScript>().Mod = mod; } }
//Add your config vars here. internal static void Load() { try { using (UMFConfig cfg = new UMFConfig()) { string cfgVer = cfg.Read("ConfigVersion", new UMFConfigString()); if (cfgVer != string.Empty && cfgVer != configVersion) { cfg.DeleteConfig(false); GadgetCore.Log("The config file was outdated and has been deleted. A new config will be generated."); } //cfg.Write("SupportsHotLoading", new UMFConfigBool(false)); //Uncomment if your mod can't be loaded once the game has started. //cfg.Write("ModDependencies", new UMFConfigStringArray(new string[] { "" })); //A comma separated list of mod names that this mod requires to function. //cfg.Write("ModDependenciesVersions", new UMFConfigStringArray(new string[] { "" })); //A comma separated list of mod versions matching the ModDependencies setting. cfg.Read("LoadPriority", new UMFConfigString("AboveNormal")); cfg.Write("MinVersion", new UMFConfigString("0.52.1")); //cfg.Write("MaxVersion", new UMFConfigString("0.54.99999.99999")); //Uncomment if you think your mod may break with the next major UMF release. cfg.Write("UpdateURL", new UMFConfigString("")); cfg.Write("ConfigVersion", new UMFConfigString(configVersion)); GadgetCore.Log("Finished UMF Settings."); MaxConnections = cfg.Read("MaxConnections", new UMFConfigInt(4, 1, int.MaxValue, 4), "The maximum number of connections allowed when using host-and-play. This setting only matters on the host."); UseUPnP = cfg.Read("UseUPnP", new UMFConfigBool(false), "If True, will attempt to use UPnP to bypass the need to port-forward to host-and-play over the internet. Not all routers support this. Disabled by default due to severe unresolved bugs that prevent the game from working at all sometimes."); GadgetNetwork.MatrixTimeout = cfg.Read("NetworkTimeout", new UMFConfigFloat(2.5f), "How long to wait for the host's game to respond to Gadget Core's ID synchronization. If the host's game does not respond in time, it will be assumed that the host does not have Gadget Core installed."); string enabledModsString = PlayerPrefs.GetString("EnabledMods", ""); try { enabledMods = enabledModsString.Split(',').Select(x => x.Split(':')).ToDictionary(x => x[0], x => bool.Parse(x[1])); } catch (IndexOutOfRangeException) { enabledMods = new Dictionary <string, bool>(); } foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos()) { mod.Mod.Enabled = enabledMods.ContainsKey(mod.Attribute.Name) ? enabledMods[mod.Attribute.Name] : (enabledMods[mod.Attribute.Name] = mod.Attribute.EnableByDefault); } GadgetCore.Log("Finished loading settings."); } } catch (Exception e) { GadgetCore.Log("Error loading mod settings: " + e.ToString()); } }
private static void InitializeRegistries() { Log("Initializing Registries"); GameRegistry.RegisterRegistry(ItemRegistry.GetSingleton()); GameRegistry.RegisterRegistry(ChipRegistry.GetSingleton()); GameRegistry.RegisterRegistry(TileRegistry.GetSingleton()); GameRegistry.RegisterRegistry(EntityRegistry.GetSingleton()); foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos()) { if (mod.Mod.Enabled) { foreach (Registry registry in mod.Mod.CreateRegistries()) { GameRegistry.RegisterRegistry(registry); } } } Log("Finished Initializing Registries"); }
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(); }
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(); }
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()); }
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); } }
internal void Build() { string modInfo = null; foreach (GadgetMod mod in GadgetMods.ListAllMods().Where(x => x.LoadedGadgets.Count > 0)) { if (mod.Name == "GadgetCore") { modInfo = CoreMod.GadgetCoreMod.GetDesc(); } else if (mod.HasModFile("ModInfo.txt")) { using (GadgetModFile infoFile = mod.GetModFile("ModInfo.txt")) modInfo = infoFile.ReadAllText(); } if (string.IsNullOrEmpty(modInfo) || modInfo == "Insert the description for your mod here!") { modInfo = "This Gadget mod does not have a ModInfo file."; } Dictionary <string, string> info = new Dictionary <string, string> { ["Name"] = mod.Name, ["Version"] = mod.Version.ToString(), ["File Name"] = Path.GetFileName(mod.ModPath), ["Dependencies"] = mod.ModDependencies.Count > 0 ? mod.ModDependencies.Concat() : "None", ["Gadgets"] = mod.LoadedGadgets.Select(x => x.Attribute.Name).Concat() }; if (mod.UnloadedGadgets.Count > 0) { info.Add("Unloaded/Errored Gadgets", mod.UnloadedGadgets.Select(x => x.Attribute.Name).Concat()); } using (GadgetModFile infoFile = mod.GetModFile("ModInfo.txt")) modEntries.Add(new ModMenuEntry(mod.Name, ModMenuEntryType.GADGET, modInfo, info, mod.LoadedGadgets.ToArray())); } foreach (GadgetMod mod in GadgetLoader.EmptyMods) { if (mod.Name == "GadgetCore") { modInfo = CoreMod.GadgetCoreMod.GetDesc(); } else if (mod.HasModFile("ModInfo.txt")) { using (GadgetModFile infoFile = mod.GetModFile("ModInfo.txt")) modInfo = infoFile.ReadAllText(); } if (string.IsNullOrEmpty(modInfo) || modInfo == "Insert the description for your mod here!") { modInfo = "This Gadget mod does not have a ModInfo file."; } Dictionary <string, string> info = new Dictionary <string, string> { ["Name"] = mod.Name, ["Version"] = mod.Version.ToString(), ["File Name"] = Path.GetFileName(mod.ModPath), ["Dependencies"] = mod.ModDependencies.Count > 0 ? mod.ModDependencies.Concat() : "None", }; if (mod.UnloadedGadgets.Count > 0) { info.Add("Unloaded/Errored Gadgets", mod.UnloadedGadgets.Select(x => x.Attribute.Name).Concat()); } modEntries.Add(new ModMenuEntry(mod.Name, ModMenuEntryType.EMPTY_GADGET, modInfo, info)); } foreach (GadgetMod mod in GadgetLoader.IncompatibleMods) { if (mod.Name == "GadgetCore") { modInfo = CoreMod.GadgetCoreMod.GetDesc(); } else if (mod.HasModFile("ModInfo.txt")) { using (GadgetModFile infoFile = mod.GetModFile("ModInfo.txt")) modInfo = infoFile.ReadAllText(); } if (string.IsNullOrEmpty(modInfo) || modInfo == "Insert the description for your mod here!") { modInfo = "This Gadget mod does not have a ModInfo file."; } Dictionary <string, string> info = new Dictionary <string, string> { ["Name"] = mod.Name, ["Version"] = mod.Version.ToString(), ["File Name"] = Path.GetFileName(mod.ModPath), ["Dependencies"] = mod.ModDependencies.Count > 0 ? mod.ModDependencies.Concat() : "None" }; modEntries.Add(new ModMenuEntry(mod.Name, ModMenuEntryType.INCOMPATIBLE_GADGET, modInfo, info)); } foreach (GadgetMod mod in GadgetMods.ListAllMods().Where(x => x.LoadedGadgets.Count == 0)) { if (mod.Name == "GadgetCore") { modInfo = CoreMod.GadgetCoreMod.GetDesc(); } else if (mod.HasModFile("ModInfo.txt")) { using (GadgetModFile infoFile = mod.GetModFile("ModInfo.txt")) modInfo = infoFile.ReadAllText(); } if (string.IsNullOrEmpty(modInfo) || modInfo == "Insert the description for your mod here!") { modInfo = "This Gadget mod does not have a ModInfo file."; } Dictionary <string, string> info = new Dictionary <string, string> { ["Name"] = mod.Name, ["Version"] = mod.Version.ToString(), ["File Name"] = Path.GetFileName(mod.ModPath), ["Dependencies"] = mod.ModDependencies.Count > 0 ? mod.ModDependencies.Concat() : "None", }; if (mod.UnloadedGadgets.Count > 0) { info.Add("Unloaded/Errored Gadgets", mod.UnloadedGadgets.Select(x => x.Attribute.Name).Concat()); } modEntries.Add(new ModMenuEntry(mod.Name, ModMenuEntryType.ERRORED_GADGET, modInfo, info)); } foreach (Tuple <string, string> mod in GadgetLoader.ErroredMods) { if (mod.Item1 == "GadgetCore") { modInfo = CoreMod.GadgetCoreMod.GetDesc(); } modInfo = "As there was an error loading this mod, its description could not be loaded.\nThe error that prevented this mod from loading should be in the log.\nYou should report this to the mod author."; Dictionary <string, string> info = new Dictionary <string, string> { ["Name"] = mod.Item1, ["File Name"] = Path.GetFileName(mod.Item2) }; modEntries.Add(new ModMenuEntry(mod.Item1, ModMenuEntryType.ERRORED_GADGET, modInfo, info)); } if (GadgetCoreAPI.GetUMFAPI() != null) { foreach (string mod in GadgetCoreAPI.GetUMFAPI().GetModNames()) { try { modInfo = File.ReadAllText(GadgetCoreAPI.GetUMFAPI().GetModInfosPath() + "/" + mod + "_v" + GadgetCoreAPI.GetUMFAPI().GetModVersion(mod) + "_ModInfo.txt"); } catch (Exception) { } if (string.IsNullOrEmpty(modInfo) || modInfo == "A UMF Mod(umodframework.com) for Roguelands") { modInfo = "This UMF mod does not have a ModInfo file."; } Dictionary <string, string> info = new Dictionary <string, string>() { ["Name"] = mod, ["Version"] = GadgetCoreAPI.GetUMFAPI().GetModVersion(mod).ToString(), ["Description"] = GadgetCoreAPI.GetUMFAPI().GetModDescription(mod), }; if (GadgetCoreAPI.GetUMFAPI().GetModNamesEnabled().Contains(mod)) { modEntries.Add(new ModMenuEntry(mod, ModMenuEntryType.UMF, modInfo, info)); } else { modEntries.Add(new ModMenuEntry(mod, ModMenuEntryType.DISABLED_UMF, modInfo, info)); } umfModEntries.Add(modEntries[modEntries.Count - 1]); } foreach (string mod in GadgetCoreAPI.GetUMFAPI().GetModNamesMissingDependencies()) { try { modInfo = File.ReadAllText(GadgetCoreAPI.GetUMFAPI().GetModInfosPath() + "/" + mod + "_v" + GadgetCoreAPI.GetUMFAPI().GetModVersion(mod) + "_ModInfo.txt"); } catch (Exception) { } if (string.IsNullOrEmpty(modInfo) || modInfo == "A UMF Mod(umodframework.com) for Roguelands") { modInfo = "This UMF mod does not have a ModInfo file."; } Dictionary <string, string> info = new Dictionary <string, string>() { ["Name"] = mod, ["Version"] = GadgetCoreAPI.GetUMFAPI().GetModVersion(mod).ToString(), ["Description"] = GadgetCoreAPI.GetUMFAPI().GetModDescription(mod), }; modEntries.Add(new ModMenuEntry(mod, ModMenuEntryType.INCOMPATIBLE_UMF, modInfo, info)); } } int modCount = modEntries.Count + modEntries.Where(x => x.Type == ModMenuEntryType.GADGET).SelectMany(x => x.Gadgets).Count(); ScrollRect modListScrollView = new GameObject("Scroll View", typeof(RectTransform), typeof(ScrollRect), typeof(CanvasRenderer), typeof(Image)).GetComponent <ScrollRect>(); modListScrollView.GetComponent <RectTransform>().SetParent(transform); 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 = SceneInjector.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 = SceneInjector.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, modCount <= 6 ? 0f : (1f - (modCount / 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 = SceneInjector.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 = SceneInjector.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 (modCount <= 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 = modCount <= 6 ? (1f / 6f) : (1f / modCount); Toggle selectedToggle = null; int bonusOffset = 0; for (int i = 0; i < modEntries.Count; i++) { ModMenuEntry modEntry = modEntries[i]; if (modEntry.Gadgets.Length > 0) { int gadgetCount = modEntry.Gadgets.Count(); float gadgetHeight = 1f / (gadgetCount + 1); RectTransform modEntryRect = new GameObject("Gadget-Containing Mod Entry: " + modEntry.Name, typeof(RectTransform), typeof(Toggle), typeof(CanvasRenderer), typeof(Image), typeof(Mask)).GetComponent <RectTransform>(); modEntryRect.SetParent(modList); modEntryRect.anchorMin = new Vector2(0f, 1 - ((i + bonusOffset + 1 + gadgetCount) * entryHeight)); modEntryRect.anchorMax = new Vector2(1f, 1 - ((i + bonusOffset) * entryHeight)); modEntryRect.offsetMin = Vector2.zero; modEntryRect.offsetMax = Vector2.zero; Toggle modToggle = modEntryRect.GetComponent <Toggle>(); Image modSelected = new GameObject("Selected", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <Image>(); modSelected.rectTransform.SetParent(modEntryRect); 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 = SceneInjector.BoxSprite; modSelected.type = Image.Type.Sliced; Text modLabel = new GameObject("Label", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>(); modLabel.rectTransform.SetParent(modEntryRect); modLabel.rectTransform.anchorMin = new Vector2(0f, 1f - gadgetHeight); modLabel.rectTransform.anchorMax = new Vector2(1f, 1f); modLabel.rectTransform.offsetMin = new Vector2(10, 10); modLabel.rectTransform.offsetMax = new Vector2(-10, -10); modLabel.font = SceneInjector.ModConfigMenuText.GetComponent <TextMesh>().font; modLabel.fontSize = 12; modLabel.horizontalOverflow = HorizontalWrapMode.Overflow; modLabel.verticalOverflow = VerticalWrapMode.Overflow; modLabel.alignment = TextAnchor.MiddleLeft; modToggle.GetComponent <Image>().sprite = SceneInjector.BoxSprite; modToggle.GetComponent <Image>().type = Image.Type.Sliced; modToggle.transition = Selectable.Transition.None; modToggle.isOn = i == modIndex && gadgetIndex == -1; modToggle.toggleTransition = Toggle.ToggleTransition.None; modToggle.graphic = modSelected; modToggle.group = modList.GetComponent <ToggleGroup>(); int toggleIndex = i; if (i == modIndex) { selectedToggle = modToggle; } modToggle.onValueChanged.AddListener((toggled) => { if (toggled) { UpdateInfo(modToggle, toggleIndex); GadgetCoreAPI.CloseDialog(); } }); switch (modEntry.Type) { case ModMenuEntryType.GADGET: modSelected.color = new Color(1f, 1f, 0.5f, 1f); modToggle.GetComponent <Image>().color = new Color(1f, 1f, 0.5f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 1f); modLabel.text = modEntry.Name + "\nGadget Mod"; break; case ModMenuEntryType.EMPTY_GADGET: modSelected.color = new Color(0.5f, 0.5f, 0.125f, 1f); modToggle.GetComponent <Image>().color = new Color(0.5f, 0.5f, 0.125f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 0.5f); modLabel.text = modEntry.Name + "\nEmpty Gadget Mod"; break; case ModMenuEntryType.INCOMPATIBLE_GADGET: modSelected.color = new Color(1f, 0.5f, 0f, 1f); modToggle.GetComponent <Image>().color = new Color(1f, 0.5f, 0f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 0.5f); modLabel.text = modEntry.Name + "\nIncompatible Gadget Mod"; break; case ModMenuEntryType.ERRORED_GADGET: modSelected.color = new Color(1f, 0f, 0f, 1f); modToggle.GetComponent <Image>().color = new Color(1f, 0f, 0f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 0.5f); modLabel.text = modEntry.Name + "\nErrored Gadget Mod"; break; case ModMenuEntryType.UMF: modSelected.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 1f); modToggle.GetComponent <Image>().color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 0.25f); modLabel.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 1f); modLabel.text = modEntry.Name + "\nUMF Mod"; break; case ModMenuEntryType.DISABLED_UMF: modSelected.color = new Color(69 / 255f, 34 / 255f, 9 / 255f, 1f); modToggle.GetComponent <Image>().color = new Color(69 / 255f, 34 / 255f, 9 / 255f, 0.25f); modLabel.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 0.5f); modLabel.text = modEntry.Name + "\nDisabled UMF Mod"; break; case ModMenuEntryType.INCOMPATIBLE_UMF: modSelected.color = new Color(210 / 255f, 105 / 255f, 30 / 255f, 1f); modToggle.GetComponent <Image>().color = new Color(210 / 255f, 105 / 255f, 30 / 255f, 0.25f); modLabel.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 0.5f); modLabel.text = modEntry.Name + "\nIncompatible UMF Mod"; break; } for (int g = 0; g < gadgetCount; g++) { GadgetInfo gadget = modEntry.Gadgets[g]; RectTransform gadgetRect = new GameObject("Gadget: " + gadget.Attribute.Name, typeof(RectTransform), typeof(Toggle), typeof(CanvasRenderer), typeof(Image), typeof(Mask)).GetComponent <RectTransform>(); gadgetRect.SetParent(modEntryRect); gadgetRect.anchorMin = new Vector2(0f, 1 - ((g + 2) * gadgetHeight)); gadgetRect.anchorMax = new Vector2(1f, 1 - ((g + 1) * gadgetHeight)); gadgetRect.offsetMin = new Vector2(10f, 10f); gadgetRect.offsetMax = new Vector2(-10f, 10f); Toggle gadgetToggle = gadgetRect.GetComponent <Toggle>(); Image gadgetSelected = new GameObject("Selected", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <Image>(); gadgetSelected.rectTransform.SetParent(gadgetRect); gadgetSelected.rectTransform.anchorMin = new Vector2(0f, 0f); gadgetSelected.rectTransform.anchorMax = new Vector2(1f, 1f); gadgetSelected.rectTransform.offsetMin = Vector2.zero; gadgetSelected.rectTransform.offsetMax = Vector2.zero; gadgetSelected.sprite = SceneInjector.BoxSprite; gadgetSelected.type = Image.Type.Sliced; gadgetSelected.color = new Color(1f, 1f, 0.5f, 1f); Text gadgetLabel = new GameObject("Label", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>(); gadgetLabel.rectTransform.SetParent(gadgetRect); gadgetLabel.rectTransform.anchorMin = new Vector2(0f, 0f); gadgetLabel.rectTransform.anchorMax = new Vector2(1f, 1f); gadgetLabel.rectTransform.offsetMin = new Vector2(10, 10); gadgetLabel.rectTransform.offsetMax = new Vector2(-10, -10); gadgetLabel.font = SceneInjector.ModConfigMenuText.GetComponent <TextMesh>().font; gadgetLabel.fontSize = 12; gadgetLabel.horizontalOverflow = HorizontalWrapMode.Overflow; gadgetLabel.verticalOverflow = VerticalWrapMode.Overflow; gadgetLabel.alignment = TextAnchor.MiddleLeft; gadgetLabel.text = gadget.Attribute.Name + "\n" + (gadget.Gadget.Enabled ? "Enabled" : "Disabled"); gadgetLabel.color = gadget.Gadget.Enabled ? new Color(1f, 1f, 1f, 1f) : new Color(1f, 1f, 1f, 0.5f); gadgetToggle.GetComponent <Image>().sprite = SceneInjector.BoxSprite; gadgetToggle.GetComponent <Image>().type = Image.Type.Sliced; gadgetToggle.transition = Selectable.Transition.None; gadgetToggle.isOn = i == modIndex && g == this.gadgetIndex; gadgetToggle.toggleTransition = Toggle.ToggleTransition.None; gadgetToggle.graphic = gadgetSelected; gadgetToggle.group = modList.GetComponent <ToggleGroup>(); gadgetToggle.GetComponent <Image>().color = new Color(1f, 1f, 0.5f, 0.25f); int gadgetIndex = g; gadgetToggle.onValueChanged.AddListener((toggled) => { if (toggled) { UpdateInfo(modToggle, toggleIndex, gadgetIndex); GadgetCoreAPI.CloseDialog(); } }); bonusOffset++; } } else { RectTransform modEntryRect = new GameObject("Mod Entry: " + modEntry.Name, typeof(RectTransform), typeof(Toggle), typeof(CanvasRenderer), typeof(Image), typeof(Mask)).GetComponent <RectTransform>(); modEntryRect.SetParent(modList); modEntryRect.anchorMin = new Vector2(0f, 1 - ((i + bonusOffset + 1) * entryHeight)); modEntryRect.anchorMax = new Vector2(1f, 1 - ((i + bonusOffset) * entryHeight)); modEntryRect.offsetMin = Vector2.zero; modEntryRect.offsetMax = Vector2.zero; Toggle modToggle = modEntryRect.GetComponent <Toggle>(); Image modSelected = new GameObject("Selected", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <Image>(); modSelected.rectTransform.SetParent(modEntryRect); 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 = SceneInjector.BoxSprite; modSelected.type = Image.Type.Sliced; Text modLabel = new GameObject("Label", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>(); modLabel.rectTransform.SetParent(modEntryRect); 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 = SceneInjector.ModConfigMenuText.GetComponent <TextMesh>().font; modLabel.fontSize = 12; modLabel.horizontalOverflow = HorizontalWrapMode.Overflow; modLabel.verticalOverflow = VerticalWrapMode.Overflow; modLabel.alignment = TextAnchor.MiddleLeft; modToggle.GetComponent <Image>().sprite = SceneInjector.BoxSprite; modToggle.GetComponent <Image>().type = Image.Type.Sliced; modToggle.transition = Selectable.Transition.None; modToggle.isOn = i == modIndex; modToggle.toggleTransition = Toggle.ToggleTransition.None; modToggle.graphic = modSelected; modToggle.group = modList.GetComponent <ToggleGroup>(); int toggleIndex = i; if (i == modIndex) { selectedToggle = modToggle; } modToggle.onValueChanged.AddListener((toggled) => { if (toggled) { UpdateInfo(modToggle, toggleIndex); GadgetCoreAPI.CloseDialog(); } }); switch (modEntry.Type) { case ModMenuEntryType.EMPTY_GADGET: modSelected.color = new Color(0.5f, 0.5f, 0.125f, 1f); modToggle.GetComponent <Image>().color = new Color(0.5f, 0.5f, 0.125f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 0.5f); modLabel.text = modEntry.Name + "\nEmpty Gadget Mod"; break; case ModMenuEntryType.INCOMPATIBLE_GADGET: modSelected.color = new Color(1f, 0.5f, 0f, 1f); modToggle.GetComponent <Image>().color = new Color(1f, 0.5f, 0f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 0.5f); modLabel.text = modEntry.Name + "\nIncompatible Gadget Mod"; break; case ModMenuEntryType.ERRORED_GADGET: modSelected.color = new Color(1f, 0f, 0f, 1f); modToggle.GetComponent <Image>().color = new Color(1f, 0f, 0f, 0.25f); modLabel.color = new Color(1f, 1f, 1f, 0.5f); modLabel.text = modEntry.Name + "\nErrored Gadget Mod"; break; case ModMenuEntryType.UMF: modSelected.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 1f); modToggle.GetComponent <Image>().color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 0.25f); modLabel.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 1f); modLabel.text = modEntry.Name + "\nUMF Mod"; break; case ModMenuEntryType.DISABLED_UMF: modSelected.color = new Color(69 / 255f, 34 / 255f, 9 / 255f, 1f); modToggle.GetComponent <Image>().color = new Color(69 / 255f, 34 / 255f, 9 / 255f, 0.25f); modLabel.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 0.5f); modLabel.text = modEntry.Name + "\nDisabled UMF Mod"; break; case ModMenuEntryType.INCOMPATIBLE_UMF: modSelected.color = new Color(210 / 255f, 105 / 255f, 30 / 255f, 1f); modToggle.GetComponent <Image>().color = new Color(210 / 255f, 105 / 255f, 30 / 255f, 0.25f); modLabel.color = new Color(139 / 255f, 69 / 255f, 19 / 255f, 0.5f); modLabel.text = modEntry.Name + "\nIncompatible UMF Mod"; break; } } } modListScrollView.GetComponent <RectTransform>().localScale = Vector3.one; if (scrollPositionCache >= 0) { modListScrollView.verticalNormalizedPosition = 1 - (scrollPositionCache / (modList.anchorMax.y - modList.anchorMin.y)); } scrollPositionCache = -1; if (GadgetModConfigs.GetConfigMenuObject(0) != null) { GadgetModConfigs.ResetAllConfigMenus(); } else { GadgetModConfigs.BuildConfigMenus(SceneInjector.ModConfigMenus); } if (modCount > 0) { UpdateInfo(selectedToggle, modIndex, gadgetIndex); } }
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); }
internal void SendRequiredModList(string modList, NetworkMessageInfo info) { try { bool isCompatible = true; int modCount = 0; string[][] splitModList = string.IsNullOrEmpty(modList) ? new string[0][] : modList.Split(',').Select(x => x.Split(':')).ToArray(); foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos().Where(x => x.Mod.Enabled && x.Attribute.RequiredOnClients)) { modCount++; int[] hostVersionNums = mod.Mod.GetModVersionString().Split('.').Select(x => int.Parse(x)).ToArray(); int[] clientVersionNums = splitModList.Single(x => x[0] == mod.Attribute.Name)[1].Split('.').Select(x => int.Parse(x)).Take(4).ToArray(); hostVersionNums = hostVersionNums.Concat(Enumerable.Repeat(0, 4 - hostVersionNums.Length)).ToArray(); clientVersionNums = clientVersionNums.Concat(Enumerable.Repeat(0, 4 - clientVersionNums.Length)).ToArray(); if (!((mod.Attribute.GadgetVersionSpecificity == VersionSpecificity.MAJOR && clientVersionNums[0] == hostVersionNums[0] && (clientVersionNums[1] > hostVersionNums[1] || (clientVersionNums[1] == hostVersionNums[1] && (clientVersionNums[2] > hostVersionNums[2] || (clientVersionNums[2] == hostVersionNums[2] && clientVersionNums[3] >= hostVersionNums[3]))))) || (mod.Attribute.GadgetVersionSpecificity == VersionSpecificity.MINOR && clientVersionNums[0] == hostVersionNums[0] && clientVersionNums[1] == hostVersionNums[1] && (clientVersionNums[2] > hostVersionNums[2] || (clientVersionNums[2] == hostVersionNums[2] && clientVersionNums[3] >= hostVersionNums[3]))) || (mod.Attribute.GadgetVersionSpecificity == VersionSpecificity.NONBREAKING && clientVersionNums[0] == hostVersionNums[0] && clientVersionNums[1] == hostVersionNums[1] && clientVersionNums[2] == hostVersionNums[2] && clientVersionNums[3] >= hostVersionNums[3]) || (mod.Attribute.GadgetVersionSpecificity == VersionSpecificity.BUGFIX && clientVersionNums[0] == hostVersionNums[0] && clientVersionNums[1] == hostVersionNums[1] && clientVersionNums[2] == hostVersionNums[2] && clientVersionNums[3] == hostVersionNums[3]))) { isCompatible = false; } } if (isCompatible && modCount != splitModList.Length) { GadgetCore.Log(modCount + ":" + splitModList.Length); isCompatible = false; } if (isCompatible) { if (string.IsNullOrEmpty(info.sender.ipAddress)) { GadgetCore.Log("Self-connection succesfully established and identified."); ReceiveIDMatrixData(GadgetNetwork.GenerateIDMatrixData()); } else { GadgetCore.Log("A client connected with compatible mods: " + info.sender.ipAddress); view.RPC("ReceiveIDMatrixData", info.sender, GadgetNetwork.GenerateIDMatrixData()); } } else { GadgetCore.Log("A client tried to connect with incompatible mods: " + info.sender.ipAddress + Environment.NewLine + modList); if (Network.isServer) { Network.Disconnect(); } else { Network.CloseConnection(info.sender, true); } } } catch (Exception e) { GadgetCore.Log("The following error occured processing the client's mod list: " + info.sender.ipAddress + Environment.NewLine + e.ToString()); if (Network.isServer) { Network.CloseConnection(info.sender, true); } else { Network.Disconnect(); } } }
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()); }
public static void Prefix(PlayerScript __instance) { if (__instance.GetComponent <NetworkView>().isMine) { InstanceTracker.PlayerScript = __instance; InstanceTracker.SpawnerScript = Camera.main.gameObject.GetComponent <SpawnerScript>(); __instance.GetComponentInChildren <AudioSource>().PlayOneShot(GadgetCoreAPI.LoadAudioClipInternal("Sounds/particleacc.wav", GadgetMods.GetModByName("Tiers+")), 1); } }
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); } }
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()); } }
public static MethodBase[] TargetMethods() { MethodBase[] methods = GadgetMods.ListAllMods().SelectMany(x => x.Assembly.GetExportedTypes()).Where(x => typeof(CustomEntityScript).IsAssignableFrom(x)).SelectMany(x => new MethodInfo[] { x.GetMethod("Update", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), x.GetMethod("FixedUpdate", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) }).Where(x => x != null).ToArray(); return(methods != null && methods.Length > 0 ? methods : null); }
internal static void BuildConfigMenus(RectTransform parent) { UMFConfigMenu umfConfigMenu = new UMFConfigMenu(); if (umfConfigMenu != null) { RectTransform menuParent = new GameObject("uModFramework", typeof(RectTransform)).GetComponent <RectTransform>(); menuParent.gameObject.SetActive(false); menuParent.SetParent(parent); menuParent.anchorMin = new Vector2(0f, 0f); menuParent.anchorMax = new Vector2(1f, 1f); menuParent.offsetMin = Vector2.zero; menuParent.offsetMax = Vector2.zero; umfConfigMenu.Build(menuParent); UMFConfigMenu = Tuple.Create <IGadgetConfigMenu, RectTransform>(umfConfigMenu, menuParent); } ConfigMenus = new List <Tuple <IGadgetConfigMenu, RectTransform> >(); 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(); for (int i = 0; i < allMods.Length; i++) { try { if (i < gadgetMods.Length) { IGadgetConfigMenu configMenu = gadgetMods[i].Mod.GetConfigMenu(); if (configMenu != null) { RectTransform menuParent = new GameObject(allMods[i], typeof(RectTransform)).GetComponent <RectTransform>(); menuParent.gameObject.SetActive(false); menuParent.SetParent(parent); menuParent.anchorMin = new Vector2(0f, 0f); menuParent.anchorMax = new Vector2(1f, 1f); menuParent.offsetMin = Vector2.zero; menuParent.offsetMax = Vector2.zero; configMenu.Build(menuParent); ConfigMenus.Add(Tuple.Create(configMenu, menuParent)); } else { ConfigMenus.Add(null); } } else { try { IGadgetConfigMenu configMenu = new UMFGadgetConfigMenu(allMods[i], false, Path.Combine(UMFData.ConfigsPath, allMods[i]) + ".ini"); if (configMenu != null) { RectTransform menuParent = new GameObject(allMods[i], typeof(RectTransform)).GetComponent <RectTransform>(); menuParent.gameObject.SetActive(false); menuParent.SetParent(parent); menuParent.anchorMin = new Vector2(0f, 0f); menuParent.anchorMax = new Vector2(1f, 1f); menuParent.offsetMin = Vector2.zero; menuParent.offsetMax = Vector2.zero; configMenu.Build(menuParent); ConfigMenus.Add(Tuple.Create(configMenu, menuParent)); } else { ConfigMenus.Add(null); } } catch (InvalidOperationException e) { if (e.Message == UMFGadgetConfigMenu.NO_CONFIGURABLE_DATA) { ConfigMenus.Add(null); } else { throw; } } } } catch { ConfigMenus.Add(null); throw; } } }
public static bool Prefix(GameScript __instance) { if (!GadgetNetwork.MatrixReady && GadgetNetwork.GetTimeSinceConnect() < GadgetNetwork.MatrixTimeout) { if (InstanceTracker.GameScript.gameObject.GetComponent <RPCHooks>() == null) { InstanceTracker.GameScript.gameObject.AddComponent <RPCHooks>(); } __instance.StartCoroutine(WaitAndTryAgain(__instance)); return(false); } else { if (GadgetNetwork.GetTimeSinceConnect() > GadgetNetwork.MatrixTimeout && GadgetMods.ListAllModInfos().Any(x => x.Attribute.RequiredOnClients)) { Network.Disconnect(); return(false); } return(true); } }
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(); }
internal static void Initialize() { if (Initialized) { return; } Initialized = true; try { CoreLogger = new GadgetLogger("GadgetCore", "Core"); CoreLogger.Log("GadgetCore v" + GadgetCoreAPI.FULL_VERSION + " Initializing!"); Debug.Log("GadgetCore v" + GadgetCoreAPI.FULL_VERSION); } catch (Exception e) { Debug.Log(e); GadgetCoreAPI.Quit(); return; } try { if (File.Exists(Application.persistentDataPath + "/PlayerPrefs.txt") && VerifySaveFile()) { if (GadgetCoreConfig.MaxBackups > 0) { File.Copy(Application.persistentDataPath + "/PlayerPrefs.txt", Path.Combine(GadgetPaths.SaveBackupsPath, "Save Backup - " + DateTime.Now.ToString("yyyy-dd-M_HH-mm-ss") + ".txt")); FileInfo[] backups = new DirectoryInfo(GadgetPaths.SaveBackupsPath).GetFiles().OrderByDescending(x => x.LastWriteTime.Year <= 1601 ? x.CreationTime : x.LastWriteTime).ToArray(); if (backups.Length > GadgetCoreConfig.MaxBackups) { for (int i = GadgetCoreConfig.MaxBackups; i < backups.Length; i++) { backups[i].Delete(); } } } } else { GadgetCoreAPI.Quit(); return; } HarmonyInstance = new Harmony("GadgetCore.core"); Type[] types; try { types = Assembly.GetExecutingAssembly().GetTypes(); } catch (ReflectionTypeLoadException e) { types = e.Types.Where(t => t != null).ToArray(); } types.Do(delegate(Type type) { object[] attributes = type.GetCustomAttributes(true); if (!attributes.Any(x => x.GetType() == typeof(HarmonyGadgetAttribute))) { HarmonyInstance.CreateClassProcessor(type).Patch(); } }); new Thread(new ThreadStart(() => { Thread.CurrentThread.Name = "GadgetCore Unity Engine Log Cloner"; Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Lowest; Thread.CurrentThread.IsBackground = true; string logPath = Application.dataPath + "\\output_log.txt"; if (!File.Exists(logPath)) { logPath = Application.persistentDataPath + "\\output_log.txt"; } if (!File.Exists(logPath)) { logPath = "~/Library/Logs/Unity/Player.log"; } if (!File.Exists(logPath)) { logPath = "~/.config/unity3d/DefaultCompany/Roguelands/Player.log"; } if (!File.Exists(logPath)) { CoreLogger.LogWarning("Unable to find Unity log file!"); return; } string targetPath = Path.Combine(GadgetPaths.LogsPath, "Unity Output.log"); DateTime t = default; while (!Quitting) { if (File.Exists(logPath) && File.GetLastWriteTime(logPath) > t) { File.Copy(logPath, targetPath, true); t = DateTime.Now; } Thread.Sleep(100); } })).Start(); AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) => { string name = new AssemblyName(args.Name).Name; if (LoadedAssemblies.ContainsKey(name)) { return(LoadedAssemblies[name]); } foreach (string file in Directory.GetFiles(GadgetPaths.LibsPath)) { if (AssemblyName.GetAssemblyName(file).Name == name) { Assembly assembly = Assembly.LoadFrom(file); LoadedAssemblies[name] = assembly; return(assembly); } } return(null); }; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (object sender, ResolveEventArgs args) => { string name = new AssemblyName(args.Name).Name; if (LoadedAssemblies.ContainsKey("ReflectionOnly: " + name)) { return(LoadedAssemblies["ReflectionOnly: " + name]); } foreach (string file in Directory.GetFiles(GadgetPaths.LibsPath)) { if (AssemblyName.GetAssemblyName(file).Name == name) { Assembly assembly = Assembly.ReflectionOnlyLoadFrom(file); LoadedAssemblies["ReflectionOnly: " + name] = assembly; return(assembly); } } return(null); }; LoadMainMenu(); try { UMFAPI = new UMFAPI(); UMFAPI.GetModNames(); CoreLogger.Log("Enabling UMF API as UMF is installed."); } catch (Exception) { UMFAPI = null; CoreLogger.Log("Disabling UMF API as UMF is not installed."); } CoreLib = Activator.CreateInstance(Assembly.LoadFile(Path.Combine(Path.Combine(GadgetPaths.GadgetCorePath, "DependentLibs"), "GadgetCoreLib.dll")).GetTypes().First(x => typeof(IGadgetCoreLib).IsAssignableFrom(x))) as IGadgetCoreLib; CoreLib.ProvideLogger(CoreLogger); GadgetCoreConfig.Load(); CoreLogger.Log("Finished loading config."); RegisterKeys(); IniData coreManifest = new IniData(); coreManifest["Metadata"]["Name"] = "GadgetCore"; coreManifest["Metadata"]["Assembly"] = Path.Combine(GadgetPaths.ManagedPath, "GadgetCore.dll"); GadgetMod coreMod = new GadgetMod(GadgetPaths.GadgetCorePath, coreManifest, Assembly.GetExecutingAssembly()); GadgetMods.RegisterMod(coreMod); VanillaRegistration(); SceneManager.sceneLoaded += OnSceneLoaded; SceneInjector.InjectMainMenu(); GadgetLoader.LoadAllMods(); DontDestroyOnLoad(new GameObject("GadgetCore", typeof(GadgetCore))); CoreLogger.LogConsole("GadgetCore v" + GadgetCoreAPI.FULL_VERSION + " Initialized!"); #pragma warning disable CS0162 // Unreachable code detected if (GadgetCoreAPI.IS_BETA) { CoreLogger.LogWarning("You are currently running a beta version of GadgetCore! Be prepared for bugs!"); } #pragma warning restore CS0162 // Unreachable code detected } catch (Exception e) { CoreLogger.LogError("There was a fatal error loading GadgetCore: " + e); } }
private static void VerifyCompatible(NetworkPlayer pl) { if (!GadgetNetwork.MatrixReady && GadgetNetwork.GetTimeSinceConnect() > GadgetNetwork.MatrixTimeout && GadgetMods.ListAllModInfos().Any(x => x.Attribute.RequiredOnClients)) { Network.CloseConnection(pl, true); } }