From b72a0d12eff3a3aa598f5fd59e79e9420b18a374 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 24 Jan 2025 21:09:34 +0100 Subject: [PATCH] fix: apply spoofing stuff to missionInventoryUpdate's InventoryJson (#866) --- src/controllers/api/inventoryController.ts | 13 ++++++++++--- .../api/missionInventoryUpdateController.ts | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/controllers/api/inventoryController.ts b/src/controllers/api/inventoryController.ts index 11ba1378..60d02aeb 100644 --- a/src/controllers/api/inventoryController.ts +++ b/src/controllers/api/inventoryController.ts @@ -59,6 +59,15 @@ export const inventoryController: RequestHandler = async (request, response) => ); const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON(); + applyInventoryResponseOverrides(inventoryResponse, "xpBasedLevelCapDisabled" in request.query); + + response.json(inventoryResponse); +}; + +export const applyInventoryResponseOverrides = ( + inventoryResponse: IInventoryClient, + xpBasedLevelCapDisabled: boolean +): void => { if (config.infiniteCredits) { inventoryResponse.RegularCredits = 999999999; } @@ -175,7 +184,7 @@ export const inventoryController: RequestHandler = async (request, response) => if (typeof config.spoofMasteryRank === "number" && config.spoofMasteryRank >= 0) { inventoryResponse.PlayerLevel = config.spoofMasteryRank; - if (!("xpBasedLevelCapDisabled" in request.query)) { + if (!xpBasedLevelCapDisabled) { // This client has not been patched to accept any mastery rank, need to fake the XP. inventoryResponse.XPInfo = []; let numFrames = getExpRequiredForMr(Math.min(config.spoofMasteryRank, 5030)) / 6000; @@ -251,8 +260,6 @@ export const inventoryController: RequestHandler = async (request, response) => inventoryResponse.HasOwnedVoidProjectionsPreviously = true; inventoryResponse.LastInventorySync = toOid(new Types.ObjectId()); - - response.json(inventoryResponse); }; const addString = (arr: string[], str: string): void => { diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index 837e449e..ba2ae9bc 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -8,6 +8,8 @@ import { calculateFinalCredits } from "@/src/services/missionInventoryUpdateService"; import { getInventory } from "@/src/services/inventoryService"; +import { applyInventoryResponseOverrides } from "./inventoryController"; +import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes"; /* **** INPUT **** @@ -58,9 +60,13 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res) const inventoryUpdates = addMissionInventoryUpdates(inventory, missionReport); if (missionReport.MissionStatus !== "GS_SUCCESS") { - const InventoryJson = JSON.stringify((await inventory.save()).toJSON()); - - res.json({ InventoryJson, MissionRewards: [] }); + await inventory.save(); + const inventoryResponse = inventory.toJSON(); + applyInventoryResponseOverrides(inventoryResponse, true); + res.json({ + InventoryJson: JSON.stringify(inventoryResponse), + MissionRewards: [] + }); return; } const missionRewardsResults = await addMissionRewards(inventory, missionReport); @@ -76,11 +82,13 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res) rngRewardCredits: inventoryChanges.RegularCredits as number }); - const InventoryJson = JSON.stringify((await inventory.save()).toJSON()); + await inventory.save(); + const inventoryResponse = inventory.toJSON(); + applyInventoryResponseOverrides(inventoryResponse, true); //TODO: figure out when to send inventory. it is needed for many cases. res.json({ - InventoryJson, + InventoryJson: JSON.stringify(inventoryResponse), InventoryChanges: inventoryChanges, MissionRewards, ...credits,