@openmouse/protocol 0.29.0 → 0.31.0
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/dist/ajazz/ak820.d.ts +35 -0
- package/dist/ajazz/ak820.d.ts.map +1 -0
- package/dist/ajazz/ak820.js +44 -0
- package/dist/ajazz/ak820.js.map +1 -0
- package/dist/asus/devices.d.ts +2 -4
- package/dist/asus/devices.d.ts.map +1 -1
- package/dist/asus/devices.js +2 -4
- package/dist/asus/devices.js.map +1 -1
- package/dist/asus/index.d.ts +4 -2
- package/dist/asus/index.d.ts.map +1 -1
- package/dist/asus/index.js +15 -7
- package/dist/asus/index.js.map +1 -1
- package/dist/asus/omni.d.ts +49 -0
- package/dist/asus/omni.d.ts.map +1 -0
- package/dist/asus/omni.js +95 -0
- package/dist/asus/omni.js.map +1 -0
- package/dist/atk/index.d.ts +10 -3
- package/dist/atk/index.d.ts.map +1 -1
- package/dist/atk/index.js +59 -4
- package/dist/atk/index.js.map +1 -1
- package/dist/drivers/ajazz/ak820-hid.d.ts +48 -0
- package/dist/drivers/ajazz/ak820-hid.d.ts.map +1 -0
- package/dist/drivers/ajazz/ak820-hid.js +99 -0
- package/dist/drivers/ajazz/ak820-hid.js.map +1 -0
- package/dist/drivers/asus/hid.d.ts +22 -2
- package/dist/drivers/asus/hid.d.ts.map +1 -1
- package/dist/drivers/asus/hid.js +139 -24
- package/dist/drivers/asus/hid.js.map +1 -1
- package/dist/drivers/atk/device-catalog.generated.d.ts +57 -0
- package/dist/drivers/atk/device-catalog.generated.d.ts.map +1 -0
- package/dist/drivers/atk/device-catalog.generated.js +2436 -0
- package/dist/drivers/atk/device-catalog.generated.js.map +1 -0
- package/dist/drivers/atk/hid.d.ts +30 -0
- package/dist/drivers/atk/hid.d.ts.map +1 -1
- package/dist/drivers/atk/hid.js +98 -21
- package/dist/drivers/atk/hid.js.map +1 -1
- package/dist/drivers/atk/products.d.ts +13 -0
- package/dist/drivers/atk/products.d.ts.map +1 -1
- package/dist/drivers/atk/products.js +32 -0
- package/dist/drivers/atk/products.js.map +1 -1
- package/dist/drivers/finalmouse/hid.d.ts +49 -0
- package/dist/drivers/finalmouse/hid.d.ts.map +1 -1
- package/dist/drivers/finalmouse/hid.js +234 -22
- package/dist/drivers/finalmouse/hid.js.map +1 -1
- package/dist/drivers/glorious/core2-hid.d.ts +56 -0
- package/dist/drivers/glorious/core2-hid.d.ts.map +1 -0
- package/dist/drivers/glorious/core2-hid.js +344 -0
- package/dist/drivers/glorious/core2-hid.js.map +1 -0
- package/dist/drivers/logitech/dfu.d.ts +118 -0
- package/dist/drivers/logitech/dfu.d.ts.map +1 -0
- package/dist/drivers/logitech/dfu.js +216 -0
- package/dist/drivers/logitech/dfu.js.map +1 -0
- package/dist/drivers/logitech/hidpp.d.ts +20 -0
- package/dist/drivers/logitech/hidpp.d.ts.map +1 -1
- package/dist/drivers/logitech/hidpp.js +79 -0
- package/dist/drivers/logitech/hidpp.js.map +1 -1
- package/dist/drivers/mouse-types.d.ts +68 -1
- package/dist/drivers/mouse-types.d.ts.map +1 -1
- package/dist/drivers/pulsar/pulsar-xs1-hid.d.ts.map +1 -1
- package/dist/drivers/pulsar/pulsar-xs1-hid.js +23 -10
- package/dist/drivers/pulsar/pulsar-xs1-hid.js.map +1 -1
- package/dist/drivers/razer/hid.d.ts +6 -0
- package/dist/drivers/razer/hid.d.ts.map +1 -1
- package/dist/drivers/razer/hid.js +63 -2
- package/dist/drivers/razer/hid.js.map +1 -1
- package/dist/drivers/registry.d.ts +3 -1
- package/dist/drivers/registry.d.ts.map +1 -1
- package/dist/drivers/registry.js +5 -0
- package/dist/drivers/registry.js.map +1 -1
- package/dist/drivers/vendors.d.ts +20 -1
- package/dist/drivers/vendors.d.ts.map +1 -1
- package/dist/drivers/vendors.js +51 -10
- package/dist/drivers/vendors.js.map +1 -1
- package/dist/drivers/wallhack/mouse-hid.d.ts +56 -0
- package/dist/drivers/wallhack/mouse-hid.d.ts.map +1 -1
- package/dist/drivers/wallhack/mouse-hid.js +249 -13
- package/dist/drivers/wallhack/mouse-hid.js.map +1 -1
- package/dist/finalmouse/index.d.ts +162 -1
- package/dist/finalmouse/index.d.ts.map +1 -1
- package/dist/finalmouse/index.js +310 -2
- package/dist/finalmouse/index.js.map +1 -1
- package/dist/glorious-core2/index.d.ts +174 -0
- package/dist/glorious-core2/index.d.ts.map +1 -0
- package/dist/glorious-core2/index.js +266 -0
- package/dist/glorious-core2/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/razer/codec.d.ts +9 -0
- package/dist/razer/codec.d.ts.map +1 -1
- package/dist/razer/codec.js +25 -0
- package/dist/razer/codec.js.map +1 -1
- package/dist/razer/devices.d.ts +2 -0
- package/dist/razer/devices.d.ts.map +1 -1
- package/dist/razer/devices.js +1 -1
- package/dist/razer/devices.js.map +1 -1
- package/dist/wallhack/index.d.ts +240 -0
- package/dist/wallhack/index.d.ts.map +1 -1
- package/dist/wallhack/index.js +670 -0
- package/dist/wallhack/index.js.map +1 -1
- package/package.json +6 -2
package/dist/wallhack/index.js
CHANGED
|
@@ -78,6 +78,9 @@ export const WALLHACK_FLASH = {
|
|
|
78
78
|
turnOffAutomaticSleep: 114,
|
|
79
79
|
angleTuneValue: 115,
|
|
80
80
|
gameMode: 116,
|
|
81
|
+
dynamicDpiEnable: 117,
|
|
82
|
+
dynamicDpiMode: 118,
|
|
83
|
+
dynamicDpiCoordinateReportEnable: 119,
|
|
81
84
|
};
|
|
82
85
|
/** Polling-rate rank → Hz (`Z1`). Same table for wired and wireless. */
|
|
83
86
|
export const WALLHACK_POLLING_BY_RANK = {
|
|
@@ -114,6 +117,51 @@ export function wallhackLodFromCode(code) {
|
|
|
114
117
|
export function wallhackLodToCode(lod) {
|
|
115
118
|
return lod === "Low" ? 0 : lod === "Medium" ? 1 : 2;
|
|
116
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Sensor-rotation encoding (`z7`/`mB`): the `angleTuneValue` byte stores
|
|
122
|
+
* degrees + 30, so 30 means straight and the range 0-60 maps to -30..+30.
|
|
123
|
+
*/
|
|
124
|
+
export const WALLHACK_SENSOR_ANGLE_CENTER = 30;
|
|
125
|
+
export const WALLHACK_SENSOR_ANGLE_MIN = -30;
|
|
126
|
+
export const WALLHACK_SENSOR_ANGLE_MAX = 30;
|
|
127
|
+
/** Raw `angleTuneValue` byte → degrees, or null when outside 0-60. */
|
|
128
|
+
export function wallhackRawToSensorAngle(raw) {
|
|
129
|
+
const degrees = raw - WALLHACK_SENSOR_ANGLE_CENTER;
|
|
130
|
+
if (!Number.isInteger(raw) || degrees < WALLHACK_SENSOR_ANGLE_MIN || degrees > WALLHACK_SENSOR_ANGLE_MAX) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return degrees;
|
|
134
|
+
}
|
|
135
|
+
/** Degrees (-30..+30) → raw `angleTuneValue` byte. Throws outside the range. */
|
|
136
|
+
export function wallhackSensorAngleToRaw(degrees) {
|
|
137
|
+
if (!Number.isInteger(degrees) || degrees < WALLHACK_SENSOR_ANGLE_MIN || degrees > WALLHACK_SENSOR_ANGLE_MAX) {
|
|
138
|
+
throw new Error(`WALLHACK sensor angle must be a whole number of degrees in -30..+30, got ${degrees}.`);
|
|
139
|
+
}
|
|
140
|
+
return degrees + WALLHACK_SENSOR_ANGLE_CENTER;
|
|
141
|
+
}
|
|
142
|
+
export function wallhackScanningModeFromByte(value) {
|
|
143
|
+
if (value === 0)
|
|
144
|
+
return "HIGH";
|
|
145
|
+
if (value === 1)
|
|
146
|
+
return "ACCEL";
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
export function wallhackScanningModeToByte(mode) {
|
|
150
|
+
return mode === "ACCEL" ? 1 : 0;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Minimum mouse-Nordic firmware triples (mouse/dongle/nxp5516) the vendor app
|
|
154
|
+
* gates features behind (`W7`). The M-001 demo reports V1.17.0-era versions;
|
|
155
|
+
* anything older answers these areas with noise or a status error.
|
|
156
|
+
*/
|
|
157
|
+
export const WALLHACK_MIN_FIRMWARE = {
|
|
158
|
+
customSleepTimer: { mouse: 51, dongle: 36, nxp5516: 48 },
|
|
159
|
+
sensorScanning: { mouse: 52, dongle: 36, nxp5516: 48 },
|
|
160
|
+
buttonMapping: { mouse: 53, dongle: 37, nxp5516: 52 },
|
|
161
|
+
sensorRotation: { mouse: 53, dongle: 37, nxp5516: 52 },
|
|
162
|
+
macros: { mouse: 57, dongle: 40, nxp5516: 53 },
|
|
163
|
+
dynamicSensitivity: { mouse: 57, dongle: 40, nxp5516: 53 },
|
|
164
|
+
};
|
|
117
165
|
/** Human-facing product name for a device by product id. */
|
|
118
166
|
export function wallhackMouseName(_productId) {
|
|
119
167
|
return "WALLHACK M-001";
|
|
@@ -223,4 +271,626 @@ export function wallhackDecodeBattery(response) {
|
|
|
223
271
|
const percent = raw >= 0 && raw <= 100 ? raw : null;
|
|
224
272
|
return { percent, charging: response[8] === 1 };
|
|
225
273
|
}
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
// Dynamic sensitivity (DPI acceleration) curves
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
/**
|
|
278
|
+
* DPI-acceleration curves (`dynamicSensitivity` in the app). Every curve has
|
|
279
|
+
* exactly 5 points; X is cursor speed in sensor counts/ms (whole numbers
|
|
280
|
+
* 0-280, strictly increasing) and Y is the gain multiplier (a multiple of
|
|
281
|
+
* 0.01 in 0.10-6.00). Preset tables live at their own function-area
|
|
282
|
+
* addresses and pack one point into 2 bytes (`speed u8, gain*100 u8`); the
|
|
283
|
+
* custom table packs one point into 4 bytes (u16LE speed, u16LE gain*100).
|
|
284
|
+
* Curve replies carry a status code at byte 6: 0 is OK.
|
|
285
|
+
*/
|
|
286
|
+
export const WALLHACK_CURVE_POINT_COUNT = 5;
|
|
287
|
+
export const WALLHACK_CURVE_SPEED_MAX = 280;
|
|
288
|
+
export const WALLHACK_CURVE_GAIN_MIN = 0.1;
|
|
289
|
+
export const WALLHACK_CURVE_GAIN_MAX = 6.0;
|
|
290
|
+
export const WALLHACK_CURVE_GAIN_STEP = 0.01;
|
|
291
|
+
export const WALLHACK_CURVE_ADDRESS = {
|
|
292
|
+
classic: 640,
|
|
293
|
+
natural: 650,
|
|
294
|
+
jump: 660,
|
|
295
|
+
custom: 670,
|
|
296
|
+
};
|
|
297
|
+
export const WALLHACK_CURVE_MODE_INDEX = {
|
|
298
|
+
classic: 0,
|
|
299
|
+
natural: 1,
|
|
300
|
+
jump: 2,
|
|
301
|
+
custom: 3,
|
|
302
|
+
};
|
|
303
|
+
export const WALLHACK_CURVE_PRESETS = {
|
|
304
|
+
classic: [
|
|
305
|
+
{ speed: 0, gain: 1 }, { speed: 20, gain: 1.1 }, { speed: 40, gain: 1.2 },
|
|
306
|
+
{ speed: 70, gain: 1.35 }, { speed: 100, gain: 1.5 },
|
|
307
|
+
],
|
|
308
|
+
natural: [
|
|
309
|
+
{ speed: 0, gain: 1 }, { speed: 11, gain: 1.45 }, { speed: 20, gain: 1.5 },
|
|
310
|
+
{ speed: 35, gain: 1.5 }, { speed: 100, gain: 1.5 },
|
|
311
|
+
],
|
|
312
|
+
jump: [
|
|
313
|
+
{ speed: 0, gain: 1 }, { speed: 9, gain: 1 }, { speed: 21, gain: 1.5 },
|
|
314
|
+
{ speed: 24, gain: 1.5 }, { speed: 100, gain: 1.5 },
|
|
315
|
+
],
|
|
316
|
+
custom: [
|
|
317
|
+
{ speed: 0, gain: 1 }, { speed: 70, gain: 1 }, { speed: 140, gain: 1 },
|
|
318
|
+
{ speed: 210, gain: 1 }, { speed: 280, gain: 1 },
|
|
319
|
+
],
|
|
320
|
+
};
|
|
321
|
+
/** Validate curve points; returns an error string or null when valid. */
|
|
322
|
+
export function wallhackValidateCurve(points) {
|
|
323
|
+
if (points.length !== WALLHACK_CURVE_POINT_COUNT) {
|
|
324
|
+
return `a curve has exactly ${WALLHACK_CURVE_POINT_COUNT} points`;
|
|
325
|
+
}
|
|
326
|
+
let previous = -1;
|
|
327
|
+
for (const [index, point] of points.entries()) {
|
|
328
|
+
if (!Number.isInteger(point.speed) || point.speed < 0 || point.speed > WALLHACK_CURVE_SPEED_MAX) {
|
|
329
|
+
return `point ${index} speed must be a whole number in 0..${WALLHACK_CURVE_SPEED_MAX}`;
|
|
330
|
+
}
|
|
331
|
+
if (point.speed <= previous)
|
|
332
|
+
return "speeds must be strictly increasing";
|
|
333
|
+
previous = point.speed;
|
|
334
|
+
const hundredths = Math.round(point.gain * 100);
|
|
335
|
+
if (Number.isNaN(point.gain) ||
|
|
336
|
+
Math.abs(point.gain * 100 - hundredths) > 1e-6 ||
|
|
337
|
+
hundredths < WALLHACK_CURVE_GAIN_MIN * 100 ||
|
|
338
|
+
hundredths > WALLHACK_CURVE_GAIN_MAX * 100) {
|
|
339
|
+
return `point ${index} gain must be a multiple of 0.01 in 0.10..6.00`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
/** Read packet for a curve table: preset tables read 10 bytes, custom 20. */
|
|
345
|
+
export function wallhackBuildCurveRead(mode) {
|
|
346
|
+
return wallhackBuildRead(WALLHACK_CURVE_ADDRESS[mode], mode === "custom" ? 20 : 10);
|
|
347
|
+
}
|
|
348
|
+
/** Write packet for the custom curve table (20-byte payload). Throws when invalid. */
|
|
349
|
+
export function wallhackBuildCustomCurveWrite(points) {
|
|
350
|
+
const error = wallhackValidateCurve(points);
|
|
351
|
+
if (error)
|
|
352
|
+
throw new Error(`Invalid dynamic sensitivity curve: ${error}.`);
|
|
353
|
+
const payload = new Uint8Array(20);
|
|
354
|
+
points.forEach((point, index) => {
|
|
355
|
+
payload[index * 4] = point.speed & 0xff;
|
|
356
|
+
payload[index * 4 + 1] = (point.speed >> 8) & 0xff;
|
|
357
|
+
const hundredths = Math.round(point.gain * 100);
|
|
358
|
+
payload[index * 4 + 2] = hundredths & 0xff;
|
|
359
|
+
payload[index * 4 + 3] = (hundredths >> 8) & 0xff;
|
|
360
|
+
});
|
|
361
|
+
return wallhackBuildWrite(WALLHACK_CURVE_ADDRESS.custom, [...payload]);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Decode a preset-curve payload (10 bytes from response byte 7): one point
|
|
365
|
+
* per 2 bytes as `speed u8, gain*100 u8`. Returns null when malformed.
|
|
366
|
+
*/
|
|
367
|
+
export function wallhackDecodePresetCurve(payload) {
|
|
368
|
+
if (payload.length < 10)
|
|
369
|
+
return null;
|
|
370
|
+
const points = [];
|
|
371
|
+
for (let index = 0; index < WALLHACK_CURVE_POINT_COUNT; index++) {
|
|
372
|
+
points.push({ speed: payload[index * 2], gain: payload[index * 2 + 1] / 100 });
|
|
373
|
+
}
|
|
374
|
+
return wallhackValidateCurve(points) === null ? points : null;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Decode a custom-curve payload (20 bytes): one point per 4 bytes as u16LE
|
|
378
|
+
* speed + u16LE gain*100. Returns null when malformed.
|
|
379
|
+
*/
|
|
380
|
+
export function wallhackDecodeCustomCurve(payload) {
|
|
381
|
+
if (payload.length < 20)
|
|
382
|
+
return null;
|
|
383
|
+
const points = [];
|
|
384
|
+
for (let index = 0; index < WALLHACK_CURVE_POINT_COUNT; index++) {
|
|
385
|
+
const speed = (payload[index * 4] | (payload[index * 4 + 1] << 8)) & 0xffff;
|
|
386
|
+
const hundredths = (payload[index * 4 + 2] | (payload[index * 4 + 3] << 8)) & 0xffff;
|
|
387
|
+
points.push({ speed, gain: hundredths / 100 });
|
|
388
|
+
}
|
|
389
|
+
return wallhackValidateCurve(points) === null ? points : null;
|
|
390
|
+
}
|
|
391
|
+
/** Curve-table status code (response byte 6) rendered as text. */
|
|
392
|
+
export function wallhackCurveStatusText(response) {
|
|
393
|
+
const status = response.length > 6 ? response[6] : 0;
|
|
394
|
+
switch (status) {
|
|
395
|
+
case 0: return "ok";
|
|
396
|
+
case 1: return "address or length rejected by the mouse";
|
|
397
|
+
case 2: return "the mouse rejected the curve as invalid (speed ≤ 280, gain 0.10–6.00, speeds strictly increasing)";
|
|
398
|
+
case 3: return "that curve table is read-only";
|
|
399
|
+
default: return `unknown status 0x${status.toString(16).padStart(2, "0")}`;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
export function wallhackCurveModeFromIndex(index) {
|
|
403
|
+
switch (index) {
|
|
404
|
+
case 0: return "classic";
|
|
405
|
+
case 1: return "natural";
|
|
406
|
+
case 2: return "jump";
|
|
407
|
+
case 3: return "custom";
|
|
408
|
+
default: return null;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
// ---------------------------------------------------------------------------
|
|
412
|
+
// Button bindings (GET_KEYS / SET_KEYS)
|
|
413
|
+
// ---------------------------------------------------------------------------
|
|
414
|
+
/**
|
|
415
|
+
* Button bindings: the mouse holds 8 key slots of 3-byte triplets
|
|
416
|
+
* (`keyType, codeL, codeH`); the first five are the physical buttons in
|
|
417
|
+
* `WALLHACK_BUTTON_ORDER` and the last three are reserved (read as
|
|
418
|
+
* disabled, preserved on write). `GET_KEYS` reads all 8; `SET_KEYS` writes
|
|
419
|
+
* triplets at a triplet (not byte) offset: slot N starts at offset N*3.
|
|
420
|
+
*/
|
|
421
|
+
export const WALLHACK_KEY_SLOTS = 8;
|
|
422
|
+
export const WALLHACK_TRIPLET_SIZE = 3;
|
|
423
|
+
export const WALLHACK_BUTTON_ORDER = ["left", "right", "middle", "back", "forward"];
|
|
424
|
+
/** Mouse-button bitmask used by keyType 16 (`Zp`). */
|
|
425
|
+
export const WALLHACK_BUTTON_BITS = {
|
|
426
|
+
left: 1,
|
|
427
|
+
right: 2,
|
|
428
|
+
middle: 4,
|
|
429
|
+
back: 8,
|
|
430
|
+
forward: 16,
|
|
431
|
+
};
|
|
432
|
+
const WALLHACK_DPI_OPS = { increment: 1, decrement: 2, loop: 3 };
|
|
433
|
+
const WALLHACK_SYSTEM_ACTIONS = { power: 1, sleep: 2, wake: 4 };
|
|
434
|
+
const WALLHACK_MEDIA_ACTIONS = {
|
|
435
|
+
nextTrack: 181,
|
|
436
|
+
previousTrack: 182,
|
|
437
|
+
stop: 183,
|
|
438
|
+
playPause: 205,
|
|
439
|
+
mute: 226,
|
|
440
|
+
volumeUp: 233,
|
|
441
|
+
volumeDown: 234,
|
|
442
|
+
};
|
|
443
|
+
const WALLHACK_MACRO_STOP_MODES = { once: 0, finishCycleOnRelease: 1, toggle: 2, stopOnRelease: 3 };
|
|
444
|
+
const WALLHACK_MOUSE_BUTTON_BY_INDEX = ["left", "middle", "right", "back", "forward"];
|
|
445
|
+
function wallhackLookupKey(table, code) {
|
|
446
|
+
for (const [name, value] of Object.entries(table)) {
|
|
447
|
+
if (value === code)
|
|
448
|
+
return name;
|
|
449
|
+
}
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
/** Encode a binding into its wire triplet (`K7`). Throws on bad parameters. */
|
|
453
|
+
export function wallhackEncodeBinding(binding) {
|
|
454
|
+
switch (binding.kind) {
|
|
455
|
+
case "disabled": return { keyType: 0, codeL: 0, codeH: 0 };
|
|
456
|
+
case "mouseButton": {
|
|
457
|
+
const bits = WALLHACK_BUTTON_BITS[binding.button];
|
|
458
|
+
if (bits === undefined)
|
|
459
|
+
throw new Error(`Unknown WALLHACK mouse button "${binding.button}".`);
|
|
460
|
+
return { keyType: 16, codeL: bits, codeH: 0 };
|
|
461
|
+
}
|
|
462
|
+
case "key": return { keyType: 32, codeL: binding.modifiers, codeH: binding.hidUsage };
|
|
463
|
+
case "dpi": return { keyType: 19, codeL: WALLHACK_DPI_OPS[binding.op], codeH: 0 };
|
|
464
|
+
case "system": return { keyType: 64, codeL: WALLHACK_SYSTEM_ACTIONS[binding.action], codeH: 0 };
|
|
465
|
+
case "media": return { keyType: 48, codeL: WALLHACK_MEDIA_ACTIONS[binding.action], codeH: 0 };
|
|
466
|
+
case "rapidFire": {
|
|
467
|
+
if (!Number.isInteger(binding.intervalMs) || binding.intervalMs < 0 || binding.intervalMs > 255) {
|
|
468
|
+
throw new Error("Rapid-fire interval must be a whole ms from 0 to 255.");
|
|
469
|
+
}
|
|
470
|
+
if (!Number.isInteger(binding.clickCount) || binding.clickCount < 1 || binding.clickCount > 255) {
|
|
471
|
+
throw new Error("Rapid-fire click count must be from 1 to 255.");
|
|
472
|
+
}
|
|
473
|
+
return { keyType: 20, codeL: binding.intervalMs, codeH: binding.clickCount };
|
|
474
|
+
}
|
|
475
|
+
case "macro": return { keyType: 112, codeL: binding.macroNumber, codeH: WALLHACK_MACRO_STOP_MODES[binding.stop.mode] };
|
|
476
|
+
case "unknown": return { ...binding.triplet };
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/** Decode a wire triplet into a binding (`e2`), keeping unknowns lossless. */
|
|
480
|
+
export function wallhackDecodeTriplet(triplet) {
|
|
481
|
+
const unknown = { kind: "unknown", triplet: { ...triplet } };
|
|
482
|
+
if (triplet.keyType === 0 && triplet.codeL === 0 && triplet.codeH === 0)
|
|
483
|
+
return { kind: "disabled" };
|
|
484
|
+
switch (triplet.keyType) {
|
|
485
|
+
case 16: {
|
|
486
|
+
const name = wallhackLookupKey(WALLHACK_BUTTON_BITS, triplet.codeL);
|
|
487
|
+
return name ? { kind: "mouseButton", button: name } : unknown;
|
|
488
|
+
}
|
|
489
|
+
case 1: {
|
|
490
|
+
const name = WALLHACK_MOUSE_BUTTON_BY_INDEX[triplet.codeL - 1];
|
|
491
|
+
return name ? { kind: "mouseButton", button: name } : unknown;
|
|
492
|
+
}
|
|
493
|
+
case 32:
|
|
494
|
+
case 7: return { kind: "key", modifiers: triplet.codeL, hidUsage: triplet.codeH };
|
|
495
|
+
case 19:
|
|
496
|
+
case 4: {
|
|
497
|
+
const op = wallhackLookupKey(WALLHACK_DPI_OPS, triplet.codeL);
|
|
498
|
+
return op ? { kind: "dpi", op: op } : unknown;
|
|
499
|
+
}
|
|
500
|
+
case 64: {
|
|
501
|
+
const action = wallhackLookupKey(WALLHACK_SYSTEM_ACTIONS, triplet.codeL);
|
|
502
|
+
return action ? { kind: "system", action: action } : unknown;
|
|
503
|
+
}
|
|
504
|
+
case 48: {
|
|
505
|
+
const action = wallhackLookupKey(WALLHACK_MEDIA_ACTIONS, triplet.codeL);
|
|
506
|
+
return action
|
|
507
|
+
? {
|
|
508
|
+
kind: "media",
|
|
509
|
+
action: action,
|
|
510
|
+
}
|
|
511
|
+
: unknown;
|
|
512
|
+
}
|
|
513
|
+
case 20: return triplet.codeH > 0 ? { kind: "rapidFire", intervalMs: triplet.codeL, clickCount: triplet.codeH } : unknown;
|
|
514
|
+
case 112: {
|
|
515
|
+
const mode = wallhackLookupKey(WALLHACK_MACRO_STOP_MODES, triplet.codeH);
|
|
516
|
+
return mode
|
|
517
|
+
? {
|
|
518
|
+
kind: "macro",
|
|
519
|
+
macroNumber: triplet.codeL,
|
|
520
|
+
stop: { mode: mode },
|
|
521
|
+
}
|
|
522
|
+
: unknown;
|
|
523
|
+
}
|
|
524
|
+
case 11: {
|
|
525
|
+
const stop = wallhackLookupKey(WALLHACK_MACRO_STOP_MODES, triplet.codeH);
|
|
526
|
+
return stop
|
|
527
|
+
? {
|
|
528
|
+
kind: "macro",
|
|
529
|
+
macroNumber: triplet.codeL,
|
|
530
|
+
stop: { mode: stop },
|
|
531
|
+
}
|
|
532
|
+
: unknown;
|
|
533
|
+
}
|
|
534
|
+
default: return unknown;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
export function wallhackTripletsEqual(a, b) {
|
|
538
|
+
return a.keyType === b.keyType && a.codeL === b.codeL && a.codeH === b.codeH;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Human labels for button bindings, used by OpenMouse's shared button
|
|
542
|
+
* remapper (`buttonMappings`/`buttonOptions`/`setButtonMapping`). Every
|
|
543
|
+
* label parses back through `wallhackBindingFromLabel`, including the
|
|
544
|
+
* parametric `Rapid Fire …`, `Macro …`, `Key …` and `Unknown (…)` forms.
|
|
545
|
+
*/
|
|
546
|
+
export const WALLHACK_BUTTON_OPTIONS = [
|
|
547
|
+
"Left Click",
|
|
548
|
+
"Right Click",
|
|
549
|
+
"Middle Click",
|
|
550
|
+
"Back",
|
|
551
|
+
"Forward",
|
|
552
|
+
"DPI +",
|
|
553
|
+
"DPI -",
|
|
554
|
+
"DPI Cycle",
|
|
555
|
+
"Power",
|
|
556
|
+
"Sleep",
|
|
557
|
+
"Wake",
|
|
558
|
+
"Next Track",
|
|
559
|
+
"Previous Track",
|
|
560
|
+
"Stop",
|
|
561
|
+
"Play / Pause",
|
|
562
|
+
"Mute",
|
|
563
|
+
"Volume +",
|
|
564
|
+
"Volume -",
|
|
565
|
+
"Macro 1",
|
|
566
|
+
"Macro 2",
|
|
567
|
+
"Macro 3",
|
|
568
|
+
"Macro 4",
|
|
569
|
+
"Rapid Fire 100ms x5",
|
|
570
|
+
"Disabled",
|
|
571
|
+
];
|
|
572
|
+
const WALLHACK_MACRO_MODE_LABELS = {
|
|
573
|
+
once: "Once",
|
|
574
|
+
finishCycleOnRelease: "Finish Cycle on Release",
|
|
575
|
+
toggle: "Toggle",
|
|
576
|
+
stopOnRelease: "Stop on Release",
|
|
577
|
+
};
|
|
578
|
+
export function wallhackBindingLabel(binding) {
|
|
579
|
+
switch (binding.kind) {
|
|
580
|
+
case "disabled": return "Disabled";
|
|
581
|
+
case "mouseButton": {
|
|
582
|
+
switch (binding.button) {
|
|
583
|
+
case "left": return "Left Click";
|
|
584
|
+
case "right": return "Right Click";
|
|
585
|
+
case "middle": return "Middle Click";
|
|
586
|
+
case "back": return "Back";
|
|
587
|
+
case "forward": return "Forward";
|
|
588
|
+
default: return `Unknown (16,${WALLHACK_BUTTON_BITS[binding.button] ?? 0},0)`;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
case "key": return binding.modifiers === 0 ? `Key ${binding.hidUsage}` : `Key ${binding.hidUsage} +${binding.modifiers}`;
|
|
592
|
+
case "dpi": return binding.op === "increment" ? "DPI +" : binding.op === "decrement" ? "DPI -" : "DPI Cycle";
|
|
593
|
+
case "system": return binding.action === "power" ? "Power" : binding.action === "sleep" ? "Sleep" : "Wake";
|
|
594
|
+
case "media": {
|
|
595
|
+
switch (binding.action) {
|
|
596
|
+
case "nextTrack": return "Next Track";
|
|
597
|
+
case "previousTrack": return "Previous Track";
|
|
598
|
+
case "stop": return "Stop";
|
|
599
|
+
case "playPause": return "Play / Pause";
|
|
600
|
+
case "mute": return "Mute";
|
|
601
|
+
case "volumeUp": return "Volume +";
|
|
602
|
+
case "volumeDown": return "Volume -";
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
case "rapidFire": return `Rapid Fire ${binding.intervalMs}ms x${binding.clickCount}`;
|
|
607
|
+
case "macro": {
|
|
608
|
+
const mode = WALLHACK_MACRO_MODE_LABELS[binding.stop.mode];
|
|
609
|
+
return binding.stop.mode === "once" ? `Macro ${binding.macroNumber + 1}` : `Macro ${binding.macroNumber + 1} ${mode}`;
|
|
610
|
+
}
|
|
611
|
+
case "unknown": return `Unknown (${binding.triplet.keyType},${binding.triplet.codeL},${binding.triplet.codeH})`;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
/** Parse a `wallhackBindingLabel` label back into a binding. Throws when unknown. */
|
|
615
|
+
export function wallhackBindingFromLabel(label) {
|
|
616
|
+
switch (label) {
|
|
617
|
+
case "Disabled": return { kind: "disabled" };
|
|
618
|
+
case "Left Click": return { kind: "mouseButton", button: "left" };
|
|
619
|
+
case "Right Click": return { kind: "mouseButton", button: "right" };
|
|
620
|
+
case "Middle Click": return { kind: "mouseButton", button: "middle" };
|
|
621
|
+
case "Back": return { kind: "mouseButton", button: "back" };
|
|
622
|
+
case "Forward": return { kind: "mouseButton", button: "forward" };
|
|
623
|
+
case "DPI +": return { kind: "dpi", op: "increment" };
|
|
624
|
+
case "DPI -": return { kind: "dpi", op: "decrement" };
|
|
625
|
+
case "DPI Cycle": return { kind: "dpi", op: "loop" };
|
|
626
|
+
case "Power": return { kind: "system", action: "power" };
|
|
627
|
+
case "Sleep": return { kind: "system", action: "sleep" };
|
|
628
|
+
case "Wake": return { kind: "system", action: "wake" };
|
|
629
|
+
case "Next Track": return { kind: "media", action: "nextTrack" };
|
|
630
|
+
case "Previous Track": return { kind: "media", action: "previousTrack" };
|
|
631
|
+
case "Stop": return { kind: "media", action: "stop" };
|
|
632
|
+
case "Play / Pause": return { kind: "media", action: "playPause" };
|
|
633
|
+
case "Mute": return { kind: "media", action: "mute" };
|
|
634
|
+
case "Volume +": return { kind: "media", action: "volumeUp" };
|
|
635
|
+
case "Volume -": return { kind: "media", action: "volumeDown" };
|
|
636
|
+
}
|
|
637
|
+
let match = /^Rapid Fire (\d+)ms x(\d+)$/.exec(label);
|
|
638
|
+
if (match) {
|
|
639
|
+
return {
|
|
640
|
+
kind: "rapidFire",
|
|
641
|
+
intervalMs: Number(match[1]),
|
|
642
|
+
clickCount: Number(match[2]),
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
match = /^Macro (\d)(?: (.+))?$/.exec(label);
|
|
646
|
+
if (match) {
|
|
647
|
+
const macroNumber = Number(match[1]) - 1;
|
|
648
|
+
const modeLabel = match[2];
|
|
649
|
+
if (!Number.isInteger(macroNumber) || macroNumber < 0 || macroNumber > 3) {
|
|
650
|
+
throw new Error(`Unknown button action "${label}".`);
|
|
651
|
+
}
|
|
652
|
+
const modeName = modeLabel === undefined
|
|
653
|
+
? "once"
|
|
654
|
+
: (Object.entries(WALLHACK_MACRO_MODE_LABELS).find(([, name]) => name === modeLabel)?.[0] ?? null);
|
|
655
|
+
if (modeName === null)
|
|
656
|
+
throw new Error(`Unknown button action "${label}".`);
|
|
657
|
+
return {
|
|
658
|
+
kind: "macro",
|
|
659
|
+
macroNumber,
|
|
660
|
+
stop: { mode: modeName },
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
match = /^Key (\d+)(?: \+(\d+))?$/.exec(label);
|
|
664
|
+
if (match)
|
|
665
|
+
return { kind: "key", modifiers: Number(match[2] ?? 0), hidUsage: Number(match[1]) };
|
|
666
|
+
match = /^Unknown \((\d+),(\d+),(\d+)\)$/.exec(label);
|
|
667
|
+
if (match) {
|
|
668
|
+
return {
|
|
669
|
+
kind: "unknown",
|
|
670
|
+
triplet: { keyType: Number(match[1]), codeL: Number(match[2]), codeH: Number(match[3]) },
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
throw new Error(`Unknown button action "${label}".`);
|
|
674
|
+
}
|
|
675
|
+
/** `GET_KEYS` read-all packet (8 slots × 3 bytes). */
|
|
676
|
+
export function wallhackBuildGetKeys(slots = WALLHACK_KEY_SLOTS) {
|
|
677
|
+
return wallhackReport([0, 0, WALLHACK_COMMAND.getKeys, slots * WALLHACK_TRIPLET_SIZE, 0, 0, 0]);
|
|
678
|
+
}
|
|
679
|
+
/** `GET_DEFAULT_KEYS` read-all packet. */
|
|
680
|
+
export function wallhackBuildGetDefaultKeys(slots = WALLHACK_KEY_SLOTS) {
|
|
681
|
+
return wallhackReport([0, 0, WALLHACK_COMMAND.getDefaultKeys, slots * WALLHACK_TRIPLET_SIZE, 0, 0, 0]);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* `SET_KEYS` write packet for `triplets` at triplet offset `start`
|
|
685
|
+
* (slot N starts at offset N*3).
|
|
686
|
+
*/
|
|
687
|
+
export function wallhackBuildSetKeys(triplets, start = 0) {
|
|
688
|
+
const body = new Uint8Array(triplets.length * WALLHACK_TRIPLET_SIZE);
|
|
689
|
+
triplets.forEach((triplet, index) => {
|
|
690
|
+
body.set([triplet.keyType, triplet.codeL, triplet.codeH], index * WALLHACK_TRIPLET_SIZE);
|
|
691
|
+
});
|
|
692
|
+
const header = [0, 0, WALLHACK_COMMAND.setKeys, body.length, start & 0xff, (start >> 8) & 0xff, 0];
|
|
693
|
+
return wallhackReport([...header, ...body]);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Decode a `GET_KEYS`/`GET_DEFAULT_KEYS` reply: byte 3 is the payload length
|
|
697
|
+
* and the triplets start at byte 7. Returns null when malformed.
|
|
698
|
+
*/
|
|
699
|
+
export function wallhackDecodeKeysReply(response) {
|
|
700
|
+
if (response.length < 8)
|
|
701
|
+
return null;
|
|
702
|
+
const length = response[3];
|
|
703
|
+
const payload = response.subarray(7, 7 + Math.min(length, response.length - 7));
|
|
704
|
+
const triplets = [];
|
|
705
|
+
for (let offset = 0; offset + WALLHACK_TRIPLET_SIZE <= payload.length; offset += WALLHACK_TRIPLET_SIZE) {
|
|
706
|
+
triplets.push({ keyType: payload[offset], codeL: payload[offset + 1], codeH: payload[offset + 2] });
|
|
707
|
+
}
|
|
708
|
+
return triplets;
|
|
709
|
+
}
|
|
710
|
+
// ---------------------------------------------------------------------------
|
|
711
|
+
// Macros (GET_MACRO / SET_MACRO)
|
|
712
|
+
// ---------------------------------------------------------------------------
|
|
713
|
+
/**
|
|
714
|
+
* Onboard macros: 4 slots (`Ja`), up to 30 steps each (`$i`). An index table
|
|
715
|
+
* at offset 16 holds one u16LE content address per slot (0/0xFFFF = empty);
|
|
716
|
+
* content lives from offset 32 in 16-byte-aligned, 128-byte-max records
|
|
717
|
+
* (`Fu`/`Jp`/`GB`). One step packs into 4 bytes: `delayMs u16LE`,
|
|
718
|
+
* `eventType|make + code`. Set-macro payloads are written in 24-byte blocks.
|
|
719
|
+
*/
|
|
720
|
+
export const WALLHACK_MACRO_SLOTS = 4;
|
|
721
|
+
export const WALLHACK_MACRO_MAX_STEPS = 30;
|
|
722
|
+
export const WALLHACK_MACRO_INDEX_BASE = 16;
|
|
723
|
+
export const WALLHACK_MACRO_CONTENT_BASE = 32;
|
|
724
|
+
export const WALLHACK_MACRO_SLOT_BYTES = 128;
|
|
725
|
+
export const WALLHACK_MACRO_WRITE_BLOCK = 24;
|
|
726
|
+
const WALLHACK_MACRO_CODE = { msButton: 1, wheel: 3, x: 4, y: 5, kbModifier: 9, kbOrdinary: 10 };
|
|
727
|
+
const WALLHACK_MODIFIER_BASE = 224;
|
|
728
|
+
function wallhackModifierBit(hidUsage) {
|
|
729
|
+
return hidUsage >= WALLHACK_MODIFIER_BASE && hidUsage <= WALLHACK_MODIFIER_BASE + 7
|
|
730
|
+
? 1 << (hidUsage - WALLHACK_MODIFIER_BASE)
|
|
731
|
+
: null;
|
|
732
|
+
}
|
|
733
|
+
function wallhackBitToModifier(bit) {
|
|
734
|
+
if (bit === 0 || (bit & (bit - 1)) !== 0)
|
|
735
|
+
return null;
|
|
736
|
+
return WALLHACK_MODIFIER_BASE + Math.log2(bit);
|
|
737
|
+
}
|
|
738
|
+
/** Encode macro steps into the content-record bytes (`tO`). Throws when invalid. */
|
|
739
|
+
export function wallhackEncodeMacro(steps) {
|
|
740
|
+
if (steps.length > WALLHACK_MACRO_MAX_STEPS) {
|
|
741
|
+
throw new Error(`Macro has ${steps.length} steps; the slot holds ${WALLHACK_MACRO_MAX_STEPS}.`);
|
|
742
|
+
}
|
|
743
|
+
const record = new Uint8Array(4 + steps.length * 4);
|
|
744
|
+
record[0] = steps.length & 0xff;
|
|
745
|
+
record[1] = (steps.length >> 8) & 0xff;
|
|
746
|
+
steps.forEach((step, index) => {
|
|
747
|
+
const base = 4 + index * 4;
|
|
748
|
+
record[base] = step.delayMs & 0xff;
|
|
749
|
+
record[base + 1] = (step.delayMs >> 8) & 0xff;
|
|
750
|
+
const { event } = step;
|
|
751
|
+
switch (event.type) {
|
|
752
|
+
case "keyDown":
|
|
753
|
+
case "keyUp": {
|
|
754
|
+
const bit = wallhackModifierBit(event.hidUsage);
|
|
755
|
+
record[base + 2] = (bit === null ? WALLHACK_MACRO_CODE.kbOrdinary : WALLHACK_MACRO_CODE.kbModifier) |
|
|
756
|
+
(event.type === "keyDown" ? 128 : 0);
|
|
757
|
+
record[base + 3] = bit ?? event.hidUsage;
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
case "buttonDown":
|
|
761
|
+
case "buttonUp": {
|
|
762
|
+
const bits = WALLHACK_BUTTON_BITS[event.button];
|
|
763
|
+
if (bits === undefined)
|
|
764
|
+
throw new Error(`Unknown WALLHACK mouse button "${event.button}".`);
|
|
765
|
+
record[base + 2] = WALLHACK_MACRO_CODE.msButton | (event.type === "buttonDown" ? 128 : 0);
|
|
766
|
+
record[base + 3] = bits;
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
case "wheel":
|
|
770
|
+
case "wheelReset":
|
|
771
|
+
record[base + 2] = WALLHACK_MACRO_CODE.wheel | (event.type === "wheel" ? 128 : 0);
|
|
772
|
+
record[base + 3] = event.type === "wheelReset" ? 255 : event.direction === "up" ? 1 : 255;
|
|
773
|
+
break;
|
|
774
|
+
case "move": {
|
|
775
|
+
if (!Number.isInteger(event.delta) || event.delta === 0 || Math.abs(event.delta) > 255) {
|
|
776
|
+
throw new Error("Macro movement must be a non-zero integer from -255 to 255.");
|
|
777
|
+
}
|
|
778
|
+
record[base + 2] = WALLHACK_MACRO_CODE[event.axis] | (event.delta < 0 ? 128 : 0);
|
|
779
|
+
record[base + 3] = Math.abs(event.delta);
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
return record;
|
|
785
|
+
}
|
|
786
|
+
/** Decode a macro content record into steps (`nO`). Returns null when malformed. */
|
|
787
|
+
export function wallhackDecodeMacro(record) {
|
|
788
|
+
if (record.length < 4)
|
|
789
|
+
return null;
|
|
790
|
+
const count = (record[0] | (record[1] << 8)) & 0xffff;
|
|
791
|
+
const steps = [];
|
|
792
|
+
for (let index = 0; index < count; index++) {
|
|
793
|
+
const base = 4 + index * 4;
|
|
794
|
+
if (base + 4 > record.length || steps.length >= WALLHACK_MACRO_MAX_STEPS)
|
|
795
|
+
break;
|
|
796
|
+
const delayMs = (record[base] | (record[base + 1] << 8)) & 0xffff;
|
|
797
|
+
const codeType = record[base + 2] & 127;
|
|
798
|
+
const make = (record[base + 2] & 128) !== 0;
|
|
799
|
+
const code = record[base + 3];
|
|
800
|
+
if (codeType === WALLHACK_MACRO_CODE.kbOrdinary || codeType === WALLHACK_MACRO_CODE.kbModifier) {
|
|
801
|
+
const hidUsage = codeType === WALLHACK_MACRO_CODE.kbModifier ? wallhackBitToModifier(code) : code;
|
|
802
|
+
if (hidUsage === null)
|
|
803
|
+
continue;
|
|
804
|
+
steps.push({ delayMs, event: { type: make ? "keyDown" : "keyUp", hidUsage } });
|
|
805
|
+
}
|
|
806
|
+
else if (codeType === WALLHACK_MACRO_CODE.msButton) {
|
|
807
|
+
const button = wallhackLookupKey(WALLHACK_BUTTON_BITS, code);
|
|
808
|
+
if (button)
|
|
809
|
+
steps.push({ delayMs, event: { type: make ? "buttonDown" : "buttonUp", button } });
|
|
810
|
+
}
|
|
811
|
+
else if (codeType === WALLHACK_MACRO_CODE.wheel) {
|
|
812
|
+
if (code === 1 || code === 255) {
|
|
813
|
+
steps.push({
|
|
814
|
+
delayMs,
|
|
815
|
+
event: make
|
|
816
|
+
? { type: "wheel", direction: code === 1 ? "up" : "down" }
|
|
817
|
+
: { type: "wheelReset" },
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
else if (codeType === WALLHACK_MACRO_CODE.x || codeType === WALLHACK_MACRO_CODE.y) {
|
|
822
|
+
steps.push({
|
|
823
|
+
delayMs,
|
|
824
|
+
event: { type: "move", axis: codeType === WALLHACK_MACRO_CODE.x ? "x" : "y", delta: make ? -code : code },
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return steps;
|
|
829
|
+
}
|
|
830
|
+
/** `GET_MACRO` read packet for `length` bytes at `address` (`Mv`). */
|
|
831
|
+
export function wallhackBuildGetMacro(address, length) {
|
|
832
|
+
return wallhackReport([0, 0, WALLHACK_COMMAND.getMacro, length, address & 0xff, (address >> 8) & 0xff, 0]);
|
|
833
|
+
}
|
|
834
|
+
/** `SET_MACRO` write packet for `bytes` at `address` (`PB`). */
|
|
835
|
+
export function wallhackBuildSetMacro(address, bytes) {
|
|
836
|
+
return wallhackReport([0, 0, WALLHACK_COMMAND.setMacro, bytes.length, address & 0xff, (address >> 8) & 0xff, 0, ...bytes]);
|
|
837
|
+
}
|
|
838
|
+
/** Payload bytes of a `GET_MACRO` reply (from byte 7, per byte 3). */
|
|
839
|
+
export function wallhackMacroReplyBytes(response) {
|
|
840
|
+
if (response.length < 8)
|
|
841
|
+
return null;
|
|
842
|
+
return response.subarray(7, 7 + Math.min(response[3], response.length - 7)).slice();
|
|
843
|
+
}
|
|
844
|
+
/** Index-table address for macro slot N. */
|
|
845
|
+
export function wallhackMacroIndexAddress(slot) {
|
|
846
|
+
return WALLHACK_MACRO_INDEX_BASE + slot * 2;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Write blocks that store `record` for `slot`, reusing the slot's current
|
|
850
|
+
* address when it still fits and allocating a 16-byte-aligned,
|
|
851
|
+
* non-overlapping range otherwise (ports the app's `FB`/`XB`). `index` maps
|
|
852
|
+
* slot → content address for the slots currently on the device; pass an
|
|
853
|
+
* empty map when unknown (always allocates fresh). An empty record clears
|
|
854
|
+
* the slot: only the index write is returned.
|
|
855
|
+
*/
|
|
856
|
+
export function wallhackMacroWriteBlocks(slot, record, index) {
|
|
857
|
+
if (!Number.isInteger(slot) || slot < 0 || slot >= WALLHACK_MACRO_SLOTS) {
|
|
858
|
+
throw new Error(`Macro slot ${slot} outside 0..${WALLHACK_MACRO_SLOTS - 1}.`);
|
|
859
|
+
}
|
|
860
|
+
const blocks = [];
|
|
861
|
+
const occupied = [...index.entries()]
|
|
862
|
+
.filter(([other]) => other !== slot)
|
|
863
|
+
.map(([, address]) => address)
|
|
864
|
+
.filter((address) => Number.isInteger(address) && address >= WALLHACK_MACRO_CONTENT_BASE);
|
|
865
|
+
const overlaps = (start, length) => occupied.some((address) => start < address + length && address < start + length);
|
|
866
|
+
const current = index.get(slot);
|
|
867
|
+
let address = 0;
|
|
868
|
+
if (record.length > 0) {
|
|
869
|
+
if (current !== undefined && current >= WALLHACK_MACRO_CONTENT_BASE &&
|
|
870
|
+
current + record.length <= WALLHACK_MACRO_CONTENT_BASE + WALLHACK_MACRO_SLOTS * WALLHACK_MACRO_SLOT_BYTES &&
|
|
871
|
+
!overlaps(current, record.length)) {
|
|
872
|
+
address = current;
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
const align = (value) => (value + 15) & -16;
|
|
876
|
+
const sorted = [...occupied].sort((a, b) => a - b);
|
|
877
|
+
let candidate = WALLHACK_MACRO_CONTENT_BASE;
|
|
878
|
+
for (const other of sorted) {
|
|
879
|
+
if (candidate + record.length <= other)
|
|
880
|
+
break;
|
|
881
|
+
candidate = Math.max(candidate, align(other + record.length));
|
|
882
|
+
}
|
|
883
|
+
const top = WALLHACK_MACRO_CONTENT_BASE + WALLHACK_MACRO_SLOTS * WALLHACK_MACRO_SLOT_BYTES;
|
|
884
|
+
if (!Number.isInteger(candidate) || candidate < WALLHACK_MACRO_CONTENT_BASE || candidate + record.length > top) {
|
|
885
|
+
throw new Error("No non-overlapping macro storage range is available.");
|
|
886
|
+
}
|
|
887
|
+
address = candidate;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
blocks.push({ offset: wallhackMacroIndexAddress(slot), bytes: [address & 0xff, (address >> 8) & 0xff] });
|
|
891
|
+
for (let offset = 0; offset < record.length; offset += WALLHACK_MACRO_WRITE_BLOCK) {
|
|
892
|
+
blocks.push({ offset: address + offset, bytes: [...record.subarray(offset, offset + WALLHACK_MACRO_WRITE_BLOCK)] });
|
|
893
|
+
}
|
|
894
|
+
return blocks;
|
|
895
|
+
}
|
|
226
896
|
//# sourceMappingURL=index.js.map
|