Added mongoid item validation to 39x profile migration

This commit is contained in:
Dev 2024-09-21 19:00:14 +01:00
parent 47a7ccdfdd
commit 98d4bcc8ae
2 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import { ApplicationContext } from "@spt/context/ApplicationContext";
import { ContextVariableType } from "@spt/context/ContextVariableType";
import { HideoutHelper } from "@spt/helpers/HideoutHelper";
import { HttpServerHelper } from "@spt/helpers/HttpServerHelper";
import { InventoryHelper } from "@spt/helpers/InventoryHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
@ -68,6 +69,7 @@ export class GameController {
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("PreSptModLoader") protected preSptModLoader: PreSptModLoader,
@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper,
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("HideoutHelper") protected hideoutHelper: HideoutHelper,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@ -165,6 +167,9 @@ export class GameController {
//3.9 migrations
if (fullProfile.spt.version.includes("3.9.") && !fullProfile.spt.migrations["39x"]) {
// Check every item has a valid mongoid
this.inventoryHelper.validateInventoryUsesMonogoIds(fullProfile.characters.pmc.Inventory.items);
this.migrate39xProfile(fullProfile);
// Flag as migrated

View File

@ -1138,6 +1138,16 @@ export class InventoryHelper {
// Start recursive check
return isParentInStash(itemToCheck._id);
}
public validateInventoryUsesMonogoIds(itemsToValidate: Item[]) {
for (const item of itemsToValidate) {
if (!/^[a-fA-F0-9]{24}$/.test(item._id)) {
throw new Error(
`This profile is not compatible with 3.10.0, It contains an item with the ID: ${item._id} that is not compatible. Loading of SPT has been halted, use another profile or create a new one.`,
);
}
}
}
}
namespace InventoryHelper {