From 91a9685d815f13aa057a242fa247b0e930f7397e Mon Sep 17 00:00:00 2001 From: FLSoz <65517812+FLSoz@users.noreply.github.com> Date: Sun, 21 Aug 2022 20:35:35 -0700 Subject: [PATCH] Add safety around workshop ID, add pure vanilla option --- src/main/main.ts | 2 +- src/model/AppConfig.ts | 5 +- src/renderer/Api.ts | 33 +++++-- src/renderer/views/CollectionView.tsx | 1 + src/renderer/views/SettingsView.tsx | 120 ++++++++++++++++++++++---- 5 files changed, 132 insertions(+), 29 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 06cf667..574c1e0 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -471,7 +471,7 @@ ipcMain.on(ValidChannel.GAME_RUNNING, async (event) => { // Launch steam as separate process ipcMain.handle(ValidChannel.LAUNCH_GAME, async (_event, gameExec, workshopID, closeOnLaunch, args) => { log.info('Launching game with custom args:'); - const allArgs = ['+custom_mod_list', `[workshop:${workshopID}]`, ...args]; + const allArgs = ['+custom_mod_list', !!workshopID ? `[workshop:${workshopID}]` : '[]', ...args]; log.info(allArgs); await child_process.spawn(gameExec, allArgs, { detached: true diff --git a/src/model/AppConfig.ts b/src/model/AppConfig.ts index 8295b21..98bee80 100644 --- a/src/model/AppConfig.ts +++ b/src/model/AppConfig.ts @@ -26,6 +26,8 @@ export interface AppConfig { language: string; + pureVanilla?: boolean; + [AppConfigKeys.LOCAL_DIR]?: string; [AppConfigKeys.GAME_EXEC]: string; [AppConfigKeys.MANAGER_ID]: bigint; @@ -62,5 +64,6 @@ export interface SeparatedCollectionConfig extends CollectionConfig { export enum SettingsViewModalType { NONE = 0, - LOG_EDIT = 1 + LOG_EDIT = 1, + WORKSHOP_ID_EDIT = 2 } diff --git a/src/renderer/Api.ts b/src/renderer/Api.ts index 04a0131..248953a 100644 --- a/src/renderer/Api.ts +++ b/src/renderer/Api.ts @@ -96,27 +96,42 @@ class API { workshopID: string, closeOnLaunch: boolean, modList: ModData[], + pureVanilla?: boolean, logParams?: { [loggerID: string]: NLogLevel }, extraParams?: string ): Promise { - const modListStr: string = modList + const actualMods = modList .filter((modData) => modData && modData.workshopID !== BigInt(workshopID)) .map((mod: ModData) => { return mod ? `[${mod.uid.toString().replaceAll(' ', ':/%20')}]` : ''; - }) - .join(','); - let args: string[] = ['+ttsmm_mod_list', `[${modListStr}]`]; - if (logParams) { - Object.entries(logParams).forEach(([loggerID, logLevel]: [string, NLogLevel]) => { - args.push(loggerID && loggerID.length > 0 ? `+log_level_${loggerID}` : '+log_level'); - args.push(logLevel); }); + let args: string[] = []; + let passedWorkshopID: string | null = workshopID; + + let addMods = true; + // Don't block pure vanilla if only Mod Manager & Harmony are selected + if (actualMods.length === 0 || (actualMods.length === 1 && actualMods[0] === '[workshop:2571814511]')) { + if (pureVanilla) { + passedWorkshopID = null; + addMods = false; + } + } + if (addMods) { + const modListStr: string = actualMods.join(','); + args.push('+ttsmm_mod_list'); + args.push(`[${modListStr}]`); + if (logParams) { + Object.entries(logParams).forEach(([loggerID, logLevel]: [string, NLogLevel]) => { + args.push(loggerID && loggerID.length > 0 ? `+log_level_${loggerID}` : '+log_level'); + args.push(logLevel); + }); + } } if (extraParams) { const splitParams: string[] = extraParams.split(' '); args = args.concat(splitParams); } - return ipcRenderer.invoke(ValidChannel.LAUNCH_GAME, gameExec, workshopID, closeOnLaunch, args); + return ipcRenderer.invoke(ValidChannel.LAUNCH_GAME, gameExec, passedWorkshopID, closeOnLaunch, args); } gameRunning(): Promise { diff --git a/src/renderer/views/CollectionView.tsx b/src/renderer/views/CollectionView.tsx index 4cef7be..86c776e 100644 --- a/src/renderer/views/CollectionView.tsx +++ b/src/renderer/views/CollectionView.tsx @@ -618,6 +618,7 @@ class CollectionView extends Component<{ appState: AppState; location: Location config!.workshopID, config!.closeOnLaunch, mods, + config!.pureVanilla, config!.logParams, config!.extraParams ) diff --git a/src/renderer/views/SettingsView.tsx b/src/renderer/views/SettingsView.tsx index 74b67e7..aed99a4 100644 --- a/src/renderer/views/SettingsView.tsx +++ b/src/renderer/views/SettingsView.tsx @@ -33,7 +33,6 @@ interface LogConfig { } interface EditingConfig extends AppConfig { - editingWorkshopID?: string; editingLogConfig: LogConfig[]; } @@ -54,7 +53,6 @@ interface SettingsFields { workshopID?: string; steamMaxConcurrency?: number; extraParams?: string[]; - loggingParams?: string[]; } class SettingsView extends Component { @@ -76,7 +74,7 @@ class SettingsView extends Component { }); } this.state = { - editingConfig: { ...config, editingWorkshopID: appState.config.workshopID.toString(), editingLogConfig: logConfig }, + editingConfig: { ...config, editingLogConfig: logConfig }, selectingDirectory: false, madeLocalEdits: false, modalType: SettingsViewModalType.NONE, @@ -206,10 +204,10 @@ class SettingsView extends Component { } renderModal() { - const { modalType, editingContext } = this.state; + const { modalType, editingContext, editingConfig } = this.state; const { updateState } = this.props; switch (modalType) { - case SettingsViewModalType.LOG_EDIT: + case SettingsViewModalType.LOG_EDIT: { const config: LogConfig = editingContext as LogConfig; return ( { ); + } + case SettingsViewModalType.WORKSHOP_ID_EDIT: { + return ( + { + const { config } = this.props; + editingConfig.workshopID = config.workshopID; + this.modalFormRef.current?.resetFields(); + this.setState({ modalType: SettingsViewModalType.NONE }); + }} + > + Make No Changes + , + + ]} + > +
{ + this.setState({ modalType: SettingsViewModalType.NONE }); + }} + > + + { + editingConfig!.workshopID = BigInt(value); + updateState({ madeConfigEdits: true }); + }} + style={{ width: '200px' }} + /> + +
+
+ ); + } default: return null; } @@ -376,34 +429,29 @@ class SettingsView extends Component { checked={editingConfig!.closeOnLaunch} onChange={(checked) => { editingConfig!.closeOnLaunch = checked; - /* this.formRef.current!.setFieldsValue({ - closeOnLaunch: checked - }); */ updateState({ madeConfigEdits: true }); }} /> -

Which workshop mod is used as the underlying mod manager

+

Should TTSMM launch the game without the integrated mod loader if no other mods are selected?

) }} > - { - editingConfig!.workshopID = BigInt(value); + { + editingConfig!.pureVanilla = checked; updateState({ madeConfigEdits: true }); }} - style={{ width: 125 }} />
{ + +

Which workshop mod is used as the underlying mod manager

+ + ) + }} + > + + { + editingConfig!.workshopID = BigInt(value); + updateState({ madeConfigEdits: true }); + }} + disabled + style={{ width: 175 }} + /> +