Skip to content

Commit

Permalink
v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
m417z committed Nov 4, 2023
1 parent 0f673d7 commit e11d42a
Show file tree
Hide file tree
Showing 95 changed files with 12,100 additions and 6,394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function About() {
<ContentSection>
<h1>
{t('about.title', {
version: currentVersion + ' ' + t('about.beta'),
// version: currentVersion + ' ' + t('about.beta'),
version: currentVersion,
})}
</h1>
<h3>{t('about.subtitle')}</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Dropdown, List, message, Select, Space } from 'antd';
import { Button, Dropdown, List, message, Select, Space, Switch } from 'antd';
import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
Expand Down Expand Up @@ -44,6 +44,8 @@ function ModDetailsAdvanced({ modId }: Props) {
const [customIncludeModified, setCustomIncludeModified] = useState(false);
const [customExclude, setCustomExclude] = useState<string>();
const [customExcludeModified, setCustomExcludeModified] = useState(false);
const [includeExcludeCustomOnly, setIncludeExcludeCustomOnly] =
useState<boolean>();

const { getModConfig } = useGetModConfig(
useCallback((data) => {
Expand All @@ -58,6 +60,10 @@ function ModDetailsAdvanced({ modId }: Props) {
setCustomInclude(data.config?.includeCustom?.join('\n') ?? '');

setCustomExclude(data.config?.excludeCustom?.join('\n') ?? '');

setIncludeExcludeCustomOnly(
data.config?.includeExcludeCustomOnly ?? false
);
}, [])
);

Expand Down Expand Up @@ -96,7 +102,8 @@ function ModDetailsAdvanced({ modId }: Props) {
modSettingsUI === undefined ||
debugLogging === undefined ||
customInclude === undefined ||
customExclude === undefined
customExclude === undefined ||
includeExcludeCustomOnly === undefined
) {
return null;
}
Expand Down Expand Up @@ -302,6 +309,26 @@ function ModDetailsAdvanced({ modId }: Props) {
</Button>
</SpaceWithWidth>
</List.Item>
<List.Item>
<SettingsListItemMeta
title={t('modDetails.advanced.includeExcludeCustomOnly.title')}
description={t(
'modDetails.advanced.includeExcludeCustomOnly.description'
)}
/>
<Switch
checked={includeExcludeCustomOnly}
onChange={(checked) => {
setIncludeExcludeCustomOnly(checked);
updateModConfig({
modId,
config: {
includeExcludeCustomOnly: checked,
},
});
}}
/>
</List.Item>
</List>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SettingInputNumber = styled(InputWithContextMenu.InputNumber)`
}
`;

const SettingSelect = styled(Select)`
const SettingSelect = styled(InputWithContextMenu.Select)`
width: 100%;
`;

Expand Down Expand Up @@ -104,7 +104,11 @@ function StringSetting({ value, sampleValue, onChange }: StringSettingProps) {

return (
<InputWithContextMenu.Input
placeholder={t('modDetails.settings.sampleValue') + `: ${sampleValue}`}
placeholder={
sampleValue
? t('modDetails.settings.sampleValue') + `: ${sampleValue}`
: undefined
}
value={value}
onChange={(e) => onChange(e.target.value)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ const appLanguages = [
es: 'Español',
fr: 'Français',
it: 'Italiano',
jp: '日本語',
ja: '日本語',
ko: '한국어',
pl: 'Polski',
'pt-BR': 'Português',
ro: 'Română',
ru: 'Русский',
tr: 'Türkçe',
ua: 'Українська',
'zh-CN': '简体中文',
'zh-TW': '繁體中文',
}).sort((a, b) => a[1].localeCompare(b[1])),
Expand All @@ -63,6 +69,46 @@ function parseIntLax(value?: string | number | null) {
return Number.isNaN(result) ? 0 : result;
}

function engineIncludeFromEngineAppSettings(
engineAppSettings: AppSettings['engine']
) {
return engineAppSettings.include.join('\n');
}

function engineExcludeFromEngineAppSettings(
engineAppSettings: AppSettings['engine']
) {
return [
...(engineAppSettings.injectIntoCriticalProcesses
? []
: ['<critical_system_processes>']),
...engineAppSettings.exclude,
].join('\n');
}

function engineIncludeToEngineAppSettings(include: string) {
const includeArray = include
.split('\n')
.map((x) => x.trim())
.filter((x) => x);
return {
include: includeArray,
};
}

function engineExcludeToEngineAppSettings(exclude: string) {
const excludeArray = exclude
.split('\n')
.map((x) => x.trim())
.filter((x) => x);
return {
exclude: excludeArray.filter((x) => x !== '<critical_system_processes>'),
injectIntoCriticalProcesses: !excludeArray.includes(
'<critical_system_processes>'
),
};
}

function Settings() {
const { t, i18n } = useTranslation();
const appLanguage = i18n.resolvedLanguage;
Expand All @@ -76,20 +122,20 @@ function Settings() {
const [engineLoggingVerbosity, setEngineLoggingVerbosity] = useState(0);
const [engineInclude, setEngineInclude] = useState('');
const [engineExclude, setEngineExclude] = useState('');
const [engineThreadAttachExempt, setEngineThreadAttachExempt] = useState('');
const [injectIntoCriticalProcesses, setInjectIntoCriticalProcesses] =
useState<boolean | null>(false);
const [
engineLoadModsInCriticalSystemProcesses,
setEngineLoadModsInCriticalSystemProcesses,
] = useState(0);

const resetMoreAdvancedSettings = useCallback(() => {
if (appSettings) {
setAppLoggingVerbosity(appSettings.loggingVerbosity);
setEngineLoggingVerbosity(appSettings.engine.loggingVerbosity);
setEngineInclude(appSettings.engine.include.join('\n'));
setEngineExclude(appSettings.engine.exclude.join('\n'));
setEngineThreadAttachExempt(
appSettings.engine.threadAttachExempt.join('\n')
setEngineInclude(engineIncludeFromEngineAppSettings(appSettings.engine));
setEngineExclude(engineExcludeFromEngineAppSettings(appSettings.engine));
setEngineLoadModsInCriticalSystemProcesses(
appSettings.engine.loadModsInCriticalSystemProcesses
);
setInjectIntoCriticalProcesses(appSettings.injectIntoCriticalProcesses);
}
}, [appSettings]);

Expand Down Expand Up @@ -120,6 +166,14 @@ function Settings() {
const [isMoreAdvancedSettingsModalOpen, setIsMoreAdvancedSettingsModalOpen] =
useState(false);

const excludeListHasCriticalSystemProcesses = !!engineExclude.match(
/^[ \t]*<critical_system_processes>[ \t]*$/m
);
const includeListEmpty = engineInclude.trim() === '';
const excludeListEmpty = engineExclude.trim() === '';
const excludeListHasWildcard =
!excludeListEmpty && !!engineExclude.match(/^[ \t]*\*[ \t]*$/m);

if (!appSettings) {
return null;
}
Expand Down Expand Up @@ -305,22 +359,13 @@ function Settings() {
onOk={() => {
updateAppSettings({
appSettings: {
injectIntoCriticalProcesses,
loggingVerbosity: appLoggingVerbosity,
engine: {
loggingVerbosity: engineLoggingVerbosity,
include: engineInclude
.split('\n')
.map((x) => x.trim())
.filter((x) => x),
exclude: engineExclude
.split('\n')
.map((x) => x.trim())
.filter((x) => x),
threadAttachExempt: engineThreadAttachExempt
.split('\n')
.map((x) => x.trim())
.filter((x) => x),
...engineIncludeToEngineAppSettings(engineInclude),
...engineExcludeToEngineAppSettings(engineExclude),
loadModsInCriticalSystemProcesses:
engineLoadModsInCriticalSystemProcesses,
},
},
});
Expand Down Expand Up @@ -405,6 +450,29 @@ function Settings() {
setEngineExclude(e.target.value);
}}
/>
{!excludeListHasCriticalSystemProcesses && (
<Alert
description={
<Trans
t={t}
i18nKey="settings.processList.exclusionCriticalProcessesNotice"
components={[<code />]}
values={{
critical_system_processes: '<critical_system_processes>',
}}
// A workaround to make a value with `<` work properly.
shouldUnescape
tOptions={{
interpolation: {
escapeValue: true,
},
}}
/>
}
type="info"
showIcon
/>
)}
</List.Item>
<List.Item>
<SettingsListItemMeta
Expand All @@ -425,63 +493,53 @@ function Settings() {
setEngineInclude(e.target.value);
}}
/>
{engineExclude.replace(/\n+$/g, '').length === 0 &&
engineInclude.replace(/\n+$/g, '').length > 0 && (
<Alert
description={t(
'settings.processList.inclusionWithoutExclusionNotice'
)}
type="warning"
showIcon
/>
)}
{!includeListEmpty && excludeListEmpty && (
<Alert
description={t(
'settings.processList.inclusionWithoutExclusionNotice'
)}
type="warning"
showIcon
/>
)}
{!includeListEmpty && !excludeListHasWildcard && (
<Alert
description={t(
'settings.processList.inclusionWithoutTotalExclusionNotice'
)}
type="info"
showIcon
/>
)}
</List.Item>
<List.Item>
<SettingsListItemMeta
title={t('settings.processList.titleThreadAttachExempt')}
description={
<Trans
t={t}
i18nKey="settings.processList.descriptionThreadAttachExempt"
components={[
<a href="https://m417z.com/A-guest-in-another-process-a-story-of-a-remote-thread-crash/">
website
</a>,
]}
/>
}
title={t('settings.loadModsInCriticalSystemProcesses.title')}
description={t(
'settings.loadModsInCriticalSystemProcesses.description'
)}
/>
<InputWithContextMenu.TextArea
rows={4}
value={engineThreadAttachExempt}
placeholder={
(t('settings.processList.processListPlaceholder') as string) +
'\n' +
'notepad.exe\n' +
'%ProgramFiles%\\Notepad++\\notepad++.exe\n' +
'C:\\Windows\\system32\\*'
}
onChange={(e) => {
setEngineThreadAttachExempt(e.target.value);
<SettingsSelect
value={engineLoadModsInCriticalSystemProcesses}
onChange={(value) => {
setEngineLoadModsInCriticalSystemProcesses(
typeof value === 'number' ? value : 0
);
}}
/>
</List.Item>
{injectIntoCriticalProcesses !== null && (
<List.Item>
<SettingsListItemMeta
title={t('settings.injectIntoCriticalProcesses.title')}
description={t(
'settings.injectIntoCriticalProcesses.description'
>
<Select.Option key="never" value={0}>
{t('settings.loadModsInCriticalSystemProcesses.never')}
</Select.Option>
<Select.Option key="onlyExplicitMatch" value={1}>
{t(
'settings.loadModsInCriticalSystemProcesses.onlyExplicitMatch'
)}
/>
<Switch
checked={injectIntoCriticalProcesses}
onChange={(checked) => {
setInjectIntoCriticalProcesses(checked);
}}
/>
</List.Item>
)}
</Select.Option>
<Select.Option key="always" value={2}>
{t('settings.loadModsInCriticalSystemProcesses.always')}
</Select.Option>
</SettingsSelect>
</List.Item>
</List>
</Modal>
</SettingsWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const mockSettings = !useMockData
hideTrayIcon: false,
dontAutoShowToolkit: false,
modTasksDialogDelay: 2000,
injectIntoCriticalProcesses: false,
safeMode: false,
loggingVerbosity: 0,
engine: {
loggingVerbosity: 0,
include: ['a.exe', 'b.exe'],
exclude: ['c.exe', 'd.exe'],
threadAttachExempt: ['e.exe', 'f.exe'],
injectIntoCriticalProcesses: false,
loadModsInCriticalSystemProcesses: 1,
},
};

Expand Down Expand Up @@ -52,6 +52,7 @@ const mockModConfig = {
exclude: ['explorer.exe'],
includeCustom: [],
excludeCustom: [],
includeExcludeCustomOnly: false,
architecture: ['x86-64'],
version: '1.0',
};
Expand Down
Loading

0 comments on commit e11d42a

Please sign in to comment.