Skip to content

Commit

Permalink
Reimplement/refactor everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 21, 2024
1 parent b0e76d1 commit f4f16c8
Show file tree
Hide file tree
Showing 11 changed files with 637 additions and 566 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
endif

LIBS := -lwups -lwut -lmappedmemory
LIBS := -lwups -lwut -lnotifications -lmappedmemory

#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level
Expand Down
68 changes: 68 additions & 0 deletions src/function_patches.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "utils/SettingsUtils.h"
#include "utils/logger.h"
#include <coreinit/debug.h>
#include <coreinit/userconfig.h>
#include <nn/acp/title.h>
#include <string_view>
#include <sysapp/switch.h>
#include <sysapp/title.h>
#include <wups/function_patching.h>

DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint64_t titleid, ACPMetaXml *metaxml, uint32_t device) {
int result = real_ACPGetTitleMetaXmlByDevice(titleid, metaxml, device);
if (metaxml != nullptr) {
metaxml->region = 0xFFFFFFFF;
}
return result;
}

DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) {
int result = real_ACPGetLaunchMetaXml(metaxml);
if (metaxml != nullptr) {
metaxml->region = 0xFFFFFFFF;
}

return result;
}

DECL_FUNCTION(int, UCReadSysConfig, int IOHandle, int count, UCSysConfig *settings) {
int result = real_UCReadSysConfig(IOHandle, count, settings);
auto upid = OSGetUPID();

if (!gRegionFreeValuesSetupDone || result != 0 || (upid != SYSAPP_PFID_WII_U_MENU && upid != SYSAPP_PFID_DOWNLOAD_GAME && upid != SYSAPP_PFID_EMANUAL)) {
return result;
}

if (std::string_view("cafe.language") == settings->name) {
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: cafe.language found!");
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: forcing language...");
DEBUG_FUNCTION_LINE("UCReadSysConfig: original lang %d, new %d", *((int *) settings->data), gCurrentLanguage);
*((int *) settings->data) = gCurrentLanguage;
} else if (std::string_view("cafe.cntry_reg") == settings->name) {
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: cafe.cntry_reg found!");
DEBUG_FUNCTION_LINE_VERBOSE("UCReadSysConfig: forcing cntry_reg...");
DEBUG_FUNCTION_LINE("UCReadSysConfig: original cntry_reg %d, new %d", *((int *) settings->data), gCurrentCountry);
*((int *) settings->data) = gCurrentCountry;
}

return result;
}

DECL_FUNCTION(int, MCP_GetSysProdSettings, int IOHandle, MCPSysProdSettings *settings) {
int result = real_MCP_GetSysProdSettings(IOHandle, settings);
auto upid = OSGetUPID();
if (!gRegionFreeValuesSetupDone || result != 0 || (upid != SYSAPP_PFID_WII_U_MENU && upid != SYSAPP_PFID_DOWNLOAD_GAME && upid != SYSAPP_PFID_EMANUAL)) {
return result;
}

DEBUG_FUNCTION_LINE_VERBOSE("MCP_GetSysProdSettings: forcing platform region...");
DEBUG_FUNCTION_LINE("MCP_GetSysProdSettings: original region %d, new %d...", settings->product_area, gCurrentProductArea);
settings->product_area = gCurrentProductArea;

return result;
}

WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice);
WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml);
WUPS_MUST_REPLACE_FOR_PROCESS(MCP_GetSysProdSettings, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetSysProdSettings, WUPS_FP_TARGET_PROCESS_ALL);
WUPS_MUST_REPLACE_FOR_PROCESS(UCReadSysConfig, WUPS_LOADER_LIBRARY_COREINIT, UCReadSysConfig, WUPS_FP_TARGET_PROCESS_ALL);
7 changes: 7 additions & 0 deletions src/function_patches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <coreinit/mcp.h>
#include <coreinit/userconfig.h>

extern "C" int (*real_UCReadSysConfig)(int IOHandle, int count, UCSysConfig *settings) __attribute__((section(".data")));
extern "C" int (*real_MCP_GetSysProdSettings)(int IOHandle, MCPSysProdSettings *settings) __attribute__((section(".data")));
23 changes: 12 additions & 11 deletions src/globals.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#include "globals.h"

std::optional<MCPRegion> gRealRegionOpt = {};
std::optional<int32_t> gRealCountryOpt = {};
std::optional<Languages> gRealLanguageOpt = {};

bool gRegionFreeValuesSetupDone = false;

bool gPreferSystemSettings = DEFAULT_PREFER_SYSTEM_SETTINGS;
bool gSkipOwnRegion = DEFAULT_SKIP_OWN_REGION;
bool gAutoDetection = DEFAULT_AUTO_DETECTION_VALUE;

int gForceSettingsEnabled = 0;
Lanuages gDefaultLanguage = LANG_ENGLISH;
int32_t gDefaultCountry = 78;
MCPRegion gDefaultProductArea = MCP_REGION_EUROPE;

Lanuages gCurrentLanguage = gDefaultLanguage;
int32_t gCurrentCountry = gDefaultCountry;
MCPRegion gCurrentProductArea = gDefaultProductArea;
Languages gCurrentLanguage = LANG_ENGLISH;
int32_t gCurrentCountry = 0;
MCPRegion gCurrentProductArea = MCP_REGION_USA;

Lanuages gDefaultLangForEUR = DEFAULT_LANG_FOR_EUR;
Languages gDefaultLangForEUR = DEFAULT_LANG_FOR_EUR;
int32_t gDefaultCountryForEUR = DEFAULT_COUNTRY_FOR_EUR;
Lanuages gDefaultLangForUSA = DEFAULT_LANG_FOR_USA;
Languages gDefaultLangForUSA = DEFAULT_LANG_FOR_USA;
int32_t gDefaultCountryForUSA = DEFAULT_COUNTRY_FOR_USA;
Lanuages gDefaultLangForJPN = DEFAULT_LANG_FOR_JPN;
Languages gDefaultLangForJPN = DEFAULT_LANG_FOR_JPN;
int32_t gDefaultCountryForJPN = DEFAULT_COUNTRY_FOR_JPN;
25 changes: 13 additions & 12 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

#include "version.h"
#include <coreinit/mcp.h>
#include <optional>

#define VERSION "v0.2.3"
#define VERSION "v0.2.4"
#define VERSION_FULL VERSION VERSION_EXTRA

extern int gForceSettingsEnabled;

enum Lanuages {
enum Languages {
LANG_JAPANESE = 0,
LANG_ENGLISH = 1,
LANG_FRANCAIS = 2,
Expand All @@ -20,6 +19,12 @@ enum Lanuages {
LANG_RUSSKI = 10,
};

extern std::optional<MCPRegion> gRealRegionOpt;
extern std::optional<int32_t> gRealCountryOpt;
extern std::optional<Languages> gRealLanguageOpt;

extern bool gRegionFreeValuesSetupDone;

#define DEFAULT_AUTO_DETECTION_VALUE true
extern bool gAutoDetection;

Expand All @@ -29,11 +34,7 @@ extern bool gPreferSystemSettings;
#define DEFAULT_SKIP_OWN_REGION true
extern bool gSkipOwnRegion;

extern Lanuages gDefaultLanguage;
extern int32_t gDefaultCountry;
extern MCPRegion gDefaultProductArea;

extern Lanuages gCurrentLanguage;
extern Languages gCurrentLanguage;
extern int32_t gCurrentCountry;
extern MCPRegion gCurrentProductArea;

Expand All @@ -46,11 +47,11 @@ extern MCPRegion gCurrentProductArea;
#define DEFAULT_LANG_FOR_JPN LANG_JAPANESE
#define DEFAULT_COUNTRY_FOR_JPN 1

extern Lanuages gDefaultLangForEUR;
extern Languages gDefaultLangForEUR;
extern int32_t gDefaultCountryForEUR;

extern Lanuages gDefaultLangForUSA;
extern Languages gDefaultLangForUSA;
extern int32_t gDefaultCountryForUSA;

extern Lanuages gDefaultLangForJPN;
extern Languages gDefaultLangForJPN;
extern int32_t gDefaultCountryForJPN;
Loading

0 comments on commit f4f16c8

Please sign in to comment.