If a preset has a different _id property than its object key, output an error and skip it. (!233)
This resolves an issue where a mod with bad preset data is able to break loot generation Can be tested by changing the "\_id" property of an item preset in globals.json, and seeing the error output to the console. A better solution for the future may be to deprecate the "\_id" property entirely, and use just the object key, however that would have more far reaching changes compared to this simple fix Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/233 Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com> Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
946dc52f1a
commit
19013a478f
@ -2,12 +2,14 @@ import { inject, injectable } from "tsyringe";
|
|||||||
|
|
||||||
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
||||||
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
|
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
|
||||||
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class PresetController
|
export class PresetController
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
|
@inject("WinstonLogger") protected logger: ILogger,
|
||||||
@inject("PresetHelper") protected presetHelper: PresetHelper,
|
@inject("PresetHelper") protected presetHelper: PresetHelper,
|
||||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||||
)
|
)
|
||||||
@ -15,11 +17,17 @@ export class PresetController
|
|||||||
|
|
||||||
public initialize(): void
|
public initialize(): void
|
||||||
{
|
{
|
||||||
const presets: IPreset[] = Object.values(this.databaseServer.getTables().globals.ItemPresets);
|
const presets: [string, IPreset][] = Object.entries(this.databaseServer.getTables().globals.ItemPresets);
|
||||||
const reverse: Record<string, string[]> = {};
|
const reverse: Record<string, string[]> = {};
|
||||||
|
|
||||||
for (const preset of presets)
|
for (const [id, preset] of presets)
|
||||||
{
|
{
|
||||||
|
if (id != preset._id)
|
||||||
|
{
|
||||||
|
this.logger.error(`Preset for template '${preset._items[0]._tpl}' has invalid id (${id} != ${preset._id}). Skipping`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const tpl = preset._items[0]._tpl;
|
const tpl = preset._items[0]._tpl;
|
||||||
|
|
||||||
if (!(tpl in reverse))
|
if (!(tpl in reverse))
|
||||||
|
Loading…
Reference in New Issue
Block a user