Ejemplo n.º 1
0
        public unsafe AnimationFrame(GraphicsDevice graphics, ushort[] palette, BinaryFileReader reader)
        {
            int xCenter = reader.ReadShort();
            int yCenter = reader.ReadShort();

            int width = reader.ReadUShort();
            int height = reader.ReadUShort();

            // Fix for animations with no IO.
            if ((width == 0) || (height == 0))
            {
                m_Texture = null;
                return;
            }

            ushort[] data = new ushort[width * height];

            int header;

            int xBase = xCenter - 0x200;
            int yBase = (yCenter + height) - 0x200;

            fixed (ushort* pData = data)
            {
                ushort* dataRef = pData;
                int delta = width;

                int dataRead = 0;

                dataRef += xBase;
                dataRef += (yBase * delta);

                while ((header = reader.ReadInt()) != 0x7FFF7FFF)
                {
                    header ^= DoubleXor;

                    ushort* cur = dataRef + ((((header >> 12) & 0x3FF) * delta) + ((header >> 22) & 0x3FF));
                    ushort* end = cur + (header & 0xFFF);

                    int filecounter = 0;
                    byte[] filedata = reader.ReadBytes(header & 0xFFF);

                    while (cur < end)
                        *cur++ = palette[filedata[filecounter++]];

                    dataRead += header & 0xFFF;
                }

                Metrics.ReportDataRead(dataRead);
            }

            m_Center = new Microsoft.Xna.Framework.Point(xCenter, yCenter);

            m_Texture = new Texture2D(graphics, width, height, false, SurfaceFormat.Bgra5551);
            m_Texture.SetData<ushort>(data);
        }
Ejemplo n.º 2
0
        public MultiComponentList(BinaryFileReader reader, int count)
        {
            int metrics_dataread_start = (int)reader.Position;

            m_Min = m_Max = Point.Empty;

            Items = new MultiItem[count];

            for (int i = 0; i < count; ++i)
            {
                Items[i].ItemID = reader.ReadUShort();
                Items[i].OffsetX = reader.ReadShort();
                Items[i].OffsetY = reader.ReadShort();
                Items[i].OffsetZ = reader.ReadShort();
                Items[i].Flags = reader.ReadInt();
                reader.ReadInt();

                if (Items[i].OffsetX < m_Min.X)
                    m_Min.X = Items[i].OffsetX;

                if (Items[i].OffsetY < m_Min.Y)
                    m_Min.Y = Items[i].OffsetY;

                if (Items[i].OffsetX > m_Max.X)
                    m_Max.X = Items[i].OffsetX;

                if (Items[i].OffsetY > m_Max.Y)
                    m_Max.Y = Items[i].OffsetY;
            }

            m_Center = new Point(-m_Min.X, -m_Min.Y);
            m_Width = (m_Max.X - m_Min.X) + 1;
            m_Height = (m_Max.Y - m_Min.Y) + 1;

            // SortMultiComponentList();

            Metrics.ReportDataRead((int)reader.Position - metrics_dataread_start);
        }
Ejemplo n.º 3
0
 private ushort[] GetPalette(BinaryFileReader reader)
 {
     ushort[] pal = new ushort[0x100];
     for (int i = 0; i < 0x100; ++i)
     {
         pal[i] = (ushort)(reader.ReadUShort() | 0x8000);
     }
     return pal;
 }
Ejemplo n.º 4
0
 private static ushort[] getPalette(BinaryFileReader reader)
 {
     ushort[] pal = new ushort[0x100];
     for (int i = 0; i < 0x100; ++i)
     {
         pal[i] = (ushort)(reader.ReadUShort() | 0x8000);
         /*pal[i] = 0xFF000000 + (
             ((((color >> 10) & 0x1F) * 0xFF / 0x1F)) |
             ((((color >> 5) & 0x1F) * 0xFF / 0x1F) << 8) |
             (((color & 0x1F) * 0xFF / 0x1F) << 16)
             );*/
     }
     return pal;
 }
Ejemplo n.º 5
0
        private bool Unserialize(BinaryFileReader reader)
        {
            uint magic = reader.ReadUInt();
            if (magic != MAGIC)
                return false;

            if (m_Macros == null)
                m_Macros = new List<Action>();
            m_Macros.Clear();

            int version = reader.ReadInt();
            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                Action action = new Action();
                action.Keystroke = (WinKeys)reader.ReadUShort();
                action.Ctrl = reader.ReadBool();
                action.Alt = reader.ReadBool();
                action.Shift = reader.ReadBool();
                reader.ReadBool(); // unused filler byte

                int macroCount = reader.ReadUShort();
                for (int j = 0; j < macroCount; j++)
                {
                    int type = reader.ReadInt();
                    Macro.ValueTypes valueType = (Macro.ValueTypes)reader.ReadByte();
                    if (valueType == Macro.ValueTypes.Integer)
                        action.Macros.Add(new Macro((MacroType)type, reader.ReadInt()));
                    else if (valueType == Macro.ValueTypes.String)
                        action.Macros.Add(new Macro((MacroType)type, reader.ReadString()));
                    else
                        action.Macros.Add(new Macro((MacroType)type));
                }

                m_Macros.Add(action);

            }

            return true;
        }
Ejemplo n.º 6
0
        public unsafe AnimationFrame(GraphicsDevice graphics, ushort[] palette, BinaryFileReader reader, SittingTransformation sitting)
        {
            int xCenter = reader.ReadShort();
            int yCenter = reader.ReadShort();

            int width = reader.ReadUShort();
            int height = reader.ReadUShort();

            // Fix for animations with no pixels.
            if ((width == 0) || (height == 0))
            {
                Texture = null;
                return;
            }

            if (sitting == SittingTransformation.StandSouth)
            {
                xCenter += 8;
                width += 8;
                height += 4;
            }

            ushort[] data = new ushort[width * height];
            /*for (int i = 0; i < data.Length; i++)
                data[i] = 0xFFFF;*/

            // somewhere around the waist of a typical mobile animation, we take twelve rows of pixels,
            // discard every third, and shift every remaining row (total of eight) one pixel to the left
            // or right (depending on orientation), for a total skew of eight pixels.

            fixed (ushort* pData = data)
            {
                ushort* dataRef = pData;

                int dataRead = 0;

                int header;
                while ((header = reader.ReadInt()) != 0x7FFF7FFF)
                {
                    header ^= DoubleXor;

                    int x = ((header >> 22) & 0x3FF) + xCenter - 0x200;
                    int y = ((header >> 12) & 0x3FF) + yCenter + height - 0x200;

                    if (sitting == SittingTransformation.StandSouth)
                    {
                        const int skew_start = -17;
                        const int skew_end = skew_start - 16;
                        int iy = y - height - yCenter;
                        if (iy > skew_start)
                        {
                            // pixels below the skew
                            x -= 8;
                            y -= 4;
                        }
                        else if (iy > skew_end)
                        {
                            // pixels within the skew
                            if ((iy - skew_end) % 4 == 0)
                            {
                                reader.Position += (header & 0xFFF);
                                continue;
                            }
                            else
                            {
                                x -= (iy - skew_end) / 2;
                                y -= (iy - skew_end) / 4;
                            }
                        }
                    }

                    ushort* cur = dataRef + y * width + x;
                    ushort* end = cur + (header & 0xFFF);

                    int filecounter = 0;
                    byte[] filedata = reader.ReadBytes(header & 0xFFF);

                    while (cur < end)
                        *cur++ = palette[filedata[filecounter++]];

                    dataRead += header & 0xFFF;
                }

                Metrics.ReportDataRead(dataRead);
            }

            Center = new Point(xCenter, yCenter);

            Texture = new Texture2D(graphics, width, height, false, SurfaceFormat.Bgra5551);
            Texture.SetData<ushort>(data);
        }