Skip to content

Commit

Permalink
Add safety around workshop ID, add pure vanilla option
Browse files Browse the repository at this point in the history
  • Loading branch information
FLSoz committed Aug 22, 2022
1 parent 0de9abc commit 91a9685
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/model/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface AppConfig {

language: string;

pureVanilla?: boolean;

[AppConfigKeys.LOCAL_DIR]?: string;
[AppConfigKeys.GAME_EXEC]: string;
[AppConfigKeys.MANAGER_ID]: bigint;
Expand Down Expand Up @@ -62,5 +64,6 @@ export interface SeparatedCollectionConfig extends CollectionConfig {

export enum SettingsViewModalType {
NONE = 0,
LOG_EDIT = 1
LOG_EDIT = 1,
WORKSHOP_ID_EDIT = 2
}
33 changes: 24 additions & 9 deletions src/renderer/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,42 @@ class API {
workshopID: string,
closeOnLaunch: boolean,
modList: ModData[],
pureVanilla?: boolean,
logParams?: { [loggerID: string]: NLogLevel },
extraParams?: string
): Promise<any> {
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<boolean> {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/CollectionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ class CollectionView extends Component<{ appState: AppState; location: Location
config!.workshopID,
config!.closeOnLaunch,
mods,
config!.pureVanilla,
config!.logParams,
config!.extraParams
)
Expand Down
120 changes: 102 additions & 18 deletions src/renderer/views/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface LogConfig {
}

interface EditingConfig extends AppConfig {
editingWorkshopID?: string;
editingLogConfig: LogConfig[];
}

Expand All @@ -54,7 +53,6 @@ interface SettingsFields {
workshopID?: string;
steamMaxConcurrency?: number;
extraParams?: string[];
loggingParams?: string[];
}

class SettingsView extends Component<AppState, SettingsState> {
Expand All @@ -76,7 +74,7 @@ class SettingsView extends Component<AppState, SettingsState> {
});
}
this.state = {
editingConfig: { ...config, editingWorkshopID: appState.config.workshopID.toString(), editingLogConfig: logConfig },
editingConfig: { ...config, editingLogConfig: logConfig },
selectingDirectory: false,
madeLocalEdits: false,
modalType: SettingsViewModalType.NONE,
Expand Down Expand Up @@ -206,10 +204,10 @@ class SettingsView extends Component<AppState, SettingsState> {
}

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 (
<Modal
Expand Down Expand Up @@ -249,6 +247,61 @@ class SettingsView extends Component<AppState, SettingsState> {
</Form>
</Modal>
);
}
case SettingsViewModalType.WORKSHOP_ID_EDIT: {
return (
<Modal
key="workshop-id-modal"
title={`Select Mod Manager`}
visible
closable={false}
footer={[
<Button
type="primary"
key="no-changes"
onClick={() => {
const { config } = this.props;
editingConfig.workshopID = config.workshopID;
this.modalFormRef.current?.resetFields();
this.setState({ modalType: SettingsViewModalType.NONE });
}}
>
Make No Changes
</Button>,
<Button
key="save-settings"
type="primary"
htmlType="submit"
danger
onClick={() => {
this.modalFormRef.current?.submit();
}}
>
Save Settings
</Button>
]}
>
<Form
className="WorkshopIDForm"
ref={this.modalFormRef}
onFinish={() => {
this.setState({ modalType: SettingsViewModalType.NONE });
}}
>
<Form.Item key="workshop-id" name="workshop-id" label="Workshop ID" initialValue={editingConfig.workshopID}>
<InputNumber
value={editingConfig!.workshopID.toString()}
onChange={(value) => {
editingConfig!.workshopID = BigInt(value);
updateState({ madeConfigEdits: true });
}}
style={{ width: '200px' }}
/>
</Form.Item>
</Form>
</Modal>
);
}
default:
return null;
}
Expand Down Expand Up @@ -376,34 +429,29 @@ class SettingsView extends Component<AppState, SettingsState> {
checked={editingConfig!.closeOnLaunch}
onChange={(checked) => {
editingConfig!.closeOnLaunch = checked;
/* this.formRef.current!.setFieldsValue({
closeOnLaunch: checked
}); */
updateState({ madeConfigEdits: true });
}}
/>
</Form.Item>
<Form.Item
name="workshopID"
label="Workshop ID"
rules={[{ required: true }]}
initialValue={editingConfig!.workshopID.toString()}
name="pureVanilla"
label="Pure Vanilla"
initialValue={editingConfig!.pureVanilla}
tooltip={{
overlayInnerStyle: { minWidth: 300 },
title: (
<div>
<p>Which workshop mod is used as the underlying mod manager</p>
<p>Should TTSMM launch the game without the integrated mod loader if no other mods are selected?</p>
</div>
)
}}
>
<InputNumber
value={editingConfig!.workshopID.toString()}
onChange={(value) => {
editingConfig!.workshopID = BigInt(value);
<Switch
checked={editingConfig!.pureVanilla}
onChange={(checked) => {
editingConfig!.pureVanilla = checked;
updateState({ madeConfigEdits: true });
}}
style={{ width: 125 }}
/>
</Form.Item>
<Form.Item
Expand Down Expand Up @@ -455,6 +503,42 @@ class SettingsView extends Component<AppState, SettingsState> {
</Select.Option>
</Select>
</Form.Item>
<Form.Item
name="workshopID"
label="Workshop ID"
rules={[{ required: true }]}
initialValue={editingConfig!.workshopID.toString()}
tooltip={{
overlayInnerStyle: { minWidth: 300 },
title: (
<div>
<p>Which workshop mod is used as the underlying mod manager</p>
</div>
)
}}
>
<Input.Group compact style={{ width: '100%' }}>
<InputNumber
value={editingConfig!.workshopID.toString()}
onChange={(value) => {
editingConfig!.workshopID = BigInt(value);
updateState({ madeConfigEdits: true });
}}
disabled
style={{ width: 175 }}
/>
<Button
icon={<EditFilled />}
type="primary"
danger
onClick={() => {
this.setState({
modalType: SettingsViewModalType.WORKSHOP_ID_EDIT
});
}}
/>
</Input.Group>
</Form.Item>
</Col>
<Col span={12} key="additional-commands">
<Form.Item name="extraParams" label="Additional launch Arguments" initialValue={editingConfig!.extraParams}>
Expand Down

0 comments on commit 91a9685

Please sign in to comment.