bun-memory 1.1.40 → 1.1.42
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/package.json +1 -1
- package/structs/Memory.ts +77 -0
package/package.json
CHANGED
package/structs/Memory.ts
CHANGED
|
@@ -1793,6 +1793,48 @@ class Memory {
|
|
|
1793
1793
|
return capacity === count ? result : result.subarray(0, count);
|
|
1794
1794
|
}
|
|
1795
1795
|
|
|
1796
|
+
/**
|
|
1797
|
+
* Reads or writes a generic UtlVector as raw bytes (no typing).
|
|
1798
|
+
* Pass elementSize (bytes per element) so we can set/read the header count.
|
|
1799
|
+
* @example
|
|
1800
|
+
* ```ts
|
|
1801
|
+
* const bytes = cs2.utlVectorRaw(0x1234n, 0x14); // read size*elementSize bytes
|
|
1802
|
+
* cs2.utlVectorRaw(0x1234n, 0x14, new Uint8Array([...])); // write
|
|
1803
|
+
* ```
|
|
1804
|
+
*/
|
|
1805
|
+
public utlVectorRaw(address: bigint, elementSize: number): Uint8Array;
|
|
1806
|
+
public utlVectorRaw(address: bigint, elementSize: number, values: Uint8Array, force?: boolean): this;
|
|
1807
|
+
public utlVectorRaw(address: bigint, elementSize: number, values?: Uint8Array, force?: boolean): Uint8Array | this {
|
|
1808
|
+
const elementsPtr = this.u64(address + 0x08n);
|
|
1809
|
+
|
|
1810
|
+
if (values === undefined) {
|
|
1811
|
+
const count = this.u32(address);
|
|
1812
|
+
|
|
1813
|
+
if (count === 0 || elementsPtr === 0n) {
|
|
1814
|
+
return new Uint8Array(0);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
const byteLength = count * elementSize;
|
|
1818
|
+
const scratch = new Uint8Array(byteLength);
|
|
1819
|
+
|
|
1820
|
+
void this.read(elementsPtr, scratch);
|
|
1821
|
+
|
|
1822
|
+
return scratch;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
if (values.byteLength % elementSize !== 0) {
|
|
1826
|
+
throw new RangeError('values length must be a multiple of elementSize');
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
const count = values.byteLength / elementSize;
|
|
1830
|
+
|
|
1831
|
+
this.u32(address, count, force);
|
|
1832
|
+
|
|
1833
|
+
void this.write(elementsPtr, values, force);
|
|
1834
|
+
|
|
1835
|
+
return this;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1796
1838
|
/**
|
|
1797
1839
|
* Reads or writes a UtlVectorU32 (Uint32Array).
|
|
1798
1840
|
* @param address Address to access.
|
|
@@ -1828,6 +1870,41 @@ class Memory {
|
|
|
1828
1870
|
return this;
|
|
1829
1871
|
}
|
|
1830
1872
|
|
|
1873
|
+
/**
|
|
1874
|
+
* Reads or writes a UtlVectorU64 (BigUint64Array).
|
|
1875
|
+
* @param address Address to access.
|
|
1876
|
+
* @param values Optional BigUint64Array to write.
|
|
1877
|
+
* @param force When writing, if true temporarily changes page protection to allow the write.
|
|
1878
|
+
* @returns The vector at address, or this instance if writing.
|
|
1879
|
+
* @example
|
|
1880
|
+
* ```ts
|
|
1881
|
+
* const cs2 = new Memory('cs2.exe');
|
|
1882
|
+
* const myVector = cs2.utlVectorU64(0x12345678n);
|
|
1883
|
+
* cs2.utlVectorU64(0x12345678n, new BigUint64Array([1n,2n,3n]));
|
|
1884
|
+
* ```
|
|
1885
|
+
*/
|
|
1886
|
+
public utlVectorU64(address: bigint): BigUint64Array;
|
|
1887
|
+
public utlVectorU64(address: bigint, values: BigUint64Array, force?: boolean): this;
|
|
1888
|
+
public utlVectorU64(address: bigint, values?: BigUint64Array, force?: boolean): BigUint64Array | this {
|
|
1889
|
+
const elementsPtr = this.u64(address + 0x08n);
|
|
1890
|
+
|
|
1891
|
+
if (values === undefined) {
|
|
1892
|
+
const size = this.u32(address);
|
|
1893
|
+
|
|
1894
|
+
const scratch = new BigUint64Array(size);
|
|
1895
|
+
|
|
1896
|
+
void this.read(elementsPtr, scratch);
|
|
1897
|
+
|
|
1898
|
+
return scratch;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
this.u32(address, values.length, force);
|
|
1902
|
+
|
|
1903
|
+
void this.write(elementsPtr, values, force);
|
|
1904
|
+
|
|
1905
|
+
return this;
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1831
1908
|
/**
|
|
1832
1909
|
* Reads or writes a Vector2 (object with x, y).
|
|
1833
1910
|
* @param address Address to access.
|