forked from ndeadly/MissionControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtm_mitm_service.cpp
More file actions
113 lines (95 loc) · 5.47 KB
/
btm_mitm_service.cpp
File metadata and controls
113 lines (95 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (c) 2020-2022 ndeadly
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "btm_mitm_service.hpp"
#include "btm_shim.h"
#include "../controllers/controller_management.hpp"
#include "../mcmitm_config.hpp"
#include "../controllers/switch_controller.hpp"
namespace ams::mitm::btm {
namespace {
void RenameConnectedDevices(BtmConnectedDeviceV1 devices[], size_t count) {
for (unsigned int i = 0; i < count; ++i) {
auto device = &devices[i];
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
}
}
}
}
Result BtmMitmService::GetDeviceConditionDeprecated1(sf::Out<ams::btm::DeviceConditionV100> out) {
auto device_condition = reinterpret_cast<BtmDeviceConditionV100 *>(out.GetPointer());
R_TRY(btmGetDeviceConditionDeprecated1Fwd(m_forward_service.get(), device_condition));
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
return ams::ResultSuccess();
}
Result BtmMitmService::GetDeviceConditionDeprecated2(sf::Out<ams::btm::DeviceConditionV510> out) {
auto device_condition = reinterpret_cast<BtmDeviceConditionV510 *>(out.GetPointer());
R_TRY(btmGetDeviceConditionDeprecated2Fwd(m_forward_service.get(), device_condition));
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
return ams::ResultSuccess();
}
Result BtmMitmService::GetDeviceConditionDeprecated3(sf::Out<ams::btm::DeviceConditionV800> out) {
auto device_condition = reinterpret_cast<BtmDeviceConditionV800 *>(out.GetPointer());
R_TRY(btmGetDeviceConditionDeprecated3Fwd(m_forward_service.get(), device_condition));
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
return ams::ResultSuccess();
}
Result BtmMitmService::GetDeviceConditionDeprecated4(sf::Out<ams::btm::DeviceConditionV900> out) {
auto device_condition = reinterpret_cast<BtmDeviceConditionV900 *>(out.GetPointer());
R_TRY(btmGetDeviceConditionDeprecated4Fwd(m_forward_service.get(), device_condition));
RenameConnectedDevices(device_condition->devices, device_condition->connected_count);
return ams::ResultSuccess();
}
Result BtmMitmService::GetDeviceCondition(u32 id, const sf::OutArray<ams::btm::ConnectedDevice> &out, sf::Out<s32> total_out) {
auto device_condition = reinterpret_cast<BtmConnectedDeviceV13 *>(out.GetPointer());
R_TRY(btmGetDeviceConditionFwd(m_forward_service.get(), id, device_condition, out.GetSize(), total_out.GetPointer()));
for (int i = 0; i < total_out.GetValue(); ++i) {
auto device = &device_condition[i];
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
}
}
return ams::ResultSuccess();
}
Result BtmMitmService::GetDeviceInfoDeprecated(sf::Out<ams::btm::DeviceInfoList> out) {
auto device_info = reinterpret_cast<BtmDeviceInfoList *>(out.GetPointer());
R_TRY(btmGetDeviceInfoDeprecatedFwd(m_forward_service.get(), device_info));
for (unsigned int i = 0; i < device_info->device_count; ++i) {
auto device = &device_info->devices[i];
if (!controller::IsOfficialSwitchControllerName(device->name.name)) {
std::strncpy(device->name.name, controller::pro_controller_name, sizeof(device->name) - 1);
}
else if (mitm::GetGlobalConfig()->misc.spoof_nso_as_pro_controller && ams::controller::IsNsoController(device->profile_info.hid_device_info.vid, device->profile_info.hid_device_info.pid)) {
device->profile_info.hid_device_info.pid = 0x2009;
}
}
return ams::ResultSuccess();
}
Result BtmMitmService::GetDeviceInfo(u32 id, const sf::OutArray<ams::btm::DeviceInfo> &out, sf::Out<s32> total_out) {
auto device_info = reinterpret_cast<BtmDeviceInfoV13 *>(out.GetPointer());
R_TRY(btmGetDeviceInfoFwd(m_forward_service.get(), id, device_info, out.GetSize(), total_out.GetPointer()));
for (int i = 0; i < total_out.GetValue(); ++i) {
auto device = &device_info[i];
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
}
else if (mitm::GetGlobalConfig()->misc.spoof_nso_as_pro_controller && ams::controller::IsNsoController(device->profile_info.hid_device_info.vid, device->profile_info.hid_device_info.pid)) {
device->profile_info.hid_device_info.pid = 0x2009;
}
}
return ams::ResultSuccess();
}
}