Compare commits

..
Author SHA1 Message Date
Ash Logan
9698114e5a chore: CI tweaks 2026-07-29 21:21:04 +10:00
Ash Logan
344d41a0f2 chore: bump libplum submodule 2026-07-29 21:15:28 +10:00
Ash Logan
60e0b0bc12 feat: Initial UPnP impl using libplum
fix: makefile

feat: add libplum for UPnP and co
2026-07-29 15:26:43 +10:00
Ash Logan
e1558493f2 fix: getaddrinfo(NULL) is valid apparently 2026-07-29 15:26:43 +10:00
10 changed files with 79 additions and 113 deletions

View file

@ -11,11 +11,13 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v7
with:
submodules: 'true'
- name: build toolchain container
run: docker build . -t builder
- uses: ammaraskar/gcc-problem-matcher@master
- name: build Inkay
run: docker run --rm -v ${PWD}:/app -w /app builder
run: docker run --rm -v ${PWD}:${PWD} -w ${PWD} builder
- uses: actions/upload-artifact@v7
with:
name: inkay

View file

@ -1,101 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '25 19 * * 2'
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write
# required to fetch internal or private CodeQL packs
packages: read
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: c-cpp
build-mode: none
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- name: Run manual build steps
if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{matrix.language}}"

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "src/ext/libplum"]
path = src/ext/libplum
url = https://github.com/PretendoNetwork/libplum

View file

@ -21,9 +21,9 @@ WUT_ROOT := $(DEVKITPRO)/wut
#-------------------------------------------------------------------------------
TARGET := Inkay-pretendo
BUILD := build
SOURCES := src src/patches src/utils src/ext/inih common
SOURCES := src src/patches src/utils src/ext/inih src/ext/libplum/src common
DATA := data
INCLUDES := src src/ext/inih src/lang common
INCLUDES := src src/ext/inih src/ext/libplum/include/plum src/lang common
#-------------------------------------------------------------------------------
# options for code generation

8
common/wut_ac_missing.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#include <nn/ac/ac_c.h>
NNResult ACGetAssignedAlternativeDns(uint32_t *ip);
NNResult ACGetAssignedGateway(uint32_t *ip);
NNResult ACGetAssignedPreferedDns(uint32_t *ip); // sic
NNResult ACGetAssignedSubnet(uint32_t *ip);

1
src/ext/libplum Submodule

@ -0,0 +1 @@
Subproject commit 79e85e61e638e04c10f74f65e1e06957d7658ac7

View file

@ -23,6 +23,7 @@
#include "patches/olv_urls.h"
#include "patches/game_matchmaking.h"
#include <plum.h>
#include <wums.h>
#include <coreinit/dynload.h>
@ -189,6 +190,12 @@ WUMS_INITIALIZE() {
if (NotificationModule_InitLibrary() != NOTIFICATION_MODULE_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("NotificationModule_InitLibrary failed");
}
const plum_config_t plum_config = {
.log_level = PLUM_LOG_LEVEL_VERBOSE,
.log_callback = [](const plum_log_level_t level, const char *message) { DEBUG_FUNCTION_LINE("[PLUM-%d] %s", level, message) },
};
plum_init(&plum_config);
}
WUMS_DEINITIALIZE() {
@ -202,6 +209,8 @@ WUMS_DEINITIALIZE() {
NotificationModule_DeInitLibrary();
FunctionPatcher_DeInitLibrary();
plum_cleanup();
WHBLogCafeDeinit();
WHBLogUdpDeinit();
}
@ -237,6 +246,7 @@ WUMS_ALL_APPLICATION_STARTS_DONE() {
}
WUMS_APPLICATION_ENDS() {
peertopeer_notify_titleswitch();
}
WUMS_EXPORT_FUNCTION(Inkay_Initialize);

View file

@ -34,6 +34,7 @@ constexpr std::pair<const char *, const char *> dns_replacements[] = {
static const char * replace_dns_name(const char *dns_name) {
if (!Config::connect_to_network) return dns_name;
if (!dns_name) return dns_name;
for (auto [original, replacement] : dns_replacements) {
if (strcmp(original, dns_name) == 0)

View file

@ -13,6 +13,7 @@
#include <coreinit/title.h>
#include <coreinit/dynload.h>
#include <plum.h>
#include "game_peertopeer.h"
#include "config.h"
@ -26,6 +27,31 @@
#include <string_view>
using namespace std::string_view_literals;
static std::optional<int> upnp_id;
static void upnp_cb(int id, plum_state_t state, const plum_mapping_t *mapping) {
DEBUG_FUNCTION_LINE("Plum result %d, %s:%hu", state, mapping->external_host, mapping->external_port);
}
static void upnp_go() {
const plum_mapping_t mapping = {
.protocol = PLUM_IP_PROTOCOL_UDP,
.internal_port = get_console_peertopeer_port(),
.user_ptr = nullptr,
};
int id = plum_create_mapping(&mapping, upnp_cb);
if (id < 0) return;
upnp_id = id;
}
static void upnp_stop() {
if (!upnp_id) return;
plum_destroy_mapping(*upnp_id);
upnp_id = std::nullopt;
}
static struct {
std::array<uint64_t, 3> tid;
uint16_t version;
@ -51,24 +77,25 @@ static struct {
},
};
static void generic_peertopeer_patch() {
static bool 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;
return false;
} else {
title_version = *version_opt;
DEBUG_FUNCTION_LINE("Title version detected: %d", title_version);
}
bool result = false;
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);
if (!game) {
DEBUG_FUNCTION_LINE("Couldn't find game rpx! (%s)", patch.rpx.data());
return;
return false;
}
if (title_version != patch.version) {
@ -85,19 +112,23 @@ static void generic_peertopeer_patch() {
target = (uint16_t *)rpl_addr(*game, patch.max_port_addr);
replace_unsigned<uint16_t>(target, 0xffff, port);
result = true;
break;
}
return result;
}
static void minecraft_peertopeer_patch() {
static bool minecraft_peertopeer_patch() {
std::optional<OSDynLoad_NotifyData> minecraft = search_for_rpl("Minecraft.Client.rpx"sv);
if (!minecraft) {
DEBUG_FUNCTION_LINE("Couldn't find minecraft rpx!");
return;
return false;
}
if (const auto version_opt = get_current_title_version(); !version_opt || *version_opt != 688) {
DEBUG_FUNCTION_LINE("Wrong mincecraft version detected");
return;
return false;
}
auto port = get_console_peertopeer_port();
@ -112,6 +143,8 @@ static void minecraft_peertopeer_patch() {
replace_instruction(&target_func[0], 0x3c600001, 0x3c600000); // li r3, 0
replace_instruction(&target_func[1], 0x3863ffff, 0x60630000 | port); // ori r3, r3, port
// blr
return true;
}
void peertopeer_patch() {
@ -119,13 +152,21 @@ void peertopeer_patch() {
return;
}
uint64_t tid = OSGetTitleID();
bool patched;
const uint64_t tid = OSGetTitleID();
if (tid == 0x00050000'101D7500 || // EUR
tid == 0x00050000'101D9D00 || // USA
tid == 0x00050000'101DBE00) { // JPN
minecraft_peertopeer_patch();
patched = minecraft_peertopeer_patch();
} else {
generic_peertopeer_patch();
patched = generic_peertopeer_patch();
}
if (patched)
upnp_go();
}
void peertopeer_notify_titleswitch() {
upnp_stop();
}

View file

@ -14,3 +14,4 @@
#pragma once
void peertopeer_patch();
void peertopeer_notify_titleswitch();