From f650bb6be524c3d38b9991f3f21de8e3937d1292 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Fri, 4 Oct 2024 15:21:44 +0000 Subject: [PATCH] Fix sealed weapon crates when bad mod data exists (!416) If a modded weapon includes non-existant items in some of its fields, sealed weapon crates had the potential to throw an exception on open due to not validating that all `LinkedDbItems` existed. This filters the list to only items that are found in the item DB Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/416 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/services/RagfairLinkedItemService.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/project/src/services/RagfairLinkedItemService.ts b/project/src/services/RagfairLinkedItemService.ts index 963d9a71..ba859135 100644 --- a/project/src/services/RagfairLinkedItemService.ts +++ b/project/src/services/RagfairLinkedItemService.ts @@ -1,6 +1,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper"; import { ITemplateItem } from "@spt/models/eft/common/tables/ITemplateItem"; import { BaseClasses } from "@spt/models/enums/BaseClasses"; +import { ILogger } from "@spt/models/spt/utils/ILogger"; import { DatabaseService } from "@spt/services/DatabaseService"; import { inject, injectable } from "tsyringe"; @@ -11,6 +12,7 @@ export class RagfairLinkedItemService { constructor( @inject("DatabaseService") protected databaseService: DatabaseService, @inject("ItemHelper") protected itemHelper: ItemHelper, + @inject("PrimaryLogger") protected logger: ILogger, ) {} public getLinkedItems(linkedSearchId: string): Set { @@ -28,10 +30,15 @@ export class RagfairLinkedItemService { */ public getLinkedDbItems(itemTpl: string): ITemplateItem[] { const linkedItemsToWeaponTpls = this.getLinkedItems(itemTpl); - return [...linkedItemsToWeaponTpls].map((x) => { - const itemDetails = this.itemHelper.getItem(x); - return itemDetails[1]; - }); + return [...linkedItemsToWeaponTpls].reduce((result, linkedTpl) => { + const itemDetails = this.itemHelper.getItem(linkedTpl); + if (itemDetails[0]) { + result.push(itemDetails[1]); + } else { + this.logger.warning(`Item ${itemTpl} has invalid linked item ${linkedTpl}`); + } + return result; + }, []); } /**