bun-memory 1.1.22 → 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.
- package/README.md +2 -0
- package/example/trigger-bot.ts +8 -11
- package/package.json +2 -2
- package/structs/Memory.ts +146 -124
package/README.md
CHANGED
|
@@ -97,6 +97,8 @@ cs2.i32Array(0x12345678n, new Int32Array([1, 2, 3, 4]));
|
|
|
97
97
|
|
|
98
98
|
## Example: Using Scratches (Recommended)
|
|
99
99
|
|
|
100
|
+
Scratches let you reuse buffers and typed arrays for repeated memory operations, avoiding unnecessary allocations and maximizing performance. This is the most efficient way to read or write large or frequent data.
|
|
101
|
+
|
|
100
102
|
```ts
|
|
101
103
|
const buffer = Buffer.allocUnsafe(256);
|
|
102
104
|
const array = new Uint64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8);
|
package/example/trigger-bot.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
32
|
-
|
|
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)[
|
|
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": "
|
|
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.
|
|
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
|
|
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
|
|
145
|
+
private readonly Scratch12Float32Array = new Float32Array(this.Scratch12.buffer, this.Scratch12.byteOffset, 0x03);
|
|
127
146
|
|
|
128
|
-
private readonly
|
|
129
|
-
private readonly
|
|
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
|
|
140
|
-
private static
|
|
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
|
|
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
|
-
|
|
349
|
-
this.read(address, this.Scratch1);
|
|
361
|
+
const Scratch1 = this.Scratch1;
|
|
350
362
|
|
|
351
|
-
|
|
363
|
+
if (value === undefined) {
|
|
364
|
+
return this.read(address, Scratch1)[0x00] !== 0;
|
|
352
365
|
}
|
|
353
366
|
|
|
354
|
-
|
|
367
|
+
Scratch1[0x00] = value ? 1 : 0;
|
|
355
368
|
|
|
356
|
-
this.write(address,
|
|
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
|
-
|
|
439
|
-
this.read(address, this.Scratch4);
|
|
448
|
+
const Scratch4Float32Array = this.Scratch4Float32Array; // prettier-ignore
|
|
440
449
|
|
|
441
|
-
|
|
450
|
+
if (value === undefined) {
|
|
451
|
+
return this.read(address, Scratch4Float32Array)[0x00];
|
|
442
452
|
}
|
|
443
453
|
|
|
444
|
-
|
|
454
|
+
Scratch4Float32Array[0x00] = value;
|
|
445
455
|
|
|
446
|
-
this.write(address,
|
|
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
|
-
|
|
498
|
-
this.read(address, this.Scratch8);
|
|
507
|
+
const Scratch8Float64Array = this.Scratch8Float64Array; // prettier-ignore
|
|
499
508
|
|
|
500
|
-
|
|
509
|
+
if (value === undefined) {
|
|
510
|
+
return this.read(address, Scratch8Float64Array)[0x00];
|
|
501
511
|
}
|
|
502
512
|
|
|
503
|
-
|
|
513
|
+
Scratch8Float64Array[0x00] = value;
|
|
504
514
|
|
|
505
|
-
this.write(address,
|
|
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
|
-
|
|
557
|
-
this.read(address, this.Scratch2);
|
|
566
|
+
const Scratch2Int16Array = this.Scratch2Int16Array; // prettier-ignore
|
|
558
567
|
|
|
559
|
-
|
|
568
|
+
if (value === undefined) {
|
|
569
|
+
return this.read(address, Scratch2Int16Array)[0x00];
|
|
560
570
|
}
|
|
561
571
|
|
|
562
|
-
|
|
572
|
+
Scratch2Int16Array[0x00] = value;
|
|
563
573
|
|
|
564
|
-
this.write(address,
|
|
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
|
-
|
|
616
|
-
this.read(address, this.Scratch4);
|
|
625
|
+
const Scratch4Int32Array = this.Scratch4Int32Array;
|
|
617
626
|
|
|
618
|
-
|
|
627
|
+
if (value === undefined) {
|
|
628
|
+
return this.read(address, Scratch4Int32Array)[0x00];
|
|
619
629
|
}
|
|
620
630
|
|
|
621
|
-
|
|
631
|
+
Scratch4Int32Array[0x00] = value;
|
|
622
632
|
|
|
623
|
-
this.write(address,
|
|
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
|
-
|
|
675
|
-
this.read(address, this.Scratch8);
|
|
684
|
+
const Scratch8BigInt64Array = this.Scratch8BigInt64Array;
|
|
676
685
|
|
|
677
|
-
|
|
686
|
+
if (value === undefined) {
|
|
687
|
+
return this.read(address, Scratch8BigInt64Array)[0x00];
|
|
678
688
|
}
|
|
679
689
|
|
|
680
|
-
|
|
690
|
+
Scratch8BigInt64Array[0x00] = value;
|
|
681
691
|
|
|
682
|
-
this.write(address,
|
|
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
|
-
|
|
734
|
-
this.read(address, this.Scratch1);
|
|
743
|
+
const Scratch1Int8Array = this.Scratch1Int8Array;
|
|
735
744
|
|
|
736
|
-
|
|
745
|
+
if (value === undefined) {
|
|
746
|
+
return this.read(address, Scratch1Int8Array)[0x00];
|
|
737
747
|
}
|
|
738
748
|
|
|
739
|
-
|
|
749
|
+
Scratch1Int8Array[0x00] = value;
|
|
740
750
|
|
|
741
|
-
this.write(address,
|
|
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,
|
|
935
|
+
this.read(address, Scratch8Float32Array);
|
|
924
936
|
|
|
925
|
-
const x =
|
|
926
|
-
|
|
937
|
+
const x = Scratch8Float32Array[0x00],
|
|
938
|
+
y = Scratch8Float32Array[0x01]; // prettier-ignore
|
|
927
939
|
|
|
928
940
|
return { x, y };
|
|
929
941
|
}
|
|
930
942
|
|
|
931
|
-
|
|
932
|
-
|
|
943
|
+
Scratch8Float32Array[0x00] = value.x;
|
|
944
|
+
Scratch8Float32Array[0x01] = value.y;
|
|
933
945
|
|
|
934
|
-
this.write(address,
|
|
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,
|
|
1017
|
+
this.read(address, Scratch12Float32Array);
|
|
1004
1018
|
|
|
1005
|
-
const pitch =
|
|
1006
|
-
|
|
1007
|
-
|
|
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
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1026
|
+
Scratch12Float32Array[0x00] = value.pitch;
|
|
1027
|
+
Scratch12Float32Array[0x02] = value.roll;
|
|
1028
|
+
Scratch12Float32Array[0x01] = value.yaw;
|
|
1015
1029
|
|
|
1016
|
-
this.write(address,
|
|
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,
|
|
1102
|
+
this.read(address, Scratch16Float32Array);
|
|
1087
1103
|
|
|
1088
|
-
const w =
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
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
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
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,
|
|
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,
|
|
1192
|
+
this.read(address, Scratch3);
|
|
1175
1193
|
|
|
1176
|
-
const r =
|
|
1177
|
-
g =
|
|
1178
|
-
b =
|
|
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
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1201
|
+
Scratch3[0x00] = value.r;
|
|
1202
|
+
Scratch3[0x01] = value.g;
|
|
1203
|
+
Scratch3[0x02] = value.b;
|
|
1186
1204
|
|
|
1187
|
-
return this.write(address,
|
|
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,
|
|
1226
|
+
this.read(address, Scratch4);
|
|
1207
1227
|
|
|
1208
|
-
const r =
|
|
1209
|
-
g =
|
|
1210
|
-
b =
|
|
1211
|
-
a =
|
|
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
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
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,
|
|
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
|
-
|
|
1240
|
-
this.read(address, this.Scratch2);
|
|
1259
|
+
const Scratch2Uint16Array = this.Scratch2Uint16Array;
|
|
1241
1260
|
|
|
1242
|
-
|
|
1261
|
+
if (value === undefined) {
|
|
1262
|
+
return this.read(address, Scratch2Uint16Array)[0x00];
|
|
1243
1263
|
}
|
|
1244
1264
|
|
|
1245
|
-
|
|
1265
|
+
Scratch2Uint16Array[0x00] = value;
|
|
1246
1266
|
|
|
1247
|
-
this.write(address,
|
|
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
|
-
|
|
1299
|
-
this.read(address, this.Scratch4);
|
|
1318
|
+
const Scratch4Uint32Array = this.Scratch4Uint32Array;
|
|
1300
1319
|
|
|
1301
|
-
|
|
1320
|
+
if (value === undefined) {
|
|
1321
|
+
return this.read(address, Scratch4Uint32Array)[0x00];
|
|
1302
1322
|
}
|
|
1303
1323
|
|
|
1304
|
-
|
|
1324
|
+
Scratch4Uint32Array[0x00] = value;
|
|
1305
1325
|
|
|
1306
|
-
this.write(address,
|
|
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
|
-
|
|
1358
|
-
this.read(address, this.Scratch8);
|
|
1377
|
+
const Scratch8BigUint64Array = this.Scratch8BigUint64Array;
|
|
1359
1378
|
|
|
1360
|
-
|
|
1379
|
+
if (value === undefined) {
|
|
1380
|
+
return this.read(address, Scratch8BigUint64Array)[0x00];
|
|
1361
1381
|
}
|
|
1362
1382
|
|
|
1363
|
-
|
|
1383
|
+
Scratch8BigUint64Array[0x00] = value;
|
|
1364
1384
|
|
|
1365
|
-
this.write(address,
|
|
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
|
-
|
|
1417
|
-
this.read(address, this.Scratch1);
|
|
1436
|
+
const Scratch1 = this.Scratch1;
|
|
1418
1437
|
|
|
1419
|
-
|
|
1438
|
+
if (value === undefined) {
|
|
1439
|
+
return this.read(address, Scratch1)[0x00];
|
|
1420
1440
|
}
|
|
1421
1441
|
|
|
1422
|
-
|
|
1442
|
+
Scratch1[0x00] = value;
|
|
1423
1443
|
|
|
1424
|
-
this.write(address,
|
|
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,
|
|
1590
|
+
this.read(address, Scratch12Float32Array);
|
|
1569
1591
|
|
|
1570
|
-
const x =
|
|
1571
|
-
|
|
1572
|
-
|
|
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
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1599
|
+
Scratch12Float32Array[0x00] = value.x;
|
|
1600
|
+
Scratch12Float32Array[0x01] = value.y;
|
|
1601
|
+
Scratch12Float32Array[0x02] = value.z;
|
|
1580
1602
|
|
|
1581
|
-
this.write(address,
|
|
1603
|
+
this.write(address, Scratch12Float32Array);
|
|
1582
1604
|
|
|
1583
1605
|
return this;
|
|
1584
1606
|
}
|