示例#1
0
        internal static void Check()
        {
            if (PlayerPrefs.GetInt("QModManager_EnableUpdateCheck", 1) == 0)
            {
                Logger.Info("Update check disabled");
                return;
            }

            if (!NetworkUtilities.CheckConnection())
            {
                Logger.Warn("Cannot check for updates, internet disabled");
                return;
            }

            ServicePointManager.ServerCertificateValidationCallback = NetworkUtilities.CustomSCVC;

            using (WebClient client = new WebClient())
            {
                client.DownloadStringCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        Logger.Error("There was an error retrieving the latest version from GitHub!");
                        Logger.Exception(e.Error);
                        return;
                    }
                    Parse(e.Result);
                };

                Logger.Debug("Getting the latest version...");
                client.DownloadStringAsync(new Uri(VersionURL));
            }
        }
示例#2
0
        //// <summary>
        //// The <see cref="MessageReceiver"/>s and <see cref="GlobalMessageReceiver"/>s defined in this mod
        //// </summary>
        //[JsonIgnore] public Dictionary<IQMod, List<MethodInfo>> MessageReceivers { get; set; }

        internal static QMod FromJsonFile(string file)
        {
            try
            {
                JsonSerializerSettings settings = new JsonSerializerSettings
                {
                    MissingMemberHandling = MissingMemberHandling.Ignore,
                };

                string json = File.ReadAllText(file);
                QMod   mod  = JsonConvert.DeserializeObject <QMod>(json);

                if (mod == null)
                {
                    return(null);
                }

                if (mod.Game == "BelowZero")
                {
                    mod.ParsedGame = Patcher.Game.BelowZero;
                }
                else if (mod.Game == "Both")
                {
                    mod.ParsedGame = Patcher.Game.Both;
                }
                else
                {
                    mod.ParsedGame = Patcher.Game.Subnautica;
                }

                try
                {
                    mod.ParsedVersion = new Version(mod.Version);
                }
                catch (Exception e)
                {
                    Logger.Error($"There was an error parsing version \"{mod.Version}\" for mod \"{mod.DisplayName}\"");
                    Logger.Exception(e);
                    mod.ParsedVersion = null;
                }

                return(mod);
            }
            catch (Exception e)
            {
                Logger.Error($"\"mod.json\" deserialization failed for file \"{file}\"!");
                Logger.Exception(e);

                return(null);
            }
        }
示例#3
0
        internal static bool LoadMod(QMod mod)
        {
            if (mod == null || mod.Loaded)
            {
                return(false);
            }

            try
            {
                string[] entryMethodSig = mod.EntryMethod.Split('.');
                string   entryType      = string.Join(".", entryMethodSig.Take(entryMethodSig.Length - 1).ToArray());
                string   entryMethod    = entryMethodSig[entryMethodSig.Length - 1];

                MethodInfo patchMethod = mod.LoadedAssembly.GetType(entryType).GetMethod(entryMethod);
                patchMethod.Invoke(mod.LoadedAssembly, new object[] { });
            }
            catch (ArgumentNullException e)
            {
                Logger.Error($"Could not parse entry method \"{mod.AssemblyName}\" for mod \"{mod.Id}\"");
                Logger.Exception(e);
                erroredMods.Add(mod);

                return(false);
            }
            catch (TargetInvocationException e)
            {
                Logger.Error($"Invoking the specified entry method \"{mod.EntryMethod}\" failed for mod \"{mod.Id}\"");
                Logger.Exception(e);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error($"An unexpected error occurred whilst trying to load mod \"{mod.Id}\"");
                Logger.Exception(e);
                return(false);
            }

            if (QModAPI.ErroredMods.Contains(mod?.LoadedAssembly))
            {
                Logger.Error($"Mod \"{mod.Id}\" could not be loaded.");
                QModAPI.ErroredMods.Remove(mod?.LoadedAssembly);
                return(false);
            }
            mod.Loaded = true;
            Logger.Info($"Loaded mod \"{mod.Id}\"");

            return(true);
        }
示例#4
0
 internal static void Parse(string versionStr)
 {
     try
     {
         Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
         if (versionStr == null)
         {
             Logger.Error("There was an error retrieving the latest version from GitHub!");
             return;
         }
         Version latestVersion = new Version(versionStr);
         if (latestVersion == null)
         {
             Logger.Error("There was an error retrieving the latest version from GitHub!");
             return;
         }
         if (latestVersion > currentVersion)
         {
             Logger.Info($"Newer version found: {latestVersion.ToStringParsed()} (current version: {currentVersion.ToStringParsed()}");
             if (Patcher.erroredMods.Count <= 0)
             {
                 Dialog.Show(
                     $"There is a newer version of QModManager available: {latestVersion.ToStringParsed()} (current version: {currentVersion.ToStringParsed()})",
                     Dialog.Button.download, Dialog.Button.close, true);
             }
         }
         else
         {
             Logger.Info($"Recieved latest version from GitHub. We are up to date!");
         }
     }
     catch (Exception e)
     {
         Logger.Error("There was an error retrieving the latest version from GitHub!");
         Logger.Exception(e);
         return;
     }
 }
示例#5
0
        internal static void Patch()
        {
            try
            {
                if (patched)
                {
                    Logger.Warn("Patch method was called multiple times!");
                    return;
                }
                patched = true;

                Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");

                if (QModBaseDir == null)
                {
                    Logger.Fatal("A fatal error has occurred.");
                    Logger.Fatal("There was an error with the QMods directory");
                    Logger.Fatal("Please make sure that you ran Subnautica from Steam/Epic/Discord, and not from the executable file!");
                    return;
                }

                try
                {
                    Logger.Info($"Folder structure:\n{IOUtilities.GetFolderStructureAsTree()}\n");
                }
                catch (Exception e)
                {
                    Logger.Error("There was an error while trying to display the folder structure.");
                    Logger.Exception(e);
                }

                QModHooks.Load();
#pragma warning disable CS0618 // Type or member is obsolete
                Hooks.Load();
#pragma warning restore CS0618 // Type or member is obsolete

                PirateCheck.IsPirate(Environment.CurrentDirectory);

                if (!DetectGame())
                {
                    return;
                }

                PatchHarmony();

                if (NitroxCheck.IsInstalled)
                {
                    Logger.Fatal($"Nitrox was detected!");
                    Dialog.Show("Both QModManager and Nitrox detected. QModManager is not compatible with Nitrox. Please uninstall one of them.", Dialog.Button.disabled, Dialog.Button.disabled, false);
                    return;
                }

                StartLoadingMods();
                ShowErroredMods();

                VersionCheck.Check();

                QModHooks.Start += PrefabDebugger.Main;

                QModHooks.OnLoadEnd?.Invoke();
#pragma warning disable CS0618 // Type or member is obsolete
                Hooks.OnLoadEnd?.Invoke();
#pragma warning restore CS0618 // Type or member is obsolete

                Logger.Info($"Finished loading QModManager. Loaded {loadedMods.Count} mods");
            }
            catch (Exception e)
            {
                Logger.Error("EXCEPTION CAUGHT!");
                Logger.Exception(e);
            }
        }