Esempio n. 1
0
        internal static void ChangeDisableUnityAudio(string path, bool newValue, Patcher.Game game)
        {
            if (game != Patcher.Game.Subnautica && game != Patcher.Game.BelowZero)
            {
                throw new ArgumentException("Neither Subnautica nor Below Zero detected!");
            }
            AssetsManager      am  = new AssetsManager();
            AssetsFileInstance afi = am.LoadAssetsFile(path, false);

            if (game == Patcher.Game.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());
                }
        }
Esempio n. 2
0
        internal static void GetInfo(out OS os, out string directory, out Patcher.Game 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 = Patcher.Game.None;
            if (subnautica)
            {
                game |= Patcher.Game.Subnautica;
            }
            if (belowzero)
            {
                game |= Patcher.Game.BelowZero;
            }
        }