void ReadHeader(bool randomPrice = true) { BinaryReader reader = bookFile.GetReader(); header = new BookHeader(); header.Title = FileProxy.ReadCStringSkip(reader, 0, 64); header.Author = FileProxy.ReadCStringSkip(reader, 0, 64); header.IsNaughty = (FileProxy.ReadCStringSkip(reader, 0, 8) == naughty); header.NullValues = reader.ReadBytes(88); header.Price = reader.ReadUInt32(); header.Unknown1 = reader.ReadUInt16(); header.Unknown2 = reader.ReadUInt16(); header.Unknown3 = reader.ReadUInt16(); header.PageCount = reader.ReadUInt16(); header.PageOffsets = new UInt32[header.PageCount]; for (int i = 0; i < header.PageCount; i++) { header.PageOffsets[i] = reader.ReadUInt32(); } if (randomPrice) { // Overwrite price field using random seeded with first 4 bytes. // (See https://forums.dfworkshop.net/viewtopic.php?f=23&t=1576) reader.BaseStream.Position = 0; DFRandom.Seed = reader.ReadUInt32(); // first 4 bytes of book file as a uint header.Price = (uint)DFRandom.random_range_inclusive(300, 800); } }
public MinibookMessage Parse(string message) { BookHeader msg = null; string[] columns = message.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string stock = columns[INDEX_STOCK]; switch (columns[INDEX_COMMAND]) { case ADD_COMMAND: return(new MinibookMessage(stock, CreateBookAdd(columns, stock))); case UPDATE_COMMAND: return(new MinibookMessage(stock, CreateBookUpdate(columns, stock))); case CANCEL_COMMAND: return(new MinibookMessage(stock, CreateBookDelete(columns, stock))); case ERROR_COMMAND: return(new MinibookMessage(stock, CreateBookError(columns, stock))); } return(new MinibookMessage(stock, msg)); }
private void UpdateTables(TimePacket packet) { if (packet.Packet is WorldItem) { WorldItem item = (WorldItem)packet.Packet; m_Items[item.Serial] = packet.Packet; if (m_Books[item.Serial] != null) { ((BookInfo)m_Books[item.Serial]).Item = item; } } else if (packet.Packet is BookHeader) { BookHeader header = (BookHeader)packet.Packet; if (m_Books[header.Serial] != null) { BookInfo book = (BookInfo)m_Books[header.Serial]; book.Title = header.Title; book.Author = header.Author; book.Writable = header.Writable; if (book.Lines.Length != header.PagesCount) { book.Lines = new string[header.PagesCount][]; } } else { BookInfo book = new BookInfo(header.Serial, header.Title, header.Author, header.Writable, header.PagesCount); if (m_Items[book.Serial] != null) { book.Item = (WorldItem)m_Items[book.Serial]; } m_Books[book.Serial] = book; } } else if (packet.Packet is BookPageDetails) { BookPageDetails details = (BookPageDetails)packet.Packet; if (m_Books[details.Serial] != null) { BookInfo book = (BookInfo)m_Books[details.Serial]; for (int i = 0; i < details.Pages.Length; i++) { if (!details.Pages[i].Request && details.Pages[i].Index - 1 < book.Lines.Length) { book.Lines[details.Pages[i].Index - 1] = details.Pages[i].Lines; } } } } }
void ReadHeader() { BinaryReader reader = bookFile.GetReader(); header = new BookHeader(); header.Title = bookFile.ReadCStringSkip(reader, 0, 64); header.Author = bookFile.ReadCStringSkip(reader, 0, 64); header.IsNaughty = (bookFile.ReadCStringSkip(reader, 0, 8) == naughty); header.NullValues = reader.ReadBytes(88); header.Price = reader.ReadUInt32(); header.Unknown1 = reader.ReadUInt16(); header.Unknown2 = reader.ReadUInt16(); header.Unknown3 = reader.ReadUInt16(); header.PageCount = reader.ReadUInt16(); header.PageOffsets = new UInt32[header.PageCount]; for (int i = 0; i < header.PageCount; i++) { header.PageOffsets[i] = reader.ReadUInt32(); } }
public void TestBookCover(string author, string title) { var m = new Mobile(0x1); m.DefaultMobileInit(); var book = new BlueBook { Author = author, Title = title }; var expected = new BookHeader(m, book).Compile(); var ns = PacketTestUtilities.CreateTestNetState(); ns.SendBookCover(m, book); var result = ns.SendPipe.Reader.TryRead(); AssertThat.Equal(result.Buffer[0].AsSpan(0), expected); }
void ReadHeader() { BinaryReader reader = bookFile.GetReader(); header = new BookHeader(); header.Title = bookFile.ReadCStringSkip(reader, 0, 64); header.Author = bookFile.ReadCStringSkip(reader, 0, 64); header.IsNaughty = (bookFile.ReadCStringSkip(reader, 0, 8) == naughty); header.NullValues = reader.ReadBytes(88); header.Price = reader.ReadUInt32(); header.Unknown1 = reader.ReadUInt16(); header.Unknown2 = reader.ReadUInt16(); header.Unknown3 = reader.ReadUInt16(); header.PageCount = reader.ReadUInt16(); header.PageOffsets = new UInt32[header.PageCount]; for (int i = 0; i < header.PageCount; i++) { header.PageOffsets[i] = reader.ReadUInt32(); } }