Skip to content

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

Fixes Steam Input issues

NotProtonNot98d2929ab645
diff --git a/Makefile b/Makefile
index 062ad12..318a5e7 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ CFLAGS := -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) \
LDFLAGS := -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) \
-dynamiclib -install_name @rpath/notproton.dylib
-FRAMEWORKS := -framework CoreFoundation
+FRAMEWORKS := -framework CoreFoundation -framework CoreGraphics
DOBBY_DIR := build/dobby
DOBBY_LIBS := $(DOBBY_DIR)/libdobby.a \
@@ -41,6 +41,7 @@ SRCS := \
dylib/feats/webui.c \
dylib/feats/compatsvc.c \
dylib/feats/webpatch.c \
+ dylib/feats/input_access.c \
vendor/cJSON.c
OUT_DIR := out
diff --git a/app/Sources/NotProtonApp/Model/SteamBundle.swift b/app/Sources/NotProtonApp/Model/SteamBundle.swift
index 320cb6f..7d8fbc8 100644
--- a/app/Sources/NotProtonApp/Model/SteamBundle.swift
+++ b/app/Sources/NotProtonApp/Model/SteamBundle.swift
@@ -15,6 +15,8 @@ enum SteamDeployment: Sendable, Equatable {
enum SteamBundle {
static let insertKey = "DYLD_INSERT_LIBRARIES"
+ static let controllerBlockKey = "SDL_JOYSTICK_BLACKLIST_DEVICES"
+ static let controllerBlockValue = "0x05ac/0x0004"
static let plistBackupName = "Info.plist.before-notproton"
static let environmentKey = "LSEnvironment"
@@ -46,6 +48,10 @@ enum SteamBundle {
guard files.fileExists(atPath: deployedDylib) else { return .notInstalled }
+ guard currentControllerBlock(at: plist) == controllerBlockValue else {
+ return .outdated(deployed: deployedVersion(at: versionFile) ?? "", bundled: bundledVersion)
+ }
+
guard let deployed = deployedVersion(at: versionFile) else { return .installed(version: nil) }
if deployed == bundledVersion { return .installed(version: deployed) }
return .outdated(deployed: deployed, bundled: bundledVersion)
@@ -58,6 +64,13 @@ enum SteamBundle {
return environment[insertKey] as? String
}
+ static func currentControllerBlock(at url: URL = SupportPaths.Steam.infoPlist) -> String? {
+ guard let dict = readInfoPlist(at: url),
+ let environment = dict[environmentKey] as? [String: Any]
+ else { return nil }
+ return environment[controllerBlockKey] as? String
+ }
+
static func deployedVersion(at url: URL = SupportPaths.deployedVersion) -> String? {
guard let data = try? Data(contentsOf: url) else { return nil }
let text = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
diff --git a/app/Sources/NotProtonApp/Model/SteamInstaller.swift b/app/Sources/NotProtonApp/Model/SteamInstaller.swift
index f662683..69cfad7 100644
--- a/app/Sources/NotProtonApp/Model/SteamInstaller.swift
+++ b/app/Sources/NotProtonApp/Model/SteamInstaller.swift
@@ -73,6 +73,7 @@ enum SteamInstaller {
},
stopClient: ClientStopper = stopTheClient,
register: BundleRegistrar = { SteamBundle.register($0) },
+ resetInputAccess: () -> Void = resetInputAccess,
report: @escaping @Sendable (InstallPhase) -> Void = { _ in }
) throws -> InstallOutcome {
report(.checkingPayload)
@@ -155,6 +156,7 @@ enum SteamInstaller {
backedUp = try backUpPlist(plist, into: backups)
let priorPlist = try? Data(contentsOf: plist)
+ let priorHash = cdhash(of: app)
do {
try setInsert(at: plist, to: dylib)
@@ -166,6 +168,9 @@ enum SteamInstaller {
revertPlist(priorPlist, at: plist, app: app)
throw error
}
+ if cdhash(of: app) != priorHash {
+ resetInputAccess()
+ }
}
report(.registering)
@@ -245,6 +250,7 @@ enum SteamInstaller {
static func needsPatching(plist: URL, dylib: URL, shipping: URL, app: URL) throws -> Bool {
let deployed = SteamBundle.currentInsert(at: plist) == dylib.path(percentEncoded: false)
+ && SteamBundle.currentControllerBlock(at: plist) == SteamBundle.controllerBlockValue
let file = DeploymentContent.File(source: shipping, destination: dylib, name: "notproton.dylib", allowsResigning: true)
if deployed, try file.matches() {
AppLog.note("install: Steam already carries this dylib, installing for this account only")
@@ -327,6 +333,7 @@ enum SteamInstaller {
var environment = dict[SteamBundle.environmentKey] as? [String: Any] ?? [:]
environment[SteamBundle.insertKey] = dylib.path(percentEncoded: false)
+ environment[SteamBundle.controllerBlockKey] = SteamBundle.controllerBlockValue
dict[SteamBundle.environmentKey] = environment
try SteamBundle.writeInfoPlist(dict, at: plist)
}
@@ -343,4 +350,28 @@ enum SteamInstaller {
}
}
+ static func cdhash(of app: URL) -> String? {
+ guard let result = try? Shell.run("/usr/bin/codesign", ["-dvvv", app.path(percentEncoded: false)]) else { return nil }
+ return (result.stdout + result.stderr).split(separator: "\n")
+ .first { $0.hasPrefix("CDHash=") }
+ .map { String($0.dropFirst("CDHash=".count)) }
+ }
+
+ // macOS does not automatically clear a pre-existing input access approval, so it needs to be cleared
+ // or Steam Input will silently not work.
+ static let inputAccessServices = ["Accessibility", "PostEvent", "ListenEvent"]
+
+ static func resetInputAccess() {
+ for service in failedInputAccessResets() {
+ AppLog.note("install: could not reset \(service) for Steam")
+ }
+ }
+
+ static func failedInputAccessResets() -> [String] {
+ inputAccessServices.filter { service in
+ let result = try? Shell.run("/usr/bin/tccutil", ["reset", service, "com.valvesoftware.steam"])
+ return result?.succeeded != true
+ }
+ }
+
}
diff --git a/app/Sources/NotProtonApp/Model/SteamRepair.swift b/app/Sources/NotProtonApp/Model/SteamRepair.swift
index 663b481..a063db6 100644
--- a/app/Sources/NotProtonApp/Model/SteamRepair.swift
+++ b/app/Sources/NotProtonApp/Model/SteamRepair.swift
@@ -188,11 +188,12 @@ enum SteamRepair {
static func clearInsert(at plist: URL) throws -> Bool {
guard var dict = SteamBundle.readInfoPlist(at: plist),
- var environment = dict[SteamBundle.environmentKey] as? [String: Any],
- environment[SteamBundle.insertKey] != nil
+ var environment = dict[SteamBundle.environmentKey] as? [String: Any]
else { return false }
- environment.removeValue(forKey: SteamBundle.insertKey)
+ let removed = [SteamBundle.insertKey, SteamBundle.controllerBlockKey]
+ .compactMap { environment.removeValue(forKey: $0) }
+ guard !removed.isEmpty else { return false }
dict[SteamBundle.environmentKey] = environment
try SteamBundle.writeInfoPlist(dict, at: plist)
return true
diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swift
index 85ddfb7..31e8477 100644
--- a/app/Sources/NotProtonApp/SystemStatus.swift
+++ b/app/Sources/NotProtonApp/SystemStatus.swift
@@ -459,6 +459,21 @@ final class SystemStatus {
}
}
+ func resetControllerPermission() async {
+ await perform(from: "Resetting Steam's controller permission") { _ in
+ let failed = SteamInstaller.failedInputAccessResets()
+ guard failed.isEmpty else {
+ throw StepFailure(
+ step: "Reset controller permission",
+ detail: "macOS did not reset \(failed.joined(separator: ", ")) for Steam."
+ )
+ }
+ return SteamBundle.isRunning
+ ? "Controller permission reset. Restart Steam so macOS asks again."
+ : "Controller permission reset. macOS asks again when Steam starts."
+ }
+ }
+
func removeEverything() async {
await perform(from: UninstallPhase.stoppingClient.label) { progress in
let lock = try DeploymentContent.acquireInstallationLock(for: SupportPaths.Steam.app)
diff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swift
index 5d3888b..b00d18f 100644
--- a/app/Sources/NotProtonApp/Views/StatusView.swift
+++ b/app/Sources/NotProtonApp/Views/StatusView.swift
@@ -323,6 +323,14 @@ struct StatusView: View {
)
}
updateBlockRow(snapshot.updateBlocked)
+ StatusRow(
+ title: "Controller permission",
+ value: "Clear Steam's controller permission so macOS asks for it again.",
+ action: StatusAction(
+ label: "Reset",
+ isEnabled: status.isIdle
+ ) { Task { await status.resetControllerPermission() } }
+ )
}
Section {
diff --git a/app/Tests/NotProtonAppTests/SteamBundleTests.swift b/app/Tests/NotProtonAppTests/SteamBundleTests.swift
index 39a7828..ae4f95b 100644
--- a/app/Tests/NotProtonAppTests/SteamBundleTests.swift
+++ b/app/Tests/NotProtonAppTests/SteamBundleTests.swift
@@ -43,6 +43,7 @@ struct SteamBundleTests {
private enum Insert {
case absent
case own
+ case ownWithoutControllerBlock
case other(String)
}
@@ -68,6 +69,12 @@ struct SteamBundleTests {
case .absent:
break
case .own:
+ let own = SupportPaths.Steam.deployedDylib(inBundle: app)
+ plist[SteamBundle.environmentKey] = [
+ SteamBundle.insertKey: own.path(percentEncoded: false),
+ SteamBundle.controllerBlockKey: SteamBundle.controllerBlockValue,
+ ]
+ case .ownWithoutControllerBlock:
let own = SupportPaths.Steam.deployedDylib(inBundle: app)
plist[SteamBundle.environmentKey] = [
SteamBundle.insertKey: own.path(percentEncoded: false)
@@ -107,6 +114,14 @@ struct SteamBundleTests {
)
}
+ @Test("A bundle patched before the controller block reads as outdated")
+ func missingControllerBlock() throws {
+ #expect(
+ try deployment(insert: .ownWithoutControllerBlock, dylib: true, version: "0.2.0")
+ == .outdated(deployed: "0.2.0", bundled: "0.2.0")
+ )
+ }
+
@Test("Somebody else's insert is left alone")
func foreignInsert() throws {
#expect(
diff --git a/app/Tests/NotProtonAppTests/SteamInstallerTests.swift b/app/Tests/NotProtonAppTests/SteamInstallerTests.swift
index dc04e68..00e5604 100644
--- a/app/Tests/NotProtonAppTests/SteamInstallerTests.swift
+++ b/app/Tests/NotProtonAppTests/SteamInstallerTests.swift
@@ -83,6 +83,9 @@ struct SteamInstallerTests {
private var registered: [URL] = []
func register(_ url: URL) { lock.lock(); registered.append(url); lock.unlock() }
var registrations: [URL] { lock.lock(); defer { lock.unlock() }; return registered }
+ private var resets = 0
+ func resetInputAccess() { lock.lock(); resets += 1; lock.unlock() }
+ var inputAccessResets: Int { lock.lock(); defer { lock.unlock() }; return resets }
}
private func install(
@@ -110,7 +113,8 @@ struct SteamInstallerTests {
verifyRunner: verifyRunner,
patchRunner: { _, _, _ in },
stopClient: { _, onStopping in if stopped { onStopping() }; return stopped },
- register: { calls.register($0) }
+ register: { calls.register($0) },
+ resetInputAccess: { calls.resetInputAccess() }
)
if recordBuild {
try SteamInstaller.finish(outcome, deployedVersion: fixture.deployedVersion, isCurrent: { _ in true })
@@ -131,6 +135,7 @@ struct SteamInstallerTests {
#expect(outcome.signatureDatabases == 2)
#expect(outcome.backedUpPlist)
#expect(!outcome.stoppedClient)
+ #expect(calls.inputAccessResets == 1)
let files = FileManager.default
#expect(files.fileExists(atPath: fixture.deployedDylib.path(percentEncoded: false)))
@@ -170,7 +175,8 @@ struct SteamInstallerTests {
let after = try #require(SteamBundle.readInfoPlist(at: fixture.plist))
let environment = try #require(after[SteamBundle.environmentKey] as? [String: Any])
#expect(environment["LC_ALL"] as? String == "en_US.UTF-8", "LC_ALL is Valve's and has to survive")
- #expect(environment.count == 2, "only the insert should have been added")
+ #expect(environment[SteamBundle.controllerBlockKey] as? String == SteamBundle.controllerBlockValue)
+ #expect(environment.count == 3, "only the insert and the controller block should have been added")
#expect(after["CFBundleVersion"] as? String == "6.1", "the rest of the plist was disturbed")
}
@@ -379,9 +385,11 @@ struct SteamInstallerTests {
)
try files.removeItem(at: fixture.support)
- let outcome = try install(fixture, stopped: true)
+ let calls = Calls()
+ let outcome = try install(fixture, calls: calls, stopped: true)
#expect(!outcome.stoppedClient, "Steam was stopped for an install that changed nothing")
+ #expect(calls.inputAccessResets == 0)
#expect(!outcome.backedUpPlist)
#expect(outcome.signatureDatabases == 2)
diff --git a/app/Tests/NotProtonAppTests/SteamRepairTests.swift b/app/Tests/NotProtonAppTests/SteamRepairTests.swift
index dc17d29..4b8f73b 100644
--- a/app/Tests/NotProtonAppTests/SteamRepairTests.swift
+++ b/app/Tests/NotProtonAppTests/SteamRepairTests.swift
@@ -136,7 +136,7 @@ struct SteamRepairTests {
// MARK: - The inner plist
- @Test("Clearing the insert removes that key and nothing else")
+ @Test("Clearing the insert removes the keys NotProton added and nothing else")
func clearsOnlyTheInsert() throws {
let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
@@ -150,6 +150,7 @@ struct SteamRepairTests {
tampered[SteamBundle.environmentKey] = [
"LC_ALL": "en_US.UTF-8",
SteamBundle.insertKey: "/Applications/Steam.app/Contents/MacOS/notproton.dylib",
+ SteamBundle.controllerBlockKey: SteamBundle.controllerBlockValue,
]
try SteamBundle.writeInfoPlist(tampered, at: plist)
@@ -158,6 +159,7 @@ struct SteamRepairTests {
let after = try #require(SteamBundle.readInfoPlist(at: plist))
let environment = try #require(after[SteamBundle.environmentKey] as? [String: Any])
#expect(environment[SteamBundle.insertKey] == nil)
+ #expect(environment[SteamBundle.controllerBlockKey] == nil)
#expect(environment["LC_ALL"] as? String == "en_US.UTF-8", "LC_ALL is Valve's and has to survive")
#expect(environment.count == 1, "the environment dict is kept rather than emptied")
#expect(after["CFBundleVersion"] as? String == "6.1")
diff --git a/dylib/core/loader.c b/dylib/core/loader.c
index a89f467..9a9940b 100644
--- a/dylib/core/loader.c
+++ b/dylib/core/loader.c
@@ -7,6 +7,7 @@
#include "../core/macho.h"
#include "../hooks/hooks.h"
#include "../feats/compat.h"
+#include "../feats/input_access.h"
#include <stdio.h>
#include <stdlib.h>
@@ -155,6 +156,8 @@ static void *install_thread(void *unused) {
return NULL;
}
+ np_input_access_check();
+
uintptr_t text_base = 0;
size_t text_size = 0;
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index 7e1c931..4461529 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -368,15 +368,83 @@ lay_out_proton_profile() {
fi
}
+controller_ids() {
+ printf '%s\n' "$1" | tr ',' '\n' | tr 'A-F' 'a-f' \
+ | sed -n 's/^[[:space:]]*0x\([0-9a-f]\{4\}\)\/0x\([0-9a-f]\{4\}\)[[:space:]]*$/\1\/\2/p' \
+ | sort -u
+}
+
+ids_without() {
+ printf '%s\n' "$2" -- "$1" \
+ | awk '$0 == "--" { s = 1; next } !s { b[$0]; next } $0 != "" && !($0 in b)'
+}
+
+hidraw_lines() {
+ printf '%s\n' "$2" | while read -r id; do
+ [ -n "$id" ] || continue
+ if [ "$1" = add ]; then
+ printf '%s\r\n' "[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\WineBus\\Devices\\$id]" \
+ '"Hidraw"=dword:00000000' ''
+ else
+ printf '%s\r\n' "[-HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\WineBus\\Devices\\$id]" ''
+ fi
+ done
+}
+
+write_owned_controllers() {
+ if printf '%s\n' "$1" | sed '/^$/d' | sort -u > "$controllers_file.new" \
+ && mv -f "$controllers_file.new" "$controllers_file"; then
+ return 0
+ fi
+ rm -f "$controllers_file.new"
+ return 1
+}
+
+# Proton hides the controllers that Steam Input handles from the Wine process. CrossOver
+# still reads a few directly (DualSense, DualShock 4, Switch 1 Pro Controller and Joy-Cons),
+# so Hidraw=0 hides those too. The Switch controllers get Hidraw=0 even when Steam Input
+# is off, to avoid silently breaking controller support in most games.
+plan_hidden_controllers() {
+ controllers_file="$STEAM_COMPAT_DATA_PATH/notproton-hidden-controllers"
+ controllers_add=""
+ controllers_remove=""
+ controllers_wanted=""
+ [ -n "$STEAM_COMPAT_DATA_PATH" ] && [ ! -L "$controllers_file" ] || return 1
+ owned=""
+ [ ! -f "$controllers_file" ] || owned=$(sed -n '/^[0-9a-f]\{4\}\/[0-9a-f]\{4\}$/p' "$controllers_file")
+ in_registry=""
+ [ ! -f "$WINEPREFIX/system.reg" ] || in_registry=$(tr '[:upper:]' '[:lower:]' < "$WINEPREFIX/system.reg" \
+ | sed -n 's/^\[system\\\\controlset001\\\\services\\\\winebus\\\\devices\\\\\([0-9a-f]\{4\}\/[0-9a-f]\{4\}\)\].*/\1/p' \
+ | sort -u)
+ if [ "$NOTPROTON_RAW_CONTROLLERS" != "1" ]; then
+ controllers_wanted=$(ids_without "$(controller_ids "$SDL_GAMECONTROLLER_IGNORE_DEVICES")" \
+ "$(controller_ids "$SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT")")
+ controllers_wanted=$(printf '%s\n' "$controllers_wanted" 057e/2006 057e/2007 057e/2009 | sed '/^$/d' | sort -u)
+ controllers_wanted=$(ids_without "$controllers_wanted" "$(ids_without "$in_registry" "$owned")")
+ fi
+ controllers_add=$(ids_without "$controllers_wanted" "$in_registry")
+ controllers_remove=$(ids_without "$owned" "$controllers_wanted")
+ write_owned_controllers "$owned
+$controllers_wanted"
+}
+
import_prefix_settings() {
if [ "$NOTPROTON_RETINA" = "1" ]; then
retina_line='"RetinaMode"="y"'
else
retina_line='"RetinaMode"=-'
fi
+ controllers_planned=0
+ if plan_hidden_controllers 2>/dev/null; then
+ controllers_planned=1
+ else
+ controllers_add=""
+ controllers_remove=""
+ echo "=== could not track the hidden controllers, leaving them as they are ===" >> "$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' \
+ if [ -z "$settings_file" ] || ! { printf '%s\r\n' \
'Windows Registry Editor Version 5.00' '' \
'[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug]' '"Auto"="0"' '' \
'[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]' '"Auto"="0"' '' \
@@ -385,6 +453,7 @@ 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"; } \
> "$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
@@ -395,6 +464,20 @@ 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 ] && [ "$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
+ echo "controllers: $(printf '%s\n' "$controllers_wanted" | grep -c .) kept off hidraw" \
+ >> "$log" 2>&1 || true
+ fi
+ fi
[ "$import_status" -eq 0 ] \
|| echo "=== prefix settings import exited status=$import_status ===" >> "$log" 2>&1 || true
}
diff --git a/dylib/feats/input_access.c b/dylib/feats/input_access.c
new file mode 100644
index 0000000..27993ec
--- /dev/null
+++ b/dylib/feats/input_access.c
@@ -0,0 +1,14 @@
+#include "input_access.h"
+#include "../util/log.h"
+
+#include <CoreGraphics/CoreGraphics.h>
+
+// Steam needs this permission for Steam Input. Re-signing Steam silently breaks the existing approval.
+void np_input_access_check(void) {
+ if (CGPreflightPostEventAccess()) {
+ NP_LOG("input access: granted");
+ return;
+ }
+ NP_LOG("input access: missing, asking macOS");
+ CGRequestPostEventAccess();
+}
diff --git a/dylib/feats/input_access.h b/dylib/feats/input_access.h
new file mode 100644
index 0000000..f43ff07
--- /dev/null
+++ b/dylib/feats/input_access.h
@@ -0,0 +1,6 @@
+#ifndef NOTPROTON_FEATS_INPUT_ACCESS_H
+#define NOTPROTON_FEATS_INPUT_ACCESS_H
+
+void np_input_access_check(void);
+
+#endif
diff --git a/dylib/feats/webpatch.c b/dylib/feats/webpatch.c
index 1123ce6..1a1e786 100644
--- a/dylib/feats/webpatch.c
+++ b/dylib/feats/webpatch.c
@@ -199,7 +199,9 @@ static int out_expand(np_out_t *o, const char *replace, const np_cap_t *caps) {
"{label:\"MetalFX Upscaling (Samples from the resolution the game is set to)\"," \
"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\")" \
+ "onChange:v=>s([[\"DXMT_METALFX_SPATIAL_SWAPCHAIN\",v.data?\"1\":\"\"],[\"DXMT_CONFIG\",fx(v.data)]])})},\"usf\")," \
+ "(0," RT ".jsx)(" BARREL ".XY,{label:\"Controllers (May break Steam Input. Not recommended)\",children:" \
+ "T([\"NOTPROTON_RAW_CONTROLLERS\"],\"Let games read controllers directly\",\"1\",\"\")},\"ctl\")" \
"]})})}"
#define NP_CX_OPTIONS_COMPONENT \
diff --git a/dylib/hooks/hook_spawn.c b/dylib/hooks/hook_spawn.c
index a8d486b..3ae86fb 100644
--- a/dylib/hooks/hook_spawn.c
+++ b/dylib/hooks/hook_spawn.c
@@ -1,4 +1,4 @@
-// Strips DYLD_INSERT_LIBRARIES from child processes
+// Strips DYLD_INSERT_LIBRARIES and the SDL block list from child processes
#include "hooks.h"
#include "../util/log.h"
@@ -20,8 +20,20 @@ static fn_execve orig_execve;
static fn_posix_spawn orig_posix_spawn;
static fn_posix_spawn orig_posix_spawnp;
-#define NP_INSERT_KEY "DYLD_INSERT_LIBRARIES="
-#define NP_INSERT_KEY_LEN (sizeof(NP_INSERT_KEY) - 1)
+// The SDL block list stops Steam from seeing a second, generic copy of the Steam Controller.
+// This solves double input issues.
+static const char *const np_steam_only_keys[] = {
+ "DYLD_INSERT_LIBRARIES=",
+ "SDL_JOYSTICK_BLACKLIST_DEVICES=",
+};
+
+static int np_is_steam_only(const char *entry) {
+ for (size_t k = 0; k < sizeof(np_steam_only_keys) / sizeof(np_steam_only_keys[0]); k++) {
+ if (strncmp(entry, np_steam_only_keys[k], strlen(np_steam_only_keys[k])) == 0)
+ return 1;
+ }
+ return 0;
+}
// steam_osx re-execs itself and needs the insert for hooks. Steam Helper runs
// CEF and needs it for the webpatch fopen interpose, strips elsewhere
@@ -41,7 +53,7 @@ static char **np_without_insert(char *const envp[]) {
int count = 0;
int found = 0;
for (int i = 0; envp[i]; i++) {
- if (strncmp(envp[i], NP_INSERT_KEY, NP_INSERT_KEY_LEN) == 0)
+ if (np_is_steam_only(envp[i]))
found = 1;
count++;
}
@@ -56,7 +68,7 @@ static char **np_without_insert(char *const envp[]) {
int j = 0;
for (int i = 0; envp[i]; i++) {
- if (strncmp(envp[i], NP_INSERT_KEY, NP_INSERT_KEY_LEN) != 0)
+ if (!np_is_steam_only(envp[i]))
clean[j++] = envp[i];
}
clean[j] = NULL;
diff --git a/dylib/tests/panel-behavior/behavior.js b/dylib/tests/panel-behavior/behavior.js
index b89ac89..c71d229 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 === 5 && sections(r).length === 2, 'automatic shows five toggles in two sections');
+ t.ok(toggles(r).length === 6 && sections(r).length === 3, 'automatic shows six 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,7 +79,19 @@ 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 === 5 && classes.every(c => c === 'MSCXRow'), 'every checkbox carries the row class');
+ 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(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;
+ raw('').props.onChange(true);
+ t.ok(last().trim() === 'NOTPROTON_RAW_CONTROLLERS=1 %command%', `the controller row writes its flag (${last()})`);
+ t.ok(raw('NOTPROTON_RAW_CONTROLLERS=1').props.checked === true, 'the controller row reads its flag');
+ written.length = 0;
+ raw('NOTPROTON_RAW_CONTROLLERS=1 WINEMSYNC=1').props.onChange(false);
+ t.ok(last().trim() === 'WINEMSYNC=1 %command%', `turning the controller row off removes its flag (${last()})`);
const css = nodes('').filter(x => x.type === 'style');
t.ok(css.length === 1 && css[0].props.children.includes('.MSCXPanel .MSCXRow{'),
'the panel carries one stylesheet defining the row rule');
diff --git a/dylib/tests/panel-behavior/shell.js b/dylib/tests/panel-behavior/shell.js
index 5100dac..bf2ba36 100644
--- a/dylib/tests/panel-behavior/shell.js
+++ b/dylib/tests/panel-behavior/shell.js
@@ -13,9 +13,11 @@ const TOGGLES = {
'MSync': 'WINEMSYNC',
'High Resolution': 'NOTPROTON_RETINA',
'Advertise AVX2 to Rosetta': 'ROSETTA_ADVERTISE_AVX',
+ 'Let games read controllers directly': 'NOTPROTON_RAW_CONTROLLERS',
};
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'];
+ 'DXMT_METALFX_SPATIAL_SWAPCHAIN', 'DXMT_CONFIG', 'ROSETTA_ADVERTISE_AVX', 'WINEMSYNC', 'NOTPROTON_RETINA',
+ 'NOTPROTON_RAW_CONTROLLERS'];
const OTHER_KEYS = ['WINEDEBUG', 'DXVK_HUD', 'FOO'];
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'np-shell-'));
@@ -100,6 +102,8 @@ const ACTIONS = [
want: (v0, v1) => v1.toggles.MTL_HUD_ENABLED.props.checked === !v0.toggles.MTL_HUD_ENABLED.props.checked },
{ name: 'MSync', run: v => v.toggles.WINEMSYNC.props.onChange(!v.toggles.WINEMSYNC.props.checked),
want: (v0, v1) => v1.toggles.WINEMSYNC.props.checked === !v0.toggles.WINEMSYNC.props.checked },
+ { name: 'raw controllers', run: v => v.toggles.NOTPROTON_RAW_CONTROLLERS.props.onChange(!v.toggles.NOTPROTON_RAW_CONTROLLERS.props.checked),
+ want: (v0, v1) => v1.toggles.NOTPROTON_RAW_CONTROLLERS.props.checked === !v0.toggles.NOTPROTON_RAW_CONTROLLERS.props.checked },
{ name: 'backend dxvk', run: v => v.backend.props.onChange({ data: 'dxvk' }),
want: (v0, v1) => v1.backend.props.selectedOption === 'dxvk' },
{ name: 'backend automatic', run: v => v.backend.props.onChange({ data: '' }),
diff --git a/dylib/tests/settingscheck.sh b/dylib/tests/settingscheck.sh
index 4c81680..1a0c433 100644
--- a/dylib/tests/settingscheck.sh
+++ b/dylib/tests/settingscheck.sh
@@ -8,7 +8,15 @@ body=$(sed -n '/^import_prefix_settings() {$/,/^}$/p' "$SRC")
[ -n "$body" ] || { echo "FAIL: import_prefix_settings not found in $SRC"; exit 1; }
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
+ part=$(sed -n "/^$helper() {\$/,/^}\$/p" "$SRC")
+ [ -n "$part" ] || { echo "FAIL: $helper not found in $SRC"; exit 1; }
+ helpers="$helpers
+$part"
+done
body="$wrapper
+$helpers
$body"
work=$(mktemp -d)
@@ -23,6 +31,8 @@ fi
exit "${FAKE_STATUS:-0}"
EOF
chmod +x "$work/wine"
+printf '#!/bin/sh\nprintf "wineserver %%s\\n" "$*" >> "$FAKE_CALLS"\n' > "$work/wineserver"
+chmod +x "$work/wineserver"
settings() {
printf '%s\r\n' 'Windows Registry Editor Version 5.00' '' \
@@ -44,13 +54,30 @@ is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }
same_file() { if cmp -s "$2" "$3"; then ok "$1"; else bad "$1" "contents of ${2##*/}" "$(cat -v "$3" 2>/dev/null)"; fi; }
case_dir=""
-launch() {
+new_case() {
case_dir=$(mktemp -d "$work/case.XXXXXX")
mkdir -p "$case_dir/pfx/drive_c"
: > "$case_dir/calls"
: > "$case_dir/log"
+}
+in_registry() {
+ for id in "$@"; do
+ printf '%s\n' "[System\\\\ControlSet001\\\\Services\\\\winebus\\\\Devices\\\\$id] 1791230000" '"Hidraw"=dword:00000000' ''
+ done > "$case_dir/pfx/system.reg"
+}
+launch() {
+ new_case
+ in_registry 057e/2006 057e/2007 057e/2009
+ printf '%s\n' 057e/2006 057e/2007 057e/2009 > "$case_dir/notproton-hidden-controllers"
[ "$3" != unwritable ] || chmod 500 "$case_dir/pfx/drive_c"
+ run_in "$1" "$2"
+}
+run_in() {
env WINEPREFIX="$case_dir/pfx" WINELOADER="$work/wine" NOTPROTON_RETINA="$1" \
+ WINESERVER="$work/wineserver" STEAM_COMPAT_DATA_PATH="$case_dir" \
+ SDL_GAMECONTROLLER_IGNORE_DEVICES="${IGNORE-}" \
+ SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT="${EXCEPT-}" \
+ NOTPROTON_RAW_CONTROLLERS="${RAW-}" \
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' \
@@ -65,7 +92,7 @@ launch "" 0
is "Retina unset runs a single import and nothing else" 'reg import C:\notproton-settings.X' "$(calls)"
same_file "Retina unset deletes RetinaMode" "$work/retina-off" "$case_dir/imported"
is "the file is gone after the import" 0 "$(leftovers)"
-is "a clean import logs nothing" "" "$(cat "$case_dir/log")"
+is "a clean import only logs the controller count" "controllers: 3 kept off hidraw" "$(cat "$case_dir/log")"
is "the launch carries on" returned "$(cat "$case_dir/out")"
launch 1 0
@@ -85,6 +112,86 @@ is "an unwritable C: drive falls back to wineboot, which builds the prefix" "win
is "an unwritable C: drive is logged" "=== could not write the prefix settings, launching without them ===" "$(cat "$case_dir/log")"
is "an unwritable C: drive does not end the launch" returned "$(cat "$case_dir/out")"
+echo "== controllers on Steam's ignore list"
+again() { : > "$case_dir/calls"; : > "$case_dir/log"; rm -f "$case_dir/imported"; run_in "$1" "$2"; }
+hidden() { printf '%s\r\n' "[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\WineBus\\Devices\\$1]" '"Hidraw"=dword:00000000' ''; }
+shown() { printf '%s\r\n' "[-HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\WineBus\\Devices\\$1]" ''; }
+owned() { tr '\n' ' ' < "$case_dir/notproton-hidden-controllers" | sed 's/ $//'; }
+
+new_case
+IGNORE='' EXCEPT='' RAW=''
+again "" 0
+{ cat "$work/retina-off"; hidden 057e/2006; hidden 057e/2007; hidden 057e/2009; } > "$work/expected"
+same_file "the Switch pads get Hidraw=0 with nothing on the list" "$work/expected" "$case_dir/imported"
+
+new_case
+IGNORE='0x054C/0x0CE6,0x054c/0x09cc,0x057e/0x2009,0x54c/0x5c4,junk,' EXCEPT='' RAW=''
+again "" 0
+{ cat "$work/retina-off"; hidden 054c/09cc; hidden 054c/0ce6; hidden 057e/2006; hidden 057e/2007; hidden 057e/2009; } > "$work/expected"
+same_file "each listed controller gets Hidraw=0 in the same import" "$work/expected" "$case_dir/imported"
+is "new keys restart the prefix so winebus reads them" "reg import C:\\notproton-settings.X
+wineserver -k
+wineserver -w" "$(calls)"
+is "malformed entries are skipped and the rest are tracked" "054c/09cc 054c/0ce6 057e/2006 057e/2007 057e/2009" "$(owned)"
+is "the count is logged" "controllers: 5 kept off hidraw" "$(cat "$case_dir/log")"
+
+in_registry 054c/09cc 054c/0ce6 057e/2006 057e/2007 057e/2009
+IGNORE='0x054c/0x0ce6' EXCEPT='' RAW=''
+again "" 0
+{ cat "$work/retina-off"; shown 054c/09cc; } > "$work/expected"
+same_file "a controller that leaves the list loses the key and nothing is rewritten" "$work/expected" "$case_dir/imported"
+is "the listed controller and the Nintendo pads stay tracked" "054c/0ce6 057e/2006 057e/2007 057e/2009" "$(owned)"
+is "a removed key restarts the prefix too" "wineserver -w" "$(calls | tail -1)"
+in_registry 054c/0ce6 057e/2006 057e/2007 057e/2009
+IGNORE='0x054c/0x0ce6' EXCEPT='' RAW=''
+again "" 0
+is "an unchanged list does not restart the prefix" "reg import C:\\notproton-settings.X" "$(calls)"
+
+in_registry 054c/0ce6 057e/2006 057e/2007 057e/2009
+IGNORE='0x054c/0x0ce6' EXCEPT='' RAW='1'
+again "" 0
+{ cat "$work/retina-off"; shown 054c/0ce6; shown 057e/2006; shown 057e/2007; shown 057e/2009; } > "$work/expected"
+same_file "NOTPROTON_RAW_CONTROLLERS=1 removes every key NotProton wrote" "$work/expected" "$case_dir/imported"
+is "NOTPROTON_RAW_CONTROLLERS=1 tracks nothing" "" "$(owned)"
+is "NOTPROTON_RAW_CONTROLLERS=1 is logged" "controllers: games read them directly (NOTPROTON_RAW_CONTROLLERS=1)" "$(cat "$case_dir/log")"
+
+new_case
+in_registry 28de/1304 057e/2009
+IGNORE='0x28de/0x1304,0x054c/0x0ce6' EXCEPT='' RAW=''
+again "" 0
+{ cat "$work/retina-off"; hidden 054c/0ce6; hidden 057e/2006; hidden 057e/2007; } > "$work/expected"
+same_file "a key the user wrote is left alone" "$work/expected" "$case_dir/imported"
+is "a key the user wrote is not tracked" "054c/0ce6 057e/2006 057e/2007" "$(owned)"
+in_registry 28de/1304 054c/0ce6 057e/2006 057e/2007 057e/2009
+IGNORE='0x28de/0x1304,0x054c/0x0ce6' EXCEPT='' RAW='1'
+again "" 0
+{ cat "$work/retina-off"; shown 054c/0ce6; shown 057e/2006; shown 057e/2007; } > "$work/expected"
+same_file "NOTPROTON_RAW_CONTROLLERS=1 keeps a key the user wrote" "$work/expected" "$case_dir/imported"
+
+new_case
+IGNORE='0x054c/0x09cc,0x054c/0x0ce6,0x057e/0x2009' EXCEPT='0x054C/0x0CE6,0x057e/0x2009' RAW=''
+again "" 0
+{ cat "$work/retina-off"; hidden 054c/09cc; hidden 057e/2006; hidden 057e/2007; hidden 057e/2009; } > "$work/expected"
+same_file "a controller on the exception list keeps hidraw" "$work/expected" "$case_dir/imported"
+is "a Nintendo pad on the exception list still gets Hidraw=0" "054c/09cc 057e/2006 057e/2007 057e/2009" "$(owned)"
+
+IGNORE='0x054c/0x0ce6' EXCEPT='' RAW=''
+launch "" 1
+is "a failed import still tracks what it may have written" "054c/0ce6 057e/2006 057e/2007 057e/2009" "$(owned)"
+in_registry 054c/0ce6 057e/2006 057e/2007 057e/2009
+IGNORE='' EXCEPT='' RAW=''
+again "" 0
+{ cat "$work/retina-off"; shown 054c/0ce6; } > "$work/expected"
+same_file "so the next launch can remove it once it leaves the list" "$work/expected" "$case_dir/imported"
+
+in_registry
+rm -f "$case_dir/notproton-hidden-controllers"
+ln -s /dev/null "$case_dir/notproton-hidden-controllers"
+IGNORE='0x054c/0x0ce6' EXCEPT='' RAW=''
+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")"
+
if [ "$fails" -eq 0 ]; then
echo "==> settingscheck: all assertions hold"
else
diff --git a/dylib/tests/spawn-env.c b/dylib/tests/spawn-env.c
index 873135c..3a8f1b4 100644
--- a/dylib/tests/spawn-env.c
+++ b/dylib/tests/spawn-env.c
@@ -108,6 +108,19 @@ int main(void) {
const char *once[] = { "PATH=/bin", NULL };
survives(twice, once, "every copy of the insert is taken out");
+ char *blocked[] = { (char *)"PATH=/bin",
+ (char *)"SDL_JOYSTICK_BLACKLIST_DEVICES=0x05ac/0x0004",
+ (char *)"DYLD_INSERT_LIBRARIES=/x.dylib", NULL };
+ survives(blocked, once, "the SDL block list goes with the insert");
+
+ char *alone[] = { (char *)"SDL_JOYSTICK_BLACKLIST_DEVICES=0x05ac/0x0004",
+ (char *)"PATH=/bin", NULL };
+ survives(alone, once, "the SDL block list goes without the insert");
+
+ char *sdl[] = { (char *)"SDL_JOYSTICK_BLACKLIST_DEVICES_EXCLUDED=0x05ac/0x0004",
+ (char *)"SDL_GAMECONTROLLER_IGNORE_DEVICES=0x045e/0x028e", NULL };
+ survives(sdl, NULL, "other SDL lists stay");
+
if (failures) {
printf("==> spawn env: %d check(s) failed\n", failures);
return 1;