Files
2026-04-17 11:55:23 +00:00

83 lines
2.8 KiB
JavaScript

//Import some assets from Vortex we'll need.
const path = require('path');
const { fs, log, util } = require('vortex-api');
const GAME_ID = 'derailvalley'; // Nexus Mods domain for the game. e.g. nexusmods.com/derailvalley
const STEAMAPP_ID = '588030'; //Steam Application ID, you can get this from https://steamdb.info/apps/
const MOD_FILE_EXT = ".pak";
function main(context) {
//This is the main function Vortex will run when detecting the game extension.
context.registerGame({
id: GAME_ID,
name: 'Derail Valley',
mergeMods: true,
queryPath: findGame,
supportedTools: [],
queryModPath: () => 'Mods',
logo: 'gameart.jpg',
executable: () => 'DerailValley.exe',
requiredFiles: [
'DerailValley.exe',
],
setup: prepareForModding,
environment: {
SteamAPPId: STEAMAPP_ID,
},
details: {
steamAppId: STEAMAPP_ID,
stopPatterns: [
'(^|/)Info.json(/|$)',
],
},
});
context.registerInstaller('derailvalley-mod', 25, testSupportedContent, installContent);
function testSupportedContent(files, gameId) {
// we check for the existence of an Info.json file in any subdirectory
return Promise.resolve({
supported: files.some(file => path.basename(file).toLowerCase() === 'info.json'),
priority: 25,
});
}
function installContent(files, destinationPath, gameId, installOptions) {
const infoJson = files.find(file => path.basename(file).toLowerCase() === 'info.json');
const rootPath = path.dirname(infoJson);
const filteredFiles = files.filter(file => {
const isChild = (rootPath === '.') ? true : file.startsWith(rootPath);
const isNotDirectory = !file.endsWith('/') && !file.endsWith('\\');
return isChild && isNotDirectory;
});
const modName = (rootPath !== '.') ? path.basename(rootPath) : (installOptions.modName || installOptions.name || path.basename(destinationPath) || 'UnknownMod');
const instructions = filteredFiles.map(file => {
const relativePath = (rootPath === '.') ? file : path.relative(rootPath, file);
return {
type: 'copy',
source: file,
destination: path.join(modName, relativePath).replace(/\\/g, '/'),
};
});
return Promise.resolve({ instructions });
}
function findGame() {
return util.GameStoreHelper.findByAppId([STEAMAPP_ID])
.then(game => game.gamePath);
}
function prepareForModding(discovery) {
return fs.ensureDirWritableAsync(path.join(discovery.path, 'Mods'));
}
return true;
}
module.exports = {
default: main,
};