Skip to content

Commit 8bc8ac0

Browse files
authored
Merge pull request #61 from Maschell/notifications
2 parents 4cf3b74 + 4a880c1 commit 8bc8ac0

File tree

12 files changed

+136
-56
lines changed

12 files changed

+136
-56
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COPY --from=ghcr.io/wiiu-env/libnotifications:20240426 /artifacts $DEVKITPRO
44
COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO
55
COPY --from=ghcr.io/wiiu-env/libkernel:20230621 /artifacts $DEVKITPRO
66
COPY --from=ghcr.io/wiiu-env/libmocha:20231127 /artifacts $DEVKITPRO
7-
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20240424 /artifacts $DEVKITPRO
7+
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20250208 /artifacts $DEVKITPRO
88
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240505 /artifacts $DEVKITPRO
99

1010
WORKDIR /app

plugin/src/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <sysapp/title.h>
3434
#include <sysapp/launch.h>
3535
#include <nn/act.h>
36+
3637
#include <format>
3738

3839
static config_strings strings;

plugin/src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ DEINITIALIZE_PLUGIN() {
6262
}
6363

6464
ON_APPLICATION_START() {
65-
65+
// Tell the module the plugin is running!
66+
Inkay_SetPluginRunning();
6667
}
6768

6869
ON_APPLICATION_ENDS() {

plugin/src/module.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
*/
1616

1717
#include "module.h"
18-
#include <coreinit/dynload.h>
1918

20-
#include "config.h"
2119
#include "Notification.h"
2220
#include "utils/logger.h"
2321
#include "sysconfig.h"
2422
#include "lang.h"
2523

24+
#include <coreinit/dynload.h>
25+
2626
static OSDynLoad_Module module;
2727
static void (*moduleInitialize)(bool) = nullptr;
2828
static InkayStatus (*moduleGetStatus)() = nullptr;
29+
static void (*moduleSetPluginRunning)() = nullptr;
2930

3031
static const char *get_module_not_found_message() {
3132
return get_config_strings(get_system_language()).module_not_found.data();
@@ -61,6 +62,7 @@ void Inkay_Finalize() {
6162
OSDynLoad_Release(module);
6263
moduleInitialize = nullptr;
6364
moduleGetStatus = nullptr;
65+
moduleSetPluginRunning = nullptr;
6466
}
6567
}
6668

@@ -76,3 +78,16 @@ InkayStatus Inkay_GetStatus() {
7678

7779
return moduleGetStatus();
7880
}
81+
82+
void Inkay_SetPluginRunning() {
83+
if (!module) {
84+
return;
85+
}
86+
87+
if (!moduleSetPluginRunning && OSDynLoad_FindExport(module, OS_DYNLOAD_EXPORT_FUNC, "Inkay_SetPluginRunning", reinterpret_cast<void * *>(&moduleSetPluginRunning)) != OS_DYNLOAD_OK) {
88+
DEBUG_FUNCTION_LINE("Failed to find \"Inkay_SetPluginRunning\" function");
89+
return;
90+
}
91+
92+
moduleSetPluginRunning();
93+
}

plugin/src/module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ enum class InkayStatus {
2727
void Inkay_Initialize(bool apply_patches);
2828
void Inkay_Finalize();
2929
InkayStatus Inkay_GetStatus();
30+
void Inkay_SetPluginRunning();

src/config.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919

2020
bool Config::connect_to_network = false;
2121
bool Config::initialized = false;
22-
bool Config::shown_uninitialized_warning = false;
22+
bool Config::shown_warning = false;
23+
bool Config::plugin_is_loaded = false;
24+
bool Config::block_initialize = false;

src/config.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
#ifndef INKAY_CONFIG_H
66
#define INKAY_CONFIG_H
77

8-
#include <string_view>
9-
#include <nn/swkbd.h>
10-
118
class Config {
129
public:
10+
1311
static bool connect_to_network;
1412

1513
static bool initialized;
1614

17-
static bool shown_uninitialized_warning;
15+
static bool shown_warning;
16+
17+
static bool plugin_is_loaded;
18+
19+
static bool block_initialize;
1820
};
1921

2022
#endif //INKAY_CONFIG_H

src/main.cpp

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,28 @@
1616
along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include <stdio.h>
20-
#include <stdint.h>
21-
#include <stdlib.h>
22-
#include <wums.h>
23-
#include <optional>
24-
#include <nsysnet/nssl.h>
25-
#include <sysapp/title.h>
26-
#include <coreinit/cache.h>
27-
#include <coreinit/dynload.h>
28-
#include <coreinit/mcp.h>
29-
#include <coreinit/memory.h>
30-
#include <coreinit/memorymap.h>
31-
#include <coreinit/memexpheap.h>
32-
#include <coreinit/title.h>
33-
#include <notifications/notifications.h>
34-
#include <utils/logger.h>
3519
#include "export.h"
3620
#include "iosu_url_patches.h"
3721
#include "config.h"
3822
#include "Notification.h"
3923
#include "patches/olv_urls.h"
4024
#include "patches/game_matchmaking.h"
4125

42-
#include <coreinit/filesystem.h>
43-
#include <cstring>
26+
#include <wums.h>
27+
28+
#include <coreinit/dynload.h>
29+
#include <coreinit/mcp.h>
30+
31+
#include <notifications/notifications.h>
32+
#include <utils/logger.h>
33+
4434
#include <string>
45-
#include <nn/erreula/erreula_cpp.h>
46-
#include <nn/act/client_cpp.h>
35+
#include <optional>
4736

48-
#include "ca_pem.h"
37+
#include <cstring>
38+
#include <cstdint>
4939

50-
#include <gx2/surface.h>
40+
#include "ca_pem.h"
5141

5242
#define INKAY_VERSION "v2.6.0"
5343

@@ -67,7 +57,6 @@ WUMS_DEPENDS_ON(homebrew_notifications);
6757

6858
WUMS_USE_WUT_DEVOPTAB();
6959

70-
#include <kernel/kernel.h>
7160
#include <mocha/mocha.h>
7261
#include <function_patcher/function_patching.h>
7362
#include "patches/account_settings.h"
@@ -118,6 +107,10 @@ static const char *get_pretendo_message() {
118107
return get_config_strings(get_system_language()).using_pretendo_network.data();
119108
}
120109

110+
static void Inkay_SetPluginRunning() {
111+
Config::plugin_is_loaded = true;
112+
}
113+
121114
static InkayStatus Inkay_GetStatus() {
122115
if (!Config::initialized)
123116
return InkayStatus::Uninitialized;
@@ -131,7 +124,12 @@ static InkayStatus Inkay_GetStatus() {
131124

132125
static void Inkay_Initialize(bool apply_patches) {
133126
if (Config::initialized)
134-
return;
127+
return;
128+
129+
if (Config::block_initialize) {
130+
ShowNotification("Cannot load Inkay while the system is running. Please restart the console");
131+
return;
132+
}
135133

136134
// if using pretendo then (try to) apply the ssl patches
137135
if (apply_patches) {
@@ -177,9 +175,7 @@ WUMS_INITIALIZE() {
177175
WHBLogCafeInit();
178176
WHBLogUdpInit();
179177

180-
auto res = Mocha_InitLibrary();
181-
182-
if (res != MOCHA_RESULT_SUCCESS) {
178+
if (const auto res = Mocha_InitLibrary(); res != MOCHA_RESULT_SUCCESS) {
183179
DEBUG_FUNCTION_LINE("Mocha init failed with code %d!", res);
184180
return;
185181
}
@@ -207,24 +203,36 @@ WUMS_DEINITIALIZE() {
207203
WUMS_APPLICATION_STARTS() {
208204
DEBUG_FUNCTION_LINE_VERBOSE("Inkay " INKAY_VERSION " starting up...\n");
209205

210-
// TODO - Add a way to reliably check this. We can't do it here since this path gets triggered before
211-
// the plugin gets initialized.
212-
//
213-
// if (!Config::initialized && !Config::shown_uninitialized_warning) {
214-
// DEBUG_FUNCTION_LINE("Inkay module not initialized");
215-
// ShowNotification("Inkay module was not initialized. Ensure you have the Inkay plugin loaded");
216-
// Config::shown_uninitialized_warning = true;
217-
// }
206+
// Reset plugin loaded flag
207+
Config::plugin_is_loaded = false;
208+
}
218209

210+
WUMS_ALL_APPLICATION_STARTS_DONE() {
211+
// we need to do the patches here because otherwise the Config::connect_to_network flag might be set yet
219212
setup_olv_libs();
220213
peertopeer_patch();
221214
matchmaking_notify_titleswitch();
222215
hotpatchAccountSettings();
216+
217+
if (Config::initialized && !Config::plugin_is_loaded) {
218+
DEBUG_FUNCTION_LINE("Inkay is running but the plugin got unloaded");
219+
if (!Config::block_initialize) {
220+
ShowNotification("Inkay module is still running. Please restart the console");
221+
}
222+
Config::shown_warning = true;
223+
} else if (!Config::initialized && !Config::shown_warning) {
224+
DEBUG_FUNCTION_LINE("Inkay module not initialized");
225+
ShowNotification("Inkay module was not initialized. Ensure you have the Inkay plugin loaded");
226+
Config::shown_warning = true;
227+
}
228+
if (!Config::initialized) {
229+
Config::block_initialize = true;
230+
}
223231
}
224232

225233
WUMS_APPLICATION_ENDS() {
226-
227234
}
228235

229236
WUMS_EXPORT_FUNCTION(Inkay_Initialize);
230237
WUMS_EXPORT_FUNCTION(Inkay_GetStatus);
238+
WUMS_EXPORT_FUNCTION(Inkay_SetPluginRunning);

src/patches/account_settings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include "inkay_config.h"
2525

2626
#include <function_patcher/function_patching.h>
27-
#include <vector>
28-
#include <optional>
29-
#include <coreinit/debug.h>
27+
3028
#include <coreinit/filesystem.h>
3129
#include <coreinit/title.h>
32-
#include <nsysnet/nssl.h>
30+
31+
#include <vector>
32+
#include <optional>
3333

3434
#include "ca_pem.h" // generated at buildtime
3535

@@ -163,7 +163,7 @@ bool hotpatchAccountSettings() {
163163
}
164164

165165
void unpatchAccountSettings() {
166-
for (auto handle: account_patches) {
166+
for (const auto handle: account_patches) {
167167
FunctionPatcher_RemoveFunctionPatch(handle);
168168
}
169169
account_patches.clear();

src/patches/game_peertopeer.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ using namespace std::string_view_literals;
2828

2929
static struct {
3030
std::array<uint64_t, 3> tid;
31+
uint16_t version;
3132
uint32_t min_port_addr;
3233
uint32_t max_port_addr;
3334
std::string_view rpx;
34-
} generic_patch_games [] = {
35-
{ // MARIO KART 8
36-
{ 0x00050000'1010ec00, 0x00050000'1010ed00, 0x00050000'1010eb00 },
35+
} generic_patch_games[] = {
36+
{
37+
// MARIO KART 8
38+
{0x00050000'1010ec00, 0x00050000'1010ed00, 0x00050000'1010eb00},
39+
81,
3740
0x101a9a52,
3841
0x101a9a54,
3942
"Turbo.rpx"sv,
4043
},
41-
{ // Splatoon
42-
{ 0x00050000'10176900, 0x00050000'10176a00, 0x00050000'10162b00 },
44+
{
45+
// Splatoon
46+
{0x00050000'10176900, 0x00050000'10176a00, 0x00050000'10162b00},
47+
288,
4348
0x101e8952,
4449
0x101e8954,
4550
"Gambit.rpx"sv,
@@ -48,8 +53,16 @@ static struct {
4853

4954
static void generic_peertopeer_patch() {
5055
uint64_t tid = OSGetTitleID();
56+
uint16_t title_version = 0;
57+
if (const auto version_opt = get_current_title_version(); !version_opt) {
58+
DEBUG_FUNCTION_LINE("Failed to detect current title version");
59+
return;
60+
} else {
61+
title_version = *version_opt;
62+
DEBUG_FUNCTION_LINE("Title version detected: %d", title_version);
63+
}
5164

52-
for (const auto& patch : generic_patch_games) {
65+
for (const auto &patch: generic_patch_games) {
5366
if (std::ranges::find(patch.tid, tid) == patch.tid.end()) continue;
5467

5568
std::optional<OSDynLoad_NotifyData> game = search_for_rpl(patch.rpx);
@@ -58,6 +71,12 @@ static void generic_peertopeer_patch() {
5871
return;
5972
}
6073

74+
if (title_version != patch.version) {
75+
DEBUG_FUNCTION_LINE("Unexpected title version. Expected %d but got %d (%s)", patch.version, title_version,
76+
patch.rpx.data());
77+
continue;
78+
}
79+
6180
auto port = get_console_peertopeer_port();
6281
DEBUG_FUNCTION_LINE_VERBOSE("Will use port %d. %08x", port, game->textAddr);
6382

@@ -76,6 +95,10 @@ static void minecraft_peertopeer_patch() {
7695
DEBUG_FUNCTION_LINE("Couldn't find minecraft rpx!");
7796
return;
7897
}
98+
if (const auto version_opt = get_current_title_version(); !version_opt || *version_opt != 688) {
99+
DEBUG_FUNCTION_LINE("Wrong mincecraft version detected");
100+
return;
101+
}
79102

80103
auto port = get_console_peertopeer_port();
81104
DEBUG_FUNCTION_LINE_VERBOSE("Will use port %d. %08x", port, minecraft->textAddr);

0 commit comments

Comments
 (0)