@vlydev/cs2-masked-inspect-ts 1.0.0

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +221 -0
  3. package/dist/cjs/InspectLink.d.ts +45 -0
  4. package/dist/cjs/InspectLink.d.ts.map +1 -0
  5. package/dist/cjs/InspectLink.js +368 -0
  6. package/dist/cjs/ItemPreviewData.d.ts +59 -0
  7. package/dist/cjs/ItemPreviewData.d.ts.map +1 -0
  8. package/dist/cjs/ItemPreviewData.js +28 -0
  9. package/dist/cjs/Sticker.d.ts +34 -0
  10. package/dist/cjs/Sticker.d.ts.map +1 -0
  11. package/dist/cjs/Sticker.js +19 -0
  12. package/dist/cjs/crc32.d.ts +9 -0
  13. package/dist/cjs/crc32.d.ts.map +1 -0
  14. package/dist/cjs/crc32.js +28 -0
  15. package/dist/cjs/index.d.ts +10 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +15 -0
  18. package/dist/cjs/proto/reader.d.ts +42 -0
  19. package/dist/cjs/proto/reader.d.ts.map +1 -0
  20. package/dist/cjs/proto/reader.js +105 -0
  21. package/dist/cjs/proto/writer.d.ts +31 -0
  22. package/dist/cjs/proto/writer.d.ts.map +1 -0
  23. package/dist/cjs/proto/writer.js +105 -0
  24. package/dist/esm/InspectLink.d.ts +45 -0
  25. package/dist/esm/InspectLink.d.ts.map +1 -0
  26. package/dist/esm/InspectLink.js +364 -0
  27. package/dist/esm/ItemPreviewData.d.ts +59 -0
  28. package/dist/esm/ItemPreviewData.d.ts.map +1 -0
  29. package/dist/esm/ItemPreviewData.js +24 -0
  30. package/dist/esm/Sticker.d.ts +34 -0
  31. package/dist/esm/Sticker.d.ts.map +1 -0
  32. package/dist/esm/Sticker.js +15 -0
  33. package/dist/esm/crc32.d.ts +9 -0
  34. package/dist/esm/crc32.d.ts.map +1 -0
  35. package/dist/esm/crc32.js +25 -0
  36. package/dist/esm/index.d.ts +10 -0
  37. package/dist/esm/index.d.ts.map +1 -0
  38. package/dist/esm/index.js +6 -0
  39. package/dist/esm/proto/reader.d.ts +42 -0
  40. package/dist/esm/proto/reader.d.ts.map +1 -0
  41. package/dist/esm/proto/reader.js +101 -0
  42. package/dist/esm/proto/writer.d.ts +31 -0
  43. package/dist/esm/proto/writer.d.ts.map +1 -0
  44. package/dist/esm/proto/writer.js +101 -0
  45. package/package.json +43 -0
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Pure TypeScript protobuf binary reader.
3
+ *
4
+ * Implements the subset of wire types needed for CEconItemPreviewDataBlock:
5
+ * - Wire type 0: varint (uint32, uint64, int32)
6
+ * - Wire type 2: length-delimited (string, bytes, nested messages)
7
+ * - Wire type 5: 32-bit fixed (float32)
8
+ */
9
+ export const WIRE_VARINT = 0;
10
+ export const WIRE_64BIT = 1;
11
+ export const WIRE_LEN = 2;
12
+ export const WIRE_32BIT = 5;
13
+ export class ProtoReader {
14
+ constructor(data) {
15
+ this._data = data;
16
+ this._pos = 0;
17
+ }
18
+ get pos() {
19
+ return this._pos;
20
+ }
21
+ remaining() {
22
+ return this._data.length - this._pos;
23
+ }
24
+ readByte() {
25
+ if (this._pos >= this._data.length) {
26
+ throw new RangeError('Unexpected end of protobuf data');
27
+ }
28
+ return this._data[this._pos++];
29
+ }
30
+ readBytes(n) {
31
+ if (this._pos + n > this._data.length) {
32
+ throw new RangeError(`Need ${n} bytes but only ${this._data.length - this._pos} remain`);
33
+ }
34
+ const chunk = this._data.slice(this._pos, this._pos + n);
35
+ this._pos += n;
36
+ return chunk;
37
+ }
38
+ /**
39
+ * Read a base-128 varint.
40
+ * Returns a BigInt for 64-bit range safety; callers convert as needed.
41
+ */
42
+ readVarint() {
43
+ let result = 0n;
44
+ let shift = 0n;
45
+ while (true) {
46
+ const b = this.readByte();
47
+ result |= BigInt(b & 0x7F) << shift;
48
+ if (!(b & 0x80))
49
+ break;
50
+ shift += 7n;
51
+ if (shift > 63n) {
52
+ throw new RangeError('Varint too long');
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ /**
58
+ * Read tag and return [fieldNumber, wireType].
59
+ */
60
+ readTag() {
61
+ const tag = this.readVarint();
62
+ return [Number(tag >> 3n), Number(tag & 7n)];
63
+ }
64
+ readLengthDelimited() {
65
+ const length = Number(this.readVarint());
66
+ return this.readBytes(length);
67
+ }
68
+ /**
69
+ * Read all fields until EOF.
70
+ * Max 100 fields enforced.
71
+ */
72
+ readAllFields() {
73
+ const fields = [];
74
+ let fieldCount = 0;
75
+ while (this.remaining() > 0) {
76
+ if (++fieldCount > 100) {
77
+ throw new RangeError('Protobuf field count exceeds limit of 100');
78
+ }
79
+ const [fieldNum, wireType] = this.readTag();
80
+ let value;
81
+ switch (wireType) {
82
+ case WIRE_VARINT:
83
+ value = this.readVarint();
84
+ break;
85
+ case WIRE_64BIT:
86
+ value = this.readBytes(8);
87
+ break;
88
+ case WIRE_LEN:
89
+ value = this.readLengthDelimited();
90
+ break;
91
+ case WIRE_32BIT:
92
+ value = this.readBytes(4);
93
+ break;
94
+ default:
95
+ throw new RangeError(`Unknown wire type ${wireType} for field ${fieldNum}`);
96
+ }
97
+ fields.push({ field: fieldNum, wire: wireType, value });
98
+ }
99
+ return fields;
100
+ }
101
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Pure TypeScript protobuf binary writer.
3
+ *
4
+ * Writes to an in-memory buffer; call toBytes() to retrieve the result.
5
+ * Fields with default/zero values are omitted (proto3 semantics).
6
+ */
7
+ export declare class ProtoWriter {
8
+ private _buf;
9
+ constructor();
10
+ toBytes(): Uint8Array;
11
+ private _writeVarint;
12
+ private _writeTag;
13
+ writeUint32(fieldNum: number, value: number | bigint): void;
14
+ writeUint64(fieldNum: number, value: number | bigint): void;
15
+ writeInt32(fieldNum: number, value: number | bigint): void;
16
+ writeString(fieldNum: number, value: string): void;
17
+ /**
18
+ * Write a float32 as wire type 5 (fixed 32-bit, little-endian).
19
+ * Used for sticker float fields (wear, scale, rotation, etc.).
20
+ */
21
+ writeFloat32Fixed(fieldNum: number, value: number): void;
22
+ /**
23
+ * Write raw bytes as a length-delimited field (wire type 2).
24
+ */
25
+ writeRawBytes(fieldNum: number, data: Uint8Array): void;
26
+ /**
27
+ * Write a nested message (another ProtoWriter's output) as a length-delimited field.
28
+ */
29
+ writeEmbedded(fieldNum: number, nested: ProtoWriter): void;
30
+ }
31
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../../src/proto/writer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,qBAAa,WAAW;IACtB,OAAO,CAAC,IAAI,CAAe;;IAM3B,OAAO,IAAI,UAAU;IAerB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,SAAS;IAQjB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAM3D,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAM3D,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAM1D,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAQlD;;;OAGG;IACH,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAOxD;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAOvD;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI;CAG3D"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Pure TypeScript protobuf binary writer.
3
+ *
4
+ * Writes to an in-memory buffer; call toBytes() to retrieve the result.
5
+ * Fields with default/zero values are omitted (proto3 semantics).
6
+ */
7
+ const WIRE_VARINT = 0;
8
+ const WIRE_LEN = 2;
9
+ const WIRE_32BIT = 5;
10
+ export class ProtoWriter {
11
+ constructor() {
12
+ this._buf = [];
13
+ }
14
+ toBytes() {
15
+ const totalLength = this._buf.reduce((sum, chunk) => sum + chunk.length, 0);
16
+ const result = new Uint8Array(totalLength);
17
+ let offset = 0;
18
+ for (const chunk of this._buf) {
19
+ result.set(chunk, offset);
20
+ offset += chunk.length;
21
+ }
22
+ return result;
23
+ }
24
+ // ------------------------------------------------------------------
25
+ // Low-level primitives
26
+ // ------------------------------------------------------------------
27
+ _writeVarint(value) {
28
+ let v = BigInt(value);
29
+ // Handle negative: treat as unsigned 64-bit two's complement
30
+ if (v < 0n) {
31
+ v = BigInt.asUintN(64, v);
32
+ }
33
+ const parts = [];
34
+ do {
35
+ let b = Number(v & 0x7fn);
36
+ v >>= 7n;
37
+ if (v !== 0n)
38
+ b |= 0x80;
39
+ parts.push(b);
40
+ } while (v !== 0n);
41
+ this._buf.push(new Uint8Array(parts));
42
+ }
43
+ _writeTag(fieldNum, wireType) {
44
+ this._writeVarint((fieldNum << 3) | wireType);
45
+ }
46
+ // ------------------------------------------------------------------
47
+ // Public field writers
48
+ // ------------------------------------------------------------------
49
+ writeUint32(fieldNum, value) {
50
+ if (value === 0 || value === 0n)
51
+ return;
52
+ this._writeTag(fieldNum, WIRE_VARINT);
53
+ this._writeVarint(value);
54
+ }
55
+ writeUint64(fieldNum, value) {
56
+ if (value === 0 || value === 0n)
57
+ return;
58
+ this._writeTag(fieldNum, WIRE_VARINT);
59
+ this._writeVarint(value);
60
+ }
61
+ writeInt32(fieldNum, value) {
62
+ if (value === 0 || value === 0n)
63
+ return;
64
+ this._writeTag(fieldNum, WIRE_VARINT);
65
+ this._writeVarint(value);
66
+ }
67
+ writeString(fieldNum, value) {
68
+ if (!value)
69
+ return;
70
+ const encoded = new TextEncoder().encode(value);
71
+ this._writeTag(fieldNum, WIRE_LEN);
72
+ this._writeVarint(encoded.length);
73
+ this._buf.push(encoded);
74
+ }
75
+ /**
76
+ * Write a float32 as wire type 5 (fixed 32-bit, little-endian).
77
+ * Used for sticker float fields (wear, scale, rotation, etc.).
78
+ */
79
+ writeFloat32Fixed(fieldNum, value) {
80
+ this._writeTag(fieldNum, WIRE_32BIT);
81
+ const dv = new DataView(new ArrayBuffer(4));
82
+ dv.setFloat32(0, value, true); // little-endian
83
+ this._buf.push(new Uint8Array(dv.buffer));
84
+ }
85
+ /**
86
+ * Write raw bytes as a length-delimited field (wire type 2).
87
+ */
88
+ writeRawBytes(fieldNum, data) {
89
+ if (!data || data.length === 0)
90
+ return;
91
+ this._writeTag(fieldNum, WIRE_LEN);
92
+ this._writeVarint(data.length);
93
+ this._buf.push(data);
94
+ }
95
+ /**
96
+ * Write a nested message (another ProtoWriter's output) as a length-delimited field.
97
+ */
98
+ writeEmbedded(fieldNum, nested) {
99
+ this.writeRawBytes(fieldNum, nested.toBytes());
100
+ }
101
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vlydev/cs2-masked-inspect-ts",
3
+ "version": "1.0.0",
4
+ "description": "Offline encoder/decoder for CS2 masked inspect URLs — TypeScript, fully typed, no dependencies",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.js",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/esm/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/esm/index.d.ts",
13
+ "default": "./dist/esm/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/cjs/index.d.ts",
17
+ "default": "./dist/cjs/index.js"
18
+ }
19
+ }
20
+ },
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
23
+ "test": "node --experimental-strip-types --test tests/inspect_link.test.ts",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "keywords": ["cs2", "csgo", "inspect", "protobuf", "steam", "typescript"],
27
+ "author": {
28
+ "name": "VlyDev",
29
+ "email": "vladdnepr1989@gmail.com",
30
+ "url": "https://github.com/vlydev"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/vlydev/cs2-masked-inspect-ts"
35
+ },
36
+ "license": "MIT",
37
+ "engines": {
38
+ "node": ">=18.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "^5.6.0"
42
+ }
43
+ }