Jump to content

Registering an installer for my game plugin


chipsugar

Recommended Posts

I am new to Javascript and to Nexus Mods. I am wanting to get support added for Street Fighter V and am happy to follow the guides to see what I can do myself first. However I could do with help for the following as I'm getting an error.

 

I have followed the "Creating a Game Extension for Vortex" guide. My plugin works except if I follow the instructions in the "Mod Installation patterns" section and try to register an installer. If I do so I receive the following error and I am not able to manage the game:

Wed, 27 Jul 2022 20:15:41 GMT - warn: couldn't initialize extension name=game-streetfighterv, err=Unexpected token ';', stack=C:\Users\Darren Wilkinson\AppData\Roaming\Vortex\plugins\game-streetfighterv\index.js:72
Wed, 27 Jul 2022 20:15:54 GMT - warn: couldn't initialize extension name=game-streetfighterv, err=Unexpected token ';', stack=C:\Users\Darren Wilkinson\AppData\Roaming\Vortex\plugins\game-streetfighterv\index.js:72

My index.js file looks like this:

// Nexus Mods domain for the game. e.g. nexusmods.com/streetfighterv
const GAME_ID = 'streetfighterv';

//Steam Application ID, you can get this from https://steamdb.info/apps/
const STEAMAPP_ID = '310950';

const MOD_FILE_EXT = ".pak";

//Import some assets from Vortex we'll need.
const path = require('path');
const { fs, log, util } = require('vortex-api');

function main(context) {
	//This is the main function Vortex will run when detecting the game extension. 
	context.registerGame({
    id: GAME_ID,
    name: 'Street Fighter V',
    mergeMods: true,
    queryPath: findGame,
    supportedTools: [],
    queryModPath: () => 'StreetFighterV/Content/Paks/~mods',
    logo: 'gameart.jpg',
    executable: () => 'StreetFighterV.exe',
    requiredFiles: [
      'StreetFighterV.exe',
      'StreetFighterV/Binaries/Win64/StreetFighterV.exe'
    ],
    setup: prepareForModding,
    environment: {
      SteamAppId: STEAMAPP_ID,
    },
    details: {
      steamAppId: STEAMAPP_ID,
    },
  });
context.registerInstaller('streetfighterv-mod', 25, testSupportedContent, installContent);
	return true
}

module.exports = {
    default: main,
  };

function findGame() {
  return util.GameStoreHelper.findByAppId([STEAMAPP_ID])
      .then(game => game.gamePath);
}

function prepareForModding(discovery) {
    return fs.ensureDirAsync(path.join(discovery.path, 'StreetFighterV', 'Content', 'Paks', '~mods'));
}

function testSupportedContent(files, gameId) {
  // Make sure we're able to support this mod.
  let supported = (gameId === GAME_ID) &&
    (files.find(file => path.extname(file).toLowerCase() === MOD_FILE_EXT)!== undefined);

  return Promise.resolve({
    supported,
    requiredFiles: [],
  });
}

function installContent(files) {
  // The .pak file is expected to always be positioned in the mods directory we're going to disregard anything placed outside the root.
  const modFile = files.find(file => path.extname(file).toLowerCase() === MOD_FILE_EXT);
  const idx = modFile.indexOf(path.basename(modFile));
  const rootPath = path.dirname(modFile);

  // Remove directories and anything that isn't in the rootPath.
  const filtered = files.filter(file =>
    ((file.indexOf(rootPath) !== -1)
    && (!file.endsWith(path.sep))));

  const instructions = filtered.map(file => {
    return {
      type: 'copy',
      source: file,
      destination: path.join(file.substr(idx)),
    };
  });

  return Promise.resolve({ instructions });
}

Link to comment
Share on other sites

I would have thought that was the error too, but line 72 is:

 

((file.indexOf(rootPath) !== -1)

 

which I copied directly from the guide posted here (Creating a game extension for Vortex | Modding.wiki) from the Mod installation patterns section. If the error is mine I'm not sure what it is. This is the code exactly as it appears in the guide:

function installContent(files) {
  // The .pak file is expected to always be positioned in the mods directory we're going to disregard anything placed outside the root.
  const modFile = files.find(file => path.extname(file).toLowerCase() === MOD_FILE_EXT);
  const idx = modFile.indexOf(path.basename(modFile));
  const rootPath = path.dirname(modFile);

  // Remove directories and anything that isn't in the rootPath.
  const filtered = files.filter(file =>
    ((file.indexOf(rootPath) !== -1)
    && (!file.endsWith(path.sep))));

  const instructions = filtered.map(file => {
    return {
      type: 'copy',
      source: file,
      destination: path.join(file.substr(idx)),
    };
  });

  return Promise.resolve({ instructions });
}
Link to comment
Share on other sites

Thanks both. I'll follow that guide and check if there are any other differences as well, but this leads me to another thing, where the older versions of that guide are the ones still being pointed to on the nexusmods.com website. Feel free to skip to the TLDR.

 

I found the page I followed by going to www.nexusmods.com, and under the MODS tab at the top clicked on MODDING TUTORIALS and clicked on the massive VORTEX SUPPORT link. This took me to wiki.nexusmods.com where I saw "adding a new game to Vortex". I imagine this would be the same path the average person takes, including people new to Vortex but wanting to add game support.

 

At the bottom of that page is the following link (https://wiki.nexusmods.com/index.php/Creating_a_game_extension_for_Vortex). Following that links to an older version of the guide, but the older guide links to a newer (but still old) version at the top of that page. That link leads to a page hosted at modding.wiki ( Creating a game extension for Vortex | Modding.wiki) which still has the above errors which will trip up anyone who can follow a guide but is unfamiliar with coding/javascript (like me).

 

TLDR: Could the https://nexus-mods.github.io/vortex-api/2022/04/03/Creating-a-game-extension.html be linked to from one of the pages mentioned above?

Edited by chipsugar
Link to comment
Share on other sites

Also I thought I'd point this out as it's a small thing but an easy fix:

 

In the middle of the new official guide it says "Once this has been added, make sure to go back to your registerGame function and change the setup: undefined, line to setup: prepareForModding, otherwise the code we have just added will never be called."

 

However in context.registergame at the top of the page it already says "setup: prepareForModding,"

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...