Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Add a per-game Disable hidraw option

NotProtonNot3e1293fe9100
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index f24cbac..0da1052 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -593,6 +593,28 @@ plan_hidden_controllers() {
$controllers_wanted"
}
+# Sets Wine's DisableHidraw for games with "Disable hidraw" checked. When it's
+# unchecked, the value is removed only if NotProton set it.
+plan_disable_hidraw() {
+ hidraw_file="$STEAM_COMPAT_DATA_PATH/notproton-disable-hidraw"
+ hidraw_value=""
+ [ -n "$STEAM_COMPAT_DATA_PATH" ] && [ ! -L "$hidraw_file" ] || return 1
+ hidraw_set=""
+ [ ! -f "$WINEPREFIX/system.reg" ] || hidraw_set=$(tr '[:upper:]' '[:lower:]' < "$WINEPREFIX/system.reg" \
+ | awk '/^\[/ { s = index($0, "[system\\\\controlset001\\\\services\\\\winebus]") == 1; next }
+ s && $0 == "\"disablehidraw\"=dword:00000001" { print 1; exit }')
+ if [ "$NOTPROTON_DISABLE_HIDRAW" = "1" ]; then
+ [ -n "$hidraw_set" ] || hidraw_value='"DisableHidraw"=dword:00000001'
+ elif [ -f "$hidraw_file" ] && [ -n "$hidraw_set" ]; then
+ hidraw_value='"DisableHidraw"=-'
+ fi
+}
+
+winebus_lines() {
+ [ -n "$hidraw_value" ] || return 0
+ printf '%s\r\n' '[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\WineBus]' "$hidraw_value" ''
+}
+
import_prefix_settings() {
if [ "$NOTPROTON_RETINA" = "1" ]; then
retina_line='"RetinaMode"="y"'
@@ -607,6 +629,16 @@ import_prefix_settings() {
controllers_remove=""
echo "=== could not track the hidden controllers, leaving them as they are ===" >> "$log" 2>&1 || true
fi
+ hidraw_planned=0
+ if plan_disable_hidraw 2>/dev/null; then
+ hidraw_planned=1
+ if [ "$NOTPROTON_DISABLE_HIDRAW" = "1" ] && [ -n "$hidraw_value" ]; then
+ : > "$hidraw_file" 2>/dev/null || hidraw_value=""
+ fi
+ else
+ hidraw_value=""
+ echo "=== could not track DisableHidraw, leaving it as it is ===" >> "$log" 2>&1 || true
+ fi
settings_file=$(mktemp "$WINEPREFIX/drive_c/notproton-settings.XXXXXX" 2>/dev/null) \
|| settings_file=""
if [ -z "$settings_file" ] || ! { printf '%s\r\n' \
@@ -618,7 +650,8 @@ import_prefix_settings() {
'[HKEY_LOCAL_MACHINE\Software\Classes\steam]' '"URL Protocol"=""' '' \
'[HKEY_LOCAL_MACHINE\Software\Classes\steam\shell\open\command]' \
'@="\"C:\\Program Files (x86)\\Steam\\steam.exe\" \"%1\""' '' \
- && hidraw_lines add "$controllers_add" && hidraw_lines remove "$controllers_remove"; } \
+ && hidraw_lines add "$controllers_add" && hidraw_lines remove "$controllers_remove" \
+ && winebus_lines; } \
> "$settings_file" 2>/dev/null; then
[ -z "$settings_file" ] || rm -f "$settings_file"
echo "=== could not write the prefix settings, launching without them ===" >> "$log" 2>&1 || true
@@ -629,13 +662,19 @@ import_prefix_settings() {
without_lock_fds "$WINELOADER" reg import "C:\\${settings_file##*/}" >> "$log" 2>&1 \
&& import_status=0 || import_status=$?
rm -f "$settings_file"
+ if [ "$import_status" -eq 0 ] && [ "$hidraw_planned" -eq 1 ] && [ "$NOTPROTON_DISABLE_HIDRAW" != "1" ]; then
+ rm -f "$hidraw_file"
+ fi
+ if [ "$import_status" -eq 0 ] && [ -n "$controllers_add$controllers_remove$hidraw_value" ]; then
+ # Wine only reads these keys when it starts, so restart Wine to apply them.
+ without_lock_fds "$WINESERVER" -k >> "$log" 2>&1 || true
+ without_lock_fds "$WINESERVER" -w >> "$log" 2>&1 || true
+ fi
+ if [ "$import_status" -eq 0 ] && [ "$hidraw_planned" -eq 1 ] && [ "$NOTPROTON_DISABLE_HIDRAW" = "1" ]; then
+ echo "controllers: hidraw disabled (NOTPROTON_DISABLE_HIDRAW=1)" >> "$log" 2>&1 || true
+ fi
if [ "$import_status" -eq 0 ] && [ "$controllers_planned" -eq 1 ]; then
write_owned_controllers "$controllers_wanted" 2>/dev/null || true
- if [ -n "$controllers_add$controllers_remove" ]; then
- # Wine only reads these keys when it starts, so restart Wine to apply them.
- without_lock_fds "$WINESERVER" -k >> "$log" 2>&1 || true
- without_lock_fds "$WINESERVER" -w >> "$log" 2>&1 || true
- fi
if [ "$NOTPROTON_RAW_CONTROLLERS" = "1" ]; then
echo "controllers: games read them directly (NOTPROTON_RAW_CONTROLLERS=1)" >> "$log" 2>&1 || true
elif [ -n "$controllers_wanted" ]; then
diff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.c
index 4f40bed..020f14e 100644
--- a/dylib/feats/webpatch.c
+++ b/dylib/feats/webpatch.c
@@ -346,10 +346,12 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {
"children:(0," RT ".jsx)(" BARREL ".m,{rgOptions:U," \
"selectedOption:sw?(U.find(u=>u.data&&+u.data===fn)||{data:String(fn)}).data:\"\"," \
"onChange:v=>s([[\"DXMT_METALFX_SPATIAL_SWAPCHAIN\",v.data?\"1\":\"\"],[\"DXMT_CONFIG\",fx(v.data)]])})},\"usf\")," \
- "(0," RT ".jsx)(" BARREL ".XY,{label:npL(\"Controllers (May break Steam Input. Not recommended)\"," \
- "\"控制器(可能导致 Steam Input 失效,不推荐)\",\"Controller (pu\\u00f2 interferire con Steam Input, sconsigliato)\"),children:" \
- "T([\"NOTPROTON_RAW_CONTROLLERS\"],npL(\"Let games read controllers directly\"," \
- "\"允许游戏直接读取控制器\",\"Lascia che i giochi leggano direttamente i controller\"),\"1\",\"\")},\"ctl\")" \
+ "(0," RT ".jsxs)(" BARREL ".XY,{label:npL(\"Controllers\",\"控制器\",\"Controller\"),children:[" \
+ "T([\"NOTPROTON_RAW_CONTROLLERS\"],npL(\"Let games read controllers directly (May break Steam Input. Not recommended)\"," \
+ "\"允许游戏直接读取控制器(可能导致 Steam Input 失效,不推荐)\"," \
+ "\"Lascia che i giochi leggano direttamente i controller (pu\\u00f2 interferire con Steam Input, sconsigliato)\"),\"1\",\"\")," \
+ "T([\"NOTPROTON_DISABLE_HIDRAW\"],npL(\"Disable hidraw\",\"停用 hidraw\",\"Disable hidraw\"),\"1\",\"\")" \
+ "]},\"ctl\")" \
"]})})}"
#define NP_CX_OPTIONS_CAPTURE(RT, BARREL) \
diff --git a/dylib/tests/panel-behavior/behavior.js b/dylib/tests/panel-behavior/behavior.js
index a82053b..2ea6350 100644
--- a/dylib/tests/panel-behavior/behavior.js
+++ b/dylib/tests/panel-behavior/behavior.js
@@ -21,7 +21,7 @@ for (const form of Object.keys(FORMS)) {
'a shortcut renders the panel before a tool name reaches the page');
let r = nodes('');
- t.ok(toggles(r).length === 6 && sections(r).length === 3, 'automatic shows six toggles in three sections');
+ t.ok(toggles(r).length === 7 && sections(r).length === 3, 'automatic shows seven toggles in three sections');
t.ok(r.filter(x => x.type === 'Dropdown').length === 2, 'two dropdowns');
t.ok(!('label' in r.find(x => x.type === 'Dropdown').props), 'the backend dropdown carries no label column');
@@ -79,12 +79,13 @@ for (const form of Object.keys(FORMS)) {
const root = P({ details: details('') });
t.ok(root.props.className === 'MSCXPanel', 'the panel root carries its own class');
const classes = nodes('').filter(x => x.type === 'Toggle').map(x => x.props.className);
- t.ok(classes.length === 6 && classes.every(c => c === 'MSCXRow'), 'every checkbox carries the row class');
- const raw = o => nodes(o).find(x => x.props.label === 'Let games read controllers directly');
+ t.ok(classes.length === 7 && classes.every(c => c === 'MSCXRow'), 'every checkbox carries the row class');
+ const raw = o => nodes(o).find(x => x.props.label === 'Let games read controllers directly (May break Steam Input. Not recommended)');
t.ok(sections(nodes('')).includes('Controllers') && raw('').props.checked === false,
'controller hiding is on unless the game says otherwise');
- t.ok(nodes('').some(x => x.type === 'Section' && x.props.label === 'Controllers (May break Steam Input. Not recommended)'),
- 'the controller section warns what the row changes');
+ written.length = 0;
+ nodes('').find(x => x.props.label === 'Disable hidraw').props.onChange(true);
+ t.ok(last().trim() === 'NOTPROTON_DISABLE_HIDRAW=1 %command%', `hidraw (${last()})`);
written.length = 0;
raw('').props.onChange(true);
t.ok(last().trim() === 'NOTPROTON_RAW_CONTROLLERS=1 %command%', `the controller row writes its flag (${last()})`);
diff --git a/dylib/tests/panel-behavior/localization.js b/dylib/tests/panel-behavior/localization.js
index 8c8eafd..a9f5ff4 100644
--- a/dylib/tests/panel-behavior/localization.js
+++ b/dylib/tests/panel-behavior/localization.js
@@ -27,11 +27,12 @@ for (const form of Object.keys(FORMS)) {
assert.deepEqual(dropdowns[0].props.rgOptions.map(o => o.data),
['', 'd3dmetal', 'dxmt', 'dxvk', 'wined3d']);
assert(nodes.some(n => n.props.label === t('Graphics', '图形', 'Grafica')));
- assert(nodes.some(n => n.props.label === t('Controllers (May break Steam Input. Not recommended)',
- '控制器(可能导致 Steam Input 失效,不推荐)',
- 'Controller (può interferire con Steam Input, sconsigliato)')));
- const raw = nodes.find(n => n.props.label === t('Let games read controllers directly',
- '允许游戏直接读取控制器', 'Lascia che i giochi leggano direttamente i controller'));
+ assert(nodes.some(n => n.props.label === t('Controllers', '控制器', 'Controller')));
+ const raw = nodes.find(n => n.props.label === t(
+ 'Let games read controllers directly (May break Steam Input. Not recommended)',
+ '允许游戏直接读取控制器(可能导致 Steam Input 失效,不推荐)',
+ 'Lascia che i giochi leggano direttamente i controller (può interferire con Steam Input, sconsigliato)'));
+ assert(nodes.some(n => n.props.label === t('Disable hidraw', '停用 hidraw', 'Disable hidraw')));
raw.props.onChange(true);
assert.equal(written.at(-1).opts, 'NOTPROTON_RAW_CONTROLLERS=1 CX_GRAPHICS_BACKEND=dxmt %command%');
const hud = nodes.find(n => n.props.label === t('Metal HUD', 'Metal 性能监视器', 'Metal HUD'));
diff --git a/dylib/tests/panel-behavior/shell.js b/dylib/tests/panel-behavior/shell.js
index bf2ba36..50e3287 100644
--- a/dylib/tests/panel-behavior/shell.js
+++ b/dylib/tests/panel-behavior/shell.js
@@ -13,11 +13,12 @@ const TOGGLES = {
'MSync': 'WINEMSYNC',
'High Resolution': 'NOTPROTON_RETINA',
'Advertise AVX2 to Rosetta': 'ROSETTA_ADVERTISE_AVX',
- 'Let games read controllers directly': 'NOTPROTON_RAW_CONTROLLERS',
+ 'Let games read controllers directly (May break Steam Input. Not recommended)': 'NOTPROTON_RAW_CONTROLLERS',
+ 'Disable hidraw': 'NOTPROTON_DISABLE_HIDRAW',
};
const PANEL_KEYS = ['CX_GRAPHICS_BACKEND', 'MTL_HUD_ENABLED', 'D3DM_ENABLE_METALFX', 'DXMT_ENABLE_NVEXT',
'DXMT_METALFX_SPATIAL_SWAPCHAIN', 'DXMT_CONFIG', 'ROSETTA_ADVERTISE_AVX', 'WINEMSYNC', 'NOTPROTON_RETINA',
- 'NOTPROTON_RAW_CONTROLLERS'];
+ 'NOTPROTON_RAW_CONTROLLERS', 'NOTPROTON_DISABLE_HIDRAW'];
const OTHER_KEYS = ['WINEDEBUG', 'DXVK_HUD', 'FOO'];
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'np-shell-'));
diff --git a/dylib/tests/settingscheck.sh b/dylib/tests/settingscheck.sh
index 0a5c1c6..b9b1c14 100644
--- a/dylib/tests/settingscheck.sh
+++ b/dylib/tests/settingscheck.sh
@@ -9,7 +9,8 @@ body=$(sed -n '/^import_prefix_settings() {$/,/^}$/p' "$SRC")
wrapper=$(sed -n '/^without_lock_fds() {$/,/^}$/p' "$SRC")
[ -n "$wrapper" ] || { echo "FAIL: without_lock_fds not found in $SRC"; exit 1; }
helpers=""
-for helper in controller_ids ids_without hidraw_lines write_owned_controllers plan_hidden_controllers; do
+for helper in controller_ids ids_without hidraw_lines write_owned_controllers plan_hidden_controllers \
+ plan_disable_hidraw winebus_lines; do
part=$(sed -n "/^$helper() {\$/,/^}\$/p" "$SRC")
[ -n "$part" ] || { echo "FAIL: $helper not found in $SRC"; exit 1; }
helpers="$helpers
@@ -77,7 +78,7 @@ run_in() {
WINESERVER="$work/wineserver" STEAM_COMPAT_DATA_PATH="$case_dir" \
SDL_GAMECONTROLLER_IGNORE_DEVICES="${IGNORE-}" \
SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT="${EXCEPT-}" \
- NOTPROTON_RAW_CONTROLLERS="${RAW-}" verb="${VERB-waitforexitandrun}" \
+ NOTPROTON_RAW_CONTROLLERS="${RAW-}" NOTPROTON_DISABLE_HIDRAW="${HIDRAW-}" verb="${VERB-waitforexitandrun}" \
FAKE_STATUS="$2" FAKE_CALLS="$case_dir/calls" FAKE_IMPORTED="$case_dir/imported" \
log="$case_dir/log" body="$body" \
sh -ec 'eval "$body"; import_prefix_settings; echo returned' \
@@ -213,6 +214,23 @@ again "" 0
same_file "a linked tracking file writes no controller keys" "$work/retina-off" "$case_dir/imported"
is "a linked tracking file is logged" "=== could not track the hidden controllers, leaving them as they are ===" "$(cat "$case_dir/log")"
+echo "== Disable hidraw"
+winebus() { printf '%s\r\n' '[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\WineBus]' "$1" ''; }
+IGNORE='' EXCEPT='' RAW=''
+new_case
+in_registry 057e/2006 057e/2007 057e/2009
+printf '%s\n' 057e/2006 057e/2007 057e/2009 > "$case_dir/notproton-hidden-controllers"
+HIDRAW=1
+again "" 0
+{ cat "$work/retina-off"; winebus '"DisableHidraw"=dword:00000001'; } > "$work/expected"
+same_file "on" "$work/expected" "$case_dir/imported"
+printf '%s\n' '[System\\ControlSet001\\Services\\winebus] 1791230000' '"DisableHidraw"=dword:00000001' '' >> "$case_dir/pfx/system.reg"
+HIDRAW=''
+again "" 0
+{ cat "$work/retina-off"; winebus '"DisableHidraw"=-'; } > "$work/expected"
+same_file "off" "$work/expected" "$case_dir/imported"
+unset HIDRAW
+
if [ "$fails" -eq 0 ]; then
echo "==> settingscheck: all assertions hold"
else