Skip to content

Commit

Permalink
Fix UWUVCI injects
Browse files Browse the repository at this point in the history
Closes #4 - thanks danny8376 for the initial work and
to BonQ who made me aware of this issue and helped me testing it!
  • Loading branch information
Brawl345 committed Sep 8, 2022
1 parent b76c431 commit c2db4fe
Showing 1 changed file with 76 additions and 34 deletions.
110 changes: 76 additions & 34 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <cstring>
#include <curl/curl.h>
#include <malloc.h>
#include <nn/acp/title.h>
#include <utils/logger.h>
#include <wups.h>

Expand All @@ -9,14 +11,14 @@

WUPS_PLUGIN_NAME("UTag");
WUPS_PLUGIN_DESCRIPTION("Display the last played titles on your RiiTag!");
WUPS_PLUGIN_VERSION("v2.0");
WUPS_PLUGIN_AUTHOR("twosecslater, Brawl345");
WUPS_PLUGIN_VERSION("v2.1.0");
WUPS_PLUGIN_AUTHOR("RiiConnect24, WiiDatabase");
WUPS_PLUGIN_LICENSE("GPLv3");

WUPS_USE_WUT_DEVOPTAB();

char key[129];
char titleId[17];
uint64_t title_id;

INITIALIZE_PLUGIN() {
initLogging();
Expand All @@ -33,17 +35,17 @@ INITIALIZE_PLUGIN() {
}

DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2,
uint32_t u3, uint32_t u4, uint32_t u5) {
uint64_t u3, uint32_t u4) {
initLogging();
DEBUG_FUNCTION_LINE("Entered MCP_RightCheckLaunchable()");
uint32_t result = real_MCP_RightCheckLaunchable(u1, u2, u3, u4, u5);
uint32_t result = real_MCP_RightCheckLaunchable(u1, u2, u3, u4);

if (result == 0 && strlen(key) != 0) {
uint64_t tid = ((uint64_t)u3) << 32 | u4;
sprintf(titleId, "%016llX", tid);
DEBUG_FUNCTION_LINE("TitleID: %s", titleId);
title_id = u3;
DEBUG_FUNCTION_LINE("Title ID: %016llx", title_id);
}

deinitLogging();
return result;
}

Expand All @@ -53,44 +55,84 @@ WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT,
ON_APPLICATION_REQUESTS_EXIT() {
initLogging();

DEBUG_FUNCTION_LINE("ON_APPLICATION_REQUESTS_EXIT() called");
DEBUG_FUNCTION_LINE("ON_APPLICATION_REQUESTS_EXIT called");

if (strlen(key) == 0) {
DEBUG_FUNCTION_LINE("Key not loaded, so ignoring.");
return;
} else if (strlen(titleId) == 0) {
DEBUG_FUNCTION_LINE("TitleID is not set, so ignoring.");
} else if (title_id == 0) {
DEBUG_FUNCTION_LINE("Title ID is not set, so ignoring.");
return;
}

char type[9];
char tagURL[180];
snprintf(type, sizeof(type), titleId);
char TID[17];

uint32_t title_type = title_id >> 32;
uint16_t title_gid_high = (title_id >> 16) & 0xffff;
uint16_t title_gid_low = title_id & 0xffff;
bool is_uwuvci = false;

if (title_type == 0x00050002 &&
(title_gid_high >= 0x3000 &&
title_gid_low >= 0x3000)) { // UWUVCI AIO Injected game
// need to be aligned to 0x40 for IOSU
auto *meta = (ACPMetaXml *)memalign(0x40, sizeof(ACPMetaXml));

if (!meta) {
DEBUG_FUNCTION_LINE("Allocation of meta failed!");
return;
}

ACPResult result = ACPGetTitleMetaXml(title_id, meta);
if (result == ACPResult::ACP_RESULT_SUCCESS) {
uint32_t real_tid = meta->reserved_flag2;
char real_t_type = (char)(real_tid >> 24);
if ((real_t_type > 'A' &&
real_t_type <
'Z') || // should be uppercase letter for correct titles
(real_t_type > '0' &&
real_t_type < '9')) { // only 091E00 falls into this?
// transform it to (TeconMoon's) vc injection id format
sprintf(TID, "%08x%08x", title_type, real_tid);
is_uwuvci = true;
}
}

free(meta);
}

if (strcmp(type, "00050000") == 0 || strcmp(type, "00050002") == 0) {
snprintf(tagURL, sizeof(tagURL), "http://%s/wiiu?game=%s&key=%s", SERVER,
titleId, key);
} else {
memset(&titleId[0], 0, sizeof(titleId));
return;
if (!is_uwuvci) { // normal wiiu tid
sprintf(TID, "%016llX", title_id);
}

DEBUG_FUNCTION_LINE_VERBOSE("Tag URL is %s", tagURL);
DEBUG_FUNCTION_LINE("Contacting RiiTag");

CURL *curl = curl_easy_init();
CURLcode ec;
curl_easy_setopt(curl, CURLOPT_URL, tagURL);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L);
ec = curl_easy_perform(curl);
if (ec != CURLE_OK) {
DEBUG_FUNCTION_LINE("curl failed with exit code %s",
curl_easy_strerror(ec));
} else {
DEBUG_FUNCTION_LINE("RiiTag updated");
if (title_type == 0x00050000 || // normal wii u titles
is_uwuvci ||
// (TeconMoon's) vc injections
// should exclude all demos accroding to
// https://wiiubrew.org/w/index.php?title=Title_database&oldid=3473#00050002:_Kiosk_Interactive_Demo_and_eShop_Demo
(title_type == 0x00050002 &&
(title_gid_high < 0x1010 || title_gid_high > 0x1021))) {
snprintf(tagURL, sizeof(tagURL), "http://%s/wiiu?game=%s&key=%s", SERVER,
TID, key);

DEBUG_FUNCTION_LINE_VERBOSE("Tag URL is %s", tagURL);
DEBUG_FUNCTION_LINE("Contacting RiiTag");

CURL *curl = curl_easy_init();
CURLcode ec;
curl_easy_setopt(curl, CURLOPT_URL, tagURL);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L);
ec = curl_easy_perform(curl);
if (ec != CURLE_OK) {
DEBUG_FUNCTION_LINE("curl failed with exit code %s",
curl_easy_strerror(ec));
} else {
DEBUG_FUNCTION_LINE("RiiTag updated");
}
curl_easy_cleanup(curl);
}
curl_easy_cleanup(curl);
memset(&titleId[0], 0, sizeof(titleId));

title_id = 0;
deinitLogging();
}

0 comments on commit c2db4fe

Please sign in to comment.