Ejemplo n.º 1
0
        public static Task <BeatMods> CreateSession(bool useCachedOldMods = true)
        {
            return(Task.Run(async() =>
            {
                // Delete old files...
                if (File.Exists("cachedMods.json"))
                {
                    File.Delete("cachedMods.json");
                }
                if (File.Exists("cachedModsUnapproved.json"))
                {
                    File.Delete("cachedModsUnapproved.json");
                }

                BeatMods session = new BeatMods();
                await session.RefreshMods(useCachedOldMods);
                return session;
            }));
        }
Ejemplo n.º 2
0
        public BeatSaberInstallation(string beatSaberDirectory, BeatMods beatModsConnection)
        {
            BeatSaberDirectory = beatSaberDirectory;
            beatMods           = beatModsConnection;

            if (!Directory.Exists(beatSaberDirectory))
            {
                throw new FileNotFoundException("The given Beat Saber root directory does not exist.");
            }

            BeatSaberDotExe    = Path.Combine(beatSaberDirectory, "Beat Saber.exe");
            BeatSaberPluginDir = Path.Combine(beatSaberDirectory, "Plugins");
            ConfigFileName     = Path.Combine(beatSaberDirectory, "beatModderConfig.json");

            // Detecting Beat Saber version.
            // Current Beat Saber version is located in 'globalgamemanagers' file at byte offset 0x00001200
            try
            {
                string versionFile = Path.Combine(BeatSaberDirectory, "Beat Saber_Data", "globalgamemanagers");

                using (FileStream streamReader = new FileStream(versionFile, FileMode.Open))
                {
                    streamReader.Position = 0x1200;
                    byte[] asciiByteVersion = new byte[12];
                    streamReader.Read(asciiByteVersion, 0, asciiByteVersion.Length);
                    BeatSaberVersionString = Encoding.ASCII.GetString(asciiByteVersion).Trim('\0');
                    //BeatSaberVersion = SemVersion.Parse(BeatSaberVersionString.FixOddVersion());
                }
            }
            catch (Exception e)
            {
                throw new FileLoadException("Could not grab Beat Saber's version, is the game running?", e);
            }

            if (!File.Exists(BeatSaberDotExe))
            {
                throw new FileNotFoundException("'Beat Saber.exe' was not found in the given root directory.");
            }

            if (!File.Exists(ConfigFileName))
            {
                config = new Config
                {
                    ogFiles       = new List <string>(OriginalBeatSaberFiles.Select((e) => Path.Combine(BeatSaberDirectory, e))),
                    beatSaberType = BeatSaberDirectory.ToLower().Contains("steam") ? BeatSaberInstalledType.Steam : BeatSaberInstalledType.Oculus,
                    installedMods = new List <InstalledMod>()
                };
            }
            else
            {
                try
                {
                    config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(ConfigFileName));
                }
                catch (JsonException e1)
                {
                    throw new Exception("Could not parse config file, was it modified?", e1);
                }
                catch (IOException e2)
                {
                    throw new Exception("Could not read config file.", e2);
                }
            }

            //DidBeatSaberUpdate = BeatSaberVersion > (config.lastBeatSaberVersion?.FixOddVersion() ?? "0.0");
            PreviousBeatSaberVersionString = config.lastBeatSaberVersion;
            DidBeatSaberUpdate             = config.lastBeatSaberVersion != BeatSaberVersionString;
            config.lastBeatSaberVersion    = BeatSaberVersionString;

            FixPluginBinaries();
            SaveConfig();
        }