Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src-tauri/src/northstar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn get_northstar_version_number(game_path: &str) -> Result<String, String> {
pub fn launch_northstar(
game_install: GameInstall,
bypass_checks: Option<bool>,
launch_parameters: Option<String>,
) -> Result<String, String> {
dbg!(game_install.clone());

Expand All @@ -77,7 +78,7 @@ pub fn launch_northstar(
));
}

return launch_northstar_steam(game_install, bypass_checks);
return launch_northstar_steam(game_install, bypass_checks, launch_parameters);
}

let bypass_checks = bypass_checks.unwrap_or(false);
Expand Down Expand Up @@ -112,8 +113,17 @@ pub fn launch_northstar(
|| matches!(game_install.install_type, InstallType::UNKNOWN))
{
let ns_exe_path = format!("{}/NorthstarLauncher.exe", game_install.game_path);

let mut args = vec!["/C", "start", "", &ns_exe_path];
// We cannot add the params directly because of limitations with cmd.exe
Copy link
Copy Markdown
Contributor

@catornot catornot Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you try powershell? or is it the same thing for powershell?

// https://stackoverflow.com/questions/9964865/c-system-not-working-when-there-are-spaces-in-two-different-parameters/9965141#9965141

let launch_parameters = launch_parameters.unwrap_or_default();
let ns_params: Vec<&str> = launch_parameters.split_whitespace().collect();
dbg!(ns_params.clone());
args.extend(ns_params);
let _output = std::process::Command::new("C:\\Windows\\System32\\cmd.exe")
.args(["/C", "start", "", &ns_exe_path])
.args(args)
Comment on lines +117 to +224
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @Jan200101 cause this will 100% merge conflict with #444 so we should probably figure out how to best merge it ^^"

I.e. turn profile command into launch arg and then pass it or keep profile arg in GameInstall struct and then combine inside the Rust code.
(second one probably makes more sense)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of APIs rely on having profile information available, that would require adapting, which is why I made the profile part of GameInstall.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, profile should stay in GameInstall so second option it is then ^^

.spawn()
.expect("failed to execute process");
return Ok("Launched game".to_string());
Expand All @@ -131,6 +141,7 @@ pub fn launch_northstar(
pub fn launch_northstar_steam(
game_install: GameInstall,
_bypass_checks: Option<bool>,
launch_parameters: Option<String>,
) -> Result<String, String> {
if !matches!(game_install.install_type, InstallType::STEAM) {
return Err("Titanfall2 was not installed via Steam".to_string());
Expand Down Expand Up @@ -173,7 +184,11 @@ pub fn launch_northstar_steam(
return Err("Couldn't access Titanfall2 directory".to_string());
}

match open::that(format!("steam://run/{}//--northstar/", TITANFALL2_STEAM_ID)) {
let launch_parameters = launch_parameters.unwrap_or_default();
match open::that(format!(
"steam://run/{}//--northstar {}/",
TITANFALL2_STEAM_ID, launch_parameters
)) {
Ok(()) => Ok("Started game".to_string()),
Err(_err) => Err("Failed to launch Titanfall 2 via Steam".to_string()),
}
Expand Down
2 changes: 1 addition & 1 deletion src-vue/src/components/PlayButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default defineComponent({
},
methods: {
async launchGame() {
this.$store.commit('launchGame');
this.$store.commit('launchGame', {});
}
}
});
Expand Down
13 changes: 8 additions & 5 deletions src-vue/src/plugins/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Tabs } from "../utils/Tabs";
import { InstallType } from "../utils/InstallType";
import { invoke } from "@tauri-apps/api";
import { GameInstall } from "../utils/GameInstall";
import { LaunchObject } from "../utils/LaunchObject.d";
import { ReleaseCanal } from "../utils/ReleaseCanal";
import { FlightCoreVersion } from "../../../src-tauri/bindings/FlightCoreVersion";
import { NotificationHandle } from 'element-plus';
Expand Down Expand Up @@ -167,14 +168,15 @@ export const store = createStore<FlightCoreStore>({
}
}
},
async launchGame(state: any, no_checks = false) {
async launchGame(state: any, payload: LaunchObject) {
const { no_checks = false, launch_args = undefined } = payload;
let game_install = {
game_path: state.game_path,
install_type: state.install_type
} as GameInstall;

if (no_checks) {
await invoke("launch_northstar", { gameInstall: game_install, bypassChecks: no_checks })
await invoke("launch_northstar", {gameInstall: game_install, bypassChecks: no_checks, launchParameters: launch_args})
.then((message) => {
console.log("Launched with bypassed checks");
console.log(message);
Expand Down Expand Up @@ -224,7 +226,7 @@ export const store = createStore<FlightCoreStore>({

// Game is ready to play.
case NorthstarState.READY_TO_PLAY:
await invoke("launch_northstar", { gameInstall: game_install })
await invoke("launch_northstar", { gameInstall: game_install, launchParameters: launch_args })
.then((message) => {
console.log(message);
// NorthstarState.RUNNING
Expand All @@ -240,13 +242,14 @@ export const store = createStore<FlightCoreStore>({
break;
}
},
async launchGameSteam(state: any, no_checks = false) {
async launchGameSteam(state: any, payload: LaunchObject) {
const { no_checks = false, launch_args = undefined } = payload;
let game_install = {
game_path: state.game_path,
install_type: state.install_type
} as GameInstall;

await invoke("launch_northstar_steam", { gameInstall: game_install, bypassChecks: no_checks })
await invoke("launch_northstar_steam", { gameInstall: game_install, bypassChecks: no_checks, launchParametres: launch_args })
.then((message) => {
showNotification('Success');
})
Expand Down
4 changes: 4 additions & 0 deletions src-vue/src/utils/LaunchObject.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LaunchObject {
no_checks: boolean,
launch_args: string,
}
27 changes: 25 additions & 2 deletions src-vue/src/views/DeveloperView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@
Launch Northstar via Steam
</el-button>

<br />
<br />

<el-input v-model="launch_args" placeholder="Launch args" clearable />
<el-button type="primary" @click="launchGameWithArgs">
Launch Northstar with args
</el-button>

<el-button type="primary" @click="launchGameViaSteamWithArgs">
Launch Northstar with args via Steam
</el-button>

<br />
<br />

<el-button type="primary" @click="installLauncherGitMain">
Install launcher from main branch
</el-button>
Expand Down Expand Up @@ -147,6 +162,7 @@ export default defineComponent({
data() {
return {
mod_to_install_field_string: "",
launch_args: undefined,
release_notes_text: "",
first_tag: { label: '', value: { name: '' } },
second_tag: { label: '', value: { name: '' } },
Expand Down Expand Up @@ -203,10 +219,17 @@ export default defineComponent({
});
},
async launchGameWithoutChecks() {
this.$store.commit('launchGame', true);
this.$store.commit('launchGame', {no_checks: true});
},
async launchGameWithArgs() {
console.log(this.launch_args);
this.$store.commit('launchGame', {no_checks: false, launch_args: this.launch_args});
},
async launchGameViaSteam() {
this.$store.commit('launchGameSteam', true);
this.$store.commit('launchGameSteam', {no_checks: true});
},
async launchGameViaSteamWithArgs() {
this.$store.commit('launchGameSteam', {no_checks: false, launch_args: this.launch_args});
},
async getInstalledMods() {
let game_install = {
Expand Down