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