Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProfileLinker abstract class + Shimloader implementation #1240

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/installers/ProfileLinker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Profile from "../model/Profile";
import ManifestV2 from "../model/ManifestV2";
import { InstallArgs } from "./PackageInstaller";
import Game from "../model/game/Game";

export abstract class ProfileLinker {
abstract perform(profile: Profile, game: Game, gameDir: string): Promise<string[]>;
// abstract unwind(args: LinkArgs): Promise<void>; <-- TODO
}
30 changes: 30 additions & 0 deletions src/installers/ShimloaderInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import FileTree from "../model/file/FileTree";
import FileUtils from "../utils/FileUtils";
import R2Error from "../model/errors/R2Error";
import { InstallRuleInstaller } from "./InstallRuleInstaller";
import { ProfileLinker } from "./ProfileLinker";
import Profile from "../model/Profile";
import Game from "../model/game/Game";

export class ShimloaderInstaller extends PackageInstaller {
/**
Expand Down Expand Up @@ -85,3 +88,30 @@ export class ShimloaderPluginInstaller extends PackageInstaller {
await this.installer.install(args);
}
}

export class ShimloaderLinker extends ProfileLinker {
async perform(profile: Profile, game: Game, gameDir: string): Promise<string[]> {
const fs = FsProvider.instance;
const profilePath = profile.getPathOfProfile();
const tracked = [];
const targets = [
"dwmapi.dll",
"ue4ss.dll",
"UE4SS-settings.ini",
];

for (const target of targets) {
let absSrc = path.join(profilePath, target);
let absDest = path.join(gameDir, game.dataFolderName, "Binaries", "Win64", target);

if (await fs.exists(absDest)) {
await fs.unlink(absDest);
}

fs.copyFile(absSrc, absDest);
tracked.push(absDest);
}

return tracked;
}
}
12 changes: 10 additions & 2 deletions src/installers/registry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { PackageInstaller } from "./PackageInstaller";
import { ProfileLinker } from "./ProfileLinker";
import { BepInExInstaller } from "./BepInExInstaller";
import { GodotMLInstaller } from "./GodotMLInstaller";
import { MelonLoaderInstaller } from "./MelonLoaderInstaller";
import { PackageInstaller } from "./PackageInstaller";
import { InstallRuleInstaller } from "./InstallRuleInstaller";
import { ShimloaderInstaller, ShimloaderPluginInstaller } from "./ShimloaderInstaller";
import { ShimloaderInstaller, ShimloaderPluginInstaller, ShimloaderLinker } from "./ShimloaderInstaller";


const _PackageInstallers = {
Expand All @@ -15,5 +16,12 @@ const _PackageInstallers = {
"shimloader-plugin": new ShimloaderPluginInstaller(),
}

const _ProfileLinkers = {
"shimloader-linker": new ShimloaderLinker(),
}

export type PackageInstallerId = keyof typeof _PackageInstallers;
export const PackageInstallers: {[key in PackageInstallerId]: PackageInstaller} = _PackageInstallers;

export type ProfileLinkerId = keyof typeof _ProfileLinkers;
export const ProfileLinkers: {[key in ProfileLinkerId]: ProfileLinker} = _ProfileLinkers;
10 changes: 9 additions & 1 deletion src/model/installing/PackageLoader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PackageInstallerId, PackageInstallers } from "../../installers/registry";
import { PackageInstallerId, PackageInstallers, ProfileLinkerId } from "../../installers/registry";
import Game from "../game/Game";

export enum PackageLoader {
Expand Down Expand Up @@ -30,3 +30,11 @@ export function GetInstallerIdForPlugin(loader: PackageLoader): PackageInstaller

return null;
}

export function GetLinkerIdForLoader(loader: PackageLoader): ProfileLinkerId | null {
switch (loader) {
case PackageLoader.SHIMLOADER: return "shimloader-linker";
}

return null;
}
13 changes: 11 additions & 2 deletions src/r2mm/manager/ModLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import ManagerInformation from '../../_managerinf/ManagerInformation';
import Game from '../../model/game/Game';
import LinuxGameDirectoryResolver from './linux/GameDirectoryResolver';
import FileTree from '../../model/file/FileTree';
import { PackageLoader } from "../../model/installing/PackageLoader";
import { GetLinkerIdForLoader, PackageLoader } from "../../model/installing/PackageLoader";
import { ProfileLinkers } from '../../installers/registry';

export default class ModLinker {

Expand All @@ -32,7 +33,15 @@ export default class ModLinker {
if (gameDirectory instanceof R2Error) {
return gameDirectory;
}
return this.performLink(profile, game, gameDirectory);

const linkerId = GetLinkerIdForLoader(game.packageLoader);
if (linkerId == null) {
// Default to this behavior if there's no linker associated with this loader.
return this.performLink(profile, game, gameDirectory);
}

const linker = ProfileLinkers[linkerId];
return linker.perform(profile, game, gameDirectory);
}

/**
Expand Down