Skip to content

Commit

Permalink
feat: allow single player games to be parsed successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
PBug90 committed Oct 20, 2018
1 parent 8cc7f53 commit c626119
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/W3GReplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ W3GReplay.prototype.createPlayerList = function () {
this.teams[slot.teamId] = this.teams[slot.teamId] || []
this.teams[slot.teamId].push(slot.playerId)
this.players[slot.playerId] =
new Player(slot.playerId, tempPlayers[slot.playerId].playerName, slot.teamId, slot.color, slot.raceFlag)
new Player(slot.playerId, tempPlayers[slot.playerId] ? tempPlayers[slot.playerId].playerName : 'Computer', slot.teamId, slot.color, slot.raceFlag)
}
})
}
Expand Down
23 changes: 18 additions & 5 deletions parsers/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const PlayerRecordLadder = new Parser()
.int32le('raceFlags', { formatter: raceFlagFormatter })

const PlayerRecord = new Parser()
.int8('recordId')
.int8('playerId')
.string('playerName', {zeroTerminated: true})
.uint8('addDataFlag')
Expand Down Expand Up @@ -76,18 +75,32 @@ const PlayerSlotRecord = new Parser()

const GameMetaData = new Parser()
.skip(4)
.skip(1)
.nest('player', {type: PlayerRecord})
.string('gameName', {zeroTerminated: true})
.skip(1)
.string('encodedString', {zeroTerminated: true, encoding: 'hex'})
.int32le('playerCount')
.string('gameType', {length: 4, encoding: 'hex'})
.string('languageId', {length: 4, encoding: 'hex'})
.array('playerList', {type: PlayerRecordInList,
.array('playerList', {
type: new Parser()
.int8('hasRecord')
.choice(null, {tag: 'hasRecord',
choices: {
0: new Parser(),
22: PlayerRecordInList
},
defaultChoice: new Parser()
}),
readUntil: function (item, buffer) {
return buffer.readInt8() !== 22
}})
.string('gameStartRecord', {length: 1, encoding: 'hex'})
return (buffer.readInt8() !== 22 && buffer.readInt8() !== 25) || item.hasRecord === 25
},
formatter: (input) => {
input.splice(-1, 1)
return input
}
})
.int16('dataByteCount')
.int8('slotRecordCount')
.array('playerSlotRecords', {type: PlayerSlotRecord, length: 'slotRecordCount'})
Expand Down

0 comments on commit c626119

Please sign in to comment.