コード例 #1
0
        private static void ReadMap(ImcFile imc, BinaryReader file, int imusRawSize)
        {
            int mapSize = file.ReadBigEndianInt32();

            if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "FRMT")
            {
                throw new InvalidDataException();
            }

            int frmtSize = file.ReadBigEndianInt32();

            if (frmtSize != 20)
            {
                throw new InvalidDataException();
            }

            int frmtPosition = file.ReadBigEndianInt32();

            if (mapSize + 24 != frmtPosition)
            {
                throw new InvalidDataException();
            }

            int frmtIsBigEndian = file.ReadBigEndianInt32();

            if (frmtIsBigEndian != 1)
            {
                throw new InvalidDataException();
            }

            imc.BitsPerSample = file.ReadBigEndianInt32();
            imc.SampleRate = file.ReadBigEndianInt32();
            imc.Channels = file.ReadBigEndianInt32();

            int blockAlign = imc.BlockAlign;

            while (true)
            {
                string fourcc = Encoding.ASCII.GetString(file.ReadBytes(4));

                if (string.Equals(fourcc, "STOP", StringComparison.Ordinal))
                {
                    int size = file.ReadBigEndianInt32();

                    if (size != 4)
                    {
                        throw new InvalidDataException();
                    }

                    int position = file.ReadBigEndianInt32() - frmtPosition;

                    if (position != imusRawSize - mapSize - 16)
                    {
                        throw new InvalidDataException();
                    }

                    break;
                }

                switch (fourcc)
                {
                    case "REGN":
                        var regn = new ImcRegnBlock();
                        regn.Read(file, frmtPosition);
                        break;

                    case "TEXT":
                        var text = new ImcTextBlock();
                        text.Read(file, frmtPosition);

                        imc.Map.Add(new ImcText
                        {
                            Position = text.Position / blockAlign,
                            Text = text.Text
                        });
                        break;

                    case "JUMP":
                        var jump = new ImcJumpBlock();
                        jump.Read(file, frmtPosition);

                        imc.Map.Add(new ImcJump
                        {
                            Position = jump.Position / blockAlign,
                            Destination = jump.Destination / blockAlign,
                            HookId = jump.HookId,
                            Delay = jump.Delay
                        });
                        break;

                    default:
                        throw new NotSupportedException("Unknown block " + fourcc);
                }
            }
        }
コード例 #2
0
        private static void ReadMap(ImcFile imc, BinaryReader file, int imusRawSize)
        {
            int mapSize = file.ReadBigEndianInt32();

            if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "FRMT")
            {
                throw new InvalidDataException();
            }

            int frmtSize = file.ReadBigEndianInt32();

            if (frmtSize != 20)
            {
                throw new InvalidDataException();
            }

            int frmtPosition = file.ReadBigEndianInt32();

            if (mapSize + 24 != frmtPosition)
            {
                throw new InvalidDataException();
            }

            int frmtIsBigEndian = file.ReadBigEndianInt32();

            if (frmtIsBigEndian != 1)
            {
                throw new InvalidDataException();
            }

            imc.BitsPerSample = file.ReadBigEndianInt32();
            imc.SampleRate    = file.ReadBigEndianInt32();
            imc.Channels      = file.ReadBigEndianInt32();

            int blockAlign = imc.BlockAlign;

            while (true)
            {
                string fourcc = Encoding.ASCII.GetString(file.ReadBytes(4));

                if (string.Equals(fourcc, "STOP", StringComparison.Ordinal))
                {
                    int size = file.ReadBigEndianInt32();

                    if (size != 4)
                    {
                        throw new InvalidDataException();
                    }

                    int position = file.ReadBigEndianInt32() - frmtPosition;

                    if (position != imusRawSize - mapSize - 16)
                    {
                        throw new InvalidDataException();
                    }

                    break;
                }

                switch (fourcc)
                {
                case "REGN":
                    var regn = new ImcRegnBlock();
                    regn.Read(file, frmtPosition);
                    break;

                case "TEXT":
                    var text = new ImcTextBlock();
                    text.Read(file, frmtPosition);

                    imc.Map.Add(new ImcText
                    {
                        Position = text.Position / blockAlign,
                        Text     = text.Text
                    });
                    break;

                case "JUMP":
                    var jump = new ImcJumpBlock();
                    jump.Read(file, frmtPosition);

                    imc.Map.Add(new ImcJump
                    {
                        Position    = jump.Position / blockAlign,
                        Destination = jump.Destination / blockAlign,
                        HookId      = jump.HookId,
                        Delay       = jump.Delay
                    });
                    break;

                default:
                    throw new NotSupportedException("Unknown block " + fourcc);
                }
            }
        }