internal StringArchive(AssetManager manager, BinaryReader reader, string name, long length)
            : base(manager, name)
        {
            ByteOrder = ByteOrder.LittleEndian;

            Encoding = Encoding.Unicode;
            if (reader is BigEndianBinaryReader)
                Encoding = Encoding.BigEndianUnicode;

            using (reader) {
                reader.Require(Magic1);

                int totalFileLength = reader.ReadInt32();
                if (totalFileLength != length) {
                    if (totalFileLength.ReverseBytes() == length) {
                        ByteOrder = ByteOrder.BigEndian;
                        Encoding = Encoding.BigEndianUnicode;
                    } else
                        throw new InvalidDataException();
                }

                int magic2 = reader.ReadInt32();
                if (magic2 != Magic2 && magic2 != Magic2BE)
                    throw new InvalidDataException();

                int groupCount = reader.ReadInt32(ByteOrder);
                int stringCount = reader.ReadInt32(ByteOrder);
                int stringOffset = reader.ReadInt32(ByteOrder);
                reader.RequireZeroes(4 * 1);

                for (int index = 0; index < groupCount; index++)
                    groups.Add(new StringGroup(reader, ByteOrder));

                int[] stringOffsets = reader.ReadArrayInt32(stringCount, ByteOrder);

                for (int index = 0; index < stringCount; index++) {
                    int offset = stringOffsets[index];

                    if (offset == 0)
                        strings.Add(null);
                    else {
                        reader.BaseStream.Position = offset;
                        string value = reader.ReadStringz(Encoding);
                        strings.Add(value);
                    }
                }

                foreach (StringGroup group in groups) {
                    for (int index = 0; index < group.StringCount; index++) {
                        int stringIndex = group.StringsIndex + index;
                        string stringValue = strings[stringIndex];
                        int realIndex = group.IndexStart + index;

                        if (stringValue != null)
                            stringsById[realIndex] = stringValue;
                    }
                }
            }
        }
Example #2
0
        public FbxValue(BinaryReader reader)
            : this()
        {
            Type = (FbxValueType)reader.ReadByte();
            switch (Type) {
                case FbxValueType.Double:
                    ValueCombo.Double = reader.ReadDouble();
                    break;

                case FbxValueType.DoubleArray:
                    int doubleCount = reader.ReadInt32();
                    reader.RequireZeroes(4);
                    reader.Require(doubleCount * 8);
                    ValueObject = reader.ReadArrayDouble(doubleCount);
                    break;

                case FbxValueType.Int32:
                    ValueCombo.Int32 = reader.ReadInt32();
                    break;

                case FbxValueType.Int32Array:
                    int int32Count = reader.ReadInt32();
                    reader.RequireZeroes(4);
                    reader.Require(int32Count * 4);
                    ValueObject = reader.ReadArrayInt32(int32Count);
                    break;

                case FbxValueType.String:
                    int stringLength = reader.ReadInt32();
                    ValueObject = reader.ReadString(stringLength, Encoding.UTF8);
                    break;

                case FbxValueType.Data:
                    int dataLength = reader.ReadInt32();
                    ValueObject = reader.ReadBytes(dataLength);
                    break;

                default:
                    throw new NotImplementedException(string.Format("{0} {1:X2}h/'{2}' is not implemented.", typeof(FbxValueType).Name, (int)Type, (char)Type));
            }
        }
        internal TextureArchiveRecord(TextureArchive archive, BinaryReader reader, ByteOrder order)
            : base(archive, "")
        {
            Offset = reader.ReadInt32(order);
            Size = reader.ReadInt32(order);

            if (Archive.Platform == DSPlatform.PS3) {
                int format = reader.ReadInt16(order);
                Id = reader.ReadInt16(order);
                Ps3Dimensions = new Vector2i(reader.ReadUInt16(order), reader.ReadUInt16(order));

                switch (format) {
                    case 0: Ps3Format = Glare.Graphics.Formats.DXT1; break;
                    case 0x0500: Ps3Format = Glare.Graphics.Formats.DXT5; break;
                    case 0x0900: Ps3Format = Glare.Graphics.Formats.Vector4nb; break;
                    default: throw new NotSupportedException(string.Format("PS3 format 0x{0:X4} (dimensions {1}, data size {2}) is not known.", format, Ps3Dimensions, Size));
                }

                Unknowns.ReadInt32s(reader, 1);
                reader.RequireZeroes(4);
            } else {
                Id = reader.ReadInt32(order);
            }

            Name = reader.ReadStringzAtUInt32(order, Alexandria.Engines.DarkSouls.Archive.ShiftJis);
            reader.RequireZeroes(4);
        }
Example #4
0
        internal void ReadVertexHeaders(BinaryReader reader, int dataOffset, ArrayBackedList<byte> bufferData)
        {
            reader.RequireZeroes(4 * 1);
            VertexDeclarationIndex = reader.ReadInt32();
            VertexSize = reader.ReadInt32();
            VertexCount = reader.ReadInt32();
            reader.RequireZeroes(4 * 2);
            int vertexDataSize = reader.ReadInt32();
            if (VertexSize * VertexCount != vertexDataSize)
                throw new Exception();
            VertexDataOffset = reader.ReadInt32() + dataOffset;

            // Read vertex data.
            long reset = reader.BaseStream.Position;
            reader.BaseStream.Position = VertexDataOffset;
            BufferDataOffset = bufferData.Count;
            bufferData.AddRange(reader, vertexDataSize);
            reader.BaseStream.Position = reset;
        }
Example #5
0
        internal string ReadString(BinaryReader reader)
        {
            int size = ReadSizeT(reader);

            if (size == 0)
                return null;
            var value = reader.ReadString(size - 1, Encoding.GetEncoding("shift-jis"));
            reader.RequireZeroes(1);
            return value;
        }
Example #6
0
        internal ArchiveRecord(Archive archive, int index, BinaryReader reader, int recordHeaderSize)
            : base(archive, "")
        {
            archive.records.Add(this);
            Index = index;

            switch (archive.Variant) {
                case ArchiveVariant.V3:
                    reader.Require(0x40);
                    Size = reader.ReadInt32();
                    Offset = reader.ReadInt32();
                    Id = reader.ReadInt32();
                    Name = reader.ReadStringzAtUInt32(Archive.ShiftJis);
                    int size2 = reader.ReadInt32();
                    if (Size != size2)
                        throw new Exception();
                    fixedUncompressedSize = Size;
                    break;

                case ArchiveVariant.V4:
                    Compression = reader.ReadInt32(); // 2 or 3 - compression?
                    reader.ReadMatch(-1);
                    Size = reader.ReadInt64();
                    if (recordHeaderSize == 0x1C) {
                        Offset = reader.ReadInt64();
                        Name = reader.ReadStringzAtUInt32(Archive.ShiftJis);
                    } else {
                        fixedUncompressedSize = reader.ReadInt64();
                        Offset = reader.ReadUInt32();
                        Unknowns.ReadInt32s(reader, 1);
                        // 'Compression' = 2, Unknown = 0, Encoding = UTF8
                        Name = reader.ReadStringzAtUInt32(Archive.ShiftJis);
                    }
                    Id = DarkSouls.Archive.HashFilename(Name);
                    break;

                case ArchiveVariant.V5:
                    Id = reader.ReadInt32();
                    Size = reader.ReadInt32();
                    Offset = reader.ReadInt32();
                    reader.RequireZeroes(4); // NameOffset, but zero?

                    string foundName;
                    if (!Archive.KnownFiles.TryGetValue(Id, out foundName))
                        Name = string.Format("#{0:X}", Id);
                    else
                        Name = foundName;
                    break;

                default:
                    throw new NotImplementedException();
            }

            MoveIntoPath(Name);
        }