feat(bionic): dd-directcontroller, XInput from the pad state for games started without Steam (#3792)

Two problems with games set to "Start without Steam" on DroidDeck-Bionic.

1. launch.sh set WINE_LSTEAMCLIENT=1 for every launch, so Wine replaced any steamclient(64).dll
   a game loads with lsteamclient, DroidDeck's bridge to its Steam client. A game started
   without Steam has no Steam client behind it; one that brings its own steamclient64.dll (a
   Steam emulator such as gbe_fork's ColdClient loader) quit after its splash screen because
   SteamAPI_Init failed. With DROIDDECK_NO_STEAM on, launch.sh now sets WINE_LSTEAMCLIENT=0
   unless the player set a value.

2. Wine's xinput reads the HID reports winebus makes from the evdev events fakeinput replays
   out of each controller ring, through a queue per handle. A game that reads them slower than
   the pad reports gets old stick positions: in Halo: The Master Chief Collection the character
   kept moving for a second or two after the stick was let go (vibration off in DroidDeck and
   in the game changed nothing).

dd-directcontroller (tools/bionic-runtime/dd-directcontroller) is an XInput DLL set
(xinput1_1..1_4, 9_1_0, uap; ARM64X for system32, i386 for syswow64) that answers
XInputGetState from the snapshot of the whole pad FakeInputWriter keeps in each ring file's
header (sequence-locked, read with 32-bit loads only). XInputSetState returns at once; a worker
thread hands rumble changes to a renamed copy of Wine's builtin xinput1_4
(dd-directcontroller-wine-xinput.dll), so rumble keeps DroidDeck's force-feedback path without
Wine's lock holding up a game thread. A pass-through mode sends every call to that copy. A
background thread reads the mode file every 250 ms ('1' direct, '0' pass-through) and does the
once-a-second ring and pad-node checks, so a game thread never waits on a file. Based on
Bannerlator's direct XInput DLL (GPL-3.0).

- launch.sh copies the DLLs into the prefix (replacing the links to the tool's builtins, never
  writing through them), sets xinput*=n,b and writes the mode file next to the controller
  folder (DD_DIRECTCONTROLLER_CONTROL) when the game is set to start without Steam;
  DD_DIRECTCONTROLLER=0 starts it in pass-through, and a game no longer set to start without
  Steam gets Wine's links back. DROIDDECK_NO_STEAM is kept in the environment it passes on.
- tools/bionic-runtime/build.sh builds and checks the DLLs (export tables of both ARM64X views,
  imports, no TLS directory, version resource) with a pinned llvm-mingw and runs the host test
  of the ring reader; the workflow caches the toolchain.
- App: a "Direct controller" switch under Controller > Device settings in the session menu,
  shown while the running game uses dd-directcontroller. It writes the mode file, so the game
  moves between the pad state and Wine's own xinput at once, and saves the choice for the game
  (DD_DIRECTCONTROLLER=0). A session deletes the mode file at start, so only a launch that uses
  dd-directcontroller brings the switch back. Translated in every language.


Review fixes: synchronized setting save; the DLL pins itself before its worker threads; pass-through forwards XInputPowerOffController; launch.sh keeps a native XInput DLL that is neither Wine's nor ours; switch requests run in order; XInputEnable reaches Wine's xinput when there is no rumble worker.
This commit is contained in:
The412Banner authored and GitHub committed 2026-12-06 04:16:37 -05:00
1 parent a8224c76a2
commit 59397f0ef9
54 files changed
+2164 -3

No files matched your search

@@ -185,6 +185,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private var unfoldedControls by mutableStateOf(false)
private var unfoldedControlsWithController by mutableStateOf(false)
private var adaptiveSticks by mutableStateOf<Boolean?>(null)
private var directController by mutableStateOf<Boolean?>(null)
private var quickButtons by mutableStateOf<Map<InputCommand, Boolean>>(emptyMap())
private var picturePosition by mutableStateOf("center")
@@ -586,6 +587,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
drawerLayerOpen = false
drawerPinned = false
if (value) {
directController = com.droiddeck.launcher.session.DirectControllerSwitch.state(this)
releaseHeldKeys()
drawerXr = com.droiddeck.launcher.session.xr.XrPanels.showMenu()
drawerDocked = !drawerXr && dockDrawer() && openDockedMenu()
@@ -2140,6 +2142,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
primaryInputLayout?.let { com.droiddeck.launcher.input.InputLibraries.setAdaptiveSticks(this@SessionActivity, it.id, on) }
refreshInputProfile()
},
directController = directController,
onDirectController = { on ->
com.droiddeck.launcher.session.DirectControllerSwitch.set(this@SessionActivity, on)
directController = on
},
showFloatingSteamControls = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad && unfoldedPanel == null &&
oscMode != SessionPrefs.OSC_NEVER && oscMode != SessionPrefs.OSC_STEAM_QAM &&
!steamTouchInUse && OnScreenLayout.supportsFloatingSteamControls(padType, primaryInputLayout),
@@ -50,6 +50,17 @@ object GameEnvironment {
return withScopeValue(config, scope, NO_STEAM, if (on) "1" else null)
}
/** dd-directcontroller on DroidDeck-Bionic: "0" starts the game in pass-through (Wine's own xinput); unset = the pad state. */
const val DIRECT_CONTROLLER = "DD_DIRECTCONTROLLER"
fun gameDirectController(config: Config, scope: String): Boolean =
scope.isEmpty() || config.games[scope]?.get(DIRECT_CONTROLLER) != "0"
fun withGameDirectController(config: Config, scope: String, on: Boolean): Config {
require(scope.isNotEmpty() && validScope(scope))
return withScopeValue(config, scope, DIRECT_CONTROLLER, if (on) null else "0")
}
const val GAME_RESOLUTION = "DROIDDECK_GAME_RESOLUTION"
fun gameResolution(config: Config, scope: String): GameResolution.Choice? =
@@ -0,0 +1,46 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.runtime.LinuxRuntime
import java.io.File
/**
* dd-directcontroller's mode file. DroidDeck-Bionic's launch.sh writes it beside the controller folder when a game set to start
* without Steam reads XInput through dd-directcontroller; the game's DLLs read it while it runs ('1' the pad state, '0' Wine's own
* xinput). No file = the session's game does not use dd-directcontroller.
*/
object DirectControllerSwitch {
const val FILE = "dd-directcontroller.mode"
fun file(context: Context): File = File(LinuxRuntime.sessionRoot(context), "dev/$FILE")
/** The running game's mode, or null when it does not use dd-directcontroller. */
fun state(context: Context): Boolean? = runCatching {
when (file(context).takeIf { it.isFile }?.readText()?.trim()) {
"1" -> true
"0" -> false
else -> null
}
}.getOrNull()
/** One request after another, in call order: the last switch sets both the live mode and the saved choice. */
private val queue = java.util.concurrent.Executors.newSingleThreadExecutor { Thread(it, "dd-directcontroller") }
/** Switches the running game now and remembers the choice for its next start. */
fun set(context: Context, on: Boolean) {
val app = context.applicationContext
queue.execute {
runCatching { file(app).takeIf { it.isFile }?.writeText(if (on) "1\n" else "0\n") }
val scope = NoSteamLaunch.scopeOf(SessionState.program, SessionState.programArgs) { NoSteamLaunch.battleNetTitleScope(app, it) }
if (!scope.isNullOrEmpty() && GameEnvironment.validScope(scope)) runCatching {
GameEnvironmentStore.setGameDirectController(app, scope, on)
}
}
}
/** A session starts without the file: only a launch that uses dd-directcontroller writes it again. */
fun clear(context: Context) {
file(context).delete()
}
}
@@ -91,6 +91,13 @@ object GameEnvironmentStore {
return config
}
@Synchronized
fun setGameDirectController(context: Context, scope: String, on: Boolean): GameEnvironment.Config {
val config = GameEnvironment.withGameDirectController(read(context), scope, on)
save(context, config)
return config
}
@Synchronized
fun setGameResolution(context: Context, scope: String, choice: com.droiddeck.launcher.core.GameResolution.Choice?): GameEnvironment.Config {
val config = GameEnvironment.withGameResolution(read(context), scope, choice)
@@ -1249,6 +1249,7 @@ class SessionService : Service() {
}
private fun addControllerEnvironment(guest: MutableList<String>, fakeInputDir: File, sessionDir: File) {
DirectControllerSwitch.clear(this)
FakeInputWriter.prepareRingSlots(fakeInputDir, 5)
val builtinPad = SessionPrefs.builtinPad(this)
val hiddenPad = SessionState.mode == MODE_STEAM && !builtinPad &&
@@ -414,6 +414,9 @@ class DrawerActions(
val unfoldedControls: Boolean? = null,
val adaptiveSticks: Boolean? = null,
val onAdaptiveSticks: (Boolean) -> Unit = {},
/** dd-directcontroller's mode for the running game; null = the game does not use it. */
val directController: Boolean? = null,
val onDirectController: (Boolean) -> Unit = {},
val showFloatingSteamControls: Boolean = false,
val oscRearButtons: Boolean = false,
val oscTrackpads: Boolean = false,
@@ -792,10 +795,12 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected:
val rumbleLabel = stringResource(R.string.ctrl_rumble)
val airTriggers = a.airTriggers
val airTriggersLabel = stringResource(R.string.air_triggers_title)
if (a.padType != null || c != null || airTriggers != null) SettingsGroup(
val directControllerLabel = stringResource(R.string.ctrl_direct_controller)
if (a.padType != null || c != null || airTriggers != null || a.directController != null) SettingsGroup(
stringResource(R.string.input_device_settings), key = "controller-pad", tag = padTag,
detail = summary(a.padType?.let { padTypes.labelOf(it) }, c?.let { "$rumbleLabel ${if (it.rumble) on else off}" },
airTriggers?.let { "$airTriggersLabel ${if (it.enabled) on else off}" }),
airTriggers?.let { "$airTriggersLabel ${if (it.enabled) on else off}" },
a.directController?.let { "$directControllerLabel ${if (it) on else off}" }),
) {
a.padType?.let { type ->
ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), stringResource(R.string.input_virtual_controller_hint),
@@ -804,6 +809,9 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected:
c?.let {
ToggleRow(host, "rumble", rumbleLabel, null, it.rumble, chipModifier = track("rumble"), onChange = a.onRumble)
}
a.directController?.let {
ToggleRow(host, "direct-controller", directControllerLabel, null, it, chipModifier = track("direct-controller"), onChange = a.onDirectController)
}
airTriggers?.let {
ActionRow(airTriggersLabel, if (it.enabled) on else off, stringResource(R.string.air_triggers_open), onAirTriggers,
modifier = track("air-triggers"))