Skip to content

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

fix(steam-input): forward Wine virtual gamepad rumble to native Steam

sn0wst0rme1e109be9c2d
diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml
index 1a5f791..e4bff03 100644
--- a/.github/workflows/app.yml
+++ b/.github/workflows/app.yml
@@ -136,6 +136,7 @@ jobs:
run: |
make game-host-check
make dualsense-check
+ make steam-rumble-check
- name: Package the app bundle
run: |
diff --git a/Makefile b/Makefile
index 12ed296..27182cb 100644
--- a/Makefile
+++ b/Makefile
@@ -529,7 +529,34 @@ dualsense-check: dualsense
DSB_TEST_BUILD=$(DUALSENSE_OUT) python3 $(DUALSENSE_SRC)/test-lifecycle.py
DSB_TEST_BUILD=$(DUALSENSE_OUT) python3 $(DUALSENSE_SRC)/test-trigger-routing.py
-helpers-install: $(ICONMAKER) $(APPINFO) $(GAME_HOST) $(GAME_METADATA) $(DUALSENSE_RUNTIME)
+STEAM_RUMBLE_SRC := controllers/steam-input
+STEAM_RUMBLE_OUT := $(OUT_DIR)/controllers/steam-input
+STEAM_RUMBLE := $(STEAM_RUMBLE_OUT)/rumble.dylib
+STEAM_SDK := build/lsteamclient/steamworks_sdk_162
+STEAM_RUMBLE_FLAGS := -arch arm64 -arch x86_64 -mmacosx-version-min=$(MIN_VER) -std=c++17 -Wall -Wextra -I$(STEAM_SDK)
+
+$(STEAM_SDK)/steam_api.h: lsteamclient/fetch.sh
+ sh lsteamclient/fetch.sh
+ @touch $@
+
+$(STEAM_RUMBLE): $(STEAM_RUMBLE_SRC)/rumble.cpp $(STEAM_RUMBLE_SRC)/VirtualGamepad.h $(STEAM_RUMBLE_SRC)/SteamSession.h $(STEAM_SDK)/steam_api.h
+ @mkdir -p $(STEAM_RUMBLE_OUT)
+ clang++ -dynamiclib $(STEAM_RUMBLE_FLAGS) -O2 $< -framework CoreFoundation -framework IOKit -o $@
+ codesign -f -s - --identifier com.notproton.steam-input.rumble $@
+
+.PHONY: steam-rumble steam-rumble-check
+steam-rumble: $(STEAM_RUMBLE)
+
+steam-rumble-check: $(STEAM_RUMBLE)
+ clang++ -dynamiclib $(STEAM_RUMBLE_FLAGS) -O1 -Wno-unused-parameter $(STEAM_RUMBLE_SRC)/tests/mock-steam.cpp -o $(STEAM_RUMBLE_OUT)/steamclient.dylib
+ clang++ $(STEAM_RUMBLE_FLAGS) -g -O1 $(STEAM_RUMBLE_SRC)/tests/routing.cpp -framework CoreFoundation -framework IOKit -o $(STEAM_RUMBLE_OUT)/test-routing
+ $(STEAM_RUMBLE_OUT)/test-routing "$(CURDIR)/$(STEAM_RUMBLE_OUT)"
+ clang++ $(STEAM_RUMBLE_FLAGS) -g -O1 $(STEAM_RUMBLE_SRC)/tests/hooks.cpp -framework CoreFoundation -framework IOKit -o $(STEAM_RUMBLE_OUT)/test-hooks
+ $(STEAM_RUMBLE_OUT)/test-hooks
+ python3 $(STEAM_RUMBLE_SRC)/tests/launcher.py
+
+helpers-install: $(ICONMAKER) $(APPINFO) $(GAME_HOST) $(GAME_METADATA) $(DUALSENSE_RUNTIME) $(STEAM_RUMBLE)
+ $(call install_atomically,$(STEAM_RUMBLE),$(SUPPORT_DIR)/controllers/steam-input/rumble.dylib)
$(call install_atomically,$(DUALSENSE_OUT)/launch,$(SUPPORT_DIR)/controllers/dualsense/launch)
$(call install_atomically,$(DUALSENSE_OUT)/broker,$(SUPPORT_DIR)/controllers/dualsense/broker)
$(call install_atomically,$(DUALSENSE_OUT)/bridge.dylib,$(SUPPORT_DIR)/controllers/dualsense/bridge.dylib)
@@ -608,8 +635,10 @@ bridge:
fonts:
fonts/build.sh
-app-payload: $(TARGET) $(OVERLAY_SHIM) $(ICONMAKER) $(APPINFO) $(GAME_HOST) $(GAME_METADATA) $(DUALSENSE_RUNTIME)
+app-payload: $(TARGET) $(OVERLAY_SHIM) $(ICONMAKER) $(APPINFO) $(GAME_HOST) $(GAME_METADATA) $(DUALSENSE_RUNTIME) $(STEAM_RUMBLE)
@mkdir -p "$(APP_PAYLOAD)/signatures/macos.arm64"
+ @mkdir -p "$(APP_PAYLOAD)/controllers/steam-input"
+ cp -f $(STEAM_RUMBLE) "$(APP_PAYLOAD)/controllers/steam-input/"
@mkdir -p "$(APP_PAYLOAD)/controllers/dualsense"
cp -f $(DUALSENSE_RUNTIME) "$(APP_PAYLOAD)/controllers/dualsense/"
cp -f $(GAME_HOST) $(GAME_METADATA) "$(APP_PAYLOAD)/"
diff --git a/app/Sources/NotProtonApp/Model/InstallPayload.swift b/app/Sources/NotProtonApp/Model/InstallPayload.swift
index 715a614..8c3cc2c 100644
--- a/app/Sources/NotProtonApp/Model/InstallPayload.swift
+++ b/app/Sources/NotProtonApp/Model/InstallPayload.swift
@@ -7,6 +7,7 @@ enum InstallPayload {
static let runtimeFiles = [
"prepare-game-loader", "game-host.dylib",
+ "controllers/steam-input/rumble.dylib",
"controllers/dualsense/launch", "controllers/dualsense/broker", "controllers/dualsense/bridge.dylib",
]
diff --git a/controllers/steam-input/README.md b/controllers/steam-input/README.md
new file mode 100644
index 0000000..ed945cf
--- /dev/null
+++ b/controllers/steam-input/README.md
@@ -0,0 +1,55 @@
+# Steam Input rumble in Wine
+
+This adapter forwards the two motor values from Winebus's
+`SDL_JoystickRumble` to the native Steam `SteamController008` interface.
+It fixes the missing rumble backend for Steam's macOS virtual Xbox gamepad.
+Games using the Steam Controller/Input API directly use their existing route.
+
+The adapter is a universal Mach-O library injected into NotProton's Wine
+processes. It intercepts Wine's dynamic SDL2 symbol lookup for symbols from
+the selected CrossOver runtime.
+
+A device qualifies only when its SDL GUID matches an IOKit device with
+`Transport=Virtual`, `Manufacturer=Microsoft`, and `Product=GamePad-N`.
+Both Darwin and HIDAPI SDL GUID signatures are supported. The corresponding
+Steam gamepad index supplies the controller handle. Unknown devices use
+original SDL.
+
+One worker owns the native Steam API and forwards the latest motor values.
+It handles effect expiry, explicit stops and device close. While an effect is
+active, controller assignments are checked every 20 ms. A missing assignment
+is retried until the effect expires; a changed assignment stops the previous
+controller before forwarding to its replacement. A re-created SDL device
+starts with an empty mailbox. Each slot retains the latest command, and Steam
+handles output to the physical controller.
+
+`rumble.cpp` owns SDL interception and the command mailbox. `VirtualGamepad.h`
+validates the virtual device identity; `SteamSession.h` owns the native Steam
+connection and releases partially initialized sessions on failure.
+
+## Build and use
+
+`make steam-rumble` builds the library; `make steam-rumble-check` tests routing,
+SDL hook selection, virtual-device detection, reconnection, player indices,
+amplitude preservation, expiry, reassignment, explicit stop, close, shutdown
+and launch gating without controller output. The Steam mock implements the
+SDK interfaces and rejects unexpected calls, including LED changes. Steamworks
+headers are obtained through the project's pinned `lsteamclient/fetch.sh`.
+
+The regular app payload includes `controllers/steam-input/rumble.dylib` and
+installs/removes it with the other NotProton runtime components. The run script
+enables it for game sessions with direct controller access disabled. To opt
+out for a game, set `NOTPROTON_STEAM_RUMBLE=0 %command%` in Steam launch options.
+`NOTPROTON_RAW_CONTROLLERS=1` also bypasses it, preserving direct DualSense PCM.
+A missing adapter leaves the previous launch behavior intact.
+
+## Validation and limits
+
+Verified with CrossOver 26.3 / SDL 2.30.12 (Rosetta), native Steam Input,
+INVERSUS Deluxe and a Bluetooth DualSense. The adapter logs the mapped
+virtual slot and the first nonzero rumble forwarded from XInputSetState.
+
+The binary includes arm64 for the FEX runtime, but gameplay under FEX and
+multiple simultaneous physical controllers still need hardware validation.
+See the [direct-controller bridge](../../docs/dualsense-bluetooth.md) for
+LED and PCM transport.
diff --git a/controllers/steam-input/SteamSession.h b/controllers/steam-input/SteamSession.h
new file mode 100644
index 0000000..023eafa
--- /dev/null
+++ b/controllers/steam-input/SteamSession.h
@@ -0,0 +1,75 @@
+#pragma once
+#include <dlfcn.h>
+#include <cstdio>
+#include <cstdlib>
+#include <unistd.h>
+#include "steam_api.h"
+
+// Owned by the rumble worker; no Steam calls run on the SDL input thread.
+struct SteamSession {
+ SteamSession() = default;
+ SteamSession(const SteamSession &) = delete;
+ SteamSession &operator=(const SteamSession &) = delete;
+ ~SteamSession() {
+ close();
+ }
+
+ void *library = nullptr;
+ ISteamClient *client = nullptr;
+ ISteamController *controller = nullptr;
+ HSteamPipe pipe = 0;
+ HSteamUser user = 0;
+ bool open() {
+ if (controller) {
+ return true;
+ }
+ const char *path = getenv("STEAM_COMPAT_CLIENT_INSTALL_PATH");
+ if (!path || !*path) {
+ return false;
+ }
+ char file[4096];
+ if (snprintf(file, sizeof(file), "%s/steamclient.dylib", path) >= (int)sizeof(file)) {
+ return false;
+ }
+ if (!library) {
+ library = dlopen(file, RTLD_NOW | RTLD_LOCAL);
+ }
+ if (!library) {
+ return false;
+ }
+ auto factory = (void *(*)(const char *, int *))dlsym(library, "CreateInterface");
+ if (!factory) {
+ return false;
+ }
+ client = (ISteamClient *)factory(STEAMCLIENT_INTERFACE_VERSION, nullptr);
+ if (!client || !(pipe = client->CreateSteamPipe()) ||
+ !(user = client->ConnectToGlobalUser(pipe))) {
+ close();
+ return false;
+ }
+ controller = client->GetISteamController(user, pipe, STEAMCONTROLLER_INTERFACE_VERSION);
+ if (!controller || !controller->Init()) {
+ controller = nullptr;
+ close();
+ return false;
+ }
+ fprintf(stderr, "notproton-rumble: native Steam controller API ready (pid %d)\n", getpid());
+ return true;
+ }
+ void close() {
+ if (controller) {
+ controller->Shutdown();
+ }
+ if (client && user) {
+ client->ReleaseUser(pipe, user);
+ }
+ if (client && pipe) {
+ client->BReleaseSteamPipe(pipe);
+ }
+ // Steam owns background threads. Keep its image mapped until process exit.
+ controller = nullptr;
+ client = nullptr;
+ user = 0;
+ pipe = 0;
+ }
+};
diff --git a/controllers/steam-input/VirtualGamepad.h b/controllers/steam-input/VirtualGamepad.h
new file mode 100644
index 0000000..69c3f7e
--- /dev/null
+++ b/controllers/steam-input/VirtualGamepad.h
@@ -0,0 +1,49 @@
+#pragma once
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+// Steam exposes at most sixteen emulated gamepad indices.
+constexpr int kGamepadCount = 16;
+
+struct JoystickGUID {
+ uint8_t data[16];
+};
+
+// SDL2's public GUID format uses a CRC-16/IBM of the original HID name.
+// Check the complete GUID, not just the Xbox VID/PID shared by real devices.
+static JoystickGUID virtualGamepadGUID(unsigned slot, uint16_t version) {
+ char name[64];
+ snprintf(name, sizeof(name), "Microsoft GamePad-%u", slot + 1);
+ uint16_t crc = 0;
+ for (const unsigned char *p = (const unsigned char *)name; *p; ++p) {
+ crc ^= *p;
+ for (int bit = 0; bit < 8; ++bit) {
+ crc = (crc >> 1) ^ ((crc & 1) ? 0xa001 : 0);
+ }
+ }
+ return {{3, 0, (uint8_t)crc, (uint8_t)(crc >> 8), 0x5e, 4, 0, 0, 0x8e, 2, 0, 0,
+ (uint8_t)version, (uint8_t)(version >> 8), 0, 0}};
+}
+
+static int virtualGamepadSlot(JoystickGUID guid, const char *transport, const char *manufacturer,
+ const char *product, int vendor, int model, uint16_t version) {
+ if (!transport || strcmp(transport, "Virtual") || !manufacturer ||
+ strcmp(manufacturer, "Microsoft") || !product || vendor != 0x045e || model != 0x028e) {
+ return -1;
+ }
+ unsigned number = 0;
+ char extra;
+ if (sscanf(product, "GamePad-%u%c", &number, &extra) != 1 || number < 1 ||
+ number > kGamepadCount) {
+ return -1;
+ }
+ // SDL HIDAPI uses the same GUID plus its documented driver signature.
+ // Darwin IOKit leaves that byte zero. Both can enumerate Steam's device.
+ if (guid.data[14] != 0 && guid.data[14] != 'h') {
+ return -1;
+ }
+ guid.data[14] = 0;
+ JoystickGUID expected = virtualGamepadGUID(number - 1, version);
+ return !memcmp(&guid, &expected, sizeof(guid)) ? (int)number - 1 : -1;
+}
diff --git a/controllers/steam-input/rumble.cpp b/controllers/steam-input/rumble.cpp
new file mode 100644
index 0000000..f5aeec7
--- /dev/null
+++ b/controllers/steam-input/rumble.cpp
@@ -0,0 +1,347 @@
+// Forward Winebus SDL2 rumble for Steam's virtual gamepads to native Steam Input.
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/IOKitLib.h>
+#include <dlfcn.h>
+#include <pthread.h>
+#include <atomic>
+#include <algorithm>
+#include <chrono>
+#include <cstdlib>
+#include <cstring>
+#include <limits>
+#include <unistd.h>
+#include "SteamSession.h"
+#include "VirtualGamepad.h"
+
+#ifndef INTERPOSE
+#define INTERPOSE(replacement, original) \
+ __attribute__((used)) static const struct { \
+ const void *a, *b; \
+ } ip_##original \
+ __attribute__((section("__DATA,__interpose"))) = {(void *)replacement, (void *)original}
+#endif
+static_assert(kGamepadCount == STEAM_CONTROLLER_MAX_COUNT);
+constexpr double kMappingPollSeconds = 0.020;
+constexpr double kSteamRetrySeconds = 2;
+
+// The mutex protects the slot mailbox; the worker alone owns the Steam session.
+using Clock = std::chrono::steady_clock;
+static double now() {
+ return std::chrono::duration<double>(Clock::now().time_since_epoch()).count();
+}
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t wake = PTHREAD_COND_INITIALIZER;
+static pthread_once_t workerOnce = PTHREAD_ONCE_INIT;
+static std::atomic<bool> running{true};
+static pthread_t workerThread;
+static std::atomic<bool> workerStarted{false};
+static void *sdlLibrary;
+static int (*originalRumble)(void *, uint16_t, uint16_t, uint32_t);
+static int (*originalHasRumble)(void *);
+static void (*originalClose)(void *);
+static JoystickGUID (*getGUID)(void *);
+static int32_t (*getInstance)(void *);
+static int (*getAttached)(void *);
+
+struct Slot {
+ int32_t instance = -1;
+ uint16_t left = 0, right = 0;
+ double until = 0;
+ uint64_t generation = 0;
+};
+static Slot slots[kGamepadCount];
+
+static bool enabled() {
+ const char *mode = getenv("NOTPROTON_STEAM_RUMBLE");
+ const char *raw = getenv("NOTPROTON_RAW_CONTROLLERS");
+ const char *app = getenv("SteamAppId");
+ return mode && !strcmp(mode, "1") && (!raw || strcmp(raw, "1")) && app && *app;
+}
+static int readNumberProperty(CFDictionaryRef properties, CFStringRef key) {
+ int n = 0;
+ CFTypeRef v = CFDictionaryGetValue(properties, key);
+ if (v && CFGetTypeID(v) == CFNumberGetTypeID()) {
+ CFNumberGetValue((CFNumberRef)v, kCFNumberIntType, &n);
+ }
+ return n;
+}
+static void readStringProperty(CFDictionaryRef properties, CFStringRef key, char *out,
+ size_t capacity) {
+ out[0] = 0;
+ CFTypeRef v = CFDictionaryGetValue(properties, key);
+ if (v && CFGetTypeID(v) == CFStringGetTypeID()) {
+ CFStringGetCString((CFStringRef)v, out, capacity, kCFStringEncodingUTF8);
+ }
+}
+static int lookupSlot(void *joystick) {
+ if (!getGUID || !getInstance || !getAttached || !getAttached(joystick)) {
+ return -1;
+ }
+ int32_t instance = getInstance(joystick);
+ if (instance < 0) {
+ return -1;
+ }
+ pthread_mutex_lock(&lock);
+ for (int i = 0; i < kGamepadCount; ++i) {
+ if (slots[i].instance == instance) {
+ pthread_mutex_unlock(&lock);
+ return i;
+ }
+ }
+ pthread_mutex_unlock(&lock);
+ JoystickGUID guid = getGUID(joystick);
+ // Reject physical controllers before consulting IOKit. No device is opened.
+ if (guid.data[0] != 3 || guid.data[4] != 0x5e || guid.data[5] != 4 || guid.data[8] != 0x8e ||
+ guid.data[9] != 2) {
+ return -1;
+ }
+ io_iterator_t devices = 0;
+ if (IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceMatching("IOHIDDevice"),
+ &devices)) {
+ return -1;
+ }
+ int found = -1;
+ io_service_t device;
+ while ((device = IOIteratorNext(devices))) {
+ CFMutableDictionaryRef properties = nullptr;
+ if (!IORegistryEntryCreateCFProperties(device, &properties, kCFAllocatorDefault, 0)) {
+ char transport[64], manufacturer[128], product[128];
+ readStringProperty(properties, CFSTR("Transport"), transport, sizeof(transport));
+ readStringProperty(properties, CFSTR("Manufacturer"), manufacturer,
+ sizeof(manufacturer));
+ readStringProperty(properties, CFSTR("Product"), product, sizeof(product));
+ int slot = virtualGamepadSlot(guid, transport, manufacturer, product,
+ readNumberProperty(properties, CFSTR("VendorID")),
+ readNumberProperty(properties, CFSTR("ProductID")),
+ readNumberProperty(properties, CFSTR("VersionNumber")));
+ if (slot >= 0) {
+ found = slot;
+ }
+ CFRelease(properties);
+ }
+ IOObjectRelease(device);
+ }
+ IOObjectRelease(devices);
+ if (found >= 0) {
+ pthread_mutex_lock(&lock);
+ if (slots[found].instance != instance) {
+ uint64_t generation = slots[found].generation + 1;
+ slots[found] = Slot{};
+ slots[found].instance = instance;
+ slots[found].generation = generation;
+ pthread_cond_signal(&wake);
+ }
+ pthread_mutex_unlock(&lock);
+ fprintf(stderr, "notproton-rumble: Steam virtual gamepad slot %d mapped (pid %d)\n", found,
+ getpid());
+ }
+ return found;
+}
+
+static void *worker(void *) {
+ SteamSession steam;
+ uint64_t seen[kGamepadCount] = {};
+ ControllerHandle_t active[kGamepadCount] = {};
+ double retryAt = 0;
+ while (running) {
+ Slot snapshot[kGamepadCount];
+ pthread_mutex_lock(&lock);
+ memcpy(snapshot, slots, sizeof(slots));
+ pthread_mutex_unlock(&lock);
+ double time = now(), next = time + 1;
+ bool pending = false;
+ for (int i = 0; i < kGamepadCount; ++i) {
+ pending |= snapshot[i].generation != seen[i] && snapshot[i].instance >= 0 &&
+ snapshot[i].until > time;
+ }
+ if (!steam.controller && pending && time >= retryAt) {
+ if (!steam.open()) {
+ retryAt = now() + kSteamRetrySeconds;
+ }
+ }
+ if (steam.controller) {
+ steam.controller->RunFrame();
+ // Use commands received while Steam was opening or RunFrame was blocked.
+ pthread_mutex_lock(&lock);
+ memcpy(snapshot, slots, sizeof(slots));
+ pthread_mutex_unlock(&lock);
+ time = now();
+ ControllerHandle_t handles[kGamepadCount] = {};
+ for (int i = 0; i < kGamepadCount; ++i) {
+ if (snapshot[i].until > time && snapshot[i].instance >= 0) {
+ handles[i] = steam.controller->GetControllerForGamepadIndex(i);
+ }
+ }
+ // Stop every old assignment before starting any new one. This also
+ // handles two controllers exchanging their gamepad indices.
+ for (int i = 0; i < kGamepadCount; ++i) {
+ if (active[i] && active[i] != handles[i]) {
+ steam.controller->TriggerVibration(active[i], 0, 0);
+ active[i] = 0;
+ }
+ }
+ for (int i = 0; i < kGamepadCount; ++i) {
+ const Slot &request = snapshot[i];
+ bool alive = request.until > time && request.instance >= 0;
+ ControllerHandle_t handle = handles[i];
+ if (handle && (request.generation != seen[i] || active[i] != handle)) {
+ steam.controller->TriggerVibration(handle, request.left, request.right);
+ active[i] = handle;
+ static bool logged;
+ if (!logged) {
+ fprintf(stderr, "notproton-rumble: forwarding rumble via Steam\n");
+ logged = true;
+ }
+ }
+ if (handle || !alive) {
+ seen[i] = request.generation;
+ }
+ // Retry a missing mapping, and detect reassignment during an effect.
+ if (alive) {
+ next = std::min(next, std::min(time + kMappingPollSeconds, request.until));
+ }
+ }
+ }
+ pthread_mutex_lock(&lock);
+ bool changed = false;
+ for (int i = 0; i < kGamepadCount; ++i) {
+ changed |= slots[i].generation != snapshot[i].generation;
+ }
+ if (!changed && running) {
+ double wait = next - now();
+ if (wait > 0) {
+ struct timespec timeout{(time_t)wait, (long)((wait - (time_t)wait) * 1e9)};
+ pthread_cond_timedwait_relative_np(&wake, &lock, &timeout);
+ }
+ }
+ pthread_mutex_unlock(&lock);
+ }
+ if (steam.controller) {
+ for (auto handle : active) {
+ if (handle) {
+ steam.controller->TriggerVibration(handle, 0, 0);
+ }
+ }
+ }
+ return nullptr;
+}
+static void startWorker() {
+ workerStarted = pthread_create(&workerThread, nullptr, worker, nullptr) == 0;
+}
+static int rumble(void *joystick, uint16_t left, uint16_t right, uint32_t duration) {
+ int slot = lookupSlot(joystick);
+ if (slot < 0) {
+ return originalRumble(joystick, left, right, duration);
+ }
+ // Wine probes with zeroes: advertise support without connecting to Steam or
+ // cancelling rumble owned by another client (e.g. the game's Steam API).
+ pthread_mutex_lock(&lock);
+ bool idle = slots[slot].until == 0;
+ pthread_mutex_unlock(&lock);
+ if (idle && !(left || right)) {
+ return 0;
+ }
+ pthread_once(&workerOnce, startWorker);
+ if (!workerStarted) {
+ return -1;
+ }
+ pthread_mutex_lock(&lock);
+ slots[slot].left = left;
+ slots[slot].right = right;
+ // SDL2 uses a zero duration for effects without an automatic expiry.
+ if (!(left || right)) {
+ slots[slot].until = 0;
+ } else if (duration) {
+ slots[slot].until = now() + std::min(duration, uint32_t{65535}) / 1000.0;
+ } else {
+ slots[slot].until = std::numeric_limits<double>::infinity();
+ }
+ ++slots[slot].generation;
+ pthread_cond_signal(&wake);
+ pthread_mutex_unlock(&lock);
+ return 0;
+}
+static int hasRumble(void *joystick) {
+ if (lookupSlot(joystick) >= 0) {
+ return 1;
+ }
+ return originalHasRumble ? originalHasRumble(joystick) : 0;
+}
+static void closeJoystick(void *joystick) {
+ int32_t instance = getInstance ? getInstance(joystick) : -1;
+ pthread_mutex_lock(&lock);
+ for (auto &slot : slots) {
+ if (instance >= 0 && slot.instance == instance) {
+ slot.instance = -1;
+ slot.until = 0;
+ ++slot.generation;
+ }
+ }
+ pthread_cond_signal(&wake);
+ pthread_mutex_unlock(&lock);
+ originalClose(joystick);
+}
+static void *resolve(void *library, const char *symbol) {
+ void *original = dlsym(library, symbol);
+ if (getenv("NOTPROTON_STEAM_RUMBLE_TRACE") && !strcmp(symbol, "SDL_JoystickRumble")) {
+ Dl_info diag{};
+ dladdr(original, &diag);
+ fprintf(stderr, "notproton-rumble: resolve pid=%d enabled=%d source=%s root=%s app=%s\n",
+ getpid(), enabled(), diag.dli_fname ? diag.dli_fname : "?",
+ getenv("CX_ROOT") ? getenv("CX_ROOT") : "?",
+ getenv("SteamAppId") ? getenv("SteamAppId") : "?");
+ }
+ if (!original || !enabled() ||
+ (strcmp(symbol, "SDL_JoystickRumble") && strcmp(symbol, "SDL_JoystickHasRumble") &&
+ strcmp(symbol, "SDL_JoystickClose"))) {
+ return original;
+ }
+ // Never hook Steam's own SDL or an unrelated application/library.
+ Dl_info image{};
+ const char *root = getenv("CX_ROOT");
+ if (!root || !*root || !dladdr(original, &image) || !image.dli_fname ||
+ strncmp(image.dli_fname, root, strlen(root)) || image.dli_fname[strlen(root)] != '/') {
+ return original;
+ }
+ pthread_mutex_lock(&lock);
+ if (!sdlLibrary) {
+ auto guid = (decltype(getGUID))dlsym(library, "SDL_JoystickGetGUID");
+ auto instance = (decltype(getInstance))dlsym(library, "SDL_JoystickInstanceID");
+ auto attached = (decltype(getAttached))dlsym(library, "SDL_JoystickGetAttached");
+ auto rumble = (decltype(originalRumble))dlsym(library, "SDL_JoystickRumble");
+ auto hasRumble = (decltype(originalHasRumble))dlsym(library, "SDL_JoystickHasRumble");
+ auto close = (decltype(originalClose))dlsym(library, "SDL_JoystickClose");
+ if (guid && instance && attached && rumble && close) {
+ getGUID = guid;
+ getInstance = instance;
+ getAttached = attached;
+ originalRumble = rumble;
+ originalHasRumble = hasRumble;
+ originalClose = close;
+ sdlLibrary = library;
+ }
+ }
+ bool matched = sdlLibrary == library;
+ pthread_mutex_unlock(&lock);
+ if (!matched) {
+ return original;
+ }
+ if (!strcmp(symbol, "SDL_JoystickRumble")) {
+ return (void *)rumble;
+ }
+ if (!strcmp(symbol, "SDL_JoystickHasRumble")) {
+ return (void *)hasRumble;
+ }
+ return (void *)closeJoystick;
+}
+INTERPOSE(resolve, dlsym);
+__attribute__((destructor)) static void shutdownBridge() {
+ if (!workerStarted.exchange(false)) {
+ return;
+ }
+ running = false;
+ pthread_mutex_lock(&lock);
+ pthread_cond_signal(&wake);
+ pthread_mutex_unlock(&lock);
+ pthread_join(workerThread, nullptr);
+}
diff --git a/controllers/steam-input/tests/MockSteam.h b/controllers/steam-input/tests/MockSteam.h
new file mode 100644
index 0000000..2150a8f
--- /dev/null
+++ b/controllers/steam-input/tests/MockSteam.h
@@ -0,0 +1,10 @@
+#pragma once
+#include <cstdint>
+
+struct RumbleEvent {
+ uint64_t handle;
+ uint16_t left, right;
+};
+struct SessionStats {
+ unsigned pipes, releasedPipes, users, releasedUsers, initializations, shutdowns;
+};
diff --git a/controllers/steam-input/tests/hooks.cpp b/controllers/steam-input/tests/hooks.cpp
new file mode 100644
index 0000000..6ca9ef8
--- /dev/null
+++ b/controllers/steam-input/tests/hooks.cpp
@@ -0,0 +1,172 @@
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/IOKitLib.h>
+#include <dlfcn.h>
+#include <cassert>
+#include <cstring>
+#include <string>
+#include "../VirtualGamepad.h"
+
+struct Joystick {
+ int32_t instance;
+ bool attached = true;
+ JoystickGUID guid;
+};
+static CFMutableDictionaryRef deviceProperties;
+static bool devicePending, incompleteSDL;
+static unsigned enumerations, fallbackCalls, closeCalls;
+static const char *imagePath = "/test/CrossOver/lib/libSDL2.dylib";
+static JoystickGUID mockGUID(void *j) {
+ return ((Joystick *)j)->guid;
+}
+static int32_t mockInstance(void *j) {
+ return ((Joystick *)j)->instance;
+}
+static int mockAttached(void *j) {
+ return ((Joystick *)j)->attached;
+}
+static int mockRumble(void *, uint16_t, uint16_t, uint32_t) {
+ ++fallbackCalls;
+ return -7;
+}
+static int mockHasRumble(void *) {
+ return 0;
+}
+static void mockClose(void *j) {
+ ((Joystick *)j)->attached = false;
+ ++closeCalls;
+}
+static void *mockDlsym(void *, const char *name) {
+ if (!strcmp(name, "SDL_JoystickGetGUID")) {
+ return (void *)mockGUID;
+ }
+ if (!strcmp(name, "SDL_JoystickInstanceID")) {
+ return (void *)mockInstance;
+ }
+ if (!strcmp(name, "SDL_JoystickGetAttached")) {
+ return incompleteSDL ? nullptr : (void *)mockAttached;
+ }
+ if (!strcmp(name, "SDL_JoystickRumble")) {
+ return (void *)mockRumble;
+ }
+ if (!strcmp(name, "SDL_JoystickHasRumble")) {
+ return (void *)mockHasRumble;
+ }
+ if (!strcmp(name, "SDL_JoystickClose")) {
+ return (void *)mockClose;
+ }
+ return nullptr;
+}
+static int mockDladdr(const void *, Dl_info *info) {
+ info->dli_fname = imagePath;
+ return 1;
+}
+static kern_return_t mockMatching(mach_port_t, CFDictionaryRef matching, io_iterator_t *iterator) {
+ CFRelease(matching);
+ ++enumerations;
+ devicePending = true;
+ *iterator = 1;
+ return KERN_SUCCESS;
+}
+static io_object_t mockNext(io_iterator_t) {
+ if (!devicePending) {
+ return 0;
+ }
+ devicePending = false;
+ return 2;
+}
+static kern_return_t mockProperties(io_registry_entry_t, CFMutableDictionaryRef *out,
+ CFAllocatorRef, IOOptionBits) {
+ *out = CFDictionaryCreateMutableCopy(nullptr, 0, deviceProperties);
+ return KERN_SUCCESS;
+}
+static kern_return_t mockRelease(io_object_t) {
+ return KERN_SUCCESS;
+}
+
+#define INTERPOSE(replacement, original)
+#define dlsym mockDlsym
+#define dladdr mockDladdr
+#define IOServiceGetMatchingServices mockMatching
+#define IOIteratorNext mockNext
+#define IORegistryEntryCreateCFProperties mockProperties
+#define IOObjectRelease mockRelease
+#include "../rumble.cpp"
+#undef dlsym
+#undef dladdr
+#undef IOServiceGetMatchingServices
+#undef IOIteratorNext
+#undef IORegistryEntryCreateCFProperties
+#undef IOObjectRelease
+
+static void number(CFStringRef key, int value) {
+ auto property = CFNumberCreate(nullptr, kCFNumberIntType, &value);
+ CFDictionarySetValue(deviceProperties, key, property);
+ CFRelease(property);
+}
+int main() {
+ void *library = (void *)1;
+ setenv("NOTPROTON_STEAM_RUMBLE", "1", 1);
+ setenv("NOTPROTON_RAW_CONTROLLERS", "0", 1);
+ setenv("SteamAppId", "242680", 1);
+ setenv("CX_ROOT", "/test/CrossOver", 1);
+ assert(resolve(library, "missing") == nullptr);
+ for (const char *key : {"NOTPROTON_STEAM_RUMBLE", "SteamAppId", "CX_ROOT"}) {
+ std::string saved = getenv(key);
+ setenv(key, "", 1);
+ assert(resolve(library, "SDL_JoystickRumble") == (void *)mockRumble);
+ setenv(key, saved.c_str(), 1);
+ }
+ setenv("NOTPROTON_RAW_CONTROLLERS", "1", 1);
+ assert(resolve(library, "SDL_JoystickRumble") == (void *)mockRumble);
+ setenv("NOTPROTON_RAW_CONTROLLERS", "0", 1);
+ for (auto path : {"/Steam/libSDL2.dylib", "/test/CrossOver-other/libSDL2.dylib"}) {
+ imagePath = path;
+ assert(resolve(library, "SDL_JoystickRumble") == (void *)mockRumble);
+ }
+ imagePath = "/test/CrossOver/lib/libSDL2.dylib";
+ incompleteSDL = true;
+ assert(resolve(library, "SDL_JoystickRumble") == (void *)mockRumble);
+ assert(!getGUID && !originalRumble && !sdlLibrary);
+ incompleteSDL = false;
+ assert(resolve(library, "SDL_JoystickRumble") == (void *)rumble);
+ assert(resolve(library, "SDL_JoystickHasRumble") == (void *)hasRumble);
+ assert(resolve(library, "SDL_JoystickClose") == (void *)closeJoystick);
+ assert(resolve((void *)2, "SDL_JoystickRumble") == (void *)mockRumble);
+
+ deviceProperties = CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ CFDictionarySetValue(deviceProperties, CFSTR("Transport"), CFSTR("Virtual"));
+ CFDictionarySetValue(deviceProperties, CFSTR("Manufacturer"), CFSTR("Microsoft"));
+ CFDictionarySetValue(deviceProperties, CFSTR("Product"), CFSTR("GamePad-1"));
+ number(CFSTR("VendorID"), 0x45e);
+ number(CFSTR("ProductID"), 0x28e);
+ number(CFSTR("VersionNumber"), 0);
+ Joystick physical{10, true, {}};
+ assert(hasRumble(&physical) == 0 && enumerations == 0);
+ assert(rumble(&physical, 1, 2, 3) == -7 && fallbackCalls == 1);
+ Joystick first{11, true, virtualGamepadGUID(0, 0)};
+ assert(hasRumble(&first) == 1 && enumerations == 1);
+ assert(hasRumble(&first) == 1 && enumerations == 1); // Cached SDL instance.
+ assert(rumble(&first, 0, 0, 0) == 0 && !workerStarted);
+ first.attached = false;
+ assert(hasRumble(&first) == 0);
+ slots[0].until = now() + 60;
+ slots[0].left = 123;
+ uint64_t oldGeneration = slots[0].generation;
+ Joystick replacement{12, true, virtualGamepadGUID(0, 0)};
+ replacement.guid.data[14] = 'h';
+ assert(hasRumble(&replacement) == 1);
+ assert(slots[0].instance == 12 && slots[0].until == 0 && slots[0].left == 0);
+ assert(slots[0].generation > oldGeneration);
+ closeJoystick(&first);
+ assert(slots[0].instance == 12); // A late close cannot invalidate the replacement.
+ closeJoystick(&replacement);
+ assert(slots[0].instance == -1 && closeCalls == 2);
+ CFDictionarySetValue(deviceProperties, CFSTR("Transport"), CFSTR("USB"));
+ Joystick realXbox{13, true, virtualGamepadGUID(0, 0)};
+ assert(hasRumble(&realXbox) == 0);
+ assert(!workerStarted);
+ CFRelease(deviceProperties);
+ puts("steam-input: SDL symbol gating, IOKit identity, cache, HIDAPI, replacement and close "
+ "passed");
+}
diff --git a/controllers/steam-input/tests/launcher.py b/controllers/steam-input/tests/launcher.py
new file mode 100644
index 0000000..167489b
--- /dev/null
+++ b/controllers/steam-input/tests/launcher.py
@@ -0,0 +1,50 @@
+"""Exercise launch gating with real shell expansion; no Steam or hardware needed."""
+
+import os
+import subprocess
+import tempfile
+from pathlib import Path
+
+root = Path(__file__).resolve().parents[3]
+source = (root / "dylib/feats/compat_run.sh").read_text()
+start = source.index('steam_rumble="$np_support/controllers/steam-input/rumble.dylib"')
+end = source.index("export NOTPROTON_RUMBLE_LIBRARY", start) + len(
+ "export NOTPROTON_RUMBLE_LIBRARY"
+)
+block = source[start:end]
+with tempfile.TemporaryDirectory(prefix="notproton rumble ") as tmp:
+ library = Path(tmp) / "controllers/steam-input/rumble.dylib"
+ library.parent.mkdir(parents=True)
+ library.touch()
+ for verb, raw, setting, expected in [
+ ("waitforexitandrun", "0", "", True),
+ ("waitforexitandrun", "1", "", False),
+ ("waitforexitandrun", "0", "0", False),
+ ("run", "0", "", False),
+ ("waitforexitandrun", "", "1", True),
+ ]:
+ env = dict(
+ os.environ,
+ np_support=tmp,
+ verb=verb,
+ NOTPROTON_RAW_CONTROLLERS=raw,
+ NOTPROTON_STEAM_RUMBLE=setting,
+ )
+ for overlay in ("", "overlay"):
+ command = (
+ f"DYLD_INSERT_LIBRARIES={overlay}\n"
+ + block
+ + '\nprintf "%s|%s" "$NOTPROTON_RUMBLE_LIBRARY" "$DYLD_INSERT_LIBRARIES"'
+ )
+ result = subprocess.check_output(["/bin/sh", "-c", command], env=env, text=True)
+ libraries = str(library) + (f":{overlay}" if overlay else "")
+ assert result == (f"{library}|{libraries}" if expected else f"|{overlay}"), result
+ library.unlink()
+ env.update(verb="waitforexitandrun")
+ assert subprocess.check_output(["/bin/sh", "-c", command], env=env, text=True) == "|overlay"
+for name in ("NOTPROTON_RUMBLE_LIBRARY", "NOTPROTON_STEAM_RUMBLE", "NOTPROTON_RAW_CONTROLLERS"):
+ assert f"--env {name}=" in source
+assert "\\$NOTPROTON_RUMBLE_LIBRARY\\${DYLD_INSERT_LIBRARIES:+" in source
+print(
+ "steam-input: game/helper/raw/disabled/missing-library launch gating and environment forwarding passed"
+)
diff --git a/controllers/steam-input/tests/mock-steam.cpp b/controllers/steam-input/tests/mock-steam.cpp
new file mode 100644
index 0000000..f6c2137
--- /dev/null
+++ b/controllers/steam-input/tests/mock-steam.cpp
@@ -0,0 +1,350 @@
+#include "steam_api.h"
+#include "MockSteam.h"
+#include <atomic>
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+#include <mutex>
+#include <unistd.h>
+#include <vector>
+
+static std::mutex eventLock;
+static std::vector<RumbleEvent> events;
+static std::atomic<ControllerHandle_t> handles[STEAM_CONTROLLER_MAX_COUNT];
+static std::atomic<unsigned> frameDelay{0};
+static std::atomic<bool> frameBlocked{false};
+static unsigned failure, pipes, releasedPipes, users, releasedUsers, initializations, shutdowns;
+
+// Implement the SDK interfaces so the compiler checks the ABI. Any unexpected
+// API call aborts the test, including attempts to change LEDs or input bindings.
+struct ControllerMock final : ISteamController {
+ bool Init() override {
+ ++initializations;
+ return failure != 4;
+ }
+ bool Shutdown() override {
+ ++shutdowns;
+ return true;
+ }
+ void RunFrame() override {
+ unsigned delay = frameDelay.exchange(0);
+ if (delay) {
+ frameBlocked = true;
+ usleep(delay * 1000);
+ frameBlocked = false;
+ }
+ }
+ int GetConnectedControllers(ControllerHandle_t *handlesOut) override {
+ std::abort();
+ }
+ ControllerActionSetHandle_t GetActionSetHandle(const char *pszActionSetName) override {
+ std::abort();
+ }
+ void ActivateActionSet(ControllerHandle_t controllerHandle,
+ ControllerActionSetHandle_t actionSetHandle) override {
+ std::abort();
+ }
+ ControllerActionSetHandle_t GetCurrentActionSet(ControllerHandle_t controllerHandle) override {
+ std::abort();
+ }
+ void ActivateActionSetLayer(ControllerHandle_t controllerHandle,
+ ControllerActionSetHandle_t actionSetLayerHandle) override {
+ std::abort();
+ }
+ void DeactivateActionSetLayer(ControllerHandle_t controllerHandle,
+ ControllerActionSetHandle_t actionSetLayerHandle) override {
+ std::abort();
+ }
+ void DeactivateAllActionSetLayers(ControllerHandle_t controllerHandle) override {
+ std::abort();
+ }
+ int GetActiveActionSetLayers(ControllerHandle_t controllerHandle,
+ ControllerActionSetHandle_t *handlesOut) override {
+ std::abort();
+ }
+ ControllerDigitalActionHandle_t GetDigitalActionHandle(const char *pszActionName) override {
+ std::abort();
+ }
+ ControllerDigitalActionData_t
+ GetDigitalActionData(ControllerHandle_t controllerHandle,
+ ControllerDigitalActionHandle_t digitalActionHandle) override {
+ std::abort();
+ }
+ int GetDigitalActionOrigins(ControllerHandle_t controllerHandle,
+ ControllerActionSetHandle_t actionSetHandle,
+ ControllerDigitalActionHandle_t digitalActionHandle,
+ EControllerActionOrigin *originsOut) override {
+ std::abort();
+ }
+ ControllerAnalogActionHandle_t GetAnalogActionHandle(const char *pszActionName) override {
+ std::abort();
+ }
+ ControllerAnalogActionData_t
+ GetAnalogActionData(ControllerHandle_t controllerHandle,
+ ControllerAnalogActionHandle_t analogActionHandle) override {
+ std::abort();
+ }
+ int GetAnalogActionOrigins(ControllerHandle_t controllerHandle,
+ ControllerActionSetHandle_t actionSetHandle,
+ ControllerAnalogActionHandle_t analogActionHandle,
+ EControllerActionOrigin *originsOut) override {
+ std::abort();
+ }
+ const char *GetGlyphForActionOrigin(EControllerActionOrigin eOrigin) override {
+ std::abort();
+ }
+ const char *GetStringForActionOrigin(EControllerActionOrigin eOrigin) override {
+ std::abort();
+ }
+ void StopAnalogActionMomentum(ControllerHandle_t controllerHandle,
+ ControllerAnalogActionHandle_t eAction) override {
+ std::abort();
+ }
+ ControllerMotionData_t GetMotionData(ControllerHandle_t controllerHandle) override {
+ std::abort();
+ }
+ void TriggerHapticPulse(ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad,
+ unsigned short usDurationMicroSec) override {
+ std::abort();
+ }
+ void TriggerRepeatedHapticPulse(ControllerHandle_t controllerHandle,
+ ESteamControllerPad eTargetPad,
+ unsigned short usDurationMicroSec, unsigned short usOffMicroSec,
+ unsigned short unRepeat, unsigned int nFlags) override {
+ std::abort();
+ }
+ void TriggerVibration(ControllerHandle_t controllerHandle, unsigned short usLeftSpeed,
+ unsigned short usRightSpeed) override {
+ std::lock_guard<std::mutex> guard(eventLock);
+ events.push_back({controllerHandle, usLeftSpeed, usRightSpeed});
+ }
+ void SetLEDColor(ControllerHandle_t controllerHandle, uint8 nColorR, uint8 nColorG,
+ uint8 nColorB, unsigned int nFlags) override {
+ std::abort();
+ }
+ bool ShowBindingPanel(ControllerHandle_t controllerHandle) override {
+ std::abort();
+ }
+ ESteamInputType GetInputTypeForHandle(ControllerHandle_t controllerHandle) override {
+ std::abort();
+ }
+ ControllerHandle_t GetControllerForGamepadIndex(int nIndex) override {
+ return handles[nIndex].load();
+ }
+ int GetGamepadIndexForController(ControllerHandle_t ulControllerHandle) override {
+ std::abort();
+ }
+ const char *GetStringForXboxOrigin(EXboxOrigin eOrigin) override {
+ std::abort();
+ }
+ const char *GetGlyphForXboxOrigin(EXboxOrigin eOrigin) override {
+ std::abort();
+ }
+ EControllerActionOrigin GetActionOriginFromXboxOrigin(ControllerHandle_t controllerHandle,
+ EXboxOrigin eOrigin) override {
+ std::abort();
+ }
+ EControllerActionOrigin TranslateActionOrigin(ESteamInputType eDestinationInputType,
+ EControllerActionOrigin eSourceOrigin) override {
+ std::abort();
+ }
+ bool GetControllerBindingRevision(ControllerHandle_t controllerHandle, int *pMajor,
+ int *pMinor) override {
+ std::abort();
+ }
+};
+static ControllerMock controller;
+
+struct ClientMock final : ISteamClient {
+ HSteamPipe CreateSteamPipe() override {
+ if (failure == 1) {
+ return 0;
+ }
+ ++pipes;
+ return 1;
+ }
+ bool BReleaseSteamPipe(HSteamPipe hSteamPipe) override {
+ assert(hSteamPipe == 1);
+ ++releasedPipes;
+ return true;
+ }
+ HSteamUser ConnectToGlobalUser(HSteamPipe hSteamPipe) override {
+ assert(hSteamPipe == 1);
+ if (failure == 2) {
+ return 0;
+ }
+ ++users;
+ return 1;
+ }
+ HSteamUser CreateLocalUser(HSteamPipe *phSteamPipe, EAccountType eAccountType) override {
+ std::abort();
+ }
+ void ReleaseUser(HSteamPipe hSteamPipe, HSteamUser hUser) override {
+ assert(hSteamPipe == 1 && hUser == 1);
+ ++releasedUsers;
+ }
+ ISteamUser *GetISteamUser(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamGameServer *GetISteamGameServer(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ void SetLocalIPBinding(const SteamIPAddress_t &unIP, uint16 usPort) override {
+ std::abort();
+ }
+ ISteamFriends *GetISteamFriends(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamUtils *GetISteamUtils(HSteamPipe hSteamPipe, const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamMatchmaking *GetISteamMatchmaking(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamMatchmakingServers *GetISteamMatchmakingServers(HSteamUser hSteamUser,
+ HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ void *GetISteamGenericInterface(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamUserStats *GetISteamUserStats(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamGameServerStats *GetISteamGameServerStats(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamApps *GetISteamApps(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamNetworking *GetISteamNetworking(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamRemoteStorage *GetISteamRemoteStorage(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamScreenshots *GetISteamScreenshots(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamGameSearch *GetISteamGameSearch(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ void RunFrame() override {
+ std::abort();
+ }
+ uint32 GetIPCCallCount() override {
+ std::abort();
+ }
+ void SetWarningMessageHook(SteamAPIWarningMessageHook_t pFunction) override {
+ std::abort();
+ }
+ bool BShutdownIfAllPipesClosed() override {
+ std::abort();
+ }
+ ISteamHTTP *GetISteamHTTP(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamController *GetISteamController(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ assert(hSteamUser == 1 && hSteamPipe == 1);
+ assert(!strcmp(pchVersion, STEAMCONTROLLER_INTERFACE_VERSION));
+ return failure == 3 ? nullptr : &controller;
+ }
+ ISteamUGC *GetISteamUGC(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamMusic *GetISteamMusic(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamMusicRemote *GetISteamMusicRemote(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamHTMLSurface *GetISteamHTMLSurface(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ void DEPRECATED_Set_SteamAPI_CPostAPIResultInProcess(void (*)()) override {
+ std::abort();
+ }
+ void DEPRECATED_Remove_SteamAPI_CPostAPIResultInProcess(void (*)()) override {
+ std::abort();
+ }
+ void Set_SteamAPI_CCheckCallbackRegisteredInProcess(
+ SteamAPI_CheckCallbackRegistered_t func) override {
+ std::abort();
+ }
+ ISteamInventory *GetISteamInventory(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamVideo *GetISteamVideo(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamParentalSettings *GetISteamParentalSettings(HSteamUser hSteamuser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamInput *GetISteamInput(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamParties *GetISteamParties(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ ISteamRemotePlay *GetISteamRemotePlay(HSteamUser hSteamUser, HSteamPipe hSteamPipe,
+ const char *pchVersion) override {
+ std::abort();
+ }
+ void DestroyAllInterfaces() override {
+ std::abort();
+ }
+};
+static ClientMock client;
+
+extern "C" void *CreateInterface(const char *version, int *) {
+ assert(!strcmp(version, STEAMCLIENT_INTERFACE_VERSION));
+ return &client;
+}
+extern "C" unsigned testCount() {
+ std::lock_guard<std::mutex> guard(eventLock);
+ return events.size();
+}
+extern "C" RumbleEvent testEvent(unsigned i) {
+ std::lock_guard<std::mutex> guard(eventLock);
+ return events.at(i);
+}
+extern "C" void testSetHandle(int slot, ControllerHandle_t handle) {
+ handles[slot] = handle;
+}
+extern "C" void testDelayFrame(unsigned milliseconds) {
+ frameDelay = milliseconds;
+}
+extern "C" void testFailure(unsigned stage) {
+ failure = stage;
+}
+extern "C" SessionStats testStats() {
+ return {pipes, releasedPipes, users, releasedUsers, initializations, shutdowns};
+}
+
+extern "C" bool testFrameBlocked() {
+ return frameBlocked;
+}
diff --git a/controllers/steam-input/tests/routing.cpp b/controllers/steam-input/tests/routing.cpp
new file mode 100644
index 0000000..cab1655
--- /dev/null
+++ b/controllers/steam-input/tests/routing.cpp
@@ -0,0 +1,197 @@
+#include <cassert>
+#include <string>
+#include "../rumble.cpp"
+#include "MockSteam.h"
+static unsigned (*countEvents)();
+static RumbleEvent (*eventAt)(unsigned);
+static unsigned fallbackCalls;
+static int32_t instance(void *j) {
+ return (int32_t)(uintptr_t)j;
+}
+static int attached(void *j) {
+ return j != nullptr;
+}
+static JoystickGUID physicalGUID(void *) {
+ return {};
+}
+static int fallback(void *, uint16_t, uint16_t, uint32_t) {
+ ++fallbackCalls;
+ return -7;
+}
+static void noop(void *) {}
+static void waitFor(unsigned count) {
+ for (int i = 0; i < 200 && countEvents() < count; ++i) {
+ usleep(5000);
+ }
+ assert(countEvents() >= count);
+}
+int main(int argc, char **argv) {
+ assert(argc == 2);
+ // Raw Xbox IDs are insufficient; confirm IOKit's Virtual transport and
+ // original product name, including slot, against SDL's complete GUID.
+ auto guid = virtualGamepadGUID(0, 0);
+ const uint8_t recorded[16] = {3, 0, 0x53, 0x25, 0x5e, 4, 0, 0, 0x8e, 2, 0, 0, 0, 0, 0, 0};
+ assert(!memcmp(guid.data, recorded, 16));
+ assert(virtualGamepadSlot(guid, "Virtual", "Microsoft", "GamePad-1", 0x45e, 0x28e, 0) == 0);
+ assert(virtualGamepadSlot(guid, "USB", "Microsoft", "GamePad-1", 0x45e, 0x28e, 0) == -1);
+ assert(virtualGamepadSlot(guid, "Virtual", "Microsoft", "GamePad-2", 0x45e, 0x28e, 0) == -1);
+ assert(virtualGamepadSlot(guid, "Virtual", "Microsoft", "GamePad-1junk", 0x45e, 0x28e, 0) ==
+ -1);
+ auto hidapi = guid;
+ hidapi.data[14] = 'h';
+ assert(virtualGamepadSlot(hidapi, "Virtual", "Microsoft", "GamePad-1", 0x45e, 0x28e, 0) == 0);
+ hidapi.data[14] = 'm';
+ assert(virtualGamepadSlot(hidapi, "Virtual", "Microsoft", "GamePad-1", 0x45e, 0x28e, 0) == -1);
+ for (unsigned i = 0; i < 16; i++) {
+ char name[32];
+ snprintf(name, sizeof(name), "GamePad-%u", i + 1);
+ assert(virtualGamepadSlot(virtualGamepadGUID(i, 7), "Virtual", "Microsoft", name, 0x45e,
+ 0x28e, 7) == (int)i);
+ }
+ setenv("STEAM_COMPAT_CLIENT_INSTALL_PATH", argv[1], 1);
+ std::string library = std::string(argv[1]) + "/steamclient.dylib";
+ void *mock = dlopen(library.c_str(), RTLD_NOW | RTLD_LOCAL);
+ assert(mock);
+ countEvents = (decltype(countEvents))dlsym(mock, "testCount");
+ eventAt = (decltype(eventAt))dlsym(mock, "testEvent");
+ auto setHandle = (void (*)(int, ControllerHandle_t))dlsym(mock, "testSetHandle");
+ auto delayFrame = (void (*)(unsigned))dlsym(mock, "testDelayFrame");
+ auto setFailure = (void (*)(unsigned))dlsym(mock, "testFailure");
+ auto stats = (SessionStats (*)())dlsym(mock, "testStats");
+ assert(countEvents && eventAt && setHandle && delayFrame && setFailure && stats);
+ setHandle(0, 100);
+ setHandle(1, 101);
+
+ for (unsigned failure = 1; failure <= 4; ++failure) {
+ setFailure(failure);
+ SteamSession session;
+ assert(!session.open());
+ auto counts = stats();
+ assert(counts.pipes == counts.releasedPipes && counts.users == counts.releasedUsers);
+ assert(!session.controller && !session.pipe && !session.user);
+ }
+ setFailure(0);
+ {
+ SteamSession session;
+ assert(session.open());
+ }
+ auto counts = stats();
+ assert(counts.pipes == counts.releasedPipes && counts.users == counts.releasedUsers);
+ assert(counts.shutdowns == 1);
+
+ getInstance = instance;
+ getAttached = attached;
+ getGUID = physicalGUID;
+ originalRumble = fallback;
+ originalClose = noop;
+ slots[0].instance = 42;
+ slots[1].instance = 43;
+ assert(rumble((void *)99, 1, 2, 3) == -7 && fallbackCalls == 1); // physical path
+ assert(rumble((void *)42, 0, 0, 0) == 0 && !workerStarted); // capability probe
+ assert(rumble((void *)42, 12345, 54321, 200) == 0);
+ waitFor(1);
+ auto e = eventAt(0);
+ assert(e.handle == 100 && e.left == 12345 && e.right == 54321);
+ waitFor(2);
+ e = eventAt(1);
+ assert(e.handle == 100 && !e.left && !e.right); // expiry
+ rumble((void *)43, 200, 400, 2000);
+ waitFor(3);
+ assert(eventAt(2).handle == 101);
+ rumble((void *)43, 0, 0, 0);
+ waitFor(4);
+ assert(eventAt(3).handle == 101 && !eventAt(3).left); // explicit stop
+ rumble((void *)42, 333, 444, 2000);
+ waitFor(5);
+ closeJoystick((void *)42);
+ waitFor(6);
+ assert(!eventAt(5).left); // removal
+ assert(slots[0].instance == -1);
+ rumble((void *)43, 500, 600, 2000);
+ waitFor(7);
+ // A game can send its first effect while Steam is still publishing the
+ // virtual-to-physical mapping. It must not need another XInput call.
+ rumble((void *)43, 0, 0, 0);
+ waitFor(8);
+ setHandle(1, 0);
+ rumble((void *)43, 777, 888, 2000);
+ usleep(60000);
+ assert(countEvents() == 8);
+ setHandle(1, 101);
+ waitFor(9);
+ assert(eventAt(8).left == 777 && eventAt(8).right == 888);
+
+ // Mapping changes must stop the old handle before using the replacement,
+ // even if Wine has not issued another rumble command.
+ setHandle(1, 201);
+ waitFor(11);
+ assert(eventAt(9).handle == 101 && !eventAt(9).left);
+ assert(eventAt(10).handle == 201 && eventAt(10).left == 777);
+ setHandle(1, 0);
+ waitFor(12);
+ assert(eventAt(11).handle == 201 && !eventAt(11).left);
+ setHandle(1, 101);
+ waitFor(13);
+ assert(eventAt(12).left == 777);
+ rumble((void *)43, 0, 0, 0);
+ waitFor(14);
+
+ // A slow Steam update must not resurrect an effect whose deadline passed.
+ delayFrame(100);
+ rumble((void *)43, 111, 222, 30);
+ usleep(160000);
+ assert(countEvents() == 14);
+
+ // SDL2 leaves a nonzero effect running when duration is zero.
+ rumble((void *)43, 555, 666, 0);
+ waitFor(15);
+ usleep(60000);
+ assert(countEvents() == 15 && eventAt(14).left == 555);
+ rumble((void *)43, 0, 0, 0);
+ waitFor(16);
+ rumble((void *)43, 123, 456, UINT32_MAX);
+ waitFor(17);
+ pthread_mutex_lock(&lock);
+ double remaining = slots[1].until - now();
+ pthread_mutex_unlock(&lock);
+ assert(remaining > 64 && remaining <= 65.535);
+ // Replace a command while RunFrame is blocked; only the new one may escape.
+ auto frameBlocked = (bool (*)())dlsym(mock, "testFrameBlocked");
+ delayFrame(150);
+ rumble((void *)43, 321, 654, 2000);
+ for (int i = 0; i < 200 && !frameBlocked(); ++i) {
+ usleep(1000);
+ }
+ assert(frameBlocked());
+ rumble((void *)43, 500, 600, 2000);
+ waitFor(18);
+ assert(eventAt(17).left == 500);
+
+ pthread_mutex_lock(&lock);
+ slots[0].instance = 44;
+ pthread_mutex_unlock(&lock);
+ rumble((void *)44, 1000, 2000, 2000);
+ waitFor(19);
+ delayFrame(150);
+ rumble((void *)43, 501, 601, 2000);
+ for (int i = 0; i < 200 && !frameBlocked(); ++i) {
+ usleep(1000);
+ }
+ assert(frameBlocked());
+ setHandle(0, 101);
+ setHandle(1, 100);
+ waitFor(23);
+ assert(eventAt(19).handle == 100 && !eventAt(19).left);
+ assert(eventAt(20).handle == 101 && !eventAt(20).left);
+ assert(eventAt(21).handle == 101 && eventAt(21).left == 1000);
+ assert(eventAt(22).handle == 100 && eventAt(22).left == 501);
+
+ shutdownBridge();
+ assert(countEvents() == 25 && !eventAt(23).left && !eventAt(24).left);
+ counts = stats();
+ assert(counts.pipes == counts.releasedPipes && counts.users == counts.releasedUsers);
+ shutdownBridge(); // Idempotent cleanup; no duplicate stop or thread join.
+ assert(countEvents() == 25);
+ puts("steam-input: routing, fallback, amplitudes, expiry, stop, reassignment, late mapping, "
+ "slow Steam, zero/max duration, session failures and shutdown passed");
+}
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index fa85924..e95c265 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -25,6 +25,18 @@ fi
if [ -n "$DSB_LIBRARY" ] && [ -f "$DSB_LIBRARY" ]; then
export DYLD_INSERT_LIBRARIES="$DSB_LIBRARY${DYLD_INSERT_LIBRARIES:+:$DYLD_INSERT_LIBRARIES}"
fi
+# Steam's macOS virtual Xbox device has input but no SDL2 rumble backend.
+# The Wine-local adapter forwards only that device's rumble to native Steam.
+steam_rumble="$np_support/controllers/steam-input/rumble.dylib"
+NOTPROTON_RUMBLE_LIBRARY=""
+if [ "$verb" = waitforexitandrun ] && [ "${NOTPROTON_RAW_CONTROLLERS:-0}" != 1 ] \
+ && [ "${NOTPROTON_STEAM_RUMBLE:-1}" != 0 ] && [ -f "$steam_rumble" ]; then
+ export NOTPROTON_STEAM_RUMBLE=1
+ NOTPROTON_RUMBLE_LIBRARY="$steam_rumble"
+ export DYLD_INSERT_LIBRARIES="$steam_rumble${DYLD_INSERT_LIBRARIES:+:$DYLD_INSERT_LIBRARIES}"
+fi
+export NOTPROTON_RUMBLE_LIBRARY
+
# cxcompatdb resolves its database through CX_HOME and logs an error for
# every module loaded without it :(
export CX_HOME="$HOME/Library/Application Support/CrossOver"
@@ -2045,6 +2057,9 @@ elif [ -f "\$shim" ] && [ "\${NOTPROTON_FRAMEGEN:-0}" != 0 ] && [ "\$NOTPROTON_F
export DYLD_INSERT_LIBRARIES="\$shim"
export NOTPROTON_OVERLAY_SHIM="\$shim"
fi
+if [ -n "\$NOTPROTON_RUMBLE_LIBRARY" ] && [ -f "\$NOTPROTON_RUMBLE_LIBRARY" ]; then
+ export DYLD_INSERT_LIBRARIES="\$NOTPROTON_RUMBLE_LIBRARY\${DYLD_INSERT_LIBRARIES:+:\$DYLD_INSERT_LIBRARIES}"
+fi
export NOTPROTON_GAME_LOADER="$WINELOADER"
if [ -n "\$DSB_LIBRARY" ] && [ -f "\$DSB_LIBRARY" ]; then
export DYLD_INSERT_LIBRARIES="\$DSB_LIBRARY\${DYLD_INSERT_LIBRARIES:+:\$DYLD_INSERT_LIBRARIES}"
@@ -2193,6 +2208,9 @@ for name in $(env | sed -nE 's/^(CX_APPLEGPTK_LIBD3DSHARED_PATH|SDL_GAMECONTROLL
set -- --env "$name=$value" "$@"
done
set -- \
+ --env NOTPROTON_RUMBLE_LIBRARY="${NOTPROTON_RUMBLE_LIBRARY:-}" \
+ --env NOTPROTON_STEAM_RUMBLE="${NOTPROTON_STEAM_RUMBLE:-}" \
+ --env NOTPROTON_RAW_CONTROLLERS="${NOTPROTON_RAW_CONTROLLERS:-}" \
--env DSB_SESSION="${DSB_SESSION:-}" \
--env DSB_LIBRARY="${DSB_LIBRARY:-}" \
--env DSB_PORT="${DSB_PORT:-}" \