예제 #1
0
        public void Load(BinaryRobloxFileReader reader)
        {
            int numSignatures = reader.ReadInt32();

            Signatures = new Signature[numSignatures];

            for (int i = 0; i < numSignatures; i++)
            {
                var signature = new Signature
                {
                    Version = reader.ReadInt32(),
                    Id      = reader.ReadInt64(),

                    Length = reader.ReadInt32(),
                };

                signature.Data = reader.ReadBytes(signature.Length);
                Signatures[i]  = signature;
            }

            var file = reader.File;

            file.SIGN = this;
        }
        protected override void ReadFile(byte[] contents)
        {
            using (MemoryStream file = new MemoryStream(contents))
                using (BinaryRobloxFileReader reader = new BinaryRobloxFileReader(this, file))
                {
                    // Verify the signature of the file.
                    byte[] binSignature = reader.ReadBytes(14);
                    string signature    = Encoding.UTF7.GetString(binSignature);

                    if (signature != MagicHeader)
                    {
                        throw new InvalidDataException("Provided file's signature does not match BinaryRobloxFile.MagicHeader!");
                    }

                    // Read header data.
                    Version      = reader.ReadUInt16();
                    NumClasses   = reader.ReadUInt32();
                    NumInstances = reader.ReadUInt32();
                    Reserved     = reader.ReadInt64();

                    // Begin reading the file chunks.
                    bool reading = true;

                    Classes   = new INST[NumClasses];
                    Instances = new Instance[NumInstances];

                    while (reading)
                    {
                        try
                        {
                            var chunk = new BinaryRobloxFileChunk(reader);
                            IBinaryFileChunk handler = null;

                            switch (chunk.ChunkType)
                            {
                            case "INST":
                                handler = new INST();
                                break;

                            case "PROP":
                                handler = new PROP();
                                break;

                            case "PRNT":
                                handler = new PRNT();
                                break;

                            case "META":
                                handler = new META();
                                break;

                            case "SSTR":
                                handler = new SSTR();
                                break;

                            case "SIGN":
                                handler = new SIGN();
                                break;

                            case "END\0":
                                ChunksImpl.Add(chunk);
                                reading = false;
                                break;

                            case string unhandled:
                                Console.Error.WriteLine("BinaryRobloxFile - Unhandled chunk-type: {0}!", unhandled);
                                break;

                            default: break;
                            }

                            if (handler != null)
                            {
                                using (var readBuffer = new MemoryStream(chunk.Data))
                                {
                                    using (var dataReader = new BinaryRobloxFileReader(this, readBuffer))
                                    {
                                        chunk.Handler = handler;
                                        handler.Load(dataReader);
                                    }
                                }

                                ChunksImpl.Add(chunk);
                            }
                        }
                        catch (EndOfStreamException)
                        {
                            throw new Exception("Unexpected end of file!");
                        }
                    }
                }
        }