Exemplo n.º 1
0
        public static TpfFileEntry Read(BinaryReader reader)
        {
            TpfFileEntry result     = new TpfFileEntry();
            int          dataOffset = reader.ReadInt32();
            int          dataSize   = reader.ReadInt32();

            //   0 = ?
            //   1 = ?
            //   5 = ?
            //   6 = ?
            //   9 = ?
            //  10 = ?
            // 100 = ?
            // 102 = ?
            // 103 = ?
            // 104 = ?
            // 105 = ?
            // 106 = ?
            // 107 = ?
            // 108 = ?
            // 109 = ?
            // 113 = ?
            result.Format      = reader.ReadByte();
            result.Type        = reader.ReadByte(); // 0 = texture, 1 = cubemap
            result.MipMapCount = reader.ReadByte();
            result.Flags       = reader.ReadByte(); // 00

            int fileNameOffset = reader.ReadInt32();

            result.Unknown = reader.ReadInt32(); // 0 = ?, 1 = ?

            long position = reader.GetPosition();

            if (fileNameOffset > 0)
            {
                reader.Seek(fileNameOffset);
                result.FileName  = reader.ReadNullTerminatedString();
                result.FileName += ".dds";
            }

            if (dataOffset > 0)
            {
                reader.Seek(dataOffset);
                result.Data = reader.ReadBytes(dataSize);
            }

            reader.Seek(position);

            return(result);
        }
Exemplo n.º 2
0
        private void Read(Stream inputStream)
        {
            BinaryReader reader     = new BinaryReader(inputStream, Encoding.ASCII, true);
            string       signature  = reader.ReadString(4);
            int          sizeSum    = reader.ReadInt32();
            int          entryCount = reader.ReadInt32();

            byte versionFlag = reader.ReadByte(); // 00 DS / 02 DeS / 04 BB
            byte flag2       = reader.ReadByte(); // 03
            byte encoding    = reader.ReadByte();
            byte flag3       = reader.ReadByte(); // 00

            switch (encoding)
            {
            case 1:     // Unicode
                reader = new BinaryReader(inputStream, Encoding.Unicode, true);
                break;

            case 2:     // ASCII
                break;

            default:
                reader = new BinaryReader(inputStream, Encoding.Unicode, true);
                Debug.WriteLine($"Unknown encoding {encoding}");
                break;
            }

            //  TODO: Verify that versionFlag is actually different between DS and BB
            GameVersion gameVersion = versionFlag == 0x04
                ? GameVersion.Bloodborne
                : GameVersion.Common;

            List <TpfFileEntry> entries = new List <TpfFileEntry>(entryCount);

            for (int i = 0; i < entryCount; i++)
            {
                entries.Add(TpfFileEntry.Read(reader, gameVersion));
            }

            Entries = entries;
        }
Exemplo n.º 3
0
        private void Read(Stream inputStream)
        {
            BinaryReader reader     = new BinaryReader(inputStream, Encoding.ASCII, true);
            string       signature  = reader.ReadString(4);
            int          sizeSum    = reader.ReadInt32();
            int          entryCount = reader.ReadInt32();

            byte flag1    = reader.ReadByte(); // 00
            byte flag2    = reader.ReadByte(); // 03
            byte encoding = reader.ReadByte();
            byte flag3    = reader.ReadByte(); // 00

            switch (encoding)
            {
            case 1:     // Unicode
                reader = new BinaryReader(inputStream, Encoding.Unicode, true);
                break;

            case 2:     // ASCII
                break;

            default:
                reader = new BinaryReader(inputStream, Encoding.Unicode, true);
                Debug.WriteLine($"Unknown encoding {encoding}");
                break;
            }

            List <TpfFileEntry> entries = new List <TpfFileEntry>(entryCount);

            for (int i = 0; i < entryCount; i++)
            {
                entries.Add(TpfFileEntry.Read(reader));
            }

            Entries = entries;
        }
Exemplo n.º 4
0
        public static TpfFileEntry Read(BinaryReader reader, GameVersion gameVersion)
        {
            TpfFileEntry result = new TpfFileEntry();

            result.GameVersion = gameVersion;
            int dataOffset = reader.ReadInt32();
            int dataSize   = reader.ReadInt32();

            //   0 = ?
            //   1 = ?
            //   5 = ?
            //   6 = ?
            //   9 = ?
            //  10 = ?
            // 100 = ?
            // 102 = ?
            // 103 = ?
            // 104 = ?
            // 105 = ?
            // 106 = ?
            // 107 = ?
            // 108 = ?
            // 109 = ?
            // 113 = ?
            result.Format = reader.ReadByte();
            result.Type   = reader.ReadByte(); // 0 = texture, 1 = cubemap

            result.MipMapCount = reader.ReadByte();
            result.Flags       = reader.ReadByte();

            int fileNameOffset;

            if (gameVersion == GameVersion.Bloodborne)
            {
                result.Width  = reader.ReadInt16();
                result.Height = reader.ReadInt16();
                int unknown1 = reader.ReadInt32(); // 1
                int unknown2 = reader.ReadInt32(); // 13
                fileNameOffset = reader.ReadInt32();
                int unknown3 = reader.ReadInt32(); // 0
                result.DxgiFormat = reader.ReadInt32();
            }
            else
            {
                fileNameOffset = reader.ReadInt32();
                result.Unknown = reader.ReadInt32(); // 0 = ?, 1 = ?
            }

            long position = reader.GetPosition();

            if (fileNameOffset > 0)
            {
                reader.Seek(fileNameOffset);
                result.FileName  = reader.ReadNullTerminatedString();
                result.FileName += ".dds";
            }

            if (dataOffset > 0)
            {
                reader.Seek(dataOffset);
                result.Data = reader.ReadBytes(dataSize);
            }

            reader.Seek(position);

            return(result);
        }