From d493bc342455e999ae3258efd546df8b27b9a0d9 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 4 Feb 2022 15:51:17 +0100 Subject: [PATCH] Format the code via clang-format --- .clang-format | 67 +++++++++ .github/workflows/ci.yml | 10 +- .github/workflows/pr.yml | 8 ++ README.md | 6 + src/ConfigUtils.cpp | 87 ++++++------ src/DrawUtils.cpp | 40 +++--- src/DrawUtils.h | 2 +- src/globals.cpp | 20 +-- src/globals.h | 16 +-- src/main.cpp | 291 +++++++++++++++++++-------------------- src/utils/logger.c | 8 +- src/utils/logger.h | 21 +-- 12 files changed, 333 insertions(+), 243 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f222b8..b988ac3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,16 @@ on: - main jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary @@ -26,7 +34,7 @@ jobs: id: get_repository_name run: | echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV - echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV + echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV - uses: actions/download-artifact@master with: name: binary diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f21e109..423702f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,8 +3,16 @@ name: CI-PR on: [pull_request] jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/README.md b/README.md index 8d2d444..e1d7c07 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![CI-Release](https://github.com/wiiu-env/region_free_plugin/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/region_free_plugin/actions/workflows/ci.yml) + # Region Free Plugin This plugin allows you to launch an title of an other region and / or force a language of an title. @@ -44,3 +46,7 @@ docker run -it --rm -v ${PWD}:/project regionfree_plugin-builder make # make clean docker run -it --rm -v ${PWD}:/project regionfree_plugin-builder make clean ``` + +## Format the code via docker + +`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i` \ No newline at end of file diff --git a/src/ConfigUtils.cpp b/src/ConfigUtils.cpp index 976479c..eb0a5ba 100644 --- a/src/ConfigUtils.cpp +++ b/src/ConfigUtils.cpp @@ -1,28 +1,28 @@ #include "ConfigUtils.h" -#include "utils/logger.h" #include "DrawUtils.h" +#include "utils/logger.h" +#include "globals.h" +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include -#include "globals.h" -#define COLOR_BACKGROUND Color(238, 238, 238, 255) -#define COLOR_TEXT Color(51, 51, 51, 255) -#define COLOR_TEXT2 Color(72, 72, 72, 255) -#define COLOR_DISABLED Color(255, 0, 0, 255) -#define COLOR_BORDER Color(204, 204, 204, 255) +#define COLOR_BACKGROUND Color(238, 238, 238, 255) +#define COLOR_TEXT Color(51, 51, 51, 255) +#define COLOR_TEXT2 Color(72, 72, 72, 255) +#define COLOR_DISABLED Color(255, 0, 0, 255) +#define COLOR_BORDER Color(204, 204, 204, 255) #define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4FF) -#define COLOR_WHITE Color(0xFFFFFFFF) -#define COLOR_BLACK Color(0, 0, 0, 255) +#define COLOR_WHITE Color(0xFFFFFFFF) +#define COLOR_BLACK Color(0, 0, 0, 255) -#define MAX_BUTTONS_ON_SCREEN 8 +#define MAX_BUTTONS_ON_SCREEN 8 static uint32_t remapWiiMoteButtons(uint32_t buttons) { uint32_t conv_buttons = 0; @@ -121,14 +121,14 @@ void ConfigUtils::displayMenu() { auto selectedBtn = 0; std::map region_map{ - {MCP_REGION_JAPAN, "Japan"}, - {MCP_REGION_USA, "USA"}, + {MCP_REGION_JAPAN, "Japan"}, + {MCP_REGION_USA, "USA"}, {MCP_REGION_EUROPE, "Europe"}, }; std::map region_map_to_index{ - {MCP_REGION_JAPAN, 0}, - {MCP_REGION_USA, 1}, + {MCP_REGION_JAPAN, 0}, + {MCP_REGION_USA, 1}, {MCP_REGION_EUROPE, 2}, }; @@ -143,26 +143,26 @@ void ConfigUtils::displayMenu() { DEBUG_FUNCTION_LINE("Current %d", curSelectedRegion); std::map lang_map{ - {LANG_JAPANESE, "Japanese"}, - {LANG_ENGLISH, "English"}, - {LANG_FRANCAIS, "Francais"}, - {LANG_DEUTSCH, "Deutsch"}, - {LANG_ITALIANO, "Italiano"}, - {LANG_ESPANOL, "Espanol"}, + {LANG_JAPANESE, "Japanese"}, + {LANG_ENGLISH, "English"}, + {LANG_FRANCAIS, "Francais"}, + {LANG_DEUTSCH, "Deutsch"}, + {LANG_ITALIANO, "Italiano"}, + {LANG_ESPANOL, "Espanol"}, {LANG_NEDERLANDS, "Nederlands"}, - {LANG_PORTUGUES, "Portugues"}, - {LANG_RUSSKI, "Russki"}, + {LANG_PORTUGUES, "Portugues"}, + {LANG_RUSSKI, "Russki"}, }; std::map lang_map_to_index{ - {LANG_JAPANESE, 0}, - {LANG_ENGLISH, 1}, - {LANG_FRANCAIS, 2}, - {LANG_DEUTSCH, 3}, - {LANG_ITALIANO, 4}, - {LANG_ESPANOL, 5}, + {LANG_JAPANESE, 0}, + {LANG_ENGLISH, 1}, + {LANG_FRANCAIS, 2}, + {LANG_DEUTSCH, 3}, + {LANG_ITALIANO, 4}, + {LANG_ESPANOL, 5}, {LANG_NEDERLANDS, 6}, - {LANG_PORTUGUES, 7}, - {LANG_RUSSKI, 8}, + {LANG_PORTUGUES, 7}, + {LANG_RUSSKI, 8}, }; std::map lang_index_to_map{ {0, LANG_JAPANESE}, @@ -179,16 +179,16 @@ void ConfigUtils::displayMenu() { auto curSelectedLanguage = gCurrentLanguage; int32_t curRegionIndex = region_map_to_index[curSelectedRegion]; - int32_t curLangIndex = lang_map_to_index[curSelectedLanguage]; + int32_t curLangIndex = lang_map_to_index[curSelectedLanguage]; while (true) { buttonsTriggered = 0; - buttonsReleased = 0; + buttonsReleased = 0; VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error); if (vpad_error == VPAD_READ_SUCCESS) { buttonsTriggered = vpad_data.trigger; - buttonsReleased = vpad_data.release; + buttonsReleased = vpad_data.release; } for (int i = 0; i < 4; i++) { @@ -238,7 +238,7 @@ void ConfigUtils::displayMenu() { curRegionIndex = region_map.size() - 1; } gCurrentProductArea = region_index_to_map[curRegionIndex]; - curSelectedRegion = gCurrentProductArea; + curSelectedRegion = gCurrentProductArea; } else if (selectedBtn == 1) { if (buttonsTriggered & VPAD_BUTTON_LEFT) { curLangIndex--; @@ -253,7 +253,7 @@ void ConfigUtils::displayMenu() { if (curLangIndex >= lang_map.size()) { curLangIndex = lang_map.size() - 1; } - gCurrentLanguage = lang_index_to_map[curLangIndex]; + gCurrentLanguage = lang_index_to_map[curLangIndex]; curSelectedLanguage = gCurrentLanguage; } @@ -311,7 +311,6 @@ void ConfigUtils::displayMenu() { DrawUtils::beginDraw(); DrawUtils::clear(COLOR_BLACK); DrawUtils::endDraw(); - } void ConfigUtils::openConfigMenu() { @@ -319,8 +318,8 @@ void ConfigUtils::openConfigMenu() { uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC); - void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100); - void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100); + void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100); + void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100); if (!screenbuffer0 || !screenbuffer1) { DEBUG_FUNCTION_LINE("Failed to alloc buffers"); @@ -348,7 +347,7 @@ void ConfigUtils::openConfigMenu() { DrawUtils::deinitFont(); - error_exit: +error_exit: if (screenbuffer0) { MEMFreeToMappedMemory(screenbuffer0); diff --git a/src/DrawUtils.cpp b/src/DrawUtils.cpp index 49f8537..c03e7c4 100644 --- a/src/DrawUtils.cpp +++ b/src/DrawUtils.cpp @@ -6,26 +6,26 @@ #include FT_FREETYPE_H // buffer width -#define TV_WIDTH 0x500 +#define TV_WIDTH 0x500 #define DRC_WIDTH 0x380 bool DrawUtils::isBackBuffer; -uint8_t *DrawUtils::tvBuffer = nullptr; -uint32_t DrawUtils::tvSize = 0; +uint8_t *DrawUtils::tvBuffer = nullptr; +uint32_t DrawUtils::tvSize = 0; uint8_t *DrawUtils::drcBuffer = nullptr; -uint32_t DrawUtils::drcSize = 0; +uint32_t DrawUtils::drcSize = 0; // Don't put those into the clase or we have to include ft everywhere static FT_Library ft_lib = nullptr; -static FT_Face ft_face = nullptr; +static FT_Face ft_face = nullptr; static Color font_col(0xFFFFFFFF); void DrawUtils::initBuffers(void *tvBuffer_, uint32_t tvSize_, void *drcBuffer_, uint32_t drcSize_) { - DrawUtils::tvBuffer = (uint8_t *) tvBuffer_; - DrawUtils::tvSize = tvSize_; + DrawUtils::tvBuffer = (uint8_t *) tvBuffer_; + DrawUtils::tvSize = tvSize_; DrawUtils::drcBuffer = (uint8_t *) drcBuffer_; - DrawUtils::drcSize = drcSize_; + DrawUtils::drcSize = drcSize_; } void DrawUtils::beginDraw() { @@ -67,11 +67,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t i += drcSize / 2; } if (a == 0xFF) { - drcBuffer[i] = r; + drcBuffer[i] = r; drcBuffer[i + 1] = g; drcBuffer[i + 2] = b; } else { - drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity); + drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity); drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity); drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity); } @@ -86,11 +86,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t i += tvSize / 2; } if (a == 0xFF) { - tvBuffer[i] = r; + tvBuffer[i] = r; tvBuffer[i + 1] = g; tvBuffer[i + 2] = b; } else { - tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity); + tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity); tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity); tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity); } @@ -121,8 +121,8 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32 } uint32_t dataPos = __builtin_bswap32(*(uint32_t *) &(data[0x0A])); - uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12])); - uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16])); + uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12])); + uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16])); if (dataPos == 0) { dataPos = 54; @@ -141,7 +141,7 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32 } void DrawUtils::initFont() { - void *font = nullptr; + void *font = nullptr; uint32_t size = 0; OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size); @@ -189,7 +189,8 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh buffer[num] = 0; } else { wchar_t *tmp = buffer; - while ((*tmp++ = *string++)); + while ((*tmp++ = *string++)) + ; } print(x, y, buffer, alignRight); @@ -198,7 +199,7 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) { FT_GlyphSlot slot = ft_face->glyph; - FT_Vector pen = {(int) x, (int) y}; + FT_Vector pen = {(int) x, (int) y}; if (alignRight) { pen.x -= getTextWidth(string); @@ -229,7 +230,8 @@ uint32_t DrawUtils::getTextWidth(const char *string) { buffer[num] = 0; } else { wchar_t *tmp = buffer; - while ((*tmp++ = *string++)); + while ((*tmp++ = *string++)) + ; } uint32_t width = getTextWidth(buffer); @@ -240,7 +242,7 @@ uint32_t DrawUtils::getTextWidth(const char *string) { uint32_t DrawUtils::getTextWidth(const wchar_t *string) { FT_GlyphSlot slot = ft_face->glyph; - uint32_t width = 0; + uint32_t width = 0; for (; *string; string++) { FT_Load_Glyph(ft_face, FT_Get_Char_Index(ft_face, *string), FT_LOAD_BITMAP_METRICS_ONLY); diff --git a/src/DrawUtils.h b/src/DrawUtils.h index 6ebcf5e..315d379 100644 --- a/src/DrawUtils.h +++ b/src/DrawUtils.h @@ -3,7 +3,7 @@ #include // visible screen sizes -#define SCREEN_WIDTH 854 +#define SCREEN_WIDTH 854 #define SCREEN_HEIGHT 480 union Color { diff --git a/src/globals.cpp b/src/globals.cpp index ef630d0..b2c91aa 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -1,19 +1,19 @@ #include "globals.h" -int gPreferSystemSettings = 1; -int gAutoDetection = 1; -int gForceSettingsEnabled = 0; -Lanuages gDefaultLanguage = LANG_ENGLISH; -int32_t gDefaultCountry = 78; +int gPreferSystemSettings = 1; +int gAutoDetection = 1; +int gForceSettingsEnabled = 0; +Lanuages gDefaultLanguage = LANG_ENGLISH; +int32_t gDefaultCountry = 78; MCPRegion gDefaultProductArea = MCP_REGION_EUROPE; -Lanuages gCurrentLanguage = gDefaultLanguage; -int32_t gCurrentCountry = gDefaultCountry; +Lanuages gCurrentLanguage = gDefaultLanguage; +int32_t gCurrentCountry = gDefaultCountry; MCPRegion gCurrentProductArea = gDefaultProductArea; -Lanuages gDefaultLangForEUR = LANG_ENGLISH; +Lanuages gDefaultLangForEUR = LANG_ENGLISH; int32_t gDefaultCountryForEUR = 110; -Lanuages gDefaultLangForUSA = LANG_ENGLISH; +Lanuages gDefaultLangForUSA = LANG_ENGLISH; int32_t gDefaultCountryForUSA = 49; -Lanuages gDefaultLangForJPN = LANG_JAPANESE; +Lanuages gDefaultLangForJPN = LANG_JAPANESE; int32_t gDefaultCountryForJPN = 1; \ No newline at end of file diff --git a/src/globals.h b/src/globals.h index f4058ed..5b3d5e0 100644 --- a/src/globals.h +++ b/src/globals.h @@ -5,15 +5,15 @@ extern int gForceSettingsEnabled; enum Lanuages { - LANG_JAPANESE = 0, - LANG_ENGLISH = 1, - LANG_FRANCAIS = 2, - LANG_DEUTSCH = 3, - LANG_ESPANOL = 5, - LANG_ITALIANO = 4, + LANG_JAPANESE = 0, + LANG_ENGLISH = 1, + LANG_FRANCAIS = 2, + LANG_DEUTSCH = 3, + LANG_ESPANOL = 5, + LANG_ITALIANO = 4, LANG_NEDERLANDS = 8, - LANG_PORTUGUES = 9, - LANG_RUSSKI = 10, + LANG_PORTUGUES = 9, + LANG_RUSSKI = 10, }; diff --git a/src/main.cpp b/src/main.cpp index 2b245d4..48b95a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,22 +1,22 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "utils/logger.h" #include "ConfigUtils.h" -#include -#include -#include -#include -#include -#include -#include -#include #include "globals.h" +#include "utils/logger.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include WUPS_PLUGIN_NAME("Region Free Plugin"); WUPS_PLUGIN_DESCRIPTION("Allows the user to load titles from other regions"); @@ -63,29 +63,29 @@ DECL_FUNCTION(int, UCReadSysConfig, int IOHandle, int count, struct UCSysConfig } ON_APPLICATION_ENDS() { - gCurrentLanguage = gDefaultLanguage; - gCurrentCountry = gDefaultCountry; + gCurrentLanguage = gDefaultLanguage; + gCurrentCountry = gDefaultCountry; gCurrentProductArea = gDefaultProductArea; deinitLogging(); } -#define CAT_GENERAL_ROOT "root" -#define CAT_GENERAL_SETTINGS "general_settings" -#define CAT_TITLE_SETTINGS "title_settings" +#define CAT_GENERAL_ROOT "root" +#define CAT_GENERAL_SETTINGS "general_settings" +#define CAT_TITLE_SETTINGS "title_settings" -#define VAL_LANGUAGE "language" -#define VAL_COUNTRY "cntry_reg" -#define VAL_PRODUCT_AREA "product_area" +#define VAL_LANGUAGE "language" +#define VAL_COUNTRY "cntry_reg" +#define VAL_PRODUCT_AREA "product_area" -#define VAL_PREFER_SYSTEM_SETTINGS "prefer_system_settings" -#define VAL_AUTO_DETECTION "auto_detection" -#define VAL_DEFAULT_LANG_EUR "default_lang_eur" -#define VAL_DEFAULT_LANG_USA "default_lang_usa" -#define VAL_DEFAULT_LANG_JPN "default_lang_jpn" +#define VAL_PREFER_SYSTEM_SETTINGS "prefer_system_settings" +#define VAL_AUTO_DETECTION "auto_detection" +#define VAL_DEFAULT_LANG_EUR "default_lang_eur" +#define VAL_DEFAULT_LANG_USA "default_lang_usa" +#define VAL_DEFAULT_LANG_JPN "default_lang_jpn" -#define VAL_DEFAULT_COUNTRY_EUR "default_cntry_reg_eur" -#define VAL_DEFAULT_COUNTRY_USA "default_cntry_reg_usa" -#define VAL_DEFAULT_COUNTRY_JPN "default_cntry_reg_jpn" +#define VAL_DEFAULT_COUNTRY_EUR "default_cntry_reg_eur" +#define VAL_DEFAULT_COUNTRY_USA "default_cntry_reg_usa" +#define VAL_DEFAULT_COUNTRY_JPN "default_cntry_reg_jpn" extern "C" void ACPInitialize(); extern "C" void ACPFinalize(); @@ -101,24 +101,25 @@ DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint3 ON_FUNCTIONS_PATCHED() { MCPRegion real_product_area; auto real_product_area_valid = getRealProductArea(&real_product_area); - if(real_product_area_valid){ - if(real_product_area == MCP_REGION_EUROPE){ + if (real_product_area_valid) { + if (real_product_area == MCP_REGION_EUROPE) { gDefaultProductArea = MCP_REGION_EUROPE; - gDefaultLanguage = gDefaultLangForEUR; - gDefaultCountry = gDefaultCountryForEUR; - } else if(real_product_area == MCP_REGION_JAPAN){ + gDefaultLanguage = gDefaultLangForEUR; + gDefaultCountry = gDefaultCountryForEUR; + } else if (real_product_area == MCP_REGION_JAPAN) { gDefaultProductArea = MCP_REGION_JAPAN; - gDefaultLanguage = gDefaultLangForJPN; - gDefaultCountry = gDefaultCountryForJPN; - }if(real_product_area == MCP_REGION_USA){ + gDefaultLanguage = gDefaultLangForJPN; + gDefaultCountry = gDefaultCountryForJPN; + } + if (real_product_area == MCP_REGION_USA) { gDefaultProductArea = MCP_REGION_USA; - gDefaultLanguage = gDefaultLangForUSA; - gDefaultCountry = gDefaultCountryForUSA; + gDefaultLanguage = gDefaultLangForUSA; + gDefaultCountry = gDefaultCountryForUSA; } } bool forceConfigMenu = false; - auto *acpMetaXml = (ACPMetaXml *) memalign(0x40, 0x4000); + auto *acpMetaXml = (ACPMetaXml *) memalign(0x40, 0x4000); memset(acpMetaXml, 0, sizeof(ACPMetaXml)); auto regionFromXML = 0; @@ -133,18 +134,18 @@ ON_FUNCTIONS_PATCHED() { if (OSGetTitleID() == 0x0005001010040000L || acpMetaXml->region == 1) { DEBUG_FUNCTION_LINE("Set default to JAPAN"); gDefaultProductArea = MCP_REGION_JAPAN; - gDefaultLanguage = gDefaultLangForJPN; - gDefaultCountry = gDefaultCountryForJPN; + gDefaultLanguage = gDefaultLangForJPN; + gDefaultCountry = gDefaultCountryForJPN; } else if (OSGetTitleID() == 0x0005001010040100L || acpMetaXml->region == 2) { DEBUG_FUNCTION_LINE("Set default to USA"); gDefaultProductArea = MCP_REGION_USA; - gDefaultLanguage = gDefaultLangForUSA; - gDefaultCountry = gDefaultCountryForUSA; + gDefaultLanguage = gDefaultLangForUSA; + gDefaultCountry = gDefaultCountryForUSA; } else if (OSGetTitleID() == 0x0005001010040200L || acpMetaXml->region == 4) { DEBUG_FUNCTION_LINE("Set default to EUR"); gDefaultProductArea = MCP_REGION_EUROPE; - gDefaultLanguage = gDefaultLangForEUR; - gDefaultCountry = gDefaultCountryForEUR; + gDefaultLanguage = gDefaultLangForEUR; + gDefaultCountry = gDefaultCountryForEUR; } else { DEBUG_FUNCTION_LINE("Unknown area %08X, forcing language will be disabled", acpMetaXml->region); forceConfigMenu = true; @@ -160,8 +161,8 @@ ON_FUNCTIONS_PATCHED() { } // Get region and lang from console and set these as default. - gCurrentLanguage = gDefaultLanguage; - gCurrentCountry = gDefaultCountry; + gCurrentLanguage = gDefaultLanguage; + gCurrentCountry = gDefaultCountry; gCurrentProductArea = gDefaultProductArea; if (gPreferSystemSettings && real_product_area_valid) { @@ -172,10 +173,10 @@ ON_FUNCTIONS_PATCHED() { if (ucHandle >= 0) { UCSysConfig sysConfig; memset((void *) &sysConfig, 0, sizeof(sysConfig)); - uint32_t data = 0xFFFFFFFF; + uint32_t data = 0xFFFFFFFF; sysConfig.dataType = UC_DATATYPE_UNSIGNED_INT; sysConfig.dataSize = 4; - sysConfig.data = &data; + sysConfig.data = &data; strncpy(sysConfig.name, "cafe.language", 64); int ucRes = real_UCReadSysConfig(ucHandle, 1, &sysConfig); @@ -194,7 +195,7 @@ ON_FUNCTIONS_PATCHED() { } wups_storage_item_t *root = nullptr; - auto resa = WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root); + auto resa = WUPS_GetSubItem(nullptr, CAT_GENERAL_ROOT, &root); if (resa != WUPS_STORAGE_ERROR_SUCCESS) { DEBUG_FUNCTION_LINE("Failed to read %s subitem", CAT_GENERAL_ROOT); return; @@ -372,11 +373,11 @@ void default_lang_changed(ConfigItemMultipleValues *item, uint32_t newValue) { void getConfigInfoForLangMap(std::map &curLangMap, ConfigItemMultipleValuesPair *pair, uint32_t default_lang, uint32_t *default_index, uint32_t *len) { uint32_t i = 0; - for (auto &curEntry: curLangMap) { + for (auto &curEntry : curLangMap) { if (default_lang == curEntry.first) { *default_index = i; } - pair[i].value = curEntry.first; + pair[i].value = curEntry.first; pair[i].valueName = (char *) curEntry.second; i++; } @@ -397,26 +398,25 @@ WUPS_GET_CONFIG() { WUPSConfigItemBoolean_AddToCategoryHandled(config, cat, VAL_PREFER_SYSTEM_SETTINGS, "Prefer System Settings For Own Region", gPreferSystemSettings, &prefer_system_changed); std::map eur_lang_map{ - {LANG_ENGLISH, "English"}, - {LANG_FRANCAIS, "Francais"}, - {LANG_DEUTSCH, "Deutsch"}, - {LANG_ITALIANO, "Italiano"}, - {LANG_ESPANOL, "Espanol"}, + {LANG_ENGLISH, "English"}, + {LANG_FRANCAIS, "Francais"}, + {LANG_DEUTSCH, "Deutsch"}, + {LANG_ITALIANO, "Italiano"}, + {LANG_ESPANOL, "Espanol"}, {LANG_NEDERLANDS, "Nederlands"}, - {LANG_PORTUGUES, "Portugues"}, - {LANG_RUSSKI, "Russki"}, + {LANG_PORTUGUES, "Portugues"}, + {LANG_RUSSKI, "Russki"}, }; std::map usa_lang_map{ - {LANG_ENGLISH, "English"}, - {LANG_FRANCAIS, "Francais"}, - {LANG_ESPANOL, "Espanol"}, - {LANG_PORTUGUES, "Portugues"} - }; + {LANG_ENGLISH, "English"}, + {LANG_FRANCAIS, "Francais"}, + {LANG_ESPANOL, "Espanol"}, + {LANG_PORTUGUES, "Portugues"}}; ConfigItemMultipleValuesPair lang_eur_pair[eur_lang_map.size()]; uint32_t number_lang_eur_values = 0; - uint32_t default_index_eur = 0; + uint32_t default_index_eur = 0; getConfigInfoForLangMap(eur_lang_map, lang_eur_pair, gDefaultLangForEUR, &default_index_eur, &number_lang_eur_values); @@ -425,7 +425,7 @@ WUPS_GET_CONFIG() { ConfigItemMultipleValuesPair lang_usa_pair[eur_lang_map.size()]; uint32_t number_lang_usa_values = 0; - uint32_t default_index_usa = 0; + uint32_t default_index_usa = 0; getConfigInfoForLangMap(usa_lang_map, lang_usa_pair, gDefaultLangForUSA, &default_index_usa, &number_lang_usa_values); @@ -459,91 +459,91 @@ DECL_FUNCTION(int, MCP_GetSysProdSettings, int IOHandle, struct MCPSysProdSettin static const uint64_t sSysAppTitleId[][3] = - { { - // Updater - 0x0005001010040000ull, - 0x0005001010040100ull, - 0x0005001010040200ull, - }, + { + // Updater + 0x0005001010040000ull, + 0x0005001010040100ull, + 0x0005001010040200ull, + }, - { - // System Settings - 0x0005001010047000ull, - 0x0005001010047100ull, - 0x0005001010047200ull, - }, + { + // System Settings + 0x0005001010047000ull, + 0x0005001010047100ull, + 0x0005001010047200ull, + }, - { - // Parental Controls - 0x0005001010048000ull, - 0x0005001010048100ull, - 0x0005001010048200ull, - }, + { + // Parental Controls + 0x0005001010048000ull, + 0x0005001010048100ull, + 0x0005001010048200ull, + }, - { - // User Settings - 0x0005001010049000ull, - 0x0005001010049100ull, - 0x0005001010049200ull, - }, + { + // User Settings + 0x0005001010049000ull, + 0x0005001010049100ull, + 0x0005001010049200ull, + }, - { - // Mii Maker - 0x000500101004A000ull, - 0x000500101004A100ull, - 0x000500101004A200ull, - }, + { + // Mii Maker + 0x000500101004A000ull, + 0x000500101004A100ull, + 0x000500101004A200ull, + }, - { - // Account Settings - 0x000500101004B000ull, - 0x000500101004B100ull, - 0x000500101004B200ull, - }, + { + // Account Settings + 0x000500101004B000ull, + 0x000500101004B100ull, + 0x000500101004B200ull, + }, - { - // Daily log - 0x000500101004C000ull, - 0x000500101004C100ull, - 0x000500101004C200ull, - }, + { + // Daily log + 0x000500101004C000ull, + 0x000500101004C100ull, + 0x000500101004C200ull, + }, - { - // Notifications - 0x000500101004D000ull, - 0x000500101004D100ull, - 0x000500101004D200ull, - }, + { + // Notifications + 0x000500101004D000ull, + 0x000500101004D100ull, + 0x000500101004D200ull, + }, - { - // Health and Safety Information - 0x000500101004E000ull, - 0x000500101004E100ull, - 0x000500101004E200ull, - }, + { + // Health and Safety Information + 0x000500101004E000ull, + 0x000500101004E100ull, + 0x000500101004E200ull, + }, - { - // Electronic Manual - 0x0005001B10059000ull, - 0x0005001B10059100ull, - 0x0005001B10059200ull, - }, + { + // Electronic Manual + 0x0005001B10059000ull, + 0x0005001B10059100ull, + 0x0005001B10059200ull, + }, - { - // Wii U Chat - 0x000500101005A000ull, - 0x000500101005A100ull, - 0x000500101005A200ull, - }, + { + // Wii U Chat + 0x000500101005A000ull, + 0x000500101005A100ull, + 0x000500101005A200ull, + }, - { - // "Software/Data Transfer" - 0x0005001010062000ull, - 0x0005001010062100ull, - 0x0005001010062200ull, - }, - }; + { + // "Software/Data Transfer" + 0x0005001010062000ull, + 0x0005001010062100ull, + 0x0005001010062200ull, + }, +}; bool getRealProductArea(MCPRegion *out) { if (out == nullptr) { @@ -552,7 +552,7 @@ bool getRealProductArea(MCPRegion *out) { auto handle = MCP_Open(); if (handle >= 0) { auto data = (struct MCPSysProdSettings *) memalign(0x40, sizeof(struct MCPSysProdSettings)); - auto res = real_MCP_GetSysProdSettings(handle, data); + auto res = real_MCP_GetSysProdSettings(handle, data); if (res >= 0) { *out = data->product_area; } @@ -587,4 +587,3 @@ WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchM WUPS_MUST_REPLACE(MCP_GetSysProdSettings, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetSysProdSettings); WUPS_MUST_REPLACE(UCReadSysConfig, WUPS_LOADER_LIBRARY_COREINIT, UCReadSysConfig); WUPS_MUST_REPLACE(_SYSGetSystemApplicationTitleIdByProdArea, WUPS_LOADER_LIBRARY_SYSAPP, _SYSGetSystemApplicationTitleIdByProdArea); - diff --git a/src/utils/logger.c b/src/utils/logger.c index 0411db7..f700806 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -1,19 +1,19 @@ #ifdef DEBUG #include -#include #include #include +#include uint32_t moduleLogInit = false; -uint32_t cafeLogInit = false; -uint32_t udpLogInit = false; +uint32_t cafeLogInit = false; +uint32_t udpLogInit = false; #endif // DEBUG void initLogging() { #ifdef DEBUG if (!(moduleLogInit = WHBLogModuleInit())) { cafeLogInit = WHBLogCafeInit(); - udpLogInit = WHBLogUdpInit(); + udpLogInit = WHBLogUdpInit(); } #endif // DEBUG } diff --git a/src/utils/logger.h b/src/utils/logger.h index 6ff5ae2..061d52e 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { @@ -9,26 +9,28 @@ extern "C" { #ifdef DEBUG -#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) +#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ - WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \ + do { \ + WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ - WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ + do { \ + WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) #else #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) #endif @@ -39,4 +41,3 @@ void deinitLogging(); #ifdef __cplusplus } #endif -