From a8b7cad002a2a45dad152bbf34572ba640f30f6c Mon Sep 17 00:00:00 2001 From: Michael Morrison Date: Fri, 9 Jul 2021 02:23:36 -0500 Subject: [PATCH] Fix corrupted dayzMods when packet overflow is used (3.0.7) --- CHANGELOG.md | 3 +++ package.json | 2 +- protocols/valve.js | 35 ++++++++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e53523..1e9b9f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### 3.0.7 +* Fixes corrupted dayzMods when packet overflow is present + ### 3.0.6 * raw.tags for valve servers is now an array rather than a string * The special mod list for dayz servers is now parsed into raw.dayzMods is requestRules is set to true diff --git a/package.json b/package.json index a28a807..fa901e8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "main": "lib/index.js", "author": "GameDig Contributors", - "version": "3.0.6", + "version": "3.0.7", "repository": { "type": "git", "url": "https://github.com/gamedig/node-gamedig.git" diff --git a/protocols/valve.js b/protocols/valve.js index 19919e1..f82803c 100644 --- a/protocols/valve.js +++ b/protocols/valve.js @@ -298,7 +298,14 @@ class Valve extends Core { this.logger.debug(buffer); const reader = this.reader(buffer); - reader.skip(8); // always 01 01 01 02 01 02 01 02 + const version = this.readDayzByte(reader); + const overflow = this.readDayzByte(reader); + const dlc1 = this.readDayzByte(reader); + const dlc2 = this.readDayzByte(reader); + this.logger.debug("version " + version); + this.logger.debug("overflow " + overflow); + this.logger.debug("dlc1 " + dlc1); + this.logger.debug("dlc2 " + dlc2); const mods = []; mods.push(...this.readDayzModsSection(reader, true)); mods.push(...this.readDayzModsSection(reader, false)); @@ -306,30 +313,31 @@ class Valve extends Core { } readDayzModsSection(reader, withHeader) { const out = []; - const count = reader.uint(1); + const count = this.readDayzByte(reader); for(let i = 0; i < count; i++) { const mod = {}; if (withHeader) { - mod.unknown = this.readDayzNum(reader); + const unknown = this.readDayzUint(reader, 4); // mod hash? if (i !== count - 1) { // For some reason this is 4 on all of them, but doesn't exist on the last one? - reader.skip(1); + const flag = this.readDayzByte(reader); + //mod.flag = flag; } - mod.workshopId = this.readDayzNum(reader); + mod.workshopId = this.readDayzUint(reader, 4); } - mod.title = reader.pascalString(1); + mod.title = this.readDayzString(reader); out.push(mod); } return out; } - readDayzNum(reader) { + readDayzUint(reader, bytes) { const out = []; - for (let i = 0; i < 4; i++) { + for (let i = 0; i < bytes; i++) { out.push(this.readDayzByte(reader)); } const buf = Buffer.from(out); const r2 = this.reader(buf); - return r2.uint(4); + return r2.uint(bytes); } readDayzByte(reader) { const byte = reader.uint(1); @@ -337,10 +345,19 @@ class Valve extends Core { const byte2 = reader.uint(1); if (byte2 === 1) return 1; if (byte2 === 2) return 0; + if (byte2 === 3) return 0xff; return 0; // ? } return byte; } + readDayzString(reader) { + const length = this.readDayzByte(reader); + const out = []; + for (let i = 0; i < length; i++) { + out.push(this.readDayzByte(reader)); + } + return Buffer.from(out).toString('utf8'); + } async cleanup(/** Results */ state) { // Organize players / hidden players into player / bot arrays