示例#1
0
        public static bool Load(RiffChunk parent, RiffChunk chunk, IReadable stream)
        {
            if (parent != null && RiffChunk.HeaderSize > parent.Size)
            {
                return(false);
            }

            if (stream.Position + HeaderSize >= stream.Length)
            {
                return(false);
            }

            chunk.Id = stream.Read8BitStringLength(4);
            if (chunk.Id[0] <= ' ' || chunk.Id[0] >= 'z')
            {
                return(false);
            }
            chunk.Size = stream.ReadUInt32LE();

            if (parent != null && HeaderSize + chunk.Size > parent.Size)
            {
                return(false);
            }

            if (parent != null)
            {
                parent.Size -= HeaderSize + chunk.Size;
            }

            var isRiff = chunk.Id == "RIFF";
            var isList = chunk.Id == "LIST";

            if (isRiff && parent != null)
            {
                // not allowed
                return(false);
            }

            if (!isRiff && !isList)
            {
                // custom type without sub type
                return(true);
            }

            // for lists unwrap the list type
            chunk.Id = stream.Read8BitStringLength(4);
            if (chunk.Id[0] <= ' ' || chunk.Id[0] >= 'z')
            {
                return(false);
            }
            chunk.Size -= 4;

            return(true);
        }
示例#2
0
        public void Load(IReadable readable)
        {
            var chunkHead     = new RiffChunk();
            var chunkFastList = new RiffChunk();

            if (!RiffChunk.Load(null, chunkHead, readable) || chunkHead.Id != "sfbk")
            {
                return;
            }

            while (RiffChunk.Load(chunkHead, chunkFastList, readable))
            {
                var chunk = new RiffChunk();
                if (chunkFastList.Id == "pdta")
                {
                    while (RiffChunk.Load(chunkFastList, chunk, readable))
                    {
                        switch (chunk.Id)
                        {
                        case "phdr":
                            for (uint i = 0, count = chunk.Size / HydraPhdr.SizeInFile; i < count; i++)
                            {
                                Phdrs.Add(HydraPhdr.Load(readable));
                            }

                            break;

                        case "pbag":
                            for (uint i = 0, count = chunk.Size / HydraPbag.SizeInFile; i < count; i++)
                            {
                                Pbags.Add(HydraPbag.Load(readable));
                            }

                            break;

                        case "pmod":
                            for (uint i = 0, count = chunk.Size / HydraPmod.SizeInFile; i < count; i++)
                            {
                                Pmods.Add(HydraPmod.Load(readable));
                            }

                            break;

                        case "pgen":
                            for (uint i = 0, count = chunk.Size / HydraPgen.SizeInFile; i < count; i++)
                            {
                                Pgens.Add(HydraPgen.Load(readable));
                            }

                            break;

                        case "inst":
                            for (uint i = 0, count = chunk.Size / HydraInst.SizeInFile; i < count; i++)
                            {
                                Insts.Add(HydraInst.Load(readable));
                            }

                            break;

                        case "ibag":
                            for (uint i = 0, count = chunk.Size / HydraIbag.SizeInFile; i < count; i++)
                            {
                                Ibags.Add(HydraIbag.Load(readable));
                            }

                            break;

                        case "imod":
                            for (uint i = 0, count = chunk.Size / HydraImod.SizeInFile; i < count; i++)
                            {
                                Imods.Add(HydraImod.Load(readable));
                            }

                            break;

                        case "igen":
                            for (uint i = 0, count = chunk.Size / HydraIgen.SizeInFile; i < count; i++)
                            {
                                Igens.Add(HydraIgen.Load(readable));
                            }

                            break;

                        case "shdr":
                            for (uint i = 0, count = chunk.Size / HydraShdr.SizeInFile; i < count; i++)
                            {
                                SHdrs.Add(HydraShdr.Load(readable));
                            }

                            break;

                        default:
                            readable.Position += (int)chunk.Size;
                            break;
                        }
                    }
                }
                else if (chunkFastList.Id == "sdta")
                {
                    while (RiffChunk.Load(chunkFastList, chunk, readable))
                    {
                        switch (chunk.Id)
                        {
                        case "smpl":
                            FontSamples = LoadSamples(chunk, readable);
                            break;

                        default:
                            readable.Position += (int)chunk.Size;
                            break;
                        }
                    }
                }
                else
                {
                    readable.Position += (int)chunkFastList.Size;
                }
            }
        }