Skip to content

Commit

Permalink
Add wiimmfi.de domain to be replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
mkwcat committed Nov 23, 2023
1 parent 580f390 commit 03cedf6
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions payload/wwfcSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,55 @@ WWFC_DEFINE_PATCH = {Patch::Write(
(u32[]){AUTH_HANDLERESP_UNPATCH}
)};

static void FixHostname(char* name)
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++) {
if (std::strncmp(
name + i, "nintendowifi.net", sizeof("nintendowifi.net") - 1
) == 0) {
OSReport("[WWFC] Hostname: %s", name);

// Replace nintendowifi.net with the custom domain
std::memcpy(name + i, WWFC_DOMAIN, sizeof(WWFC_DOMAIN) - 1);
if (sizeof(WWFC_DOMAIN) < sizeof("nintendowifi.net")) {
std::strcpy(
name + i + sizeof(WWFC_DOMAIN) - 1,
name + i + sizeof("nintendowifi.net") - 1
);
auto replaceDomain = [&](const char* check, u32 checkSize,
const char* replace, u32 replaceSize) {
if (std::strncmp(name + i, check, checkSize) != 0) {
return false;
}

OSReport(" -> %s\n", name);
break;
// Replace with the custom hostname
std::memcpy(out, name, i);
std::memcpy(out + i, replace, replaceSize);
std::strcpy(out + i + replaceSize, name + i + checkSize);
OSReport("[WWFC] Hostname: %s -> %s\n", 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;
}

if (std::strncmp(name + i, "gamespy.com", sizeof("gamespy.com") - 1) ==
0) {
OSReport("[WWFC] Hostname: %s", name);

// Replace gamespy.com with the custom domain
std::memcpy(
name + i, "gs." WWFC_DOMAIN, sizeof("gs." WWFC_DOMAIN) - 1
);
if (sizeof("gs." WWFC_DOMAIN) < sizeof("gamespy.com")) {
std::strcpy(
name + i + sizeof("gs." WWFC_DOMAIN) - 1,
name + i + sizeof("gamespy.com") - 1
);
}
// 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;
}

OSReport(" -> %s\n", name);
break;
// 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( //
Expand All @@ -72,8 +81,8 @@ WWFC_DEFINE_PATCH = {Patch::BranchWithCTR(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_gethostbyname, //
[](char* name) -> void* {
FixHostname(name);
return gethostbyname(name);
char fixedName[256];
return gethostbyname(FixHostname(name, fixedName));
}
)};

Expand All @@ -92,9 +101,9 @@ WWFC_DEFINE_CTR_STUB( //
WWFC_DEFINE_PATCH = {Patch::BranchWithCTR(
WWFC_PATCH_LEVEL_SUPPORT, //
ADDRESS_SOInetAtoN, //
[](char* name, u8* param_2) -> u32 {
FixHostname(name);
return SOInetAtoN(name, param_2);
[](const char* name, u8* param_2) -> u32 {
char fixedName[256];
return SOInetAtoN(FixHostname(name, fixedName), param_2);
}
)};

Expand Down

0 comments on commit 03cedf6

Please sign in to comment.