removed SDL joystick support + SECCOMP fixes

This commit is contained in:
ref-err 2026-07-06 19:46:13 +05:00
parent 6b4dd52ae0
commit 640f83e10e
No known key found for this signature in database
GPG Key ID: 4EA33C4621229029
6 changed files with 50 additions and 74 deletions

View File

@ -28,8 +28,10 @@
#include "keybindings-binding.h" #include "keybindings-binding.h"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_keyboard.h> #include <SDL3/SDL_keyboard.h>
#include <SDL3/SDL_gamepad.h> #include <SDL3/SDL_gamepad.h>
#include <cstdio>
#include <vector> #include <vector>
RB_METHOD(inputUpdate){ 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) { static VALUE setLED(VALUE self, VALUE r, VALUE g, VALUE b) {
if (gc != nullptr) { if (gc != nullptr) {
SDL_SetGamepadLED(gc, NUM2INT(r), NUM2INT(g), NUM2INT(b)); if (!SDL_SetGamepadLED(gc, NUM2INT(r), NUM2INT(g), NUM2INT(b))) {
} else if (js != nullptr) { printf("failed to set gamepad led for gamepad %s: %s\n", SDL_GetGamepadName(gc), SDL_GetError());
SDL_SetJoystickLED(js, NUM2INT(r), NUM2INT(g), NUM2INT(b));
} }
}
return Qnil; 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; Uint16 high_freq = NUM2DBL(high_frequency_rumble) * 65535;
if (gc != nullptr) { if (gc != nullptr) {
SDL_RumbleGamepad(gc, low_freq, high_freq, NUM2INT(duration_ms)); printf("low freq: %d, high freq: %d, duration: %d", low_freq, high_freq, NUM2INT(duration_ms));
} else if (js != nullptr) { if (!SDL_RumbleGamepad(gc, low_freq, high_freq, NUM2INT(duration_ms))) {
SDL_RumbleJoystick(js, low_freq, high_freq, NUM2INT(duration_ms)); printf("failed to rumble gamepad %s: %s\n", SDL_GetGamepadName(gc), SDL_GetError());
} }
}
return Qnil; return Qnil;
} }

View File

@ -50,3 +50,5 @@ Mirrors!
Nice eror formating in Events script command Nice eror formating in Events script command
Optimizations for steamshim Optimizations for steamshim
crash() function update crash() function update
removed SDL joystick support
fixed SECCOMP blocking UDEV sockets

View File

@ -16,7 +16,7 @@ begin
Graphics.frame_rate = 60 Graphics.frame_rate = 60
Font.default_size = 20 Font.default_size = 20
#debug shit #debug shit
Input.set_led(0, 255, 0) Input.set_led(255, 150, 30)
# Load persistent data # Load persistent data
Persistent.load Persistent.load

View File

@ -21,10 +21,13 @@
#include "eventthread.h" #include "eventthread.h"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h> #include <SDL3/SDL_events.h>
#include <SDL3/SDL_joystick.h> #include <SDL3/SDL_joystick.h>
#include <SDL3/SDL_gamepad.h> #include <SDL3/SDL_gamepad.h>
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_messagebox.h> #include <SDL3/SDL_messagebox.h>
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL_timer.h> #include <SDL3/SDL_timer.h>
#include <SDL3/SDL_thread.h> #include <SDL3/SDL_thread.h>
#include <SDL3/SDL_touch.h> #include <SDL3/SDL_touch.h>
@ -39,6 +42,7 @@
#include <SDL3/SDL_stdinc.h> #include <SDL3/SDL_stdinc.h>
#include <cstdio>
#include <map> #include <map>
#include <iostream> #include <iostream>
@ -90,7 +94,6 @@ enum{
static uint32_t usrIdStart; static uint32_t usrIdStart;
SDL_Gamepad* gc = nullptr; SDL_Gamepad* gc = nullptr;
SDL_Joystick* js = nullptr;
bool EventThread::allocUserEvents(){ bool EventThread::allocUserEvents(){
usrIdStart = SDL_RegisterEvents(EVENT_COUNT); usrIdStart = SDL_RegisterEvents(EVENT_COUNT);
@ -139,22 +142,24 @@ void EventThread::process(RGSSThreadData &rtData){
bool terminate = false; bool terminate = false;
std::map<int, SDL_Gamepad*> controllers; std::map<int, SDL_Gamepad*> gamepads;
std::map<int, SDL_Joystick*> joysticks;
int tmpstupidshit; int count = 0;
SDL_GetJoysticks(&tmpstupidshit); int jId = 0;
SDL_JoystickID *ids = SDL_GetGamepads(&count);
for (int i = 0; i < tmpstupidshit; ++i) { for(int i = 0; i < count; i++) {
if (SDL_IsGamepad(i)) { SDL_Gamepad* gamepd = SDL_OpenGamepad(ids[i]);
//Load as game controller
gc = SDL_OpenGamepad(i); if (gc == nullptr) {
int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc)); gc = gamepd;
controllers[id] = gc; jId = ids[i];
} else { }
//Fall back to joystick
js = SDL_OpenJoystick(i); printf("Gamepad connected: %s", SDL_GetGamepadName(gc));
joysticks[SDL_GetJoystickID(js)] = js;
if (i > 0) {
SDL_CloseGamepad(gamepd);
} }
} }
@ -168,7 +173,6 @@ void EventThread::process(RGSSThreadData &rtData){
int i; int i;
int id; int id;
std::map<int, SDL_Joystick*>::iterator jsit;
std::map<int, SDL_Gamepad*>::iterator gcit; std::map<int, SDL_Gamepad*>::iterator gcit;
SDL_GetWindowSize(win, &winW, &winH); // SDL_GL_GetDrawableSize(win, &winW, &winH); SDL_GetWindowSize(win, &winW, &winH); // SDL_GL_GetDrawableSize(win, &winW, &winH);
@ -179,7 +183,6 @@ void EventThread::process(RGSSThreadData &rtData){
break; break;
} }
/* Preselect and discard unwanted events here */
switch (event.type){ switch (event.type){
case SDL_EVENT_MOUSE_BUTTON_DOWN : case SDL_EVENT_MOUSE_BUTTON_DOWN :
case SDL_EVENT_MOUSE_BUTTON_UP : case SDL_EVENT_MOUSE_BUTTON_UP :
@ -345,51 +348,15 @@ void EventThread::process(RGSSThreadData &rtData){
break; break;
case SDL_EVENT_GAMEPAD_ADDED: case SDL_EVENT_GAMEPAD_ADDED:
gc = SDL_OpenGamepad(event.jdevice.which); gc = SDL_OpenGamepad(event.gdevice.which);
id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc)); id = SDL_GetJoystickID(SDL_GetGamepadJoystick(gc));
controllers[id] = gc; gamepads[id] = gc;
break; break;
case SDL_EVENT_GAMEPAD_REMOVED: case SDL_EVENT_GAMEPAD_REMOVED:
gcit = controllers.find(event.jdevice.which); gcit = gamepads.find(event.gdevice.which);
SDL_CloseGamepad(gcit->second); SDL_CloseGamepad(gcit->second);
controllers.erase(gcit); gamepads.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();
}
break; break;
case SDL_EVENT_MOUSE_BUTTON_DOWN : case SDL_EVENT_MOUSE_BUTTON_DOWN :
@ -491,10 +458,8 @@ void EventThread::process(RGSSThreadData &rtData){
/* Just in case */ /* Just in case */
rtData.syncPoint.resumeThreads(); rtData.syncPoint.resumeThreads();
for (gcit = controllers.begin(); gcit != controllers.end(); ++gcit) for (gcit = gamepads.begin(); gcit != gamepads.end(); ++gcit)
SDL_CloseGamepad(gcit->second); SDL_CloseGamepad(gcit->second);
for (jsit = joysticks.begin(); jsit != joysticks.end(); ++jsit)
SDL_CloseJoystick(jsit->second);
} }
bool EventThread::eventFilter(void *data, SDL_Event *event){ bool EventThread::eventFilter(void *data, SDL_Event *event){

View File

@ -45,7 +45,6 @@ union SDL_Event;
#define MAX_FINGERS 4 #define MAX_FINGERS 4
extern SDL_Gamepad* gc; extern SDL_Gamepad* gc;
extern SDL_Joystick* js;
class EventThread{ class EventThread{
public: public:

View File

@ -38,11 +38,16 @@ void SecurityManagerInit(){
//Extra rules //Extra rules
//Deny all network connections //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))){ 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"; 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))){ 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)";
} }