mirror of
https://github.com/djhackersdev/minime.git
synced 2026-08-27 21:14:00 -05:00
Aimedb: Adjust deframe/decode responsibility split
This commit is contained in:
@@ -10,20 +10,20 @@ class Decoder extends Transform {
|
||||
}
|
||||
|
||||
static ident(payload) {
|
||||
const gameId = payload.toString('ascii', 2, 6)
|
||||
const keychipId = payload.toString('ascii', 12, 23)
|
||||
const gameId = payload.toString('ascii', 0x000A, 0x000E)
|
||||
const keychipId = payload.toString('ascii', 0x0014, 0x001F)
|
||||
|
||||
return { gameId, keychipId }
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
const { cmd, payload } = chunk
|
||||
const cmd = chunk.readUInt16LE(0x04)
|
||||
|
||||
switch (cmd) {
|
||||
case 0x0064:
|
||||
return callback(null, {
|
||||
cmd: 'hello',
|
||||
...Decoder.ident(payload)
|
||||
...Decoder.ident(chunk)
|
||||
})
|
||||
|
||||
case 0x0066:
|
||||
|
||||
@@ -17,26 +17,25 @@ class Deframer extends Transform {
|
||||
return
|
||||
}
|
||||
|
||||
const magic = this.state.readUInt16LE(0)
|
||||
const magic = this.state.readUInt16LE(0x0000)
|
||||
|
||||
if (magic != 0xA13E) {
|
||||
return callback(new Error(`Invalid magic (decimal ${magic})`))
|
||||
}
|
||||
|
||||
const len = this.state.readUInt16LE(6)
|
||||
const len = this.state.readUInt16LE(0x0006)
|
||||
|
||||
if (this.state.length < len) {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Aimedb: Recv', this.state)
|
||||
const frame = this.state.slice(0, len)
|
||||
|
||||
const cmd = this.state.readUInt16LE(4)
|
||||
const payload = this.state.slice(8, len)
|
||||
console.log('Aimedb: Recv', frame)
|
||||
|
||||
this.state = this.state.slice(len)
|
||||
|
||||
return callback(null, { cmd, payload })
|
||||
return callback(null, frame)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user