Skip to content

Commit

Permalink
add PackageInstaller implementation for unreal_shimloader
Browse files Browse the repository at this point in the history
  • Loading branch information
ethangreen-dev committed Jan 30, 2024
1 parent e2a4710 commit 6061c6b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/installers/InstallRuleInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async function installSubDirTracked(profile: Profile, rule: ManagedRule, install
sources.push(...contents);
}

addToStateFile(mod, relocations, profile);
await addToStateFile(mod, relocations, profile);
}

async function buildInstallForRuleSubtype(
Expand Down Expand Up @@ -311,6 +311,7 @@ export class InstallRuleInstaller extends PackageInstaller {
case 'NONE': await installUntracked(profile, managedRule, files, mod); break;
case 'SUBDIR_NO_FLATTEN': await installSubDirNoFlatten(profile, managedRule, files, mod); break;
case 'PACKAGE_ZIP': await installPackageZip(profile, managedRule, files, mod); break;
case 'SUBDIR_TRACKED': await installSubDirTracked(profile, managedRule, files, mod); break;
}
}
return Promise.resolve(undefined);
Expand Down
55 changes: 55 additions & 0 deletions src/installers/ShimloaderInstaller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { InstallArgs, PackageInstaller } from "./PackageInstaller";
import path from "path";
import FsProvider from "../providers/generic/file/FsProvider";
import FileTree from "../model/file/FileTree";
import FileUtils from "src/utils/FileUtils";
import R2Error from "src/model/errors/R2Error";

export class ShimloaderInstaller extends PackageInstaller {
/**
* Handle installation of unreal-shimloader
*/
async install(args: InstallArgs) {
const {
mod,
packagePath,
profile,
} = args;

const fs = FsProvider.instance;
const fileRelocations = new Map<string, string>();

const targets = [
["dwmapi.dll", "dwmapi.dll"],
["UE4SS/ue4ss.dll", "ue4ss.dll"],
["UE4SS/UE4SS-settings.ini", "UE4SS-settings.ini"],
];

const ue4ssTree = await FileTree.buildFromLocation(path.join(packagePath, "UE4SS/Mods"));
if (ue4ssTree instanceof R2Error) {
throw ue4ssTree;
}

for (const subFile of ue4ssTree.getRecursiveFiles()) {
const relSrc = path.relative(path.join(packagePath, "UE4SS/Mods"), subFile);

targets.push([path.join("UE4SS/Mods", relSrc), path.join("shimloader/lua", relSrc)]);
}

for (const targetPath of targets) {
const absSrc = path.join(packagePath, targetPath[0]);
const absDest = path.join(profile.getPathOfProfile(), targetPath[1]);

await FileUtils.ensureDirectory(path.dirname(absDest));
await fs.copyFile(absSrc, absDest);

fileRelocations.set(absSrc, targetPath[1]);
}

// The config subdir needs to be created for shimloader (it will get cranky if it's not there).
const configDir = path.join(profile.getPathOfProfile(), "shimloader", "cfg");
if (!await fs.exists(configDir)) {
await fs.mkdirs(configDir);
}
}
}
1 change: 1 addition & 0 deletions src/model/installing/PackageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function GetInstallerIdForLoader(loader: PackageLoader): PackageInstaller
case PackageLoader.MELON_LOADER: return "melonloader";
case PackageLoader.GODOT_ML: return "godotml";
case PackageLoader.NORTHSTAR: return "bepinex";
case PackageLoader.SHIMLOADER: return "shimloader";
case PackageLoader.ANCIENT_DUNGEON_VR: return null;
}
}

0 comments on commit 6061c6b

Please sign in to comment.