Cxbx-Reloaded / XbSymbolDatabase

Xbox Symbol Database library
MIT License
24 stars 10 forks source link

Derive XInput device type exports #71

Closed JayFoxRox closed 5 years ago

JayFoxRox commented 5 years ago

Device types which are part of the XDK libraries, should be derived, as they are necessary to use / emulate the XInput APIs.

This is some code I've used in one of my projects:

// The XPP gamepad types are not found by XbSymbolDatabase
// We derive them from GetTypeInformation
//FIXME: If this is NULL, there's another strategy for older XDKs:
//       https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/blob/2e5b9562e0f93af9e475660451c6177ea6dd41c2/src/core/hle/XAPI/Xapi.cpp#L162
write_log("Trying to find XPP device types\n");
assert(GetTypeInformation != NULL);
struct {
  UCHAR xid_devtype;
  void** xdevice_type;
} xdevice_types[] = {
  { XID_DEVTYPE_GAMECONTROLLER, &XDEVICE_TYPE_GAMEPAD }, // 0x00062274 //FIXME: !!!
  { XID_DEVTYPE_KEYBOARD,       &XDEVICE_TYPE_DEBUG_KEYBOARD },
  { XID_DEVTYPE_IRREMOTE,       &XDEVICE_TYPE_IR_REMOTE },
};
//FIXME: There's 2 of GetTypeInformation.. which one does XbSymbolDatabase resolve?
//FIXME: We can just call GetTypeInformation(); ?
for(unsigned int i = 0; i < ARRAY_SIZE(xdevice_types); i++) {
  UCHAR index;
  write_log("Trying XID type %d [table index %u]\n", xdevice_types[i].xid_devtype, i);
  uint32_t* type_information = GetTypeInformation(xdevice_types[i].xid_devtype, &index);
  *xdevice_types[i].xdevice_type = type_information ? type_information[1] : NULL;
  write_log("Set XID type %d to 0x%08X [index: %u]\n", xdevice_types[i].xid_devtype, (uint32_t)*xdevice_types[i].xdevice_type, index);
}

If the xdevice_type is found, we should call the symbol register callback with names like "XDEVICE_TYPE_GAMEPAD".

I'm not sure how to handle custom device types like the Steel Battalion controller. But I don't know how MS handled them either (are they part of all newer libs, or is it part of the games code?). Therefore, we probably shouldn't handle custom devices for now.

JayFoxRox commented 5 years ago

Closing as incomplete duplicate of #75