Skip to content

Commit c2db4fe

Browse files
committed
Fix UWUVCI injects
Closes #4 - thanks danny8376 for the initial work and to BonQ who made me aware of this issue and helped me testing it!
1 parent b76c431 commit c2db4fe

File tree

1 file changed

+76
-34
lines changed

1 file changed

+76
-34
lines changed

src/main.cpp

Lines changed: 76 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <cstring>
22
#include <curl/curl.h>
3+
#include <malloc.h>
4+
#include <nn/acp/title.h>
35
#include <utils/logger.h>
46
#include <wups.h>
57

@@ -9,14 +11,14 @@
911

1012
WUPS_PLUGIN_NAME("UTag");
1113
WUPS_PLUGIN_DESCRIPTION("Display the last played titles on your RiiTag!");
12-
WUPS_PLUGIN_VERSION("v2.0");
13-
WUPS_PLUGIN_AUTHOR("twosecslater, Brawl345");
14+
WUPS_PLUGIN_VERSION("v2.1.0");
15+
WUPS_PLUGIN_AUTHOR("RiiConnect24, WiiDatabase");
1416
WUPS_PLUGIN_LICENSE("GPLv3");
1517

1618
WUPS_USE_WUT_DEVOPTAB();
1719

1820
char key[129];
19-
char titleId[17];
21+
uint64_t title_id;
2022

2123
INITIALIZE_PLUGIN() {
2224
initLogging();
@@ -33,17 +35,17 @@ INITIALIZE_PLUGIN() {
3335
}
3436

3537
DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2,
36-
uint32_t u3, uint32_t u4, uint32_t u5) {
38+
uint64_t u3, uint32_t u4) {
3739
initLogging();
3840
DEBUG_FUNCTION_LINE("Entered MCP_RightCheckLaunchable()");
39-
uint32_t result = real_MCP_RightCheckLaunchable(u1, u2, u3, u4, u5);
41+
uint32_t result = real_MCP_RightCheckLaunchable(u1, u2, u3, u4);
4042

4143
if (result == 0 && strlen(key) != 0) {
42-
uint64_t tid = ((uint64_t)u3) << 32 | u4;
43-
sprintf(titleId, "%016llX", tid);
44-
DEBUG_FUNCTION_LINE("TitleID: %s", titleId);
44+
title_id = u3;
45+
DEBUG_FUNCTION_LINE("Title ID: %016llx", title_id);
4546
}
4647

48+
deinitLogging();
4749
return result;
4850
}
4951

@@ -53,44 +55,84 @@ WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT,
5355
ON_APPLICATION_REQUESTS_EXIT() {
5456
initLogging();
5557

56-
DEBUG_FUNCTION_LINE("ON_APPLICATION_REQUESTS_EXIT() called");
58+
DEBUG_FUNCTION_LINE("ON_APPLICATION_REQUESTS_EXIT called");
5759

5860
if (strlen(key) == 0) {
5961
DEBUG_FUNCTION_LINE("Key not loaded, so ignoring.");
6062
return;
61-
} else if (strlen(titleId) == 0) {
62-
DEBUG_FUNCTION_LINE("TitleID is not set, so ignoring.");
63+
} else if (title_id == 0) {
64+
DEBUG_FUNCTION_LINE("Title ID is not set, so ignoring.");
6365
return;
6466
}
6567

66-
char type[9];
6768
char tagURL[180];
68-
snprintf(type, sizeof(type), titleId);
69+
char TID[17];
70+
71+
uint32_t title_type = title_id >> 32;
72+
uint16_t title_gid_high = (title_id >> 16) & 0xffff;
73+
uint16_t title_gid_low = title_id & 0xffff;
74+
bool is_uwuvci = false;
75+
76+
if (title_type == 0x00050002 &&
77+
(title_gid_high >= 0x3000 &&
78+
title_gid_low >= 0x3000)) { // UWUVCI AIO Injected game
79+
// need to be aligned to 0x40 for IOSU
80+
auto *meta = (ACPMetaXml *)memalign(0x40, sizeof(ACPMetaXml));
81+
82+
if (!meta) {
83+
DEBUG_FUNCTION_LINE("Allocation of meta failed!");
84+
return;
85+
}
86+
87+
ACPResult result = ACPGetTitleMetaXml(title_id, meta);
88+
if (result == ACPResult::ACP_RESULT_SUCCESS) {
89+
uint32_t real_tid = meta->reserved_flag2;
90+
char real_t_type = (char)(real_tid >> 24);
91+
if ((real_t_type > 'A' &&
92+
real_t_type <
93+
'Z') || // should be uppercase letter for correct titles
94+
(real_t_type > '0' &&
95+
real_t_type < '9')) { // only 091E00 falls into this?
96+
// transform it to (TeconMoon's) vc injection id format
97+
sprintf(TID, "%08x%08x", title_type, real_tid);
98+
is_uwuvci = true;
99+
}
100+
}
101+
102+
free(meta);
103+
}
69104

70-
if (strcmp(type, "00050000") == 0 || strcmp(type, "00050002") == 0) {
71-
snprintf(tagURL, sizeof(tagURL), "http://%s/wiiu?game=%s&key=%s", SERVER,
72-
titleId, key);
73-
} else {
74-
memset(&titleId[0], 0, sizeof(titleId));
75-
return;
105+
if (!is_uwuvci) { // normal wiiu tid
106+
sprintf(TID, "%016llX", title_id);
76107
}
77108

78-
DEBUG_FUNCTION_LINE_VERBOSE("Tag URL is %s", tagURL);
79-
DEBUG_FUNCTION_LINE("Contacting RiiTag");
80-
81-
CURL *curl = curl_easy_init();
82-
CURLcode ec;
83-
curl_easy_setopt(curl, CURLOPT_URL, tagURL);
84-
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L);
85-
ec = curl_easy_perform(curl);
86-
if (ec != CURLE_OK) {
87-
DEBUG_FUNCTION_LINE("curl failed with exit code %s",
88-
curl_easy_strerror(ec));
89-
} else {
90-
DEBUG_FUNCTION_LINE("RiiTag updated");
109+
if (title_type == 0x00050000 || // normal wii u titles
110+
is_uwuvci ||
111+
// (TeconMoon's) vc injections
112+
// should exclude all demos accroding to
113+
// https://wiiubrew.org/w/index.php?title=Title_database&oldid=3473#00050002:_Kiosk_Interactive_Demo_and_eShop_Demo
114+
(title_type == 0x00050002 &&
115+
(title_gid_high < 0x1010 || title_gid_high > 0x1021))) {
116+
snprintf(tagURL, sizeof(tagURL), "http://%s/wiiu?game=%s&key=%s", SERVER,
117+
TID, key);
118+
119+
DEBUG_FUNCTION_LINE_VERBOSE("Tag URL is %s", tagURL);
120+
DEBUG_FUNCTION_LINE("Contacting RiiTag");
121+
122+
CURL *curl = curl_easy_init();
123+
CURLcode ec;
124+
curl_easy_setopt(curl, CURLOPT_URL, tagURL);
125+
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L);
126+
ec = curl_easy_perform(curl);
127+
if (ec != CURLE_OK) {
128+
DEBUG_FUNCTION_LINE("curl failed with exit code %s",
129+
curl_easy_strerror(ec));
130+
} else {
131+
DEBUG_FUNCTION_LINE("RiiTag updated");
132+
}
133+
curl_easy_cleanup(curl);
91134
}
92-
curl_easy_cleanup(curl);
93-
memset(&titleId[0], 0, sizeof(titleId));
94135

136+
title_id = 0;
95137
deinitLogging();
96138
}

0 commit comments

Comments
 (0)