From a3b97ff3ef917b92d7d455b928476feac70bc230 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 12 Jul 2024 09:48:30 +0100 Subject: [PATCH] Added nullguards to `giveProfileMoney()` (cherry picked from commit f7a617d6218e171de97610cbed58296a3e8979d4) --- project/src/services/PaymentService.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/project/src/services/PaymentService.ts b/project/src/services/PaymentService.ts index a2ae5e86..efc0a6e1 100644 --- a/project/src/services/PaymentService.ts +++ b/project/src/services/PaymentService.ts @@ -180,9 +180,22 @@ export class PaymentService ): void { const trader = this.traderHelper.getTrader(request.tid, sessionID); + if (!trader) + { + this.logger.error(`Unable to add currency to profile as trader: ${request.tid} does not exist`); + + return; + } + const currencyTpl = this.paymentHelper.getCurrency(trader.currency); let calcAmount = this.handbookHelper.fromRUB(this.handbookHelper.inRUB(amountToSend, currencyTpl), currencyTpl); - const currencyMaxStackSize = this.itemHelper.getItem(currencyTpl)[1]._props.StackMaxSize!; + const currencyMaxStackSize = this.itemHelper.getItem(currencyTpl)[1]._props?.StackMaxSize; + if (!currencyMaxStackSize) + { + this.logger.error(`Unable to add currency: ${currencyTpl} to profile as it lacks a _props property`); + + return; + } let skipSendingMoneyToStash = false; for (const item of pmcData.Inventory.items)