Пример #1
0
        public void Deserialize(Stream input)
        {
            input.Position = 0;

            var magic = input.ReadValueU32(endian);

            if (magic != _signature)
            {
                throw new FormatException("Bad magic");
            }

            var version = input.ReadValueS32(endian);

            if (version != 13)
            {
                throw new FormatException("Unsupported version");
            }

            var flags = input.ReadValueU32(endian);

            this.version  = version;
            this.target   = flags & 0xFF;
            this.platform = (flags >> 8) & 0xFF;
            this.unk70    = (byte)((flags >> 16) & 0xFF);
            this.unk5     = input.ReadValueU64(endian);
            this.unk6     = input.ReadValueU32(endian);

            uint entryCount = input.ReadValueU32(endian);

            FatEntry fatEntry = new FatEntry();

            for (uint i = 0; i < entryCount; i++)
            {
                FatEntry entry;

                fatEntry.Deserialize(input, endian, out entry);
                this.entries.Add(entry);

                //Console.WriteLine(entry.ToString());

                //Console.WriteLine($"Read DAT entry {i}: {entry.nameHash:X16}");
            }

            /*
             * Console.WriteLine(string.Format("flags: {0}\nunk1: {1}\nunk2: {2}\nunk3: {3}\nunk4: {4}\nentryCount: {5}\nentries: {6}",
             *  flags,
             *  unk1,
             *  unk2,
             *  unk3,
             *  unk4,
             *  entryCount,
             *  entries.Count));
             */

            //Utility.Log.ToConsole($"Deserialized FAT with {entryCount} entries");
        }
Пример #2
0
        public void Serialize(Stream output)
        {
            output.Position = 0;

            var version = 13;

            //var unk1 = this.unk1;
            //var unk2 = this.unk2;
            //var unk3 = this.unk3;
            //var unk4 = this.unk4;
            var unk5 = this.unk5;
            var unk6 = this.unk6;

            output.WriteValueU32(_signature, endian);
            output.WriteValueS32(version, endian);

            uint flags = 0;

            flags |= (uint)((byte)target & 0xFF) << 0;
            flags |= (uint)((byte)platform & 0xFF) << 8;
            flags |= (uint)(unk70 & 0xFF) << 16;

            output.WriteValueU32(flags, endian);
            output.WriteValueU64(unk5, endian);
            output.WriteValueU32(unk6, endian);

            int entryCount = this.entries.Count;

            output.WriteValueS32(entryCount, endian);

            FatEntry fatEntry = new FatEntry();

            for (int i = 0; i < this.entries.Count; i++)
            {
                FatEntry entry = this.entries[i];
                fatEntry.Serialize(output, entry, endian);

                //Console.WriteLine($"Write DAT entry {i}: {entry.nameHash:X16}");
            }

            output.WriteValueU64(0, endian);

            //Utility.Log.ToConsole($"Serialized FAT with {entryCount} entries");
        }
Пример #3
0
        public void Serialize(Stream output, FatEntry entry, Endian endian)
        {
            ulong hash = entry.nameHash;

            ulong compressedSizeAndOffset = 0;

            compressedSizeAndOffset |= (entry.compressedSize & 0x1FFFFFFFu) << 0;
            compressedSizeAndOffset |= entry.offset << 30;

            uint compressionMethodAndUncompressedSize = 0;

            compressionMethodAndUncompressedSize |= entry.compressionScheme & 3;
            compressionMethodAndUncompressedSize |= (uint)entry.uncompressedSize << 2;

            output.WriteValueU64(hash, endian);
            output.WriteValueU64(compressedSizeAndOffset, endian);
            output.WriteValueU32(compressionMethodAndUncompressedSize, endian);

            /*
             * Console.WriteLine(string.Format("Serializing {0:X16}:", entry.nameHash));
             * Console.WriteLine(string.Format("\tcompressedSize:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  Convert.ToString(entry.compressedSize),
             *  Convert.ToString((long)entry.compressedSize, toBase: 2),
             *  Convert.ToString((long)compressedSizeAndOffset, toBase: 2),
             *  compressedSizeAndOffset));
             * Console.WriteLine(string.Format("\toffset:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  Convert.ToString(entry.offset),
             *  Convert.ToString((long)entry.offset, toBase: 2),
             *  Convert.ToString((long)compressedSizeAndOffset, toBase: 2),
             *  compressedSizeAndOffset));
             * Console.WriteLine(string.Format("\tcompressionScheme:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  Convert.ToString(entry.compressionScheme),
             *  Convert.ToString(entry.compressionScheme, toBase: 2),
             *  Convert.ToString(compressionMethodAndUncompressedSize, toBase: 2),
             *  compressionMethodAndUncompressedSize));
             * Console.WriteLine(string.Format("\tuncompressedSize:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  Convert.ToString(entry.uncompressedSize),
             *  Convert.ToString((long)entry.uncompressedSize, toBase: 2),
             *  Convert.ToString(compressionMethodAndUncompressedSize, toBase: 2),
             *  compressionMethodAndUncompressedSize));
             */
        }
Пример #4
0
        public void Deserialize(Stream input, Endian endian, out FatEntry entry)
        {
            var hash = input.ReadValueU64(endian);
            var compressedSizeAndOffset = input.ReadValueU64(endian);
            var compressionMethodAndUncompressedSize = input.ReadValueU32(endian);

            entry.nameHash          = hash;
            entry.uncompressedSize  = compressionMethodAndUncompressedSize >> 2;
            entry.compressionScheme = compressionMethodAndUncompressedSize & 3;
            entry.offset            = compressedSizeAndOffset >> 30;
            entry.compressedSize    = compressedSizeAndOffset & 0x3fffffff;

            /*
             * Console.WriteLine(string.Format("Deserializing {0:X16}:", entry.nameHash));
             * Console.WriteLine(string.Format("\tcompressedSize:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  compressedSizeAndOffset,
             *  Convert.ToString((long) compressedSizeAndOffset, toBase: 2),
             *  Convert.ToString((long) entry.compressedSize, toBase: 2),
             *  Convert.ToString(entry.compressedSize)));
             * Console.WriteLine(string.Format("\toffset:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  compressedSizeAndOffset,
             *  Convert.ToString((long) compressedSizeAndOffset, toBase: 2),
             *  Convert.ToString((long) entry.offset, toBase: 2),
             *  Convert.ToString(entry.offset)));
             * Console.WriteLine(string.Format("\tcompressionScheme:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  compressionMethodAndUncompressedSize,
             *  Convert.ToString(compressionMethodAndUncompressedSize, toBase: 2),
             *  Convert.ToString(entry.compressionScheme, toBase: 2),
             *  Convert.ToString(entry.compressionScheme)));
             * Console.WriteLine(string.Format("\tuncompressedSize:\n\t\ta = {0}\n\t\tb = {1}\n\t\tc = {2}\n\t\td = {3}",
             *  compressionMethodAndUncompressedSize,
             *  Convert.ToString(compressionMethodAndUncompressedSize, toBase: 2),
             *  Convert.ToString((long) entry.uncompressedSize, toBase: 2),
             *  Convert.ToString(entry.uncompressedSize)));
             */
        }