コード例 #1
0
        internal GameDetector()
        {
            bool isSubnautica = Directory.GetFiles(Environment.CurrentDirectory, "Subnautica.exe", SearchOption.TopDirectoryOnly).Length > 0 ||
                                Directory.GetDirectories(Environment.CurrentDirectory, "Subnautica.app", SearchOption.TopDirectoryOnly).Length > 0;
            bool isBelowZero = Directory.GetFiles(Environment.CurrentDirectory, "SubnauticaZero.exe", SearchOption.TopDirectoryOnly).Length > 0 ||
                               Directory.GetDirectories(Environment.CurrentDirectory, "SubnauticaZero.app", SearchOption.TopDirectoryOnly).Length > 0;

            if (isSubnautica && !isBelowZero)
            {
                Logger.Info("Detected game: Subnautica");
                CurrentlyRunningGame = QModGame.Subnautica;
            }
            else if (isBelowZero && !isSubnautica)
            {
                Logger.Info("Detected game: BelowZero");
                CurrentlyRunningGame = QModGame.BelowZero;
            }
            else if (isSubnautica && isBelowZero)
            {
                Logger.Fatal("A fatal error has occurred. Both Subnautica and Below Zero files detected!");
                throw new FatalPatchingException("Both Subnautica and Below Zero files detected!");
            }
            else
            {
                Logger.Fatal("A fatal error has occurred. No game executable was found!");
                throw new FatalPatchingException("No game executable was found!");
            }
        }
コード例 #2
0
ファイル: AudioFixer.cs プロジェクト: Z4t4r/QModManager
        internal static void ChangeDisableUnityAudio(string path, bool newValue, QModGame game)
        {
            if (game != QModGame.Subnautica && game != QModGame.BelowZero)
            {
                throw new ArgumentException("Neither Subnautica nor Below Zero detected!");
            }
            AssetsManager      am  = new AssetsManager();
            AssetsFileInstance afi = am.LoadAssetsFile(path, false);

            if (game == QModGame.Subnautica)
            {
                am.LoadClassDatabase("cldb.dat");
            }
            else
            {
                am.LoadClassDatabase("cldb2018.dat");
            }
            AssetFileInfoEx     audioInfo      = afi.table.getAssetInfo(4);
            AssetTypeInstance   audioAti       = am.GetATI(afi.file, audioInfo);
            AssetTypeValueField audioBaseField = audioAti.GetBaseField();

            audioBaseField.Get("m_DisableAudio").GetValue().Set(newValue);
            byte[] audioAsset;
            using (MemoryStream memStream = new MemoryStream())
                using (AssetsFileWriter writer = new AssetsFileWriter(memStream))
                {
                    writer.bigEndian = false;
                    audioBaseField.Write(writer);
                    audioAsset = memStream.ToArray();
                }
            List <AssetsReplacer> rep = new List <AssetsReplacer>()
            {
                new AssetsReplacerFromMemory(0, 4, 0x0B, 0xFFFF, audioAsset)
            };

            using (MemoryStream memStream = new MemoryStream())
                using (AssetsFileWriter writer = new AssetsFileWriter(memStream))
                {
                    afi.file.Write(writer, 0, rep.ToArray(), 0);
                    afi.stream.Close();
                    File.WriteAllBytes(path, memStream.ToArray());
                }
        }
コード例 #3
0
        internal GameDetector()
        {
            bool isSubnautica = Directory.GetFiles(Environment.CurrentDirectory, "Subnautica.exe", SearchOption.TopDirectoryOnly).Length > 0 ||
                                Directory.GetDirectories(Environment.CurrentDirectory, "Subnautica.app", SearchOption.TopDirectoryOnly).Length > 0;
            bool isBelowZero = Directory.GetFiles(Environment.CurrentDirectory, "SubnauticaZero.exe", SearchOption.TopDirectoryOnly).Length > 0 ||
                               Directory.GetDirectories(Environment.CurrentDirectory, "SubnauticaZero.app", SearchOption.TopDirectoryOnly).Length > 0;

            if (isSubnautica && !isBelowZero)
            {
                Logger.Info("Detected game: Subnautica");
                CurrentlyRunningGame = QModGame.Subnautica;
            }
            else if (isBelowZero && !isSubnautica)
            {
                Logger.Info("Detected game: BelowZero");
                CurrentlyRunningGame = QModGame.BelowZero;
            }
            else if (isSubnautica && isBelowZero)
            {
                Logger.Fatal("A fatal error has occurred. Both Subnautica and Below Zero files detected!");
                throw new FatalPatchingException("Both Subnautica and Below Zero files detected!");
            }
            else
            {
                Logger.Fatal("A fatal error has occurred. No game executable was found!");
                throw new FatalPatchingException("No game executable was found!");
            }

            Logger.Info($"Game Version: {SNUtils.GetPlasticChangeSetOfBuild()} Build Date: {SNUtils.GetDateTimeOfBuild():dd-MMMM-yyyy}");
            Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}{(IsValidGameRunning && MinimumBuildVersion != 0 ? $" built for {CurrentlyRunningGame} v{MinimumBuildVersion}" : string.Empty)}...");
            Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");

            CurrentGameVersion = SNUtils.GetPlasticChangeSetOfBuild(-1);
            if (!IsValidGameVersion)
            {
                Logger.Fatal("A fatal error has occurred. An invalid game version was detected!");
                throw new FatalPatchingException("An invalid game version was detected!");
            }
        }
コード例 #4
0
 internal Initializer(QModGame currentlyRunningGame)
 {
     currentGame = currentlyRunningGame;
 }
コード例 #5
0
        private static void GetInfo(out OS os, out string directory, out QModGame game)
        {
            string windowsDirectory = Path.Combine(Environment.CurrentDirectory, "../..");
            string macDirectory     = Path.Combine(Environment.CurrentDirectory, "../../../../..");

            bool subnautica = false, belowzero = false;

            // Check if the device is running Windows OS
            bool onWindows = false, onWindowsSN = false, onWindowsBZ = false;

            if (Directory.Exists(windowsDirectory))
            {
                try
                {
                    // Try to get the Subnautica executable
                    // This method throws a lot of exceptions
                    onWindowsSN = Directory.GetFiles(windowsDirectory, "Subnautica.exe", SearchOption.TopDirectoryOnly).Length > 0;
                    onWindowsBZ = Directory.GetFiles(windowsDirectory, "SubnauticaZero.exe", SearchOption.TopDirectoryOnly).Length > 0;

                    onWindows = onWindowsSN || onWindowsBZ;

                    subnautica = subnautica || onWindowsSN;
                    belowzero  = belowzero || onWindowsBZ;
                }
                catch (Exception)
                {
                    // If an exception was thrown, the file probably isn't there
                    onWindows = false;
                }
            }

            // Check if the device is running Mac OS
            bool onMac = false, onMacSN = false, onMacBZ = false;

            if (Directory.Exists(macDirectory))
            {
                try
                {
                    // Try to get the Subnautica executable
                    // This method throws a lot of exceptions
                    // On mac, .app files act as files and folders at the same time, but they are detected as folders.
                    onMacSN = Directory.GetDirectories(macDirectory, "Subnautica.app", SearchOption.TopDirectoryOnly).Length > 0;
                    onMacBZ = Directory.GetDirectories(macDirectory, "SubnauticaZero.app", SearchOption.TopDirectoryOnly).Length > 0;

                    onMac = onMacSN || onMacBZ;

                    subnautica = subnautica || onMacSN;
                    belowzero  = belowzero || onMacBZ;
                }
                catch (Exception)
                {
                    // If an exception was thrown, the file probably isn't there
                    onMac = false;
                }
            }

            os        = OS.None;
            directory = null;
            if (onWindows)
            {
                os       |= OS.Windows;
                directory = windowsDirectory;
            }
            if (onMac)
            {
                os       |= OS.Mac;
                directory = windowsDirectory;
            }

            game = QModGame.None;
            if (subnautica)
            {
                game |= QModGame.Subnautica;
            }
            if (belowzero)
            {
                game |= QModGame.BelowZero;
            }
        }