Skip to content

Commit 017fc85

Browse files
authored
Fix: Inventory Asset Detection (#353)
* fix: steam inventory assets * chore: run format * fix: backwards compatibility * chore: run format
1 parent 7cc8de2 commit 017fc85

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

src/lib/components/common/item_holder_metadata.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export abstract class ItemHolderMetadata extends FloatElement {
7979
return $J(this).parent().attr('id')?.split('_')[2];
8080
}
8181

82+
get isTradeProtected(): boolean {
83+
return $J(this).parent().hasClass('provisional_item');
84+
}
85+
8286
abstract get asset(): rgAsset | undefined;
8387
abstract get ownerSteamId(): string | undefined;
8488

src/lib/components/inventory/inventory_item_holder_metadata.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {CustomElement, InjectAppend, InjectionMode} from '../injectors';
22
import {rgAsset} from '../../types/steam';
33
import {ItemHolderMetadata} from '../common/item_holder_metadata';
4+
import {ContextId} from '../../types/steam_constants';
5+
import {isCAppwideInventory} from '../../utils/checkers';
46

57
@CustomElement()
68
@InjectAppend(
@@ -11,7 +13,15 @@ export class InventoryItemHolderMetadata extends ItemHolderMetadata {
1113
get asset(): rgAsset | undefined {
1214
if (!this.assetId) return;
1315

14-
return g_ActiveInventory?.m_rgAssets[this.assetId]?.description;
16+
if (!g_ActiveInventory) return;
17+
18+
if (isCAppwideInventory(g_ActiveInventory)) {
19+
const contextId = this.isTradeProtected ? ContextId.PROTECTED : ContextId.PRIMARY;
20+
21+
return g_ActiveInventory.m_rgChildInventories[contextId]?.m_rgAssets[this.assetId]?.description;
22+
} else {
23+
return g_ActiveInventory.m_rgAssets[this.assetId]?.description;
24+
}
1525
}
1626

1727
get ownerSteamId(): string | undefined {

src/lib/types/steam.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import {AppId, ContextId, Currency} from './steam_constants';
2+
import {AppId, ContextId} from './steam_constants';
33

44
type ClassId = string;
55
type InstanceId = string;
@@ -116,17 +116,24 @@ export interface mOwner {
116116
strSteamId: string;
117117
}
118118

119-
// g_ActiveInventory
119+
// g_ActiveInventory.m_rgChildInventories[contextId]
120120
export interface CInventory {
121121
initialized: boolean;
122122
m_rgAssets: {[assetId: string]: InventoryAsset};
123+
m_parentInventory: CAppwideInventory | null;
123124
rgInventory: {[assetId: string]: rgAsset};
124125
m_owner?: mOwner;
125126
owner?: mOwner;
126127
selectedItem?: InventoryAsset;
127128
appid?: number;
128129
}
129130

131+
// g_ActiveInventory
132+
export interface CAppwideInventory extends CInventory {
133+
m_rgChildInventories: {[contextId in ContextId]: CInventory};
134+
m_rgContextIds: string[];
135+
}
136+
130137
export interface CAjaxPagingControls {
131138
m_bLoading: boolean;
132139
m_cMaxPages: number;
@@ -231,7 +238,7 @@ declare global {
231238
const g_rgListingInfo: {[listingId: string]: ListingData};
232239
const g_rgWalletInfo: WalletInfo | undefined; // Not populated when user is signed-out
233240
const g_rgAssets: SteamAssets;
234-
const g_ActiveInventory: CInventory | undefined; // Only populated on Steam inventory pages
241+
const g_ActiveInventory: CAppwideInventory | CInventory | undefined; // Only populated on Steam inventory pages
235242
const g_steamID: string;
236243
const g_oSearchResults: CAjaxPagingControls;
237244
const BuyItemDialog: BuyItemDialog | undefined; // Only populated on Steam Market pages

src/lib/types/steam_constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum AppId {
99

1010
export enum ContextId {
1111
PRIMARY = 2,
12+
PROTECTED = 16,
1213
}
1314

1415
// https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService

src/lib/utils/checkers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import {CInventory, CAppwideInventory} from '../types/steam';
2+
13
export function defined(t: string): boolean {
24
return t !== 'undefined';
35
}
6+
7+
export function isCAppwideInventory(inventory: CInventory | CAppwideInventory): inventory is CAppwideInventory {
8+
return 'm_rgChildInventories' in inventory;
9+
}

0 commit comments

Comments
 (0)