cheatengine 5.8.20 → 5.8.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/pipe-client.js +45 -23
package/package.json
CHANGED
package/src/pipe-client.js
CHANGED
|
@@ -86,30 +86,32 @@ class PipeClient extends EventEmitter {
|
|
|
86
86
|
_handleData(data) {
|
|
87
87
|
this.responseBuffer = Buffer.concat([this.responseBuffer, data]);
|
|
88
88
|
|
|
89
|
-
// Try to parse response
|
|
90
|
-
if (this.pendingResponse
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
// Try to parse response only if we have a pending request
|
|
90
|
+
if (!this.pendingResponse || this.responseBuffer.length < 4) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const respLen = this.responseBuffer.readUInt32LE(0);
|
|
95
|
+
|
|
96
|
+
if (respLen === 0 || respLen > Config.MAX_RESPONSE_SIZE) {
|
|
97
|
+
this.pendingResponse.reject(new Error(`Invalid response size: ${respLen}`));
|
|
98
|
+
this.pendingResponse = null;
|
|
99
|
+
this.responseBuffer = Buffer.alloc(0);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
this.pendingResponse = null;
|
|
103
|
+
if (this.responseBuffer.length >= 4 + respLen) {
|
|
104
|
+
const respData = this.responseBuffer.slice(4, 4 + respLen);
|
|
105
|
+
this.responseBuffer = this.responseBuffer.slice(4 + respLen);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const decoded = this._decodeResponse(respData);
|
|
109
|
+
const result = JSON.parse(decoded);
|
|
110
|
+
this.pendingResponse.resolve(result);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
this.pendingResponse.reject(err);
|
|
112
113
|
}
|
|
114
|
+
this.pendingResponse = null;
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
|
|
@@ -258,7 +260,27 @@ class PipeClient extends EventEmitter {
|
|
|
258
260
|
_waitForResponse() {
|
|
259
261
|
return new Promise((resolve, reject) => {
|
|
260
262
|
this.pendingResponse = { resolve, reject };
|
|
261
|
-
|
|
263
|
+
|
|
264
|
+
// Check if we already have data in buffer (race condition fix)
|
|
265
|
+
if (this.responseBuffer.length >= 4) {
|
|
266
|
+
const respLen = this.responseBuffer.readUInt32LE(0);
|
|
267
|
+
if (respLen > 0 && respLen <= Config.MAX_RESPONSE_SIZE && this.responseBuffer.length >= 4 + respLen) {
|
|
268
|
+
const respData = this.responseBuffer.slice(4, 4 + respLen);
|
|
269
|
+
this.responseBuffer = this.responseBuffer.slice(4 + respLen);
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
const decoded = this._decodeResponse(respData);
|
|
273
|
+
const result = JSON.parse(decoded);
|
|
274
|
+
this.pendingResponse = null;
|
|
275
|
+
resolve(result);
|
|
276
|
+
return;
|
|
277
|
+
} catch (err) {
|
|
278
|
+
this.pendingResponse = null;
|
|
279
|
+
reject(err);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
262
284
|
});
|
|
263
285
|
}
|
|
264
286
|
|