public bool ProcessAnimations(BinaryReader b)
        {
            try
            {
                animations.Clear();

                b.BaseStream.Position = 0;
                // Get location of animation data
                b.ReadBytes(28);
                int animationCount = b.ReadInt32();
                int animationMemAllocSize = b.ReadInt32();
                int filesize = b.ReadInt32();

                // Seek to animation data
                int noriheadersize = 40;
                int animationLocation = filesize - (animationMemAllocSize - noriheadersize);
                b.BaseStream.Position = animationLocation;

                // Read animation offsets
                List<int> offsets = new List<int>();
                if (animationCount > 1) // Address list only present if more than 1 animation
                {
                    int offsetsSize = animationCount * 4;
                    for (int i = 0; i < animationCount; i++)
                    {
                        offsets.Add(b.ReadInt32() + animationLocation + offsetsSize);
                    }
                }
                else
                {
                    offsets.Add(animationLocation);
                }

                for (int i = 0; i < animationCount; i++)
                {
                    b.BaseStream.Position = offsets[i];
                    Animation anim = new Animation();
                    anim.frames = new List<Frame>();
                    anim.offset = b.BaseStream.Position;

                    byte[] name_raw = b.ReadBytes(32);
                    string name = Encoding.GetEncoding(51949).GetString(name_raw); // EUC-KR
                    // Convert to null-terminated version
                    string[] parts = name.Split(new char[] { '\0' });
                    name = parts[0];

                    int frameCount = b.ReadInt32();
                    anim.name = name;

                    // Get frame offsets
                    int refPosition = (int)b.BaseStream.Position;
                    List<int> frameOffsets = new List<int>();
                    int frameOffsetsSize = frameCount * 4;
                    for (int j = 0; j < frameCount; j++)
                    {
                        frameOffsets.Add(b.ReadInt32() + refPosition + frameOffsetsSize);
                    }

                    // Process frame data
                    for (int j = 0; j < frameCount; j++)
                    {
                        b.BaseStream.Position = frameOffsets[j];
                        Frame frame = new Frame();
                        frame.delay = b.ReadInt32();
                        frame.planes = new List<FramePlane>();
                        frame.effects = new List<FrameEffect>();

                        // Read plane data
                        int planeCount = b.ReadInt32();
                        for (int c = 0; c < planeCount; c++)
                        {
                            FramePlane plane = new FramePlane();
                            plane.bitmapid = b.ReadInt32();
                            plane.x = b.ReadInt32();
                            plane.y = b.ReadInt32();
                            plane.transparency = b.ReadInt32();
                            plane.reverseflag = b.ReadInt32();
                            plane.param5 = b.ReadInt32();
                            plane.param6 = b.ReadInt32();
                            frame.planes.Add(plane);
                        }

                        // Read frame additional data
                        switch (this.nritype)
                        {
                            case 0x12C:
                                b.ReadBytes(0x90); // CD block
                                b.ReadBytes(0x50); // Null block
                                break;
                            case 0x12D:
                                b.ReadInt32(); // int32 value
                                b.ReadBytes(0x90); // CD block
                                b.ReadBytes(0x50); // Null block
                                break;
                            case 0x12E:
                                b.ReadInt32(); // int32 value
                                b.ReadBytes(0x60); // CD block
                                for (int z = 0; z < 6; z++)
                                {
                                    FrameEffect effect = new FrameEffect();
                                    b.ReadInt32(); // 0xCDCDCDCD
                                    effect.param1 = b.ReadInt32();
                                    effect.x = b.ReadInt32();
                                    effect.y = b.ReadInt32();
                                    effect.param4 = b.ReadInt32();
                                    effect.param5 = b.ReadInt32();
                                    effect.param6 = b.ReadInt32();
                                    frame.effects.Add(effect);
                                }
                                b.ReadBytes(0x50); // Null block
                                break;
                            case 0x12F:
                                b.ReadInt32(); // int32 value
                                b.ReadBytes(0x60); // CD block
                                for (int z = 0; z < 6; z++)
                                {
                                    FrameEffect effect = new FrameEffect();
                                    b.ReadInt32(); // 0xCDCDCDCD
                                    effect.param1 = b.ReadInt32();
                                    effect.x = b.ReadInt32();
                                    effect.y = b.ReadInt32();
                                    effect.param4 = b.ReadInt32();
                                    effect.param5 = b.ReadInt32();
                                    effect.param6 = b.ReadInt32();
                                    frame.effects.Add(effect);
                                }
                                b.ReadBytes(0x54); // Null block
                                break;
                        }

                        anim.frames.Add(frame);
                    }

                    animations.Add(anim);
                }
                return true;
            }
            catch
            {
            }
            return false;
        }
Exemple #2
0
        public bool ProcessAnimations(BinaryReader b)
        {
            try
            {
                animations.Clear();

                b.BaseStream.Position = 0;
                // Get location of animation data
                b.ReadBytes(28);
                int animationCount        = b.ReadInt32();
                int animationMemAllocSize = b.ReadInt32();
                int filesize = b.ReadInt32();

                // Seek to animation data
                int noriheadersize    = 40;
                int animationLocation = filesize - (animationMemAllocSize - noriheadersize);
                b.BaseStream.Position = animationLocation;

                // Read animation offsets
                List <int> offsets = new List <int>();
                if (animationCount >= 1) // Address list only present if more than 1 animation
                {
                    int offsetsSize = animationCount * 4;
                    for (int i = 0; i < animationCount; i++)
                    {
                        offsets.Add(b.ReadInt32() + animationLocation + offsetsSize);
                    }
                }
                else
                {
                    offsets.Add(animationLocation);
                }

                for (int i = 0; i < animationCount; i++)
                {
                    b.BaseStream.Position = offsets[i];
                    Animation anim = new Animation();
                    anim.frames = new List <Frame>();
                    anim.offset = b.BaseStream.Position;

                    byte[] name_raw = b.ReadBytes(32);
                    string name     = Encoding.GetEncoding(51949).GetString(name_raw); // EUC-KR
                    // Convert to null-terminated version
                    string[] parts = name.Split(new char[] { '\0' });
                    name = parts[0];

                    int frameCount = b.ReadInt32();
                    anim.name = name;

                    // Get frame offsets
                    int        refPosition      = (int)b.BaseStream.Position;
                    List <int> frameOffsets     = new List <int>();
                    int        frameOffsetsSize = frameCount * 4;
                    for (int j = 0; j < frameCount; j++)
                    {
                        frameOffsets.Add(b.ReadInt32() + refPosition + frameOffsetsSize);
                    }

                    // Process frame data
                    for (int j = 0; j < frameCount; j++)
                    {
                        b.BaseStream.Position = frameOffsets[j];
                        Frame frame = new Frame();
                        frame.delay   = b.ReadInt32();
                        frame.planes  = new List <FramePlane>();
                        frame.effects = new List <FrameEffect>();

                        // Read plane data
                        int planeCount = b.ReadInt32();
                        for (int c = 0; c < planeCount; c++)
                        {
                            FramePlane plane = new FramePlane();
                            plane.bitmapid     = b.ReadInt32();
                            plane.x            = b.ReadInt32();
                            plane.y            = b.ReadInt32();
                            plane.transparency = b.ReadInt32();
                            plane.reverseflag  = b.ReadInt32();
                            plane.param5       = b.ReadInt32();
                            plane.param6       = b.ReadInt32();
                            frame.planes.Add(plane);
                        }

                        // Read frame additional data
                        switch (this.nritype)
                        {
                        case 0x12C:
                            b.ReadBytes(0x90);     // CD block
                            b.ReadBytes(0x50);     // Null block
                            break;

                        case 0x12D:
                            b.ReadInt32();     // int32 value
                            b.ReadBytes(0x90); // CD block
                            b.ReadBytes(0x50); // Null block
                            break;

                        case 0x12E:
                            b.ReadInt32();     // int32 value
                            b.ReadBytes(0x60); // CD block
                            for (int z = 0; z < 6; z++)
                            {
                                FrameEffect effect = new FrameEffect();
                                b.ReadInt32();     // 0xCDCDCDCD
                                effect.param1 = b.ReadInt32();
                                effect.x      = b.ReadInt32();
                                effect.y      = b.ReadInt32();
                                effect.param4 = b.ReadInt32();
                                effect.param5 = b.ReadInt32();
                                effect.param6 = b.ReadInt32();
                                frame.effects.Add(effect);
                            }
                            b.ReadBytes(0x50);     // Null block
                            break;

                        case 0x12F:
                            b.ReadInt32();     // int32 value
                            b.ReadBytes(0x60); // CD block
                            for (int z = 0; z < 6; z++)
                            {
                                FrameEffect effect = new FrameEffect();
                                b.ReadInt32();     // 0xCDCDCDCD
                                effect.param1 = b.ReadInt32();
                                effect.x      = b.ReadInt32();
                                effect.y      = b.ReadInt32();
                                effect.param4 = b.ReadInt32();
                                effect.param5 = b.ReadInt32();
                                effect.param6 = b.ReadInt32();
                                frame.effects.Add(effect);
                            }
                            b.ReadBytes(0x54);     // Null block
                            break;
                        }

                        anim.frames.Add(frame);
                    }

                    animations.Add(anim);
                }
                return(true);
            }
            catch
            {
            }
            return(false);
        }