Example #1
0
        private static void Main(string[] args)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            bool flag  = false;
            bool flag2 = false;

            foreach (string text in args)
            {
                if (text.Contains("="))
                {
                    dictionary = (from s in args
                                  select s.Split(new char[]
                    {
                        '='
                    }, 1)).ToDictionary((string[] s) => s[0], (string[] s) => s[1]);
                }
                else if (text.StartsWith("-"))
                {
                    if (text == "-i")
                    {
                        flag = true;
                    }
                    if (text == "-u")
                    {
                        flag2 = true;
                    }
                }
            }
            string dir = Path.Combine(Environment.CurrentDirectory, "../..");
            string currentDirectory = Environment.CurrentDirectory;

            if (dictionary.Keys.Contains("SubnauticaDirectory"))
            {
                dir = dictionary["SubnauticaDirectory"];
            }
            QModInjector qmodInjector = new QModInjector(dir, currentDirectory);
            bool         flag3        = qmodInjector.IsPatcherInjected();

            if (flag)
            {
                if (!flag3)
                {
                    Console.WriteLine("Installing QMods...");
                    qmodInjector.Inject();
                    return;
                }
                Console.WriteLine("Tried to Force Install, was already injected. Skipping installation.");
                return;
            }
            else
            {
                if (!flag2)
                {
                    if (!qmodInjector.IsPatcherInjected())
                    {
                        Console.WriteLine("No patch detected, type 'yes' to install: ");
                        string a = Console.ReadLine().Replace("'", "");
                        if (a == "yes" || a == "YES")
                        {
                            if (qmodInjector.Inject())
                            {
                                Console.WriteLine("QMods was installed!");
                            }
                            else
                            {
                                Console.WriteLine("Error installed QMods. Please contact us on Discord");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Patch already installed! Type 'yes' to remove: ");
                        string a2 = Console.ReadLine().Replace("'", "");
                        if (a2 == "yes" || a2 == "YES")
                        {
                            if (qmodInjector.Remove())
                            {
                                Console.WriteLine("QMods was removed!");
                            }
                            else
                            {
                                Console.WriteLine("Error removing QMods. Please contact us on Discord");
                            }
                        }
                    }
                    Console.WriteLine("Press any key to exit ...");
                    Console.ReadKey();
                    return;
                }
                if (flag3)
                {
                    Console.WriteLine("Uninstalling QMods...");
                    qmodInjector.Remove();
                    return;
                }
                Console.WriteLine("Tried to Force Uninstall, was not injected. Skipping uninstallation.");
                return;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            var  parsedArgs     = new Dictionary <string, string>();
            bool forceInstall   = false;
            bool forceUninstall = false;

            foreach (var arg in args)
            {
                if (arg.Contains("="))
                {
                    parsedArgs = args.Select(s => s.Split(new[] { '=' }, 1)).ToDictionary(s => s[0], s => s[1]);
                }
                else if (arg.StartsWith("-"))
                {
                    if (arg == "-i")
                    {
                        forceInstall = true;
                    }

                    if (arg == "-u")
                    {
                        forceUninstall = true;
                    }
                }
            }

            string config = @"QModManagerConfig.txt";
            string GraveyardKeeperDirectory = "";

            /* Check the config file for alternate installation location - make this nicer later*/
            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(config);
                string line = file.ReadLine();
                Console.WriteLine(line);
                GraveyardKeeperDirectory = line;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            if (GraveyardKeeperDirectory == "" || GraveyardKeeperDirectory == "default")
            {
                string steamPath = "";
                try
                {
                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Valve\\Steam"))
                    {
                        if (key != null)
                        {
                            Object o = key.GetValue("InstallPath");
                            if (o != null)
                            {
                                steamPath = o as String;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR accessing registry key for steam path: " + ex);
                }

                GraveyardKeeperDirectory = steamPath + @"\steamapps\common\Graveyard Keeper";
            }
            Logger.StartNewLog(GraveyardKeeperDirectory);
            Logger.WriteLog("\n" + DateTime.Now + "\n");

            string ManagedDirectory = Path.Combine(GraveyardKeeperDirectory, @"\Graveyard Keeper_Data\Managed");

            if (parsedArgs.Keys.Contains("GraveyardKeeperDirectory"))
            {
                GraveyardKeeperDirectory = parsedArgs["GraveyardKeeperDirectory"];
            }

            QModInjector injector = new QModInjector(GraveyardKeeperDirectory);

            bool isInjected = injector.IsPatcherInjected();

            if (forceInstall)
            {
                if (!isInjected)
                {
                    Console.WriteLine("Installing QMods...");
                    injector.Inject();
                }
                else
                {
                    Console.WriteLine("Tried to Force Install, was already injected. Skipping installation.");
                    return;
                }
            }
            else if (forceUninstall)
            {
                if (isInjected)
                {
                    Console.WriteLine("Uninstalling QMods...");
                    injector.Remove();
                }
                else
                {
                    Console.WriteLine("Tried to Force Uninstall, was not injected. Skipping uninstallation.");
                    return;
                }
            }
            else
            {
                if (!injector.IsPatcherInjected())
                {
                    Console.WriteLine("No patch detected, type 'yes' to install: ");
                    string consent = Console.ReadLine().Replace("'", "");
                    if (consent == "yes" || consent == "YES")
                    {
                        if (injector.Inject())
                        {
                            Console.WriteLine("QMods was installed!");
                        }
                        else
                        {
                            Console.WriteLine("Error installed QMods. Please contact us on Discord");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Patch already installed! Type 'yes' to remove: ");
                    string consent = Console.ReadLine().Replace("'", "");
                    if (consent == "yes" || consent == "YES")
                    {
                        if (injector.Remove())
                        {
                            Console.WriteLine("QMods was removed!");
                        }
                        else
                        {
                            Console.WriteLine("Error removing QMods. Please contact us on Discord");
                        }
                    }
                }

                Console.WriteLine("Press any key to exit ...");

                Console.ReadKey();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var  parsedArgs     = new Dictionary <string, string>();
            bool forceInstall   = false;
            bool forceUninstall = false;

            foreach (var arg in args)
            {
                if (arg.Contains("="))
                {
                    parsedArgs = args.Select(s => s.Split(new[] { '=' }, 1)).ToDictionary(s => s[0], s => s[1]);
                }
                else if (arg.StartsWith("-"))
                {
                    if (arg == "-i")
                    {
                        forceInstall = true;
                    }

                    if (arg == "-u")
                    {
                        forceUninstall = true;
                    }
                }
            }

            //string SubnauticaDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\Subnautica";
            string SubnauticaDirectory = Path.Combine(Environment.CurrentDirectory, @"..\..");
            string ManagedDirectory    = Environment.CurrentDirectory;

            if (parsedArgs.Keys.Contains("SubnauticaDirectory"))
            {
                SubnauticaDirectory = parsedArgs["SubnauticaDirectory"];
            }

            QModInjector injector = new QModInjector(SubnauticaDirectory, ManagedDirectory);

            bool isInjected = injector.IsPatcherInjected();

            if (forceInstall)
            {
                if (!isInjected)
                {
                    Console.WriteLine("Installing QMods...");
                    injector.Inject();
                }
                else
                {
                    Console.WriteLine("Tried to Force Install, was already injected. Skipping installation.");
                    return;
                }
            }
            else if (forceUninstall)
            {
                if (isInjected)
                {
                    Console.WriteLine("Uninstalling QMods...");
                    injector.Remove();
                }
                else
                {
                    Console.WriteLine("Tried to Force Uninstall, was not injected. Skipping uninstallation.");
                    return;
                }
            }
            else
            {
                if (!injector.IsPatcherInjected())
                {
                    Console.WriteLine("No patch detected, type 'yes' to install: ");
                    string consent = Console.ReadLine().Replace("'", "");
                    if (consent == "yes" || consent == "YES")
                    {
                        if (injector.Inject())
                        {
                            Console.WriteLine("QMods was installed!");
                        }
                        else
                        {
                            Console.WriteLine("Error installed QMods. Please contact us on Discord");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Patch already installed! Type 'yes' to remove: ");
                    string consent = Console.ReadLine().Replace("'", "");
                    if (consent == "yes" || consent == "YES")
                    {
                        if (injector.Remove())
                        {
                            Console.WriteLine("QMods was removed!");
                        }
                        else
                        {
                            Console.WriteLine("Error removing QMods. Please contact us on Discord");
                        }
                    }
                }

                Console.WriteLine("Press any key to exit ...");

                Console.ReadKey();
            }
        }