From ddf7a658ca3eaacf22232147a8fd70f94ac6ffa3 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 2 Apr 2025 14:22:31 +0200 Subject: [PATCH] fix: clamp ItemCount within 32-bit integer range It seems the game uses 32-bit ints for these values on the C++ side before passing them on to Lua where they become floats. This would cause the game to have overflow/underflow semantics when receiving values outside of these bounds. --- src/models/inventoryModels/inventoryModel.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index a7966871..01c4dbc0 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -102,6 +102,16 @@ import { EquipmentSelectionSchema } from "./loadoutModel"; export const typeCountSchema = new Schema({ ItemType: String, ItemCount: Number }, { _id: false }); +typeCountSchema.set("toJSON", { + transform(_doc, obj) { + if (obj.ItemCount > 2147483647) { + obj.ItemCount = 2147483647; + } else if (obj.ItemCount < -2147483648) { + obj.ItemCount = -2147483648; + } + } +}); + const focusXPSchema = new Schema( { AP_POWER: Number,