bun-memory 1.1.19 → 1.1.22

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/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
- * Memory class provides cross-process memory manipulation capabilities on Windows systems.
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
- * @todo Reimplement `findPattern(…)`.
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
- * ```typescript
36
- * // Connect to a process by name
37
- * const memory = new Memory('notepad.exe');
38
- *
39
- * // Connect to a process by ID
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
- * Creates a new Memory instance and attaches to the specified process.
55
- *
56
- * @param identifier - Either a process ID (number) or process name (string)
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
- * ```typescript
62
- * // Attach to process by name
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
- * Internal storage for loaded modules information.
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 the loaded modules for the target process.
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
- * ```typescript
198
- * const modules = memory.modules;
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
- * Retrieves memory region information for a specified address range.
214
- * This method queries the virtual memory layout to identify safe regions for memory operations.
215
- *
216
- * @param address - Starting memory address
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,34 +193,40 @@ class Memory {
258
193
  return result;
259
194
  }
260
195
 
261
- // Core memory operations
262
-
263
196
  /**
264
- * Reads data from the target process memory into the provided scratch buffer and returns that
265
- * same scratch object (strongly typed). This is a low-level, zero-copy helper used internally by
266
- * typed readers.
267
- *
268
- * @typeParam T - Concrete scratch type extending {@link Scratch} (for example, `Scratch16`,
269
- * `Scratch32`, a CString scratch, etc.).
270
- *
271
- * @param address - Absolute memory address to read from (BigInt).
272
- * @param scratch - Destination scratch instance to receive the bytes.
273
- * @returns The same scratch instance you passed in, typed as `T`.
274
- * @throws {Win32Error} When the underlying `ReadProcessMemory` call fails.
275
- *
276
- * @todo Research what it will take to add CString to the Scratch type.
277
- *
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.
278
201
  * @example
279
202
  * ```ts
280
- * // Strongly typed result based on the scratch you pass in:
281
- * const s16 = memory.Scratch16;
282
- * const out16 = memory.read(0x12345678n, s16);
203
+ * const cs2 = new Memory('cs2.exe');
204
+ * const myAddress = cs2.follow(0x10000000n, [0x10n, 0x20n]);
283
205
  * ```
284
- *
206
+ */
207
+ public follow(address: bigint, offsets: readonly bigint[]): bigint {
208
+ const last = offsets.length - 1;
209
+
210
+ for (let i = 0; i < last; i++) {
211
+ address = this.u64(address + offsets[i]);
212
+
213
+ if (address === 0n) {
214
+ return -1n;
215
+ }
216
+ }
217
+
218
+ return address + (offsets[last] ?? 0n);
219
+ }
220
+
221
+ /**
222
+ * Reads memory into a buffer.
223
+ * @param address Address to read from.
224
+ * @param scratch Buffer to fill.
225
+ * @returns The filled buffer.
285
226
  * @example
286
227
  * ```ts
287
- * const myScratch = Buffer.allocUnsafe(64);
288
- * const out = memory.read(0x1000_2000n, myScratch);
228
+ * const cs2 = new Memory('cs2.exe');
229
+ * const myBuffer = cs2.read(0x12345678n, new Uint8Array(4));
289
230
  * ```
290
231
  */
291
232
  public read<T extends Scratch>(address: bigint, scratch: T): T {
@@ -304,17 +245,14 @@ class Memory {
304
245
  }
305
246
 
306
247
  /**
307
- * Writes data from a scratch buffer to the target process memory.
308
- * This is a low-level method used internally by the typed write methods.
309
- *
310
- * @param address - Memory address to write to
311
- * @param scratch - Buffer containing the data to write
312
- * @throws {Win32Error} When the write operation fails
313
- *
248
+ * Writes a buffer to memory.
249
+ * @param address Address to write to.
250
+ * @param scratch Buffer to write.
251
+ * @returns This instance.
314
252
  * @example
315
- * ```typescript
316
- * const buffer = new Uint8Array([0x41, 0x42, 0x43, 0x44]);
317
- * memory.write(0x12345678n, buffer);
253
+ * ```ts
254
+ * const cs2 = new Memory('cs2.exe');
255
+ * cs2.write(0x12345678n, new Uint8Array([1,2,3,4]));
318
256
  * ```
319
257
  */
320
258
  private write(address: bigint, scratch: Scratch): this {
@@ -332,17 +270,12 @@ class Memory {
332
270
  return this;
333
271
  }
334
272
 
335
- // Public read / write methods…
336
-
337
273
  /**
338
- * Closes the handle to the target process and releases resources.
339
- * This method should be called when the Memory instance is no longer needed.
340
- *
274
+ * Closes the process handle.
341
275
  * @example
342
- * ```typescript
343
- * const memory = new Memory('notepad.exe');
344
- * // ... perform memory operations
345
- * memory.close(); // Clean up resources
276
+ * ```ts
277
+ * const cs2 = new Memory('cs2.exe');
278
+ * cs2.close();
346
279
  * ```
347
280
  */
348
281
  public close(): void {
@@ -352,19 +285,11 @@ class Memory {
352
285
  }
353
286
 
354
287
  /**
355
- * Refreshes the list of modules loaded in the target process.
356
- * This method should be called if modules are loaded or unloaded during runtime.
357
- *
358
- * @throws {Win32Error} When module enumeration fails
359
- *
288
+ * Refreshes the module list for the process.
360
289
  * @example
361
- * ```typescript
362
- * // Initial modules
363
- * console.log('Initial modules:', Object.keys(memory.modules));
364
- *
365
- * // After some time, refresh to get updated module list
366
- * memory.refresh();
367
- * console.log('Updated modules:', Object.keys(memory.modules));
290
+ * ```ts
291
+ * const cs2 = new Memory('cs2.exe');
292
+ * cs2.refresh();
368
293
  * ```
369
294
  */
370
295
  public refresh(): void {
@@ -405,23 +330,16 @@ class Memory {
405
330
  return;
406
331
  }
407
332
 
408
- // Typed read/write methods
409
-
410
333
  /**
411
- * Reads a boolean value from memory or writes a boolean value to memory.
412
- *
413
- * @param address - Memory address to read from or write to
414
- * @param value - Optional value to write. If omitted, performs a read operation
415
- * @returns The boolean value when reading, or this Memory instance when writing
416
- *
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.
417
338
  * @example
418
- * ```typescript
419
- * // Read a boolean value
420
- * const isAlive = memory.bool(0x12345678n);
421
- * console.log('Player is alive:', isAlive);
422
- *
423
- * // Write a boolean value
424
- * memory.bool(0x12345678n, true);
339
+ * ```ts
340
+ * const cs2 = new Memory('cs2.exe');
341
+ * const myBool = cs2.bool(0x12345678n);
342
+ * cs2.bool(0x12345678n, true);
425
343
  * ```
426
344
  */
427
345
  public bool(address: bigint): boolean;
@@ -441,24 +359,15 @@ class Memory {
441
359
  }
442
360
 
443
361
  /**
444
- * Reads a raw byte buffer from memory or writes a raw byte buffer to memory.
445
- *
446
- * When reading, exactly `length` bytes are copied from `address` into a new `Buffer`.
447
- * Bytes are returned exactly as laid out in memory—no decoding, alignment, or transformation
448
- * is applied. When writing, the contents of `value` are copied to `address` verbatim.
449
- *
450
- * @param address - Memory address to read from or write to
451
- * @param lengthOrValue - Number of bytes to read (when reading), or `Buffer` to write (when writing)
452
- * @returns `Buffer` when reading, or this `Memory` instance when writing
453
- *
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.
454
366
  * @example
455
- * ```typescript
456
- * // Read 16 bytes from memory
457
- * const bytes = memory.buffer(0x12345678n, 16);
458
- *
459
- * // Write a 4-byte patch (NOP sled, for example)
460
- * const patch = Buffer.from([0x90, 0x90, 0x90, 0x90]);
461
- * 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]));
462
371
  * ```
463
372
  */
464
373
  public buffer(address: bigint, length: number): Buffer;
@@ -482,31 +391,15 @@ class Memory {
482
391
  }
483
392
 
484
393
  /**
485
- * Reads a NUL-terminated C string from memory or writes a NUL-terminated C string to memory.
486
- *
487
- * When reading, up to `length` bytes are copied into a temporary buffer and a `CString`
488
- * is constructed from that buffer. Ensure the requested `length` is large enough to
489
- * include the terminator to avoid truncation. When writing, pass a `CString` that is
490
- * already NUL-terminated.
491
- *
492
- * @param address - Memory address to read from or write to
493
- * @param lengthOrValue - Number of bytes to read (when reading), or `CString` to write (when writing)
494
- * @returns `CString` when reading, or this `Memory` instance when writing
495
- *
496
- * @todo Investigate odd behavior when reading strings longer than `lengthOrValue`.
497
- * @todo Research and consider alternatives that do not require so many new allocations.
498
- *
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.
499
398
  * @example
500
- * ```typescript
501
- * // Read up to 64 bytes and interpret as a C string
502
- * const playerName = memory.cString(0x12345678n, 64);
503
- * console.log('Player name:', playerName.toString());
504
- *
505
- * // Write a C string (NUL-terminated)
506
- * const valueBuffer = Buffer.from('PlayerOne\0');
507
- * const valuePtr = ptr(valueBuffer);
508
- * const value = new CString(valuePtr);
509
- * 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'));
510
403
  * ```
511
404
  */
512
405
  public cString(address: bigint, length: number): CString;
@@ -528,20 +421,15 @@ class Memory {
528
421
  }
529
422
 
530
423
  /**
531
- * Reads a 32-bit floating-point value from memory or writes a 32-bit floating-point value to memory.
532
- *
533
- * @param address - Memory address to read from or write to
534
- * @param value - Optional value to write. If omitted, performs a read operation
535
- * @returns The float value when reading, or this Memory instance when writing
536
- *
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.
537
428
  * @example
538
- * ```typescript
539
- * // Read a float value
540
- * const playerHealth = memory.f32(0x12345678n);
541
- * console.log('Player health:', playerHealth);
542
- *
543
- * // Write a float value
544
- * 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);
545
433
  * ```
546
434
  */
547
435
  public f32(address: bigint): number;
@@ -561,21 +449,15 @@ class Memory {
561
449
  }
562
450
 
563
451
  /**
564
- * Reads an array of 32-bit floating-point values from memory or writes an array of 32-bit floating-point values to memory.
565
- *
566
- * @param address - Memory address to read from or write to
567
- * @param lengthOrValues - Length of array to read, or array of values to write
568
- * @returns Float32Array when reading, or this Memory instance when writing
569
- *
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.
570
456
  * @example
571
- * ```typescript
572
- * // Read an array of 10 float values
573
- * const coordinates = memory.f32Array(0x12345678n, 10);
574
- * console.log('Coordinates:', coordinates);
575
- *
576
- * // Write an array of float values
577
- * const newCoordinates = new Float32Array([1.0, 2.5, 3.14, 4.2]);
578
- * 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]));
579
461
  * ```
580
462
  */
581
463
  public f32Array(address: bigint, length: number): Float32Array;
@@ -598,20 +480,15 @@ class Memory {
598
480
  }
599
481
 
600
482
  /**
601
- * Reads a 64-bit floating-point value from memory or writes a 64-bit floating-point value to memory.
602
- *
603
- * @param address - Memory address to read from or write to
604
- * @param value - Optional value to write. If omitted, performs a read operation
605
- * @returns The double value when reading, or this Memory instance when writing
606
- *
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.
607
487
  * @example
608
- * ```typescript
609
- * // Read a double precision value
610
- * const preciseValue = memory.f64(0x12345678n);
611
- * console.log('Precise value:', preciseValue);
612
- *
613
- * // Write a double precision value
614
- * 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);
615
492
  * ```
616
493
  */
617
494
  public f64(address: bigint): number;
@@ -631,21 +508,15 @@ class Memory {
631
508
  }
632
509
 
633
510
  /**
634
- * Reads an array of 64-bit floating-point values from memory or writes an array of 64-bit floating-point values to memory.
635
- *
636
- * @param address - Memory address to read from or write to
637
- * @param lengthOrValues - Length of array to read, or array of values to write
638
- * @returns Float64Array when reading, or this Memory instance when writing
639
- *
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.
640
515
  * @example
641
- * ```typescript
642
- * // Read an array of 5 double precision values
643
- * const preciseData = memory.f64Array(0x12345678n, 5);
644
- * console.log('Precise data:', preciseData);
645
- *
646
- * // Write an array of double precision values
647
- * const newData = new Float64Array([1.1, 2.2, 3.3, 4.4, 5.5]);
648
- * 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]));
649
520
  * ```
650
521
  */
651
522
  public f64Array(address: bigint, length: number): Float64Array;
@@ -668,20 +539,15 @@ class Memory {
668
539
  }
669
540
 
670
541
  /**
671
- * Reads a signed 16-bit integer value from memory or writes a signed 16-bit integer value to memory.
672
- *
673
- * @param address - Memory address to read from or write to
674
- * @param value - Optional value to write. If omitted, performs a read operation
675
- * @returns The int16 value when reading, or this Memory instance when writing
676
- *
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.
677
546
  * @example
678
- * ```typescript
679
- * // Read a signed 16-bit integer
680
- * const temperature = memory.i16(0x12345678n);
681
- * console.log('Temperature:', temperature);
682
- *
683
- * // Write a signed 16-bit integer
684
- * memory.i16(0x12345678n, -273);
547
+ * ```ts
548
+ * const cs2 = new Memory('cs2.exe');
549
+ * const myInt = cs2.i16(0x12345678n);
550
+ * cs2.i16(0x12345678n, 42);
685
551
  * ```
686
552
  */
687
553
  public i16(address: bigint): number;
@@ -701,21 +567,15 @@ class Memory {
701
567
  }
702
568
 
703
569
  /**
704
- * Reads an array of signed 16-bit integer values from memory or writes an array of signed 16-bit integer values to memory.
705
- *
706
- * @param address - Memory address to read from or write to
707
- * @param lengthOrValues - Length of array to read, or array of values to write
708
- * @returns Int16Array when reading, or this Memory instance when writing
709
- *
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.
710
574
  * @example
711
- * ```typescript
712
- * // Read an array of audio samples
713
- * const samples = memory.i16Array(0x12345678n, 1024);
714
- * console.log('Audio samples:', samples);
715
- *
716
- * // Write audio samples
717
- * const newSamples = new Int16Array([-100, 200, -300, 400]);
718
- * 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]));
719
579
  * ```
720
580
  */
721
581
  public i16Array(address: bigint, length: number): Int16Array;
@@ -738,20 +598,15 @@ class Memory {
738
598
  }
739
599
 
740
600
  /**
741
- * Reads a signed 32-bit integer value from memory or writes a signed 32-bit integer value to memory.
742
- *
743
- * @param address - Memory address to read from or write to
744
- * @param value - Optional value to write. If omitted, performs a read operation
745
- * @returns The int32 value when reading, or this Memory instance when writing
746
- *
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.
747
605
  * @example
748
- * ```typescript
749
- * // Read a player's score
750
- * const score = memory.i32(0x12345678n);
751
- * console.log('Player score:', score);
752
- *
753
- * // Set a new score
754
- * memory.i32(0x12345678n, 999999);
606
+ * ```ts
607
+ * const cs2 = new Memory('cs2.exe');
608
+ * const myInt = cs2.i32(0x12345678n);
609
+ * cs2.i32(0x12345678n, 42);
755
610
  * ```
756
611
  */
757
612
  public i32(address: bigint): number;
@@ -771,21 +626,15 @@ class Memory {
771
626
  }
772
627
 
773
628
  /**
774
- * Reads an array of signed 32-bit integer values from memory or writes an array of signed 32-bit integer values to memory.
775
- *
776
- * @param address - Memory address to read from or write to
777
- * @param lengthOrValues - Length of array to read, or array of values to write
778
- * @returns Int32Array when reading, or this Memory instance when writing
779
- *
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.
780
633
  * @example
781
- * ```typescript
782
- * // Read inventory item counts
783
- * const inventory = memory.i32Array(0x12345678n, 20);
784
- * console.log('Inventory:', inventory);
785
- *
786
- * // Set inventory values
787
- * const newInventory = new Int32Array([99, 50, 25, 10, 5]);
788
- * 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]));
789
638
  * ```
790
639
  */
791
640
  public i32Array(address: bigint, length: number): Int32Array;
@@ -808,20 +657,15 @@ class Memory {
808
657
  }
809
658
 
810
659
  /**
811
- * Reads a signed 64-bit integer value from memory or writes a signed 64-bit integer value to memory.
812
- *
813
- * @param address - Memory address to read from or write to
814
- * @param value - Optional value to write. If omitted, performs a read operation
815
- * @returns The int64 value when reading, or this Memory instance when writing
816
- *
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.
817
664
  * @example
818
- * ```typescript
819
- * // Read a large number (timestamp, file size, etc.)
820
- * const timestamp = memory.i64(0x12345678n);
821
- * console.log('Timestamp:', timestamp);
822
- *
823
- * // Write a large number
824
- * memory.i64(0x12345678n, 9223372036854775807n);
665
+ * ```ts
666
+ * const cs2 = new Memory('cs2.exe');
667
+ * const myBigInt = cs2.i64(0x12345678n);
668
+ * cs2.i64(0x12345678n, 123n);
825
669
  * ```
826
670
  */
827
671
  public i64(address: bigint): bigint;
@@ -841,21 +685,15 @@ class Memory {
841
685
  }
842
686
 
843
687
  /**
844
- * Reads an array of signed 64-bit integer values from memory or writes an array of signed 64-bit integer values to memory.
845
- *
846
- * @param address - Memory address to read from or write to
847
- * @param lengthOrValues - Length of array to read, or array of values to write
848
- * @returns BigInt64Array when reading, or this Memory instance when writing
849
- *
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.
850
692
  * @example
851
- * ```typescript
852
- * // Read an array of large numbers
853
- * const largeNumbers = memory.i64Array(0x12345678n, 10);
854
- * console.log('Large numbers:', largeNumbers);
855
- *
856
- * // Write an array of large numbers
857
- * const newNumbers = new BigInt64Array([1n, 2n, 3n, 4n, 5n]);
858
- * 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]));
859
697
  * ```
860
698
  */
861
699
  public i64Array(address: bigint, length: number): BigInt64Array;
@@ -878,20 +716,15 @@ class Memory {
878
716
  }
879
717
 
880
718
  /**
881
- * Reads a signed 8-bit integer value from memory or writes a signed 8-bit integer value to memory.
882
- *
883
- * @param address - Memory address to read from or write to
884
- * @param value - Optional value to write. If omitted, performs a read operation
885
- * @returns The int8 value when reading, or this Memory instance when writing
886
- *
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.
887
723
  * @example
888
- * ```typescript
889
- * // Read a small signed value (e.g., direction, state)
890
- * const direction = memory.i8(0x12345678n);
891
- * console.log('Direction:', direction);
892
- *
893
- * // Write a small signed value
894
- * memory.i8(0x12345678n, -127);
724
+ * ```ts
725
+ * const cs2 = new Memory('cs2.exe');
726
+ * const myInt = cs2.i8(0x12345678n);
727
+ * cs2.i8(0x12345678n, 7);
895
728
  * ```
896
729
  */
897
730
  public i8(address: bigint): number;
@@ -911,21 +744,15 @@ class Memory {
911
744
  }
912
745
 
913
746
  /**
914
- * Reads an array of signed 8-bit integer values from memory or writes an array of signed 8-bit integer values to memory.
915
- *
916
- * @param address - Memory address to read from or write to
917
- * @param lengthOrValues - Length of array to read, or array of values to write
918
- * @returns Int8Array when reading, or this Memory instance when writing
919
- *
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.
920
751
  * @example
921
- * ```typescript
922
- * // Read an array of small signed values
923
- * const directions = memory.i8Array(0x12345678n, 8);
924
- * console.log('Movement directions:', directions);
925
- *
926
- * // Write movement directions
927
- * const newDirections = new Int8Array([-1, 0, 1, -1, 0, 1, -1, 0]);
928
- * 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]));
929
756
  * ```
930
757
  */
931
758
  public i8Array(address: bigint, length: number): Int8Array;
@@ -948,28 +775,15 @@ class Memory {
948
775
  }
949
776
 
950
777
  /**
951
- * Reads a 3×3 matrix from memory or writes a 3×3 matrix to memory.
952
- *
953
- * The matrix is represented as 9 contiguous 32-bit floating-point values (`Float32Array`).
954
- * No transposition or stride is applied—values are copied exactly as stored in memory.
955
- *
956
- * @param address - Memory address to read from or write to
957
- * @param values - Optional `Float32Array` of length 9 to write. If omitted, performs a read operation
958
- * @returns `Float32Array` of length 9 when reading, or this `Memory` instance when writing
959
- * @throws {RangeError} When `values.length` is not exactly 9
960
- *
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.
961
782
  * @example
962
- * ```typescript
963
- * // Read a 3×3 matrix
964
- * const matrix = memory.matrix3x3(0x12345678n); // Float32Array(9)
965
- *
966
- * // Write a 3×3 matrix (length must be 9)
967
- * const next = new Float32Array([
968
- * 1, 0, 0,
969
- * 0, 1, 0,
970
- * 0, 0, 1
971
- * ]);
972
- * 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));
973
787
  * ```
974
788
  */
975
789
  public matrix3x3(address: bigint): Float32Array;
@@ -992,6 +806,18 @@ class Memory {
992
806
  return this;
993
807
  }
994
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
+ */
995
821
  public matrix3x4(address: bigint): Float32Array;
996
822
  public matrix3x4(address: bigint, values: Float32Array): this;
997
823
  public matrix3x4(address: bigint, values?: Float32Array): Float32Array | this {
@@ -1013,29 +839,15 @@ class Memory {
1013
839
  }
1014
840
 
1015
841
  /**
1016
- * Reads a 4×4 matrix from memory or writes a 4×4 matrix to memory.
1017
- *
1018
- * The matrix is represented as 16 contiguous 32-bit floating-point values (`Float32Array`).
1019
- * No transposition or stride is applied—values are copied exactly as stored in memory.
1020
- *
1021
- * @param address - Memory address to read from or write to
1022
- * @param values - Optional `Float32Array` of length 16 to write. If omitted, performs a read operation
1023
- * @returns `Float32Array` of length 16 when reading, or this `Memory` instance when writing
1024
- * @throws {RangeError} When `values.length` is not exactly 16
1025
- *
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.
1026
846
  * @example
1027
- * ```typescript
1028
- * // Read a 4×4 matrix
1029
- * const matrix = memory.matrix4x4(0x12345678n); // Float32Array(16)
1030
- *
1031
- * // Write a 4×4 matrix (length must be 16)
1032
- * const next = new Float32Array([
1033
- * 1, 0, 0, 0,
1034
- * 0, 1, 0, 0,
1035
- * 0, 0, 1, 0,
1036
- * 0, 0, 0, 1
1037
- * ]);
1038
- * 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));
1039
851
  * ```
1040
852
  */
1041
853
  public matrix4x4(address: bigint): Float32Array;
@@ -1059,31 +871,15 @@ class Memory {
1059
871
  }
1060
872
 
1061
873
  /**
1062
- * Reads a `NetworkUtlVector` (`Uint32Array`) from memory or writes a `NetworkUtlVector` to memory.
1063
- *
1064
- * The vector is represented in memory as a small header with an out-of-line elements buffer.
1065
- * Layout at `address`:
1066
- * - 0x00: `uint32` size (number of elements)
1067
- * - 0x04: `uint32` capacity/reserved (not modified by this method)
1068
- * - 0x08: `uint64` pointer to a contiguous array of `uint32` elements
1069
- *
1070
- * When reading, this method returns a `Uint32Array` containing `size` elements copied from the
1071
- * elements pointer. When writing, it updates the size field and writes the provided values to the
1072
- * existing elements buffer (no reallocation is performed).
1073
- *
1074
- * @param address - Memory address of the vector header to read from or write to
1075
- * @param values - Optional `NetworkUtlVector` to write. If omitted, performs a read operation
1076
- * @returns `NetworkUtlVector` when reading, or this `Memory` instance when writing
1077
- *
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.
1078
878
  * @example
1079
- * ```typescript
1080
- * // Read the current vector
1081
- * const ids = memory.networkUtlVector(0x12345678n);
1082
- * console.log('IDs:', Array.from(ids));
1083
- *
1084
- * // Write new values (must fit the existing buffer capacity)
1085
- * const next = new Uint32Array([10, 20, 30, 40]);
1086
- * 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]));
1087
883
  * ```
1088
884
  */
1089
885
  public networkUtlVector(address: bigint): NetworkUtlVector;
@@ -1109,24 +905,97 @@ class Memory {
1109
905
  }
1110
906
 
1111
907
  /**
1112
- * Reads a set of Euler angles from memory or writes a set of Euler angles to memory.
1113
- *
1114
- * Angles are stored as three 32-bit floats in the order **pitch, yaw, roll**.
1115
- *
1116
- * @param address - Memory address to read from or write to
1117
- * @param value - Optional `QAngle` to write. If omitted, performs a read operation
1118
- * @returns The `QAngle` value when reading, or this `Memory` instance when writing
1119
- *
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.
1120
944
  * @example
1121
- * ```typescript
1122
- * // Read current view angles
1123
- * const view = memory.qAngle(0x12345678n);
1124
- *
1125
- * // Write new view angles (e.g., level the roll)
1126
- * 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 }]);
1127
949
  * ```
1128
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);
983
+
984
+ return this;
985
+ }
1129
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
+ */
1130
999
  public qAngle(address: bigint): QAngle;
1131
1000
  public qAngle(address: bigint, value: QAngle): this;
1132
1001
  public qAngle(address: bigint, value?: QAngle): QAngle | this {
@@ -1150,22 +1019,15 @@ class Memory {
1150
1019
  }
1151
1020
 
1152
1021
  /**
1153
- * Reads an array of Euler angles from memory or writes an array of Euler angles to memory.
1154
- *
1155
- * Each element is three 32-bit floats in the order **pitch, yaw, roll**.
1156
- *
1157
- * @param address - Memory address to read from or write to
1158
- * @param lengthOrValues - Length of array to read, or array of `QAngle` values to write
1159
- * @returns `QAngle[]` when reading, or this `Memory` instance when writing
1160
- *
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.
1161
1026
  * @example
1162
- * ```typescript
1163
- * // Read bone aim offsets
1164
- * const bones = memory.qAngleArray(0x12345678n, 64);
1165
- *
1166
- * // Write new bone angles (e.g., reset all roll to zero)
1167
- * bones.forEach(b => (b.roll = 0));
1168
- * 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 }]);
1169
1031
  * ```
1170
1032
  */
1171
1033
  public qAngleArray(address: bigint, length: number): QAngle[];
@@ -1206,21 +1068,15 @@ class Memory {
1206
1068
  }
1207
1069
 
1208
1070
  /**
1209
- * Reads a quaternion (4D rotation) from memory or writes a quaternion to memory.
1210
- * Quaternions are stored as four 32-bit floats: x, y, z, w.
1211
- *
1212
- * @param address - Memory address to read from or write to
1213
- * @param value - Optional quaternion to write. If omitted, performs a read operation
1214
- * @returns The Quaternion object when reading, or this Memory instance when writing
1215
- *
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.
1216
1075
  * @example
1217
- * ```typescript
1218
- * // Read player rotation
1219
- * const rotation = memory.quaternion(0x12345678n);
1220
- * console.log('Player rotation:', rotation);
1221
- *
1222
- * // Set player rotation to identity
1223
- * 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 });
1224
1080
  * ```
1225
1081
  */
1226
1082
  public quaternion(address: bigint): Quaternion;
@@ -1248,21 +1104,15 @@ class Memory {
1248
1104
  }
1249
1105
 
1250
1106
  /**
1251
- * Reads an array of quaternions from memory or writes an array of quaternions to memory.
1252
- *
1253
- * @param address - Memory address to read from or write to
1254
- * @param lengthOrValues - Length of array to read, or array of quaternions to write
1255
- * @returns Array of Quaternion objects when reading, or this Memory instance when writing
1256
- *
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.
1257
1111
  * @example
1258
- * ```typescript
1259
- * // Read bone rotations for skeletal animation
1260
- * const boneRotations = memory.quaternionArray(0x12345678n, 50);
1261
- * console.log('Bone rotations:', boneRotations);
1262
- *
1263
- * // Set all bones to identity rotation
1264
- * const identityRotations = Array(50).fill({ x: 0, y: 0, z: 0, w: 1 });
1265
- * 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 }]);
1266
1116
  * ```
1267
1117
  */
1268
1118
  public quaternionArray(address: bigint, length: number): Quaternion[];
@@ -1306,20 +1156,81 @@ class Memory {
1306
1156
  }
1307
1157
 
1308
1158
  /**
1309
- * Reads an unsigned 16-bit integer value from memory or writes an unsigned 16-bit integer value to memory.
1310
- *
1311
- * @param address - Memory address to read from or write to
1312
- * @param value - Optional value to write. If omitted, performs a read operation
1313
- * @returns The uint16 value when reading, or this Memory instance when writing
1314
- *
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.
1315
1229
  * @example
1316
- * ```typescript
1317
- * // Read a port number or small positive value
1318
- * const port = memory.u16(0x12345678n);
1319
- * console.log('Network port:', port);
1320
- *
1321
- * // Write a port number
1322
- * memory.u16(0x12345678n, 8080);
1230
+ * ```ts
1231
+ * const cs2 = new Memory('cs2.exe');
1232
+ * const myInt = cs2.u16(0x12345678n);
1233
+ * cs2.u16(0x12345678n, 42);
1323
1234
  * ```
1324
1235
  */
1325
1236
  public u16(address: bigint): number;
@@ -1339,21 +1250,15 @@ class Memory {
1339
1250
  }
1340
1251
 
1341
1252
  /**
1342
- * Reads an array of unsigned 16-bit integer values from memory or writes an array of unsigned 16-bit integer values to memory.
1343
- *
1344
- * @param address - Memory address to read from or write to
1345
- * @param lengthOrValues - Length of array to read, or array of values to write
1346
- * @returns Uint16Array when reading, or this Memory instance when writing
1347
- *
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.
1348
1257
  * @example
1349
- * ```typescript
1350
- * // Read an array of port numbers
1351
- * const ports = memory.u16Array(0x12345678n, 10);
1352
- * console.log('Active ports:', ports);
1353
- *
1354
- * // Write port configuration
1355
- * const newPorts = new Uint16Array([80, 443, 8080, 3000, 5432]);
1356
- * 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]));
1357
1262
  * ```
1358
1263
  */
1359
1264
  public u16Array(address: bigint, length: number): Uint16Array;
@@ -1376,20 +1281,15 @@ class Memory {
1376
1281
  }
1377
1282
 
1378
1283
  /**
1379
- * Reads an unsigned 32-bit integer value from memory or writes an unsigned 32-bit integer value to memory.
1380
- *
1381
- * @param address - Memory address to read from or write to
1382
- * @param value - Optional value to write. If omitted, performs a read operation
1383
- * @returns The uint32 value when reading, or this Memory instance when writing
1384
- *
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.
1385
1288
  * @example
1386
- * ```typescript
1387
- * // Read player's money (always positive)
1388
- * const money = memory.u32(0x12345678n);
1389
- * console.log('Player money:', money);
1390
- *
1391
- * // Give player maximum money
1392
- * memory.u32(0x12345678n, 4294967295);
1289
+ * ```ts
1290
+ * const cs2 = new Memory('cs2.exe');
1291
+ * const myInt = cs2.u32(0x12345678n);
1292
+ * cs2.u32(0x12345678n, 42);
1393
1293
  * ```
1394
1294
  */
1395
1295
  public u32(address: bigint): number;
@@ -1409,21 +1309,15 @@ class Memory {
1409
1309
  }
1410
1310
 
1411
1311
  /**
1412
- * Reads an array of unsigned 32-bit integer values from memory or writes an array of unsigned 32-bit integer values to memory.
1413
- *
1414
- * @param address - Memory address to read from or write to
1415
- * @param lengthOrValues - Length of array to read, or array of values to write
1416
- * @returns Uint32Array when reading, or this Memory instance when writing
1417
- *
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.
1418
1316
  * @example
1419
- * ```typescript
1420
- * // Read resource amounts
1421
- * const resources = memory.u32Array(0x12345678n, 6);
1422
- * console.log('Resources:', resources);
1423
- *
1424
- * // Set resource amounts
1425
- * const newResources = new Uint32Array([1000, 2000, 3000, 4000, 5000, 6000]);
1426
- * 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]));
1427
1321
  * ```
1428
1322
  */
1429
1323
  public u32Array(address: bigint, length: number): Uint32Array;
@@ -1446,20 +1340,15 @@ class Memory {
1446
1340
  }
1447
1341
 
1448
1342
  /**
1449
- * Reads an unsigned 64-bit integer value from memory or writes an unsigned 64-bit integer value to memory.
1450
- *
1451
- * @param address - Memory address to read from or write to
1452
- * @param value - Optional value to write. If omitted, performs a read operation
1453
- * @returns The uint64 value when reading, or this Memory instance when writing
1454
- *
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.
1455
1347
  * @example
1456
- * ```typescript
1457
- * // Read a very large positive number
1458
- * const recordId = memory.u64(0x12345678n);
1459
- * console.log('Record ID:', recordId);
1460
- *
1461
- * // Write a very large positive number
1462
- * memory.u64(0x12345678n, 18446744073709551615n);
1348
+ * ```ts
1349
+ * const cs2 = new Memory('cs2.exe');
1350
+ * const myBigInt = cs2.u64(0x12345678n);
1351
+ * cs2.u64(0x12345678n, 123n);
1463
1352
  * ```
1464
1353
  */
1465
1354
  public u64(address: bigint): bigint;
@@ -1479,21 +1368,15 @@ class Memory {
1479
1368
  }
1480
1369
 
1481
1370
  /**
1482
- * Reads an array of unsigned 64-bit integer values from memory or writes an array of unsigned 64-bit integer values to memory.
1483
- *
1484
- * @param address - Memory address to read from or write to
1485
- * @param lengthOrValues - Length of array to read, or array of values to write
1486
- * @returns BigUint64Array when reading, or this Memory instance when writing
1487
- *
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.
1488
1375
  * @example
1489
- * ```typescript
1490
- * // Read an array of record IDs
1491
- * const recordIds = memory.u64Array(0x12345678n, 100);
1492
- * console.log('Record IDs:', recordIds);
1493
- *
1494
- * // Write record IDs
1495
- * const newIds = new BigUint64Array([1000n, 2000n, 3000n, 4000n]);
1496
- * 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]));
1497
1380
  * ```
1498
1381
  */
1499
1382
  public u64Array(address: bigint, length: number): BigUint64Array;
@@ -1516,20 +1399,15 @@ class Memory {
1516
1399
  }
1517
1400
 
1518
1401
  /**
1519
- * Reads an unsigned 8-bit integer value from memory or writes an unsigned 8-bit integer value to memory.
1520
- *
1521
- * @param address - Memory address to read from or write to
1522
- * @param value - Optional value to write. If omitted, performs a read operation
1523
- * @returns The uint8 value when reading, or this Memory instance when writing
1524
- *
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.
1525
1406
  * @example
1526
- * ```typescript
1527
- * // Read a byte value (0-255)
1528
- * const opacity = memory.u8(0x12345678n);
1529
- * console.log('UI opacity:', opacity);
1530
- *
1531
- * // Set opacity to maximum
1532
- * memory.u8(0x12345678n, 255);
1407
+ * ```ts
1408
+ * const cs2 = new Memory('cs2.exe');
1409
+ * const myInt = cs2.u8(0x12345678n);
1410
+ * cs2.u8(0x12345678n, 7);
1533
1411
  * ```
1534
1412
  */
1535
1413
  public u8(address: bigint): number;
@@ -1549,21 +1427,15 @@ class Memory {
1549
1427
  }
1550
1428
 
1551
1429
  /**
1552
- * Reads an array of unsigned 8-bit integer values from memory or writes an array of unsigned 8-bit integer values to memory.
1553
- *
1554
- * @param address - Memory address to read from or write to
1555
- * @param lengthOrValues - Length of array to read, or array of values to write
1556
- * @returns Uint8Array when reading, or this Memory instance when writing
1557
- *
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.
1558
1434
  * @example
1559
- * ```typescript
1560
- * // Read pixel data
1561
- * const pixels = memory.u8Array(0x12345678n, 1024);
1562
- * console.log('Pixel data:', pixels);
1563
- *
1564
- * // Write pixel data
1565
- * const newPixels = new Uint8Array([255, 128, 64, 32, 16, 8, 4, 2]);
1566
- * 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]));
1567
1439
  * ```
1568
1440
  */
1569
1441
  public u8Array(address: bigint, length: number): Uint8Array;
@@ -1586,117 +1458,107 @@ class Memory {
1586
1458
  }
1587
1459
 
1588
1460
  /**
1589
- * Reads a 2D vector from memory or writes a 2D vector to memory.
1590
- * Vectors are stored as two 32-bit floats: x, y.
1591
- *
1592
- * @param address - Memory address to read from or write to
1593
- * @param value - Optional vector to write. If omitted, performs a read operation
1594
- * @returns The Vector2 object when reading, or this Memory instance when writing
1595
- *
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.
1596
1465
  * @example
1597
- * ```typescript
1598
- * // Read player position
1599
- * const position = memory.vector2(0x12345678n);
1600
- * console.log('Player position:', position);
1601
- *
1602
- * // Teleport player to origin
1603
- * 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);
1604
1470
  * ```
1605
1471
  */
1606
- public vector2(address: bigint): Vector2;
1607
- public vector2(address: bigint, value: Vector2): this;
1608
- public vector2(address: bigint, value?: Vector2): Vector2 | this {
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?… 🫠…
1609
1476
  if (value === undefined) {
1610
- this.read(address, this.Scratch8);
1477
+ return this.u64(address);
1478
+ }
1611
1479
 
1612
- const x = f32(this.Scratch8.ptr);
1613
- const y = f32(this.Scratch8.ptr, 0x04);
1480
+ return this.u64(address, value);
1481
+ }
1614
1482
 
1615
- return { x, y };
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);
1616
1501
  }
1617
1502
 
1618
- this.Scratch8Buffer.writeFloatLE(value.x);
1619
- this.Scratch8Buffer.writeFloatLE(value.y, 0x04);
1503
+ return this.u64Array(address, lengthOrValues);
1504
+ }
1620
1505
 
1621
- this.write(address, this.Scratch8);
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
+ }
1622
1525
 
1623
- return this;
1526
+ return this.point(address, value);
1624
1527
  }
1625
1528
 
1626
1529
  /**
1627
- * Reads an array of 2D vectors from memory or writes an array of 2D vectors to memory.
1628
- *
1629
- * @param address - Memory address to read from or write to
1630
- * @param lengthOrValues - Length of array to read, or array of vectors to write
1631
- * @returns Array of Vector2 objects when reading, or this Memory instance when writing
1632
- *
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.
1633
1534
  * @example
1634
- * ```typescript
1635
- * // Read waypoints for AI pathfinding
1636
- * const waypoints = memory.vector2Array(0x12345678n, 20);
1637
- * console.log('AI waypoints:', waypoints);
1638
- *
1639
- * // Set new waypoints
1640
- * const newWaypoints = [
1641
- * { x: 10, y: 20 },
1642
- * { x: 30, y: 40 },
1643
- * { x: 50, y: 60 }
1644
- * ];
1645
- * 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 }]);
1646
1539
  * ```
1647
1540
  */
1648
1541
  public vector2Array(address: bigint, length: number): Vector2[];
1649
1542
  public vector2Array(address: bigint, values: Vector2[]): this;
1650
1543
  public vector2Array(address: bigint, lengthOrValues: Vector2[] | number): Vector2[] | this {
1544
+ // TypeScript is funny sometimes, isn't it?… 🫠…
1651
1545
  if (typeof lengthOrValues === 'number') {
1652
- const length = lengthOrValues;
1653
- const scratch = new Float32Array(length * 2);
1654
-
1655
- this.read(address, scratch);
1656
-
1657
- const result = new Array<Vector2>(length);
1658
-
1659
- for (let i = 0, j = 0; i < length; i++, j += 0x02) {
1660
- const x = scratch[j];
1661
- const y = scratch[j + 0x01];
1662
-
1663
- result[i] = { x, y };
1664
- }
1665
-
1666
- return result;
1667
- }
1668
-
1669
- const values = lengthOrValues;
1670
- const scratch = new Float32Array(values.length * 0x02);
1671
-
1672
- for (let i = 0, j = 0; i < values.length; i++, j += 0x02) {
1673
- const vector2 = values[i];
1674
-
1675
- scratch[j] = vector2.x;
1676
- scratch[j + 0x01] = vector2.y;
1546
+ return this.pointArray(address, lengthOrValues);
1677
1547
  }
1678
1548
 
1679
- this.write(address, scratch);
1680
-
1681
- return this;
1549
+ return this.pointArray(address, lengthOrValues);
1682
1550
  }
1683
1551
 
1684
1552
  /**
1685
- * Reads a 3D vector from memory or writes a 3D vector to memory.
1686
- * Vectors are stored as three 32-bit floats: x, y, z.
1687
- *
1688
- * @param address - Memory address to read from or write to
1689
- * @param value - Optional vector to write. If omitted, performs a read operation
1690
- * @returns The Vector3 object when reading, or this Memory instance when writing
1691
- *
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.
1692
1557
  * @example
1693
- * ```typescript
1694
- * // Read player 3D position
1695
- * const position = memory.vector3(0x12345678n);
1696
- * console.log('Player 3D position:', position);
1697
- *
1698
- * // Teleport player to specific location
1699
- * 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 });
1700
1562
  * ```
1701
1563
  */
1702
1564
  public vector3(address: bigint): Vector3;
@@ -1722,25 +1584,15 @@ class Memory {
1722
1584
  }
1723
1585
 
1724
1586
  /**
1725
- * Reads an array of 3D vectors from memory or writes an array of 3D vectors to memory.
1726
- *
1727
- * @param address - Memory address to read from or write to
1728
- * @param lengthOrValues - Length of array to read, or array of vectors to write
1729
- * @returns Array of Vector3 objects when reading, or this Memory instance when writing
1730
- *
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.
1731
1591
  * @example
1732
- * ```typescript
1733
- * // Read vertex positions for 3D model
1734
- * const vertices = memory.vector3Array(0x12345678n, 500);
1735
- * console.log('3D vertices:', vertices);
1736
- *
1737
- * // Update vertex positions
1738
- * const newVertices = [
1739
- * { x: 1.0, y: 0.0, z: 0.0 },
1740
- * { x: 0.0, y: 1.0, z: 0.0 },
1741
- * { x: 0.0, y: 0.0, z: 1.0 }
1742
- * ];
1743
- * 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 }]);
1744
1596
  * ```
1745
1597
  */
1746
1598
  public vector3Array(address: bigint, length: number): Vector3[];
@@ -1782,22 +1634,15 @@ class Memory {
1782
1634
  }
1783
1635
 
1784
1636
  /**
1785
- * Reads a 4D vector from memory or writes a 4D vector to memory.
1786
- *
1787
- * Uses the same 16-byte layout as {@link Memory.quaternion}: four 32-bit floats
1788
- * stored in the order **x, y, z, w**. Returned objects are shaped as `{ w, x, y, z }`.
1789
- *
1790
- * @param address - Memory address to read from or write to
1791
- * @param value - Optional `Vector4` to write. If omitted, performs a read operation
1792
- * @returns The `Vector4` value when reading, or this `Memory` instance when writing
1793
- *
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.
1794
1641
  * @example
1795
- * ```typescript
1796
- * // Read directional data in projective space
1797
- * const value = memory.vector4(0x12345678n);
1798
- *
1799
- * // Write a vector4 value (e.g., identity quaternion)
1800
- * 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 });
1801
1646
  * ```
1802
1647
  */
1803
1648
  public vector4(address: bigint): Vector4;
@@ -1812,23 +1657,15 @@ class Memory {
1812
1657
  }
1813
1658
 
1814
1659
  /**
1815
- * Reads an array of 4D vectors from memory or writes an array of 4D vectors to memory.
1816
- *
1817
- * Each element uses the same 16-byte layout as {@link Memory.quaternionArray}:
1818
- * four 32-bit floats stored in the order **x, y, z, w**.
1819
- *
1820
- * @param address - Memory address to read from or write to
1821
- * @param lengthOrValues - Length of array to read, or array of `Vector4` values to write
1822
- * @returns `Vector4[]` when reading, or this `Memory` instance when writing
1823
- *
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.
1824
1664
  * @example
1825
- * ```typescript
1826
- * // Read per-vertex tangent vectors (xyzw)
1827
- * const tangents = memory.vector4Array(0x12345678n, 1024);
1828
- *
1829
- * // Write tangent vectors (eg. normalize w to 1.0)
1830
- * tangents.forEach(v => (v.w = 1.0));
1831
- * 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 }]);
1832
1669
  * ```
1833
1670
  */
1834
1671
  public vector4Array(address: bigint, length: number): Vector4[];
@@ -1845,37 +1682,17 @@ class Memory {
1845
1682
  // Public utility methods…
1846
1683
 
1847
1684
  /**
1848
- * Searches a memory range for a byte sequence and returns the absolute address of the first match.
1849
- *
1850
- * This method reads `length` bytes starting at `address` into a temporary buffer and performs a
1851
- * subsequence search. No region or protection checking is performed; ensure the range is readable
1852
- * before calling.
1853
- *
1854
- * The `needle` accepts any Scratch-compatible buffer or view (`Buffer`, `TypedArray`, or `DataView`).
1855
- * Bytes are matched exactly as laid out in memory. :contentReference[oaicite:0]{index=0}
1856
- *
1857
- * @param needle - Byte sequence to search for (Scratch-compatible buffer or view)
1858
- * @param address - Base memory address to begin searching (inclusive)
1859
- * @param length - Number of bytes to scan
1860
- * @returns Absolute address (`bigint`) of the first match, or `-1n` when not found
1861
- *
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.
1862
1690
  * @example
1863
- * ```typescript
1864
- * // Search a loaded module for a byte sequence
1865
- * const client = memory.modules['client.dll'];
1866
- *
1867
- * const needle = Buffer.from([0x48, 0x8B, 0x05, 0x00, 0x00, 0x00, 0x00]);
1868
- * const matchAddress = memory.indexOf(needle, client.base, client.size);
1869
- * ```
1870
- *
1871
- * @example
1872
- * ```typescript
1873
- * // Search using a Uint32Array needle (bytes are matched exactly as laid out in memory)
1874
- * const needle = new Uint32Array([0xDEADBEEF, 0x11223344]);
1875
- * 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);
1876
1694
  * ```
1877
1695
  */
1878
-
1879
1696
  public indexOf(needle: Scratch, address: bigint, length: number): bigint {
1880
1697
  const haystackUint8Array = new Uint8Array(length);
1881
1698