From 640f83e10e33ae57d6f0ffe0dbd508b171fe7025 Mon Sep 17 00:00:00 2001 From: ref-err Date: Mon, 6 Jul 2026 19:46:13 +0500 Subject: [PATCH] removed SDL joystick support + SECCOMP fixes --- binding-mri/input-binding.cpp | 17 ++++--- changelogs/0.1.1.txt | 2 + scripts/Main.rb | 2 +- src/eventthread.cpp | 91 +++++++++++------------------------ src/eventthread.h | 1 - src/security.cpp | 11 +++-- 6 files changed, 50 insertions(+), 74 deletions(-) diff --git a/binding-mri/input-binding.cpp b/binding-mri/input-binding.cpp index e2ae4a5..27feece 100644 --- a/binding-mri/input-binding.cpp +++ b/binding-mri/input-binding.cpp @@ -28,8 +28,10 @@ #include "keybindings-binding.h" +#include #include #include +#include #include RB_METHOD(inputUpdate){ @@ -279,10 +281,11 @@ static VALUE setBinding(VALUE self, VALUE rb_arr, VALUE rb_target){ static VALUE setLED(VALUE self, VALUE r, VALUE g, VALUE b) { if (gc != nullptr) { - SDL_SetGamepadLED(gc, NUM2INT(r), NUM2INT(g), NUM2INT(b)); - } else if (js != nullptr) { - SDL_SetJoystickLED(js, NUM2INT(r), NUM2INT(g), NUM2INT(b)); + if (!SDL_SetGamepadLED(gc, NUM2INT(r), NUM2INT(g), NUM2INT(b))) { + printf("failed to set gamepad led for gamepad %s: %s\n", SDL_GetGamepadName(gc), SDL_GetError()); + } } + return Qnil; } @@ -291,10 +294,12 @@ static VALUE rumble(VALUE self, VALUE low_frequency_rumble, VALUE high_frequency Uint16 high_freq = NUM2DBL(high_frequency_rumble) * 65535; if (gc != nullptr) { - SDL_RumbleGamepad(gc, low_freq, high_freq, NUM2INT(duration_ms)); - } else if (js != nullptr) { - SDL_RumbleJoystick(js, low_freq, high_freq, NUM2INT(duration_ms)); + printf("low freq: %d, high freq: %d, duration: %d", low_freq, high_freq, NUM2INT(duration_ms)); + if (!SDL_RumbleGamepad(gc, low_freq, high_freq, NUM2INT(duration_ms))) { + printf("failed to rumble gamepad %s: %s\n", SDL_GetGamepadName(gc), SDL_GetError()); + } } + return Qnil; } diff --git a/changelogs/0.1.1.txt b/changelogs/0.1.1.txt index 6e96aba..92eb940 100644 --- a/changelogs/0.1.1.txt +++ b/changelogs/0.1.1.txt @@ -50,3 +50,5 @@ Mirrors! Nice eror formating in Events script command Optimizations for steamshim crash() function update +removed SDL joystick support +fixed SECCOMP blocking UDEV sockets \ No newline at end of file diff --git a/scripts/Main.rb b/scripts/Main.rb index c10ac3e..57d9c2f 100644 --- a/scripts/Main.rb +++ b/scripts/Main.rb @@ -16,7 +16,7 @@ begin Graphics.frame_rate = 60 Font.default_size = 20 #debug shit - Input.set_led(0, 255, 0) + Input.set_led(255, 150, 30) # Load persistent data Persistent.load diff --git a/src/eventthread.cpp b/src/eventthread.cpp index acd0637..f99e2ba 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -21,10 +21,13 @@ #include "eventthread.h" +#include #include #include #include +#include #include +#include #include #include #include @@ -39,6 +42,7 @@ #include +#include #include #include @@ -90,7 +94,6 @@ enum{ static uint32_t usrIdStart; SDL_Gamepad* gc = nullptr; -SDL_Joystick* js = nullptr; bool EventThread::allocUserEvents(){ usrIdStart = SDL_RegisterEvents(EVENT_COUNT); @@ -139,24 +142,26 @@ void EventThread::process(RGSSThreadData &rtData){ bool terminate = false; - std::map controllers; - std::map joysticks; + std::map gamepads; - int tmpstupidshit; - SDL_GetJoysticks(&tmpstupidshit); + int count = 0; + int jId = 0; + SDL_JoystickID *ids = SDL_GetGamepads(&count); - for (int i = 0; i < tmpstupidshit; ++i) { - if (SDL_IsGamepad(i)) { - //Load as game controller - gc = SDL_OpenGamepad(i); - int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc)); - controllers[id] = gc; - } else { - //Fall back to joystick - js = SDL_OpenJoystick(i); - joysticks[SDL_GetJoystickID(js)] = js; + for(int i = 0; i < count; i++) { + SDL_Gamepad* gamepd = SDL_OpenGamepad(ids[i]); + + if (gc == nullptr) { + gc = gamepd; + jId = ids[i]; } - } + + printf("Gamepad connected: %s", SDL_GetGamepadName(gc)); + + if (i > 0) { + SDL_CloseGamepad(gamepd); + } + } char buffer[128]; @@ -168,18 +173,16 @@ void EventThread::process(RGSSThreadData &rtData){ int i; int id; - std::map::iterator jsit; std::map::iterator gcit; SDL_GetWindowSize(win, &winW, &winH); // SDL_GL_GetDrawableSize(win, &winW, &winH); - while (true){ - if (!SDL_WaitEvent(&event)){ + while (true) { + if (!SDL_WaitEvent(&event)) { Debug() << "[EventThread::process] EventThread: Event error"; break; } - /* Preselect and discard unwanted events here */ switch (event.type){ case SDL_EVENT_MOUSE_BUTTON_DOWN : case SDL_EVENT_MOUSE_BUTTON_UP : @@ -345,51 +348,15 @@ void EventThread::process(RGSSThreadData &rtData){ break; case SDL_EVENT_GAMEPAD_ADDED: - gc = SDL_OpenGamepad(event.jdevice.which); + gc = SDL_OpenGamepad(event.gdevice.which); id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc)); - controllers[id] = gc; + gamepads[id] = gc; break; case SDL_EVENT_GAMEPAD_REMOVED: - gcit = controllers.find(event.jdevice.which); + gcit = gamepads.find(event.gdevice.which); SDL_CloseGamepad(gcit->second); - controllers.erase(gcit); - break; - - case SDL_EVENT_JOYSTICK_BUTTON_DOWN : - if (joysticks.find(event.jbutton.which) != joysticks.end()) - joyState.buttons[event.jbutton.button] = true; - break; - - case SDL_EVENT_JOYSTICK_BUTTON_UP : - if (joysticks.find(event.jbutton.which) != joysticks.end()) - joyState.buttons[event.jbutton.button] = false; - break; - - case SDL_EVENT_JOYSTICK_HAT_MOTION : - if (joysticks.find(event.jbutton.which) != joysticks.end()) - joyState.hats[event.jhat.hat] = event.jhat.value; - break; - - case SDL_EVENT_JOYSTICK_AXIS_MOTION : - if (joysticks.find(event.jbutton.which) != joysticks.end()) - joyState.axes[event.jaxis.axis] = event.jaxis.value; - break; - - case SDL_EVENT_JOYSTICK_ADDED : - if (SDL_IsGamepad(event.jdevice.which)) - break; - js = SDL_OpenJoystick(event.jdevice.which); - joysticks[SDL_GetJoystickID(js)] = js; - break; - - case SDL_EVENT_JOYSTICK_REMOVED : - jsit = joysticks.find(event.jdevice.which); - if (jsit != joysticks.end()) { - SDL_CloseJoystick(jsit->second); - joysticks.erase(jsit); - resetInputStates(); - } + gamepads.erase(gcit); break; case SDL_EVENT_MOUSE_BUTTON_DOWN : @@ -491,10 +458,8 @@ void EventThread::process(RGSSThreadData &rtData){ /* Just in case */ rtData.syncPoint.resumeThreads(); - for (gcit = controllers.begin(); gcit != controllers.end(); ++gcit) + for (gcit = gamepads.begin(); gcit != gamepads.end(); ++gcit) SDL_CloseGamepad(gcit->second); - for (jsit = joysticks.begin(); jsit != joysticks.end(); ++jsit) - SDL_CloseJoystick(jsit->second); } bool EventThread::eventFilter(void *data, SDL_Event *event){ diff --git a/src/eventthread.h b/src/eventthread.h index 6f9efb6..5b6386a 100644 --- a/src/eventthread.h +++ b/src/eventthread.h @@ -45,7 +45,6 @@ union SDL_Event; #define MAX_FINGERS 4 extern SDL_Gamepad* gc; -extern SDL_Joystick* js; class EventThread{ public: diff --git a/src/security.cpp b/src/security.cpp index 36e26ad..7bfe35e 100644 --- a/src/security.cpp +++ b/src/security.cpp @@ -38,11 +38,16 @@ void SecurityManagerInit(){ //Extra rules //Deny all network connections - if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_NE, AF_UNIX))){ - Debug() << "seccomp_rule_add failed for extra rules"; + if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_INET))){ + Debug() << "seccomp_rule_add failed for extra rules (socket AF_INET)"; } + + if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1, SCMP_CMP(0, SCMP_CMP_EQ, AF_INET6))){ + Debug() << "seccomp_rule_add failed for extra rules (socket AF_INET6)"; + } + if(seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socketpair), 1, SCMP_CMP(0, SCMP_CMP_NE, AF_UNIX))){ - Debug() << "seccomp_rule_add failed for extra rules"; + Debug() << "seccomp_rule_add failed for extra rules (socketpair)"; }