@ianlucas/cs2-lib-inspect 1.0.4 → 2.0.0-rc.1
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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cs2-lib-inspect
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> An extension for cs2-lib to create Counter-Strike 2 inspect links
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -11,8 +11,8 @@ npm install @ianlucas/cs2-lib-inspect
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { CS2Economy } from "@ianlucas/cs2-lib";
|
|
15
|
+
import { generateInspectLink } from "@ianlucas/cs2-lib-inspect";
|
|
16
16
|
|
|
17
|
-
const link =
|
|
17
|
+
const link = generateInspectLink(CS2Economy.getById(307));
|
|
18
18
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare function
|
|
1
|
+
import { CS2EconomyItem, CS2InventoryItem } from "@ianlucas/cs2-lib";
|
|
2
|
+
export declare const CS2_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
|
|
3
|
+
export declare function generateInspectLink(item: CS2EconomyItem | CS2InventoryItem): string;
|
package/dist/index.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* Copyright (c) candyboyz, Ian Lucas. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import {
|
|
5
|
+
import { CS2InventoryItem, CS2RarityColor, CS2_MIN_SEED, CS2_MIN_STICKER_WEAR, CS2_MIN_WEAR } from "@ianlucas/cs2-lib";
|
|
6
6
|
import { Buffer } from "buffer";
|
|
7
7
|
import CRC32 from "crc-32";
|
|
8
|
-
import { CEconItemPreviewDataBlock } from "./econ";
|
|
9
|
-
const
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
8
|
+
import { CEconItemPreviewDataBlock } from "./econ-item-preview-data-block.js";
|
|
9
|
+
const CS2_RARITY_INT = {
|
|
10
|
+
[CS2RarityColor.Common]: 1,
|
|
11
|
+
[CS2RarityColor.Uncommon]: 2,
|
|
12
|
+
[CS2RarityColor.Rare]: 3,
|
|
13
|
+
[CS2RarityColor.Mythical]: 4,
|
|
14
|
+
[CS2RarityColor.Legendary]: 5,
|
|
15
|
+
[CS2RarityColor.Ancient]: 6,
|
|
16
|
+
[CS2RarityColor.Immortal]: 7
|
|
17
17
|
};
|
|
18
18
|
const MISSING_ITEM_DEF = {
|
|
19
19
|
graffiti: 1348,
|
|
@@ -21,24 +21,24 @@ const MISSING_ITEM_DEF = {
|
|
|
21
21
|
sticker: 1209,
|
|
22
22
|
musickit: 1314
|
|
23
23
|
};
|
|
24
|
-
export const
|
|
24
|
+
export const CS2_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
|
|
25
25
|
function floatToBytes(floatValue) {
|
|
26
26
|
const floatArray = new Float32Array(1);
|
|
27
27
|
floatArray[0] = floatValue;
|
|
28
28
|
const byteArray = new Uint32Array(floatArray.buffer);
|
|
29
29
|
return byteArray[0];
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
const { def, index, rarity, type, tint,
|
|
31
|
+
function getEconomyItemPreviewData(item) {
|
|
32
|
+
const { def, index, rarity, type, tint, wearMin } = item;
|
|
33
33
|
const hasStickerObject = MISSING_ITEM_DEF[type] !== undefined;
|
|
34
34
|
const hasPaintIndex = !hasStickerObject && type !== "musickit";
|
|
35
35
|
return {
|
|
36
36
|
defindex: MISSING_ITEM_DEF[type] ?? def,
|
|
37
37
|
musicindex: type === "musickit" ? index : undefined,
|
|
38
38
|
paintindex: hasPaintIndex ? index : undefined,
|
|
39
|
-
paintseed:
|
|
40
|
-
paintwear:
|
|
41
|
-
rarity:
|
|
39
|
+
paintseed: item.hasSeed() ? CS2_MIN_SEED : undefined,
|
|
40
|
+
paintwear: item.hasWear() ? wearMin ?? CS2_MIN_WEAR : undefined,
|
|
41
|
+
rarity: CS2_RARITY_INT[rarity] ?? 0,
|
|
42
42
|
stickers: hasStickerObject
|
|
43
43
|
? [
|
|
44
44
|
{
|
|
@@ -50,24 +50,22 @@ function getItemAttributes(item) {
|
|
|
50
50
|
: []
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
const baseAttributes =
|
|
53
|
+
function getInventoryItemPreviewData(item) {
|
|
54
|
+
const { nameTag, seed, statTrak, stickers, wear } = item;
|
|
55
|
+
const baseAttributes = getEconomyItemPreviewData(item);
|
|
56
56
|
return {
|
|
57
57
|
...baseAttributes,
|
|
58
|
-
customname:
|
|
59
|
-
killeaterscoretype:
|
|
60
|
-
killeatervalue:
|
|
61
|
-
paintseed:
|
|
62
|
-
paintwear:
|
|
58
|
+
customname: nameTag,
|
|
59
|
+
killeaterscoretype: statTrak !== undefined ? 0 : undefined,
|
|
60
|
+
killeatervalue: statTrak,
|
|
61
|
+
paintseed: item.hasSeed() ? seed ?? CS2_MIN_SEED : undefined,
|
|
62
|
+
paintwear: item.hasWear() ? floatToBytes(wear ?? item.wearMin ?? CS2_MIN_WEAR) : undefined,
|
|
63
63
|
stickers: stickers !== undefined
|
|
64
|
-
?
|
|
65
|
-
.map((sticker, slot) => ({
|
|
64
|
+
? item.someStickers().map(([slot, { id, wear }]) => ({
|
|
66
65
|
slot,
|
|
67
|
-
stickerId:
|
|
68
|
-
wear:
|
|
66
|
+
stickerId: item.economy.getById(id).index,
|
|
67
|
+
wear: wear ?? CS2_MIN_STICKER_WEAR
|
|
69
68
|
}))
|
|
70
|
-
.filter(({ stickerId }) => stickerId !== CS_NONE)
|
|
71
69
|
: baseAttributes.stickers
|
|
72
70
|
};
|
|
73
71
|
}
|
|
@@ -80,11 +78,6 @@ function generateHex(attributes) {
|
|
|
80
78
|
const buffer = Buffer.concat([payload, crcBuffer]);
|
|
81
79
|
return buffer.toString("hex").toUpperCase();
|
|
82
80
|
}
|
|
83
|
-
export function
|
|
84
|
-
|
|
85
|
-
...(typeof item.uid === undefined
|
|
86
|
-
? getItemAttributes(item)
|
|
87
|
-
: getBaseInventoryItemAttributes(item))
|
|
88
|
-
};
|
|
89
|
-
return `${CS_PREVIEW_URL}${generateHex(econ)}`;
|
|
81
|
+
export function generateInspectLink(item) {
|
|
82
|
+
return `${CS2_PREVIEW_URL}${generateHex(item instanceof CS2InventoryItem ? getInventoryItemPreviewData(item) : getEconomyItemPreviewData(item))}`;
|
|
90
83
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ianlucas/cs2-lib-inspect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
4
4
|
"description": "A utility for creating inspect links for CS2 items",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "ianlucas/cs2-lib-inspect",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"crc-32": "^1.2.2"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@ianlucas/cs2-lib": "^
|
|
21
|
+
"@ianlucas/cs2-lib": "^5.0.0-rc.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@protobuf-ts/plugin": "^2.9.3",
|
|
File without changes
|
|
File without changes
|