Esempio n. 1
0
 internal Cell(Layout.Entry layout, object value)
 {
     Layout = layout;
     Value  = value;
 }
Esempio n. 2
0
            internal void ReadRow(BinaryReaderEx br, Layout layout)
            {
                br.StepIn(Offset);
                Cells = new List <Cell>(layout.Count);

                for (int i = 0; i < layout.Count; i++)
                {
                    Layout.Entry entry = layout[i];
                    CellType     type  = entry.Type;

                    object value = null;

                    if (type == CellType.s8)
                    {
                        value = br.ReadSByte();
                    }
                    else if (type == CellType.u8 || type == CellType.x8)
                    {
                        value = br.ReadByte();
                    }
                    else if (type == CellType.s16)
                    {
                        value = br.ReadInt16();
                    }
                    else if (type == CellType.u16 || type == CellType.x16)
                    {
                        value = br.ReadUInt16();
                    }
                    else if (type == CellType.s32)
                    {
                        value = br.ReadInt32();
                    }
                    else if (type == CellType.u32 || type == CellType.x32)
                    {
                        value = br.ReadUInt32();
                    }
                    else if (type == CellType.f32)
                    {
                        value = br.ReadSingle();
                    }
                    else if (type == CellType.dummy8)
                    {
                        value = br.ReadBytes(entry.Size);
                    }
                    else if (type == CellType.fixstr)
                    {
                        value = br.ReadFixStr(entry.Size);
                    }
                    else if (type == CellType.fixstrW)
                    {
                        value = br.ReadFixStrW(entry.Size);
                    }
                    else if (type == CellType.b8)
                    {
                        byte b = br.ReadByte();
                        int  j;
                        for (j = 0; j < 8; j++)
                        {
                            if (i + j >= layout.Count || layout[i + j].Type != CellType.b8)
                            {
                                break;
                            }

                            byte mask = (byte)(1 << j);
                            Cells.Add(new Cell(layout[i + j], (b & mask) != 0));
                        }
                        i += j - 1;
                    }
                    else if (type == CellType.b32)
                    {
                        byte[] b = br.ReadBytes(4);
                        int    j;
                        for (j = 0; j < 32; j++)
                        {
                            if (i + j >= layout.Count || layout[i + j].Type != CellType.b32)
                            {
                                break;
                            }

                            byte mask = (byte)(1 << (j % 8));
                            Cells.Add(new Cell(layout[i + j], (b[j / 8] & mask) != 0));
                        }
                        i += j - 1;
                    }
                    else
                    {
                        throw new NotImplementedException($"Unsupported param layout type: {type}");
                    }

                    if (value != null)
                    {
                        Cells.Add(new Cell(entry, value));
                    }
                }

                br.StepOut();
            }
Esempio n. 3
0
            internal void WriteCells(BinaryWriterEx bw, int i, Layout layout)
            {
                bw.FillInt64($"RowOffset{i}", bw.Position);
                for (int j = 0; j < layout.Count; j++)
                {
                    Cell         cell  = Cells[j];
                    Layout.Entry entry = layout[j];
                    CellType     type  = entry.Type;
                    object       value = cell.Value;

                    if (entry.Name != cell.Name || type != cell.Type)
                    {
                        throw new FormatException("Layout does not match cells.");
                    }

                    if (type == CellType.s8)
                    {
                        bw.WriteSByte((sbyte)value);
                    }
                    else if (type == CellType.u8 || type == CellType.x8)
                    {
                        bw.WriteByte((byte)value);
                    }
                    else if (type == CellType.s16)
                    {
                        bw.WriteInt16((short)value);
                    }
                    else if (type == CellType.u16 || type == CellType.x16)
                    {
                        bw.WriteUInt16((ushort)value);
                    }
                    else if (type == CellType.s32)
                    {
                        bw.WriteInt32((int)value);
                    }
                    else if (type == CellType.u32 || type == CellType.x32)
                    {
                        bw.WriteUInt32((uint)value);
                    }
                    else if (type == CellType.f32)
                    {
                        bw.WriteSingle((float)value);
                    }
                    else if (type == CellType.dummy8)
                    {
                        bw.WriteBytes((byte[])value);
                    }
                    else if (type == CellType.fixstr)
                    {
                        bw.WriteFixStr((string)value, entry.Size);
                    }
                    else if (type == CellType.fixstrW)
                    {
                        bw.WriteFixStrW((string)value, entry.Size);
                    }
                    else if (type == CellType.b8)
                    {
                        byte b = 0;
                        int  k;
                        for (k = 0; k < 8; k++)
                        {
                            if (j + k >= layout.Count || layout[j + k].Type != CellType.b8)
                            {
                                break;
                            }

                            if ((bool)Cells[j + k].Value)
                            {
                                b |= (byte)(1 << k);
                            }
                        }
                        j += k - 1;
                        bw.WriteByte(b);
                    }
                    else if (type == CellType.b32)
                    {
                        byte[] b = new byte[4];
                        int    k;
                        for (k = 0; k < 32; k++)
                        {
                            if (j + k >= layout.Count || layout[j + k].Type != CellType.b32)
                            {
                                break;
                            }

                            if ((bool)Cells[j + k].Value)
                            {
                                b[k / 8] |= (byte)(1 << (k % 8));
                            }
                        }
                        j += k - 1;
                        bw.WriteBytes(b);
                    }
                }
            }
Esempio n. 4
0
            internal void ReadRow(BinaryReaderEx br, Layout layout)
            {
                br.StepIn(Offset);
                Cells = new List <Cell>();

                for (int i = 0; i < layout.Count; i++)
                {
                    Layout.Entry entry = layout[i];
                    string       type  = entry.Type;

                    object value = null;

                    if (type == "s8")
                    {
                        value = br.ReadSByte();
                    }
                    else if (type == "u8" || type == "x8")
                    {
                        value = br.ReadByte();
                    }
                    else if (type == "s16")
                    {
                        value = br.ReadInt16();
                    }
                    else if (type == "u16" || type == "x16")
                    {
                        value = br.ReadUInt16();
                    }
                    else if (type == "s32")
                    {
                        value = br.ReadInt32();
                    }
                    else if (type == "u32" || type == "x32")
                    {
                        value = br.ReadUInt32();
                    }
                    else if (type == "f32")
                    {
                        value = br.ReadSingle();
                    }
                    else if (type == "dummy8")
                    {
                        value = br.ReadBytes(entry.Size);
                    }
                    else if (type == "fixstr")
                    {
                        value = br.ReadFixStr(entry.Size);
                    }
                    else if (type == "fixstrW")
                    {
                        value = br.ReadFixStrW(entry.Size);
                    }
                    else if (type == "b8")
                    {
                        byte b = br.ReadByte();
                        int  j;
                        for (j = 0; j < 8; j++)
                        {
                            if (i + j >= layout.Count || layout[i + j].Type != "b8")
                            {
                                break;
                            }

                            byte mask = (byte)(1 << j);
                            Cells.Add(new Cell("b8", layout[i + j].Name, (b & mask) != 0));
                        }
                        i += j - 1;
                    }
                    else if (type == "b32")
                    {
                        byte[] b = br.ReadBytes(4);
                        int    j;
                        for (j = 0; j < 32; j++)
                        {
                            if (i + j >= layout.Count || layout[i + j].Type != "b32")
                            {
                                break;
                            }

                            byte mask = (byte)(1 << (j % 8));
                            Cells.Add(new Cell("b32", layout[i + j].Name, (b[j / 8] & mask) != 0));
                        }
                        i += j - 1;
                    }
                    else
                    {
                        throw new NotImplementedException($"Unsupported param layout type: {type}");
                    }

                    if (value != null)
                    {
                        Cells.Add(new Cell(type, entry.Name, value));
                    }
                }

                br.StepOut();
            }