Exemplo 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);
        }
Exemplo n.º 2
0
        private static unsafe Skill LoadSkill(int index, BinaryFileReader reader)
        {
            int nameLength = m_FileIndex.Index[index].length - 2;
            int extra = m_FileIndex.Index[index].extra;

            byte[] set1 = new byte[1];
            byte[] set2 = new byte[nameLength];
            byte[] set3 = new byte[1];

            set1 = reader.ReadBytes(1);
            set2 = reader.ReadBytes(nameLength);
            set3 = reader.ReadBytes(1);

            bool useBtn = ToBool(set1);
            string name = ToString(set2);

            return new Skill(new SkillVars(index, name, useBtn, extra, set3[0]));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
        private IAnimationFrame[] LoadAnimation(BinaryFileReader reader, AnimationFrame.SittingTransformation sitting)
        {
            ushort[] palette = GetPalette(reader); // 0x100 * 2 = 0x0200 bytes
            int read_start = (int)reader.Position; // save file position after palette.

            int frameCount = reader.ReadInt(); // 0x04 bytes

            int[] lookups = new int[frameCount]; // frameCount * 0x04 bytes
            for (int i = 0; i < frameCount; ++i) { lookups[i] = reader.ReadInt(); }

            IAnimationFrame[] frames = new AnimationFrame[frameCount];
            for (int i = 0; i < frameCount; ++i)
            {
                if (lookups[i] < lookups[0])
                {
                    frames[i] = AnimationFrame.Empty; // Fix for broken animations, per issue13
                }
                else
                {
                    reader.Seek(read_start + lookups[i], SeekOrigin.Begin);
                    frames[i] = new AnimationFrame(m_Graphics, palette, reader, sitting);
                }
            }
            return frames;
        }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
        public void Load()
        {
            if (s_Path == null || s_Path == string.Empty)
                return;

            if (!File.Exists(s_Path))
            {
                Tracer.Debug("No macros to load. Creating deafult macro set");
                CreateDefaultMacroSet();
                return;
            }

            try
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(new FileStream(s_Path, FileMode.Open)));
                if (Unserialize(reader))
                {
                    Tracer.Debug("Macros loaded!");
                }
                else
                {
                    Tracer.Debug("Error reading macro file.");
                }
                reader.Close();
                reader = null;
            }
            catch (Exception e)
            {
                Tracer.Warn(string.Format("Error loading macros: {0}", e.Message));
            }
        }
Exemplo n.º 9
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);
        }