forked from PretendoNetwork/Inkay
Merge pull request #61 from Maschell/notifications
This commit is contained in:
commit
8bc8ac0290
12 changed files with 136 additions and 56 deletions
|
|
@ -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;
|
||||
|
|
|
|||
10
src/config.h
10
src/config.h
|
|
@ -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
|
||||
|
|
|
|||
80
src/main.cpp
80
src/main.cpp
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
Loading…
Reference in a new issue