bun-memory 1.1.23 → 1.1.24

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.
@@ -1,4 +1,4 @@
1
- import { CString, FFIType, dlopen, ptr } from 'bun:ffi';
1
+ import { FFIType, dlopen } from 'bun:ffi';
2
2
  import { sleep } from 'bun';
3
3
 
4
4
  import Memory from '../index.ts';
@@ -28,16 +28,15 @@ const { C_BaseEntity, C_BasePlayerPawn, C_BasePlayerWeapon, C_CSPlayerPawn, C_CS
28
28
  };
29
29
 
30
30
  // Load the needed offsets as bigints…
31
- const { dwEntityList, dwGlobalVars, dwLocalPlayerController, dwLocalPlayerPawn } = Object.fromEntries(
32
- Object.entries(OffsetsJSON['client.dll']).map(([key, value]) => [key, BigInt(value)]) //
31
+ const {
32
+ 'client.dll': { dwEntityList, dwGlobalVars, dwLocalPlayerController, dwLocalPlayerPawn },
33
+ 'engine2.dll': {},
34
+ } = Object.fromEntries(
35
+ Object.entries(OffsetsJSON).map(([name, section]) => [name, Object.fromEntries(Object.entries(section).map(([key, value]) => [key, BigInt(value as number)]))]) //
33
36
  ) as {
34
- [K in keyof (typeof OffsetsJSON)['client.dll']]: bigint;
37
+ [M in keyof typeof OffsetsJSON]: { [K in keyof (typeof OffsetsJSON)[M]]: bigint };
35
38
  };
36
39
 
37
- const a: bigint[] = [1n];
38
-
39
- console.log(typeof a);
40
-
41
40
  // Open a handle to cs2.exe…
42
41
  const cs2 = new Memory('cs2.exe');
43
42
 
@@ -107,9 +106,7 @@ async function tick(ClientPtr: bigint) {
107
106
  return;
108
107
  } else if (Local_NextPrimaryAttackTick > Local_TickBase) {
109
108
  return;
110
- } else if (Local_WeaponType === 0 || Local_WeaponType === 9) {
111
- return;
112
- } else if (Local_WeaponType === 5 && !(Local_IsScoped && Local_ZoomLevel !== 0)) {
109
+ } else if (Local_WeaponType === 0 || (Local_WeaponType === 5 && !(Local_IsScoped && Local_ZoomLevel !== 0)) || Local_WeaponType === 7 || Local_WeaponType === 9) {
113
110
  return;
114
111
  }
115
112
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bugs": {
4
4
  "url": "https://github.com/obscuritysrl/bun-memory/issues"
5
5
  },
6
- "description": "Fast Windows process memory utilities for Bun using bun:ffi.",
6
+ "description": "Blazing fast, high-performance Windows process memory manipulation for Bun.",
7
7
  "devDependencies": {
8
8
  "@types/bun": "latest"
9
9
  },
@@ -22,7 +22,7 @@
22
22
  "url": "git://github.com/obscuritysrl/bun-memory.git"
23
23
  },
24
24
  "type": "module",
25
- "version": "1.1.23",
25
+ "version": "1.1.24",
26
26
  "main": "./index.ts",
27
27
  "keywords": [
28
28
  "bun",
package/structs/Memory.ts CHANGED
@@ -1,14 +1,13 @@
1
- import { CString, FFIType, dlopen, read } from 'bun:ffi';
1
+ import { CString, FFIType, dlopen } from 'bun:ffi';
2
2
 
3
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
- const { f32, f64, i16, i32, i64, i8, u16, u32, u64, u8 } = read;
7
-
8
6
  const { symbols: Kernel32 } = dlopen('kernel32.dll', {
9
7
  CloseHandle: { args: [FFIType.u64], returns: FFIType.bool },
10
8
  CreateToolhelp32Snapshot: { args: [FFIType.u32, FFIType.u32], returns: FFIType.u64 },
11
9
  GetLastError: { returns: FFIType.u32 },
10
+ IsWow64Process2: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr], returns: FFIType.bool },
12
11
  Module32FirstW: { args: [FFIType.u64, FFIType.ptr], returns: FFIType.bool },
13
12
  Module32NextW: { args: [FFIType.u64, FFIType.ptr], returns: FFIType.bool },
14
13
  OpenProcess: { args: [FFIType.u32, FFIType.bool, FFIType.u32], returns: FFIType.u64 },
@@ -25,6 +24,10 @@ const { symbols: Kernel32 } = dlopen('kernel32.dll', {
25
24
  *
26
25
  * Use this class to read and write memory, access modules, and work with common data structures in external processes.
27
26
  *
27
+ * Many scalar reads utilize `TypedArray` scratches to avoid a second FFI hop, such as calling `bun:ffi.read.*`.
28
+ *
29
+ * @todo Add support for 32 or 64-bit processes using IsWow64Process2 (Windows 10+).
30
+ *
28
31
  * @example
29
32
  * ```ts
30
33
  * import Memory from './structs/Memory';
@@ -87,6 +90,7 @@ class Memory {
87
90
  }
88
91
 
89
92
  this._modules = {};
93
+
90
94
  this.hProcess = hProcess;
91
95
  this.th32ProcessID = th32ProcessID;
92
96
 
@@ -118,29 +122,38 @@ class Memory {
118
122
  private _modules: { [key: string]: Module };
119
123
 
120
124
  private readonly Scratch1 = new Uint8Array(0x01);
125
+ private readonly Scratch1Int8Array = new Int8Array(this.Scratch1.buffer, this.Scratch1.byteOffset, 0x01);
126
+
121
127
  private readonly Scratch2 = new Uint8Array(0x02);
128
+ private readonly Scratch2Int16Array = new Int16Array(this.Scratch2.buffer, this.Scratch2.byteOffset, 0x01);
129
+ private readonly Scratch2Uint16Array = new Uint16Array(this.Scratch2.buffer, this.Scratch2.byteOffset, 0x01);
130
+
122
131
  private readonly Scratch3 = new Uint8Array(0x03);
132
+
123
133
  private readonly Scratch4 = new Uint8Array(0x04);
134
+ private readonly Scratch4Float32Array = new Float32Array(this.Scratch4.buffer, this.Scratch4.byteOffset, 0x01);
135
+ private readonly Scratch4Int32Array = new Int32Array(this.Scratch4.buffer, this.Scratch4.byteOffset, 0x01);
136
+ private readonly Scratch4Uint32Array = new Uint32Array(this.Scratch4.buffer, this.Scratch4.byteOffset, 0x01);
137
+
124
138
  private readonly Scratch8 = new Uint8Array(0x08);
139
+ private readonly Scratch8BigInt64Array = new BigInt64Array(this.Scratch8.buffer, this.Scratch8.byteOffset, 0x01);
140
+ private readonly Scratch8BigUint64Array = new BigUint64Array(this.Scratch8.buffer, this.Scratch8.byteOffset, 0x01);
141
+ private readonly Scratch8Float32Array = new Float32Array(this.Scratch8.buffer, this.Scratch8.byteOffset, 0x02);
142
+ private readonly Scratch8Float64Array = new Float64Array(this.Scratch8.buffer, this.Scratch8.byteOffset, 0x01);
143
+
125
144
  private readonly Scratch12 = new Uint8Array(0x0c);
126
- private readonly Scratch16 = new Uint8Array(0x10);
145
+ private readonly Scratch12Float32Array = new Float32Array(this.Scratch12.buffer, this.Scratch12.byteOffset, 0x03);
127
146
 
128
- private readonly Scratch1Buffer = Buffer.from(this.Scratch1.buffer, this.Scratch1.byteOffset, this.Scratch1.byteLength);
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);
131
- private readonly Scratch4Buffer = Buffer.from(this.Scratch4.buffer, this.Scratch4.byteOffset, this.Scratch4.byteLength);
132
- private readonly Scratch8Buffer = Buffer.from(this.Scratch8.buffer, this.Scratch8.byteOffset, this.Scratch8.byteLength);
133
- private readonly Scratch12Buffer = Buffer.from(this.Scratch12.buffer, this.Scratch12.byteOffset, this.Scratch12.byteLength);
134
- private readonly Scratch16Buffer = Buffer.from(this.Scratch16.buffer, this.Scratch16.byteOffset, this.Scratch16.byteLength);
147
+ private readonly Scratch16 = new Uint8Array(0x10);
148
+ private readonly Scratch16Float32Array = new Float32Array(this.Scratch16.buffer, this.Scratch16.byteOffset, 0x04);
135
149
 
136
150
  private readonly ScratchMemoryBasicInformation = Buffer.allocUnsafe(0x30 /* sizeof(MEMORY_BASIC_INFORMATION) */);
137
151
  private readonly ScratchModuleEntry32W = Buffer.allocUnsafe(0x438 /* sizeof(MODULEENTRY32W) */);
138
152
 
139
- private static readonly TextDecoderUTF16 = new TextDecoder('utf-16');
140
- private static readonly TextDecoderUTF8 = new TextDecoder('utf-8');
153
+ private static TextDecoderUTF16 = new TextDecoder('utf-16');
154
+ private static TextDecoderUTF8 = new TextDecoder('utf-8');
141
155
 
142
156
  private readonly hProcess: bigint;
143
-
144
157
  private readonly th32ProcessID: number;
145
158
 
146
159
  /**
@@ -149,7 +162,7 @@ class Memory {
149
162
  * @example
150
163
  * ```ts
151
164
  * const cs2 = new Memory('cs2.exe');
152
- * const modules = cs2.modules;
165
+ * const client = cs2.modules['client.dll'];
153
166
  * ```
154
167
  */
155
168
  public get modules(): Memory['_modules'] {
@@ -345,15 +358,15 @@ class Memory {
345
358
  public bool(address: bigint): boolean;
346
359
  public bool(address: bigint, value: boolean): this;
347
360
  public bool(address: bigint, value?: boolean): boolean | this {
348
- if (value === undefined) {
349
- this.read(address, this.Scratch1);
361
+ const Scratch1 = this.Scratch1;
350
362
 
351
- return u8(this.Scratch1.ptr) !== 0;
363
+ if (value === undefined) {
364
+ return this.read(address, Scratch1)[0x00] !== 0;
352
365
  }
353
366
 
354
- this.Scratch1Buffer.writeUInt8(+value);
367
+ Scratch1[0x00] = value ? 1 : 0;
355
368
 
356
- this.write(address, this.Scratch1);
369
+ this.write(address, Scratch1);
357
370
 
358
371
  return this;
359
372
  }
@@ -375,12 +388,9 @@ class Memory {
375
388
  public buffer(address: bigint, lengthOrValue: number | Buffer): Buffer | this {
376
389
  if (typeof lengthOrValue === 'number') {
377
390
  const length = lengthOrValue;
378
-
379
391
  const scratch = Buffer.allocUnsafe(length);
380
392
 
381
- this.read(address, scratch);
382
-
383
- return scratch;
393
+ return this.read(address, scratch);
384
394
  }
385
395
 
386
396
  const value = lengthOrValue;
@@ -435,15 +445,15 @@ class Memory {
435
445
  public f32(address: bigint): number;
436
446
  public f32(address: bigint, value: number): this;
437
447
  public f32(address: bigint, value?: number): number | this {
438
- if (value === undefined) {
439
- this.read(address, this.Scratch4);
448
+ const Scratch4Float32Array = this.Scratch4Float32Array; // prettier-ignore
440
449
 
441
- return f32(this.Scratch4.ptr);
450
+ if (value === undefined) {
451
+ return this.read(address, Scratch4Float32Array)[0x00];
442
452
  }
443
453
 
444
- this.Scratch4Buffer.writeFloatLE(value);
454
+ Scratch4Float32Array[0x00] = value;
445
455
 
446
- this.write(address, this.Scratch4);
456
+ this.write(address, Scratch4Float32Array);
447
457
 
448
458
  return this;
449
459
  }
@@ -494,15 +504,15 @@ class Memory {
494
504
  public f64(address: bigint): number;
495
505
  public f64(address: bigint, value: number): this;
496
506
  public f64(address: bigint, value?: number): number | this {
497
- if (value === undefined) {
498
- this.read(address, this.Scratch8);
507
+ const Scratch8Float64Array = this.Scratch8Float64Array; // prettier-ignore
499
508
 
500
- return f64(this.Scratch8.ptr);
509
+ if (value === undefined) {
510
+ return this.read(address, Scratch8Float64Array)[0x00];
501
511
  }
502
512
 
503
- this.Scratch8Buffer.writeDoubleLE(value);
513
+ Scratch8Float64Array[0x00] = value;
504
514
 
505
- this.write(address, this.Scratch8);
515
+ this.write(address, Scratch8Float64Array);
506
516
 
507
517
  return this;
508
518
  }
@@ -553,15 +563,15 @@ class Memory {
553
563
  public i16(address: bigint): number;
554
564
  public i16(address: bigint, value: number): this;
555
565
  public i16(address: bigint, value?: number): number | this {
556
- if (value === undefined) {
557
- this.read(address, this.Scratch2);
566
+ const Scratch2Int16Array = this.Scratch2Int16Array; // prettier-ignore
558
567
 
559
- return i16(this.Scratch2.ptr);
568
+ if (value === undefined) {
569
+ return this.read(address, Scratch2Int16Array)[0x00];
560
570
  }
561
571
 
562
- this.Scratch2Buffer.writeInt16LE(value);
572
+ Scratch2Int16Array[0x00] = value;
563
573
 
564
- this.write(address, this.Scratch2);
574
+ this.write(address, Scratch2Int16Array);
565
575
 
566
576
  return this;
567
577
  }
@@ -612,15 +622,15 @@ class Memory {
612
622
  public i32(address: bigint): number;
613
623
  public i32(address: bigint, value: number): this;
614
624
  public i32(address: bigint, value?: number): number | this {
615
- if (value === undefined) {
616
- this.read(address, this.Scratch4);
625
+ const Scratch4Int32Array = this.Scratch4Int32Array;
617
626
 
618
- return i32(this.Scratch4.ptr);
627
+ if (value === undefined) {
628
+ return this.read(address, Scratch4Int32Array)[0x00];
619
629
  }
620
630
 
621
- this.Scratch4Buffer.writeInt32LE(value);
631
+ Scratch4Int32Array[0x00] = value;
622
632
 
623
- this.write(address, this.Scratch4);
633
+ this.write(address, Scratch4Int32Array);
624
634
 
625
635
  return this;
626
636
  }
@@ -671,15 +681,15 @@ class Memory {
671
681
  public i64(address: bigint): bigint;
672
682
  public i64(address: bigint, value: bigint): this;
673
683
  public i64(address: bigint, value?: bigint): bigint | this {
674
- if (value === undefined) {
675
- this.read(address, this.Scratch8);
684
+ const Scratch8BigInt64Array = this.Scratch8BigInt64Array;
676
685
 
677
- return i64(this.Scratch8.ptr);
686
+ if (value === undefined) {
687
+ return this.read(address, Scratch8BigInt64Array)[0x00];
678
688
  }
679
689
 
680
- this.Scratch8Buffer.writeBigInt64LE(value);
690
+ Scratch8BigInt64Array[0x00] = value;
681
691
 
682
- this.write(address, this.Scratch8);
692
+ this.write(address, Scratch8BigInt64Array);
683
693
 
684
694
  return this;
685
695
  }
@@ -730,15 +740,15 @@ class Memory {
730
740
  public i8(address: bigint): number;
731
741
  public i8(address: bigint, value: number): this;
732
742
  public i8(address: bigint, value?: number): number | this {
733
- if (value === undefined) {
734
- this.read(address, this.Scratch1);
743
+ const Scratch1Int8Array = this.Scratch1Int8Array;
735
744
 
736
- return i8(this.Scratch1.ptr);
745
+ if (value === undefined) {
746
+ return this.read(address, Scratch1Int8Array)[0x00];
737
747
  }
738
748
 
739
- this.Scratch1Buffer.writeInt8(value);
749
+ Scratch1Int8Array[0x00] = value;
740
750
 
741
- this.write(address, this.Scratch1);
751
+ this.write(address, Scratch1Int8Array);
742
752
 
743
753
  return this;
744
754
  }
@@ -919,19 +929,21 @@ class Memory {
919
929
  public point(address: bigint): Point;
920
930
  public point(address: bigint, value: Point): this;
921
931
  public point(address: bigint, value?: Point): Point | this {
932
+ const Scratch8Float32Array = this.Scratch8Float32Array;
933
+
922
934
  if (value === undefined) {
923
- this.read(address, this.Scratch8);
935
+ this.read(address, Scratch8Float32Array);
924
936
 
925
- const x = f32(this.Scratch8.ptr);
926
- const y = f32(this.Scratch8.ptr, 0x04);
937
+ const x = Scratch8Float32Array[0x00],
938
+ y = Scratch8Float32Array[0x01]; // prettier-ignore
927
939
 
928
940
  return { x, y };
929
941
  }
930
942
 
931
- this.Scratch8Buffer.writeFloatLE(value.x);
932
- this.Scratch8Buffer.writeFloatLE(value.y, 0x04);
943
+ Scratch8Float32Array[0x00] = value.x;
944
+ Scratch8Float32Array[0x01] = value.y;
933
945
 
934
- this.write(address, this.Scratch8);
946
+ this.write(address, Scratch8Float32Array);
935
947
 
936
948
  return this;
937
949
  }
@@ -999,21 +1011,23 @@ class Memory {
999
1011
  public qAngle(address: bigint): QAngle;
1000
1012
  public qAngle(address: bigint, value: QAngle): this;
1001
1013
  public qAngle(address: bigint, value?: QAngle): QAngle | this {
1014
+ const Scratch12Float32Array = this.Scratch12Float32Array;
1015
+
1002
1016
  if (value === undefined) {
1003
- this.read(address, this.Scratch12);
1017
+ this.read(address, Scratch12Float32Array);
1004
1018
 
1005
- const pitch = f32(this.Scratch12.ptr);
1006
- const roll = f32(this.Scratch12.ptr, 0x08);
1007
- const yaw = f32(this.Scratch12.ptr, 0x04);
1019
+ const pitch = Scratch12Float32Array[0x00],
1020
+ roll = Scratch12Float32Array[0x02],
1021
+ yaw = Scratch12Float32Array[0x01]; // prettier-ignore
1008
1022
 
1009
1023
  return { pitch, roll, yaw };
1010
1024
  }
1011
1025
 
1012
- this.Scratch12Buffer.writeFloatLE(value.pitch);
1013
- this.Scratch12Buffer.writeFloatLE(value.roll, 0x08);
1014
- this.Scratch12Buffer.writeFloatLE(value.yaw, 0x04);
1026
+ Scratch12Float32Array[0x00] = value.pitch;
1027
+ Scratch12Float32Array[0x02] = value.roll;
1028
+ Scratch12Float32Array[0x01] = value.yaw;
1015
1029
 
1016
- this.write(address, this.Scratch12);
1030
+ this.write(address, Scratch12Float32Array);
1017
1031
 
1018
1032
  return this;
1019
1033
  }
@@ -1082,23 +1096,25 @@ class Memory {
1082
1096
  public quaternion(address: bigint): Quaternion;
1083
1097
  public quaternion(address: bigint, value: Quaternion): this;
1084
1098
  public quaternion(address: bigint, value?: Quaternion): Quaternion | this {
1099
+ const Scratch16Float32Array = this.Scratch16Float32Array;
1100
+
1085
1101
  if (value === undefined) {
1086
- this.read(address, this.Scratch16);
1102
+ this.read(address, Scratch16Float32Array);
1087
1103
 
1088
- const w = f32(this.Scratch16.ptr, 0x0c);
1089
- const x = f32(this.Scratch16.ptr);
1090
- const y = f32(this.Scratch16.ptr, 0x04);
1091
- const z = f32(this.Scratch16.ptr, 0x08);
1104
+ const w = Scratch16Float32Array[0x03],
1105
+ x = Scratch16Float32Array[0x00],
1106
+ y = Scratch16Float32Array[0x01],
1107
+ z = Scratch16Float32Array[0x02]; // prettier-ignore
1092
1108
 
1093
1109
  return { w, x, y, z };
1094
1110
  }
1095
1111
 
1096
- this.Scratch16Buffer.writeFloatLE(value.w, 0x0c);
1097
- this.Scratch16Buffer.writeFloatLE(value.x);
1098
- this.Scratch16Buffer.writeFloatLE(value.y, 0x04);
1099
- this.Scratch16Buffer.writeFloatLE(value.z, 0x08);
1112
+ Scratch16Float32Array[0x03] = value.w;
1113
+ Scratch16Float32Array[0x00] = value.x;
1114
+ Scratch16Float32Array[0x01] = value.y;
1115
+ Scratch16Float32Array[0x02] = value.z;
1100
1116
 
1101
- this.write(address, this.Scratch16);
1117
+ this.write(address, Scratch16Float32Array);
1102
1118
 
1103
1119
  return this;
1104
1120
  }
@@ -1170,21 +1186,23 @@ class Memory {
1170
1186
  public rgb(address: bigint): RGB;
1171
1187
  public rgb(address: bigint, value: RGB): this;
1172
1188
  public rgb(address: bigint, value?: RGB): RGB | this {
1189
+ const Scratch3 = this.Scratch3;
1190
+
1173
1191
  if (value === undefined) {
1174
- this.read(address, this.Scratch4);
1192
+ this.read(address, Scratch3);
1175
1193
 
1176
- const r = this.Scratch3Buffer.readUInt8(),
1177
- g = this.Scratch3Buffer.readUInt8(0x01),
1178
- b = this.Scratch3Buffer.readUInt8(0x02); // prettier-ignore
1194
+ const r = Scratch3[0x00],
1195
+ g = Scratch3[0x01],
1196
+ b = Scratch3[0x02]; // prettier-ignore
1179
1197
 
1180
1198
  return { r, g, b };
1181
1199
  }
1182
1200
 
1183
- this.Scratch3Buffer.writeUInt8(value.r);
1184
- this.Scratch3Buffer.writeUInt8(value.g, 0x01);
1185
- this.Scratch3Buffer.writeUInt8(value.b, 0x02);
1201
+ Scratch3[0x00] = value.r;
1202
+ Scratch3[0x01] = value.g;
1203
+ Scratch3[0x02] = value.b;
1186
1204
 
1187
- return this.write(address, this.Scratch4);
1205
+ return this.write(address, Scratch3);
1188
1206
  }
1189
1207
 
1190
1208
  /**
@@ -1202,23 +1220,25 @@ class Memory {
1202
1220
  public rgba(address: bigint): RGBA;
1203
1221
  public rgba(address: bigint, value: RGBA): this;
1204
1222
  public rgba(address: bigint, value?: RGBA): RGBA | this {
1223
+ const Scratch4 = this.Scratch4;
1224
+
1205
1225
  if (value === undefined) {
1206
- this.read(address, this.Scratch4);
1226
+ this.read(address, Scratch4);
1207
1227
 
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
1228
+ const r = Scratch4[0x00],
1229
+ g = Scratch4[0x01],
1230
+ b = Scratch4[0x02],
1231
+ a = Scratch4[0x03]; // prettier-ignore
1212
1232
 
1213
1233
  return { r, g, b, a };
1214
1234
  }
1215
1235
 
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);
1236
+ Scratch4[0x00] = value.r;
1237
+ Scratch4[0x01] = value.g;
1238
+ Scratch4[0x02] = value.b;
1239
+ Scratch4[0x03] = value.a;
1220
1240
 
1221
- return this.write(address, this.Scratch4);
1241
+ return this.write(address, Scratch4);
1222
1242
  }
1223
1243
 
1224
1244
  /**
@@ -1236,15 +1256,15 @@ class Memory {
1236
1256
  public u16(address: bigint): number;
1237
1257
  public u16(address: bigint, value: number): this;
1238
1258
  public u16(address: bigint, value?: number): number | this {
1239
- if (value === undefined) {
1240
- this.read(address, this.Scratch2);
1259
+ const Scratch2Uint16Array = this.Scratch2Uint16Array;
1241
1260
 
1242
- return u16(this.Scratch2.ptr);
1261
+ if (value === undefined) {
1262
+ return this.read(address, Scratch2Uint16Array)[0x00];
1243
1263
  }
1244
1264
 
1245
- this.Scratch2Buffer.writeUInt16LE(value);
1265
+ Scratch2Uint16Array[0x00] = value;
1246
1266
 
1247
- this.write(address, this.Scratch2);
1267
+ this.write(address, Scratch2Uint16Array);
1248
1268
 
1249
1269
  return this;
1250
1270
  }
@@ -1295,15 +1315,15 @@ class Memory {
1295
1315
  public u32(address: bigint): number;
1296
1316
  public u32(address: bigint, value: number): this;
1297
1317
  public u32(address: bigint, value?: number): number | this {
1298
- if (value === undefined) {
1299
- this.read(address, this.Scratch4);
1318
+ const Scratch4Uint32Array = this.Scratch4Uint32Array;
1300
1319
 
1301
- return u32(this.Scratch4.ptr);
1320
+ if (value === undefined) {
1321
+ return this.read(address, Scratch4Uint32Array)[0x00];
1302
1322
  }
1303
1323
 
1304
- this.Scratch4Buffer.writeUInt32LE(value);
1324
+ Scratch4Uint32Array[0x00] = value;
1305
1325
 
1306
- this.write(address, this.Scratch4);
1326
+ this.write(address, Scratch4Uint32Array);
1307
1327
 
1308
1328
  return this;
1309
1329
  }
@@ -1354,15 +1374,15 @@ class Memory {
1354
1374
  public u64(address: bigint): bigint;
1355
1375
  public u64(address: bigint, value: bigint): this;
1356
1376
  public u64(address: bigint, value?: bigint): bigint | this {
1357
- if (value === undefined) {
1358
- this.read(address, this.Scratch8);
1377
+ const Scratch8BigUint64Array = this.Scratch8BigUint64Array;
1359
1378
 
1360
- return u64(this.Scratch8.ptr);
1379
+ if (value === undefined) {
1380
+ return this.read(address, Scratch8BigUint64Array)[0x00];
1361
1381
  }
1362
1382
 
1363
- this.Scratch8Buffer.writeBigUInt64LE(value);
1383
+ Scratch8BigUint64Array[0x00] = value;
1364
1384
 
1365
- this.write(address, this.Scratch8);
1385
+ this.write(address, Scratch8BigUint64Array);
1366
1386
 
1367
1387
  return this;
1368
1388
  }
@@ -1413,15 +1433,15 @@ class Memory {
1413
1433
  public u8(address: bigint): number;
1414
1434
  public u8(address: bigint, value: number): this;
1415
1435
  public u8(address: bigint, value?: number): number | this {
1416
- if (value === undefined) {
1417
- this.read(address, this.Scratch1);
1436
+ const Scratch1 = this.Scratch1;
1418
1437
 
1419
- return u8(this.Scratch1.ptr);
1438
+ if (value === undefined) {
1439
+ return this.read(address, Scratch1)[0x00];
1420
1440
  }
1421
1441
 
1422
- this.Scratch1Buffer.writeUInt8(value);
1442
+ Scratch1[0x00] = value;
1423
1443
 
1424
- this.write(address, this.Scratch1);
1444
+ this.write(address, Scratch1);
1425
1445
 
1426
1446
  return this;
1427
1447
  }
@@ -1564,21 +1584,23 @@ class Memory {
1564
1584
  public vector3(address: bigint): Vector3;
1565
1585
  public vector3(address: bigint, value: Vector3): this;
1566
1586
  public vector3(address: bigint, value?: Vector3): Vector3 | this {
1587
+ const Scratch12Float32Array = this.Scratch12Float32Array;
1588
+
1567
1589
  if (value === undefined) {
1568
- this.read(address, this.Scratch12);
1590
+ this.read(address, Scratch12Float32Array);
1569
1591
 
1570
- const x = f32(this.Scratch12.ptr);
1571
- const y = f32(this.Scratch12.ptr, 0x04);
1572
- const z = f32(this.Scratch12.ptr, 0x08);
1592
+ const x = Scratch12Float32Array[0x00],
1593
+ y = Scratch12Float32Array[0x01],
1594
+ z = Scratch12Float32Array[0x02]; // prettier-ignore
1573
1595
 
1574
1596
  return { x, y, z };
1575
1597
  }
1576
1598
 
1577
- this.Scratch12Buffer.writeFloatLE(value.x);
1578
- this.Scratch12Buffer.writeFloatLE(value.y, 0x04);
1579
- this.Scratch12Buffer.writeFloatLE(value.z, 0x08);
1599
+ Scratch12Float32Array[0x00] = value.x;
1600
+ Scratch12Float32Array[0x01] = value.y;
1601
+ Scratch12Float32Array[0x02] = value.z;
1580
1602
 
1581
- this.write(address, this.Scratch12);
1603
+ this.write(address, Scratch12Float32Array);
1582
1604
 
1583
1605
  return this;
1584
1606
  }