Exemple #1
0
            public PBookHeaderOld(BookGump gump) : base(0x93)
            {
                EnsureSize(15 + 60 + 30);
                WriteUInt(gump.LocalSerial);
                WriteByte(gump.BookPageCount > 0 ? (byte)1 : (byte)0);
                WriteByte(gump.BookPageCount > 0 ? (byte)1 : (byte)0);

                WriteUShort(gump.BookPageCount);

                WriteASCII(gump.BookTitle.Text, 60);
                WriteASCII(gump.BookAuthor.Text, 30);
            }
Exemple #2
0
            public PBookHeader(BookGump gump) : base(0xD4)
            {
                byte[] titleBuffer  = Encoding.UTF8.GetBytes(gump.BookTitle.Text);
                byte[] authorBuffer = Encoding.UTF8.GetBytes(gump.BookAuthor.Text);
                EnsureSize(15 + titleBuffer.Length + authorBuffer.Length);
                WriteUInt(gump.LocalSerial);
                WriteByte(gump.BookPageCount > 0 ? (byte)1 : (byte)0);
                WriteByte(gump.BookPageCount > 0 ? (byte)1 : (byte)0);
                WriteUShort(gump.BookPageCount);

                WriteUShort((ushort)(titleBuffer.Length + 1));
                WriteBytes(titleBuffer, 0, titleBuffer.Length);
                WriteByte(0);
                WriteUShort((ushort)(authorBuffer.Length + 1));
                WriteBytes(authorBuffer, 0, authorBuffer.Length);
                WriteByte(0);
            }
Exemple #3
0
            public PBookData(BookGump gump) : base(0x66)
            {
                EnsureSize(256);

                WriteUInt(gump.LocalSerial);
                List <int> changed = new List <int>();

                for (int i = 1; i < gump.PageChanged.Length; i++)
                {
                    if (gump.PageChanged[i])
                    {
                        changed.Add(i);
                    }
                }

                WriteUShort((ushort)changed.Count);

                for (int i = changed.Count - 1; i >= 0; --i)
                {
                    WriteUShort((ushort)changed[i]);
                    MultiLineEntry mle  = gump.m_Pages[changed[i] - 1].TxEntry;
                    StringBuilder  sb   = new StringBuilder(mle.Text);
                    int            rows = 0;

                    if (sb.Length > 0)
                    {
                        var lcc = mle.GetLinesCharsCount(mle.Text);
                        rows = Math.Min(MaxBookLines, lcc.Length);
                        int pos = lcc.Sum();

                        for (int l = rows - 1; l >= 0; --l)
                        {
                            if (pos > 0 && (lcc[l] == 0 || sb[pos - 1] != '\n'))
                            {
                                sb.Insert(pos, '\n');
                            }
                            pos -= lcc[l];
                        }
                    }

                    var splits = sb.ToString().Split('\n');
                    int length = splits.Length;
                    WriteUShort((ushort)Math.Min(length, MaxBookLines));
                    if (length > MaxBookLines && changed[i] >= gump.BookPageCount)
                    {
                        Log.Error($"Book page {changed[i]} split into too many lines: {length - MaxBookLines} Additional lines will be lost");
                    }

                    for (int j = 0; j < length; j++)
                    {
                        // each line should BE < 53 chars long, even if 80 is admitted (the 'dot' is the least space demanding char, '.',
                        // a page full of dots is 52 chars exactly, but in multibyte things might change in byte size!)
                        if (j < MaxBookLines)
                        {
                            if (IsNewBook)
                            {
                                byte[] buf = Encoding.UTF8.GetBytes(splits[j]);

                                if (buf.Length > 79)
                                {
                                    Log.Error($"Book page {changed[i]} single line too LONG, total lenght -> {buf.Length} vs MAX 79 bytes allowed, some content might get lost");
                                    splits[j] = splits[j].Substring(0, 79);
                                }

                                WriteBytes(buf, 0, buf.Length);
                                WriteByte(0);
                            }
                            else
                            {
                                if (splits[j].Length > 79)
                                {
                                    Log.Error($"Book page {changed[i]} single line too LONG, total lenght -> {splits[j].Length} vs MAX 79 bytes allowed, some content might get lost");
                                    splits[j] = splits[j].Substring(0, 79);
                                }

                                WriteASCII(splits[j]);
                            }
                        }
                    }
                }
            }