@ianlucas/cs2-lib-inspect 1.0.5 → 2.0.0-rc.2

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
- > A utility for creating inspect links for CS2 items
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 { CS_Economy } from "@ianlucas/cs2-lib";
15
- import { CS_generateInspectLink } from "@ianlucas/cs2-lib-inspect";
14
+ import { CS2Economy } from "@ianlucas/cs2-lib";
15
+ import { generateInspectLink } from "@ianlucas/cs2-lib-inspect";
16
16
 
17
- const link = CS_generateInspectLink(CS_Economy.getById(307));
17
+ const link = generateInspectLink(CS2Economy.getById(307));
18
18
  ```
package/dist/index.d.ts CHANGED
@@ -1,3 +1,14 @@
1
- import { CS_BaseInventoryItem, CS_InventoryItem, CS_Item } from "@ianlucas/cs2-lib";
2
- export declare const CS_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
3
- export declare function CS_generateInspectLink(item: CS_Item | CS_BaseInventoryItem | CS_InventoryItem): string;
1
+ import { CS2EconomyItem, CS2InventoryItem, CS2ItemTypeValues } from "@ianlucas/cs2-lib";
2
+ export declare const CS2PreviewRarity: {
3
+ "#b0c3d9": number;
4
+ "#5e98d9": number;
5
+ "#4b69ff": number;
6
+ "#8847ff": number;
7
+ "#d32ce6": number;
8
+ "#eb4b4b": number;
9
+ "#e4ae39": number;
10
+ };
11
+ export declare const CS2_PREVIEW_HAS_STICKERS: CS2ItemTypeValues[];
12
+ export declare const CS2_PREVIEW_INSPECTABLE_ITEMS: CS2ItemTypeValues[];
13
+ export declare const CS2_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
14
+ export declare function generateInspectLink(item: CS2EconomyItem | CS2InventoryItem): string;
package/dist/index.js CHANGED
@@ -2,44 +2,56 @@
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 { CS_Economy, CS_MIN_SEED, CS_MIN_STICKER_WEAR, CS_MIN_WEAR, CS_NONE, CS_RARITY_ANCIENT_COLOR, CS_RARITY_COMMON_COLOR, CS_RARITY_IMMORTAL_COLOR, CS_RARITY_LEGENDARY_COLOR, CS_RARITY_MYTHICAL_COLOR, CS_RARITY_RARE_COLOR, CS_RARITY_UNCOMMON_COLOR } from "@ianlucas/cs2-lib";
5
+ import { CS2InventoryItem, CS2ItemType, CS2RarityColor, CS2_MIN_SEED, CS2_MIN_STICKER_WEAR } from "@ianlucas/cs2-lib";
6
6
  import { Buffer } from "buffer";
7
7
  import CRC32 from "crc-32";
8
- import { CEconItemPreviewDataBlock } from "./econ.js";
9
- const CS_RARITY_INT = {
10
- [CS_RARITY_COMMON_COLOR]: 1,
11
- [CS_RARITY_UNCOMMON_COLOR]: 2,
12
- [CS_RARITY_RARE_COLOR]: 3,
13
- [CS_RARITY_MYTHICAL_COLOR]: 4,
14
- [CS_RARITY_LEGENDARY_COLOR]: 5,
15
- [CS_RARITY_ANCIENT_COLOR]: 6,
16
- [CS_RARITY_IMMORTAL_COLOR]: 7
8
+ import { CEconItemPreviewDataBlock } from "./econ-item-preview-data-block.js";
9
+ export const CS2PreviewRarity = {
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
- const MISSING_ITEM_DEF = {
19
- graffiti: 1348,
20
- patch: 4609,
21
- sticker: 1209,
22
- musickit: 1314
23
- };
24
- export const CS_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
18
+ export const CS2_PREVIEW_HAS_STICKERS = [
19
+ CS2ItemType.Graffiti,
20
+ CS2ItemType.Patch,
21
+ CS2ItemType.Sticker,
22
+ CS2ItemType.MusicKit
23
+ ];
24
+ export const CS2_PREVIEW_INSPECTABLE_ITEMS = [
25
+ CS2ItemType.Agent,
26
+ CS2ItemType.Container,
27
+ CS2ItemType.Collectible,
28
+ CS2ItemType.Gloves,
29
+ CS2ItemType.Graffiti,
30
+ CS2ItemType.Melee,
31
+ CS2ItemType.MusicKit,
32
+ CS2ItemType.Patch,
33
+ CS2ItemType.Sticker,
34
+ CS2ItemType.Weapon
35
+ ];
36
+ export const CS2_PREVIEW_URL = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20";
25
37
  function floatToBytes(floatValue) {
26
38
  const floatArray = new Float32Array(1);
27
39
  floatArray[0] = floatValue;
28
40
  const byteArray = new Uint32Array(floatArray.buffer);
29
41
  return byteArray[0];
30
42
  }
31
- function getItemAttributes(item) {
32
- const { def, index, rarity, type, tint, wearmin } = item;
33
- const hasStickerObject = MISSING_ITEM_DEF[type] !== undefined;
34
- const hasPaintIndex = !hasStickerObject && type !== "musickit";
43
+ function getEconomyItemPreviewData(item) {
44
+ const { def, index, rarity, type, tint } = item;
45
+ const hasStickers = CS2_PREVIEW_HAS_STICKERS.includes(type);
46
+ const hasPaintIndex = !hasStickers && !item.isMusicKit();
35
47
  return {
36
- defindex: MISSING_ITEM_DEF[type] ?? def,
37
- musicindex: type === "musickit" ? index : undefined,
48
+ defindex: def,
49
+ musicindex: item.isMusicKit() ? index : undefined,
38
50
  paintindex: hasPaintIndex ? index : undefined,
39
- paintseed: CS_Economy.hasSeed(item) ? CS_MIN_SEED : undefined,
40
- paintwear: CS_Economy.hasWear(item) ? wearmin ?? CS_MIN_WEAR : undefined,
41
- rarity: CS_RARITY_INT[rarity] ?? 0,
42
- stickers: hasStickerObject
51
+ paintseed: item.hasSeed() ? CS2_MIN_SEED : undefined,
52
+ paintwear: item.hasWear() ? item.getMinimumWear() : undefined,
53
+ rarity: CS2PreviewRarity[rarity] ?? 0,
54
+ stickers: hasStickers
43
55
  ? [
44
56
  {
45
57
  tintId: tint,
@@ -50,24 +62,22 @@ function getItemAttributes(item) {
50
62
  : []
51
63
  };
52
64
  }
53
- function getBaseInventoryItemAttributes({ id, nametag, seed, stattrak, stickers, stickerswear, wear }) {
54
- const item = CS_Economy.getById(id);
55
- const baseAttributes = getItemAttributes(item);
65
+ function getInventoryItemPreviewData(item) {
66
+ const { nameTag, seed, statTrak, stickers } = item;
67
+ const baseAttributes = getEconomyItemPreviewData(item);
56
68
  return {
57
69
  ...baseAttributes,
58
- customname: nametag,
59
- killeaterscoretype: stattrak !== undefined ? 0 : undefined,
60
- killeatervalue: stattrak,
61
- paintseed: CS_Economy.hasSeed(item) ? seed ?? CS_MIN_SEED : undefined,
62
- paintwear: CS_Economy.hasWear(item) ? floatToBytes(wear ?? item.wearmin ?? CS_MIN_WEAR) : undefined,
70
+ customname: nameTag,
71
+ killeaterscoretype: statTrak !== undefined ? 0 : undefined,
72
+ killeatervalue: statTrak,
73
+ paintseed: item.hasSeed() ? seed ?? CS2_MIN_SEED : undefined,
74
+ paintwear: item.hasWear() ? floatToBytes(item.getWear()) : undefined,
63
75
  stickers: stickers !== undefined
64
- ? stickers
65
- .map((sticker, slot) => ({
76
+ ? item.someStickers().map(([slot, { id, wear }]) => ({
66
77
  slot,
67
- stickerId: CS_Economy.getById(sticker).index,
68
- wear: stickerswear?.[slot] ?? CS_MIN_STICKER_WEAR
78
+ stickerId: item.economy.getById(id).index,
79
+ wear: wear ?? CS2_MIN_STICKER_WEAR
69
80
  }))
70
- .filter(({ stickerId }) => stickerId !== CS_NONE)
71
81
  : baseAttributes.stickers
72
82
  };
73
83
  }
@@ -80,11 +90,6 @@ function generateHex(attributes) {
80
90
  const buffer = Buffer.concat([payload, crcBuffer]);
81
91
  return buffer.toString("hex").toUpperCase();
82
92
  }
83
- export function CS_generateInspectLink(item) {
84
- const econ = {
85
- ...(typeof item.uid === undefined
86
- ? getItemAttributes(item)
87
- : getBaseInventoryItemAttributes(item))
88
- };
89
- return `${CS_PREVIEW_URL}${generateHex(econ)}`;
93
+ export function generateInspectLink(item) {
94
+ return `${CS2_PREVIEW_URL}${generateHex(item instanceof CS2InventoryItem ? getInventoryItemPreviewData(item) : getEconomyItemPreviewData(item))}`;
90
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianlucas/cs2-lib-inspect",
3
- "version": "1.0.5",
3
+ "version": "2.0.0-rc.2",
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": "^4.5.0"
21
+ "@ianlucas/cs2-lib": "^5.0.0-rc.19"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@protobuf-ts/plugin": "^2.9.3",