-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwwfcSupport.cpp
165 lines (140 loc) · 4.23 KB
/
wwfcSupport.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "import/revolution.h"
#include "wwfcLog.hpp"
#include "wwfcPatch.hpp"
#include <cstring>
namespace wwfc::Support
{
static_assert(sizeof(WWFC_DOMAIN) <= sizeof("nintendowifi.net"));
// Unpatch the auth response hook
WWFC_DEFINE_PATCH = {Patch::Write(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_AUTH_HANDLERESP_HOOK, //
(u32[]){AUTH_HANDLERESP_UNPATCH}
)};
static const char* FixHostname(const char* name, char* out)
{
if (std::strlen(name) > 256 - sizeof(WWFC_DOMAIN)) {
// Hostname is too big to replace
return name;
}
for (u32 i = 0; name[i] != '\0'; i++) {
auto replaceDomain = [&](const char* check, u32 checkSize,
const char* replace, u32 replaceSize) {
if (std::strncmp(name + i, check, checkSize) != 0) {
return false;
}
// Replace with the custom hostname
std::memcpy(out, name, i);
std::memcpy(out + i, replace, replaceSize);
std::strcpy(out + i + replaceSize, name + i + checkSize);
LOG_INFO_FMT("Hostname: %s -> %s", name, out);
return true;
};
// Replace nintendowifi.net with the custom name
if (replaceDomain(
"nintendowifi.net", sizeof("nintendowifi.net") - 1, WWFC_DOMAIN,
sizeof(WWFC_DOMAIN) - 1
)) {
return out;
}
// Redirect gamespy.com to the "gs" subdomain, required for some games
if (replaceDomain(
"gamespy.com", sizeof("gamespy.com"), "gs." WWFC_DOMAIN,
sizeof("gs." WWFC_DOMAIN) - 1
)) {
return out;
}
// WWFC patch over an already Wiimmfi patched game
if (replaceDomain(
"wiimmfi.de", sizeof("wiimmfi.de") - 1, WWFC_DOMAIN,
sizeof(WWFC_DOMAIN) - 1
)) {
return out;
}
}
// No custom hostname
return name;
}
WWFC_DEFINE_CTR_STUB( //
ADDRESS_gethostbyname + 0x10, //
void* gethostbyname(const char* name),
// clang-format off
stwu sp, -0x30(sp);
mflr r0;
stw r0, 0x34(sp);
addi r11, sp, 0x30;
// clang-format on
)
WWFC_DEFINE_PATCH = {Patch::BranchWithCTR(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_gethostbyname, //
[](char* name) -> void* {
char fixedName[256];
return gethostbyname(FixHostname(name, fixedName));
}
)};
WWFC_DEFINE_CTR_STUB( //
ADDRESS_SOInetAtoN + 0x10, //
u32 SOInetAtoN(const char* name, u8* param_2),
// clang-format off
stwu sp, -0x30(sp);
mflr r0;
stw r0, 0x34(sp);
addi r11, sp, 0x30;
// clang-format on
)
WWFC_DEFINE_PATCH = {Patch::BranchWithCTR(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_SOInetAtoN, //
[](const char* name, u8* param_2) -> u32 {
char fixedName[256];
return SOInetAtoN(FixHostname(name, fixedName), param_2);
}
)};
WWFC_DEFINE_CTR_STUB( //
ADDRESS_SOGetAddrInfo + 0x10, //
u32 SOGetAddrInfo(const char* name, u32 param_2, u32 param_3, u32 param_4),
// clang-format off
stwu sp, -0x40(sp);
mflr r0;
stw r0, 0x44(sp);
addi r11, sp, 0x40;
// clang-format on
)
WWFC_DEFINE_PATCH = {Patch::BranchWithCTR(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_SOGetAddrInfo, //
[](const char* name, u32 param_2, u32 param_3, u32 param_4) -> u32 {
char fixedName[256];
return SOGetAddrInfo(
FixHostname(name, fixedName), param_2, param_3, param_4
);
}
)};
// Disable SSL in NHTTP
WWFC_DEFINE_PATCH = {
Patch::WriteASM(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_NHTTP_HTTPS_PORT_PATCH, //
1, ASM_LAMBDA(li r0, 80)
),
Patch::WriteASM(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_NHTTPi_SocSSLConnect, //
2, ASM_LAMBDA(li r3, 0; blr)
),
};
#if ADDRESS_GHIPARSEURL_HTTPS_PATCH
// Disable SSL in GameSpy HTTP
WWFC_DEFINE_PATCH = {Patch::WriteASM(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_GHIPARSEURL_HTTPS_PATCH, //
1, ASM_LAMBDA(li r0, 0)
)};
#endif
void ChangeAuthURL()
{
*reinterpret_cast<const char**>(ADDRESS_NASWII_AC_URL_POINTER) =
"http://nas." WWFC_DOMAIN "/ac";
}
} // namespace wwfc::Support