mirror of
https://github.com/PretendoNetwork/Inkay.git
synced 2026-04-25 16:09:02 -05:00
feat: Check title version before doing game specific patches
This commit is contained in:
parent
79ccad1fd4
commit
4a880c1a2e
|
|
@ -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 New Issue
Block a user