Пример #1
0
        private void BackupSave(GameSaveDir gsd, BackupOptions opt)
        {
            if (null != opt.BackupDir)
            {
                try
                {
                    string backupPath;
                    bool   backupCreated;
                    gsd.Backup(opt.BackupDir, out backupPath, out backupCreated);

                    if (backupCreated)
                    {
                        LogVerbose("Backed up save game files to: {0}", backupPath);
                    }
                    else
                    {
                        LogVerbose("Backup file already exists: {0}", backupPath);
                    }
                }
                catch (Exception x)
                {
                    throw new Exception(string.Format("Error backing up save game files: {0}", x.Message), x);
                }
            }
        }
Пример #2
0
        private bool RunModify(ModifyOptions opt)
        {
            try
            {
                DoCommon(opt);

                GameSaveDir gsd;
                try
                {
                    gsd = new GameSaveDir(opt.SaveDir);
                }
                catch (Exception x)
                {
                    LogError("Error locating game save file:\n{0}", x.Message);
                    return(false);
                }

                dynamic json;
                try
                {
                    json = ReadLatestSaveFile(gsd, opt.GameMode);
                }
                catch (Exception x)
                {
                    Console.WriteLine("Error loading or parsing save file: {0}", x.Message);
                    return(false);
                }

                // Now iterate through JSON, maxing out technology, Substance, and Product values in Inventory, ShipInventory, and FreighterInventory

                ModifyExosuitSlots(opt, json);
                ModifyMultitoolSlots(opt, json);
                ModifyShipSlots(opt, json);
                ModifyFreighterSlots(opt, json);
                ModifyShipSeed(opt, json);
                ModifyMultitoolSeed(opt, json);
                ModifyFreighterSeed(opt, json);

                BackupSave(gsd, opt);

                try
                {
                    WriteLatestSaveFile(gsd, opt.GameMode, json, opt.UseOldFormat);
                }
                catch (Exception x)
                {
                    throw new Exception(string.Format("Error storing save file: {0}", x.Message), x);
                }
            }
            catch (Exception x)
            {
                LogError(x.Message);
                return(false);
            }

            return(true);
        }
Пример #3
0
        public bool RunEncrypt(EncryptOptions opt)
        {
            DoCommon(opt);

            GameSaveDir gsd;

            try
            {
                gsd = new GameSaveDir(opt.SaveDir);
            }
            catch (Exception x)
            {
                LogError("Error locating game save file:\n{0}", x.Message);
                return(false);
            }

            LogVerbose("Reading JSON save game data from: {0}", opt.InputPath);
            string unformattedJson;

            try
            {
                unformattedJson = File.ReadAllText(opt.InputPath);
            }
            catch (IOException x)
            {
                LogError("Error reading JSON save game file: {0}", x.Message);
                return(false);
            }

            LogVerbose("Validating (parsing) JSON save game data");
            object json;

            try
            {
                json = JsonConvert.DeserializeObject(unformattedJson);
            }
            catch (Exception x)
            {
                LogError("Error parsing save game file: {0}", x.Message);
                return(false);
            }

            BackupSave(gsd, opt);

            try
            {
                WriteLatestSaveFile(gsd, opt.GameMode, json, opt.UseOldFormat);
            }
            catch (Exception x)
            {
                LogError("Error storing save file: {0}", x.Message);
                return(false);
            }

            return(true);
        }
Пример #4
0
        public bool RunDecrypt(DecryptOptions opt)
        {
            DoCommon(opt);

            GameSaveDir gsd;

            try
            {
                gsd = new GameSaveDir(opt.SaveDir);
            }
            catch (Exception x)
            {
                LogError("Error locating game save file:\n{0}", x.Message);
                return(false);
            }

            object json;

            try
            {
                json = ReadLatestSaveFile(gsd, opt.GameMode);
            }
            catch (Exception x)
            {
                LogError("Error loading or parsing save file: {0}", x.Message);
                return(false);
            }

            LogVerbose("Parsing and formatting save game JSON");
            string formattedJson;

            try
            {
                formattedJson = JsonConvert.SerializeObject(json, Formatting.Indented);
            }
            catch (Exception x)
            {
                LogError("Error formatting JSON (invalid save?): {0}", x.Message);
                return(false);
            }

            LogVerbose("Writing formatted JSON to:\n   {0}", opt.OutputPath);
            try
            {
                File.WriteAllText(opt.OutputPath, formattedJson);
            }
            catch (Exception x)
            {
                LogError("Error writing decrypted JSON: {0}", x.Message);
                return(false);
            }

            return(true);
        }
Пример #5
0
        // TODO: Move all save file handling into a separate class
        private object ReadLatestSaveFile(GameSaveDir gsd, GameModes gameMode)
        {
            string metadataPath;
            string storagePath;
            uint   archiveNumber;
            ulong? profileKey;

            gsd.FindLatestGameSaveFiles(gameMode, out metadataPath, out storagePath, out archiveNumber, out profileKey);

            LogVerbose("Reading latest {0}-mode save game file from:\n   {1}", gameMode, storagePath);

            string jsonStr = Storage.Read(metadataPath, storagePath, archiveNumber, profileKey);

            return(JsonConvert.DeserializeObject(jsonStr));
        }
Пример #6
0
        private void WriteLatestSaveFile(GameSaveDir gsd, GameModes gameMode, object json, bool useOldFormat)
        {
            string formattedJson = JsonConvert.SerializeObject(json, Formatting.None);

            string metadataPath;
            string storagePath;
            uint   archiveNumber;
            ulong? profileKey;

            gsd.FindLatestGameSaveFiles(gameMode, out metadataPath, out storagePath, out archiveNumber, out profileKey);

            LogVerbose("Writing latest {0}-mode save game file to:\n   {1}", gameMode, storagePath);
            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(formattedJson)))
            {
                Storage.Write(metadataPath, storagePath, ms, archiveNumber, profileKey, useOldFormat);
                var now = DateTime.Now;
                File.SetLastWriteTime(metadataPath, now);
                File.SetLastWriteTime(storagePath, now);
            }
        }