Jump to content

Getting the Javascript extension to launch through the game store


Anvillior
Go to solution Solved by ChemBoy1,

Recommended Posts

Ages ago I made the Battlefleet Gothic Armada 2 extension for Vortex using add game wizard. It worked great. Recently I tried recoding it in the more standard way and it works, but there's one thing I can't get it to do: Launch through steam.

BFGA2 modded requires launch commands for its mods to work, but recently it also now crashes unless another line of code is added to its launch commands. As such, launching through vortex, through the executable, is no longer viable unless the play button on vortex routes through the steam app, and thus, runs your launch commands.

I've tried grabbing the code from the old index.js and it doesn't work, likely because the two files are structured differently. I'm stumbling through javascript, so I can barely read and understand the code as it's already written.

 

If someone knows the code to make the vortex extension launch through the steam app, or can guide me on how to code it, I'd be grateful, and so would all 3 of the people still playing Warhammer 40k: Battleboats.

Link to comment
Share on other sites

  • 4 weeks later...

You can set up a tool with the command line argument to pass to the game executable. Here's an example from my Alan Wake 2 extension. For launching in Steam, you need to add this to your game spec.

"requiresLauncher": "steam"

The Add Game Wizard extension already has this function that will pass that value to the game registration function:

function makeRequiresLauncher(api, gameSpec) {
    return () => Promise.resolve((gameSpec.game.requiresLauncher !== undefined)
        ? { launcher: gameSpec.game.requiresLauncher }
        : undefined);

 

 

const tools = [
  {
    id: "AlanWake2",
    name: "Alan Wake 2",
    logo: "icon.png",
    executable: () => "AlanWake2.exe",
    parameters: [
       '-EpicPortal',
    ],
    requiredFiles: ["AlanWake2.exe"],
    detach: true,
    relative: true,
    exclusive: true,
    defaultPrimary: true,
  },
];
  • Confused 1
Link to comment
Share on other sites

Hey, thanks for responding. So this is what my code looks like:

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

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

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

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

function prepareForModding(discovery) {
    return fs.ensureDirWritableAsync(path.join(discovery.path, 'BattlefleetGothic2', 'Content', 'Paks', 'Stock'));
}

function main(context) {
	//This is the main function Vortex will run when detecting the game extension. 
	context.registerGame({
    id: GAME_ID,
    name: 'Battlefleet Gothic: Armada 2',
    mergeMods: true,
    queryPath: findGame,
    supportedTools: [],
    queryModPath: () => 'BattlefleetGothic2',
    logo: 'gameart.jpg',
    executable: () => 'BattlefleetGothic2.exe',
    requiredFiles: [
      'BattlefleetGothic2.exe',
    ],
    setup: prepareForModding,
    environment: {
      SteamAPPId: STEAMAPP_ID,
    },
    details: {
      steamAppId: STEAMAPP_ID,
	  stopPatterns: ['(^|/)Content(/|$)'],
    },
  });
	return true;
}

module.exports = {
    default: main,
};

I did try including the line about required launcher and the function above, but it would lead to the extension failing to load. I did try changing 

function makeRequiresLauncher(api, gameSpec) {
    return () => Promise.resolve((gameSpec.game.requiresLauncher !== undefined)
        ? { launcher: gameSpec.game.requiresLauncher }
        : undefined);

to

function makeRequiresLauncher(api, main) {
    return () => Promise.resolve((main.requiresLauncher !== undefined)
        ? { launcher: main.requiresLauncher }
        : undefined);

and while it detected the extension that time, attempting to run it gave me: game.requiresLauncher is not a function

I do notice that AddGameWizard structures the main part as a constant, so I'm guessing that could have something to do with it, but I'm barely wrapping my head around javascript. 

Link to comment
Share on other sites

  • Solution
Pickysaurus
This post was recognized by Pickysaurus!

ChemBoy1 was awarded the badge 'Helpful' and 10 points.

So the thing you need is the function call to the "RequiresLauncher" function in the registerGame function:

requiresLauncher: makeRequiresLauncher(context.api, gameSpec),

 

If you are not using the "Add Game Wizard" structure, you can literally just skip the function call and write this: 

requiresLauncher: () => { launcher: 'steam' },

This should work in this case since steam launcher requires no additional parameters to function. If it were Epic or Xbox app, you would need to have additional parameters there.

 

You also need to have the "findGame" function return an arrow function to the value, like below. Notice the arrow function after "return".

function makeFindGame(api, gameSpec) {
    return () => util.GameStoreHelper.findByAppId(gameSpec.discovery.ids)
        //.catch(() => util.GameStoreHelper.findByName(gameSpec.discovery.names))
        .then((game) => game.gamePath);
}
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Out of curiosity, how does one tell the file what launcher the game is installed to? It'd be useful to know for any future updates or other games I tried to make an extension for. You said there were more parameters that'd need to be set up?

Link to comment
Share on other sites

I am actually working on that particular question myself for my Prey (2017) extension needs to be able to tell which version of the game was discovered (Steam, Epic, or GOG) since they all have different folder names for the executable (WHY!?!?!). 

Might help to dig into the extensions for a game like Fallout 3/4 since it has good support for multiple game stores. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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