bun-memory 1.1.21 → 1.1.23
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/README.md +73 -123
- package/example/trigger-bot.ts +4 -0
- package/package.json +1 -1
- package/structs/Memory.ts +565 -805
- package/structs/Win32Error.ts +28 -284
- package/types/Memory.ts +143 -795
package/structs/Memory.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { CString, FFIType, dlopen, read } from 'bun:ffi';
|
|
2
2
|
|
|
3
|
-
import type { Module, NetworkUtlVector, QAngle, Quaternion, Region, Scratch, Vector2, Vector3, Vector4 } from '../types/Memory';
|
|
3
|
+
import type { Module, NetworkUtlVector, Point, QAngle, Quaternion, Region, RGB, RGBA, Scratch, UPtr, UPtrArray, Vector2, Vector3, Vector4 } from '../types/Memory';
|
|
4
4
|
import Win32Error from './Win32Error';
|
|
5
5
|
|
|
6
6
|
const { f32, f64, i16, i32, i64, i8, u16, u32, u64, u8 } = read;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Kernel32 Windows API functions imported via Foreign Function Interface (FFI).
|
|
10
|
-
* These functions provide low-level access to process and memory management operations.
|
|
11
|
-
*/
|
|
12
8
|
const { symbols: Kernel32 } = dlopen('kernel32.dll', {
|
|
13
9
|
CloseHandle: { args: [FFIType.u64], returns: FFIType.bool },
|
|
14
10
|
CreateToolhelp32Snapshot: { args: [FFIType.u32, FFIType.u32], returns: FFIType.u64 },
|
|
@@ -25,45 +21,26 @@ const { symbols: Kernel32 } = dlopen('kernel32.dll', {
|
|
|
25
21
|
});
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
|
-
*
|
|
29
|
-
* This class allows reading from and writing to memory addresses in external processes,
|
|
30
|
-
* supporting various data types including primitives, arrays, and custom structures like vectors and quaternions.
|
|
24
|
+
* Provides cross-process memory manipulation for native applications.
|
|
31
25
|
*
|
|
32
|
-
*
|
|
26
|
+
* Use this class to read and write memory, access modules, and work with common data structures in external processes.
|
|
33
27
|
*
|
|
34
28
|
* @example
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* const
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* const memory = new Memory(1234);
|
|
41
|
-
*
|
|
42
|
-
* // Read a 32-bit integer from memory
|
|
43
|
-
* const value = memory.i32(0x12345678n);
|
|
44
|
-
*
|
|
45
|
-
* // Write a float to memory
|
|
46
|
-
* memory.f32(0x12345678n, 3.14159);
|
|
47
|
-
*
|
|
48
|
-
* // Clean up when done
|
|
49
|
-
* memory.close();
|
|
29
|
+
* ```ts
|
|
30
|
+
* import Memory from './structs/Memory';
|
|
31
|
+
* const cs2 = new Memory('cs2.exe');
|
|
32
|
+
* const myFloat = cs2.f32(0x12345678n);
|
|
33
|
+
* cs2.close();
|
|
50
34
|
* ```
|
|
51
35
|
*/
|
|
52
36
|
class Memory {
|
|
53
37
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* @throws {Win32Error} When process operations fail
|
|
58
|
-
* @throws {Error} When the specified process is not found
|
|
59
|
-
*
|
|
38
|
+
* Opens a process by PID or executable name.
|
|
39
|
+
* @param identifier Process ID or executable name.
|
|
40
|
+
* @throws If the process cannot be found or opened.
|
|
60
41
|
* @example
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* const memory = new Memory('calculator.exe');
|
|
64
|
-
*
|
|
65
|
-
* // Attach to process by ID
|
|
66
|
-
* const memory = new Memory(5432);
|
|
42
|
+
* ```ts
|
|
43
|
+
* const cs2 = new Memory('cs2.exe');
|
|
67
44
|
* ```
|
|
68
45
|
*/
|
|
69
46
|
constructor(identifier: number | string) {
|
|
@@ -125,107 +102,65 @@ class Memory {
|
|
|
125
102
|
throw new Error(`Process not found: ${identifier}…`);
|
|
126
103
|
}
|
|
127
104
|
|
|
128
|
-
/**
|
|
129
|
-
* Memory protection constants used for determining safe memory regions.
|
|
130
|
-
* Safe regions can be read from or written to, while unsafe regions should be avoided.
|
|
131
|
-
*/
|
|
132
105
|
private static readonly MemoryProtections = {
|
|
133
106
|
Safe: 0x10 /* PAGE_EXECUTE */ | 0x20 /* PAGE_EXECUTE_READ */ | 0x40 /* PAGE_EXECUTE_READWRITE */ | 0x80 /* PAGE_EXECUTE_WRITECOPY */ | 0x02 /* PAGE_READONLY */ | 0x04 /* PAGE_READWRITE */ | 0x08 /* PAGE_WRITECOPY */,
|
|
134
107
|
Unsafe: 0x100 /* PAGE_GUARD */ | 0x01 /* PAGE_NOACCESS */,
|
|
135
108
|
};
|
|
136
109
|
|
|
137
110
|
/**
|
|
138
|
-
*
|
|
111
|
+
* Map of loaded modules in the process, keyed by module name.
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const cs2 = new Memory('cs2.exe');
|
|
115
|
+
* const mainModule = cs2.modules['cs2.exe'];
|
|
116
|
+
* ```
|
|
139
117
|
*/
|
|
140
118
|
private _modules: { [key: string]: Module };
|
|
141
119
|
|
|
142
|
-
/**
|
|
143
|
-
* Pre-allocated scratch buffers for memory operations to avoid repeated allocations.
|
|
144
|
-
* These buffers are reused across multiple read/write operations for performance.
|
|
145
|
-
*/
|
|
146
120
|
private readonly Scratch1 = new Uint8Array(0x01);
|
|
147
121
|
private readonly Scratch2 = new Uint8Array(0x02);
|
|
122
|
+
private readonly Scratch3 = new Uint8Array(0x03);
|
|
148
123
|
private readonly Scratch4 = new Uint8Array(0x04);
|
|
149
124
|
private readonly Scratch8 = new Uint8Array(0x08);
|
|
150
125
|
private readonly Scratch12 = new Uint8Array(0x0c);
|
|
151
126
|
private readonly Scratch16 = new Uint8Array(0x10);
|
|
152
127
|
|
|
153
|
-
/**
|
|
154
|
-
* Buffer views of the scratch arrays for easier data manipulation.
|
|
155
|
-
*/
|
|
156
128
|
private readonly Scratch1Buffer = Buffer.from(this.Scratch1.buffer, this.Scratch1.byteOffset, this.Scratch1.byteLength);
|
|
157
129
|
private readonly Scratch2Buffer = Buffer.from(this.Scratch2.buffer, this.Scratch2.byteOffset, this.Scratch2.byteLength);
|
|
130
|
+
private readonly Scratch3Buffer = Buffer.from(this.Scratch3.buffer, this.Scratch3.byteOffset, this.Scratch3.byteLength);
|
|
158
131
|
private readonly Scratch4Buffer = Buffer.from(this.Scratch4.buffer, this.Scratch4.byteOffset, this.Scratch4.byteLength);
|
|
159
132
|
private readonly Scratch8Buffer = Buffer.from(this.Scratch8.buffer, this.Scratch8.byteOffset, this.Scratch8.byteLength);
|
|
160
133
|
private readonly Scratch12Buffer = Buffer.from(this.Scratch12.buffer, this.Scratch12.byteOffset, this.Scratch12.byteLength);
|
|
161
134
|
private readonly Scratch16Buffer = Buffer.from(this.Scratch16.buffer, this.Scratch16.byteOffset, this.Scratch16.byteLength);
|
|
162
135
|
|
|
163
|
-
/**
|
|
164
|
-
* Scratch buffers for Windows API structures.
|
|
165
|
-
*/
|
|
166
136
|
private readonly ScratchMemoryBasicInformation = Buffer.allocUnsafe(0x30 /* sizeof(MEMORY_BASIC_INFORMATION) */);
|
|
167
137
|
private readonly ScratchModuleEntry32W = Buffer.allocUnsafe(0x438 /* sizeof(MODULEENTRY32W) */);
|
|
168
138
|
|
|
169
|
-
/**
|
|
170
|
-
* Reusable UTF-16 decoder for interpreting raw process memory as UTF-16 text.
|
|
171
|
-
* Kept as a singleton to avoid repeated allocations in hot paths.
|
|
172
|
-
*/
|
|
173
139
|
private static readonly TextDecoderUTF16 = new TextDecoder('utf-16');
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Reusable UTF-8 decoder for interpreting raw process memory as UTF-8 text.
|
|
177
|
-
* Kept as a singleton to avoid repeated allocations in hot paths.
|
|
178
|
-
*/
|
|
179
140
|
private static readonly TextDecoderUTF8 = new TextDecoder('utf-8');
|
|
180
141
|
|
|
181
|
-
/**
|
|
182
|
-
* Handle to the target process.
|
|
183
|
-
*/
|
|
184
142
|
private readonly hProcess: bigint;
|
|
185
143
|
|
|
186
|
-
/**
|
|
187
|
-
* Process ID of the target process.
|
|
188
|
-
*/
|
|
189
144
|
private readonly th32ProcessID: number;
|
|
190
145
|
|
|
191
146
|
/**
|
|
192
|
-
* Gets
|
|
193
|
-
*
|
|
194
|
-
* @returns A frozen object containing module information indexed by module name
|
|
195
|
-
*
|
|
147
|
+
* Gets all loaded modules in the process.
|
|
148
|
+
* @returns Map of module name to module info.
|
|
196
149
|
* @example
|
|
197
|
-
* ```
|
|
198
|
-
* const
|
|
199
|
-
*
|
|
200
|
-
* // Access a specific module
|
|
201
|
-
* const mainModule = modules['notepad.exe'];
|
|
202
|
-
* console.log(`Base address: 0x${mainModule.base.toString(16)}`);
|
|
203
|
-
* console.log(`Size: ${mainModule.size} bytes`);
|
|
150
|
+
* ```ts
|
|
151
|
+
* const cs2 = new Memory('cs2.exe');
|
|
152
|
+
* const modules = cs2.modules;
|
|
204
153
|
* ```
|
|
205
154
|
*/
|
|
206
155
|
public get modules(): Memory['_modules'] {
|
|
207
156
|
return this._modules;
|
|
208
157
|
}
|
|
209
158
|
|
|
210
|
-
// Internal methods
|
|
211
|
-
|
|
212
159
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* @
|
|
217
|
-
* @param length - Length of the memory range to query
|
|
218
|
-
* @returns Array of Region objects describing the memory layout
|
|
219
|
-
* @throws {Win32Error} When memory query operations fail
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* const regions = memory.regions(0x10000000n, 0x1000n);
|
|
224
|
-
*
|
|
225
|
-
* regions.forEach(region => {
|
|
226
|
-
* console.log(`Region: 0x${region.base.toString(16)} - Size: ${region.size}`);
|
|
227
|
-
* });
|
|
228
|
-
* ```
|
|
160
|
+
* Returns memory regions in a given address range.
|
|
161
|
+
* @param address Start address.
|
|
162
|
+
* @param length Number of bytes to scan.
|
|
163
|
+
* @returns Array of memory regions.
|
|
229
164
|
*/
|
|
230
165
|
private regions(address: bigint, length: bigint | number): Region[] {
|
|
231
166
|
const dwLength = 0x30; /* sizeof(MEMORY_BASIC_INFORMATION) */
|
|
@@ -258,91 +193,40 @@ class Memory {
|
|
|
258
193
|
return result;
|
|
259
194
|
}
|
|
260
195
|
|
|
261
|
-
// Core memory operations
|
|
262
|
-
|
|
263
196
|
/**
|
|
264
|
-
* Follows a
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* adding the last offset without dereferencing.
|
|
269
|
-
*
|
|
270
|
-
* Semantics:
|
|
271
|
-
* - If `offsets` is empty, the original `address` is returned unchanged.
|
|
272
|
-
* - For each offset except the last, the method adds the offset to the current
|
|
273
|
-
* address and dereferences a `uint64` at that location to get the next base.
|
|
274
|
-
* - If any intermediate dereference yields `0n`:
|
|
275
|
-
* - when `throw_` is `true`, an error is thrown;
|
|
276
|
-
* - otherwise, `-1n` is returned to indicate a null chain.
|
|
277
|
-
* - After all intermediate dereferences succeed, the final offset is **added**
|
|
278
|
-
* (no dereference) and the resulting absolute address is returned.
|
|
279
|
-
*
|
|
280
|
-
* @param address - Starting absolute memory address (BigInt).
|
|
281
|
-
* @param offsets - Readonly list of `bigint` offsets that define the pointer path.
|
|
282
|
-
* @param throw_ - When `true`, throw on a null pointer encounter (default: `false`).
|
|
283
|
-
* @returns The resolved absolute address, or `-1n` if a null pointer was encountered and `throw_` is `false`.
|
|
284
|
-
* @throws {Error} When a null pointer is encountered and `throw_` is `true`.
|
|
285
|
-
*
|
|
197
|
+
* Follows a pointer chain with offsets.
|
|
198
|
+
* @param address Base address.
|
|
199
|
+
* @param offsets Array of pointer offsets.
|
|
200
|
+
* @returns Final address after following the chain, or -1n if any pointer is null.
|
|
286
201
|
* @example
|
|
287
|
-
* ```
|
|
288
|
-
*
|
|
289
|
-
* const
|
|
290
|
-
* const resolved = memory.follow(client.base, [0x10n, 0x20n, 0x30n]);
|
|
291
|
-
*
|
|
292
|
-
* if (resolved !== -1n) {
|
|
293
|
-
* const health = memory.f32(resolved);
|
|
294
|
-
* console.log('Health:', health);
|
|
295
|
-
* }
|
|
202
|
+
* ```ts
|
|
203
|
+
* const cs2 = new Memory('cs2.exe');
|
|
204
|
+
* const myAddress = cs2.follow(0x10000000n, [0x10n, 0x20n]);
|
|
296
205
|
* ```
|
|
297
206
|
*/
|
|
298
|
-
public follow(address: bigint, offsets: readonly bigint[]
|
|
207
|
+
public follow(address: bigint, offsets: readonly bigint[]): bigint {
|
|
299
208
|
const last = offsets.length - 1;
|
|
300
209
|
|
|
301
|
-
if (last === -1) {
|
|
302
|
-
return address;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
210
|
for (let i = 0; i < last; i++) {
|
|
306
|
-
address = this.u64(
|
|
211
|
+
address = this.u64(address + offsets[i]);
|
|
307
212
|
|
|
308
213
|
if (address === 0n) {
|
|
309
|
-
if (throw_) {
|
|
310
|
-
throw new Error('address must not be 0n.');
|
|
311
|
-
}
|
|
312
|
-
|
|
313
214
|
return -1n;
|
|
314
215
|
}
|
|
315
216
|
}
|
|
316
217
|
|
|
317
|
-
return address + offsets[last];
|
|
218
|
+
return address + (offsets[last] ?? 0n);
|
|
318
219
|
}
|
|
319
220
|
|
|
320
221
|
/**
|
|
321
|
-
* Reads
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @typeParam T - Concrete scratch type extending {@link Scratch} (for example, `Scratch16`,
|
|
326
|
-
* `Scratch32`, a CString scratch, etc.).
|
|
327
|
-
*
|
|
328
|
-
* @param address - Absolute memory address to read from (BigInt).
|
|
329
|
-
* @param scratch - Destination scratch instance to receive the bytes.
|
|
330
|
-
* @returns The same scratch instance you passed in, typed as `T`.
|
|
331
|
-
* @throws {Win32Error} When the underlying `ReadProcessMemory` call fails.
|
|
332
|
-
*
|
|
333
|
-
* @todo Research what it will take to add CString to the Scratch type.
|
|
334
|
-
*
|
|
222
|
+
* Reads memory into a buffer.
|
|
223
|
+
* @param address Address to read from.
|
|
224
|
+
* @param scratch Buffer to fill.
|
|
225
|
+
* @returns The filled buffer.
|
|
335
226
|
* @example
|
|
336
227
|
* ```ts
|
|
337
|
-
*
|
|
338
|
-
* const
|
|
339
|
-
* const out16 = memory.read(0x12345678n, s16);
|
|
340
|
-
* ```
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* ```ts
|
|
344
|
-
* const myScratch = Buffer.allocUnsafe(64);
|
|
345
|
-
* const out = memory.read(0x1000_2000n, myScratch);
|
|
228
|
+
* const cs2 = new Memory('cs2.exe');
|
|
229
|
+
* const myBuffer = cs2.read(0x12345678n, new Uint8Array(4));
|
|
346
230
|
* ```
|
|
347
231
|
*/
|
|
348
232
|
public read<T extends Scratch>(address: bigint, scratch: T): T {
|
|
@@ -361,17 +245,14 @@ class Memory {
|
|
|
361
245
|
}
|
|
362
246
|
|
|
363
247
|
/**
|
|
364
|
-
* Writes
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* @
|
|
368
|
-
* @param scratch - Buffer containing the data to write
|
|
369
|
-
* @throws {Win32Error} When the write operation fails
|
|
370
|
-
*
|
|
248
|
+
* Writes a buffer to memory.
|
|
249
|
+
* @param address Address to write to.
|
|
250
|
+
* @param scratch Buffer to write.
|
|
251
|
+
* @returns This instance.
|
|
371
252
|
* @example
|
|
372
|
-
* ```
|
|
373
|
-
* const
|
|
374
|
-
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* const cs2 = new Memory('cs2.exe');
|
|
255
|
+
* cs2.write(0x12345678n, new Uint8Array([1,2,3,4]));
|
|
375
256
|
* ```
|
|
376
257
|
*/
|
|
377
258
|
private write(address: bigint, scratch: Scratch): this {
|
|
@@ -389,17 +270,12 @@ class Memory {
|
|
|
389
270
|
return this;
|
|
390
271
|
}
|
|
391
272
|
|
|
392
|
-
// Public read / write methods…
|
|
393
|
-
|
|
394
273
|
/**
|
|
395
|
-
* Closes the
|
|
396
|
-
* This method should be called when the Memory instance is no longer needed.
|
|
397
|
-
*
|
|
274
|
+
* Closes the process handle.
|
|
398
275
|
* @example
|
|
399
|
-
* ```
|
|
400
|
-
* const
|
|
401
|
-
*
|
|
402
|
-
* memory.close(); // Clean up resources
|
|
276
|
+
* ```ts
|
|
277
|
+
* const cs2 = new Memory('cs2.exe');
|
|
278
|
+
* cs2.close();
|
|
403
279
|
* ```
|
|
404
280
|
*/
|
|
405
281
|
public close(): void {
|
|
@@ -409,19 +285,11 @@ class Memory {
|
|
|
409
285
|
}
|
|
410
286
|
|
|
411
287
|
/**
|
|
412
|
-
* Refreshes the list
|
|
413
|
-
* This method should be called if modules are loaded or unloaded during runtime.
|
|
414
|
-
*
|
|
415
|
-
* @throws {Win32Error} When module enumeration fails
|
|
416
|
-
*
|
|
288
|
+
* Refreshes the module list for the process.
|
|
417
289
|
* @example
|
|
418
|
-
* ```
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* // After some time, refresh to get updated module list
|
|
423
|
-
* memory.refresh();
|
|
424
|
-
* console.log('Updated modules:', Object.keys(memory.modules));
|
|
290
|
+
* ```ts
|
|
291
|
+
* const cs2 = new Memory('cs2.exe');
|
|
292
|
+
* cs2.refresh();
|
|
425
293
|
* ```
|
|
426
294
|
*/
|
|
427
295
|
public refresh(): void {
|
|
@@ -462,23 +330,16 @@ class Memory {
|
|
|
462
330
|
return;
|
|
463
331
|
}
|
|
464
332
|
|
|
465
|
-
// Typed read/write methods
|
|
466
|
-
|
|
467
333
|
/**
|
|
468
|
-
* Reads
|
|
469
|
-
*
|
|
470
|
-
* @param
|
|
471
|
-
* @
|
|
472
|
-
* @returns The boolean value when reading, or this Memory instance when writing
|
|
473
|
-
*
|
|
334
|
+
* Reads or writes a boolean value.
|
|
335
|
+
* @param address Address to access.
|
|
336
|
+
* @param value Optional value to write.
|
|
337
|
+
* @returns The boolean at address, or this instance if writing.
|
|
474
338
|
* @example
|
|
475
|
-
* ```
|
|
476
|
-
*
|
|
477
|
-
* const
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* // Write a boolean value
|
|
481
|
-
* memory.bool(0x12345678n, true);
|
|
339
|
+
* ```ts
|
|
340
|
+
* const cs2 = new Memory('cs2.exe');
|
|
341
|
+
* const myBool = cs2.bool(0x12345678n);
|
|
342
|
+
* cs2.bool(0x12345678n, true);
|
|
482
343
|
* ```
|
|
483
344
|
*/
|
|
484
345
|
public bool(address: bigint): boolean;
|
|
@@ -498,24 +359,15 @@ class Memory {
|
|
|
498
359
|
}
|
|
499
360
|
|
|
500
361
|
/**
|
|
501
|
-
* Reads
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
* is applied. When writing, the contents of `value` are copied to `address` verbatim.
|
|
506
|
-
*
|
|
507
|
-
* @param address - Memory address to read from or write to
|
|
508
|
-
* @param lengthOrValue - Number of bytes to read (when reading), or `Buffer` to write (when writing)
|
|
509
|
-
* @returns `Buffer` when reading, or this `Memory` instance when writing
|
|
510
|
-
*
|
|
362
|
+
* Reads or writes a Buffer.
|
|
363
|
+
* @param address Address to access.
|
|
364
|
+
* @param lengthOrValue Length to read or Buffer to write.
|
|
365
|
+
* @returns Buffer read or this instance if writing.
|
|
511
366
|
* @example
|
|
512
|
-
* ```
|
|
513
|
-
*
|
|
514
|
-
* const
|
|
515
|
-
*
|
|
516
|
-
* // Write a 4-byte patch (NOP sled, for example)
|
|
517
|
-
* const patch = Buffer.from([0x90, 0x90, 0x90, 0x90]);
|
|
518
|
-
* memory.buffer(0x12345678n, patch);
|
|
367
|
+
* ```ts
|
|
368
|
+
* const cs2 = new Memory('cs2.exe');
|
|
369
|
+
* const myBuffer = cs2.buffer(0x12345678n, 8);
|
|
370
|
+
* cs2.buffer(0x12345678n, Buffer.from([1,2,3,4]));
|
|
519
371
|
* ```
|
|
520
372
|
*/
|
|
521
373
|
public buffer(address: bigint, length: number): Buffer;
|
|
@@ -539,31 +391,15 @@ class Memory {
|
|
|
539
391
|
}
|
|
540
392
|
|
|
541
393
|
/**
|
|
542
|
-
* Reads
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
* include the terminator to avoid truncation. When writing, pass a `CString` that is
|
|
547
|
-
* already NUL-terminated.
|
|
548
|
-
*
|
|
549
|
-
* @param address - Memory address to read from or write to
|
|
550
|
-
* @param lengthOrValue - Number of bytes to read (when reading), or `CString` to write (when writing)
|
|
551
|
-
* @returns `CString` when reading, or this `Memory` instance when writing
|
|
552
|
-
*
|
|
553
|
-
* @todo Investigate odd behavior when reading strings longer than `lengthOrValue`.
|
|
554
|
-
* @todo Research and consider alternatives that do not require so many new allocations.
|
|
555
|
-
*
|
|
394
|
+
* Reads or writes a C-style string.
|
|
395
|
+
* @param address Address to access.
|
|
396
|
+
* @param lengthOrValue Length to read or CString to write.
|
|
397
|
+
* @returns CString read or this instance if writing.
|
|
556
398
|
* @example
|
|
557
|
-
* ```
|
|
558
|
-
*
|
|
559
|
-
* const
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
* // Write a C string (NUL-terminated)
|
|
563
|
-
* const valueBuffer = Buffer.from('PlayerOne\0');
|
|
564
|
-
* const valuePtr = ptr(valueBuffer);
|
|
565
|
-
* const value = new CString(valuePtr);
|
|
566
|
-
* memory.cString(0x12345678n, value);
|
|
399
|
+
* ```ts
|
|
400
|
+
* const cs2 = new Memory('cs2.exe');
|
|
401
|
+
* const myCString = cs2.cString(0x12345678n, 16);
|
|
402
|
+
* cs2.cString(0x12345678n, new CString('hello'));
|
|
567
403
|
* ```
|
|
568
404
|
*/
|
|
569
405
|
public cString(address: bigint, length: number): CString;
|
|
@@ -585,20 +421,15 @@ class Memory {
|
|
|
585
421
|
}
|
|
586
422
|
|
|
587
423
|
/**
|
|
588
|
-
* Reads
|
|
589
|
-
*
|
|
590
|
-
* @param
|
|
591
|
-
* @
|
|
592
|
-
* @returns The float value when reading, or this Memory instance when writing
|
|
593
|
-
*
|
|
424
|
+
* Reads or writes a 32-bit float.
|
|
425
|
+
* @param address Address to access.
|
|
426
|
+
* @param value Optional value to write.
|
|
427
|
+
* @returns The float at address, or this instance if writing.
|
|
594
428
|
* @example
|
|
595
|
-
* ```
|
|
596
|
-
*
|
|
597
|
-
* const
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
* // Write a float value
|
|
601
|
-
* memory.f32(0x12345678n, 100.0);
|
|
429
|
+
* ```ts
|
|
430
|
+
* const cs2 = new Memory('cs2.exe');
|
|
431
|
+
* const myFloat = cs2.f32(0x12345678n);
|
|
432
|
+
* cs2.f32(0x12345678n, 1.23);
|
|
602
433
|
* ```
|
|
603
434
|
*/
|
|
604
435
|
public f32(address: bigint): number;
|
|
@@ -618,21 +449,15 @@ class Memory {
|
|
|
618
449
|
}
|
|
619
450
|
|
|
620
451
|
/**
|
|
621
|
-
* Reads
|
|
622
|
-
*
|
|
623
|
-
* @param
|
|
624
|
-
* @
|
|
625
|
-
* @returns Float32Array when reading, or this Memory instance when writing
|
|
626
|
-
*
|
|
452
|
+
* Reads or writes a Float32Array.
|
|
453
|
+
* @param address Address to access.
|
|
454
|
+
* @param lengthOrValues Length to read or Float32Array to write.
|
|
455
|
+
* @returns Float32Array read or this instance if writing.
|
|
627
456
|
* @example
|
|
628
|
-
* ```
|
|
629
|
-
*
|
|
630
|
-
* const
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
* // Write an array of float values
|
|
634
|
-
* const newCoordinates = new Float32Array([1.0, 2.5, 3.14, 4.2]);
|
|
635
|
-
* memory.f32Array(0x12345678n, newCoordinates);
|
|
457
|
+
* ```ts
|
|
458
|
+
* const cs2 = new Memory('cs2.exe');
|
|
459
|
+
* const myArray = cs2.f32Array(0x12345678n, 3);
|
|
460
|
+
* cs2.f32Array(0x12345678n, new Float32Array([1,2,3]));
|
|
636
461
|
* ```
|
|
637
462
|
*/
|
|
638
463
|
public f32Array(address: bigint, length: number): Float32Array;
|
|
@@ -655,20 +480,15 @@ class Memory {
|
|
|
655
480
|
}
|
|
656
481
|
|
|
657
482
|
/**
|
|
658
|
-
* Reads
|
|
659
|
-
*
|
|
660
|
-
* @param
|
|
661
|
-
* @
|
|
662
|
-
* @returns The double value when reading, or this Memory instance when writing
|
|
663
|
-
*
|
|
483
|
+
* Reads or writes a 64-bit float.
|
|
484
|
+
* @param address Address to access.
|
|
485
|
+
* @param value Optional value to write.
|
|
486
|
+
* @returns The float at address, or this instance if writing.
|
|
664
487
|
* @example
|
|
665
|
-
* ```
|
|
666
|
-
*
|
|
667
|
-
* const
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
* // Write a double precision value
|
|
671
|
-
* memory.f64(0x12345678n, 3.141592653589793);
|
|
488
|
+
* ```ts
|
|
489
|
+
* const cs2 = new Memory('cs2.exe');
|
|
490
|
+
* const myFloat = cs2.f64(0x12345678n);
|
|
491
|
+
* cs2.f64(0x12345678n, 1.23);
|
|
672
492
|
* ```
|
|
673
493
|
*/
|
|
674
494
|
public f64(address: bigint): number;
|
|
@@ -688,21 +508,15 @@ class Memory {
|
|
|
688
508
|
}
|
|
689
509
|
|
|
690
510
|
/**
|
|
691
|
-
* Reads
|
|
692
|
-
*
|
|
693
|
-
* @param
|
|
694
|
-
* @
|
|
695
|
-
* @returns Float64Array when reading, or this Memory instance when writing
|
|
696
|
-
*
|
|
511
|
+
* Reads or writes a Float64Array.
|
|
512
|
+
* @param address Address to access.
|
|
513
|
+
* @param lengthOrValues Length to read or Float64Array to write.
|
|
514
|
+
* @returns Float64Array read or this instance if writing.
|
|
697
515
|
* @example
|
|
698
|
-
* ```
|
|
699
|
-
*
|
|
700
|
-
* const
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
* // Write an array of double precision values
|
|
704
|
-
* const newData = new Float64Array([1.1, 2.2, 3.3, 4.4, 5.5]);
|
|
705
|
-
* memory.f64Array(0x12345678n, newData);
|
|
516
|
+
* ```ts
|
|
517
|
+
* const cs2 = new Memory('cs2.exe');
|
|
518
|
+
* const myArray = cs2.f64Array(0x12345678n, 2);
|
|
519
|
+
* cs2.f64Array(0x12345678n, new Float64Array([1,2]));
|
|
706
520
|
* ```
|
|
707
521
|
*/
|
|
708
522
|
public f64Array(address: bigint, length: number): Float64Array;
|
|
@@ -725,20 +539,15 @@ class Memory {
|
|
|
725
539
|
}
|
|
726
540
|
|
|
727
541
|
/**
|
|
728
|
-
* Reads
|
|
729
|
-
*
|
|
730
|
-
* @param
|
|
731
|
-
* @
|
|
732
|
-
* @returns The int16 value when reading, or this Memory instance when writing
|
|
733
|
-
*
|
|
542
|
+
* Reads or writes a 16-bit integer.
|
|
543
|
+
* @param address Address to access.
|
|
544
|
+
* @param value Optional value to write.
|
|
545
|
+
* @returns The int at address, or this instance if writing.
|
|
734
546
|
* @example
|
|
735
|
-
* ```
|
|
736
|
-
*
|
|
737
|
-
* const
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
* // Write a signed 16-bit integer
|
|
741
|
-
* memory.i16(0x12345678n, -273);
|
|
547
|
+
* ```ts
|
|
548
|
+
* const cs2 = new Memory('cs2.exe');
|
|
549
|
+
* const myInt = cs2.i16(0x12345678n);
|
|
550
|
+
* cs2.i16(0x12345678n, 42);
|
|
742
551
|
* ```
|
|
743
552
|
*/
|
|
744
553
|
public i16(address: bigint): number;
|
|
@@ -758,21 +567,15 @@ class Memory {
|
|
|
758
567
|
}
|
|
759
568
|
|
|
760
569
|
/**
|
|
761
|
-
* Reads
|
|
762
|
-
*
|
|
763
|
-
* @param
|
|
764
|
-
* @
|
|
765
|
-
* @returns Int16Array when reading, or this Memory instance when writing
|
|
766
|
-
*
|
|
570
|
+
* Reads or writes an Int16Array.
|
|
571
|
+
* @param address Address to access.
|
|
572
|
+
* @param lengthOrValues Length to read or Int16Array to write.
|
|
573
|
+
* @returns Int16Array read or this instance if writing.
|
|
767
574
|
* @example
|
|
768
|
-
* ```
|
|
769
|
-
*
|
|
770
|
-
* const
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
* // Write audio samples
|
|
774
|
-
* const newSamples = new Int16Array([-100, 200, -300, 400]);
|
|
775
|
-
* memory.i16Array(0x12345678n, newSamples);
|
|
575
|
+
* ```ts
|
|
576
|
+
* const cs2 = new Memory('cs2.exe');
|
|
577
|
+
* const myArray = cs2.i16Array(0x12345678n, 2);
|
|
578
|
+
* cs2.i16Array(0x12345678n, new Int16Array([1,2]));
|
|
776
579
|
* ```
|
|
777
580
|
*/
|
|
778
581
|
public i16Array(address: bigint, length: number): Int16Array;
|
|
@@ -795,20 +598,15 @@ class Memory {
|
|
|
795
598
|
}
|
|
796
599
|
|
|
797
600
|
/**
|
|
798
|
-
* Reads
|
|
799
|
-
*
|
|
800
|
-
* @param
|
|
801
|
-
* @
|
|
802
|
-
* @returns The int32 value when reading, or this Memory instance when writing
|
|
803
|
-
*
|
|
601
|
+
* Reads or writes a 32-bit integer.
|
|
602
|
+
* @param address Address to access.
|
|
603
|
+
* @param value Optional value to write.
|
|
604
|
+
* @returns The int at address, or this instance if writing.
|
|
804
605
|
* @example
|
|
805
|
-
* ```
|
|
806
|
-
*
|
|
807
|
-
* const
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
* // Set a new score
|
|
811
|
-
* memory.i32(0x12345678n, 999999);
|
|
606
|
+
* ```ts
|
|
607
|
+
* const cs2 = new Memory('cs2.exe');
|
|
608
|
+
* const myInt = cs2.i32(0x12345678n);
|
|
609
|
+
* cs2.i32(0x12345678n, 42);
|
|
812
610
|
* ```
|
|
813
611
|
*/
|
|
814
612
|
public i32(address: bigint): number;
|
|
@@ -828,21 +626,15 @@ class Memory {
|
|
|
828
626
|
}
|
|
829
627
|
|
|
830
628
|
/**
|
|
831
|
-
* Reads
|
|
832
|
-
*
|
|
833
|
-
* @param
|
|
834
|
-
* @
|
|
835
|
-
* @returns Int32Array when reading, or this Memory instance when writing
|
|
836
|
-
*
|
|
629
|
+
* Reads or writes an Int32Array.
|
|
630
|
+
* @param address Address to access.
|
|
631
|
+
* @param lengthOrValues Length to read or Int32Array to write.
|
|
632
|
+
* @returns Int32Array read or this instance if writing.
|
|
837
633
|
* @example
|
|
838
|
-
* ```
|
|
839
|
-
*
|
|
840
|
-
* const
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
* // Set inventory values
|
|
844
|
-
* const newInventory = new Int32Array([99, 50, 25, 10, 5]);
|
|
845
|
-
* memory.i32Array(0x12345678n, newInventory);
|
|
634
|
+
* ```ts
|
|
635
|
+
* const cs2 = new Memory('cs2.exe');
|
|
636
|
+
* const myArray = cs2.i32Array(0x12345678n, 2);
|
|
637
|
+
* cs2.i32Array(0x12345678n, new Int32Array([1,2]));
|
|
846
638
|
* ```
|
|
847
639
|
*/
|
|
848
640
|
public i32Array(address: bigint, length: number): Int32Array;
|
|
@@ -865,20 +657,15 @@ class Memory {
|
|
|
865
657
|
}
|
|
866
658
|
|
|
867
659
|
/**
|
|
868
|
-
* Reads
|
|
869
|
-
*
|
|
870
|
-
* @param
|
|
871
|
-
* @
|
|
872
|
-
* @returns The int64 value when reading, or this Memory instance when writing
|
|
873
|
-
*
|
|
660
|
+
* Reads or writes a 64-bit integer.
|
|
661
|
+
* @param address Address to access.
|
|
662
|
+
* @param value Optional value to write.
|
|
663
|
+
* @returns The bigint at address, or this instance if writing.
|
|
874
664
|
* @example
|
|
875
|
-
* ```
|
|
876
|
-
*
|
|
877
|
-
* const
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
* // Write a large number
|
|
881
|
-
* memory.i64(0x12345678n, 9223372036854775807n);
|
|
665
|
+
* ```ts
|
|
666
|
+
* const cs2 = new Memory('cs2.exe');
|
|
667
|
+
* const myBigInt = cs2.i64(0x12345678n);
|
|
668
|
+
* cs2.i64(0x12345678n, 123n);
|
|
882
669
|
* ```
|
|
883
670
|
*/
|
|
884
671
|
public i64(address: bigint): bigint;
|
|
@@ -898,21 +685,15 @@ class Memory {
|
|
|
898
685
|
}
|
|
899
686
|
|
|
900
687
|
/**
|
|
901
|
-
* Reads
|
|
902
|
-
*
|
|
903
|
-
* @param
|
|
904
|
-
* @
|
|
905
|
-
* @returns BigInt64Array when reading, or this Memory instance when writing
|
|
906
|
-
*
|
|
688
|
+
* Reads or writes a BigInt64Array.
|
|
689
|
+
* @param address Address to access.
|
|
690
|
+
* @param lengthOrValues Length to read or BigInt64Array to write.
|
|
691
|
+
* @returns BigInt64Array read or this instance if writing.
|
|
907
692
|
* @example
|
|
908
|
-
* ```
|
|
909
|
-
*
|
|
910
|
-
* const
|
|
911
|
-
*
|
|
912
|
-
*
|
|
913
|
-
* // Write an array of large numbers
|
|
914
|
-
* const newNumbers = new BigInt64Array([1n, 2n, 3n, 4n, 5n]);
|
|
915
|
-
* memory.i64Array(0x12345678n, newNumbers);
|
|
693
|
+
* ```ts
|
|
694
|
+
* const cs2 = new Memory('cs2.exe');
|
|
695
|
+
* const myArray = cs2.i64Array(0x12345678n, 2);
|
|
696
|
+
* cs2.i64Array(0x12345678n, new BigInt64Array([1n,2n]));
|
|
916
697
|
* ```
|
|
917
698
|
*/
|
|
918
699
|
public i64Array(address: bigint, length: number): BigInt64Array;
|
|
@@ -935,20 +716,15 @@ class Memory {
|
|
|
935
716
|
}
|
|
936
717
|
|
|
937
718
|
/**
|
|
938
|
-
* Reads
|
|
939
|
-
*
|
|
940
|
-
* @param
|
|
941
|
-
* @
|
|
942
|
-
* @returns The int8 value when reading, or this Memory instance when writing
|
|
943
|
-
*
|
|
719
|
+
* Reads or writes an 8-bit integer.
|
|
720
|
+
* @param address Address to access.
|
|
721
|
+
* @param value Optional value to write.
|
|
722
|
+
* @returns The int at address, or this instance if writing.
|
|
944
723
|
* @example
|
|
945
|
-
* ```
|
|
946
|
-
*
|
|
947
|
-
* const
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
* // Write a small signed value
|
|
951
|
-
* memory.i8(0x12345678n, -127);
|
|
724
|
+
* ```ts
|
|
725
|
+
* const cs2 = new Memory('cs2.exe');
|
|
726
|
+
* const myInt = cs2.i8(0x12345678n);
|
|
727
|
+
* cs2.i8(0x12345678n, 7);
|
|
952
728
|
* ```
|
|
953
729
|
*/
|
|
954
730
|
public i8(address: bigint): number;
|
|
@@ -968,21 +744,15 @@ class Memory {
|
|
|
968
744
|
}
|
|
969
745
|
|
|
970
746
|
/**
|
|
971
|
-
* Reads
|
|
972
|
-
*
|
|
973
|
-
* @param
|
|
974
|
-
* @
|
|
975
|
-
* @returns Int8Array when reading, or this Memory instance when writing
|
|
976
|
-
*
|
|
747
|
+
* Reads or writes an Int8Array.
|
|
748
|
+
* @param address Address to access.
|
|
749
|
+
* @param lengthOrValues Length to read or Int8Array to write.
|
|
750
|
+
* @returns Int8Array read or this instance if writing.
|
|
977
751
|
* @example
|
|
978
|
-
* ```
|
|
979
|
-
*
|
|
980
|
-
* const
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
* // Write movement directions
|
|
984
|
-
* const newDirections = new Int8Array([-1, 0, 1, -1, 0, 1, -1, 0]);
|
|
985
|
-
* memory.i8Array(0x12345678n, newDirections);
|
|
752
|
+
* ```ts
|
|
753
|
+
* const cs2 = new Memory('cs2.exe');
|
|
754
|
+
* const myArray = cs2.i8Array(0x12345678n, 2);
|
|
755
|
+
* cs2.i8Array(0x12345678n, new Int8Array([1,2]));
|
|
986
756
|
* ```
|
|
987
757
|
*/
|
|
988
758
|
public i8Array(address: bigint, length: number): Int8Array;
|
|
@@ -1005,28 +775,15 @@ class Memory {
|
|
|
1005
775
|
}
|
|
1006
776
|
|
|
1007
777
|
/**
|
|
1008
|
-
* Reads
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
* @param address - Memory address to read from or write to
|
|
1014
|
-
* @param values - Optional `Float32Array` of length 9 to write. If omitted, performs a read operation
|
|
1015
|
-
* @returns `Float32Array` of length 9 when reading, or this `Memory` instance when writing
|
|
1016
|
-
* @throws {RangeError} When `values.length` is not exactly 9
|
|
1017
|
-
*
|
|
778
|
+
* Reads or writes a 3x3 matrix (Float32Array of length 9).
|
|
779
|
+
* @param address Address to access.
|
|
780
|
+
* @param values Optional Float32Array to write.
|
|
781
|
+
* @returns The matrix at address, or this instance if writing.
|
|
1018
782
|
* @example
|
|
1019
|
-
* ```
|
|
1020
|
-
*
|
|
1021
|
-
* const
|
|
1022
|
-
*
|
|
1023
|
-
* // Write a 3×3 matrix (length must be 9)
|
|
1024
|
-
* const next = new Float32Array([
|
|
1025
|
-
* 1, 0, 0,
|
|
1026
|
-
* 0, 1, 0,
|
|
1027
|
-
* 0, 0, 1
|
|
1028
|
-
* ]);
|
|
1029
|
-
* memory.matrix3x3(0x12345678n, next);
|
|
783
|
+
* ```ts
|
|
784
|
+
* const cs2 = new Memory('cs2.exe');
|
|
785
|
+
* const myMatrix = cs2.matrix3x3(0x12345678n);
|
|
786
|
+
* cs2.matrix3x3(0x12345678n, new Float32Array(9));
|
|
1030
787
|
* ```
|
|
1031
788
|
*/
|
|
1032
789
|
public matrix3x3(address: bigint): Float32Array;
|
|
@@ -1049,6 +806,18 @@ class Memory {
|
|
|
1049
806
|
return this;
|
|
1050
807
|
}
|
|
1051
808
|
|
|
809
|
+
/**
|
|
810
|
+
* Reads or writes a 3x4 matrix (Float32Array of length 12).
|
|
811
|
+
* @param address Address to access.
|
|
812
|
+
* @param values Optional Float32Array to write.
|
|
813
|
+
* @returns The matrix at address, or this instance if writing.
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* const cs2 = new Memory('cs2.exe');
|
|
817
|
+
* const myMatrix = cs2.matrix3x4(0x12345678n);
|
|
818
|
+
* cs2.matrix3x4(0x12345678n, new Float32Array(12));
|
|
819
|
+
* ```
|
|
820
|
+
*/
|
|
1052
821
|
public matrix3x4(address: bigint): Float32Array;
|
|
1053
822
|
public matrix3x4(address: bigint, values: Float32Array): this;
|
|
1054
823
|
public matrix3x4(address: bigint, values?: Float32Array): Float32Array | this {
|
|
@@ -1070,29 +839,15 @@ class Memory {
|
|
|
1070
839
|
}
|
|
1071
840
|
|
|
1072
841
|
/**
|
|
1073
|
-
* Reads
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1078
|
-
* @param address - Memory address to read from or write to
|
|
1079
|
-
* @param values - Optional `Float32Array` of length 16 to write. If omitted, performs a read operation
|
|
1080
|
-
* @returns `Float32Array` of length 16 when reading, or this `Memory` instance when writing
|
|
1081
|
-
* @throws {RangeError} When `values.length` is not exactly 16
|
|
1082
|
-
*
|
|
842
|
+
* Reads or writes a 4x4 matrix (Float32Array of length 16).
|
|
843
|
+
* @param address Address to access.
|
|
844
|
+
* @param values Optional Float32Array to write.
|
|
845
|
+
* @returns The matrix at address, or this instance if writing.
|
|
1083
846
|
* @example
|
|
1084
|
-
* ```
|
|
1085
|
-
*
|
|
1086
|
-
* const
|
|
1087
|
-
*
|
|
1088
|
-
* // Write a 4×4 matrix (length must be 16)
|
|
1089
|
-
* const next = new Float32Array([
|
|
1090
|
-
* 1, 0, 0, 0,
|
|
1091
|
-
* 0, 1, 0, 0,
|
|
1092
|
-
* 0, 0, 1, 0,
|
|
1093
|
-
* 0, 0, 0, 1
|
|
1094
|
-
* ]);
|
|
1095
|
-
* memory.matrix4x4(0x12345678n, next);
|
|
847
|
+
* ```ts
|
|
848
|
+
* const cs2 = new Memory('cs2.exe');
|
|
849
|
+
* const myMatrix = cs2.matrix4x4(0x12345678n);
|
|
850
|
+
* cs2.matrix4x4(0x12345678n, new Float32Array(16));
|
|
1096
851
|
* ```
|
|
1097
852
|
*/
|
|
1098
853
|
public matrix4x4(address: bigint): Float32Array;
|
|
@@ -1116,31 +871,15 @@ class Memory {
|
|
|
1116
871
|
}
|
|
1117
872
|
|
|
1118
873
|
/**
|
|
1119
|
-
* Reads
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1123
|
-
* - 0x00: `uint32` size (number of elements)
|
|
1124
|
-
* - 0x04: `uint32` capacity/reserved (not modified by this method)
|
|
1125
|
-
* - 0x08: `uint64` pointer to a contiguous array of `uint32` elements
|
|
1126
|
-
*
|
|
1127
|
-
* When reading, this method returns a `Uint32Array` containing `size` elements copied from the
|
|
1128
|
-
* elements pointer. When writing, it updates the size field and writes the provided values to the
|
|
1129
|
-
* existing elements buffer (no reallocation is performed).
|
|
1130
|
-
*
|
|
1131
|
-
* @param address - Memory address of the vector header to read from or write to
|
|
1132
|
-
* @param values - Optional `NetworkUtlVector` to write. If omitted, performs a read operation
|
|
1133
|
-
* @returns `NetworkUtlVector` when reading, or this `Memory` instance when writing
|
|
1134
|
-
*
|
|
874
|
+
* Reads or writes a NetworkUtlVector (Uint32Array).
|
|
875
|
+
* @param address Address to access.
|
|
876
|
+
* @param values Optional Uint32Array to write.
|
|
877
|
+
* @returns The vector at address, or this instance if writing.
|
|
1135
878
|
* @example
|
|
1136
|
-
* ```
|
|
1137
|
-
*
|
|
1138
|
-
* const
|
|
1139
|
-
*
|
|
1140
|
-
*
|
|
1141
|
-
* // Write new values (must fit the existing buffer capacity)
|
|
1142
|
-
* const next = new Uint32Array([10, 20, 30, 40]);
|
|
1143
|
-
* memory.networkUtlVector(0x12345678n, next);
|
|
879
|
+
* ```ts
|
|
880
|
+
* const cs2 = new Memory('cs2.exe');
|
|
881
|
+
* const myVector = cs2.networkUtlVector(0x12345678n);
|
|
882
|
+
* cs2.networkUtlVector(0x12345678n, new Uint32Array([1,2,3]));
|
|
1144
883
|
* ```
|
|
1145
884
|
*/
|
|
1146
885
|
public networkUtlVector(address: bigint): NetworkUtlVector;
|
|
@@ -1166,24 +905,97 @@ class Memory {
|
|
|
1166
905
|
}
|
|
1167
906
|
|
|
1168
907
|
/**
|
|
1169
|
-
* Reads
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1173
|
-
* @
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
908
|
+
* Reads or writes a Point (object with x, y).
|
|
909
|
+
* @param address Address to access.
|
|
910
|
+
* @param value Optional Point to write.
|
|
911
|
+
* @returns The point at address, or this instance if writing.
|
|
912
|
+
* @example
|
|
913
|
+
* ```ts
|
|
914
|
+
* const cs2 = new Memory('cs2.exe');
|
|
915
|
+
* const myPoint = cs2.point(0x12345678n);
|
|
916
|
+
* cs2.point(0x12345678n, { x: 1, y: 2 });
|
|
917
|
+
* ```
|
|
918
|
+
*/
|
|
919
|
+
public point(address: bigint): Point;
|
|
920
|
+
public point(address: bigint, value: Point): this;
|
|
921
|
+
public point(address: bigint, value?: Point): Point | this {
|
|
922
|
+
if (value === undefined) {
|
|
923
|
+
this.read(address, this.Scratch8);
|
|
924
|
+
|
|
925
|
+
const x = f32(this.Scratch8.ptr);
|
|
926
|
+
const y = f32(this.Scratch8.ptr, 0x04);
|
|
927
|
+
|
|
928
|
+
return { x, y };
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
this.Scratch8Buffer.writeFloatLE(value.x);
|
|
932
|
+
this.Scratch8Buffer.writeFloatLE(value.y, 0x04);
|
|
933
|
+
|
|
934
|
+
this.write(address, this.Scratch8);
|
|
935
|
+
|
|
936
|
+
return this;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Reads or writes an array of Points.
|
|
941
|
+
* @param address Address to access.
|
|
942
|
+
* @param lengthOrValues Length to read or array to write.
|
|
943
|
+
* @returns Array of points read or this instance if writing.
|
|
1177
944
|
* @example
|
|
1178
|
-
* ```
|
|
1179
|
-
*
|
|
1180
|
-
* const
|
|
1181
|
-
*
|
|
1182
|
-
* // Write new view angles (e.g., level the roll)
|
|
1183
|
-
* memory.qAngle(0x12345678n, { ...view, roll: 0 });
|
|
945
|
+
* ```ts
|
|
946
|
+
* const cs2 = new Memory('cs2.exe');
|
|
947
|
+
* const myPoints = cs2.pointArray(0x12345678n, 2);
|
|
948
|
+
* cs2.pointArray(0x12345678n, [{ x: 1, y: 2 }, { x: 3, y: 4 }]);
|
|
1184
949
|
* ```
|
|
1185
950
|
*/
|
|
951
|
+
public pointArray(address: bigint, length: number): Point[];
|
|
952
|
+
public pointArray(address: bigint, value: Point[]): this;
|
|
953
|
+
public pointArray(address: bigint, lengthOrValues: number | Point[]): Point[] | this {
|
|
954
|
+
if (typeof lengthOrValues === 'number') {
|
|
955
|
+
const length = lengthOrValues;
|
|
956
|
+
const scratch = new Float32Array(length * 2);
|
|
957
|
+
|
|
958
|
+
this.read(address, scratch);
|
|
959
|
+
|
|
960
|
+
const result = new Array<Vector2>(length);
|
|
961
|
+
|
|
962
|
+
for (let i = 0, j = 0; i < length; i++, j += 0x02) {
|
|
963
|
+
const x = scratch[j];
|
|
964
|
+
const y = scratch[j + 0x01];
|
|
965
|
+
|
|
966
|
+
result[i] = { x, y };
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
return result;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const values = lengthOrValues;
|
|
973
|
+
const scratch = new Float32Array(values.length * 0x02);
|
|
974
|
+
|
|
975
|
+
for (let i = 0, j = 0; i < values.length; i++, j += 0x02) {
|
|
976
|
+
const vector2 = values[i];
|
|
977
|
+
|
|
978
|
+
scratch[j] = vector2.x;
|
|
979
|
+
scratch[j + 0x01] = vector2.y;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
this.write(address, scratch);
|
|
1186
983
|
|
|
984
|
+
return this;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Reads or writes a QAngle (object with pitch, yaw, roll).
|
|
989
|
+
* @param address Address to access.
|
|
990
|
+
* @param value Optional QAngle to write.
|
|
991
|
+
* @returns The QAngle at address, or this instance if writing.
|
|
992
|
+
* @example
|
|
993
|
+
* ```ts
|
|
994
|
+
* const cs2 = new Memory('cs2.exe');
|
|
995
|
+
* const myQAngle = cs2.qAngle(0x12345678n);
|
|
996
|
+
* cs2.qAngle(0x12345678n, { pitch: 1, yaw: 2, roll: 3 });
|
|
997
|
+
* ```
|
|
998
|
+
*/
|
|
1187
999
|
public qAngle(address: bigint): QAngle;
|
|
1188
1000
|
public qAngle(address: bigint, value: QAngle): this;
|
|
1189
1001
|
public qAngle(address: bigint, value?: QAngle): QAngle | this {
|
|
@@ -1207,22 +1019,15 @@ class Memory {
|
|
|
1207
1019
|
}
|
|
1208
1020
|
|
|
1209
1021
|
/**
|
|
1210
|
-
* Reads
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
* @param address - Memory address to read from or write to
|
|
1215
|
-
* @param lengthOrValues - Length of array to read, or array of `QAngle` values to write
|
|
1216
|
-
* @returns `QAngle[]` when reading, or this `Memory` instance when writing
|
|
1217
|
-
*
|
|
1022
|
+
* Reads or writes an array of QAngles.
|
|
1023
|
+
* @param address Address to access.
|
|
1024
|
+
* @param lengthOrValues Length to read or array to write.
|
|
1025
|
+
* @returns Array of QAngles read or this instance if writing.
|
|
1218
1026
|
* @example
|
|
1219
|
-
* ```
|
|
1220
|
-
*
|
|
1221
|
-
* const
|
|
1222
|
-
*
|
|
1223
|
-
* // Write new bone angles (e.g., reset all roll to zero)
|
|
1224
|
-
* bones.forEach(b => (b.roll = 0));
|
|
1225
|
-
* memory.qAngleArray(0x12345678n, bones);
|
|
1027
|
+
* ```ts
|
|
1028
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1029
|
+
* const myQAngles = cs2.qAngleArray(0x12345678n, 2);
|
|
1030
|
+
* cs2.qAngleArray(0x12345678n, [{ pitch: 1, yaw: 2, roll: 3 }]);
|
|
1226
1031
|
* ```
|
|
1227
1032
|
*/
|
|
1228
1033
|
public qAngleArray(address: bigint, length: number): QAngle[];
|
|
@@ -1263,21 +1068,15 @@ class Memory {
|
|
|
1263
1068
|
}
|
|
1264
1069
|
|
|
1265
1070
|
/**
|
|
1266
|
-
* Reads a
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1269
|
-
* @
|
|
1270
|
-
* @param value - Optional quaternion to write. If omitted, performs a read operation
|
|
1271
|
-
* @returns The Quaternion object when reading, or this Memory instance when writing
|
|
1272
|
-
*
|
|
1071
|
+
* Reads or writes a Quaternion (object with w, x, y, z).
|
|
1072
|
+
* @param address Address to access.
|
|
1073
|
+
* @param value Optional Quaternion to write.
|
|
1074
|
+
* @returns The Quaternion at address, or this instance if writing.
|
|
1273
1075
|
* @example
|
|
1274
|
-
* ```
|
|
1275
|
-
*
|
|
1276
|
-
* const
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
* // Set player rotation to identity
|
|
1280
|
-
* memory.quaternion(0x12345678n, { x: 0, y: 0, z: 0, w: 1 });
|
|
1076
|
+
* ```ts
|
|
1077
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1078
|
+
* const myQuaternion = cs2.quaternion(0x12345678n);
|
|
1079
|
+
* cs2.quaternion(0x12345678n, { w: 1, x: 0, y: 0, z: 0 });
|
|
1281
1080
|
* ```
|
|
1282
1081
|
*/
|
|
1283
1082
|
public quaternion(address: bigint): Quaternion;
|
|
@@ -1305,21 +1104,15 @@ class Memory {
|
|
|
1305
1104
|
}
|
|
1306
1105
|
|
|
1307
1106
|
/**
|
|
1308
|
-
* Reads
|
|
1309
|
-
*
|
|
1310
|
-
* @param
|
|
1311
|
-
* @
|
|
1312
|
-
* @returns Array of Quaternion objects when reading, or this Memory instance when writing
|
|
1313
|
-
*
|
|
1107
|
+
* Reads or writes an array of Quaternions.
|
|
1108
|
+
* @param address Address to access.
|
|
1109
|
+
* @param lengthOrValues Length to read or array to write.
|
|
1110
|
+
* @returns Array of Quaternions read or this instance if writing.
|
|
1314
1111
|
* @example
|
|
1315
|
-
* ```
|
|
1316
|
-
*
|
|
1317
|
-
* const
|
|
1318
|
-
*
|
|
1319
|
-
*
|
|
1320
|
-
* // Set all bones to identity rotation
|
|
1321
|
-
* const identityRotations = Array(50).fill({ x: 0, y: 0, z: 0, w: 1 });
|
|
1322
|
-
* memory.quaternionArray(0x12345678n, identityRotations);
|
|
1112
|
+
* ```ts
|
|
1113
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1114
|
+
* const myQuaternions = cs2.quaternionArray(0x12345678n, 2);
|
|
1115
|
+
* cs2.quaternionArray(0x12345678n, [{ w: 1, x: 0, y: 0, z: 0 }]);
|
|
1323
1116
|
* ```
|
|
1324
1117
|
*/
|
|
1325
1118
|
public quaternionArray(address: bigint, length: number): Quaternion[];
|
|
@@ -1363,20 +1156,81 @@ class Memory {
|
|
|
1363
1156
|
}
|
|
1364
1157
|
|
|
1365
1158
|
/**
|
|
1366
|
-
* Reads
|
|
1367
|
-
*
|
|
1368
|
-
* @param
|
|
1369
|
-
* @
|
|
1370
|
-
* @
|
|
1371
|
-
*
|
|
1159
|
+
* Reads or writes an RGB color (object with r, g, b).
|
|
1160
|
+
* @param address Address to access.
|
|
1161
|
+
* @param value Optional RGB to write.
|
|
1162
|
+
* @returns The RGB at address, or this instance if writing.
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```ts
|
|
1165
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1166
|
+
* const myRGB = cs2.rgb(0x12345678n);
|
|
1167
|
+
* cs2.rgb(0x12345678n, { r: 255, g: 0, b: 0 });
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
public rgb(address: bigint): RGB;
|
|
1171
|
+
public rgb(address: bigint, value: RGB): this;
|
|
1172
|
+
public rgb(address: bigint, value?: RGB): RGB | this {
|
|
1173
|
+
if (value === undefined) {
|
|
1174
|
+
this.read(address, this.Scratch4);
|
|
1175
|
+
|
|
1176
|
+
const r = this.Scratch3Buffer.readUInt8(),
|
|
1177
|
+
g = this.Scratch3Buffer.readUInt8(0x01),
|
|
1178
|
+
b = this.Scratch3Buffer.readUInt8(0x02); // prettier-ignore
|
|
1179
|
+
|
|
1180
|
+
return { r, g, b };
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
this.Scratch3Buffer.writeUInt8(value.r);
|
|
1184
|
+
this.Scratch3Buffer.writeUInt8(value.g, 0x01);
|
|
1185
|
+
this.Scratch3Buffer.writeUInt8(value.b, 0x02);
|
|
1186
|
+
|
|
1187
|
+
return this.write(address, this.Scratch4);
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Reads or writes an RGBA color (object with r, g, b, a).
|
|
1192
|
+
* @param address Address to access.
|
|
1193
|
+
* @param value Optional RGBA to write.
|
|
1194
|
+
* @returns The RGBA at address, or this instance if writing.
|
|
1195
|
+
* @example
|
|
1196
|
+
* ```ts
|
|
1197
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1198
|
+
* const myRGBA = cs2.rgba(0x12345678n);
|
|
1199
|
+
* cs2.rgba(0x12345678n, { r: 255, g: 0, b: 0, a: 255 });
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
public rgba(address: bigint): RGBA;
|
|
1203
|
+
public rgba(address: bigint, value: RGBA): this;
|
|
1204
|
+
public rgba(address: bigint, value?: RGBA): RGBA | this {
|
|
1205
|
+
if (value === undefined) {
|
|
1206
|
+
this.read(address, this.Scratch4);
|
|
1207
|
+
|
|
1208
|
+
const r = this.Scratch4Buffer.readUInt8(),
|
|
1209
|
+
g = this.Scratch4Buffer.readUInt8(0x01),
|
|
1210
|
+
b = this.Scratch4Buffer.readUInt8(0x02),
|
|
1211
|
+
a = this.Scratch4Buffer.readUInt8(0x03); // prettier-ignore
|
|
1212
|
+
|
|
1213
|
+
return { r, g, b, a };
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
this.Scratch4Buffer.writeUInt8(value.r);
|
|
1217
|
+
this.Scratch4Buffer.writeUInt8(value.g, 0x01);
|
|
1218
|
+
this.Scratch4Buffer.writeUInt8(value.b, 0x02);
|
|
1219
|
+
this.Scratch4Buffer.writeUInt8(value.a, 0x03);
|
|
1220
|
+
|
|
1221
|
+
return this.write(address, this.Scratch4);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Reads or writes a 16-bit unsigned integer.
|
|
1226
|
+
* @param address Address to access.
|
|
1227
|
+
* @param value Optional value to write.
|
|
1228
|
+
* @returns The value at address, or this instance if writing.
|
|
1372
1229
|
* @example
|
|
1373
|
-
* ```
|
|
1374
|
-
*
|
|
1375
|
-
* const
|
|
1376
|
-
*
|
|
1377
|
-
*
|
|
1378
|
-
* // Write a port number
|
|
1379
|
-
* memory.u16(0x12345678n, 8080);
|
|
1230
|
+
* ```ts
|
|
1231
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1232
|
+
* const myInt = cs2.u16(0x12345678n);
|
|
1233
|
+
* cs2.u16(0x12345678n, 42);
|
|
1380
1234
|
* ```
|
|
1381
1235
|
*/
|
|
1382
1236
|
public u16(address: bigint): number;
|
|
@@ -1396,21 +1250,15 @@ class Memory {
|
|
|
1396
1250
|
}
|
|
1397
1251
|
|
|
1398
1252
|
/**
|
|
1399
|
-
* Reads
|
|
1400
|
-
*
|
|
1401
|
-
* @param
|
|
1402
|
-
* @
|
|
1403
|
-
* @returns Uint16Array when reading, or this Memory instance when writing
|
|
1404
|
-
*
|
|
1253
|
+
* Reads or writes a Uint16Array.
|
|
1254
|
+
* @param address Address to access.
|
|
1255
|
+
* @param lengthOrValues Length to read or Uint16Array to write.
|
|
1256
|
+
* @returns Uint16Array read or this instance if writing.
|
|
1405
1257
|
* @example
|
|
1406
|
-
* ```
|
|
1407
|
-
*
|
|
1408
|
-
* const
|
|
1409
|
-
*
|
|
1410
|
-
*
|
|
1411
|
-
* // Write port configuration
|
|
1412
|
-
* const newPorts = new Uint16Array([80, 443, 8080, 3000, 5432]);
|
|
1413
|
-
* memory.u16Array(0x12345678n, newPorts);
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1260
|
+
* const myArray = cs2.u16Array(0x12345678n, 2);
|
|
1261
|
+
* cs2.u16Array(0x12345678n, new Uint16Array([1,2]));
|
|
1414
1262
|
* ```
|
|
1415
1263
|
*/
|
|
1416
1264
|
public u16Array(address: bigint, length: number): Uint16Array;
|
|
@@ -1433,20 +1281,15 @@ class Memory {
|
|
|
1433
1281
|
}
|
|
1434
1282
|
|
|
1435
1283
|
/**
|
|
1436
|
-
* Reads
|
|
1437
|
-
*
|
|
1438
|
-
* @param
|
|
1439
|
-
* @
|
|
1440
|
-
* @returns The uint32 value when reading, or this Memory instance when writing
|
|
1441
|
-
*
|
|
1284
|
+
* Reads or writes a 32-bit unsigned integer.
|
|
1285
|
+
* @param address Address to access.
|
|
1286
|
+
* @param value Optional value to write.
|
|
1287
|
+
* @returns The value at address, or this instance if writing.
|
|
1442
1288
|
* @example
|
|
1443
|
-
* ```
|
|
1444
|
-
*
|
|
1445
|
-
* const
|
|
1446
|
-
*
|
|
1447
|
-
*
|
|
1448
|
-
* // Give player maximum money
|
|
1449
|
-
* memory.u32(0x12345678n, 4294967295);
|
|
1289
|
+
* ```ts
|
|
1290
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1291
|
+
* const myInt = cs2.u32(0x12345678n);
|
|
1292
|
+
* cs2.u32(0x12345678n, 42);
|
|
1450
1293
|
* ```
|
|
1451
1294
|
*/
|
|
1452
1295
|
public u32(address: bigint): number;
|
|
@@ -1466,21 +1309,15 @@ class Memory {
|
|
|
1466
1309
|
}
|
|
1467
1310
|
|
|
1468
1311
|
/**
|
|
1469
|
-
* Reads
|
|
1470
|
-
*
|
|
1471
|
-
* @param
|
|
1472
|
-
* @
|
|
1473
|
-
* @returns Uint32Array when reading, or this Memory instance when writing
|
|
1474
|
-
*
|
|
1312
|
+
* Reads or writes a Uint32Array.
|
|
1313
|
+
* @param address Address to access.
|
|
1314
|
+
* @param lengthOrValues Length to read or Uint32Array to write.
|
|
1315
|
+
* @returns Uint32Array read or this instance if writing.
|
|
1475
1316
|
* @example
|
|
1476
|
-
* ```
|
|
1477
|
-
*
|
|
1478
|
-
* const
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
* // Set resource amounts
|
|
1482
|
-
* const newResources = new Uint32Array([1000, 2000, 3000, 4000, 5000, 6000]);
|
|
1483
|
-
* memory.u32Array(0x12345678n, newResources);
|
|
1317
|
+
* ```ts
|
|
1318
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1319
|
+
* const myArray = cs2.u32Array(0x12345678n, 2);
|
|
1320
|
+
* cs2.u32Array(0x12345678n, new Uint32Array([1,2]));
|
|
1484
1321
|
* ```
|
|
1485
1322
|
*/
|
|
1486
1323
|
public u32Array(address: bigint, length: number): Uint32Array;
|
|
@@ -1503,20 +1340,15 @@ class Memory {
|
|
|
1503
1340
|
}
|
|
1504
1341
|
|
|
1505
1342
|
/**
|
|
1506
|
-
* Reads
|
|
1507
|
-
*
|
|
1508
|
-
* @param
|
|
1509
|
-
* @
|
|
1510
|
-
* @returns The uint64 value when reading, or this Memory instance when writing
|
|
1511
|
-
*
|
|
1343
|
+
* Reads or writes a 64-bit unsigned integer.
|
|
1344
|
+
* @param address Address to access.
|
|
1345
|
+
* @param value Optional value to write.
|
|
1346
|
+
* @returns The bigint at address, or this instance if writing.
|
|
1512
1347
|
* @example
|
|
1513
|
-
* ```
|
|
1514
|
-
*
|
|
1515
|
-
* const
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1518
|
-
* // Write a very large positive number
|
|
1519
|
-
* memory.u64(0x12345678n, 18446744073709551615n);
|
|
1348
|
+
* ```ts
|
|
1349
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1350
|
+
* const myBigInt = cs2.u64(0x12345678n);
|
|
1351
|
+
* cs2.u64(0x12345678n, 123n);
|
|
1520
1352
|
* ```
|
|
1521
1353
|
*/
|
|
1522
1354
|
public u64(address: bigint): bigint;
|
|
@@ -1536,21 +1368,15 @@ class Memory {
|
|
|
1536
1368
|
}
|
|
1537
1369
|
|
|
1538
1370
|
/**
|
|
1539
|
-
* Reads
|
|
1540
|
-
*
|
|
1541
|
-
* @param
|
|
1542
|
-
* @
|
|
1543
|
-
* @returns BigUint64Array when reading, or this Memory instance when writing
|
|
1544
|
-
*
|
|
1371
|
+
* Reads or writes a BigUint64Array.
|
|
1372
|
+
* @param address Address to access.
|
|
1373
|
+
* @param lengthOrValues Length to read or BigUint64Array to write.
|
|
1374
|
+
* @returns BigUint64Array read or this instance if writing.
|
|
1545
1375
|
* @example
|
|
1546
|
-
* ```
|
|
1547
|
-
*
|
|
1548
|
-
* const
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
* // Write record IDs
|
|
1552
|
-
* const newIds = new BigUint64Array([1000n, 2000n, 3000n, 4000n]);
|
|
1553
|
-
* memory.u64Array(0x12345678n, newIds);
|
|
1376
|
+
* ```ts
|
|
1377
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1378
|
+
* const myArray = cs2.u64Array(0x12345678n, 2);
|
|
1379
|
+
* cs2.u64Array(0x12345678n, new BigUint64Array([1n,2n]));
|
|
1554
1380
|
* ```
|
|
1555
1381
|
*/
|
|
1556
1382
|
public u64Array(address: bigint, length: number): BigUint64Array;
|
|
@@ -1573,20 +1399,15 @@ class Memory {
|
|
|
1573
1399
|
}
|
|
1574
1400
|
|
|
1575
1401
|
/**
|
|
1576
|
-
* Reads
|
|
1577
|
-
*
|
|
1578
|
-
* @param
|
|
1579
|
-
* @
|
|
1580
|
-
* @returns The uint8 value when reading, or this Memory instance when writing
|
|
1581
|
-
*
|
|
1402
|
+
* Reads or writes an 8-bit unsigned integer.
|
|
1403
|
+
* @param address Address to access.
|
|
1404
|
+
* @param value Optional value to write.
|
|
1405
|
+
* @returns The value at address, or this instance if writing.
|
|
1582
1406
|
* @example
|
|
1583
|
-
* ```
|
|
1584
|
-
*
|
|
1585
|
-
* const
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
* // Set opacity to maximum
|
|
1589
|
-
* memory.u8(0x12345678n, 255);
|
|
1407
|
+
* ```ts
|
|
1408
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1409
|
+
* const myInt = cs2.u8(0x12345678n);
|
|
1410
|
+
* cs2.u8(0x12345678n, 7);
|
|
1590
1411
|
* ```
|
|
1591
1412
|
*/
|
|
1592
1413
|
public u8(address: bigint): number;
|
|
@@ -1606,21 +1427,15 @@ class Memory {
|
|
|
1606
1427
|
}
|
|
1607
1428
|
|
|
1608
1429
|
/**
|
|
1609
|
-
* Reads
|
|
1610
|
-
*
|
|
1611
|
-
* @param
|
|
1612
|
-
* @
|
|
1613
|
-
* @returns Uint8Array when reading, or this Memory instance when writing
|
|
1614
|
-
*
|
|
1430
|
+
* Reads or writes a Uint8Array.
|
|
1431
|
+
* @param address Address to access.
|
|
1432
|
+
* @param lengthOrValues Length to read or Uint8Array to write.
|
|
1433
|
+
* @returns Uint8Array read or this instance if writing.
|
|
1615
1434
|
* @example
|
|
1616
|
-
* ```
|
|
1617
|
-
*
|
|
1618
|
-
* const
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
1621
|
-
* // Write pixel data
|
|
1622
|
-
* const newPixels = new Uint8Array([255, 128, 64, 32, 16, 8, 4, 2]);
|
|
1623
|
-
* memory.u8Array(0x12345678n, newPixels);
|
|
1435
|
+
* ```ts
|
|
1436
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1437
|
+
* const myArray = cs2.u8Array(0x12345678n, 2);
|
|
1438
|
+
* cs2.u8Array(0x12345678n, new Uint8Array([1,2]));
|
|
1624
1439
|
* ```
|
|
1625
1440
|
*/
|
|
1626
1441
|
public u8Array(address: bigint, length: number): Uint8Array;
|
|
@@ -1643,117 +1458,107 @@ class Memory {
|
|
|
1643
1458
|
}
|
|
1644
1459
|
|
|
1645
1460
|
/**
|
|
1646
|
-
* Reads
|
|
1647
|
-
*
|
|
1648
|
-
*
|
|
1649
|
-
* @
|
|
1650
|
-
* @param value - Optional vector to write. If omitted, performs a read operation
|
|
1651
|
-
* @returns The Vector2 object when reading, or this Memory instance when writing
|
|
1652
|
-
*
|
|
1461
|
+
* Reads or writes a pointer-sized unsigned integer.
|
|
1462
|
+
* @param address Address to access.
|
|
1463
|
+
* @param value Optional value to write.
|
|
1464
|
+
* @returns The value at address, or this instance if writing.
|
|
1653
1465
|
* @example
|
|
1654
|
-
* ```
|
|
1655
|
-
*
|
|
1656
|
-
* const
|
|
1657
|
-
*
|
|
1658
|
-
*
|
|
1659
|
-
* // Teleport player to origin
|
|
1660
|
-
* memory.vector2(0x12345678n, { x: 0, y: 0 });
|
|
1466
|
+
* ```ts
|
|
1467
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1468
|
+
* const myPtr = cs2.uPtr(0x12345678n);
|
|
1469
|
+
* cs2.uPtr(0x12345678n, 123n);
|
|
1661
1470
|
* ```
|
|
1662
1471
|
*/
|
|
1663
|
-
public
|
|
1664
|
-
public
|
|
1665
|
-
public
|
|
1472
|
+
public uPtr(address: bigint): UPtr;
|
|
1473
|
+
public uPtr(address: bigint, value: UPtr): this;
|
|
1474
|
+
public uPtr(address: bigint, value?: UPtr): UPtr | this {
|
|
1475
|
+
// TypeScript is funny sometimes, isn't it?… 🫠…
|
|
1666
1476
|
if (value === undefined) {
|
|
1667
|
-
this.
|
|
1477
|
+
return this.u64(address);
|
|
1478
|
+
}
|
|
1668
1479
|
|
|
1669
|
-
|
|
1670
|
-
|
|
1480
|
+
return this.u64(address, value);
|
|
1481
|
+
}
|
|
1671
1482
|
|
|
1672
|
-
|
|
1483
|
+
/**
|
|
1484
|
+
* Reads or writes an array of pointer-sized unsigned integers.
|
|
1485
|
+
* @param address Address to access.
|
|
1486
|
+
* @param lengthOrValues Length to read or array to write.
|
|
1487
|
+
* @returns Array read or this instance if writing.
|
|
1488
|
+
* @example
|
|
1489
|
+
* ```ts
|
|
1490
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1491
|
+
* const myPtrs = cs2.uPtrArray(0x12345678n, 2);
|
|
1492
|
+
* cs2.uPtrArray(0x12345678n, new BigUint64Array([1n,2n]));
|
|
1493
|
+
* ```
|
|
1494
|
+
*/
|
|
1495
|
+
public uPtrArray(address: bigint, length: number): UPtrArray;
|
|
1496
|
+
public uPtrArray(address: bigint, values: UPtrArray): this;
|
|
1497
|
+
public uPtrArray(address: bigint, lengthOrValues: UPtrArray | number): UPtrArray | this {
|
|
1498
|
+
// TypeScript is funny sometimes, isn't it?… 🫠…
|
|
1499
|
+
if (typeof lengthOrValues === 'number') {
|
|
1500
|
+
return this.u64Array(address, lengthOrValues);
|
|
1673
1501
|
}
|
|
1674
1502
|
|
|
1675
|
-
this.
|
|
1676
|
-
|
|
1503
|
+
return this.u64Array(address, lengthOrValues);
|
|
1504
|
+
}
|
|
1677
1505
|
|
|
1678
|
-
|
|
1506
|
+
/**
|
|
1507
|
+
* Reads or writes a Vector2 (object with x, y).
|
|
1508
|
+
* @param address Address to access.
|
|
1509
|
+
* @param value Optional Vector2 to write.
|
|
1510
|
+
* @returns The Vector2 at address, or this instance if writing.
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```ts
|
|
1513
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1514
|
+
* const myVector2 = cs2.vector2(0x12345678n);
|
|
1515
|
+
* cs2.vector2(0x12345678n, { x: 1, y: 2 });
|
|
1516
|
+
* ```
|
|
1517
|
+
*/
|
|
1518
|
+
public vector2(address: bigint): Vector2;
|
|
1519
|
+
public vector2(address: bigint, value: Vector2): this;
|
|
1520
|
+
public vector2(address: bigint, value?: Vector2): Vector2 | this {
|
|
1521
|
+
// TypeScript is funny sometimes, isn't it?… 🫠…
|
|
1522
|
+
if (value === undefined) {
|
|
1523
|
+
return this.point(address);
|
|
1524
|
+
}
|
|
1679
1525
|
|
|
1680
|
-
return this;
|
|
1526
|
+
return this.point(address, value);
|
|
1681
1527
|
}
|
|
1682
1528
|
|
|
1683
1529
|
/**
|
|
1684
|
-
* Reads
|
|
1685
|
-
*
|
|
1686
|
-
* @param
|
|
1687
|
-
* @
|
|
1688
|
-
* @returns Array of Vector2 objects when reading, or this Memory instance when writing
|
|
1689
|
-
*
|
|
1530
|
+
* Reads or writes an array of Vector2.
|
|
1531
|
+
* @param address Address to access.
|
|
1532
|
+
* @param lengthOrValues Length to read or array to write.
|
|
1533
|
+
* @returns Array of Vector2 read or this instance if writing.
|
|
1690
1534
|
* @example
|
|
1691
|
-
* ```
|
|
1692
|
-
*
|
|
1693
|
-
* const
|
|
1694
|
-
*
|
|
1695
|
-
*
|
|
1696
|
-
* // Set new waypoints
|
|
1697
|
-
* const newWaypoints = [
|
|
1698
|
-
* { x: 10, y: 20 },
|
|
1699
|
-
* { x: 30, y: 40 },
|
|
1700
|
-
* { x: 50, y: 60 }
|
|
1701
|
-
* ];
|
|
1702
|
-
* memory.vector2Array(0x12345678n, newWaypoints);
|
|
1535
|
+
* ```ts
|
|
1536
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1537
|
+
* const myVectors = cs2.vector2Array(0x12345678n, 2);
|
|
1538
|
+
* cs2.vector2Array(0x12345678n, [{ x: 1, y: 2 }, { x: 3, y: 4 }]);
|
|
1703
1539
|
* ```
|
|
1704
1540
|
*/
|
|
1705
1541
|
public vector2Array(address: bigint, length: number): Vector2[];
|
|
1706
1542
|
public vector2Array(address: bigint, values: Vector2[]): this;
|
|
1707
1543
|
public vector2Array(address: bigint, lengthOrValues: Vector2[] | number): Vector2[] | this {
|
|
1544
|
+
// TypeScript is funny sometimes, isn't it?… 🫠…
|
|
1708
1545
|
if (typeof lengthOrValues === 'number') {
|
|
1709
|
-
|
|
1710
|
-
const scratch = new Float32Array(length * 2);
|
|
1711
|
-
|
|
1712
|
-
this.read(address, scratch);
|
|
1713
|
-
|
|
1714
|
-
const result = new Array<Vector2>(length);
|
|
1715
|
-
|
|
1716
|
-
for (let i = 0, j = 0; i < length; i++, j += 0x02) {
|
|
1717
|
-
const x = scratch[j];
|
|
1718
|
-
const y = scratch[j + 0x01];
|
|
1719
|
-
|
|
1720
|
-
result[i] = { x, y };
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
return result;
|
|
1546
|
+
return this.pointArray(address, lengthOrValues);
|
|
1724
1547
|
}
|
|
1725
1548
|
|
|
1726
|
-
|
|
1727
|
-
const scratch = new Float32Array(values.length * 0x02);
|
|
1728
|
-
|
|
1729
|
-
for (let i = 0, j = 0; i < values.length; i++, j += 0x02) {
|
|
1730
|
-
const vector2 = values[i];
|
|
1731
|
-
|
|
1732
|
-
scratch[j] = vector2.x;
|
|
1733
|
-
scratch[j + 0x01] = vector2.y;
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
this.write(address, scratch);
|
|
1737
|
-
|
|
1738
|
-
return this;
|
|
1549
|
+
return this.pointArray(address, lengthOrValues);
|
|
1739
1550
|
}
|
|
1740
1551
|
|
|
1741
1552
|
/**
|
|
1742
|
-
* Reads
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
* @
|
|
1746
|
-
* @param value - Optional vector to write. If omitted, performs a read operation
|
|
1747
|
-
* @returns The Vector3 object when reading, or this Memory instance when writing
|
|
1748
|
-
*
|
|
1553
|
+
* Reads or writes a Vector3 (object with x, y, z).
|
|
1554
|
+
* @param address Address to access.
|
|
1555
|
+
* @param value Optional Vector3 to write.
|
|
1556
|
+
* @returns The Vector3 at address, or this instance if writing.
|
|
1749
1557
|
* @example
|
|
1750
|
-
* ```
|
|
1751
|
-
*
|
|
1752
|
-
* const
|
|
1753
|
-
*
|
|
1754
|
-
*
|
|
1755
|
-
* // Teleport player to specific location
|
|
1756
|
-
* memory.vector3(0x12345678n, { x: 100, y: 50, z: 200 });
|
|
1558
|
+
* ```ts
|
|
1559
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1560
|
+
* const myVector3 = cs2.vector3(0x12345678n);
|
|
1561
|
+
* cs2.vector3(0x12345678n, { x: 1, y: 2, z: 3 });
|
|
1757
1562
|
* ```
|
|
1758
1563
|
*/
|
|
1759
1564
|
public vector3(address: bigint): Vector3;
|
|
@@ -1779,25 +1584,15 @@ class Memory {
|
|
|
1779
1584
|
}
|
|
1780
1585
|
|
|
1781
1586
|
/**
|
|
1782
|
-
* Reads
|
|
1783
|
-
*
|
|
1784
|
-
* @param
|
|
1785
|
-
* @
|
|
1786
|
-
* @returns Array of Vector3 objects when reading, or this Memory instance when writing
|
|
1787
|
-
*
|
|
1587
|
+
* Reads or writes an array of Vector3.
|
|
1588
|
+
* @param address Address to access.
|
|
1589
|
+
* @param lengthOrValues Length to read or array to write.
|
|
1590
|
+
* @returns Array of Vector3 read or this instance if writing.
|
|
1788
1591
|
* @example
|
|
1789
|
-
* ```
|
|
1790
|
-
*
|
|
1791
|
-
* const
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
1794
|
-
* // Update vertex positions
|
|
1795
|
-
* const newVertices = [
|
|
1796
|
-
* { x: 1.0, y: 0.0, z: 0.0 },
|
|
1797
|
-
* { x: 0.0, y: 1.0, z: 0.0 },
|
|
1798
|
-
* { x: 0.0, y: 0.0, z: 1.0 }
|
|
1799
|
-
* ];
|
|
1800
|
-
* memory.vector3Array(0x12345678n, newVertices);
|
|
1592
|
+
* ```ts
|
|
1593
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1594
|
+
* const myVectors = cs2.vector3Array(0x12345678n, 2);
|
|
1595
|
+
* cs2.vector3Array(0x12345678n, [{ x: 1, y: 2, z: 3 }]);
|
|
1801
1596
|
* ```
|
|
1802
1597
|
*/
|
|
1803
1598
|
public vector3Array(address: bigint, length: number): Vector3[];
|
|
@@ -1839,22 +1634,15 @@ class Memory {
|
|
|
1839
1634
|
}
|
|
1840
1635
|
|
|
1841
1636
|
/**
|
|
1842
|
-
* Reads
|
|
1843
|
-
*
|
|
1844
|
-
*
|
|
1845
|
-
*
|
|
1846
|
-
*
|
|
1847
|
-
* @param address - Memory address to read from or write to
|
|
1848
|
-
* @param value - Optional `Vector4` to write. If omitted, performs a read operation
|
|
1849
|
-
* @returns The `Vector4` value when reading, or this `Memory` instance when writing
|
|
1850
|
-
*
|
|
1637
|
+
* Reads or writes a Vector4 (object with w, x, y, z).
|
|
1638
|
+
* @param address Address to access.
|
|
1639
|
+
* @param value Optional Vector4 to write.
|
|
1640
|
+
* @returns The Vector4 at address, or this instance if writing.
|
|
1851
1641
|
* @example
|
|
1852
|
-
* ```
|
|
1853
|
-
*
|
|
1854
|
-
* const
|
|
1855
|
-
*
|
|
1856
|
-
* // Write a vector4 value (e.g., identity quaternion)
|
|
1857
|
-
* memory.vector4(0x12345678n, { x: 0, y: 0, z: 0, w: 1 });
|
|
1642
|
+
* ```ts
|
|
1643
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1644
|
+
* const myVector4 = cs2.vector4(0x12345678n);
|
|
1645
|
+
* cs2.vector4(0x12345678n, { w: 1, x: 0, y: 0, z: 0 });
|
|
1858
1646
|
* ```
|
|
1859
1647
|
*/
|
|
1860
1648
|
public vector4(address: bigint): Vector4;
|
|
@@ -1869,23 +1657,15 @@ class Memory {
|
|
|
1869
1657
|
}
|
|
1870
1658
|
|
|
1871
1659
|
/**
|
|
1872
|
-
* Reads
|
|
1873
|
-
*
|
|
1874
|
-
*
|
|
1875
|
-
*
|
|
1876
|
-
*
|
|
1877
|
-
* @param address - Memory address to read from or write to
|
|
1878
|
-
* @param lengthOrValues - Length of array to read, or array of `Vector4` values to write
|
|
1879
|
-
* @returns `Vector4[]` when reading, or this `Memory` instance when writing
|
|
1880
|
-
*
|
|
1660
|
+
* Reads or writes an array of Vector4.
|
|
1661
|
+
* @param address Address to access.
|
|
1662
|
+
* @param lengthOrValues Length to read or array to write.
|
|
1663
|
+
* @returns Array of Vector4 read or this instance if writing.
|
|
1881
1664
|
* @example
|
|
1882
|
-
* ```
|
|
1883
|
-
*
|
|
1884
|
-
* const
|
|
1885
|
-
*
|
|
1886
|
-
* // Write tangent vectors (eg. normalize w to 1.0)
|
|
1887
|
-
* tangents.forEach(v => (v.w = 1.0));
|
|
1888
|
-
* memory.vector4Array(0x12345678n, tangents);
|
|
1665
|
+
* ```ts
|
|
1666
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1667
|
+
* const myVectors = cs2.vector4Array(0x12345678n, 2);
|
|
1668
|
+
* cs2.vector4Array(0x12345678n, [{ w: 1, x: 0, y: 0, z: 0 }]);
|
|
1889
1669
|
* ```
|
|
1890
1670
|
*/
|
|
1891
1671
|
public vector4Array(address: bigint, length: number): Vector4[];
|
|
@@ -1902,37 +1682,17 @@ class Memory {
|
|
|
1902
1682
|
// Public utility methods…
|
|
1903
1683
|
|
|
1904
1684
|
/**
|
|
1905
|
-
*
|
|
1906
|
-
*
|
|
1907
|
-
*
|
|
1908
|
-
*
|
|
1909
|
-
*
|
|
1910
|
-
*
|
|
1911
|
-
* The `needle` accepts any Scratch-compatible buffer or view (`Buffer`, `TypedArray`, or `DataView`).
|
|
1912
|
-
* Bytes are matched exactly as laid out in memory. :contentReference[oaicite:0]{index=0}
|
|
1913
|
-
*
|
|
1914
|
-
* @param needle - Byte sequence to search for (Scratch-compatible buffer or view)
|
|
1915
|
-
* @param address - Base memory address to begin searching (inclusive)
|
|
1916
|
-
* @param length - Number of bytes to scan
|
|
1917
|
-
* @returns Absolute address (`bigint`) of the first match, or `-1n` when not found
|
|
1918
|
-
*
|
|
1685
|
+
* Finds the address of a buffer within a memory region.
|
|
1686
|
+
* @param needle Buffer to search for.
|
|
1687
|
+
* @param address Start address.
|
|
1688
|
+
* @param length Number of bytes to search.
|
|
1689
|
+
* @returns Address of the buffer if found, or -1n.
|
|
1919
1690
|
* @example
|
|
1920
|
-
* ```
|
|
1921
|
-
*
|
|
1922
|
-
* const
|
|
1923
|
-
*
|
|
1924
|
-
* const needle = Buffer.from([0x48, 0x8B, 0x05, 0x00, 0x00, 0x00, 0x00]);
|
|
1925
|
-
* const matchAddress = memory.indexOf(needle, client.base, client.size);
|
|
1926
|
-
* ```
|
|
1927
|
-
*
|
|
1928
|
-
* @example
|
|
1929
|
-
* ```typescript
|
|
1930
|
-
* // Search using a Uint32Array needle (bytes are matched exactly as laid out in memory)
|
|
1931
|
-
* const needle = new Uint32Array([0xDEADBEEF, 0x11223344]);
|
|
1932
|
-
* const matchAddress = memory.indexOf(needle, client.base, client.size);
|
|
1691
|
+
* ```ts
|
|
1692
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1693
|
+
* const myAddress = cs2.indexOf(new Uint8Array([1,2,3]), 0x10000000n, 100);
|
|
1933
1694
|
* ```
|
|
1934
1695
|
*/
|
|
1935
|
-
|
|
1936
1696
|
public indexOf(needle: Scratch, address: bigint, length: number): bigint {
|
|
1937
1697
|
const haystackUint8Array = new Uint8Array(length);
|
|
1938
1698
|
|