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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/pipe-client.js +45 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cheatengine",
3
- "version": "5.8.20",
3
+ "version": "5.8.21",
4
4
  "description": "Cheat Engine MCP Server - AI-assisted reverse engineering bridge",
5
5
  "main": "ce_mcp_server.js",
6
6
  "bin": {
@@ -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 && this.responseBuffer.length >= 4) {
91
- const respLen = this.responseBuffer.readUInt32LE(0);
92
-
93
- if (respLen === 0 || respLen > Config.MAX_RESPONSE_SIZE) {
94
- this.pendingResponse.reject(new Error(`Invalid response size: ${respLen}`));
95
- this.pendingResponse = null;
96
- this.responseBuffer = Buffer.alloc(0);
97
- return;
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
- if (this.responseBuffer.length >= 4 + respLen) {
101
- const respData = this.responseBuffer.slice(4, 4 + respLen);
102
- this.responseBuffer = this.responseBuffer.slice(4 + respLen);
103
-
104
- try {
105
- const decoded = this._decodeResponse(respData);
106
- const result = JSON.parse(decoded);
107
- this.pendingResponse.resolve(result);
108
- } catch (err) {
109
- this.pendingResponse.reject(err);
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
- this.responseBuffer = Buffer.alloc(0);
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