mc.mitm: fix issues following rebase and update for libnx changes

This commit is contained in:
ndeadly 2021-06-24 00:37:52 +02:00
parent a1d19d530a
commit 3c20440eb4
4 changed files with 44 additions and 34 deletions

View file

@ -69,24 +69,45 @@ namespace ams::bluetooth::hid {
Result VirtualReconnect(const bluetooth::Address *address) {
struct ConnectionState {
BtdrvAddress address;
uint8_t pad[2];
BtdrvHidConnectionState state;
};
if (hos::GetVersion() >= hos::Version_12_0_0) {
struct ConnectionState {
BtdrvHidConnectionStatus status;
BtdrvAddress address;
};
// Signal fake disconnection event
ConnectionState disconnected = { *address, {0}, BtdrvHidConnectionState_Disconnected };
SignalFakeEvent(BtdrvHidEventType_ConnectionState, &disconnected, sizeof(disconnected));
g_data_read_event.Wait();
// Signal fake disconnection event
ConnectionState disconnected = { BtdrvHidConnectionStatus_Closed, *address };
SignalFakeEvent(BtdrvHidEventType_Connection, &disconnected, sizeof(disconnected));
g_data_read_event.Wait();
// If we don't wait a bit the console disconnects the controller for real
svcSleepThread(100'000'000ULL);
// If we don't wait a bit the console disconnects the controller for real
svcSleepThread(100'000'000ULL);
// Signal fake connection event
ConnectionState connected = { *address, {0}, BtdrvHidConnectionState_Connected };
SignalFakeEvent(BtdrvHidEventType_ConnectionState, &connected, sizeof(connected));
g_data_read_event.Wait();
// Signal fake connection event
ConnectionState connected = { BtdrvHidConnectionStatus_Opened, *address };
SignalFakeEvent(BtdrvHidEventType_Connection, &connected, sizeof(connected));
g_data_read_event.Wait();
}
else {
struct ConnectionState {
BtdrvAddress address;
uint8_t pad[2];
BtdrvHidConnectionStatus status;
};
// Signal fake disconnection event
ConnectionState disconnected = { *address, {0}, BtdrvHidConnectionStatusOld_Closed };
SignalFakeEvent(BtdrvHidEventTypeOld_Connection, &disconnected, sizeof(disconnected));
g_data_read_event.Wait();
// If we don't wait a bit the console disconnects the controller for real
svcSleepThread(100'000'000ULL);
// Signal fake connection event
ConnectionState connected = { *address, {0}, BtdrvHidConnectionStatusOld_Opened };
SignalFakeEvent(BtdrvHidEventTypeOld_Connection, &connected, sizeof(connected));
g_data_read_event.Wait();
}
return ams::ResultSuccess();
}

View file

@ -71,14 +71,14 @@ namespace ams::mitm::btm {
auto device_info = reinterpret_cast<BtmDeviceInfoList *>(out.GetPointer());
R_TRY(btmGetDeviceInfoFwd(this->forward_service.get(), device_info));
for (unsigned int i = 0; i < device_info->total_entries; ++i) {
auto device = controller::LocateHandler(&device_info->devices[i].address);
for (unsigned int i = 0; i < device_info->device_count; ++i) {
auto device = controller::LocateHandler(&device_info->devices[i].addr);
if (device) {
if (!device->IsOfficialController()) {
if (device->GetControllerType() == controller::SwitchControllerType_ProController)
std::strncpy(device_info->devices[i].name, controller::pro_controller_name, sizeof(device_info->devices[i].name) - 1);
std::strncpy(device_info->devices[i].name.name, controller::pro_controller_name, sizeof(device_info->devices[i].name) - 1);
else
std::strncpy(device_info->devices[i].name, "Joy-Con (R)", sizeof(device_info->devices[i].name) - 1);
std::strncpy(device_info->devices[i].name.name, "Joy-Con (R)", sizeof(device_info->devices[i].name) - 1);
}
}
}

View file

@ -159,16 +159,13 @@ namespace ams::controller {
switch (m_emulated_type) {
case SwitchControllerType_RightJoyCon:
if (m_buttons.dpad_down | m_buttons.dpad_up | m_buttons.dpad_right | m_buttons.dpad_left){
switch_report->input0x30.right_stick = this->PackStickData(
switch_report->input0x30.right_stick.SetData(
m_buttons.dpad_down ? UINT12_MAX : (m_buttons.dpad_up ? 0 : STICK_ZERO),
m_buttons.dpad_right ? UINT12_MAX : (m_buttons.dpad_left ? 0 : STICK_ZERO)
);
}
else {
uint16_t x;
uint16_t y;
this->UnpackStickData(&m_left_stick, &x, &y);
switch_report->input0x30.right_stick = this->PackStickData(-y, x);
switch_report->input0x30.right_stick.SetData(-m_left_stick.GetY(), m_left_stick.GetX());
}
switch_report->input0x30.buttons.SL_R = m_buttons.L | m_buttons.ZL;
@ -180,16 +177,13 @@ namespace ams::controller {
break;
case SwitchControllerType_LeftJoyCon:
if (m_buttons.dpad_down | m_buttons.dpad_up | m_buttons.dpad_right | m_buttons.dpad_left){
switch_report->input0x30.left_stick = this->PackStickData(
switch_report->input0x30.left_stick.SetData(
m_buttons.dpad_up ? UINT12_MAX : (m_buttons.dpad_down ? 0 : STICK_ZERO),
m_buttons.dpad_left ? UINT12_MAX : (m_buttons.dpad_right ? 0 : STICK_ZERO)
);
}
else {
uint16_t x;
uint16_t y;
this->UnpackStickData(&m_left_stick, &x, &y);
switch_report->input0x30.left_stick = this->PackStickData(y, -x);
switch_report->input0x30.left_stick.SetData(m_left_stick.GetY(), -m_left_stick.GetX());
}
switch_report->input0x30.buttons.SL_L = m_buttons.L | m_buttons.ZL;

View file

@ -40,11 +40,6 @@ namespace ams::controller {
virtual Result CancelVibration(void) { return ams::ResultSuccess(); };
virtual Result SetPlayerLed(uint8_t led_mask) { return ams::ResultSuccess(); };
inline void UnpackStickData(const SwitchStickData *stick, uint16_t *x, uint16_t *y) {
*x = stick->xy[0] | ((stick->xy[1] & 0xf) << 8);
*y = (stick->xy[1] >> 4) | (stick->xy[2] << 4);
}
Result HandleSubCmdReport(const bluetooth::HidReport *report);
Result HandleRumbleReport(const bluetooth::HidReport *report);