Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs')
- //const contents = fs.readFileSync(`bin/packetLog0xfb(8)`)
- const contents = fs.readFileSync(`packet_fb`)
- let offset = 0
- const packetByte = contents.readUInt8(offset).toString(16)
- offset += 1
- console.log(`packetByte: ${packetByte}`)
- const qt = contents.readUInt16LE(offset)
- offset += 2
- console.log(`qt: ${qt}`)
- const readString = () => {
- const size = contents.readUInt16LE(offset)
- //console.log(`readszie: ${size}`)
- offset += 2
- const string = contents.toString('utf8', offset, offset + size)
- //console.log(`read: ${string}`)
- offset += size
- return string
- }
- const readEntry = () => {
- const name = readString()
- const B1 = contents.readUInt8(offset)
- const B2 = contents.readUInt8(offset+1)
- offset += 2
- const image = readString()
- const parentName = readString()
- console.log(`name: "${name}" B1: ${B1} B2: ${B2} image: "${image}" parentName: "${parentName}"`)
- }
- const readDF = () => {
- const byte = contents.readUInt8(offset).toString(16)
- offset += 1
- if (byte !== 'df') {
- throw new Error(`read df called but first byte = ${byte}`)
- }
- const B = contents.readUInt8(offset)
- offset += 1
- // i guess B = 1 -> update coins, 0 -> ignore
- const c0 = contents.readUInt32LE(offset)
- offset += 4
- const c1 = contents.readUInt32LE(offset)
- offset += 4
- console.log(`readDF => B: ${B} c0: ${c0} c1: ${c1}`)
- }
- const readImage = () => {
- const byte = contents.readUInt8(offset)
- offset += 1
- if (byte === 0) {
- return readString()
- } else if (byte === 3) {
- let itemid = contents.readUInt16LE(offset)
- offset += 2
- return itemid
- } else {
- throw new Error(`unknown image type: ${byte}`)
- }
- }
- const readF2 = () => {
- const byte = contents.readUInt8(offset).toString(16)
- offset += 1
- if (byte !== 'f2') {
- throw new Error(`read f2 called but first byte = ${byte}`)
- }
- const B = contents.readUInt8(offset)
- offset += 1
- if (B === 1) {
- console.log(`readF2 => B: ${B}`)
- throw new Error('dont know what to do')
- } else {
- console.log(`readF2 => B: ${B}`)
- }
- }
- const readItem = () => {
- const name = readString()
- const offers = []
- const offerQt = contents.readUInt8(offset)
- offset += 1
- for (let i = 0; i < offerQt; i++) {
- const id = contents.readUInt32LE(offset)
- offset += 4
- const count = contents.readUInt16LE(offset)
- offset += 2
- const price = contents.readUInt32LE(offset)
- offset += 4
- const unknown = [contents.readUInt8(offset), contents.readUInt8(offset+1), contents.readUInt8(offset+2)]
- offset += 3
- let description
- let unknownAfter
- if (unknown[1] === 1 && unknown[2] === 1) {
- description = readString()
- unknownAfter = contents.readUInt8(offset)
- offset += 1
- }
- offers.push({ id, count, price, unknown, description, unknownAfter })
- }
- //const slabyte = contents.readUInt8(offset)
- //offset += 1
- //console.log(`slabyte: ${slabyte}`)
- //const description = readString()
- //const B0 = contents.readUInt8(offset)
- let image = readImage()
- const B2 = contents.readUInt8(offset)
- offset += 1
- //const unknownBytes3 = []
- //for (let i = 0; i < 5; i++) {
- // unknownBytes3.push(contents.readUInt8(offset))
- // offset += 1
- //}
- const subType = readString()
- const unknownBytes4 = []
- for (let i = 0; i < 7; i++) {
- unknownBytes4.push(contents.readUInt8(offset))
- offset += 1
- }
- const bundleSize = contents.readUInt16LE(offset)
- offset += 2
- const bundle = []
- for (let i = 0; i < bundleSize; i++) {
- const name = readString()
- const image = readImage()
- bundle.push({ name, image })
- }
- console.log(name, offers, `image: ${image}`, `B2: ${B2}`, `subType: ${subType}`, 'unknownBytes', unknownBytes4, bundle)
- }
- const readFC = () => {
- const byte = contents.readUInt8(offset).toString(16)
- offset += 1
- if (byte !== 'fc') {
- throw new Error(`read fc called but first byte = ${byte}`)
- }
- const name = readString()
- const unknownBytes1 = []
- for (let i = 0; i < 5; i++) {
- unknownBytes1.push(contents.readUInt8(offset))
- offset += 1
- }
- const subTypes = []
- const subQt = contents.readUInt8(offset)
- offset += 1
- for (let i = 0; i < subQt; i++) {
- subTypes.push(readString())
- }
- const unknownBytes2 = []
- for (let i = 0; i < 2; i++) {
- unknownBytes2.push(contents.readUInt8(offset))
- offset += 1
- }
- console.log(`readFC => name: ${name} unknownBytes1: [${unknownBytes1.join(', ')}] subTypes: [${subTypes.join(', ')}] unknownBytes2: [${unknownBytes2.join(', ')}]`)
- const itemQt = contents.readUInt16LE(offset)
- offset += 2
- for (let i = 0; i < itemQt; i++) {
- readItem()
- }
- }
- const readBanner = () => {
- const image = readString()
- const B0 = contents.readUInt8(offset)
- offset += 1
- const category = readString()
- const subType = readString()
- const unknownBytes1 = []
- for (let i = 0; i < 3; i++) {
- unknownBytes1.push(contents.readUInt8(offset))
- offset += 1
- }
- console.log(`banner Image: ${image} B0: ${B0} category: ${category} subType: ${subType} unknownBytes: [${unknownBytes1.join(', ')}]`)
- }
- const readBanners = () => {
- const bannerQt = contents.readUInt8(offset)
- offset += 1
- for (let i = 0; i < bannerQt; i++) {
- readBanner()
- }
- }
- for (let i = 0; i < qt; i++) {
- readEntry()
- }
- readDF()
- readF2()
- readFC()
- readBanners()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement