Skip to content

Commit

Permalink
feat(playback): preserve user CS2 cfg when starting the game
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Dec 2, 2023
1 parent b73c264 commit 29e7254
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'node:path';
import { getAppFolderPath } from 'csdm/node/filesystem/get-app-folder-path';

export function defineCfgFolderLocation() {
// This env variable tells CS2 to save user's config (keybindings, video...) in the specified folder.
// It allows us to not override user's config when starting CS2 from the application.
process.env.USRLOCALCSGO = path.join(getAppFolderPath(), 'cfg');
}
2 changes: 2 additions & 0 deletions src/node/counter-strike/launcher/start-counter-strike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { deleteJsonActionsFile } from '../json-actions-file/delete-json-actions-
import { isMac } from 'csdm/node/os/is-mac';
import { assertSteamIsRunning } from './assert-steam-is-running';
import { assertDemoPathIsValid } from './assert-demo-path-is-valid';
import { defineCfgFolderLocation } from './define-cfg-folder-location';

type StartCounterStrikeOptions = {
demoPath: string;
Expand Down Expand Up @@ -131,6 +132,7 @@ export async function startCounterStrike(options: StartCounterStrikeOptions) {
}

if (game !== Game.CSGO) {
defineCfgFolderLocation();
await installCs2ServerPlugin();
}

Expand Down
2 changes: 2 additions & 0 deletions src/node/counter-strike/launcher/watch-demo-with-hlae.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getCounterStrikeExecutablePath } from '../get-counter-strike-executable
import { installCs2ServerPlugin } from './cs2-server-plugin';
import { assertDemoPathIsValid } from './assert-demo-path-is-valid';
import { sleep } from 'csdm/common/sleep';
import { defineCfgFolderLocation } from './define-cfg-folder-location';

export type HlaeOptions = {
demoPath: string;
Expand Down Expand Up @@ -117,6 +118,7 @@ export async function watchDemoWithHlae({
// Wait a few seconds before installing the plugin as its files may still be locked by CS2
await sleep(2000);
}
defineCfgFolderLocation();
await installCs2ServerPlugin();
} else {
hlaeParameters.push(
Expand Down

0 comments on commit 29e7254

Please sign in to comment.