Exemple #1
0
        public byte[] GetData()
        {
            using (MemoryStream MS = new MemoryStream())
                using (BinaryWriter writer = IOTools.OpenWriteFile(MS, IsLittleEndian))
                {
                    byte[] buffer;

                    List <int> LastBlock = new List <int>();

                    #region Header

                    buffer = new byte[4] {
                        7, 0, 0, 0
                    };
                    writer.Write(buffer);
                    writer.Write((int)0x0);
                    buffer = Encoding.ASCII.GetBytes("MSG1");
                    writer.Write(BitConverter.ToInt32(buffer, 0));
                    writer.Write((int)0x0);
                    writer.Write((int)0x0);
                    writer.Write((int)0x0);
                    writer.Write(Msg.Count);
                    writer.Write((ushort)0);
                    writer.Write((ushort)0x2);

                    #endregion

                    #region MSG Pointer

                    int MSG_offset = Msg.Count * 8 + 16;

                    foreach (var MSG in Msg)
                    {
                        writer.Write(MSG.Type);
                        LastBlock.Add((int)MS.Position);
                        writer.Write(MSG_offset);
                        MSG_offset += MSG.GetSize();
                    }
                    LastBlock.Add((int)MS.Position);
                    writer.Write(MSG_offset);
                    writer.Write(Name.Count);
                    writer.Write((int)0x0);
                    writer.Write((int)0x0);

                    #endregion

                    #region MSG

                    MSG_offset = Msg.Count * 8 + 16;

                    foreach (var MSG in Msg)
                    {
                        MSG.Write(writer, MSG_offset, LastBlock);
                        MSG_offset += MSG.GetSize();
                    }

                    #endregion

                    #region Name Pointer

                    MSG_offset += Name.Count * 4;

                    foreach (var name in Name)
                    {
                        LastBlock.Add((int)MS.Position);
                        writer.Write(MSG_offset);
                        if (name.NameBytes.Length == 0)
                        {
                            MSG_offset += 2;
                        }
                        else
                        {
                            MSG_offset += name.NameBytes.Length + 1;
                        }
                    }

                    #endregion

                    #region Name

                    foreach (var name in Name)
                    {
                        if (name.NameBytes.Length == 0)
                        {
                            writer.Write((byte)0x20);
                        }
                        else
                        {
                            writer.Write(name.NameBytes);
                        }
                        writer.Write((byte)0);
                    }
                    writer.Write(new byte[IOTools.Alignment(MS.Position, 4)]);

                    #endregion

                    #region Pointers

                    int    LastBlockPos   = (int)MS.Position;
                    byte[] ptrDiffSection = CreatePointersDiffSection(LastBlock);
                    writer.Write(ptrDiffSection);

                    MS.Position = 0x10;
                    writer.Write(LastBlockPos);
                    writer.Write(ptrDiffSection.Length);

                    MS.Position = 0x4;
                    writer.Write((int)MS.Length);

                    #endregion



                    return(MS.ToArray());
                }
        }