Exemple #1
0
        public META(RobloxBinaryChunk chunk)
        {
            using (RobloxBinaryReader reader = chunk.GetReader("META"))
            {
                NumEntries = reader.ReadInt32();
                Entries    = new Dictionary <string, string>(NumEntries);

                for (int i = 0; i < NumEntries; i++)
                {
                    string key   = reader.ReadString();
                    string value = reader.ReadString();
                    Entries.Add(key, value);
                }
            }
        }
Exemple #2
0
        public PROP(RobloxBinaryChunk chunk)
        {
            Reader = chunk.GetReader("PROP");

            TypeIndex = Reader.ReadInt32();
            Name      = Reader.ReadString();

            try
            {
                byte propType = Reader.ReadByte();
                Type = (PropertyType)propType;
            }
            catch
            {
                Type = PropertyType.Unknown;
            }
        }
        public RobloxBinaryFile(byte[] contents)
        {
            using (MemoryStream file = new MemoryStream(contents))
                using (RobloxBinaryReader reader = new RobloxBinaryReader(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 RobloxBinaryFile.MagicHeader!");
                    }

                    // Read header data.
                    Version      = reader.ReadUInt16();
                    NumTypes     = reader.ReadUInt32();
                    NumInstances = reader.ReadUInt32();
                    Reserved     = reader.ReadBytes(8);

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

                    Types     = new INST[NumTypes];
                    Instances = new FileInstance[NumInstances];

                    while (reading)
                    {
                        try
                        {
                            RobloxBinaryChunk chunk = new RobloxBinaryChunk(reader);
                            Chunks.Add(chunk);

                            switch (chunk.ChunkType)
                            {
                            case "INST":
                                INST type = new INST(chunk);
                                type.Allocate(this);
                                break;

                            case "PROP":
                                PROP prop = new PROP(chunk);
                                prop.ReadProperties(this);
                                break;

                            case "PRNT":
                                PRNT hierarchy = new PRNT(chunk);
                                hierarchy.Assemble(this);
                                break;

                            case "META":
                                Metadata = new META(chunk);
                                break;

                            case "END\0":
                                reading = false;
                                break;

                            default:
                                Chunks.Remove(chunk);
                                break;
                            }
                        }
                        catch (EndOfStreamException)
                        {
                            throw new Exception("Unexpected end of file!");
                        }
                    }
                }
        }