diff --git a/project/src/controllers/LauncherController.ts b/project/src/controllers/LauncherController.ts index 86ac545d..93b1839b 100644 --- a/project/src/controllers/LauncherController.ts +++ b/project/src/controllers/LauncherController.ts @@ -185,6 +185,11 @@ export class LauncherController { const profile = this.profileHelper.getFullProfile(sessionId); - return profile?.aki?.mods ?? []; + if (profile?.aki?.mods) + { + return this.preAkiModLoader.getProfileModsGroupedByModName(profile?.aki?.mods); + } + + return []; } } diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index af7eee92..7c952400 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -3,6 +3,7 @@ import os from "os"; import path from "path"; import semver from "semver"; import { DependencyContainer, inject, injectable } from "tsyringe"; +import { ModDetails } from "../models/eft/profile/IAkiProfile"; import { ConfigTypes } from "../models/enums/ConfigTypes"; import { IPreAkiLoadMod } from "../models/external/IPreAkiLoadMod"; import { IPreAkiLoadModAsync } from "../models/external/IPreAkiLoadModAsync"; @@ -72,6 +73,40 @@ export class PreAkiModLoader implements IModLoader return this.imported; } + public getProfileModsGroupedByModName(profileMods: ModDetails[]): ModDetails[] + { + // Group all mods used by profile by name + const modsGroupedByName: Record = {}; + for (const mod of profileMods) + { + if (!modsGroupedByName[mod.name]) + { + modsGroupedByName[mod.name] = []; + } + + modsGroupedByName[mod.name].push(mod); + } + + // Find the highest versioned mod and add to results array + const result = []; + for (const modName in modsGroupedByName) + { + const modDatas = modsGroupedByName[modName]; + const modVersions = modDatas.map(x => x.version); + const highestVersion = semver.maxSatisfying(modVersions, "*"); + + const chosenVersion = modDatas.find(x => x.name === modName && x.version === highestVersion); + if (!chosenVersion) + { + continue; + } + + result.push(chosenVersion); + } + + return result; + } + public getModPath(mod: string): string { return `${this.basepath}${mod}/`;