示例#1
0
        public static Savegame Load(ISavegameSerializer savegameSerializer, SavegameInputFiles savegameFiles, IFileContainer partyTextsContainer)
        {
            var savegame = new Savegame();

            savegameSerializer.Read(savegame, savegameFiles, partyTextsContainer);

            return(savegame);
        }
示例#2
0
        public void Save(IGameData gameData, ISavegameSerializer savegameSerializer, int saveSlot, string name, Savegame savegame)
        {
            var savegameFiles = savegameSerializer.Write(savegame);

            WriteSavegameName(gameData, saveSlot, ref name);
            SaveToGameData(gameData, savegameFiles, saveSlot);
            SaveToPath(path, savegameFiles, saveSlot, gameData.Files["Saves"]);
        }
示例#3
0
        public Savegame LoadInitial(IGameData gameData, ISavegameSerializer savegameSerializer)
        {
            var savegame = new Savegame();
            SavegameInputFiles savegameFiles;
            IFileContainer     partyTextContainer;

            try
            {
                savegameFiles = new SavegameInputFiles
                {
                    SaveDataReader         = gameData.Files["Initial/Party_data.sav"].Files[1],
                    PartyMemberDataReaders = gameData.Files["Initial/Party_char.amb"],
                    ChestDataReaders       = gameData.Files["Initial/Chest_data.amb"],
                    MerchantDataReaders    = gameData.Files["Initial/Merchant_data.amb"],
                    AutomapDataReaders     = gameData.Files["Initial/Automap.amb"]
                };
            }
            catch
            {
                try
                {
                    savegameFiles = new SavegameInputFiles
                    {
                        SaveDataReader         = gameData.Files["Save.00/Party_data.sav"].Files[1],
                        PartyMemberDataReaders = gameData.Files["Save.00/Party_char.amb"],
                        ChestDataReaders       = gameData.Files["Save.00/Chest_data.amb"],
                        MerchantDataReaders    = gameData.Files["Save.00/Merchant_data.amb"],
                        AutomapDataReaders     = gameData.Files["Save.00/Automap.amb"]
                    };
                }
                catch
                {
                    savegameFiles = new SavegameInputFiles
                    {
                        SaveDataReader         = gameData.Files["Party_data.sav"].Files[1],
                        PartyMemberDataReaders = gameData.Files["Party_char.amb"],
                        ChestDataReaders       = gameData.Files["Chest_data.amb"],
                        MerchantDataReaders    = gameData.Files["Merchant_data.amb"],
                        AutomapDataReaders     = gameData.Files["Automap.amb"]
                    };
                }
            }

            partyTextContainer = gameData.Files["Party_texts.amb"];
            savegameSerializer.Read(savegame, savegameFiles, partyTextContainer);
            return(savegame);
        }
示例#4
0
        public Savegame Load(IGameData gameData, ISavegameSerializer savegameSerializer, int saveSlot)
        {
            if (!transferredFolderSaves && File.Exists(savesPath))
            {
                transferredFolderSaves = true;
                var folderSaveData = new GameData(GameData.LoadPreference.ForceExtracted, null, false);

                try
                {
                    folderSaveData.Load(path, true);

                    KeyValuePair <string, IFileContainer>?TransferFile(string name)
                    {
                        if (folderSaveData.Files.ContainsKey(name))
                        {
                            return(KeyValuePair.Create(name, folderSaveData.Files[name]));
                        }
                        return(null);
                    }

                    for (int i = 1; i <= 10; ++i)
                    {
                        var saveFiles = new List <KeyValuePair <string, IFileContainer> >(5);
                        foreach (var saveFileName in SaveFileNames)
                        {
                            var file = TransferFile($"Save.{i:00}/{saveFileName}");
                            if (file == null)
                            {
                                break;
                            }
                            saveFiles.Add(file.Value);
                        }
                        if (saveFiles.Count == 5)
                        {
                            foreach (var saveFile in saveFiles)
                            {
                                gameData.Files[saveFile.Key] = saveFile.Value;
                            }
                        }
                    }

                    var saves = TransferFile("Saves");

                    if (saves != null)
                    {
                        gameData.Files[saves.Value.Key] = saves.Value.Value;
                    }
                }
                catch
                {
                    // ignore
                }
            }

            var savegame = new Savegame();
            SavegameInputFiles savegameFiles;

            try
            {
                savegameFiles = new SavegameInputFiles
                {
                    SaveDataReader         = gameData.Files[$"Save.{saveSlot:00}/Party_data.sav"].Files[1],
                    PartyMemberDataReaders = gameData.Files[$"Save.{saveSlot:00}/Party_char.amb"],
                    ChestDataReaders       = gameData.Files[$"Save.{saveSlot:00}/Chest_data.amb"],
                    MerchantDataReaders    = gameData.Files[$"Save.{saveSlot:00}/Merchant_data.amb"],
                    AutomapDataReaders     = gameData.Files[$"Save.{saveSlot:00}/Automap.amb"]
                };
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }

            var initialPartyMemberReaders = gameData.Files.TryGetValue("Initial/Party_char.amb", out var readers)
                ? readers : gameData.Files.TryGetValue("Save.00/Party_char.amb", out readers) ? readers : null;

            savegameSerializer.Read(savegame, savegameFiles, gameData.Files["Party_texts.amb"], initialPartyMemberReaders);

            return(savegame);
        }