Exemplo n.º 1
0
 private void SetChapterType()
 {
     if (_inputFilePath.IndexOf("Map") > -1)
     {
         _type = Enums.SaveFileType.Map;
     }
     else
     {
         _type = Enums.SaveFileType.Chapter;
     }
 }
Exemplo n.º 2
0
 /// <remarks>Maybe replace this with smarter detection in the future</remarks>
 private void SetNonChapterType()
 {
     if (_filePath.IndexOf("Exchange") > -1)
     {
         _type = Enums.SaveFileType.Exchange;
     }
     else if (_filePath.IndexOf("Global") > -1)
     {
         _type = Enums.SaveFileType.Global;
     }
     else if (_filePath.IndexOf("Rating") > -1)
     {
         _type = Enums.SaveFileType.Rating;
     }
     else
     {
         _type = Enums.SaveFileType.Unknown;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Read data into this object from the file at _inputFilePath
        /// </summary>
        public virtual void Read()
        {
            byte[] chunk;
            int    length = GetFileLength();

            using (var fs = new FileStream(_inputFilePath, FileMode.Open, FileAccess.Read))
                using (var br = new BinaryReader(fs))
                {
                    // Read the first four bytes
                    chunk = new byte[4];
                    br.Read(chunk, 0, 4);

                    if (Enumerable.SequenceEqual(chunk, _compMarker))
                    {
                        _isCompressed = true;
                        SetNonChapterType();

                        br.BaseStream.Seek(0x10, SeekOrigin.Begin);
                        byte[] compressedBytes = new byte[length - 0x10];
                        br.Read(compressedBytes, 0, length - 0x10);
                        _decompressedBytes = Decompress(compressedBytes);

                        return;
                    }
                    else if (Enumerable.SequenceEqual(chunk, _indeMarker))
                    {
                        _isCompressed = false;
                        SetNonChapterType();

                        br.BaseStream.Seek(0, SeekOrigin.Begin);
                        _decompressedBytes = new byte[length];
                        br.Read(_decompressedBytes, 0, length);

                        return;
                    }

                    br.ReadBytes(0xBC); // Chapter header size (0xC0) minus the four bytes we already read

                    chunk = new byte[4];
                    br.Read(chunk, 0, 4);

                    if (Enumerable.SequenceEqual(chunk, _compMarker))
                    {
                        _isCompressed = true;
                        _type         = Enums.SaveFileType.Chapter;

                        br.BaseStream.Seek(0, SeekOrigin.Begin);
                        byte[] header = new byte[0xC0];
                        br.Read(header, 0, 0xC0);

                        br.BaseStream.Seek(0xD0, SeekOrigin.Begin);
                        byte[] compressedBytes = new byte[length - 0xD0];
                        br.Read(compressedBytes, 0, length - 0xD0);

                        byte[] decompressedBytes = Decompress(compressedBytes);

                        _decompressedBytes = header.Concat(decompressedBytes).ToArray();

                        return;
                    }
                    else if (Enumerable.SequenceEqual(chunk, _indeMarker))
                    {
                        _isCompressed = false;
                        _type         = Enums.SaveFileType.Chapter;

                        br.BaseStream.Seek(0, SeekOrigin.Begin);
                        _decompressedBytes = new byte[length];
                        br.Read(_decompressedBytes, 0, length);

                        return;
                    }

                    throw new FileLoadException("File is not a valid Fire Emblem Fates save file");
                }
        }