Open zach-morris opened 4 years ago
I noticed this too, and resulted in not updating several add-ons where the settings "disappeared". My thoughts were it's probably related to the new options api: https://github.com/libretro/RetroArch/blob/master/libretro-common/include/libretro.h#L1109
Basically we need to set the int pointed to by arg
to 1. As python doesn't do pointers, I have no clue how to do this. E.g. in C++ it would be:
*arg = 1;
@Rechi are you familiar with python ctypes?
I'll note now that I'm looking that some addons have settings that are somewhat garbled, showing multiple instances of the same possible setting values now in many addons. game.libretro.uae for example:
settings.xml shows:
<setting label="30001" type="select" id="puae_analogmouse" values="right|disabled|left|right|both" default="right"/>
<setting label="30002" type="select" id="puae_analogmouse_deadzone" values="15|0|5|10|15|20|25|30|35" default="15"/>
<setting label="30003" type="select" id="puae_analogmouse_speed" values="1.0|0.5|0.6|0.7|0.8|0.9|1.0|1.1|1.2|1.3|1.4|1.5" default="1.0"/>
...
Playing around with this, I got halfway there. A new cb_type=53 needs to be added, which I think was an API change for libretro.
Something like:
elif cb_type==53: # RETRO_ENVIRONMENT_SET_CORE_OPTIONS
index = 0
while True:
var = ctypes.cast(arg, ctypes.POINTER(
self.RetroOptions))[index]
...
But the part I can't figure out is the definition of the RetroOptions. The 'values' are structs within structs and I dont understand ctypes fully:
class RetroOptions(ctypes.Structure):
""" struct libretro_options """
_fields_ = [
('key', ctypes.c_char_p),
('desc', ctypes.c_char_p),
('info', ctypes.c_char_p),
('value', ???)
]
Good progress so far. I have a feeling a nontrivial understanding of ctypes is needed. Per the API, cb_type=53
should only be called if cb_type=52
sets an int at the specified address pointed to by the argument, and pointer indirection isn't something I know how to with ctypes today
The API function we need to handle is RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION: https://github.com/libretro/RetroArch/blob/master/libretro-common/include/libretro.h#L1117. The parameter is unsigned *
, which means it looks like this:
void environment_cb(RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION, void *data)
{
unsigned int *version = reinterpret_cast<unsigned int*>(data);
*version = 2;
}
So in ctypes, you take the void*
parameters from the function, and interpret it as an unsigned int *
, then assign the number 2 to the memory pointed to by the pointer.
Just adding some tinkering I've done with this.
In libretro_ctypes.py I created two additional structs:
class retro_core_option_value(ctypes.Structure):
_fields_ = [("value", ctypes.c_char_p),
("label", ctypes.c_char_p)]
class retro_core_option_definition(ctypes.Structure):
_fields_ = [("key", ctypes.c_char_p),
("description", ctypes.c_char_p),
("info", ctypes.c_char_p),
("values", ctypes.POINTER(retro_core_option_value)*RETRO_NUM_CORE_OPTION_VALUES_MAX),
("default_value", ctypes.c_char_p),
]
And then created another cb_type for testing:
elif cb_type == 53: #RETRO_ENVIRONMENT_SET_CORE_OPTIONS
num_options = 0
while True:
core_option = ctypes.cast(arg, ctypes.POINTER(retro_core_option_definition))[num_options]
num_options+=1
if core_option.key is None and core_option.values is None:
break
else:
num_values = 0
if core_option.key is not None:
print("Core option key:", core_option.key or '')
if core_option.description is not None:
print("Core option short description:", core_option.description or '')
if core_option.info is not None:
print("Core option info:", core_option.info or '')
if core_option.default_value is not None:
print("Core option default_value:", core_option.default_value or '')
while True:
core_option_value = ctypes.cast(core_option.values,ctypes.POINTER(retro_core_option_value))[num_values]
num_values+=1
if core_option_value.value is None and core_option_value.label is None:
break
else:
if core_option_value.value is not None:
print("Core options value:", core_option_value.value or '')
if core_option_value.label is not None:
print("Core options label:", core_option_value.label or '')
This method does pull some of the settings for RETRO_ENVIRONMENT_SET_CORE_OPTIONS, but it quickly gets out of sync. I believe the issue is because retro_core_option_value struct is dynamically sized vs. actually sized to the MAX. My best stackexchange searching can't get past how to dynamically define the struct size within the cb call (I don't speak C, so thats probably the issue, and maybe thats what you were referring to with assigning the number 2 to the memory pointed to by the pointer.).
Unfortunately I followed pretty much the exact same path and hit a wall when I couldn't find the documentation I needed to do certain things. I think the solution is to create a lightweight C++ program that loads the core, calls the retro_* functions, and translates their results to stdout, where it's then parsed by the Python code.
Actually, I just remembered I already did this: https://github.com/garbear/repository.libretro/tree/master/libretro-extract. We could use the libretro-extract utility to get settings from the libretro options v2 API.
Full disclosure, I'm trying to troubleshoot my own code utilizing kodi-game-scripting, but I think this would likely effect kodi-game-scripting's ability to generate the official addons as well.
The issue I've found with this code is that it doesn't consistently pull core settings from the binary. Here's an example:
From Retroarch directly, I can see the first binary should have the following variables:
The problem seems to be here, where the correct RETRO_ENVIRONMENT_SET_VARIABLES cb_type is never called to pull the variables for the first binary. Based on the code, I can't figure out why however.