aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-04-19 02:21:08 +0200
committer0neGal <mail@0negal.com>2022-04-19 02:26:18 +0200
commitb279ce44cb334dafc0f07b92c992742f0fcca53b (patch)
treead42ba6c7454f5f12f73841793199c4a674f3ac5
parent15fa312110fc94dcfbef58d1b0bd5f58a4e5f431 (diff)
downloadViper-b279ce44cb334dafc0f07b92c992742f0fcca53b.tar.gz
Viper-b279ce44cb334dafc0f07b92c992742f0fcca53b.zip
basic Linux launch support
extras/findgame.js is now extras/find.js, as it now also is able to find the prefix of your Steam install and the path to Origin. Generally speaking you can technically launch the game right now, both Vanilla and Northstar (from what I can tell), albeit Wine is being weird for me currently and leads to the game freezing while it's loading, or simply never running because Origin is technically already running in the background. Maybe I should add a "kill" function to the launch screen. Besides that some status text would also be nice i.e change "Launch" to "Launching", to make sure the user doesn't think Viper isn't doing anything. On the Windows side of things I also made the NS Launch use "Titanfall2.exe -northstar" instead of "NorthstarLauncher.exe" to prevent some authentication issues, I haven't tested it yet, and will do later, we unfortunately can't do that on Linux as "-northstar" never gets passed, hence why we manually have to launch Origin and everything. Overall needs more testing, and not complete. As I'm still missing a way to find Proton, which would in the end lead to a hassle free experience.
-rw-r--r--src/app/main.js1
-rw-r--r--src/extras/find.js119
-rw-r--r--src/extras/findgame.js85
-rw-r--r--src/utils.js30
4 files changed, 145 insertions, 90 deletions
diff --git a/src/app/main.js b/src/app/main.js
index 6ec5820..8894d3f 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -10,6 +10,7 @@ let shouldInstallNorthstar = false;
var settings = {
nsargs: "",
gamepath: "",
+ wineprefix: "",
nsupdate: true,
autolang: true,
forcedlang: "en",
diff --git a/src/extras/find.js b/src/extras/find.js
new file mode 100644
index 0000000..0d32157
--- /dev/null
+++ b/src/extras/find.js
@@ -0,0 +1,119 @@
+const fs = require("fs");
+const path = require("path");
+const vdf = require("simple-vdf");
+const { app } = require("electron");
+
+const util = require("util");
+const exec = util.promisify(require("child_process").exec);
+
+let home = app.getPath("home");
+
+let symdir = ".steam/steam";
+let localdir = ".local/share/Steam";
+let flatpakdir = ".var/app/com.valvesoftware.Steam/";
+
+module.exports = {
+ prefix: () => {
+ if (process.platform == "win32") {return false}
+ let compatdir = "/steamapps/compatdata/123790/pfx";
+ let folders = [
+ path.join(home, symdir, compatdir),
+ path.join(home, localdir, compatdir),
+ path.join(home, flatpakdir, symdir, compatdir),
+ path.join(home, flatpakdir, localdir, compatdir),
+ ]
+
+ for (let i = 0; i < folders.length; i++) {
+ let origin = path.join(folders[i], "drive_c/Program Files (x86)/Origin/Origin.exe");
+ if (fs.existsSync(folders[i])) {
+ if (fs.existsSync(origin)) {
+ return {
+ origin: origin,
+ path: folders[i],
+ }
+
+ }
+ }
+ }
+
+ return false;
+ },
+ game: async () => {
+ let gamepath = "";
+
+ // Autodetect path
+ // Windows only using powershell and windows registery
+ // Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2\
+ if (process.platform == "win32") {
+ try {
+ const {stdout} = await exec("Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Respawn\\Titanfall2\\ -Name \"Install Dir\"", {"shell":"powershell.exe"});
+
+ const gamepath = stdout.split('\n')
+ .filter(r => r.indexOf("Install Dir") !== -1)[0]
+ .replace(/\s+/g,' ')
+ .trim()
+ .replace("Install Dir : ","");
+
+ if (gamepath) {return gamepath}
+ } catch (err) {}
+ }
+
+ // Detect using Steam VDF
+ function readvdf(data) {
+ // Parse read_data
+ data = vdf.parse(data);
+
+ let values = Object.values(data["libraryfolders"]);
+ if (typeof values[values.length - 1] != "object") {
+ values.pop(1);
+ }
+
+ // `.length - 1` This is because the last value is `contentstatsid`
+ for (let i = 0; i < values.length; i++) {
+ let data_array = Object.values(values[i])
+
+ if (fs.existsSync(data_array[0] + "/steamapps/common/Titanfall2/Titanfall2.exe")) {
+ console.log("Found game in:", data_array[0])
+ return data_array[0] + "/steamapps/common/Titanfall2";
+ } else {
+ console.log("Game not in:", data_array[0])
+ }
+ }
+ }
+
+ let folders = [];
+ switch (process.platform) {
+ case "win32":
+ folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf"];
+ break
+ case "linux":
+ case "openbsd":
+ case "freebsd":
+ let vdfdir = "/steamapps/libraryfolders.vdf";
+ folders = [
+ path.join(home, symdir, vdfdir),
+ path.join(home, localdir, vdfdir),
+ path.join(home, flatpakdir, symdir, vdfdir),
+ path.join(home, flatpakdir, localdir, vdfdir)
+ ]
+ break
+ }
+
+ if (folders.length > 0) {
+ for (let i = 0; i < folders.length; i++) {
+ if (! fs.existsSync(folders[i])) {continue}
+ console.log("Searching VDF file at:", folders[i])
+
+ let data = fs.readFileSync(folders[i])
+ let read_vdf = readvdf(data.toString())
+ if (read_vdf) {return read_vdf}
+ }
+ }
+
+ if (gamepath) {
+ return gamepath;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/src/extras/findgame.js b/src/extras/findgame.js
deleted file mode 100644
index 3beca23..0000000
--- a/src/extras/findgame.js
+++ /dev/null
@@ -1,85 +0,0 @@
-const fs = require("fs");
-const path = require("path");
-const vdf = require("simple-vdf");
-const { app } = require("electron");
-
-const util = require("util");
-const exec = util.promisify(require("child_process").exec);
-
-module.exports = async () => {
- let gamepath = "";
-
- // Autodetect path
- // Windows only using powershell and windows registery
- // Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2\
- if (process.platform == "win32") {
- try {
- const {stdout} = await exec("Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Respawn\\Titanfall2\\ -Name \"Install Dir\"", {"shell":"powershell.exe"});
-
- const gamepath = stdout.split('\n')
- .filter(r => r.indexOf("Install Dir") !== -1)[0]
- .replace(/\s+/g,' ')
- .trim()
- .replace("Install Dir : ","");
-
- if (gamepath) {return gamepath}
- } catch (err) {}
- }
-
- // Detect using Steam VDF
- function readvdf(data) {
- // Parse read_data
- data = vdf.parse(data);
-
- let values = Object.values(data["libraryfolders"]);
- if (typeof values[values.length - 1] != "object") {
- values.pop(1);
- }
-
- // `.length - 1` This is because the last value is `contentstatsid`
- for (let i = 0; i < values.length; i++) {
- let data_array = Object.values(values[i])
-
- if (fs.existsSync(data_array[0] + "/steamapps/common/Titanfall2/Titanfall2.exe")) {
- console.log("Found game in:", data_array[0])
- return data_array[0] + "/steamapps/common/Titanfall2";
- } else {
- console.log("Game not in:", data_array[0])
- }
- }
- }
-
- let folders = [];
- switch (process.platform) {
- case "win32":
- folders = ["C:\\Program Files (x86)\\Steam\\steamapps\\libraryfolders.vdf"];
- break
- case "linux":
- case "openbsd":
- case "freebsd":
- let home = app.getPath("home");
- folders = [
- path.join(home, "/.steam/steam/steamapps/libraryfolders.vdf"),
- path.join(home, ".var/app/com.valvesoftware.Steam/.steam/steam/steamapps/libraryfolders.vdf"),
- path.join(home, ".var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/libraryfolders.vdf")
- ]
- break
- }
-
- if (folders.length > 0) {
- for (let i = 0; i < folders.length; i++) {
- if (! fs.existsSync(folders[i])) {continue}
- console.log("Searching VDF file at:", folders[i])
-
- let data = fs.readFileSync(folders[i])
- let read_vdf = readvdf(data.toString())
- if (read_vdf) {return read_vdf}
- }
- }
-
- if (gamepath) {
- return gamepath;
- } else {
- return false;
- }
-}
diff --git a/src/utils.js b/src/utils.js
index 2804322..b100cf9 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -8,8 +8,8 @@ const events = new Emitter();
const cli = require("./cli");
const lang = require("./lang");
+const find = require("./extras/find");
const requests = require("./extras/requests");
-const findgame = require("./extras/findgame");
const unzip = require("unzipper");
const run = require("child_process").spawn;
@@ -24,6 +24,7 @@ var settings = {
lang: "en-US",
nsupdate: true,
autolang: true,
+ wineprefix: "",
forcedlang: "en",
autoupdate: true,
nsargs: "-multiple",
@@ -149,7 +150,7 @@ async function setpath(win, forcedialog) {
ipcMain.emit("newpath", null, settings.gamepath);
}
- let gamepath = await findgame();
+ let gamepath = await find.game();
if (gamepath) {
setGamepath(gamepath);
return;
@@ -356,13 +357,28 @@ function updatevp(autoinstall) {
// however it'll be added at some point.
function launch(version) {
let cwd = process.cwd();
+ let prefix = settings.wineprefix;
process.chdir(settings.gamepath);
+ if (process.platform != "win32") {
+ let foundprefix = find.prefix();
+ if (foundprefix) {
+ prefix = foundprefix;
+ }
+
+ if (! fs.existsSync(prefix.path)) {
+ winAlert("invalid wine prefix");
+ return false;
+ } else {
+ process.env["WINEPREFIX"] = prefix.path;
+ }
+ }
+
switch(version) {
case "vanilla":
console.log(lang("general.launching"), "Vanilla...")
- if (process.platform == "linux") {
+ if (process.platform != "win32") {
run(settings.winebin, [path.join(settings.gamepath + "/Titanfall2.exe")])
} else {
run(path.join(settings.gamepath + "/Titanfall2.exe"))
@@ -372,11 +388,13 @@ function launch(version) {
default:
console.log(lang("general.launching"), "Northstar...")
- if (process.platform == "linux") {
+ if (process.platform != "win32") {
+ run(settings.winebin, [prefix.origin])
run(settings.winebin, [path.join(settings.gamepath + "/NorthstarLauncher.exe")])
} else {
- run(path.join(settings.gamepath + "/NorthstarLauncher.exe"))
+ run(path.join(settings.gamepath + "/Titanfall2.exe -northstar"))
}
+
break;
}
@@ -806,6 +824,8 @@ setInterval(() => {
}
}, 1500)
+console.log(find.prefix())
+
module.exports = {
mods,
lang,