Exemplo n.º 1
0
        public static SaveGameData LoadPlayers(SaveGameFile savegame)
        {
            SaveGameData saveData = new SaveGameData();

            Dictionary <int, Club_Comp> clubcomps = DataFileLoaders.GetDataFileClubCompetitionDictionary(savegame);

            Dictionary <int, string> firstnames = GetDataFileStringsDictionary(savegame, DataFileType.First_Names);

            Dictionary <int, string> secondNames = GetDataFileStringsDictionary(savegame, DataFileType.Second_Names);

            Dictionary <int, string> commonNames = GetDataFileStringsDictionary(savegame, DataFileType.Common_Names);

            Dictionary <int, Nation> nations = DataFileLoaders.GetDataFileNationDictionary(savegame);

            Dictionary <int, Club> clubs = DataFileLoaders.GetDataFileClubDictionary(savegame);

            List <Staff>            duplicates = new List <Staff>();
            Dictionary <int, Staff> staffDic   = DataFileLoaders.GetDataFileStaffDictionary(savegame, saveData, out duplicates);

            List <PlayerData> players = GetDataFilePlayerData(savegame);

            List <Player> searchablePlayers = ConstructSearchablePlayers(staffDic, players).ToList();

            saveData.GameDate    = savegame.GameDate;
            saveData.FirstNames  = firstnames;
            saveData.Surnames    = secondNames;
            saveData.CommonNames = commonNames;
            saveData.Nations     = nations;
            saveData.Clubs       = clubs;
            saveData.Players     = searchablePlayers;
            saveData.ClubComps   = clubcomps;

            return(saveData);
        }
        public static List <SaveGameFile> GetSaveGameFiles(string rootPath)
        {
            List <SaveGameFile> saveGameFiles = new List <SaveGameFile>();

            DirectoryInfo directoryInfo = new DirectoryInfo(rootPath);

            FileInfo[] files = directoryInfo.GetFiles("*.sav");

            foreach (FileInfo file in files)
            {
                SaveGameFile saveGameFile = new SaveGameFile()
                {
                    RootPath    = rootPath,
                    LastChanged = file.LastWriteTime,
                    Name        = file.Name,
                    SizeInKb    = file.Length / 1024
                };

                saveGameFiles.Add(saveGameFile);
            }

            saveGameFiles = saveGameFiles.OrderByDescending(x => x.LastChanged).ToList();

            return(saveGameFiles);
        }
Exemplo n.º 3
0
 public SaveGameReader(string saveFilePath)
 {
     _savegame     = new SaveGameFile(saveFilePath, SaveFileFormat.DUNE_37);
     _generals     = new Generals(_savegame.UncompressedData, new Dune37Offsets());
     _offsets      = new Dune37Offsets();
     _saveFilePath = saveFilePath;
 }
Exemplo n.º 4
0
        public static Dictionary <int, Staff> GetDataFileStaffDictionary(SaveGameFile savegame, SaveGameData gameData, out List <Staff> duplicateStaff)
        {
            Dictionary <int, Staff> dic = new Dictionary <int, Staff>();

            duplicateStaff = new List <Staff>();
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == DataFileType.Staff);
            var bytes     = GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);

            StaffConverter converter = new StaffConverter();

            foreach (var item in bytes)
            {
                var staff = converter.Convert(item);
                staff.Value = staff.Value * gameData.ValueMultiplier;
                staff.Wage  = staff.Wage * gameData.ValueMultiplier;

                if (staff.StaffPlayerId != -1)
                {
                    if (dic.ContainsKey(staff.StaffPlayerId))
                    {
                        duplicateStaff.Add(staff);
                    }
                    else
                    {
                        dic.Add(staff.StaffPlayerId, staff);
                    }
                }
            }

            return(dic);
        }
Exemplo n.º 5
0
        private string ReCompressUncompressedSavegameFile(string inputFilePath)
        {
            var savegame = new SaveGameFile(File.ReadAllBytes(inputFilePath).ToList(), Enums.SaveFileFormat.DUNE_37, false);

            savegame.SaveCompressedAs(_options.OutputSaveGameFile);
            return($"Compressed {_options.Compress} to {_options.OutputSaveGameFile}{Environment.NewLine}");
        }
Exemplo n.º 6
0
 private void EditSavegame(SaveGameFile savegame)
 {
     for (int i = 0; i < _options.Write.Count(); i++)
     {
         var edit = _options.Write.ElementAt(i);
         if (string.IsNullOrWhiteSpace(edit) || edit.Contains(',') == false)
         {
             throw new ArgumentException($"{nameof(_options.Write)} invalid date found: {edit}");
         }
         var  splittedEdit = edit.Split(",");
         var  pos          = 0;
         byte value        = 0;
         if (!byte.TryParse(splittedEdit[0], NumberStyles.HexNumber, CultureInfo.InstalledUICulture, out value))
         {
             throw new ArgumentException($"{nameof(_options.Write)} invalid date found: {edit} for value part");
         }
         if (!int.TryParse(splittedEdit[1], NumberStyles.HexNumber, CultureInfo.InstalledUICulture, out pos))
         {
             throw new ArgumentException($"{nameof(_options.Write)} invalid date found: {edit} for position part");
         }
         savegame.ModifyByteInUncompressedData(value, pos);
         Console.WriteLine($"Written byte 0x{value:X2} at position 0x{pos:X2}");
     }
     savegame.SaveCompressedAs(_options.OutputSaveGameFile);
     Console.WriteLine($"Modified and compressed savegame written at {_options.OutputSaveGameFile}");
 }
Exemplo n.º 7
0
        private static void ReadFileHeaders(StreamReader sr, SaveGameFile savegame)
        {
            using (var br = new BinaryReader(sr.BaseStream))
            {
                if (br.ReadInt32() == 4)
                {
                    savegame.IsCompressed = true;
                }

                sr.BaseStream.Seek(4, SeekOrigin.Current);

                var blockCount = br.ReadInt32();
                for (int j = 0; j < blockCount; j++)
                {
                    byte[] fileHeader = new byte[ByteBlockSize];
                    br.Read(fileHeader, 0, ByteBlockSize);
                    var internalName = ByteHandler.GetStringFromBytes(fileHeader, 8);

                    savegame.DataBlockNameList.Add(new DataFile()
                    {
                        InternalName = internalName,
                        FileType     = DataFileFacts.GetDataFileFact(internalName).Type,
                        Position     = ByteHandler.GetIntFromBytes(fileHeader, 0),
                        Length       = ByteHandler.GetIntFromBytes(fileHeader, 4)
                    });
                }
            }
        }
Exemplo n.º 8
0
        private static List <T> GetDataFileConverted <T>(SaveGameFile savegame, DataFileType type)
        {
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == type);
            var bytes     = DataFileLoaders.GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);
            var converter = ConverterFactory.CreateConverter <T>();
            var collect   = ConvertToCMObject <T>(bytes, converter).ToList();

            return(collect);
        }
Exemplo n.º 9
0
    public void CanLoadVanillaPatch2SaveGame()
    {
        var savePath = TestData.GetPath("SaveGames/TestData/slot0014");

        using var tempDir = new TempDirectory();

        var saveFile = SaveGameFile.Load(savePath, tempDir.Path);

        Console.WriteLine();
    }
Exemplo n.º 10
0
        private static void LoadGameData(SaveGameFile savegame)
        {
            var general   = savegame.DataBlockNameList.First(x => x.FileType == DataFileType.General);
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == DataFileType.General);

            ByteHandler.GetAllDataFromFile(general, savegame.FileName, fileFacts.DataSize);

            var fileData = ByteHandler.GetAllDataFromFile(general, savegame.FileName, fileFacts.DataSize);

            savegame.GameDate = ByteHandler.GetDateFromBytes(fileData[0], fileFacts.DataSize - 8).Value;
        }
Exemplo n.º 11
0
        private static Dictionary <int, string> GetDataFileStringsDictionary(SaveGameFile savegame, DataFileType type)
        {
            Dictionary <int, string> fileContents = new Dictionary <int, string>();
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == type);
            var fileData  = DataFileLoaders.GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);

            for (int i = 0; i < fileData.Count; i++)
            {
                fileContents.Add(i, ByteHandler.GetStringFromBytes(fileData[i], 0, fileFacts.StringLength));
            }

            return(fileContents);
        }
Exemplo n.º 12
0
        private static List <PlayerData> GetDataFilePlayerData(SaveGameFile savegame)
        {
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == DataFileType.Players);
            var bytes     = DataFileLoaders.GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);
            var converter = new PlayerDataConverter();
            var collect   = new List <PlayerData>();

            foreach (var source in bytes)
            {
                collect.Add(converter.Convert(source));
            }

            return(collect);
        }
Exemplo n.º 13
0
        public void CanEditArbitraryLocation()
        {
            var save   = Path.Combine(SavesFolder, MidGamesSaveFileName);
            var output = Path.GetTempFileName();
            var writer = new SaveGameEditorCli(new Options {
                InputSaveGameFiles = new string[] { save }, Write = new string[] { "FF,CC", "11,01" }, OutputSaveGameFile = output
            });

            writer.GetStandardOutput();
            var bytes = new SaveGameFile(output, Enums.SaveFileFormat.DUNE_37).UncompressedData;

            bytes.Should().HaveElementAt(0xCC, 0xFF);
            bytes.Should().HaveElementAt(0x01, 0x11);
        }
Exemplo n.º 14
0
        public static SaveGameData OpenSaveGameIntoMemory(string fileName)
        {
            SaveGameFile savegame = new SaveGameFile();

            savegame.FileName = fileName;

            using (var sr = new StreamReader(fileName))
            {
                ReadFileHeaders(sr, savegame);
            }

            LoadGameData(savegame);

            return(PlayerLoader.LoadPlayers(savegame));
        }
Exemplo n.º 15
0
    // Create a .dat file named (saveName) and save game relevent information to it
    public void saveGame()
    {
        //set up data container
        SaveGameFile save = new SaveGameFile();

        //save stuff
        save.save_playerClass  = (int)playerClass;
        save.save_playerBullet = playerBullet = player.transform.GetComponent <Player>().bullet.name;
        save.save_difficulty   = (int)difficulty;
        save.save_spawnX       = spawnCoordinates.x;
        save.save_spawnY       = spawnCoordinates.y;

        //save abilities
        save.abilityNames = new string[3];
        Entity entscr = player.transform.GetComponent <Entity> ();

        for (int i = 0; i < 3; i++)
        {
            if (entscr.abilities [i + 2] == null)
            {
                save.abilityNames [i] = "";
            }
            else
            {
                save.abilityNames [i] = entscr.abilities [i + 2].GetType().AssemblyQualifiedName;
            }
        }

        //save learned abilites
        Ability[] temp = new Ability[player.transform.GetComponent <Player>().learnedAbilities.Count];
        player.transform.GetComponent <Player> ().learnedAbilities.CopyTo(temp);
        save.learnedAbilityNames = new string[temp.Length];
        for (int i = 0; i < temp.Length; i++)
        {
            save.learnedAbilityNames [i] = temp [i].GetType().AssemblyQualifiedName;
        }

        //save defeated bosses
        save.defeatedBosses = completedBosses;

        //serialize and save
        FileStream      file = File.Open(Application.persistentDataPath + "\\" + saveName + ".dat", FileMode.Create);
        BinaryFormatter bf   = new BinaryFormatter();

        bf.Serialize(file, save);
        file.Close();
    }
Exemplo n.º 16
0
        private void LoadFile()
        {
            textBoxLog.AppendText("Updating selected file..." + Environment.NewLine);
            _selectedSaveGame = (SaveGameFile)coBxSaveGames.SelectedItem;
            textBoxLog.AppendText("Loaded file: " + _selectedSaveGame.FullName + Environment.NewLine);


            textBoxLog.AppendText("Reading file..." + Environment.NewLine);
            string fileContent = File.ReadAllText(_selectedSaveGame.FullName);

            textBoxLog.AppendText("Deserializing..." + Environment.NewLine);
            _loadedSaveGame = FileManager.DeSerializeFromXml <SaveGameCore>(fileContent).FillAllCollectors().HealAllCharacters().DoAllConstructions();

            textBoxLog.AppendText("Computing data..." + Environment.NewLine);
            UpdateResourceDatagrid();
            UpdateCharacterDatagrid();
            textBoxLog.AppendText("Done." + Environment.NewLine);
        }
Exemplo n.º 17
0
    public void OnAfterLoad(string saveDirectory, SaveGameFile saveFile)
    {
        var co8State = saveFile.Co8State;

        if (co8State != null)
        {
            Co8PersistentData.Flags              = new Dictionary <string, bool>(co8State.Flags);
            Co8PersistentData.Vars               = new Dictionary <string, int>(co8State.Vars);
            Co8PersistentData.StringVars         = new Dictionary <string, string>(co8State.StringVars);
            Co8PersistentData.ActiveSpellTargets = co8State.ActiveSpellTargets.ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.ToHashSet()
                );
        }
        else
        {
            Co8PersistentData.Reset();
        }
    }
Exemplo n.º 18
0
    public void OnAfterSave(string saveDirectory, SaveGameFile saveFile)
    {
        if (Co8PersistentData.Flags.Count == 0 &&
            Co8PersistentData.Vars.Count == 0 &&
            Co8PersistentData.StringVars.Count == 0 &&
            Co8PersistentData.ActiveSpellTargets.Count == 0)
        {
            return;
        }

        saveFile.Co8State = new SavedCo8State
        {
            Flags              = new Dictionary <string, bool>(Co8PersistentData.Flags),
            Vars               = new Dictionary <string, int>(Co8PersistentData.Vars),
            StringVars         = new Dictionary <string, string>(Co8PersistentData.StringVars),
            ActiveSpellTargets = Co8PersistentData.ActiveSpellTargets.ToDictionary(
                kvp => kvp.Key,
                kvp => kvp.Value.ToArray()
                )
        };
    }
Exemplo n.º 19
0
    // Load (saveName).dat and begin a game with its data
    public void loadGame()
    {
        if (File.Exists(Application.persistentDataPath + "\\" + saveName + ".dat"))
        {
            //load and deserialize file
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "\\" + saveName + ".dat", FileMode.Open);
            SaveGameFile    save = (SaveGameFile)bf.Deserialize(file);

            //set GameManager values to match deserialized values
            playerClass        = (PlayerClass)save.save_playerClass;
            playerBullet       = save.save_playerBullet;
            difficulty         = (Difficulty)save.save_difficulty;
            spawnCoordinates.x = save.save_spawnX;
            spawnCoordinates.y = save.save_spawnY;

            //load abilities
            for (int i = 0; i < save.abilityNames.Length; i++)
            {
                if (save.abilityNames [i] == "")
                {
                    flexAbilities [i] = null;
                }
                else
                {
                    flexAbilities [i] = (Ability)Activator.CreateInstance(Type.GetType(save.abilityNames [i]));
                }
            }

            //load learned abilites
            for (int i = 0; i < save.learnedAbilityNames.Length; i++)
            {
                learnedAbilites.Add((Ability)Activator.CreateInstance(Type.GetType(save.learnedAbilityNames [i])));
            }

            //load defeated bosses
            completedBosses = save.defeatedBosses;
        }
    }
Exemplo n.º 20
0
        public string GetStandardOutput()
        {
            if (_options.Write.Any() && string.IsNullOrWhiteSpace(_options.Compress) == false)
            {
                return($"Editing a savegame and recompression of another at the same time is not supported.{Environment.NewLine}");
            }

            if (_options.Write.Any() && _options.InputSaveGameFiles.Any())
            {
                var inputFile = _options.InputSaveGameFiles.ElementAt(0);
                var savegame  = new SaveGameFile(inputFile, Enums.SaveFileFormat.DUNE_37);
                EditSavegame(savegame);
            }

            if (string.IsNullOrWhiteSpace(_options.Compress) == false && string.IsNullOrWhiteSpace(_options.OutputSaveGameFile) == false)
            {
                foreach (var inputFilePath in _options.InputSaveGameFiles)
                {
                    return(ReCompressUncompressedSavegameFile(inputFilePath));
                }
            }
            return("");
        }
Exemplo n.º 21
0
        public static Dictionary <int, Club> GetDataFileClubDictionary(SaveGameFile savegame)
        {
            Dictionary <int, Club> dic = new Dictionary <int, Club>();
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == DataFileType.Clubs);
            var bytes     = GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);

            ClubConverter converter = new ClubConverter();

            foreach (var item in bytes)
            {
                var club = converter.Convert(item);

                if (club.ClubId != -1)
                {
                    if (!dic.ContainsKey(club.ClubId))
                    {
                        dic.Add(club.ClubId, club);
                    }
                }
            }

            return(dic);
        }
Exemplo n.º 22
0
        public static Dictionary <int, Nation> GetDataFileNationDictionary(SaveGameFile savegame)
        {
            Dictionary <int, Nation> dic = new Dictionary <int, Nation>();
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == DataFileType.Nations);
            var bytes     = GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);

            NationConverter converter = new NationConverter();

            foreach (var item in bytes)
            {
                var nation = converter.Convert(item);

                if (nation.Id != -1)
                {
                    if (!dic.ContainsKey(nation.Id))
                    {
                        dic.Add(nation.Id, nation);
                    }
                }
            }

            return(dic);
        }
Exemplo n.º 23
0
    public static SaveGameFile Load(string basePath, string currentSaveDir)
    {
        var result = new SaveGameFile();

        var indexPath = basePath + ".tfai";

        var archiveIndex = ArchiveIndexReader.ReadIndex(indexPath);

        using var dataStream = new FileStream(basePath + ".tfaf", FileMode.Open);

        byte[] gameStateData   = null;
        byte[] spellPacketData = null;
        byte[] partyConfigData = null;
        byte[] mapFleeData     = null;
        byte[] uiStateData     = null;

        bool GrabData(ArchiveIndexEntry entry, string filename, ref byte[] bufferOut)
        {
            if (entry.Path == filename)
            {
                if (bufferOut != null)
                {
                    throw new CorruptSaveException($"File {filename} exists twice in the save game!");
                }

                var buffer = new byte[entry.Size];
                dataStream.Read(buffer);
                if (Debugger.IsAttached)
                {
                    var fullPath = Path.Join(currentSaveDir, entry.Path);
                    File.WriteAllBytes(fullPath, buffer);
                }

                bufferOut = buffer;
                return(true);
            }

            return(false);
        }

        foreach (var entry in archiveIndex)
        {
            var fullPath = Path.Join(currentSaveDir, entry.Path);

            if (entry.Directory)
            {
                Directory.CreateDirectory(fullPath);
                continue;
            }

            if (GrabData(entry, MainStateFile, ref gameStateData) ||
                GrabData(entry, ActionSequencesSpellsFile, ref spellPacketData) ||
                GrabData(entry, PartyConfigFile, ref partyConfigData) ||
                GrabData(entry, MapFleeFile, ref mapFleeData) ||
                GrabData(entry, UiStateFile, ref uiStateData))
            {
                continue;
            }

            CopyStreamToFile(dataStream, entry.Size, fullPath);
        }

        if (gameStateData == null)
        {
            throw new CorruptSaveException($"Save file is missing {MainStateFile}");
        }

        if (spellPacketData == null)
        {
            throw new CorruptSaveException($"Save file is missing {ActionSequencesSpellsFile}");
        }

        if (partyConfigData == null)
        {
            throw new CorruptSaveException($"Save file is missing {PartyConfigFile}");
        }

        if (mapFleeData == null)
        {
            throw new CorruptSaveException($"Save file is missing {MapFleeFile}");
        }

        if (uiStateData == null)
        {
            throw new CorruptSaveException($"Save file is missing {UiStateFile}");
        }

        result.GameState = SavedGameState.Load(gameStateData, spellPacketData, partyConfigData, mapFleeData);

        result.UiState = SavedUiState.Load(uiStateData);

        // Load the optional Co8 data if it exists
        var co8Path = basePath + ".co8";

        if (File.Exists(co8Path))
        {
            result.Co8State = SavedCo8State.Load(co8Path);
        }

        return(result);
    }
Exemplo n.º 24
0
 public void WriteUncompressedSaveGameInTheSameFolder() => SaveGameFile.SaveUnCompressedAs($"{_saveFilePath}.UNCOMPRESSED", _savegame.UncompressedData);
Exemplo n.º 25
0
        public static Dictionary <int, T> GetDataFileConvertedIdDictionary <T>(ITupleConverter <T> converter, SaveGameFile savegame, DataFileType type, out List <T> duplicates) where T : class
        {
            duplicates = new List <T>();
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == type);
            var bytes     = DataFileLoaders.GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);

            Dictionary <int, T> dic        = new Dictionary <int, T>();
            List <T>            invalidIds = new List <T>();

            foreach (var item in bytes)
            {
                var converted = converter.Convert(item);

                if (converted.Item1 == -1)
                {
                    invalidIds.Add(converted.Item2 as T);
                }
                else
                {
                    if (dic.ContainsKey(converted.Item1))
                    {
                        duplicates.Add(converted.Item2 as T);
                    }
                    else
                    {
                        dic.Add(converted.Item1, converted.Item2 as T);
                    }
                }
            }

            return(dic);
        }
Exemplo n.º 26
0
        private static Dictionary <int, T> GetDataFileConvertedIdDictionary <T>(SaveGameFile savegame, DataFileType type, out List <T> duplicates) where T : class
        {
            var converter = ConverterIdFactory.CreateTupleConverter <T>();

            return(GetDataFileConvertedIdDictionary(converter, savegame, type, out duplicates));
        }
Exemplo n.º 27
0
        public static Dictionary <int, Club_Comp> GetDataFileClubCompetitionDictionary(SaveGameFile savegame)
        {
            Dictionary <int, Club_Comp> dic = new Dictionary <int, Club_Comp>();
            var fileFacts = DataFileFacts.GetDataFileFacts().First(x => x.Type == DataFileType.Club_Comps);
            var bytes     = GetDataFileBytes(savegame, fileFacts.Type, fileFacts.DataSize);

            var converter = new ClubCompConverter();

            foreach (var item in bytes)
            {
                var comp = converter.Convert(item);
                dic.Add(comp.Id, comp);
            }

            return(dic);
        }
 public static SaveGameFile LoadSaveGame(SaveGameFile saveGameFile)
 {
     return(LoadSaveGame(saveGameFile.FullName));
 }
Exemplo n.º 29
0
        public static List <byte[]> GetDataFileBytes(SaveGameFile savegame, DataFileType fileType, int sizeOfData)
        {
            DataFile dataFile = savegame.DataBlockNameList.First(x => x.FileType == fileType);

            return(ByteHandler.GetAllDataFromFile(dataFile, savegame.FileName, sizeOfData));
        }