Пример #1
0
 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());
     }
 }
Пример #2
0
        internal static void InjectMainMenu()
        {
            GadgetCore.Log("Injecting Mod Menu into Main Menu");

            GameObject mainMenu = InstanceTracker.Menuu.menuMain;

            Array.ForEach(mainMenu.GetComponentsInChildren <Animation>(), x => x.enabled = true);
            ModMenuBeam      = UnityEngine.Object.Instantiate(mainMenu.transform.Find("beamm").gameObject, mainMenu.transform);
            ModMenuBeam.name = "beamm";
            ModMenuBeam.transform.localScale = new Vector3(30, 0, 1);
            ModMenuBeam.transform.position   = new Vector3(0, -13.5f, 1);
            ModMenuButtonHolder      = UnityEngine.Object.Instantiate(mainMenu.transform.Find("BUTTONHOLDER").gameObject, mainMenu.transform);
            ModMenuButtonHolder.name = "BUTTONHOLDER";
            ModMenuButtonHolder.transform.position = new Vector3(0, -13.5f, 0);
            ModMenuButtonHolder.GetComponent <Animation>().RemoveClip("enterr1");
            ModMenuButtonHolder.GetComponent <Animation>().AddClip(BuildModMenuButtonAnimClip(false), "enterr1");
            ModMenuButtonHolder.GetComponent <Animation>().clip = ModMenuButtonHolder.GetComponent <Animation>().GetClip("enterr1");
            GameObject bModMenu = ModMenuButtonHolder.transform.GetChild(0).gameObject;

            bModMenu.name = "bModMenu";
            Array.ForEach(bModMenu.GetComponentsInChildren <TextMesh>(), x => x.text = GadgetCore.IsUnpacked ? "MOD MENU" : File.Exists(Path.Combine(UMFData.ModsPath, "GadgetCore.dll")) ? "UPDATE GADGET CORE" : "UNPACK GADGET CORE");
            ModMenuBeam.GetComponent <Animation>().Play();
            ModMenuButtonHolder.GetComponent <Animation>().Play();
            if (GadgetCore.IsUnpacked)
            {
                BuildModMenu();
            }
        }
Пример #3
0
 internal void ReceiveIDMatrixData(string IDMatrixData)
 {
     if (!Network.isServer)
     {
         GadgetCore.Log("Received Host ID Conversion Matrix data.");
         GadgetNetwork.connectTime = Time.realtimeSinceStartup;
     }
     GadgetNetwork.ParseIDMatrixData(IDMatrixData);
 }
Пример #4
0
 internal void Start()
 {
     if (Singleton != null && Singleton != this)
     {
         Destroy(Singleton);
     }
     Singleton = this;
     view      = GetComponent <NetworkView>();
     if (Network.isServer)
     {
         GadgetCore.Log("Listening for client connections...");
         IdentifyNewClients();
     }
 }
Пример #5
0
        //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());
            }
        }
Пример #6
0
 internal static void LoadRegistries()
 {
     try
     {
         foreach (Registry reg in GameRegistry.ListAllRegistries())
         {
             try
             {
                 reg.reservedIDs = PlayerPrefs.GetString("Reserved" + reg.GetRegistryName() + "IDs", "").Split(',').Select(x => x.Split('=')).ToDictionary(x => x[0], x => int.Parse(x[1]));
             }
             catch (IndexOutOfRangeException)
             {
                 reg.reservedIDs = new Dictionary <string, int>();
             }
         }
     }
     catch (Exception e)
     {
         GadgetCore.Log("Error loading registry settings: " + e.ToString());
     }
 }
Пример #7
0
 internal static void Update()
 {
     try
     {
         PlayerPrefs.SetString("EnabledMods", enabledMods.Select(x => x.Key + ":" + x.Value).Aggregate(new StringBuilder(), (a, b) => { if (a.Length > 0)
                                                                                                                                        {
                                                                                                                                            a.Append(",");
                                                                                                                                        }
                                                                                                                                        a.Append(b); return(a); }).ToString());
         foreach (Registry reg in GameRegistry.ListAllRegistries())
         {
             PlayerPrefs.SetString("Reserved" + reg.GetRegistryName() + "IDs", reg.reservedIDs.Select(x => x.Key + "=" + x.Value).Aggregate(new StringBuilder(), (a, b) => { if (a.Length > 0)
                                                                                                                                                                             {
                                                                                                                                                                                 a.Append(",");
                                                                                                                                                                             }
                                                                                                                                                                             a.Append(b); return(a); }).ToString());
         }
         PlayerPrefs.Flush();
     }
     catch (Exception e)
     {
         GadgetCore.Log("Error updating mod settings: " + e.Message + "(" + e.InnerException?.Message + ")");
     }
 }
Пример #8
0
 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();
         }
     }
 }
Пример #9
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());
     }
 }