cs2-inventory-resolver 0.4.38 → 0.4.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/LICENSE +21 -21
- package/README.md +153 -145
- package/data/inventory.json +1 -1
- package/dist/resolver.d.ts +10 -9
- package/dist/resolver.js +32 -18
- package/dist/resolver.test.js +32 -0
- package/dist/types.d.ts +6 -2
- package/package.json +39 -39
package/dist/resolver.d.ts
CHANGED
|
@@ -8,15 +8,16 @@ import type { GcItemInput, ResolvedItemData } from './types.js';
|
|
|
8
8
|
* 3. Highlights / souvenir charms (by attribute 314)
|
|
9
9
|
* 4. Sticker slabs (by attribute 321)
|
|
10
10
|
* 5. Keychains (by attribute 299)
|
|
11
|
-
* 6.
|
|
12
|
-
* 7.
|
|
13
|
-
* 8.
|
|
14
|
-
* 9.
|
|
15
|
-
* 10.
|
|
16
|
-
* 11.
|
|
17
|
-
* 12.
|
|
18
|
-
* 13.
|
|
19
|
-
* 14.
|
|
11
|
+
* 6. Pets (by attribute 296 + `style`, only for `def_index` 4681)
|
|
12
|
+
* 7. Graffiti (by `stickers[0].sticker_id` + attribute 233)
|
|
13
|
+
* 8. Keys (by `def_index`)
|
|
14
|
+
* 9. Crates / cases (by `def_index`)
|
|
15
|
+
* 10. Collectibles (by `def_index`)
|
|
16
|
+
* 11. Agents (by `def_index`)
|
|
17
|
+
* 12. Tools (by `def_index`)
|
|
18
|
+
* 13. Sticker slabs (by `stickers[0].sticker_id`, only for `def_index` 1355)
|
|
19
|
+
* 14. Patches (by `stickers[0].sticker_id`)
|
|
20
|
+
* 15. Stickers (by `stickers[0].sticker_id`)
|
|
20
21
|
*
|
|
21
22
|
* @param gcItem - The raw GC item to resolve.
|
|
22
23
|
* @returns The resolved item data, or `null` if the item could not be identified.
|
package/dist/resolver.js
CHANGED
|
@@ -3,6 +3,8 @@ import { getData } from './data-loader.js';
|
|
|
3
3
|
const TRADE_PROTECTED_ESCROW_DATE = 312;
|
|
4
4
|
/** The item def_index shared by every sticker slab. */
|
|
5
5
|
const STICKER_SLAB_DEF_INDEX = 1355;
|
|
6
|
+
/** The item def_index shared by every pet. */
|
|
7
|
+
const PET_DEF_INDEX = 4681;
|
|
6
8
|
/**
|
|
7
9
|
* Derive the trade state of an item instance from attribute 312
|
|
8
10
|
* (`trade_protected_escrow_date`).
|
|
@@ -96,15 +98,16 @@ function makeResult(entry, gcItem, entity) {
|
|
|
96
98
|
* 3. Highlights / souvenir charms (by attribute 314)
|
|
97
99
|
* 4. Sticker slabs (by attribute 321)
|
|
98
100
|
* 5. Keychains (by attribute 299)
|
|
99
|
-
* 6.
|
|
100
|
-
* 7.
|
|
101
|
-
* 8.
|
|
102
|
-
* 9.
|
|
103
|
-
* 10.
|
|
104
|
-
* 11.
|
|
105
|
-
* 12.
|
|
106
|
-
* 13.
|
|
107
|
-
* 14.
|
|
101
|
+
* 6. Pets (by attribute 296 + `style`, only for `def_index` 4681)
|
|
102
|
+
* 7. Graffiti (by `stickers[0].sticker_id` + attribute 233)
|
|
103
|
+
* 8. Keys (by `def_index`)
|
|
104
|
+
* 9. Crates / cases (by `def_index`)
|
|
105
|
+
* 10. Collectibles (by `def_index`)
|
|
106
|
+
* 11. Agents (by `def_index`)
|
|
107
|
+
* 12. Tools (by `def_index`)
|
|
108
|
+
* 13. Sticker slabs (by `stickers[0].sticker_id`, only for `def_index` 1355)
|
|
109
|
+
* 14. Patches (by `stickers[0].sticker_id`)
|
|
110
|
+
* 15. Stickers (by `stickers[0].sticker_id`)
|
|
108
111
|
*
|
|
109
112
|
* @param gcItem - The raw GC item to resolve.
|
|
110
113
|
* @returns The resolved item data, or `null` if the item could not be identified.
|
|
@@ -123,6 +126,7 @@ export function resolveItem(gcItem) {
|
|
|
123
126
|
const highlightIndex = getAttributeUint32(gcItem, 314);
|
|
124
127
|
const keychainIndex = getAttributeUint32(gcItem, 299);
|
|
125
128
|
const stickerSlabIndex = getAttributeUint32(gcItem, 321);
|
|
129
|
+
const petId = getAttributeUint32(gcItem, 296);
|
|
126
130
|
// 1. Skins: def_index + paint_index
|
|
127
131
|
if (gcItem.paint_index && gcItem.paint_index > 0) {
|
|
128
132
|
const weapon = data.skins[defIdx];
|
|
@@ -160,7 +164,17 @@ export function resolveItem(gcItem) {
|
|
|
160
164
|
if (keychain)
|
|
161
165
|
return makeResult(keychain, gcItem, 'keychain');
|
|
162
166
|
}
|
|
163
|
-
// 6.
|
|
167
|
+
// 6. Pets: pet_id (attribute 296) + style. Every pet shares def_index 4681;
|
|
168
|
+
// the pet id selects the entry in pet_definitions (egg, chick, chicken
|
|
169
|
+
// breed) and the style the breed color. Pets without styles (egg, chick)
|
|
170
|
+
// are keyed by pet id only.
|
|
171
|
+
if (gcItem.def_index === PET_DEF_INDEX && petId && petId > 0) {
|
|
172
|
+
const pet = (gcItem.style != null && data.pets[`${petId}_${gcItem.style}`]) ||
|
|
173
|
+
data.pets[String(petId)];
|
|
174
|
+
if (pet)
|
|
175
|
+
return makeResult(pet, gcItem, 'pet');
|
|
176
|
+
}
|
|
177
|
+
// 7. Graffiti: stickers[0].sticker_id + graffiti_tint (attribute 233)
|
|
164
178
|
if (graffitiTint !== undefined && gcItem.stickers?.length) {
|
|
165
179
|
const stickerId = gcItem.stickers[0].sticker_id;
|
|
166
180
|
if (stickerId) {
|
|
@@ -173,41 +187,41 @@ export function resolveItem(gcItem) {
|
|
|
173
187
|
return makeResult(mono, gcItem, 'graffiti');
|
|
174
188
|
}
|
|
175
189
|
}
|
|
176
|
-
//
|
|
190
|
+
// 8. Keys
|
|
177
191
|
const key = data.keys[defIdx];
|
|
178
192
|
if (key)
|
|
179
193
|
return makeResult(key, gcItem, 'key');
|
|
180
|
-
//
|
|
194
|
+
// 9. Crates / cases
|
|
181
195
|
const crate = data.crates[defIdx];
|
|
182
196
|
if (crate)
|
|
183
197
|
return makeResult(crate, gcItem, 'crate');
|
|
184
|
-
//
|
|
198
|
+
// 10. Collectibles (coins, pins, etc.)
|
|
185
199
|
const collectible = data.collectibles[defIdx];
|
|
186
200
|
if (collectible)
|
|
187
201
|
return makeResult(collectible, gcItem, 'collectible');
|
|
188
|
-
//
|
|
202
|
+
// 11. Agents (characters)
|
|
189
203
|
const agent = data.agents[defIdx];
|
|
190
204
|
if (agent)
|
|
191
205
|
return makeResult(agent, gcItem, 'agent');
|
|
192
|
-
//
|
|
206
|
+
// 12. Tools (Name Tag, Storage Unit, etc.)
|
|
193
207
|
const tool = data.tools[defIdx];
|
|
194
208
|
if (tool)
|
|
195
209
|
return makeResult(tool, gcItem, 'tool');
|
|
196
210
|
if (gcItem.stickers?.length) {
|
|
197
211
|
const stickerId = gcItem.stickers[0].sticker_id;
|
|
198
212
|
if (stickerId) {
|
|
199
|
-
//
|
|
213
|
+
// 13. Sticker slabs: slabs share their id with the applied sticker of the
|
|
200
214
|
// same design, so only def_index 1355 may resolve to a slab.
|
|
201
215
|
if (gcItem.def_index === STICKER_SLAB_DEF_INDEX) {
|
|
202
216
|
const slab = data.sticker_slabs[String(stickerId)];
|
|
203
217
|
if (slab)
|
|
204
218
|
return makeResult(slab, gcItem, 'sticker_slab');
|
|
205
219
|
}
|
|
206
|
-
//
|
|
220
|
+
// 14. Patches (checked before stickers)
|
|
207
221
|
const patch = data.patches[String(stickerId)];
|
|
208
222
|
if (patch)
|
|
209
223
|
return makeResult(patch, gcItem, 'patch');
|
|
210
|
-
//
|
|
224
|
+
// 15. Stickers
|
|
211
225
|
const sticker = data.stickers[String(stickerId)];
|
|
212
226
|
if (sticker)
|
|
213
227
|
return makeResult(sticker, gcItem, 'sticker');
|
package/dist/resolver.test.js
CHANGED
|
@@ -141,6 +141,38 @@ describe('resolveItem', () => {
|
|
|
141
141
|
expect(result.name).toBe(data.keychains[String(kcId)].name);
|
|
142
142
|
expect(typeof result.marketable).toBe('boolean');
|
|
143
143
|
});
|
|
144
|
+
// Pet
|
|
145
|
+
it('resolves a pet without style by attribute 296 on def_index 4681', () => {
|
|
146
|
+
const result = resolveItem({
|
|
147
|
+
def_index: 4681,
|
|
148
|
+
quality: 4,
|
|
149
|
+
style: null,
|
|
150
|
+
attribute: [makeAttr(296, 2), makeAttr(313, 57173217)],
|
|
151
|
+
});
|
|
152
|
+
expect(result).not.toBeNull();
|
|
153
|
+
expect(result.entity).toBe('pet');
|
|
154
|
+
expect(result.name).toBe(data.pets['2'].name);
|
|
155
|
+
expect(result.marketable).toBe(false);
|
|
156
|
+
});
|
|
157
|
+
it('resolves a chicken by attribute 296 and its style', () => {
|
|
158
|
+
const result = resolveItem({
|
|
159
|
+
def_index: 4681,
|
|
160
|
+
style: 9,
|
|
161
|
+
attribute: [makeAttr(296, 5), makeAttr(268, 3)],
|
|
162
|
+
});
|
|
163
|
+
expect(result).not.toBeNull();
|
|
164
|
+
expect(result.entity).toBe('pet');
|
|
165
|
+
expect(result.name).toBe(data.pets['5_9'].name);
|
|
166
|
+
expect(result.image).toBe(data.pets['5_9'].image);
|
|
167
|
+
});
|
|
168
|
+
it('does not resolve a chicken with an unknown style', () => {
|
|
169
|
+
const result = resolveItem({ def_index: 4681, style: 99, attribute: [makeAttr(296, 5)] });
|
|
170
|
+
expect(result).toBeNull();
|
|
171
|
+
});
|
|
172
|
+
it('ignores attribute 296 on items that are not pets', () => {
|
|
173
|
+
const result = resolveItem({ def_index: 4000, attribute: [makeAttr(296, 2)] });
|
|
174
|
+
expect(result).toBeNull();
|
|
175
|
+
});
|
|
144
176
|
// 5. Graffiti (tinted)
|
|
145
177
|
it('resolves a tinted graffiti by sticker_id + attribute 233', () => {
|
|
146
178
|
const tintedKey = Object.keys(data.graffiti).find(k => k.includes('_'));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Possible CS2 item entity types returned by {@link resolveItem}. */
|
|
2
|
-
export type ItemEntity = 'skin' | 'music_kit' | 'highlight' | 'keychain' | 'graffiti' | 'crate' | 'key' | 'collectible' | 'agent' | 'tool' | 'patch' | 'sticker' | 'sticker_slab';
|
|
2
|
+
export type ItemEntity = 'skin' | 'music_kit' | 'highlight' | 'keychain' | 'pet' | 'graffiti' | 'crate' | 'key' | 'collectible' | 'agent' | 'tool' | 'patch' | 'sticker' | 'sticker_slab';
|
|
3
3
|
/**
|
|
4
4
|
* Current trade state of a specific item instance, derived from attribute 312
|
|
5
5
|
* (`trade_protected_escrow_date`).
|
|
@@ -55,6 +55,8 @@ export interface GcItemInput {
|
|
|
55
55
|
quality?: number;
|
|
56
56
|
/** The paint wear float (0.0–1.0). Present only for skins. */
|
|
57
57
|
paint_wear?: number;
|
|
58
|
+
/** The item style. For pets it is the breed color (e.g. `9` = Polish Pink). */
|
|
59
|
+
style?: number | null;
|
|
58
60
|
/** Sticker slots array. Also used for graffiti and sticker/patch items via `sticker_id`. */
|
|
59
61
|
stickers?: {
|
|
60
62
|
sticker_id?: number;
|
|
@@ -63,7 +65,8 @@ export interface GcItemInput {
|
|
|
63
65
|
* Raw attribute array from the GC message.
|
|
64
66
|
*
|
|
65
67
|
* Used to extract `music_index` (def_index 166), `graffiti_tint` (def_index 233),
|
|
66
|
-
* `keychain_index` (def_index 299), `
|
|
68
|
+
* `keychain_index` (def_index 299), `pet_id` (def_index 296),
|
|
69
|
+
* `highlight_index` (def_index 314),
|
|
67
70
|
* `sticker_slab_index` (def_index 321), and the
|
|
68
71
|
* `trade_protected_escrow_date` (def_index 312) via {@link getAttributeUint32}.
|
|
69
72
|
*/
|
|
@@ -98,4 +101,5 @@ export interface InventoryData {
|
|
|
98
101
|
keys: Record<string, ItemEntry>;
|
|
99
102
|
sticker_slabs: Record<string, ItemEntry>;
|
|
100
103
|
tools: Record<string, ItemEntry>;
|
|
104
|
+
pets: Record<string, ItemEntry>;
|
|
101
105
|
}
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cs2-inventory-resolver",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "Resolve CS2 Game Coordinator protobuf items into human-readable names, images, and categories",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"cs2",
|
|
7
|
-
"csgo",
|
|
8
|
-
"counter-strike",
|
|
9
|
-
"steam",
|
|
10
|
-
"inventory",
|
|
11
|
-
"skins",
|
|
12
|
-
"game-coordinator",
|
|
13
|
-
"protobuf",
|
|
14
|
-
"resolver",
|
|
15
|
-
"valve"
|
|
16
|
-
],
|
|
17
|
-
"type": "module",
|
|
18
|
-
"main": "./dist/index.js",
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
|
-
"exports": {
|
|
21
|
-
".": {
|
|
22
|
-
"types": "./dist/index.d.ts",
|
|
23
|
-
"default": "./dist/index.js"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"files": [
|
|
27
|
-
"dist/",
|
|
28
|
-
"data/"
|
|
29
|
-
],
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "tsc",
|
|
32
|
-
"test": "vitest run"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@types/node": "^22.0.0",
|
|
36
|
-
"typescript": "^5.9.3",
|
|
37
|
-
"vitest": "^3.0.0"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "cs2-inventory-resolver",
|
|
3
|
+
"version": "0.4.39",
|
|
4
|
+
"description": "Resolve CS2 Game Coordinator protobuf items into human-readable names, images, and categories",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cs2",
|
|
7
|
+
"csgo",
|
|
8
|
+
"counter-strike",
|
|
9
|
+
"steam",
|
|
10
|
+
"inventory",
|
|
11
|
+
"skins",
|
|
12
|
+
"game-coordinator",
|
|
13
|
+
"protobuf",
|
|
14
|
+
"resolver",
|
|
15
|
+
"valve"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/",
|
|
28
|
+
"data/"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22.0.0",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "^3.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|