Merge pull request #61 from Maschell/notifications
Some checks are pending
Inkay-CI / build-inkay (push) Waiting to run

This commit is contained in:
Daniel López Guimaraes 2025-02-15 12:40:44 +00:00 committed by GitHub
commit 8bc8ac0290
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 136 additions and 56 deletions

View File

@ -4,7 +4,7 @@ COPY --from=ghcr.io/wiiu-env/libnotifications:20240426 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libkernel:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libmocha:20231127 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20240424 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20250208 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20240505 /artifacts $DEVKITPRO
WORKDIR /app

View File

@ -33,6 +33,7 @@
#include <sysapp/title.h>
#include <sysapp/launch.h>
#include <nn/act.h>
#include <format>
static config_strings strings;

View File

@ -62,7 +62,8 @@ DEINITIALIZE_PLUGIN() {
}
ON_APPLICATION_START() {
// Tell the module the plugin is running!
Inkay_SetPluginRunning();
}
ON_APPLICATION_ENDS() {

View File

@ -15,17 +15,18 @@
*/
#include "module.h"
#include <coreinit/dynload.h>
#include "config.h"
#include "Notification.h"
#include "utils/logger.h"
#include "sysconfig.h"
#include "lang.h"
#include <coreinit/dynload.h>
static OSDynLoad_Module module;
static void (*moduleInitialize)(bool) = nullptr;
static InkayStatus (*moduleGetStatus)() = nullptr;
static void (*moduleSetPluginRunning)() = nullptr;
static const char *get_module_not_found_message() {
return get_config_strings(get_system_language()).module_not_found.data();
@ -61,6 +62,7 @@ void Inkay_Finalize() {
OSDynLoad_Release(module);
moduleInitialize = nullptr;
moduleGetStatus = nullptr;
moduleSetPluginRunning = nullptr;
}
}
@ -76,3 +78,16 @@ InkayStatus Inkay_GetStatus() {
return moduleGetStatus();
}
void Inkay_SetPluginRunning() {
if (!module) {
return;
}
if (!moduleSetPluginRunning && OSDynLoad_FindExport(module, OS_DYNLOAD_EXPORT_FUNC, "Inkay_SetPluginRunning", reinterpret_cast<void * *>(&moduleSetPluginRunning)) != OS_DYNLOAD_OK) {
DEBUG_FUNCTION_LINE("Failed to find \"Inkay_SetPluginRunning\" function");
return;
}
moduleSetPluginRunning();
}

View File

@ -27,3 +27,4 @@ enum class InkayStatus {
void Inkay_Initialize(bool apply_patches);
void Inkay_Finalize();
InkayStatus Inkay_GetStatus();
void Inkay_SetPluginRunning();

View File

@ -19,4 +19,6 @@
bool Config::connect_to_network = false;
bool Config::initialized = false;
bool Config::shown_uninitialized_warning = false;
bool Config::shown_warning = false;
bool Config::plugin_is_loaded = false;
bool Config::block_initialize = false;

View File

@ -5,16 +5,18 @@
#ifndef INKAY_CONFIG_H
#define INKAY_CONFIG_H
#include <string_view>
#include <nn/swkbd.h>
class Config {
public:
static bool connect_to_network;
static bool initialized;
static bool shown_uninitialized_warning;
static bool shown_warning;
static bool plugin_is_loaded;
static bool block_initialize;
};
#endif //INKAY_CONFIG_H

View File

@ -16,22 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <wums.h>
#include <optional>
#include <nsysnet/nssl.h>
#include <sysapp/title.h>
#include <coreinit/cache.h>
#include <coreinit/dynload.h>
#include <coreinit/mcp.h>
#include <coreinit/memory.h>
#include <coreinit/memorymap.h>
#include <coreinit/memexpheap.h>
#include <coreinit/title.h>
#include <notifications/notifications.h>
#include <utils/logger.h>
#include "export.h"
#include "iosu_url_patches.h"
#include "config.h"
@ -39,16 +23,22 @@
#include "patches/olv_urls.h"
#include "patches/game_matchmaking.h"
#include <coreinit/filesystem.h>
#include <cstring>
#include <wums.h>
#include <coreinit/dynload.h>
#include <coreinit/mcp.h>
#include <notifications/notifications.h>
#include <utils/logger.h>
#include <string>
#include <nn/erreula/erreula_cpp.h>
#include <nn/act/client_cpp.h>
#include <optional>
#include <cstring>
#include <cstdint>
#include "ca_pem.h"
#include <gx2/surface.h>
#define INKAY_VERSION "v2.6.0"
/**
@ -67,7 +57,6 @@ WUMS_DEPENDS_ON(homebrew_notifications);
WUMS_USE_WUT_DEVOPTAB();
#include <kernel/kernel.h>
#include <mocha/mocha.h>
#include <function_patcher/function_patching.h>
#include "patches/account_settings.h"
@ -118,6 +107,10 @@ static const char *get_pretendo_message() {
return get_config_strings(get_system_language()).using_pretendo_network.data();
}
static void Inkay_SetPluginRunning() {
Config::plugin_is_loaded = true;
}
static InkayStatus Inkay_GetStatus() {
if (!Config::initialized)
return InkayStatus::Uninitialized;
@ -131,7 +124,12 @@ static InkayStatus Inkay_GetStatus() {
static void Inkay_Initialize(bool apply_patches) {
if (Config::initialized)
return;
return;
if (Config::block_initialize) {
ShowNotification("Cannot load Inkay while the system is running. Please restart the console");
return;
}
// if using pretendo then (try to) apply the ssl patches
if (apply_patches) {
@ -177,9 +175,7 @@ WUMS_INITIALIZE() {
WHBLogCafeInit();
WHBLogUdpInit();
auto res = Mocha_InitLibrary();
if (res != MOCHA_RESULT_SUCCESS) {
if (const auto res = Mocha_InitLibrary(); res != MOCHA_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Mocha init failed with code %d!", res);
return;
}
@ -207,24 +203,36 @@ WUMS_DEINITIALIZE() {
WUMS_APPLICATION_STARTS() {
DEBUG_FUNCTION_LINE_VERBOSE("Inkay " INKAY_VERSION " starting up...\n");
// TODO - Add a way to reliably check this. We can't do it here since this path gets triggered before
// the plugin gets initialized.
//
// if (!Config::initialized && !Config::shown_uninitialized_warning) {
// DEBUG_FUNCTION_LINE("Inkay module not initialized");
// ShowNotification("Inkay module was not initialized. Ensure you have the Inkay plugin loaded");
// Config::shown_uninitialized_warning = true;
// }
// Reset plugin loaded flag
Config::plugin_is_loaded = false;
}
WUMS_ALL_APPLICATION_STARTS_DONE() {
// we need to do the patches here because otherwise the Config::connect_to_network flag might be set yet
setup_olv_libs();
peertopeer_patch();
matchmaking_notify_titleswitch();
hotpatchAccountSettings();
if (Config::initialized && !Config::plugin_is_loaded) {
DEBUG_FUNCTION_LINE("Inkay is running but the plugin got unloaded");
if (!Config::block_initialize) {
ShowNotification("Inkay module is still running. Please restart the console");
}
Config::shown_warning = true;
} else if (!Config::initialized && !Config::shown_warning) {
DEBUG_FUNCTION_LINE("Inkay module not initialized");
ShowNotification("Inkay module was not initialized. Ensure you have the Inkay plugin loaded");
Config::shown_warning = true;
}
if (!Config::initialized) {
Config::block_initialize = true;
}
}
WUMS_APPLICATION_ENDS() {
}
WUMS_EXPORT_FUNCTION(Inkay_Initialize);
WUMS_EXPORT_FUNCTION(Inkay_GetStatus);
WUMS_EXPORT_FUNCTION(Inkay_SetPluginRunning);

View File

@ -24,12 +24,12 @@
#include "inkay_config.h"
#include <function_patcher/function_patching.h>
#include <vector>
#include <optional>
#include <coreinit/debug.h>
#include <coreinit/filesystem.h>
#include <coreinit/title.h>
#include <nsysnet/nssl.h>
#include <vector>
#include <optional>
#include "ca_pem.h" // generated at buildtime
@ -163,7 +163,7 @@ bool hotpatchAccountSettings() {
}
void unpatchAccountSettings() {
for (auto handle: account_patches) {
for (const auto handle: account_patches) {
FunctionPatcher_RemoveFunctionPatch(handle);
}
account_patches.clear();

View File

@ -28,18 +28,23 @@ using namespace std::string_view_literals;
static struct {
std::array<uint64_t, 3> tid;
uint16_t version;
uint32_t min_port_addr;
uint32_t max_port_addr;
std::string_view rpx;
} generic_patch_games [] = {
{ // MARIO KART 8
{ 0x00050000'1010ec00, 0x00050000'1010ed00, 0x00050000'1010eb00 },
} generic_patch_games[] = {
{
// MARIO KART 8
{0x00050000'1010ec00, 0x00050000'1010ed00, 0x00050000'1010eb00},
81,
0x101a9a52,
0x101a9a54,
"Turbo.rpx"sv,
},
{ // Splatoon
{ 0x00050000'10176900, 0x00050000'10176a00, 0x00050000'10162b00 },
{
// Splatoon
{0x00050000'10176900, 0x00050000'10176a00, 0x00050000'10162b00},
288,
0x101e8952,
0x101e8954,
"Gambit.rpx"sv,
@ -48,8 +53,16 @@ static struct {
static void generic_peertopeer_patch() {
uint64_t tid = OSGetTitleID();
uint16_t title_version = 0;
if (const auto version_opt = get_current_title_version(); !version_opt) {
DEBUG_FUNCTION_LINE("Failed to detect current title version");
return;
} else {
title_version = *version_opt;
DEBUG_FUNCTION_LINE("Title version detected: %d", title_version);
}
for (const auto& patch : generic_patch_games) {
for (const auto &patch: generic_patch_games) {
if (std::ranges::find(patch.tid, tid) == patch.tid.end()) continue;
std::optional<OSDynLoad_NotifyData> game = search_for_rpl(patch.rpx);
@ -58,6 +71,12 @@ static void generic_peertopeer_patch() {
return;
}
if (title_version != patch.version) {
DEBUG_FUNCTION_LINE("Unexpected title version. Expected %d but got %d (%s)", patch.version, title_version,
patch.rpx.data());
continue;
}
auto port = get_console_peertopeer_port();
DEBUG_FUNCTION_LINE_VERBOSE("Will use port %d. %08x", port, game->textAddr);
@ -76,6 +95,10 @@ static void minecraft_peertopeer_patch() {
DEBUG_FUNCTION_LINE("Couldn't find minecraft rpx!");
return;
}
if (const auto version_opt = get_current_title_version(); !version_opt || *version_opt != 688) {
DEBUG_FUNCTION_LINE("Wrong mincecraft version detected");
return;
}
auto port = get_console_peertopeer_port();
DEBUG_FUNCTION_LINE_VERBOSE("Will use port %d. %08x", port, minecraft->textAddr);

View File

@ -16,6 +16,10 @@
#include <vector>
#include <algorithm>
#include <string_view>
#include <coreinit/mcp.h>
#include <coreinit/title.h>
#include "logger.h"
// if we get more than like.. two callsites for this, it should really be refactored out rather than doing a fresh
// search every time
@ -37,3 +41,24 @@ std::optional<OSDynLoad_NotifyData> search_for_rpl(std::string_view name) {
return *rpl;
}
std::optional<uint16_t> get_current_title_version() {
const auto mcpHandle = MCP_Open();
MCPTitleListType titleInfo;
int32_t res = -1;
const uint64_t curTitleId = OSGetTitleID();
if ((curTitleId & 0x0000000F00000000) == 0) {
res = MCP_GetTitleInfo(mcpHandle, curTitleId | 0x0000000E00000000, &titleInfo);
}
if (res != 0) {
res = MCP_GetTitleInfo(mcpHandle, curTitleId, &titleInfo);
}
MCP_Close(mcpHandle);
if (res != 0) {
DEBUG_FUNCTION_LINE("Failed to get title version of %016llX.", curTitleId);
return {};
}
MCP_Close(mcpHandle);
const auto tmp_result = titleInfo.titleVersion; // make the compiler happy because we access a packed struct
return tmp_result;
}

View File

@ -26,3 +26,5 @@ constexpr void *rpl_addr(OSDynLoad_NotifyData rpl, uint32_t cemu_addr) {
return (void *)(rpl.dataAddr + cemu_addr - 0x1000'0000);
}
}
std::optional<uint16_t> get_current_title_version();