Keyboard/Joystick config bin file loads either from next to the game or wherever the emu_lib is located

This commit is contained in:
Filip Kolinsky
2026-09-28 16:19:27 +02:00
committed by voidderef
parent 33a599e2f0
commit 727f92ddb3
6 changed files with 119 additions and 2 deletions
@@ -60,6 +60,21 @@ bool ptapi_io_piubtn_open()
struct io_util_joystick_util_device_info device_info[MAX_NUM_JOYSTICKS];
size_t devices_connected;
if (util_proc_get_folder_path_shared_object(
(void *) ptapi_io_piubtn_open, path, sizeof(path))) {
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration from emu lib path: %s", config_path);
if (ptapi_io_piubtn_joystick_util_conf_read_from_file(
&ptapi_io_piubtn_joystick_util_conf, config_path)) {
free(config_path);
goto conf_loaded;
}
free(config_path);
}
// The game changes the working directory to the 'game' sub-folder. Therefore,
// ./my-config does not work here.
if (!util_proc_get_folder_path_executable_no_ld_linux(path, sizeof(path))) {
@@ -69,6 +84,8 @@ bool ptapi_io_piubtn_open()
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration from executable path: %s", config_path);
if (!ptapi_io_piubtn_joystick_util_conf_read_from_file(
&ptapi_io_piubtn_joystick_util_conf, config_path)) {
log_error("Loading joystick config file %s failed.", CONFIG_FILENAME);
@@ -78,6 +95,8 @@ bool ptapi_io_piubtn_open()
free(config_path);
conf_loaded:
devices_connected =
io_util_joystick_util_scan(device_info, MAX_NUM_JOYSTICKS);
@@ -48,6 +48,22 @@ bool ptapi_io_piubtn_open()
char path[PATH_MAX];
char *config_path;
if (util_proc_get_folder_path_shared_object(
(void *) ptapi_io_piubtn_open, path, sizeof(path))) {
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration from emu lib path: %s", config_path);
if (ptapi_io_piubtn_keyboard_util_conf_read_from_file(
&ptapi_io_piubtn_keyboard_conf, config_path)) {
free(config_path);
memset(ptapi_io_piubtn_keyboard_buffer, 0, sizeof(bool) * KEY_MAP_SIZE);
return true;
}
free(config_path);
}
// The game changes the working directory to the 'game' sub-folder. Therefore,
// ./my-config does not work here.
if (!util_proc_get_folder_path_executable_no_ld_linux(path, sizeof(path))) {
@@ -57,6 +73,8 @@ bool ptapi_io_piubtn_open()
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration from executable path: %s", config_path);
if (!ptapi_io_piubtn_keyboard_util_conf_read_from_file(
&ptapi_io_piubtn_keyboard_conf, config_path)) {
log_error("Loading keyboard config file %s failed.", config_path);
+18 -1
View File
@@ -60,6 +60,21 @@ bool ptapi_io_piuio_open()
struct io_util_joystick_util_device_info device_info[MAX_NUM_JOYSTICKS];
size_t devices_connected;
if (util_proc_get_folder_path_shared_object(
(void *) ptapi_io_piuio_open, path, sizeof(path))) {
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration from emu lib path: %s", config_path);
if (ptapi_io_piuio_joystick_util_conf_read_from_file(
&ptapi_io_piuio_joystick_util_conf, config_path)) {
free(config_path);
goto conf_loaded;
}
free(config_path);
}
// The game changes the working directory to the 'game' sub-folder. Therefore,
// ./my-config does not work here.
if (!util_proc_get_folder_path_executable_no_ld_linux(path, sizeof(path))) {
@@ -69,7 +84,7 @@ bool ptapi_io_piuio_open()
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration: ", config_path);
log_info("Loading configuration from executable path: %s", config_path);
if (!ptapi_io_piuio_joystick_util_conf_read_from_file(
&ptapi_io_piuio_joystick_util_conf, config_path)) {
@@ -80,6 +95,8 @@ bool ptapi_io_piuio_open()
free(config_path);
conf_loaded:
devices_connected =
io_util_joystick_util_scan(device_info, MAX_NUM_JOYSTICKS);
+17 -1
View File
@@ -47,6 +47,22 @@ bool ptapi_io_piuio_open()
char path[PATH_MAX];
char *config_path;
if (util_proc_get_folder_path_shared_object(
(void *) ptapi_io_piuio_open, path, sizeof(path))) {
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration from emu lib path: %s", config_path);
if (ptapi_io_piuio_keyboard_util_conf_read_from_file(
&ptapi_io_piuio_keyboard_conf, config_path)) {
free(config_path);
memset(ptapi_io_piuio_keyboard_buffer, 0, sizeof(bool) * KEY_MAP_SIZE);
return true;
}
free(config_path);
}
// The game changes the working directory to the 'game' sub-folder. Therefore,
// ./my-config does not work here.
if (!util_proc_get_folder_path_executable_no_ld_linux(path, sizeof(path))) {
@@ -56,7 +72,7 @@ bool ptapi_io_piuio_open()
config_path = util_str_merge(path, CONFIG_FILENAME);
log_info("Loading configuration: ", config_path);
log_info("Loading configuration from executable path: %s", config_path);
if (!ptapi_io_piuio_keyboard_util_conf_read_from_file(
&ptapi_io_piuio_keyboard_conf, config_path)) {
+35
View File
@@ -1,5 +1,6 @@
#define LOG_MODULE "util-proc"
#include <dlfcn.h>
#include <errno.h>
#include <linux/limits.h>
#include <string.h>
@@ -205,6 +206,40 @@ bool util_proc_get_folder_path_executable_no_ld_linux(char *buffer, size_t size)
}
}
bool util_proc_get_folder_path_shared_object(
void *symbol, char *buffer, size_t size)
{
Dl_info info;
if (!symbol || !buffer || size == 0) {
return false;
}
if (!dladdr(symbol, &info) || !info.dli_fname) {
return false;
}
if (strlen(info.dli_fname) >= size) {
return false;
}
strcpy(buffer, info.dli_fname);
// If shared object in the root folder, keep the single /
size_t pos = strlen(buffer) - 1;
while (pos > 0 && buffer[pos] != '/') {
buffer[pos] = '\0';
pos--;
}
// delete /
if (pos > 0) {
buffer[pos] = '\0';
}
return true;
}
void util_proc_log_info()
{
log_info(
+12
View File
@@ -43,6 +43,18 @@ bool util_proc_get_folder_path_executable(char *buffer, size_t size);
bool util_proc_get_folder_path_executable_no_ld_linux(
char *buffer, size_t size);
/**
* Get the full path of the folder of the shared object that contains the
* supplied symbol.
*
* @param symbol Pointer to any symbol in the target shared object.
* @param buffer Buffer to read the path into.
* @param size Size of the buffer.
* @return True on success, false on failure.
*/
bool util_proc_get_folder_path_shared_object(
void *symbol, char *buffer, size_t size);
/**
* Log information about the current process to the console.
*/