Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs')
  2.  
  3. //const contents = fs.readFileSync(`bin/packetLog0xfb(8)`)
  4. const contents = fs.readFileSync(`packet_fb`)
  5.  
  6. let offset = 0
  7.  
  8. const packetByte = contents.readUInt8(offset).toString(16)
  9. offset += 1
  10. console.log(`packetByte: ${packetByte}`)
  11.  
  12. const qt = contents.readUInt16LE(offset)
  13. offset += 2
  14. console.log(`qt: ${qt}`)
  15.  
  16. const readString = () => {
  17.     const size = contents.readUInt16LE(offset)
  18.     //console.log(`readszie: ${size}`)
  19.     offset += 2
  20.     const string = contents.toString('utf8', offset, offset + size)
  21.     //console.log(`read: ${string}`)
  22.     offset += size
  23.     return string
  24. }
  25.  
  26. const readEntry = () => {
  27.     const name = readString()
  28.     const B1 = contents.readUInt8(offset)
  29.     const B2 = contents.readUInt8(offset+1)
  30.     offset += 2
  31.     const image = readString()
  32.     const parentName = readString()
  33.     console.log(`name: "${name}" B1: ${B1} B2: ${B2} image: "${image}" parentName: "${parentName}"`)
  34. }
  35.  
  36. const readDF = () => {
  37.     const byte = contents.readUInt8(offset).toString(16)
  38.     offset += 1
  39.     if (byte !== 'df') {
  40.         throw new Error(`read df called but first byte = ${byte}`)
  41.     }
  42.     const B = contents.readUInt8(offset)
  43.     offset += 1
  44.  
  45.     // i guess B = 1 -> update coins, 0 -> ignore
  46.  
  47.     const c0 = contents.readUInt32LE(offset)
  48.     offset += 4
  49.  
  50.     const c1 = contents.readUInt32LE(offset)
  51.     offset += 4
  52.  
  53.     console.log(`readDF => B: ${B} c0: ${c0} c1: ${c1}`)
  54. }
  55.  
  56. const readImage = () => {
  57.     const byte = contents.readUInt8(offset)
  58.     offset += 1
  59.     if (byte === 0) {
  60.         return readString()
  61.     } else if (byte === 3) {
  62.         let itemid = contents.readUInt16LE(offset)
  63.         offset += 2
  64.         return itemid
  65.     } else {
  66.         throw new Error(`unknown image type: ${byte}`)
  67.     }
  68. }
  69.  
  70. const readF2 = () => {
  71.     const byte = contents.readUInt8(offset).toString(16)
  72.     offset += 1
  73.     if (byte !== 'f2') {
  74.         throw new Error(`read f2 called but first byte = ${byte}`)
  75.     }
  76.  
  77.     const B = contents.readUInt8(offset)
  78.     offset += 1
  79.  
  80.     if (B === 1) {
  81.         console.log(`readF2 => B: ${B}`)
  82.         throw new Error('dont know what to do')
  83.     } else {
  84.         console.log(`readF2 => B: ${B}`)
  85.     }
  86. }
  87.  
  88. const readItem = () => {
  89.     const name = readString()
  90.  
  91.     const offers = []
  92.     const offerQt = contents.readUInt8(offset)
  93.     offset += 1
  94.  
  95.     for (let i = 0; i < offerQt; i++) {
  96.         const id = contents.readUInt32LE(offset)
  97.         offset += 4
  98.         const count = contents.readUInt16LE(offset)
  99.         offset += 2
  100.         const price = contents.readUInt32LE(offset)
  101.         offset += 4
  102.         const unknown = [contents.readUInt8(offset), contents.readUInt8(offset+1), contents.readUInt8(offset+2)]
  103.         offset += 3
  104.         let description
  105.         let unknownAfter
  106.         if (unknown[1] === 1 && unknown[2] === 1) {
  107.             description = readString()
  108.             unknownAfter = contents.readUInt8(offset)
  109.             offset += 1
  110.         }
  111.         offers.push({ id, count, price, unknown, description, unknownAfter })
  112.     }
  113.  
  114.  
  115.     //const  slabyte = contents.readUInt8(offset)
  116.     //offset += 1
  117.     //console.log(`slabyte: ${slabyte}`)
  118.  
  119.     //const description = readString()
  120.  
  121.     //const B0 = contents.readUInt8(offset)
  122.     let image = readImage()
  123.  
  124.     const B2 = contents.readUInt8(offset)
  125.     offset += 1
  126.  
  127.     //const unknownBytes3 = []
  128.     //for (let i = 0; i < 5; i++) {
  129.     //    unknownBytes3.push(contents.readUInt8(offset))
  130.     //    offset += 1
  131.     //}
  132.  
  133.     const subType = readString()
  134.  
  135.     const unknownBytes4 = []
  136.     for (let i = 0; i < 7; i++) {
  137.         unknownBytes4.push(contents.readUInt8(offset))
  138.         offset += 1
  139.     }
  140.  
  141.     const bundleSize = contents.readUInt16LE(offset)
  142.     offset += 2
  143.  
  144.     const bundle = []
  145.     for (let i = 0; i < bundleSize; i++) {
  146.         const name = readString()
  147.         const image = readImage()
  148.         bundle.push({ name, image })
  149.     }
  150.  
  151.     console.log(name, offers, `image: ${image}`, `B2: ${B2}`, `subType: ${subType}`, 'unknownBytes', unknownBytes4, bundle)    
  152. }
  153.  
  154. const readFC = () => {
  155.     const byte = contents.readUInt8(offset).toString(16)
  156.     offset += 1
  157.     if (byte !== 'fc') {
  158.         throw new Error(`read fc called but first byte = ${byte}`)
  159.     }
  160.    
  161.     const name = readString()
  162.  
  163.     const unknownBytes1 = []
  164.     for (let i = 0; i < 5; i++) {
  165.         unknownBytes1.push(contents.readUInt8(offset))
  166.         offset += 1
  167.     }
  168.  
  169.     const subTypes = []
  170.     const subQt = contents.readUInt8(offset)
  171.     offset += 1
  172.     for (let i = 0; i < subQt; i++) {
  173.         subTypes.push(readString())
  174.     }
  175.  
  176.     const unknownBytes2 = []
  177.     for (let i = 0; i < 2; i++) {
  178.         unknownBytes2.push(contents.readUInt8(offset))
  179.         offset += 1
  180.     }
  181.  
  182.     console.log(`readFC => name: ${name} unknownBytes1: [${unknownBytes1.join(', ')}] subTypes: [${subTypes.join(', ')}] unknownBytes2: [${unknownBytes2.join(', ')}]`)
  183.  
  184.     const itemQt = contents.readUInt16LE(offset)
  185.     offset += 2
  186.     for (let i = 0; i < itemQt; i++) {
  187.         readItem()
  188.     }
  189. }
  190.  
  191. const readBanner = () => {
  192.     const image = readString()
  193.     const B0 = contents.readUInt8(offset)
  194.     offset += 1
  195.     const category = readString()
  196.     const subType = readString()
  197.     const unknownBytes1 = []
  198.     for (let i = 0; i < 3; i++) {
  199.         unknownBytes1.push(contents.readUInt8(offset))
  200.         offset += 1
  201.     }
  202.     console.log(`banner Image: ${image} B0: ${B0} category: ${category} subType: ${subType} unknownBytes: [${unknownBytes1.join(', ')}]`)
  203. }
  204.  
  205. const readBanners = () => {
  206.     const bannerQt = contents.readUInt8(offset)
  207.     offset += 1
  208.     for (let i = 0; i < bannerQt; i++) {
  209.         readBanner()
  210.     }
  211. }
  212.  
  213. for (let i = 0; i < qt; i++) {
  214.     readEntry()
  215. }
  216.  
  217. readDF()
  218. readF2()
  219. readFC()
  220. readBanners()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement