bun-memory 1.1.37 → 1.1.39

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
@@ -303,7 +303,7 @@ class Memory {
303
303
  * Writes a buffer to memory.
304
304
  * @param address Address to write to.
305
305
  * @param scratch Buffer to write.
306
- * @param force If true, temporarily changes the page protection to PAGE_EXECUTE_READWRITE using `VirtualProtectEx` while performing the write.
306
+ * @param force When writing, if true temporarily changes page protection to allow the write.
307
307
  * @returns This instance.
308
308
  * @example
309
309
  * ```ts
@@ -313,7 +313,7 @@ class Memory {
313
313
  * cs2.write(0x12345678n, new Uint8Array([1,2,3,4]), true);
314
314
  * ```
315
315
  */
316
- private write(address: bigint, scratch: Scratch, force: boolean = false): this {
316
+ public write(address: bigint, scratch: Scratch, force: boolean = false): this {
317
317
  const lpBaseAddress = address;
318
318
  const lpBuffer = scratch.ptr;
319
319
  const nSize = BigInt(scratch.byteLength);
@@ -363,6 +363,7 @@ class Memory {
363
363
  * Reads or writes a boolean value.
364
364
  * @param address Address to access.
365
365
  * @param value Optional value to write.
366
+ * @param force When writing, if true temporarily changes page protection to allow the write.
366
367
  * @returns The boolean at address, or this instance if writing.
367
368
  * @example
368
369
  * ```ts
@@ -372,8 +373,8 @@ class Memory {
372
373
  * ```
373
374
  */
374
375
  public bool(address: bigint): boolean;
375
- public bool(address: bigint, value: boolean): this;
376
- public bool(address: bigint, value?: boolean): boolean | this {
376
+ public bool(address: bigint, value: boolean, force?: boolean): this;
377
+ public bool(address: bigint, value?: boolean, force?: boolean): boolean | this {
377
378
  const Scratch1 = this.Scratch1;
378
379
 
379
380
  if (value === undefined) {
@@ -382,7 +383,7 @@ class Memory {
382
383
 
383
384
  Scratch1[0x00] = value ? 1 : 0;
384
385
 
385
- void this.write(address, Scratch1);
386
+ void this.write(address, Scratch1, force);
386
387
 
387
388
  return this;
388
389
  }
@@ -391,6 +392,7 @@ class Memory {
391
392
  * Reads or writes a Buffer.
392
393
  * @param address Address to access.
393
394
  * @param lengthOrValue Length to read or Buffer to write.
395
+ * @param force When writing, if true temporarily changes page protection to allow the write.
394
396
  * @returns Buffer read or this instance if writing.
395
397
  * @example
396
398
  * ```ts
@@ -400,8 +402,8 @@ class Memory {
400
402
  * ```
401
403
  */
402
404
  public buffer(address: bigint, length: number): Buffer;
403
- public buffer(address: bigint, value: Buffer): this;
404
- public buffer(address: bigint, lengthOrValue: number | Buffer): Buffer | this {
405
+ public buffer(address: bigint, value: Buffer, force?: boolean): this;
406
+ public buffer(address: bigint, lengthOrValue: number | Buffer, force?: boolean): Buffer | this {
405
407
  if (typeof lengthOrValue === 'number') {
406
408
  const length = lengthOrValue;
407
409
  const scratch = Buffer.allocUnsafe(length);
@@ -411,7 +413,7 @@ class Memory {
411
413
 
412
414
  const value = lengthOrValue;
413
415
 
414
- void this.write(address, value);
416
+ void this.write(address, value, force);
415
417
 
416
418
  return this;
417
419
  }
@@ -420,6 +422,7 @@ class Memory {
420
422
  * Reads or writes a C-style string.
421
423
  * @param address Address to access.
422
424
  * @param lengthOrValue Length to read or CString to write.
425
+ * @param force When writing, if true temporarily changes page protection to allow the write.
423
426
  * @returns CString read or this instance if writing.
424
427
  * @example
425
428
  * ```ts
@@ -429,8 +432,8 @@ class Memory {
429
432
  * ```
430
433
  */
431
434
  public cString(address: bigint, length: number): CString;
432
- public cString(address: bigint, value: CString): this;
433
- public cString(address: bigint, lengthOrValue: number | CString): CString | this {
435
+ public cString(address: bigint, value: CString, force?: boolean): this;
436
+ public cString(address: bigint, lengthOrValue: number | CString, force?: boolean): CString | this {
434
437
  if (typeof lengthOrValue === 'number') {
435
438
  const scratch = new Uint8Array(lengthOrValue);
436
439
 
@@ -447,7 +450,7 @@ class Memory {
447
450
 
448
451
  const scratch = Buffer.from(lengthOrValue);
449
452
 
450
- void this.write(address, scratch);
453
+ void this.write(address, scratch, force);
451
454
 
452
455
  return this;
453
456
  }
@@ -456,6 +459,7 @@ class Memory {
456
459
  * Reads or writes a 32-bit float.
457
460
  * @param address Address to access.
458
461
  * @param value Optional value to write.
462
+ * @param force When writing, if true temporarily changes page protection to allow the write.
459
463
  * @returns The float at address, or this instance if writing.
460
464
  * @example
461
465
  * ```ts
@@ -465,8 +469,8 @@ class Memory {
465
469
  * ```
466
470
  */
467
471
  public f32(address: bigint): number;
468
- public f32(address: bigint, value: number): this;
469
- public f32(address: bigint, value?: number): number | this {
472
+ public f32(address: bigint, value: number, force?: boolean): this;
473
+ public f32(address: bigint, value?: number, force?: boolean): number | this {
470
474
  const Scratch4Float32Array = this.Scratch4Float32Array; // prettier-ignore
471
475
 
472
476
  if (value === undefined) {
@@ -475,7 +479,7 @@ class Memory {
475
479
 
476
480
  Scratch4Float32Array[0x00] = value;
477
481
 
478
- void this.write(address, Scratch4Float32Array);
482
+ void this.write(address, Scratch4Float32Array, force);
479
483
 
480
484
  return this;
481
485
  }
@@ -484,6 +488,7 @@ class Memory {
484
488
  * Reads or writes a Float32Array.
485
489
  * @param address Address to access.
486
490
  * @param lengthOrValues Length to read or Float32Array to write.
491
+ * @param force When writing, if true temporarily changes page protection to allow the write.
487
492
  * @returns Float32Array read or this instance if writing.
488
493
  * @example
489
494
  * ```ts
@@ -493,8 +498,8 @@ class Memory {
493
498
  * ```
494
499
  */
495
500
  public f32Array(address: bigint, length: number): Float32Array;
496
- public f32Array(address: bigint, values: Float32Array): this;
497
- public f32Array(address: bigint, lengthOrValues: Float32Array | number): Float32Array | this {
501
+ public f32Array(address: bigint, values: Float32Array, force?: boolean): this;
502
+ public f32Array(address: bigint, lengthOrValues: Float32Array | number, force?: boolean): Float32Array | this {
498
503
  if (typeof lengthOrValues === 'number') {
499
504
  const length = lengthOrValues;
500
505
  const scratch = new Float32Array(length);
@@ -506,7 +511,7 @@ class Memory {
506
511
 
507
512
  const values = lengthOrValues;
508
513
 
509
- void this.write(address, values);
514
+ void this.write(address, values, force);
510
515
 
511
516
  return this;
512
517
  }
@@ -515,6 +520,7 @@ class Memory {
515
520
  * Reads or writes a 64-bit float.
516
521
  * @param address Address to access.
517
522
  * @param value Optional value to write.
523
+ * @param force When writing, if true temporarily changes page protection to allow the write.
518
524
  * @returns The float at address, or this instance if writing.
519
525
  * @example
520
526
  * ```ts
@@ -524,8 +530,8 @@ class Memory {
524
530
  * ```
525
531
  */
526
532
  public f64(address: bigint): number;
527
- public f64(address: bigint, value: number): this;
528
- public f64(address: bigint, value?: number): number | this {
533
+ public f64(address: bigint, value: number, force?: boolean): this;
534
+ public f64(address: bigint, value?: number, force?: boolean): number | this {
529
535
  const Scratch8Float64Array = this.Scratch8Float64Array; // prettier-ignore
530
536
 
531
537
  if (value === undefined) {
@@ -534,7 +540,7 @@ class Memory {
534
540
 
535
541
  Scratch8Float64Array[0x00] = value;
536
542
 
537
- void this.write(address, Scratch8Float64Array);
543
+ void this.write(address, Scratch8Float64Array, force);
538
544
 
539
545
  return this;
540
546
  }
@@ -543,6 +549,7 @@ class Memory {
543
549
  * Reads or writes a Float64Array.
544
550
  * @param address Address to access.
545
551
  * @param lengthOrValues Length to read or Float64Array to write.
552
+ * @param force When writing, if true temporarily changes page protection to allow the write.
546
553
  * @returns Float64Array read or this instance if writing.
547
554
  * @example
548
555
  * ```ts
@@ -552,8 +559,8 @@ class Memory {
552
559
  * ```
553
560
  */
554
561
  public f64Array(address: bigint, length: number): Float64Array;
555
- public f64Array(address: bigint, values: Float64Array): this;
556
- public f64Array(address: bigint, lengthOrValues: Float64Array | number): Float64Array | this {
562
+ public f64Array(address: bigint, values: Float64Array, force?: boolean): this;
563
+ public f64Array(address: bigint, lengthOrValues: Float64Array | number, force?: boolean): Float64Array | this {
557
564
  if (typeof lengthOrValues === 'number') {
558
565
  const length = lengthOrValues;
559
566
  const scratch = new Float64Array(length);
@@ -565,7 +572,7 @@ class Memory {
565
572
 
566
573
  const values = lengthOrValues;
567
574
 
568
- void this.write(address, values);
575
+ void this.write(address, values, force);
569
576
 
570
577
  return this;
571
578
  }
@@ -574,6 +581,7 @@ class Memory {
574
581
  * Reads or writes a 16-bit integer.
575
582
  * @param address Address to access.
576
583
  * @param value Optional value to write.
584
+ * @param force When writing, if true temporarily changes page protection to allow the write.
577
585
  * @returns The int at address, or this instance if writing.
578
586
  * @example
579
587
  * ```ts
@@ -583,8 +591,8 @@ class Memory {
583
591
  * ```
584
592
  */
585
593
  public i16(address: bigint): number;
586
- public i16(address: bigint, value: number): this;
587
- public i16(address: bigint, value?: number): number | this {
594
+ public i16(address: bigint, value: number, force?: boolean): this;
595
+ public i16(address: bigint, value?: number, force?: boolean): number | this {
588
596
  const Scratch2Int16Array = this.Scratch2Int16Array; // prettier-ignore
589
597
 
590
598
  if (value === undefined) {
@@ -593,7 +601,7 @@ class Memory {
593
601
 
594
602
  Scratch2Int16Array[0x00] = value;
595
603
 
596
- void this.write(address, Scratch2Int16Array);
604
+ void this.write(address, Scratch2Int16Array, force);
597
605
 
598
606
  return this;
599
607
  }
@@ -602,6 +610,7 @@ class Memory {
602
610
  * Reads or writes an Int16Array.
603
611
  * @param address Address to access.
604
612
  * @param lengthOrValues Length to read or Int16Array to write.
613
+ * @param force When writing, if true temporarily changes page protection to allow the write.
605
614
  * @returns Int16Array read or this instance if writing.
606
615
  * @example
607
616
  * ```ts
@@ -611,8 +620,8 @@ class Memory {
611
620
  * ```
612
621
  */
613
622
  public i16Array(address: bigint, length: number): Int16Array;
614
- public i16Array(address: bigint, values: Int16Array): this;
615
- public i16Array(address: bigint, lengthOrValues: Int16Array | number): Int16Array | this {
623
+ public i16Array(address: bigint, values: Int16Array, force?: boolean): this;
624
+ public i16Array(address: bigint, lengthOrValues: Int16Array | number, force?: boolean): Int16Array | this {
616
625
  if (typeof lengthOrValues === 'number') {
617
626
  const length = lengthOrValues;
618
627
  const scratch = new Int16Array(length);
@@ -624,7 +633,7 @@ class Memory {
624
633
 
625
634
  const values = lengthOrValues;
626
635
 
627
- void this.write(address, values);
636
+ void this.write(address, values, force);
628
637
 
629
638
  return this;
630
639
  }
@@ -633,6 +642,7 @@ class Memory {
633
642
  * Reads or writes a 32-bit integer.
634
643
  * @param address Address to access.
635
644
  * @param value Optional value to write.
645
+ * @param force When writing, if true temporarily changes page protection to allow the write.
636
646
  * @returns The int at address, or this instance if writing.
637
647
  * @example
638
648
  * ```ts
@@ -642,8 +652,8 @@ class Memory {
642
652
  * ```
643
653
  */
644
654
  public i32(address: bigint): number;
645
- public i32(address: bigint, value: number): this;
646
- public i32(address: bigint, value?: number): number | this {
655
+ public i32(address: bigint, value: number, force?: boolean): this;
656
+ public i32(address: bigint, value?: number, force?: boolean): number | this {
647
657
  const Scratch4Int32Array = this.Scratch4Int32Array;
648
658
 
649
659
  if (value === undefined) {
@@ -652,7 +662,7 @@ class Memory {
652
662
 
653
663
  Scratch4Int32Array[0x00] = value;
654
664
 
655
- void this.write(address, Scratch4Int32Array);
665
+ void this.write(address, Scratch4Int32Array, force);
656
666
 
657
667
  return this;
658
668
  }
@@ -661,6 +671,7 @@ class Memory {
661
671
  * Reads or writes an Int32Array.
662
672
  * @param address Address to access.
663
673
  * @param lengthOrValues Length to read or Int32Array to write.
674
+ * @param force When writing, if true temporarily changes page protection to allow the write.
664
675
  * @returns Int32Array read or this instance if writing.
665
676
  * @example
666
677
  * ```ts
@@ -670,8 +681,8 @@ class Memory {
670
681
  * ```
671
682
  */
672
683
  public i32Array(address: bigint, length: number): Int32Array;
673
- public i32Array(address: bigint, values: Int32Array): this;
674
- public i32Array(address: bigint, lengthOrValues: Int32Array | number): Int32Array | this {
684
+ public i32Array(address: bigint, values: Int32Array, force?: boolean): this;
685
+ public i32Array(address: bigint, lengthOrValues: Int32Array | number, force?: boolean): Int32Array | this {
675
686
  if (typeof lengthOrValues === 'number') {
676
687
  const length = lengthOrValues;
677
688
  const scratch = new Int32Array(length);
@@ -683,7 +694,7 @@ class Memory {
683
694
 
684
695
  const values = lengthOrValues;
685
696
 
686
- void this.write(address, values);
697
+ void this.write(address, values, force);
687
698
 
688
699
  return this;
689
700
  }
@@ -692,6 +703,7 @@ class Memory {
692
703
  * Reads or writes a 64-bit integer.
693
704
  * @param address Address to access.
694
705
  * @param value Optional value to write.
706
+ * @param force When writing, if true temporarily changes page protection to allow the write.
695
707
  * @returns The bigint at address, or this instance if writing.
696
708
  * @example
697
709
  * ```ts
@@ -701,8 +713,8 @@ class Memory {
701
713
  * ```
702
714
  */
703
715
  public i64(address: bigint): bigint;
704
- public i64(address: bigint, value: bigint): this;
705
- public i64(address: bigint, value?: bigint): bigint | this {
716
+ public i64(address: bigint, value: bigint, force?: boolean): this;
717
+ public i64(address: bigint, value?: bigint, force?: boolean): bigint | this {
706
718
  const Scratch8BigInt64Array = this.Scratch8BigInt64Array;
707
719
 
708
720
  if (value === undefined) {
@@ -711,7 +723,7 @@ class Memory {
711
723
 
712
724
  Scratch8BigInt64Array[0x00] = value;
713
725
 
714
- void this.write(address, Scratch8BigInt64Array);
726
+ void this.write(address, Scratch8BigInt64Array, force);
715
727
 
716
728
  return this;
717
729
  }
@@ -720,6 +732,7 @@ class Memory {
720
732
  * Reads or writes a BigInt64Array.
721
733
  * @param address Address to access.
722
734
  * @param lengthOrValues Length to read or BigInt64Array to write.
735
+ * @param force When writing, if true temporarily changes page protection to allow the write.
723
736
  * @returns BigInt64Array read or this instance if writing.
724
737
  * @example
725
738
  * ```ts
@@ -729,8 +742,8 @@ class Memory {
729
742
  * ```
730
743
  */
731
744
  public i64Array(address: bigint, length: number): BigInt64Array;
732
- public i64Array(address: bigint, values: BigInt64Array): this;
733
- public i64Array(address: bigint, lengthOrValues: BigInt64Array | number): BigInt64Array | this {
745
+ public i64Array(address: bigint, values: BigInt64Array, force?: boolean): this;
746
+ public i64Array(address: bigint, lengthOrValues: BigInt64Array | number, force?: boolean): BigInt64Array | this {
734
747
  if (typeof lengthOrValues === 'number') {
735
748
  const length = lengthOrValues;
736
749
  const scratch = new BigInt64Array(length);
@@ -742,7 +755,7 @@ class Memory {
742
755
 
743
756
  const values = lengthOrValues;
744
757
 
745
- void this.write(address, values);
758
+ void this.write(address, values, force);
746
759
 
747
760
  return this;
748
761
  }
@@ -751,6 +764,7 @@ class Memory {
751
764
  * Reads or writes an 8-bit integer.
752
765
  * @param address Address to access.
753
766
  * @param value Optional value to write.
767
+ * @param force When writing, if true temporarily changes page protection to allow the write.
754
768
  * @returns The int at address, or this instance if writing.
755
769
  * @example
756
770
  * ```ts
@@ -760,8 +774,8 @@ class Memory {
760
774
  * ```
761
775
  */
762
776
  public i8(address: bigint): number;
763
- public i8(address: bigint, value: number): this;
764
- public i8(address: bigint, value?: number): number | this {
777
+ public i8(address: bigint, value: number, force?: boolean): this;
778
+ public i8(address: bigint, value?: number, force?: boolean): number | this {
765
779
  const Scratch1Int8Array = this.Scratch1Int8Array;
766
780
 
767
781
  if (value === undefined) {
@@ -770,7 +784,7 @@ class Memory {
770
784
 
771
785
  Scratch1Int8Array[0x00] = value;
772
786
 
773
- void this.write(address, Scratch1Int8Array);
787
+ void this.write(address, Scratch1Int8Array, force);
774
788
 
775
789
  return this;
776
790
  }
@@ -779,6 +793,7 @@ class Memory {
779
793
  * Reads or writes an Int8Array.
780
794
  * @param address Address to access.
781
795
  * @param lengthOrValues Length to read or Int8Array to write.
796
+ * @param force When writing, if true temporarily changes page protection to allow the write.
782
797
  * @returns Int8Array read or this instance if writing.
783
798
  * @example
784
799
  * ```ts
@@ -788,8 +803,8 @@ class Memory {
788
803
  * ```
789
804
  */
790
805
  public i8Array(address: bigint, length: number): Int8Array;
791
- public i8Array(address: bigint, values: Int8Array): this;
792
- public i8Array(address: bigint, lengthOrValues: Int8Array | number): Int8Array | this {
806
+ public i8Array(address: bigint, values: Int8Array, force?: boolean): this;
807
+ public i8Array(address: bigint, lengthOrValues: Int8Array | number, force?: boolean): Int8Array | this {
793
808
  if (typeof lengthOrValues === 'number') {
794
809
  const length = lengthOrValues;
795
810
  const scratch = new Int8Array(length);
@@ -801,7 +816,7 @@ class Memory {
801
816
 
802
817
  const values = lengthOrValues;
803
818
 
804
- void this.write(address, values);
819
+ void this.write(address, values, force);
805
820
 
806
821
  return this;
807
822
  }
@@ -810,6 +825,7 @@ class Memory {
810
825
  * Reads or writes a 3x3 matrix (Float32Array of length 9).
811
826
  * @param address Address to access.
812
827
  * @param values Optional Float32Array to write.
828
+ * @param force When writing, if true temporarily changes page protection to allow the write.
813
829
  * @returns The matrix at address, or this instance if writing.
814
830
  * @example
815
831
  * ```ts
@@ -819,8 +835,8 @@ class Memory {
819
835
  * ```
820
836
  */
821
837
  public matrix3x3(address: bigint): Float32Array;
822
- public matrix3x3(address: bigint, values: Float32Array): this;
823
- public matrix3x3(address: bigint, values?: Float32Array): Float32Array | this {
838
+ public matrix3x3(address: bigint, values: Float32Array, force?: boolean): this;
839
+ public matrix3x3(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
824
840
  if (values === undefined) {
825
841
  const scratch = new Float32Array(0x09);
826
842
 
@@ -833,7 +849,7 @@ class Memory {
833
849
  throw new RangeError('values.length must be 9.');
834
850
  }
835
851
 
836
- void this.write(address, values);
852
+ void this.write(address, values, force);
837
853
 
838
854
  return this;
839
855
  }
@@ -842,6 +858,7 @@ class Memory {
842
858
  * Reads or writes a 3x4 matrix (Float32Array of length 12).
843
859
  * @param address Address to access.
844
860
  * @param values Optional Float32Array to write.
861
+ * @param force When writing, if true temporarily changes page protection to allow the write.
845
862
  * @returns The matrix at address, or this instance if writing.
846
863
  * @example
847
864
  * ```ts
@@ -851,8 +868,8 @@ class Memory {
851
868
  * ```
852
869
  */
853
870
  public matrix3x4(address: bigint): Float32Array;
854
- public matrix3x4(address: bigint, values: Float32Array): this;
855
- public matrix3x4(address: bigint, values?: Float32Array): Float32Array | this {
871
+ public matrix3x4(address: bigint, values: Float32Array, force?: boolean): this;
872
+ public matrix3x4(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
856
873
  if (values === undefined) {
857
874
  const scratch = new Float32Array(0x0c);
858
875
 
@@ -865,7 +882,7 @@ class Memory {
865
882
  throw new RangeError('values.length must be 12.');
866
883
  }
867
884
 
868
- void this.write(address, values);
885
+ void this.write(address, values, force);
869
886
 
870
887
  return this;
871
888
  }
@@ -874,6 +891,7 @@ class Memory {
874
891
  * Reads or writes a 4x4 matrix (Float32Array of length 16).
875
892
  * @param address Address to access.
876
893
  * @param values Optional Float32Array to write.
894
+ * @param force When writing, if true temporarily changes page protection to allow the write.
877
895
  * @returns The matrix at address, or this instance if writing.
878
896
  * @example
879
897
  * ```ts
@@ -883,8 +901,8 @@ class Memory {
883
901
  * ```
884
902
  */
885
903
  public matrix4x4(address: bigint): Float32Array;
886
- public matrix4x4(address: bigint, values: Float32Array): this;
887
- public matrix4x4(address: bigint, values?: Float32Array): Float32Array | this {
904
+ public matrix4x4(address: bigint, values: Float32Array, force?: boolean): this;
905
+ public matrix4x4(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
888
906
  if (values === undefined) {
889
907
  const scratch = new Float32Array(0x10);
890
908
 
@@ -897,7 +915,7 @@ class Memory {
897
915
  throw new RangeError('values.length must be 16.');
898
916
  }
899
917
 
900
- void this.write(address, values);
918
+ void this.write(address, values, force);
901
919
 
902
920
  return this;
903
921
  }
@@ -906,6 +924,7 @@ class Memory {
906
924
  * Reads or writes a NetworkUtlVector (Uint32Array).
907
925
  * @param address Address to access.
908
926
  * @param values Optional Uint32Array to write.
927
+ * @param force When writing, if true temporarily changes page protection to allow the write.
909
928
  * @returns The vector at address, or this instance if writing.
910
929
  * @example
911
930
  * ```ts
@@ -915,8 +934,8 @@ class Memory {
915
934
  * ```
916
935
  */
917
936
  public networkUtlVector(address: bigint): NetworkUtlVector;
918
- public networkUtlVector(address: bigint, values: NetworkUtlVector): this;
919
- public networkUtlVector(address: bigint, values?: NetworkUtlVector): NetworkUtlVector | this {
937
+ public networkUtlVector(address: bigint, values: NetworkUtlVector, force?: boolean): this;
938
+ public networkUtlVector(address: bigint, values?: NetworkUtlVector, force?: boolean): NetworkUtlVector | this {
920
939
  const elementsPtr = this.u64(address + 0x08n);
921
940
 
922
941
  if (values === undefined) {
@@ -929,9 +948,9 @@ class Memory {
929
948
  return scratch;
930
949
  }
931
950
 
932
- this.u32(address, values.length);
951
+ this.u32(address, values.length, force);
933
952
 
934
- void this.write(elementsPtr, values);
953
+ void this.write(elementsPtr, values, force);
935
954
 
936
955
  return this;
937
956
  }
@@ -940,6 +959,7 @@ class Memory {
940
959
  * Reads or writes a Point (object with x, y).
941
960
  * @param address Address to access.
942
961
  * @param value Optional Point to write.
962
+ * @param force When writing, if true temporarily changes page protection to allow the write.
943
963
  * @returns The point at address, or this instance if writing.
944
964
  * @example
945
965
  * ```ts
@@ -949,8 +969,8 @@ class Memory {
949
969
  * ```
950
970
  */
951
971
  public point(address: bigint): Point;
952
- public point(address: bigint, value: Point): this;
953
- public point(address: bigint, value?: Point): Point | this {
972
+ public point(address: bigint, value: Point, force?: boolean): this;
973
+ public point(address: bigint, value?: Point, force?: boolean): Point | this {
954
974
  const Scratch8Float32Array = this.Scratch8Float32Array;
955
975
 
956
976
  if (value === undefined) {
@@ -965,7 +985,7 @@ class Memory {
965
985
  Scratch8Float32Array[0x00] = value.x;
966
986
  Scratch8Float32Array[0x01] = value.y;
967
987
 
968
- void this.write(address, Scratch8Float32Array);
988
+ void this.write(address, Scratch8Float32Array, force);
969
989
 
970
990
  return this;
971
991
  }
@@ -974,6 +994,7 @@ class Memory {
974
994
  * Reads or writes an array of Points.
975
995
  * @param address Address to access.
976
996
  * @param lengthOrValues Length to read or array to write.
997
+ * @param force When writing, if true temporarily changes page protection to allow the write.
977
998
  * @returns Array of points read or this instance if writing.
978
999
  * @example
979
1000
  * ```ts
@@ -983,8 +1004,8 @@ class Memory {
983
1004
  * ```
984
1005
  */
985
1006
  public pointArray(address: bigint, length: number): Point[];
986
- public pointArray(address: bigint, value: Point[]): this;
987
- public pointArray(address: bigint, lengthOrValues: number | Point[]): Point[] | this {
1007
+ public pointArray(address: bigint, value: Point[], force?: boolean): this;
1008
+ public pointArray(address: bigint, lengthOrValues: number | Point[], force?: boolean): Point[] | this {
988
1009
  if (typeof lengthOrValues === 'number') {
989
1010
  const length = lengthOrValues;
990
1011
  const scratch = new Float32Array(length * 2);
@@ -1013,14 +1034,27 @@ class Memory {
1013
1034
  scratch[j + 0x01] = vector2.y;
1014
1035
  }
1015
1036
 
1016
- void this.write(address, scratch);
1037
+ void this.write(address, scratch, force);
1017
1038
 
1018
1039
  return this;
1019
1040
  }
1020
1041
 
1042
+ /**
1043
+ * Reads or writes a raw Point (two Float32 values) as a Float32Array.
1044
+ * @param address Address to access.
1045
+ * @param values Optional Float32Array of length 2 to write.
1046
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1047
+ * @returns Float32Array read or this instance if writing.
1048
+ * @example
1049
+ * ```ts
1050
+ * const cs2 = new Memory('cs2.exe');
1051
+ * const myPoint = cs2.pointRaw(0x12345678n);
1052
+ * cs2.pointRaw(0x12345678n, new Float32Array([1, 2]));
1053
+ * ```
1054
+ */
1021
1055
  public pointRaw(address: bigint): Float32Array;
1022
- public pointRaw(address: bigint, values: Float32Array): this;
1023
- public pointRaw(address: bigint, values?: Float32Array): Float32Array | this {
1056
+ public pointRaw(address: bigint, values: Float32Array, force?: boolean): this;
1057
+ public pointRaw(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1024
1058
  if (values === undefined) {
1025
1059
  return this.f32Array(address, 0x02);
1026
1060
  }
@@ -1029,7 +1063,7 @@ class Memory {
1029
1063
  throw new RangeError('values.length must be 2.');
1030
1064
  }
1031
1065
 
1032
- void this.write(address, values);
1066
+ void this.write(address, values, force);
1033
1067
 
1034
1068
  return this;
1035
1069
  }
@@ -1047,8 +1081,8 @@ class Memory {
1047
1081
  * ```
1048
1082
  */
1049
1083
  public qAngle(address: bigint): QAngle;
1050
- public qAngle(address: bigint, value: QAngle): this;
1051
- public qAngle(address: bigint, value?: QAngle): QAngle | this {
1084
+ public qAngle(address: bigint, value: QAngle, force?: boolean): this;
1085
+ public qAngle(address: bigint, value?: QAngle, force?: boolean): QAngle | this {
1052
1086
  const Scratch12Float32Array = this.Scratch12Float32Array;
1053
1087
 
1054
1088
  if (value === undefined) {
@@ -1065,7 +1099,7 @@ class Memory {
1065
1099
  Scratch12Float32Array[0x02] = value.roll;
1066
1100
  Scratch12Float32Array[0x01] = value.yaw;
1067
1101
 
1068
- void this.write(address, Scratch12Float32Array);
1102
+ void this.write(address, Scratch12Float32Array, force);
1069
1103
 
1070
1104
  return this;
1071
1105
  }
@@ -1083,8 +1117,8 @@ class Memory {
1083
1117
  * ```
1084
1118
  */
1085
1119
  public qAngleArray(address: bigint, length: number): QAngle[];
1086
- public qAngleArray(address: bigint, values: QAngle[]): this;
1087
- public qAngleArray(address: bigint, lengthOrValues: QAngle[] | number): QAngle[] | this {
1120
+ public qAngleArray(address: bigint, values: QAngle[], force?: boolean): this;
1121
+ public qAngleArray(address: bigint, lengthOrValues: QAngle[] | number, force?: boolean): QAngle[] | this {
1088
1122
  if (typeof lengthOrValues === 'number') {
1089
1123
  const length = lengthOrValues;
1090
1124
  const scratch = new Float32Array(length * 0x03);
@@ -1115,7 +1149,7 @@ class Memory {
1115
1149
  scratch[j + 0x01] = qAngle.yaw;
1116
1150
  }
1117
1151
 
1118
- void this.write(address, scratch);
1152
+ void this.write(address, scratch, force);
1119
1153
 
1120
1154
  return this;
1121
1155
  }
@@ -1124,6 +1158,7 @@ class Memory {
1124
1158
  * Reads or writes a raw QAngle as a Float32Array.
1125
1159
  * @param address Address to access.
1126
1160
  * @param values Optional Float32Array to write.
1161
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1127
1162
  * @returns Float32Array read or this instance if writing.
1128
1163
  * @example
1129
1164
  * ```ts
@@ -1133,8 +1168,8 @@ class Memory {
1133
1168
  * ```
1134
1169
  */
1135
1170
  public qAngleRaw(address: bigint): Float32Array;
1136
- public qAngleRaw(address: bigint, values: Float32Array): this;
1137
- public qAngleRaw(address: bigint, values?: Float32Array): Float32Array | this {
1171
+ public qAngleRaw(address: bigint, values: Float32Array, force?: boolean): this;
1172
+ public qAngleRaw(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1138
1173
  if (values === undefined) {
1139
1174
  return this.f32Array(address, 0x03);
1140
1175
  }
@@ -1143,7 +1178,7 @@ class Memory {
1143
1178
  throw new RangeError('values.length must be 3.');
1144
1179
  }
1145
1180
 
1146
- void this.write(address, values);
1181
+ void this.write(address, values, force);
1147
1182
 
1148
1183
  return this;
1149
1184
  }
@@ -1152,6 +1187,7 @@ class Memory {
1152
1187
  * Reads or writes a Quaternion (object with w, x, y, z).
1153
1188
  * @param address Address to access.
1154
1189
  * @param value Optional Quaternion to write.
1190
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1155
1191
  * @returns The Quaternion at address, or this instance if writing.
1156
1192
  * @example
1157
1193
  * ```ts
@@ -1161,8 +1197,8 @@ class Memory {
1161
1197
  * ```
1162
1198
  */
1163
1199
  public quaternion(address: bigint): Quaternion;
1164
- public quaternion(address: bigint, value: Quaternion): this;
1165
- public quaternion(address: bigint, value?: Quaternion): Quaternion | this {
1200
+ public quaternion(address: bigint, value: Quaternion, force?: boolean): this;
1201
+ public quaternion(address: bigint, value?: Quaternion, force?: boolean): Quaternion | this {
1166
1202
  const Scratch16Float32Array = this.Scratch16Float32Array;
1167
1203
 
1168
1204
  if (value === undefined) {
@@ -1181,7 +1217,7 @@ class Memory {
1181
1217
  Scratch16Float32Array[0x01] = value.y;
1182
1218
  Scratch16Float32Array[0x02] = value.z;
1183
1219
 
1184
- void this.write(address, Scratch16Float32Array);
1220
+ void this.write(address, Scratch16Float32Array, force);
1185
1221
 
1186
1222
  return this;
1187
1223
  }
@@ -1190,6 +1226,7 @@ class Memory {
1190
1226
  * Reads or writes an array of Quaternions.
1191
1227
  * @param address Address to access.
1192
1228
  * @param lengthOrValues Length to read or array to write.
1229
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1193
1230
  * @returns Array of Quaternions read or this instance if writing.
1194
1231
  * @example
1195
1232
  * ```ts
@@ -1199,8 +1236,8 @@ class Memory {
1199
1236
  * ```
1200
1237
  */
1201
1238
  public quaternionArray(address: bigint, length: number): Quaternion[];
1202
- public quaternionArray(address: bigint, values: Quaternion[]): this;
1203
- public quaternionArray(address: bigint, lengthOrValues: Quaternion[] | number): Quaternion[] | this {
1239
+ public quaternionArray(address: bigint, values: Quaternion[], force?: boolean): this;
1240
+ public quaternionArray(address: bigint, lengthOrValues: Quaternion[] | number, force?: boolean): Quaternion[] | this {
1204
1241
  if (typeof lengthOrValues === 'number') {
1205
1242
  const length = lengthOrValues;
1206
1243
  const scratch = new Float32Array(length * 0x04); // 4 * f32 per Quaternion
@@ -1233,7 +1270,7 @@ class Memory {
1233
1270
  scratch[j + 0x02] = quaternion.z;
1234
1271
  }
1235
1272
 
1236
- void this.write(address, scratch);
1273
+ void this.write(address, scratch, force);
1237
1274
 
1238
1275
  return this;
1239
1276
  }
@@ -1242,6 +1279,7 @@ class Memory {
1242
1279
  * Reads or writes a raw Quaternion as a Float32Array.
1243
1280
  * @param address Address to access.
1244
1281
  * @param values Optional Float32Array to write.
1282
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1245
1283
  * @returns Float32Array read or this instance if writing.
1246
1284
  * @example
1247
1285
  * ```ts
@@ -1251,8 +1289,8 @@ class Memory {
1251
1289
  * ```
1252
1290
  */
1253
1291
  public quaternionRaw(address: bigint): Float32Array;
1254
- public quaternionRaw(address: bigint, values: Float32Array): this;
1255
- public quaternionRaw(address: bigint, values?: Float32Array): Float32Array | this {
1292
+ public quaternionRaw(address: bigint, values: Float32Array, force?: boolean): this;
1293
+ public quaternionRaw(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1256
1294
  if (values === undefined) {
1257
1295
  return this.f32Array(address, 0x04);
1258
1296
  }
@@ -1261,7 +1299,7 @@ class Memory {
1261
1299
  throw new RangeError('values.length must be 4.');
1262
1300
  }
1263
1301
 
1264
- void this.write(address, values);
1302
+ void this.write(address, values, force);
1265
1303
 
1266
1304
  return this;
1267
1305
  }
@@ -1270,6 +1308,7 @@ class Memory {
1270
1308
  * Reads or writes an RGB color (object with r, g, b).
1271
1309
  * @param address Address to access.
1272
1310
  * @param value Optional RGB to write.
1311
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1273
1312
  * @returns The RGB at address, or this instance if writing.
1274
1313
  * @example
1275
1314
  * ```ts
@@ -1279,8 +1318,8 @@ class Memory {
1279
1318
  * ```
1280
1319
  */
1281
1320
  public rgb(address: bigint): RGB;
1282
- public rgb(address: bigint, value: RGB): this;
1283
- public rgb(address: bigint, value?: RGB): RGB | this {
1321
+ public rgb(address: bigint, value: RGB, force?: boolean): this;
1322
+ public rgb(address: bigint, value?: RGB, force?: boolean): RGB | this {
1284
1323
  const Scratch3 = this.Scratch3;
1285
1324
 
1286
1325
  if (value === undefined) {
@@ -1297,7 +1336,7 @@ class Memory {
1297
1336
  Scratch3[0x01] = value.g;
1298
1337
  Scratch3[0x02] = value.b;
1299
1338
 
1300
- void this.write(address, Scratch3);
1339
+ void this.write(address, Scratch3, force);
1301
1340
 
1302
1341
  return this;
1303
1342
  }
@@ -1306,6 +1345,7 @@ class Memory {
1306
1345
  * Reads or writes a raw RGB value as a Uint8Array.
1307
1346
  * @param address Address to access.
1308
1347
  * @param values Optional buffer to write.
1348
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1309
1349
  * @returns Uint8Array read or this instance if writing.
1310
1350
  * @example
1311
1351
  * ```ts
@@ -1315,8 +1355,9 @@ class Memory {
1315
1355
  * ```
1316
1356
  */
1317
1357
  public rgbRaw(address: bigint): Uint8Array;
1318
- public rgbRaw(address: bigint, values: Buffer | Uint8Array | Uint8ClampedArray): this;
1319
- public rgbRaw(address: bigint, values?: Buffer | Uint8Array | Uint8ClampedArray): Uint8Array | this {
1358
+ public rgbRaw(address: bigint): Uint8Array;
1359
+ public rgbRaw(address: bigint, values: Buffer | Uint8Array | Uint8ClampedArray, force?: boolean): this;
1360
+ public rgbRaw(address: bigint, values?: Buffer | Uint8Array | Uint8ClampedArray, force?: boolean): Uint8Array | this {
1320
1361
  if (values === undefined) {
1321
1362
  return this.u8Array(address, 0x03);
1322
1363
  }
@@ -1325,7 +1366,7 @@ class Memory {
1325
1366
  throw new RangeError('values.length must be 3.');
1326
1367
  }
1327
1368
 
1328
- void this.write(address, values);
1369
+ void this.write(address, values, force);
1329
1370
 
1330
1371
  return this;
1331
1372
  }
@@ -1334,6 +1375,7 @@ class Memory {
1334
1375
  * Reads or writes an RGBA color (object with r, g, b, a).
1335
1376
  * @param address Address to access.
1336
1377
  * @param value Optional RGBA to write.
1378
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1337
1379
  * @returns The RGBA at address, or this instance if writing.
1338
1380
  * @example
1339
1381
  * ```ts
@@ -1343,8 +1385,8 @@ class Memory {
1343
1385
  * ```
1344
1386
  */
1345
1387
  public rgba(address: bigint): RGBA;
1346
- public rgba(address: bigint, value: RGBA): this;
1347
- public rgba(address: bigint, value?: RGBA): RGBA | this {
1388
+ public rgba(address: bigint, value: RGBA, force?: boolean): this;
1389
+ public rgba(address: bigint, value?: RGBA, force?: boolean): RGBA | this {
1348
1390
  const Scratch4 = this.Scratch4;
1349
1391
 
1350
1392
  if (value === undefined) {
@@ -1363,7 +1405,7 @@ class Memory {
1363
1405
  Scratch4[0x02] = value.b;
1364
1406
  Scratch4[0x03] = value.a;
1365
1407
 
1366
- void this.write(address, Scratch4);
1408
+ void this.write(address, Scratch4, force);
1367
1409
 
1368
1410
  return this;
1369
1411
  }
@@ -1372,6 +1414,7 @@ class Memory {
1372
1414
  * Reads or writes a raw RGBA value as a Uint8Array.
1373
1415
  * @param address Address to access.
1374
1416
  * @param values Optional buffer to write.
1417
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1375
1418
  * @returns Uint8Array read or this instance if writing.
1376
1419
  * @example
1377
1420
  * ```ts
@@ -1381,8 +1424,9 @@ class Memory {
1381
1424
  * ```
1382
1425
  */
1383
1426
  public rgbaRaw(address: bigint): Uint8Array;
1384
- public rgbaRaw(address: bigint, values: Buffer | Uint8Array | Uint8ClampedArray): this;
1385
- public rgbaRaw(address: bigint, values?: Buffer | Uint8Array | Uint8ClampedArray): Uint8Array | this {
1427
+ public rgbaRaw(address: bigint): Uint8Array;
1428
+ public rgbaRaw(address: bigint, values: Buffer | Uint8Array | Uint8ClampedArray, force?: boolean): this;
1429
+ public rgbaRaw(address: bigint, values?: Buffer | Uint8Array | Uint8ClampedArray, force?: boolean): Uint8Array | this {
1386
1430
  if (values === undefined) {
1387
1431
  return this.u8Array(address, 0x04);
1388
1432
  }
@@ -1391,7 +1435,7 @@ class Memory {
1391
1435
  throw new RangeError('values.length must be 4.');
1392
1436
  }
1393
1437
 
1394
- void this.write(address, values);
1438
+ void this.write(address, values, force);
1395
1439
 
1396
1440
  return this;
1397
1441
  }
@@ -1400,6 +1444,7 @@ class Memory {
1400
1444
  * Reads or writes a UTF-8 string.
1401
1445
  * @param address Address to access.
1402
1446
  * @param lengthOrValue Length to read or string to write.
1447
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1403
1448
  * @returns The string at address, or this instance if writing.
1404
1449
  * @notice When writing, remember to null-terminate your string (e.g., 'hello\0').
1405
1450
  * @todo Compare performance when using CString vs TextDecoder when reading…
@@ -1411,8 +1456,9 @@ class Memory {
1411
1456
  * ```
1412
1457
  */
1413
1458
  public string(address: bigint, length: number): string;
1414
- public string(address: bigint, value: string): this;
1415
- public string(address: bigint, lengthOrValue: number | string): string | this {
1459
+ public string(address: bigint, length: number): string;
1460
+ public string(address: bigint, value: string, force?: boolean): this;
1461
+ public string(address: bigint, lengthOrValue: number | string, force?: boolean): string | this {
1416
1462
  if (typeof lengthOrValue === 'number') {
1417
1463
  const scratch = new Uint8Array(lengthOrValue);
1418
1464
 
@@ -1429,7 +1475,7 @@ class Memory {
1429
1475
 
1430
1476
  const scratch = Memory.TextEncoderUTF8.encode(lengthOrValue);
1431
1477
 
1432
- void this.write(address, scratch);
1478
+ void this.write(address, scratch, force);
1433
1479
 
1434
1480
  return this;
1435
1481
  }
@@ -1438,6 +1484,7 @@ class Memory {
1438
1484
  * Reads or writes a 16-bit unsigned integer.
1439
1485
  * @param address Address to access.
1440
1486
  * @param value Optional value to write.
1487
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1441
1488
  * @returns The value at address, or this instance if writing.
1442
1489
  * @example
1443
1490
  * ```ts
@@ -1447,8 +1494,8 @@ class Memory {
1447
1494
  * ```
1448
1495
  */
1449
1496
  public u16(address: bigint): number;
1450
- public u16(address: bigint, value: number): this;
1451
- public u16(address: bigint, value?: number): number | this {
1497
+ public u16(address: bigint, value: number, force?: boolean): this;
1498
+ public u16(address: bigint, value?: number, force?: boolean): number | this {
1452
1499
  const Scratch2Uint16Array = this.Scratch2Uint16Array;
1453
1500
 
1454
1501
  if (value === undefined) {
@@ -1457,7 +1504,7 @@ class Memory {
1457
1504
 
1458
1505
  Scratch2Uint16Array[0x00] = value;
1459
1506
 
1460
- void this.write(address, Scratch2Uint16Array);
1507
+ void this.write(address, Scratch2Uint16Array, force);
1461
1508
 
1462
1509
  return this;
1463
1510
  }
@@ -1466,6 +1513,7 @@ class Memory {
1466
1513
  * Reads or writes a Uint16Array.
1467
1514
  * @param address Address to access.
1468
1515
  * @param lengthOrValues Length to read or Uint16Array to write.
1516
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1469
1517
  * @returns Uint16Array read or this instance if writing.
1470
1518
  * @example
1471
1519
  * ```ts
@@ -1475,8 +1523,8 @@ class Memory {
1475
1523
  * ```
1476
1524
  */
1477
1525
  public u16Array(address: bigint, length: number): Uint16Array;
1478
- public u16Array(address: bigint, values: Uint16Array): this;
1479
- public u16Array(address: bigint, lengthOrValues: Uint16Array | number): Uint16Array | this {
1526
+ public u16Array(address: bigint, values: Uint16Array, force?: boolean): this;
1527
+ public u16Array(address: bigint, lengthOrValues: Uint16Array | number, force?: boolean): Uint16Array | this {
1480
1528
  if (typeof lengthOrValues === 'number') {
1481
1529
  const length = lengthOrValues;
1482
1530
  const scratch = new Uint16Array(length);
@@ -1488,7 +1536,7 @@ class Memory {
1488
1536
 
1489
1537
  const values = lengthOrValues;
1490
1538
 
1491
- void this.write(address, values);
1539
+ void this.write(address, values, force);
1492
1540
 
1493
1541
  return this;
1494
1542
  }
@@ -1497,6 +1545,7 @@ class Memory {
1497
1545
  * Reads or writes a 32-bit unsigned integer.
1498
1546
  * @param address Address to access.
1499
1547
  * @param value Optional value to write.
1548
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1500
1549
  * @returns The value at address, or this instance if writing.
1501
1550
  * @example
1502
1551
  * ```ts
@@ -1506,8 +1555,8 @@ class Memory {
1506
1555
  * ```
1507
1556
  */
1508
1557
  public u32(address: bigint): number;
1509
- public u32(address: bigint, value: number): this;
1510
- public u32(address: bigint, value?: number): number | this {
1558
+ public u32(address: bigint, value: number, force?: boolean): this;
1559
+ public u32(address: bigint, value?: number, force?: boolean): number | this {
1511
1560
  const Scratch4Uint32Array = this.Scratch4Uint32Array;
1512
1561
 
1513
1562
  if (value === undefined) {
@@ -1516,7 +1565,7 @@ class Memory {
1516
1565
 
1517
1566
  Scratch4Uint32Array[0x00] = value;
1518
1567
 
1519
- void this.write(address, Scratch4Uint32Array);
1568
+ void this.write(address, Scratch4Uint32Array, force);
1520
1569
 
1521
1570
  return this;
1522
1571
  }
@@ -1525,6 +1574,7 @@ class Memory {
1525
1574
  * Reads or writes a Uint32Array.
1526
1575
  * @param address Address to access.
1527
1576
  * @param lengthOrValues Length to read or Uint32Array to write.
1577
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1528
1578
  * @returns Uint32Array read or this instance if writing.
1529
1579
  * @example
1530
1580
  * ```ts
@@ -1534,8 +1584,8 @@ class Memory {
1534
1584
  * ```
1535
1585
  */
1536
1586
  public u32Array(address: bigint, length: number): Uint32Array;
1537
- public u32Array(address: bigint, values: Uint32Array): this;
1538
- public u32Array(address: bigint, lengthOrValues: Uint32Array | number): Uint32Array | this {
1587
+ public u32Array(address: bigint, values: Uint32Array, force?: boolean): this;
1588
+ public u32Array(address: bigint, lengthOrValues: Uint32Array | number, force?: boolean): Uint32Array | this {
1539
1589
  if (typeof lengthOrValues === 'number') {
1540
1590
  const length = lengthOrValues;
1541
1591
  const scratch = new Uint32Array(length);
@@ -1547,7 +1597,7 @@ class Memory {
1547
1597
 
1548
1598
  const values = lengthOrValues;
1549
1599
 
1550
- void this.write(address, values);
1600
+ void this.write(address, values, force);
1551
1601
 
1552
1602
  return this;
1553
1603
  }
@@ -1556,6 +1606,7 @@ class Memory {
1556
1606
  * Reads or writes a 64-bit unsigned integer.
1557
1607
  * @param address Address to access.
1558
1608
  * @param value Optional value to write.
1609
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1559
1610
  * @returns The bigint at address, or this instance if writing.
1560
1611
  * @example
1561
1612
  * ```ts
@@ -1565,8 +1616,8 @@ class Memory {
1565
1616
  * ```
1566
1617
  */
1567
1618
  public u64(address: bigint): bigint;
1568
- public u64(address: bigint, value: bigint): this;
1569
- public u64(address: bigint, value?: bigint): bigint | this {
1619
+ public u64(address: bigint, value: bigint, force?: boolean): this;
1620
+ public u64(address: bigint, value?: bigint, force?: boolean): bigint | this {
1570
1621
  const Scratch8BigUint64Array = this.Scratch8BigUint64Array;
1571
1622
 
1572
1623
  if (value === undefined) {
@@ -1575,7 +1626,7 @@ class Memory {
1575
1626
 
1576
1627
  Scratch8BigUint64Array[0x00] = value;
1577
1628
 
1578
- void this.write(address, Scratch8BigUint64Array);
1629
+ void this.write(address, Scratch8BigUint64Array, force);
1579
1630
 
1580
1631
  return this;
1581
1632
  }
@@ -1584,6 +1635,7 @@ class Memory {
1584
1635
  * Reads or writes a BigUint64Array.
1585
1636
  * @param address Address to access.
1586
1637
  * @param lengthOrValues Length to read or BigUint64Array to write.
1638
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1587
1639
  * @returns BigUint64Array read or this instance if writing.
1588
1640
  * @example
1589
1641
  * ```ts
@@ -1593,8 +1645,8 @@ class Memory {
1593
1645
  * ```
1594
1646
  */
1595
1647
  public u64Array(address: bigint, length: number): BigUint64Array;
1596
- public u64Array(address: bigint, values: BigUint64Array): this;
1597
- public u64Array(address: bigint, lengthOrValues: BigUint64Array | number): BigUint64Array | this {
1648
+ public u64Array(address: bigint, values: BigUint64Array, force?: boolean): this;
1649
+ public u64Array(address: bigint, lengthOrValues: BigUint64Array | number, force?: boolean): BigUint64Array | this {
1598
1650
  if (typeof lengthOrValues === 'number') {
1599
1651
  const length = lengthOrValues;
1600
1652
  const scratch = new BigUint64Array(length);
@@ -1606,7 +1658,7 @@ class Memory {
1606
1658
 
1607
1659
  const values = lengthOrValues;
1608
1660
 
1609
- void this.write(address, values);
1661
+ void this.write(address, values, force);
1610
1662
 
1611
1663
  return this;
1612
1664
  }
@@ -1615,6 +1667,7 @@ class Memory {
1615
1667
  * Reads or writes an 8-bit unsigned integer.
1616
1668
  * @param address Address to access.
1617
1669
  * @param value Optional value to write.
1670
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1618
1671
  * @returns The value at address, or this instance if writing.
1619
1672
  * @example
1620
1673
  * ```ts
@@ -1624,8 +1677,8 @@ class Memory {
1624
1677
  * ```
1625
1678
  */
1626
1679
  public u8(address: bigint): number;
1627
- public u8(address: bigint, value: number): this;
1628
- public u8(address: bigint, value?: number): number | this {
1680
+ public u8(address: bigint, value: number, force?: boolean): this;
1681
+ public u8(address: bigint, value?: number, force?: boolean): number | this {
1629
1682
  const Scratch1 = this.Scratch1;
1630
1683
 
1631
1684
  if (value === undefined) {
@@ -1634,7 +1687,7 @@ class Memory {
1634
1687
 
1635
1688
  Scratch1[0x00] = value;
1636
1689
 
1637
- void this.write(address, Scratch1);
1690
+ void this.write(address, Scratch1, force);
1638
1691
 
1639
1692
  return this;
1640
1693
  }
@@ -1643,6 +1696,7 @@ class Memory {
1643
1696
  * Reads or writes a Uint8Array.
1644
1697
  * @param address Address to access.
1645
1698
  * @param lengthOrValues Length to read or Uint8Array to write.
1699
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1646
1700
  * @returns Uint8Array read or this instance if writing.
1647
1701
  * @example
1648
1702
  * ```ts
@@ -1652,8 +1706,8 @@ class Memory {
1652
1706
  * ```
1653
1707
  */
1654
1708
  public u8Array(address: bigint, length: number): Uint8Array;
1655
- public u8Array(address: bigint, values: Uint8Array): this;
1656
- public u8Array(address: bigint, lengthOrValues: Uint8Array | number): Uint8Array | this {
1709
+ public u8Array(address: bigint, values: Uint8Array, force?: boolean): this;
1710
+ public u8Array(address: bigint, lengthOrValues: Uint8Array | number, force?: boolean): Uint8Array | this {
1657
1711
  if (typeof lengthOrValues === 'number') {
1658
1712
  const length = lengthOrValues;
1659
1713
  const scratch = new Uint8Array(length);
@@ -1665,7 +1719,7 @@ class Memory {
1665
1719
 
1666
1720
  const values = lengthOrValues;
1667
1721
 
1668
- void this.write(address, values);
1722
+ void this.write(address, values, force);
1669
1723
 
1670
1724
  return this;
1671
1725
  }
@@ -1674,6 +1728,7 @@ class Memory {
1674
1728
  * Reads or writes a pointer-sized unsigned integer.
1675
1729
  * @param address Address to access.
1676
1730
  * @param value Optional value to write.
1731
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1677
1732
  * @returns The value at address, or this instance if writing.
1678
1733
  * @example
1679
1734
  * ```ts
@@ -1683,20 +1738,21 @@ class Memory {
1683
1738
  * ```
1684
1739
  */
1685
1740
  public uPtr(address: bigint): UPtr;
1686
- public uPtr(address: bigint, value: UPtr): this;
1687
- public uPtr(address: bigint, value?: UPtr): UPtr | this {
1741
+ public uPtr(address: bigint, value: UPtr, force?: boolean): this;
1742
+ public uPtr(address: bigint, value?: UPtr, force?: boolean): UPtr | this {
1688
1743
  // TypeScript is funny sometimes, isn't it?… 🫠…
1689
1744
  if (value === undefined) {
1690
1745
  return this.u64(address);
1691
1746
  }
1692
1747
 
1693
- return this.u64(address, value);
1748
+ return this.u64(address, value, force);
1694
1749
  }
1695
1750
 
1696
1751
  /**
1697
1752
  * Reads or writes an array of pointer-sized unsigned integers.
1698
1753
  * @param address Address to access.
1699
1754
  * @param lengthOrValues Length to read or array to write.
1755
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1700
1756
  * @returns Array read or this instance if writing.
1701
1757
  * @example
1702
1758
  * ```ts
@@ -1706,20 +1762,21 @@ class Memory {
1706
1762
  * ```
1707
1763
  */
1708
1764
  public uPtrArray(address: bigint, length: number): UPtrArray;
1709
- public uPtrArray(address: bigint, values: UPtrArray): this;
1710
- public uPtrArray(address: bigint, lengthOrValues: UPtrArray | number): UPtrArray | this {
1765
+ public uPtrArray(address: bigint, values: UPtrArray, force?: boolean): this;
1766
+ public uPtrArray(address: bigint, lengthOrValues: UPtrArray | number, force?: boolean): UPtrArray | this {
1711
1767
  // TypeScript is funny sometimes, isn't it?… 🫠…
1712
1768
  if (typeof lengthOrValues === 'number') {
1713
1769
  return this.u64Array(address, lengthOrValues);
1714
1770
  }
1715
1771
 
1716
- return this.u64Array(address, lengthOrValues);
1772
+ return this.u64Array(address, lengthOrValues, force);
1717
1773
  }
1718
1774
 
1719
1775
  /**
1720
1776
  * Reads or writes a Vector2 (object with x, y).
1721
1777
  * @param address Address to access.
1722
1778
  * @param value Optional Vector2 to write.
1779
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1723
1780
  * @returns The Vector2 at address, or this instance if writing.
1724
1781
  * @example
1725
1782
  * ```ts
@@ -1729,42 +1786,56 @@ class Memory {
1729
1786
  * ```
1730
1787
  */
1731
1788
  public vector2(address: bigint): Vector2;
1732
- public vector2(address: bigint, value: Vector2): this;
1733
- public vector2(address: bigint, value?: Vector2): Vector2 | this {
1789
+ public vector2(address: bigint, value: Vector2, force?: boolean): this;
1790
+ public vector2(address: bigint, value?: Vector2, force?: boolean): Vector2 | this {
1734
1791
  // TypeScript is funny sometimes, isn't it?… 🫠…
1735
1792
  if (value === undefined) {
1736
1793
  return this.point(address);
1737
1794
  }
1738
1795
 
1739
- return this.point(address, value);
1796
+ return this.point(address, value, force);
1740
1797
  }
1741
1798
 
1742
1799
  /**
1743
1800
  * Reads or writes an array of Vector2.
1744
1801
  * @param address Address to access.
1745
1802
  * @param lengthOrValues Length to read or array to write.
1803
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1746
1804
  * @returns Array of Vector2 read or this instance if writing.
1747
1805
  * @example
1748
1806
  * ```ts
1749
1807
  * const cs2 = new Memory('cs2.exe');
1750
- * const myVectors = cs2.vector2Array(0x12345678n, 2);
1808
+ * const myVector2s = cs2.vector2Array(0x12345678n, 2);
1751
1809
  * cs2.vector2Array(0x12345678n, [{ x: 1, y: 2 }, { x: 3, y: 4 }]);
1752
1810
  * ```
1753
1811
  */
1754
1812
  public vector2Array(address: bigint, length: number): Vector2[];
1755
- public vector2Array(address: bigint, values: Vector2[]): this;
1756
- public vector2Array(address: bigint, lengthOrValues: Vector2[] | number): Vector2[] | this {
1813
+ public vector2Array(address: bigint, values: Vector2[], force?: boolean): this;
1814
+ public vector2Array(address: bigint, lengthOrValues: Vector2[] | number, force?: boolean): Vector2[] | this {
1757
1815
  // TypeScript is funny sometimes, isn't it?… 🫠…
1758
1816
  if (typeof lengthOrValues === 'number') {
1759
1817
  return this.pointArray(address, lengthOrValues);
1760
1818
  }
1761
1819
 
1762
- return this.pointArray(address, lengthOrValues);
1820
+ return this.pointArray(address, lengthOrValues, force);
1763
1821
  }
1764
1822
 
1823
+ /**
1824
+ * Reads or writes a raw Vector2 as a Float32Array.
1825
+ * @param address Address to access.
1826
+ * @param values Optional Float32Array to write.
1827
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1828
+ * @returns Float32Array read or this instance if writing.
1829
+ * @example
1830
+ * ```ts
1831
+ * const cs2 = new Memory('cs2.exe');
1832
+ * const myVector2 = cs2.vector2Raw(0x12345678n);
1833
+ * cs2.vector2Raw(0x12345678n, new Float32Array([1, 2]));
1834
+ * ```
1835
+ */
1765
1836
  public vector2Raw(address: bigint): Float32Array;
1766
- public vector2Raw(address: bigint, values: Float32Array): this;
1767
- public vector2Raw(address: bigint, values?: Float32Array): Float32Array | this {
1837
+ public vector2Raw(address: bigint, values: Float32Array, force?: boolean): this;
1838
+ public vector2Raw(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1768
1839
  if (values === undefined) {
1769
1840
  return this.f32Array(address, 0x02);
1770
1841
  }
@@ -1773,7 +1844,7 @@ class Memory {
1773
1844
  throw new RangeError('values.length must be 2.');
1774
1845
  }
1775
1846
 
1776
- void this.write(address, values);
1847
+ void this.write(address, values, force);
1777
1848
 
1778
1849
  return this;
1779
1850
  }
@@ -1782,6 +1853,7 @@ class Memory {
1782
1853
  * Reads or writes a Vector3 (object with x, y, z).
1783
1854
  * @param address Address to access.
1784
1855
  * @param value Optional Vector3 to write.
1856
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1785
1857
  * @returns The Vector3 at address, or this instance if writing.
1786
1858
  * @example
1787
1859
  * ```ts
@@ -1791,8 +1863,8 @@ class Memory {
1791
1863
  * ```
1792
1864
  */
1793
1865
  public vector3(address: bigint): Vector3;
1794
- public vector3(address: bigint, value: Vector3): this;
1795
- public vector3(address: bigint, value?: Vector3): Vector3 | this {
1866
+ public vector3(address: bigint, value: Vector3, force?: boolean): this;
1867
+ public vector3(address: bigint, value?: Vector3, force?: boolean): Vector3 | this {
1796
1868
  const Scratch12Float32Array = this.Scratch12Float32Array;
1797
1869
 
1798
1870
  if (value === undefined) {
@@ -1809,7 +1881,7 @@ class Memory {
1809
1881
  Scratch12Float32Array[0x01] = value.y;
1810
1882
  Scratch12Float32Array[0x02] = value.z;
1811
1883
 
1812
- void this.write(address, Scratch12Float32Array);
1884
+ void this.write(address, Scratch12Float32Array, force);
1813
1885
 
1814
1886
  return this;
1815
1887
  }
@@ -1818,17 +1890,18 @@ class Memory {
1818
1890
  * Reads or writes an array of Vector3.
1819
1891
  * @param address Address to access.
1820
1892
  * @param lengthOrValues Length to read or array to write.
1893
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1821
1894
  * @returns Array of Vector3 read or this instance if writing.
1822
1895
  * @example
1823
1896
  * ```ts
1824
1897
  * const cs2 = new Memory('cs2.exe');
1825
- * const myVectors = cs2.vector3Array(0x12345678n, 2);
1898
+ * const myVector3s = cs2.vector3Array(0x12345678n, 2);
1826
1899
  * cs2.vector3Array(0x12345678n, [{ x: 1, y: 2, z: 3 }]);
1827
1900
  * ```
1828
1901
  */
1829
1902
  public vector3Array(address: bigint, length: number): Vector3[];
1830
- public vector3Array(address: bigint, values: Vector3[]): this;
1831
- public vector3Array(address: bigint, lengthOrValues: Vector3[] | number): Vector3[] | this {
1903
+ public vector3Array(address: bigint, values: Vector3[], force?: boolean): this;
1904
+ public vector3Array(address: bigint, lengthOrValues: Vector3[] | number, force?: boolean): Vector3[] | this {
1832
1905
  if (typeof lengthOrValues === 'number') {
1833
1906
  const length = lengthOrValues;
1834
1907
  const scratch = new Float32Array(length * 0x03);
@@ -1859,14 +1932,27 @@ class Memory {
1859
1932
  scratch[j + 0x02] = vector3.z;
1860
1933
  }
1861
1934
 
1862
- void this.write(address, scratch);
1935
+ void this.write(address, scratch, force);
1863
1936
 
1864
1937
  return this;
1865
1938
  }
1866
1939
 
1940
+ /**
1941
+ * Reads or writes a raw Vector3 as a Float32Array.
1942
+ * @param address Address to access.
1943
+ * @param values Optional Float32Array to write.
1944
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1945
+ * @returns Float32Array read or this instance if writing.
1946
+ * @example
1947
+ * ```ts
1948
+ * const cs2 = new Memory('cs2.exe');
1949
+ * const myVector3 = cs2.vector3Raw(0x12345678n);
1950
+ * cs2.vector3Raw(0x12345678n, new Float32Array([1, 2, 3]));
1951
+ * ```
1952
+ */
1867
1953
  public vector3Raw(address: bigint): Float32Array;
1868
- public vector3Raw(address: bigint, values: Float32Array): this;
1869
- public vector3Raw(address: bigint, values?: Float32Array): Float32Array | this {
1954
+ public vector3Raw(address: bigint, values: Float32Array, force?: boolean): this;
1955
+ public vector3Raw(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1870
1956
  if (values === undefined) {
1871
1957
  return this.f32Array(address, 0x03);
1872
1958
  }
@@ -1875,7 +1961,7 @@ class Memory {
1875
1961
  throw new RangeError('values.length must be 3.');
1876
1962
  }
1877
1963
 
1878
- void this.write(address, values);
1964
+ void this.write(address, values, force);
1879
1965
 
1880
1966
  return this;
1881
1967
  }
@@ -1884,6 +1970,7 @@ class Memory {
1884
1970
  * Reads or writes a Vector4 (object with w, x, y, z).
1885
1971
  * @param address Address to access.
1886
1972
  * @param value Optional Vector4 to write.
1973
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1887
1974
  * @returns The Vector4 at address, or this instance if writing.
1888
1975
  * @example
1889
1976
  * ```ts
@@ -1893,42 +1980,57 @@ class Memory {
1893
1980
  * ```
1894
1981
  */
1895
1982
  public vector4(address: bigint): Vector4;
1896
- public vector4(address: bigint, value: Vector4): this;
1897
- public vector4(address: bigint, value?: Vector4): Vector4 | this {
1983
+ public vector4(address: bigint, value: Vector4, force?: boolean): this;
1984
+ public vector4(address: bigint, value?: Vector4, force?: boolean): Vector4 | this {
1898
1985
  // TypeScript is funny sometimes, isn't it?… 🫠…
1899
1986
  if (value === undefined) {
1900
1987
  return this.quaternion(address);
1901
1988
  }
1902
1989
 
1903
- return this.quaternion(address, value);
1990
+ return this.quaternion(address, value, force);
1904
1991
  }
1905
1992
 
1906
1993
  /**
1907
1994
  * Reads or writes an array of Vector4.
1908
1995
  * @param address Address to access.
1909
1996
  * @param lengthOrValues Length to read or array to write.
1997
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1910
1998
  * @returns Array of Vector4 read or this instance if writing.
1911
1999
  * @example
1912
2000
  * ```ts
1913
2001
  * const cs2 = new Memory('cs2.exe');
1914
- * const myVectors = cs2.vector4Array(0x12345678n, 2);
2002
+ * const myVector4s = cs2.vector4Array(0x12345678n, 2);
1915
2003
  * cs2.vector4Array(0x12345678n, [{ w: 1, x: 0, y: 0, z: 0 }]);
1916
2004
  * ```
1917
2005
  */
1918
2006
  public vector4Array(address: bigint, length: number): Vector4[];
1919
- public vector4Array(address: bigint, values: Vector4[]): this;
1920
- public vector4Array(address: bigint, lengthOrValues: Vector4[] | number): Vector4[] | this {
2007
+ public vector4Array(address: bigint, values: Vector4[], force?: boolean): this;
2008
+ public vector4Array(address: bigint, lengthOrValues: Vector4[] | number, force?: boolean): Vector4[] | this {
1921
2009
  // TypeScript is funny sometimes, isn't it?… 🫠…
1922
2010
  if (typeof lengthOrValues === 'number') {
1923
2011
  return this.quaternionArray(address, lengthOrValues);
1924
2012
  }
1925
2013
 
1926
- return this.quaternionArray(address, lengthOrValues);
2014
+ return this.quaternionArray(address, lengthOrValues, force);
1927
2015
  }
1928
2016
 
1929
2017
  public vector4Raw(address: bigint): Float32Array;
1930
- public vector4Raw(address: bigint, values: Float32Array): this;
1931
- public vector4Raw(address: bigint, values?: Float32Array): Float32Array | this {
2018
+ /**
2019
+ * Reads or writes a raw Vector4 as a Float32Array.
2020
+ * @param address Address to access.
2021
+ * @param values Optional Float32Array to write.
2022
+ * @param force When writing, if true temporarily changes page protection to allow the write.
2023
+ * @returns Float32Array read or this instance if writing.
2024
+ * @example
2025
+ * ```ts
2026
+ * const cs2 = new Memory('cs2.exe');
2027
+ * const myVector4 = cs2.vector4Raw(0x12345678n);
2028
+ * cs2.vector4Raw(0x12345678n, new Float32Array([1, 0, 0, 0]));
2029
+ * ```
2030
+ */
2031
+ public vector4Raw(address: bigint): Float32Array;
2032
+ public vector4Raw(address: bigint, values: Float32Array, force?: boolean): this;
2033
+ public vector4Raw(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1932
2034
  if (values === undefined) {
1933
2035
  return this.f32Array(address, 0x04);
1934
2036
  }
@@ -1937,7 +2039,7 @@ class Memory {
1937
2039
  throw new RangeError('values.length must be 4.');
1938
2040
  }
1939
2041
 
1940
- void this.write(address, values);
2042
+ void this.write(address, values, force);
1941
2043
 
1942
2044
  return this;
1943
2045
  }