diff --git a/Dockerfile b/Dockerfile index c48c885..8c3a580 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM ghcr.io/wiiu-env/devkitppc:20230417 COPY --from=wiiuenv/libnotifications:20230126 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO COPY --from=wiiuenv/libkernel:20220724 /artifacts $DEVKITPRO COPY --from=wiiuenv/libmocha:20220903 /artifacts $DEVKITPRO COPY --from=wiiuenv/wiiupluginsystem:20230126 /artifacts $DEVKITPRO diff --git a/Makefile b/Makefile index 2d996aa..001f89f 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) LDFLAGS += -T$(WUMS_ROOT)/share/libkernel.ld $(WUPSSPECS) -LIBS := -lwups -lmocha -lkernel -lwut -lnotifications +LIBS := -lwups -lmocha -lkernel -lwut -lnotifications -lfunctionpatcher #------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level diff --git a/src/main.cpp b/src/main.cpp index a46ca95..ded0e53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ #include "config.h" #include "Notification.h" #include "patches/olv_urls.h" +#include "patches/game_matchmaking.h" #include #include @@ -56,6 +57,7 @@ WUPS_USE_STORAGE("inkay"); #include #include +#include //thanks @Gary#4139 :p static void write_string(uint32_t addr, const char* str) @@ -134,13 +136,19 @@ INITIALIZE_PLUGIN() { StartNotificationThread("Using Nintendo Network"); } - MCP_Close(mcp); + + if (FunctionPatcher_InitLibrary() == FUNCTION_PATCHER_RESULT_SUCCESS) { + install_matchmaking_patches(); + } } DEINITIALIZE_PLUGIN() { + remove_matchmaking_patches(); + WHBLogUdpDeinit(); Mocha_DeInitLibrary(); NotificationModule_DeInitLibrary(); + FunctionPatcher_DeInitLibrary(); } ON_APPLICATION_START() { diff --git a/src/patches/game_matchmaking.cpp b/src/patches/game_matchmaking.cpp new file mode 100644 index 0000000..e18472e --- /dev/null +++ b/src/patches/game_matchmaking.cpp @@ -0,0 +1,82 @@ +/* Copyright 2023 Pretendo Network contributors + Copyright 2023 Ash Logan + Copyright 2019 Maschell + + Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby + granted, provided that the above copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "game_matchmaking.h" +#include "utils/logger.h" + +#include +#include +#include +#include + +#define MARIO_KART_8_TID_J 0x000500001010EB00 +#define MARIO_KART_8_TID_U 0x000500001010EC00 +#define MARIO_KART_8_TID_E 0x000500001010ED00 + +constexpr std::array mk8_tids = {MARIO_KART_8_TID_J, MARIO_KART_8_TID_U, MARIO_KART_8_TID_E}; +std::vector matchmaking_patches; + +DECL_FUNCTION(void, mk8_MatchmakeSessionSearchCriteria_SetAttribute, void* _this, uint32_t attributeIndex, uint32_t attributeValue) { + const int new_dlc = 4; //todo + if (attributeIndex == 4) { + DEBUG_FUNCTION_LINE("changed search DLC from %d to %d", attributeValue, new_dlc); + attributeValue = (attributeValue & ~0xFF) | new_dlc; // keep upper bits + } + + real_mk8_MatchmakeSessionSearchCriteria_SetAttribute(_this, attributeIndex, attributeValue); +} + +DECL_FUNCTION(void, mk8_MatchmakeSession_SetAttribute, void* _this, uint32_t attributeIndex, uint32_t attributeValue) { + const int new_dlc = 4; //todo + if (attributeIndex == 4) { + DEBUG_FUNCTION_LINE("changed DLC from %d to %d", attributeValue, new_dlc); + attributeValue = (attributeValue & ~0xFF) | new_dlc; // keep upper bits + } + + real_mk8_MatchmakeSession_SetAttribute(_this, attributeIndex, attributeValue); +} + +void install_matchmaking_patches() { + matchmaking_patches.reserve(2); + + function_replacement_data_t repl = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( + mk8_MatchmakeSessionSearchCriteria_SetAttribute, + mk8_tids.data(), mk8_tids.size(), + "Turbo.rpx", + 0x0098e7b4, 64, 64 + ); + PatchedFunctionHandle handle = 0; + if (FunctionPatcher_AddFunctionPatch(&repl, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE("Inkay/MK8: Failed to patch MatchmakeSessionSearchCriteria::SetAttribute!"); + } + matchmaking_patches.push_back(handle); + + function_replacement_data_t repl2 = REPLACE_FUNCTION_OF_EXECUTABLE_BY_ADDRESS_WITH_VERSION( + mk8_MatchmakeSession_SetAttribute, + mk8_tids.data(), mk8_tids.size(), + "Turbo.rpx", + 0x0098e52c, 64, 64 + ); + if (FunctionPatcher_AddFunctionPatch(&repl2, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) { + DEBUG_FUNCTION_LINE("Inkay/MK8: Failed to patch MatchmakeSession::SetAttribute!"); + } + matchmaking_patches.push_back(handle); +} + +void remove_matchmaking_patches() { + for (auto handle : matchmaking_patches) { + FunctionPatcher_RemoveFunctionPatch(handle); + } + matchmaking_patches.clear(); +} diff --git a/src/patches/game_matchmaking.h b/src/patches/game_matchmaking.h new file mode 100644 index 0000000..51263c4 --- /dev/null +++ b/src/patches/game_matchmaking.h @@ -0,0 +1,18 @@ +/* Copyright 2023 Pretendo Network contributors + Copyright 2023 Ash Logan + Copyright 2019 Maschell + + Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby + granted, provided that the above copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. +*/ + +#pragma once + +void install_matchmaking_patches(); +void remove_matchmaking_patches();