mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
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.
143 lines
5.7 KiB
C
143 lines
5.7 KiB
C
/*
|
|
* dd-directcontroller host test: the ring snapshot reader (dd_directcontroller_ring.h) against a writer that follows
|
|
* FakeInputWriter.writeSnapshotLocked, on a shared file mapping (the app and the guest map the same file),
|
|
* plus the XInput mapping and the FAKE_EVDEV_MEMFD_PATHS parser.
|
|
*/
|
|
#include <fcntl.h>
|
|
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
|
|
#include "dd_directcontroller_ring.h"
|
|
|
|
static int failures;
|
|
#define CHECK(c, ...) do { if (!(c)) { failures++; printf("FAIL %s:%d: ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0)
|
|
|
|
static uint8_t *wmap;
|
|
static volatile int stop;
|
|
|
|
static void put32(uint32_t off, uint32_t v) { __atomic_store_n((uint32_t *)(void *)(wmap + off), v, __ATOMIC_RELAXED); }
|
|
static void put64(uint32_t off, uint64_t v) { __atomic_store_n((uint64_t *)(void *)(wmap + off), v, __ATOMIC_RELAXED); }
|
|
|
|
static void header(void) {
|
|
put32(DDC_OFF_MAGIC, DDC_RING_MAGIC);
|
|
put32(DDC_OFF_VERSION, DDC_RING_VERSION);
|
|
put32(DDC_OFF_EVENT_SIZE, DDC_RING_EVENT_SIZE);
|
|
put32(DDC_OFF_CAPACITY, DDC_RING_CAPACITY);
|
|
}
|
|
|
|
/* FakeInputWriter.writeSnapshotLocked: seq + 1, fence, fields, fence, seq + 2 */
|
|
static void publish(uint64_t *seq, uint32_t buttons, const int16_t axes[8]) {
|
|
put64(DDC_OFF_SNAP_SEQ, *seq + 1);
|
|
__atomic_thread_fence(__ATOMIC_RELEASE);
|
|
put32(DDC_OFF_SNAP_BUTTONS, buttons);
|
|
for (int k = 0; k < 8; k++)
|
|
__atomic_store_n((int16_t *)(void *)(wmap + DDC_OFF_SNAP_AXES + 2 * k), axes[k], __ATOMIC_RELAXED);
|
|
__atomic_thread_fence(__ATOMIC_RELEASE);
|
|
put64(DDC_OFF_SNAP_SEQ, *seq + 2);
|
|
*seq += 2;
|
|
}
|
|
|
|
/* Every field carries the same counter, so a torn read shows up as fields that differ. */
|
|
static uint64_t writer_seq;
|
|
|
|
static void *writer(void *arg) {
|
|
(void)arg;
|
|
uint64_t seq = writer_seq; /* the sequence continues: a reused value would let a stale read pass (ABA) */
|
|
uint32_t n = 1;
|
|
while (!stop) {
|
|
int16_t v = (int16_t)(n & 0x3fff);
|
|
int16_t axes[8] = {v, v, v, v, v, v, v, v};
|
|
publish(&seq, (uint32_t)v, axes);
|
|
n++;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static void take(void *ctx, uint32_t slot, const char *p, size_t len) {
|
|
char *out = ctx;
|
|
char buf[64];
|
|
snprintf(buf, sizeof buf, "%u:%.*s|", slot, (int)len, p);
|
|
strcat(out, buf);
|
|
}
|
|
DDC_DEFINE_PARSE_PATHS(parse_paths, char)
|
|
|
|
int main(void) {
|
|
char path[] = "/tmp/ddc-ring-XXXXXX";
|
|
int fd = mkstemp(path);
|
|
CHECK(fd >= 0, "mkstemp");
|
|
size_t size = DDC_RING_HEADER_SIZE + DDC_RING_CAPACITY * DDC_RING_EVENT_SIZE;
|
|
CHECK(ftruncate(fd, (off_t)size) == 0, "ftruncate");
|
|
wmap = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
const uint8_t *rmap = mmap(NULL, DDC_RING_HEADER_SIZE, PROT_READ, MAP_SHARED, fd, 0);
|
|
CHECK(wmap != MAP_FAILED && rmap != MAP_FAILED, "mmap");
|
|
unlink(path);
|
|
|
|
CHECK(!ddc_valid(rmap), "an empty file is not a ring");
|
|
header();
|
|
CHECK(ddc_valid(rmap), "a version-2 header is a ring");
|
|
put32(DDC_OFF_VERSION, 1);
|
|
CHECK(!ddc_valid(rmap), "version 1 is refused");
|
|
put32(DDC_OFF_VERSION, DDC_RING_VERSION);
|
|
|
|
/* mapping */
|
|
uint64_t seq = 0;
|
|
int16_t axes[8] = {1000, 2000, -3000, -32767, 255, 128, -1, 1};
|
|
uint32_t buttons = (1u << DDC_B_A) | (1u << DDC_B_TR) | (1u << DDC_B_START) | (1u << DDC_B_MODE) | (1u << DDC_B_QAM);
|
|
publish(&seq, buttons, axes);
|
|
ddc_snap s;
|
|
CHECK(ddc_snapshot(rmap, &s, 64), "snapshot of a settled ring");
|
|
CHECK(s.seq == 2, "seq %u", s.seq);
|
|
ddc_pad p;
|
|
ddc_map(&s, 0, &p);
|
|
CHECK(p.buttons == (DDC_XI_A | DDC_XI_RIGHT_SHOULDER | DDC_XI_START | DDC_XI_DPAD_LEFT | DDC_XI_DPAD_DOWN),
|
|
"buttons 0x%04x (no Guide, no QAM, hat left + down)", p.buttons);
|
|
CHECK(p.lx == 1000 && p.ly == -2000 && p.rx == -3000 && p.ry == 32767, "sticks %d %d %d %d (Y flipped)", p.lx, p.ly,
|
|
p.rx, p.ry);
|
|
CHECK(p.rt == 255 && p.lt == 128, "triggers lt %u rt %u", p.lt, p.rt);
|
|
ddc_map(&s, 1, &p);
|
|
CHECK(p.buttons & DDC_XI_GUIDE, "Guide in GetStateEx");
|
|
int16_t edge[8] = {INT16_MIN, INT16_MIN, 0, 0, -5, 300, 0, -1};
|
|
publish(&seq, 0, edge);
|
|
CHECK(ddc_snapshot(rmap, &s, 64), "snapshot");
|
|
ddc_map(&s, 0, &p);
|
|
CHECK(p.ly == INT16_MAX && p.lt == 255 && p.rt == 0 && p.buttons == DDC_XI_DPAD_UP, "edges: ly %d lt %u rt %u b 0x%x",
|
|
p.ly, p.lt, p.rt, p.buttons);
|
|
|
|
/* an odd seq (a write in progress) is never taken */
|
|
put64(DDC_OFF_SNAP_SEQ, seq + 1);
|
|
CHECK(!ddc_snapshot(rmap, &s, 64), "a snapshot mid-write is refused");
|
|
put64(DDC_OFF_SNAP_SEQ, seq);
|
|
|
|
/* no torn reads against a running writer; the state before its first publish is consistent too */
|
|
int16_t zero[8] = {0};
|
|
publish(&seq, 0, zero);
|
|
writer_seq = seq;
|
|
pthread_t t;
|
|
pthread_create(&t, NULL, writer, NULL);
|
|
unsigned ok = 0, lapped = 0, torn = 0;
|
|
for (unsigned i = 0; i < 2000000u; i++) {
|
|
if (!ddc_snapshot(rmap, &s, 64)) { lapped++; continue; }
|
|
ok++;
|
|
for (int k = 1; k < 8; k++)
|
|
if (s.axes[k] != s.axes[0]) { torn++; break; }
|
|
if ((int16_t)s.buttons != s.axes[0]) torn++;
|
|
}
|
|
stop = 1;
|
|
pthread_join(t, NULL);
|
|
CHECK(torn == 0, "%u torn snapshots", torn);
|
|
CHECK(ok > 0, "no snapshot taken");
|
|
printf("concurrent: %u snapshots, %u lapped, %u torn\n", ok, lapped, torn);
|
|
|
|
/* FAKE_EVDEV_MEMFD_PATHS */
|
|
char got[256] = "";
|
|
parse_paths("0=/a/r0;1=/a/r1;4=/a/mouse;x=bad;2=;3=/a/r3", take, got, 4);
|
|
CHECK(!strcmp(got, "0:/a/r0|1:/a/r1|3:/a/r3|"), "parsed '%s' (slot 4 = mouse and malformed entries skipped)", got);
|
|
|
|
printf(failures ? "host_test: %d failure(s)\n" : "host_test: OK\n", failures);
|
|
return failures ? 1 : 0;
|
|
}
|