Example #1
0
        protected MemoryStream ReadSection(BinaryReader reader)
        {
            // read of section
            int length = reader.ReadInt32();
            byte[] buffer = new byte[length];

            // read the data
            reader.Read(buffer, 0, length);

            // align the position to a multiple of 16 bytes
            reader.AlignPosition(16);

            // return a new memorystream wrapping over the byte buffer
            return new MemoryStream(buffer);
        }
Example #2
0
        /// <summary>
        /// Initializer only to be called by <see cref="RWNodeFactory"/>.
        /// </summary>
        internal RWNode(RWNodeFactory.RWNodeInfo header, BinaryReader reader)
        {
            _type = header.Type;
            _size = header.Size;
            _rawVersion = header.Version;
            Parent = header.Parent;
            _data = reader.ReadBytes((int)_size);

            switch (_type)
            {
                case RWNodeType.RMDParticleList:
                    reader.AlignPosition(16);
                    break;
            }
        }
Example #3
0
        // Private Methods
        private void Read(BinaryReader reader)
        {
            offset = (int)reader.BaseStream.Position - HEADER_SIZE; 
            _unused = reader.ReadUInt32();
            _addressRelocTableOffset = reader.ReadInt32();
            _addressRelocTableSize = reader.ReadInt32();
            _unk1 = reader.ReadUInt32();
            _unk2 = reader.ReadUInt32();
            _nodeArrayOffset = reader.ReadUInt32();
            _materialArrayOffset = reader.ReadUInt32();
            _unk3 = reader.ReadUInt32();
            _nodeNameSectionOffset = reader.ReadUInt32();

            reader.BaseStream.Seek(offset + DATA_START_ADDRESS + _nodeArrayOffset, SeekOrigin.Begin);
            _numNodes = reader.ReadUInt32();
            reader.AlignPosition(16);
            long nodeArrayPos = reader.BaseStream.Position;

            reader.BaseStream.Seek(offset + DATA_START_ADDRESS + _materialArrayOffset, SeekOrigin.Begin);
            _numMaterials = reader.ReadUInt32();
            _materials = new MDMaterial[_numMaterials];
            for (int i = 0; i < _numMaterials; i++)
            {
                _materials[i] = new MDMaterial(reader);
            }

            if (_nodeNameSectionOffset != 0)
            {
                reader.BaseStream.Seek(offset + DATA_START_ADDRESS + _nodeNameSectionOffset, SeekOrigin.Begin);
                _nodeNameSection = new NDNM(_numNodes, reader);
            }

            _nodes = new MDNode[_numNodes];
            for (int i = 0; i < _numNodes; i++)
            {
                reader.BaseStream.Seek(nodeArrayPos + (i * MDNode.SIZE), SeekOrigin.Begin);
                _nodes[i] = new MDNode(this, reader);
            }

            for (int i = 0; i < _numNodes; i++)
            {
                _nodes[i].ReadMeshes(this, reader);
            }
        }
Example #4
0
        private void InternalRead(BinaryReader reader)
        {
            long posFileStart = reader.GetPosition();
            short flag = reader.ReadInt16();
            short userID = reader.ReadInt16();
            int length = reader.ReadInt32();
            string tag = reader.ReadCString(4);
            reader.AlignPosition(16);

            if (tag != TAG)
            {
                throw new InvalidDataException();
            }

            PaletteCount = reader.ReadByte();
            PaletteFormat = (PS2PixelFormat)reader.ReadByte();
            Width = reader.ReadUInt16();
            Height = reader.ReadUInt16();
            PixelFormat = (PS2PixelFormat)reader.ReadByte();
            MipMapCount = reader.ReadByte();
            _mipKL = reader.ReadUInt16();
            byte reserved = reader.ReadByte();
            _wrapModes = reader.ReadByte();
            UserTextureID = reader.ReadInt32();
            UserClutID = reader.ReadInt32();
            UserComment = reader.ReadCString(28);

            // Check if there's any palettes and read them
            if (UsesPalette)
            {
                ReadPalette(reader);
            }

            // Read the pixels for the image and mipmaps
            ReadPixels(reader);
        }
Example #5
0
        private void InternalRead(BinaryReader reader)
        {
            long posFileStart = reader.GetPosition();
            short flag = reader.ReadInt16();
            short userID = reader.ReadInt16();
            int length = reader.ReadInt32();
            string tag = reader.ReadCString(4);
            int unused = reader.ReadInt32();

            if (tag != TAG)
            {
                throw new InvalidDataException("Identifier mismatch.");
            }

            int numTypeTableEntries = reader.ReadInt32();
            int numUnknown = reader.ReadInt32();

            reader.AlignPosition(16);

            TypeTableEntry[] typeTable = new TypeTableEntry[numTypeTableEntries];
            for (int i = 0; i < numTypeTableEntries; i++)
            {
                typeTable[i] = new TypeTableEntry(reader);
            }

            System.Diagnostics.Debug.Assert(typeTable[(int)TypeTableType.Strings].elementCount == 0xF0);

            for (int i = 0; i < numTypeTableEntries; i++)
            {
                reader.Seek(posFileStart + typeTable[i].dataOffset, SeekOrigin.Begin);

                switch ((TypeTableType)typeTable[i].type)
                {
                    case TypeTableType.Procedures:
                        ReadCodeLabels(reader, ref _procedures, typeTable[i].elementCount, out _requireSortProcedures);
                        break;
                    case TypeTableType.JumpLabels:
                        ReadCodeLabels(reader, ref _jumpLabels, typeTable[i].elementCount, out _requireSortJumps);
                        break;
                    case TypeTableType.Opcodes:
                        {
                            bool hasExtendedOpcodes;
                            _opcodes = BFDisassembler.ParseCodeblock(reader.ReadUInt32Array(typeTable[i].elementCount), out hasExtendedOpcodes);

                            if (hasExtendedOpcodes) // only fix up the opcode indices if they have to be
                                FixupOpcodeIndices(); // this function is kinda 2*O(n^2)
                        }
                        break;
                    case TypeTableType.Messages:
                        if (typeTable[i].elementCount > 0)
                            _messageFile = new BMDFile(StreamHelper.ReadStream(reader, typeTable[i].elementCount), false);
                        break;
                    case TypeTableType.Strings:
                        // TODO: Implement this
                        break;
                }
            }
        }
Example #6
0
        private void InternalRead(BinaryReader reader)
        {
            long posFileStart = reader.GetPosition();
            short flag = reader.ReadInt16();
            short userID = reader.ReadInt16();
            int length = reader.ReadInt32();
            string tag = reader.ReadCString(4);
            reader.AlignPosition(16);

            if (tag != TAG)
            {
                throw new InvalidDataException();
            }

            int addressRelocTableOffset = reader.ReadInt32();
            int addressRelocTableSize = reader.ReadInt32();
            int numMessages = reader.ReadInt32();
            short isRelocated = reader.ReadInt16(); // actually a byte but not very important
            short unk0x1E = reader.ReadInt16();

            /*
            if (unk0x1C != UNK_CONSTANT)
            {
                Console.WriteLine("_unk0x1C isn't 0x20000");
            }
            */

            BMDMessageTable[] messagePointerTable = new BMDMessageTable[numMessages];
            for (int i = 0; i < messagePointerTable.Length; i++)
            {
                messagePointerTable[i].Type = (BMDMessageType)reader.ReadInt32();
                messagePointerTable[i].Offset = reader.ReadInt32();
            }

            int actorNamePointerTableOffset = reader.ReadInt32();
            int numActors = reader.ReadInt32();

            reader.BaseStream.Seek(posFileStart + DATA_START_ADDRESS + actorNamePointerTableOffset, SeekOrigin.Begin);
            int[] actorNamePointerTable = reader.ReadInt32Array(numActors);

            _actorNames = new string[numActors];
            for (int i = 0; i < _actorNames.Length; i++)
            {
                reader.BaseStream.Seek(posFileStart + DATA_START_ADDRESS + actorNamePointerTable[i], SeekOrigin.Begin);
                _actorNames[i] = reader.ReadCString();
            }

            _messages = new BMDMessage[numMessages];
            for (int i = 0; i < _messages.Length; i++)
            {
                _messages[i] = BMDMessageFactory.GetMessage(reader, (int)posFileStart, messagePointerTable[i]);
            }
        }
Example #7
0
 private void InternalRead(BinaryReader reader)
 {
     _header = reader.ReadStructure<CVMDirectoryListingHeader>(CVMDirectoryListingHeader.SIZE);
     _subEntries = new CVMDirectoryListingEntry[_header.entryCount];
   
     for (int i = 0; i < _header.entryCount; i++)
     {
         _subEntries[i] = new CVMDirectoryListingEntry(reader, this);
     }
     
     reader.AlignPosition(16);
    
     for (int i = 0; i < _header.entryCount; i++)
     {
         if (i > 1 && _subEntries[i].Flags.HasFlagUnchecked(RecordFlags.DirectoryRecord))
         {
             _subEntries[i].DirectoryListing = new CVMDirectoryListing(reader, _subEntries[i]);
         }
     }
 }
Example #8
0
        private void InternalRead(BinaryReader reader)
        {
            int size = reader.ReadInt32();
            _numAssignedFrames = reader.ReadUInt16();
            _type = reader.ReadUInt16();

            _assignedFrameIndices = reader.ReadUInt16Array(_numAssignedFrames);

            // Align to 4 bytes
            reader.AlignPosition(4);

            _boneKeyData = new float[_numAssignedFrames][];
            for (int i = 0; i < _numAssignedFrames; i++)
            {
                switch (_type)
                {
                    case 0x04:
                        {
                            _boneKeyData[i] = new float[2];
                            for (int j = 0; j < 2; j++)
                            {
                                _boneKeyData[i][j] = (float)reader.ReadInt16() / FIXED_POINT;
                            }
                        }

                        break;
                    case 0x08:
                        {
                            _boneKeyData[i] = new float[4];
                            for (int j = 0; j < 4; j++)
                            {
                                _boneKeyData[i][j] = (float)reader.ReadInt16() / FIXED_POINT;
                            }
                        }

                        break;
                    case 0x0C:
                        {
                            _boneKeyData[i] = new float[3];
                            for (int j = 0; j < 3; j++)
                            {
                                _boneKeyData[i][j] = reader.ReadSingle();
                            }
                        }

                        break;
                    default:
                        break;
                }
            }
        }
Example #9
0
        private void InternalRead(BinaryReader reader)
        {
            _name = reader.ReadCString(MAX_NAME_LENGTH);
            int dataLength = reader.ReadInt32();

            if (dataLength > reader.BaseStream.Length || dataLength < 0)
            {
                throw new InvalidDataException("dataLength has an invalid value.");
            }

            Data = reader.ReadBytes(dataLength);
            reader.AlignPosition(64);
        }