bun-memory 1.1.45 → 1.1.47

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/structs/Memory.ts +449 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-memory",
3
- "version": "1.1.45",
3
+ "version": "1.1.47",
4
4
  "author": "Stev Peifer <stev@bell.net>",
5
5
  "repository": {
6
6
  "type": "git",
package/structs/Memory.ts CHANGED
@@ -159,7 +159,6 @@ class Memory {
159
159
  private readonly Scratch1080 = Buffer.allocUnsafe(0x438 /* sizeof(MODULEENTRY32W) */);
160
160
 
161
161
  private static TextDecoderUTF8 = new TextDecoder('utf-8');
162
-
163
162
  private static TextEncoderUTF8 = new TextEncoder('utf-8');
164
163
 
165
164
  private readonly hProcess: bigint;
@@ -1533,6 +1532,455 @@ class Memory {
1533
1532
  return this;
1534
1533
  }
1535
1534
 
1535
+ /**
1536
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as an Int16Array.
1537
+ * @param address Address of the TArray structure.
1538
+ * @param values Optional Int16Array to write.
1539
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1540
+ * @returns An Int16Array containing the elements, or this instance if writing.
1541
+ * @example
1542
+ * ```ts
1543
+ * const rl = new Memory('RocketLeague.exe');
1544
+ * const myArray = rl.tArrayI16(0x12345678n);
1545
+ * rl.tArrayI16(0x12345678n, new Int16Array([1, 2, 3]));
1546
+ * ```
1547
+ */
1548
+ public tArrayI16(address: bigint): Int16Array;
1549
+ public tArrayI16(address: bigint, values: Int16Array, force?: boolean): this;
1550
+ public tArrayI16(address: bigint, values?: Int16Array, force?: boolean): Int16Array | this {
1551
+ const dataPtr = this.u64(address);
1552
+
1553
+ if (values === undefined) {
1554
+ const count = this.u32(address + 0x08n);
1555
+ const scratch = new Int16Array(count);
1556
+
1557
+ void this.read(dataPtr, scratch);
1558
+
1559
+ return scratch;
1560
+ }
1561
+
1562
+ this.u32(address + 0x08n, values.length, force);
1563
+
1564
+ void this.write(dataPtr, values, force);
1565
+
1566
+ return this;
1567
+ }
1568
+
1569
+ /**
1570
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as an Int32Array.
1571
+ * @param address Address of the TArray structure.
1572
+ * @param values Optional Int32Array to write.
1573
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1574
+ * @returns An Int32Array containing the elements, or this instance if writing.
1575
+ * @example
1576
+ * ```ts
1577
+ * const rl = new Memory('RocketLeague.exe');
1578
+ * const myArray = rl.tArrayI32(0x12345678n);
1579
+ * rl.tArrayI32(0x12345678n, new Int32Array([1, 2, 3]));
1580
+ * ```
1581
+ */
1582
+ public tArrayI32(address: bigint): Int32Array;
1583
+ public tArrayI32(address: bigint, values: Int32Array, force?: boolean): this;
1584
+ public tArrayI32(address: bigint, values?: Int32Array, force?: boolean): Int32Array | this {
1585
+ const dataPtr = this.u64(address);
1586
+
1587
+ if (values === undefined) {
1588
+ const count = this.u32(address + 0x08n);
1589
+ const scratch = new Int32Array(count);
1590
+
1591
+ void this.read(dataPtr, scratch);
1592
+
1593
+ return scratch;
1594
+ }
1595
+
1596
+ this.u32(address + 0x08n, values.length, force);
1597
+
1598
+ void this.write(dataPtr, values, force);
1599
+
1600
+ return this;
1601
+ }
1602
+
1603
+ /**
1604
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a BigInt64Array.
1605
+ * @param address Address of the TArray structure.
1606
+ * @param values Optional BigInt64Array to write.
1607
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1608
+ * @returns A BigInt64Array containing the elements, or this instance if writing.
1609
+ * @example
1610
+ * ```ts
1611
+ * const rl = new Memory('RocketLeague.exe');
1612
+ * const myArray = rl.tArrayI64(0x12345678n);
1613
+ * rl.tArrayI64(0x12345678n, new BigInt64Array([1n, 2n, 3n]));
1614
+ * ```
1615
+ */
1616
+ public tArrayI64(address: bigint): BigInt64Array;
1617
+ public tArrayI64(address: bigint, values: BigInt64Array, force?: boolean): this;
1618
+ public tArrayI64(address: bigint, values?: BigInt64Array, force?: boolean): BigInt64Array | this {
1619
+ const dataPtr = this.u64(address);
1620
+
1621
+ if (values === undefined) {
1622
+ const count = this.u32(address + 0x08n);
1623
+ const scratch = new BigInt64Array(count);
1624
+
1625
+ void this.read(dataPtr, scratch);
1626
+
1627
+ return scratch;
1628
+ }
1629
+
1630
+ this.u32(address + 0x08n, values.length, force);
1631
+
1632
+ void this.write(dataPtr, values, force);
1633
+
1634
+ return this;
1635
+ }
1636
+
1637
+ /**
1638
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a Float32Array.
1639
+ * @param address Address of the TArray structure.
1640
+ * @param values Optional Float32Array to write.
1641
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1642
+ * @returns A Float32Array containing the elements, or this instance if writing.
1643
+ * @example
1644
+ * ```ts
1645
+ * const rl = new Memory('RocketLeague.exe');
1646
+ * const myArray = rl.tArrayF32(0x12345678n);
1647
+ * rl.tArrayF32(0x12345678n, new Float32Array([1.0, 2.0, 3.0]));
1648
+ * ```
1649
+ */
1650
+ public tArrayF32(address: bigint): Float32Array;
1651
+ public tArrayF32(address: bigint, values: Float32Array, force?: boolean): this;
1652
+ public tArrayF32(address: bigint, values?: Float32Array, force?: boolean): Float32Array | this {
1653
+ const dataPtr = this.u64(address);
1654
+
1655
+ if (values === undefined) {
1656
+ const count = this.u32(address + 0x08n);
1657
+ const scratch = new Float32Array(count);
1658
+
1659
+ void this.read(dataPtr, scratch);
1660
+
1661
+ return scratch;
1662
+ }
1663
+
1664
+ this.u32(address + 0x08n, values.length, force);
1665
+
1666
+ void this.write(dataPtr, values, force);
1667
+
1668
+ return this;
1669
+ }
1670
+
1671
+ /**
1672
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a Float64Array.
1673
+ * @param address Address of the TArray structure.
1674
+ * @param values Optional Float64Array to write.
1675
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1676
+ * @returns A Float64Array containing the elements, or this instance if writing.
1677
+ * @example
1678
+ * ```ts
1679
+ * const rl = new Memory('RocketLeague.exe');
1680
+ * const myArray = rl.tArrayF64(0x12345678n);
1681
+ * rl.tArrayF64(0x12345678n, new Float64Array([1.0, 2.0, 3.0]));
1682
+ * ```
1683
+ */
1684
+ public tArrayF64(address: bigint): Float64Array;
1685
+ public tArrayF64(address: bigint, values: Float64Array, force?: boolean): this;
1686
+ public tArrayF64(address: bigint, values?: Float64Array, force?: boolean): Float64Array | this {
1687
+ const dataPtr = this.u64(address);
1688
+
1689
+ if (values === undefined) {
1690
+ const count = this.u32(address + 0x08n);
1691
+ const scratch = new Float64Array(count);
1692
+
1693
+ void this.read(dataPtr, scratch);
1694
+
1695
+ return scratch;
1696
+ }
1697
+
1698
+ this.u32(address + 0x08n, values.length, force);
1699
+
1700
+ void this.write(dataPtr, values, force);
1701
+
1702
+ return this;
1703
+ }
1704
+
1705
+ /**
1706
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as an Int8Array.
1707
+ * @param address Address of the TArray structure.
1708
+ * @param values Optional Int8Array to write.
1709
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1710
+ * @returns An Int8Array containing the elements, or this instance if writing.
1711
+ * @example
1712
+ * ```ts
1713
+ * const rl = new Memory('RocketLeague.exe');
1714
+ * const myArray = rl.tArrayI8(0x12345678n);
1715
+ * rl.tArrayI8(0x12345678n, new Int8Array([1, 2, 3]));
1716
+ * ```
1717
+ */
1718
+ public tArrayI8(address: bigint): Int8Array;
1719
+ public tArrayI8(address: bigint, values: Int8Array, force?: boolean): this;
1720
+ public tArrayI8(address: bigint, values?: Int8Array, force?: boolean): Int8Array | this {
1721
+ const dataPtr = this.u64(address);
1722
+
1723
+ if (values === undefined) {
1724
+ const count = this.u32(address + 0x08n);
1725
+ const scratch = new Int8Array(count);
1726
+
1727
+ void this.read(dataPtr, scratch);
1728
+
1729
+ return scratch;
1730
+ }
1731
+
1732
+ this.u32(address + 0x08n, values.length, force);
1733
+
1734
+ void this.write(dataPtr, values, force);
1735
+
1736
+ return this;
1737
+ }
1738
+
1739
+ /**
1740
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a Uint16Array.
1741
+ * @param address Address of the TArray structure.
1742
+ * @param values Optional Uint16Array to write.
1743
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1744
+ * @returns A Uint16Array containing the elements, or this instance if writing.
1745
+ * @example
1746
+ * ```ts
1747
+ * const rl = new Memory('RocketLeague.exe');
1748
+ * const myArray = rl.tArrayU16(0x12345678n);
1749
+ * rl.tArrayU16(0x12345678n, new Uint16Array([1, 2, 3]));
1750
+ * ```
1751
+ */
1752
+ public tArrayU16(address: bigint): Uint16Array;
1753
+ public tArrayU16(address: bigint, values: Uint16Array, force?: boolean): this;
1754
+ public tArrayU16(address: bigint, values?: Uint16Array, force?: boolean): Uint16Array | this {
1755
+ const dataPtr = this.u64(address);
1756
+
1757
+ if (values === undefined) {
1758
+ const count = this.u32(address + 0x08n);
1759
+ const scratch = new Uint16Array(count);
1760
+
1761
+ void this.read(dataPtr, scratch);
1762
+
1763
+ return scratch;
1764
+ }
1765
+
1766
+ this.u32(address + 0x08n, values.length, force);
1767
+
1768
+ void this.write(dataPtr, values, force);
1769
+
1770
+ return this;
1771
+ }
1772
+
1773
+ /**
1774
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a Uint32Array.
1775
+ * @param address Address of the TArray structure.
1776
+ * @param values Optional Uint32Array to write.
1777
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1778
+ * @returns A Uint32Array containing the elements, or this instance if writing.
1779
+ * @example
1780
+ * ```ts
1781
+ * const rl = new Memory('RocketLeague.exe');
1782
+ * const myArray = rl.tArrayU32(0x12345678n);
1783
+ * rl.tArrayU32(0x12345678n, new Uint32Array([1, 2, 3]));
1784
+ * ```
1785
+ */
1786
+ public tArrayU32(address: bigint): Uint32Array;
1787
+ public tArrayU32(address: bigint, values: Uint32Array, force?: boolean): this;
1788
+ public tArrayU32(address: bigint, values?: Uint32Array, force?: boolean): Uint32Array | this {
1789
+ const dataPtr = this.u64(address);
1790
+
1791
+ if (values === undefined) {
1792
+ const count = this.u32(address + 0x08n);
1793
+ const scratch = new Uint32Array(count);
1794
+
1795
+ void this.read(dataPtr, scratch);
1796
+
1797
+ return scratch;
1798
+ }
1799
+
1800
+ this.u32(address + 0x08n, values.length, force);
1801
+
1802
+ void this.write(dataPtr, values, force);
1803
+
1804
+ return this;
1805
+ }
1806
+
1807
+ /**
1808
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a BigUint64Array.
1809
+ * @param address Address of the TArray structure.
1810
+ * @param values Optional BigUint64Array to write.
1811
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1812
+ * @returns A BigUint64Array containing the elements, or this instance if writing.
1813
+ * @example
1814
+ * ```ts
1815
+ * const rl = new Memory('RocketLeague.exe');
1816
+ * const myArray = rl.tArrayU64(0x12345678n);
1817
+ * rl.tArrayU64(0x12345678n, new BigUint64Array([1n, 2n, 3n]));
1818
+ * ```
1819
+ */
1820
+ public tArrayU64(address: bigint): BigUint64Array;
1821
+ public tArrayU64(address: bigint, values: BigUint64Array, force?: boolean): this;
1822
+ public tArrayU64(address: bigint, values?: BigUint64Array, force?: boolean): BigUint64Array | this {
1823
+ const dataPtr = this.u64(address);
1824
+
1825
+ if (values === undefined) {
1826
+ const count = this.u32(address + 0x08n);
1827
+ const scratch = new BigUint64Array(count);
1828
+
1829
+ void this.read(dataPtr, scratch);
1830
+
1831
+ return scratch;
1832
+ }
1833
+
1834
+ this.u32(address + 0x08n, values.length, force);
1835
+
1836
+ void this.write(dataPtr, values, force);
1837
+
1838
+ return this;
1839
+ }
1840
+
1841
+ /**
1842
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a Uint8Array.
1843
+ * @param address Address of the TArray structure.
1844
+ * @param values Optional Uint8Array to write.
1845
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1846
+ * @returns A Uint8Array containing the elements, or this instance if writing.
1847
+ * @example
1848
+ * ```ts
1849
+ * const rl = new Memory('RocketLeague.exe');
1850
+ * const myArray = rl.tArrayU8(0x12345678n);
1851
+ * rl.tArrayU8(0x12345678n, new Uint8Array([1, 2, 3]));
1852
+ * ```
1853
+ */
1854
+ public tArrayU8(address: bigint): Uint8Array;
1855
+ public tArrayU8(address: bigint, values: Uint8Array, force?: boolean): this;
1856
+ public tArrayU8(address: bigint, values?: Uint8Array, force?: boolean): Uint8Array | this {
1857
+ const dataPtr = this.u64(address);
1858
+
1859
+ if (values === undefined) {
1860
+ const count = this.u32(address + 0x08n);
1861
+ const scratch = new Uint8Array(count);
1862
+
1863
+ void this.read(dataPtr, scratch);
1864
+
1865
+ return scratch;
1866
+ }
1867
+
1868
+ this.u32(address + 0x08n, values.length, force);
1869
+
1870
+ void this.write(dataPtr, values, force);
1871
+
1872
+ return this;
1873
+ }
1874
+
1875
+ /**
1876
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a BigUint64Array.
1877
+ * @param address Address of the TArray structure.
1878
+ * @param values Optional BigUint64Array to write.
1879
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1880
+ * @returns A BigUint64Array containing the elements, or this instance if writing.
1881
+ * @example
1882
+ * ```ts
1883
+ * const rl = new Memory('RocketLeague.exe');
1884
+ * const myArray = rl.tArrayUPtr(0x12345678n);
1885
+ * rl.tArrayUPtr(0x12345678n, new BigUint64Array([1n, 2n, 3n]));
1886
+ * ```
1887
+ */
1888
+ public tArrayUPtr(address: bigint): BigUint64Array;
1889
+ public tArrayUPtr(address: bigint, values: BigUint64Array, force?: boolean): this;
1890
+ public tArrayUPtr(address: bigint, values?: BigUint64Array, force?: boolean): BigUint64Array | this {
1891
+ // TypeScript is funny sometimes, isn't it?… 🫠…
1892
+ if (values === undefined) {
1893
+ return this.tArrayU64(address);
1894
+ }
1895
+
1896
+ return this.tArrayU64(address, values, force);
1897
+ }
1898
+
1899
+ /**
1900
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a UTF-8 string.
1901
+ * @param address Address of the TArray structure.
1902
+ * @param value Optional string to write.
1903
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1904
+ * @returns The string, or this instance if writing.
1905
+ * @example
1906
+ * ```ts
1907
+ * const rl = new Memory('RocketLeague.exe');
1908
+ * const myString = rl.tArrayChar(0x12345678n);
1909
+ * rl.tArrayChar(0x12345678n, 'hello');
1910
+ * ```
1911
+ */
1912
+ public tArrayChar(address: bigint): string;
1913
+ public tArrayChar(address: bigint, value: string, force?: boolean): this;
1914
+ public tArrayChar(address: bigint, value?: string, force?: boolean): string | this {
1915
+ const dataPtr = this.u64(address);
1916
+
1917
+ if (value === undefined) {
1918
+ const count = this.u32(address + 0x08n);
1919
+
1920
+ if (count === 0x00) {
1921
+ return '';
1922
+ }
1923
+
1924
+ const scratch = Buffer.allocUnsafe(count - 0x01);
1925
+
1926
+ void this.read(dataPtr, scratch);
1927
+
1928
+ return scratch.toString('utf8');
1929
+ }
1930
+
1931
+ const scratch = Buffer.from(value, 'utf8');
1932
+
1933
+ this.u32(address + 0x08n, scratch.length + 0x01, force);
1934
+
1935
+ void this.write(dataPtr, scratch, force);
1936
+
1937
+ return this;
1938
+ }
1939
+
1940
+ /**
1941
+ * Reads or writes a TArray (Data at 0x00, Count at 0x08, Max at 0x0c) as a UTF-16LE string.
1942
+ * This is the format used by FName/FString in Unreal Engine.
1943
+ * @param address Address of the TArray structure.
1944
+ * @param value Optional string to write.
1945
+ * @param force When writing, if true temporarily changes page protection to allow the write.
1946
+ * @returns The string, or this instance if writing.
1947
+ * @example
1948
+ * ```ts
1949
+ * const rl = new Memory('RocketLeague.exe');
1950
+ * const myString = rl.tArrayWChar(0x12345678n);
1951
+ * rl.tArrayWChar(0x12345678n, 'hello');
1952
+ * ```
1953
+ */
1954
+ public tArrayWChar(address: bigint): string;
1955
+ public tArrayWChar(address: bigint, value: string, force?: boolean): this;
1956
+ public tArrayWChar(address: bigint, value?: string, force?: boolean): string | this {
1957
+ const dataPtr = this.u64(address);
1958
+
1959
+ if (value === undefined) {
1960
+ const count = this.u32(address + 0x08n);
1961
+
1962
+ if (count === 0) {
1963
+ return '';
1964
+ }
1965
+
1966
+ const scratch = Buffer.allocUnsafe((count - 0x01) * 0x02);
1967
+
1968
+ void this.read(dataPtr, scratch);
1969
+
1970
+ return scratch.toString('utf16le');
1971
+ }
1972
+
1973
+ const scratch = Buffer.allocUnsafe(value.length * 0x02);
1974
+
1975
+ scratch.write(value, 0, 'utf16le');
1976
+
1977
+ this.u32(address + 0x08n, value.length + 0x01, force);
1978
+
1979
+ void this.write(dataPtr, scratch, force);
1980
+
1981
+ return this;
1982
+ }
1983
+
1536
1984
  /**
1537
1985
  * Reads or writes a 16-bit unsigned integer.
1538
1986
  * @param address Address to access.