From a668f2d79678cd99f8ef51857062abdd5fd7d103 Mon Sep 17 00:00:00 2001 From: Nessy Date: Wed, 20 Mar 2024 19:38:20 +0000 Subject: [PATCH] Locale.txt improvements A locale.txt file will now only be generated if the selected game region is different to the console region. If a locale.txt file does need to be generated a new option to select the language set by the file will appear. If available, the default value will be the system's language setting, otherwise it will default to English. --- source/include/setting_descriptions.hpp | 3 +- source/include/settings.hpp | 12 +++++++ source/include/system.hpp | 7 ++++ source/main.cpp | 2 ++ source/patch.cpp | 34 +++++++++++++++--- source/setting_descriptions.cpp | 6 +++- source/settings.cpp | 48 ++++++++++++++++++++++--- source/system.cpp | 14 ++++++++ 8 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 source/include/system.hpp create mode 100644 source/system.cpp diff --git a/source/include/setting_descriptions.hpp b/source/include/setting_descriptions.hpp index 8c7d541..668452b 100644 --- a/source/include/setting_descriptions.hpp +++ b/source/include/setting_descriptions.hpp @@ -228,4 +228,5 @@ extern string_view skipMikauCutsceneDesc; extern string_view skipBombersMinigameDesc; extern string_view NARegionDesc; extern string_view EURegionDesc; -extern string_view VersionDesc; \ No newline at end of file +extern string_view VersionDesc; +extern string_view LanguageDesc; \ No newline at end of file diff --git a/source/include/settings.hpp b/source/include/settings.hpp index 8cb4de4..8964fcb 100644 --- a/source/include/settings.hpp +++ b/source/include/settings.hpp @@ -252,6 +252,17 @@ class Menu { }; namespace Settings { + typedef enum { + LANGUAGE_NONE = 0, + LANGUAGE_WRAP_LOW, + LANGUAGE_ENGLISH, + LANGUAGE_FRENCH, + LANGUAGE_SPANISH, + LANGUAGE_GERMAN, + LANGUAGE_ITALIAN, + LANGUAGE_WRAP_HIGH, + } LanguageSettings; + void UpdateSettings(); rnd::SettingsContext FillContext(); void InitSettings(); @@ -420,6 +431,7 @@ namespace Settings { extern Option ChangeOverworldItems; extern Option IngameSpoilers; extern Option RegionSelect; + extern Option LanguageSelect; extern Option MenuOpeningButton; extern Option RsDurability; extern Option SkipBombersMinigame; diff --git a/source/include/system.hpp b/source/include/system.hpp new file mode 100644 index 0000000..038d972 --- /dev/null +++ b/source/include/system.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include <3ds.h> + +void SystemInfoInit(void); +CFG_Region SystemInfo_GetRegion(void); +CFG_Language SystemInfo_GetLanguage(void); diff --git a/source/main.cpp b/source/main.cpp index 5951542..bdfb2ad 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -9,6 +9,7 @@ #include "item_location.hpp" #include "location_access.hpp" #include "custom_messages.hpp" +#include "system.hpp" #define TICKS_PER_SEC 268123480.0 @@ -21,6 +22,7 @@ int main() { ItemTable_Init(); LocationTable_Init(); MenuInit(); + SystemInfoInit(); /*CustomMessages::CreateMessage(0x0224, 0x8000, 0x3FFFFFFF, 0xFF0000, "This is a test scrolling #custom message# with #multiple# #colours#, %d%e%l%a%y%s, and icons $ $ $^Let's also test filename:&#@#", diff --git a/source/patch.cpp b/source/patch.cpp index 91b4c1e..e7c2c66 100644 --- a/source/patch.cpp +++ b/source/patch.cpp @@ -485,8 +485,8 @@ bool WriteAllPatches() { /*------------------- | LOCALE EMULATION | -------------------*/ - - if (Settings::PlayOption.Value() == PATCH_CONSOLE) { + // Check if a language is selected, only the case if playing on console and region does not match selected game region + if (Settings::LanguageSelect.Value() != Settings::LANGUAGE_NONE) { Handle localeOut; //NA if (!Settings::RegionSelect){ @@ -506,10 +506,31 @@ bool WriteAllPatches() { } } - + std::vector buffer = { 'U', 'S', 'A', ' ', 'E', 'N' }; + // Change EN to appropriate language code if necessary + switch (Settings::LanguageSelect.Value()) { + case Settings::LANGUAGE_FRENCH: + buffer[4] = 'F'; + buffer[5] = 'R'; + break; + + case Settings::LANGUAGE_SPANISH: + buffer[4] = 'E'; + buffer[5] = 'S'; + break; + + case Settings::LANGUAGE_GERMAN: + buffer[4] = 'D'; + buffer[5] = 'E'; + break; + + case Settings::LANGUAGE_ITALIAN: + buffer[4] = 'I'; + buffer[5] = 'T'; + } + //NA if (!Settings::RegionSelect){ - std::vector buffer = { 'U', 'S', 'A', ' ', 'E', 'N' }; if (!R_SUCCEEDED(res = FSFILE_Write(localeOut, &bytesWritten, 0, buffer.data(), buffer.size(), FS_WRITE_FLUSH))) { return false; } @@ -517,7 +538,10 @@ bool WriteAllPatches() { } //EU if (Settings::RegionSelect){ - std::vector buffer = { 'E', 'U', 'R', ' ', 'E', 'N' }; + // Change USA to EUR + buffer[0] = 'E'; + buffer[1] = 'U'; + buffer[2] = 'R'; if (!R_SUCCEEDED(res = FSFILE_Write(localeOut, &bytesWritten, 0, buffer.data(), buffer.size(), FS_WRITE_FLUSH))) { return false; } diff --git a/source/setting_descriptions.cpp b/source/setting_descriptions.cpp index 1bb5a40..112d40e 100644 --- a/source/setting_descriptions.cpp +++ b/source/setting_descriptions.cpp @@ -655,4 +655,8 @@ string_view EURegionDesc = " Europe\n" "Currently only supports English Hints and Custom Text"; string_view VersionDesc = "Due to patch size when using version 1.1 it can \n" // "take up to 30 seconds to launch the game, this is\n"// - "expected and will not effect gameplay"; // \ No newline at end of file + "expected and will not effect gameplay"; // +string_view LanguageDesc = "Selected region differs from console meaning a\n" // + "locale.txt file will need to be generated\n\n" // + "Please select your preferred language\n" // + "NOTE: custom text still only supports English"; // \ No newline at end of file diff --git a/source/settings.cpp b/source/settings.cpp index d5aff7d..ab6a7fa 100644 --- a/source/settings.cpp +++ b/source/settings.cpp @@ -10,6 +10,7 @@ #include "random.hpp" #include "version.hpp" #include "setting_descriptions.hpp" +#include "system.hpp" #include "keys.hpp" //#include "../mm3dr/code/include/game/pad.h" @@ -72,17 +73,19 @@ namespace Settings { }; //Game Settings - Option GenerateSpoilerLog = Option::Bool("Generate Spoiler Log", { "No", "Yes" }, { genSpoilerLogDesc }, OptionCategory::Setting, 1); // On - Option IngameSpoilers = Option::Bool("Ingame Spoilers", { "Hide", "Show" }, { ingameSpoilersHideDesc, ingameSpoilersShowDesc }); - Option RegionSelect = Option::Bool("Game Region", {"NA", "EU"}, {NARegionDesc, EURegionDesc}); - Option PlayOption = Option::U8("Console/Emulator", {"3DS", "Citra"}, {"How will you Play?"}); - Option Version = Option::U8("Version", {"1.0", "1.1"}, {VersionDesc}); + Option GenerateSpoilerLog = Option::Bool("Generate Spoiler Log", { "No", "Yes" }, { genSpoilerLogDesc }, OptionCategory::Setting, 1); // On + Option IngameSpoilers = Option::Bool("Ingame Spoilers", { "Hide", "Show" }, { ingameSpoilersHideDesc, ingameSpoilersShowDesc }); + Option RegionSelect = Option::Bool("Game Region", { "NA", "EU" }, { NARegionDesc, EURegionDesc }); + Option PlayOption = Option::U8 ("Console/Emulator", { "3DS", "Citra" }, { "How will you Play?" }); + Option LanguageSelect = Option::U8 (" Language", { "", "", "English", "Francais", "Espanol", "Deutsch", "Italiano", "" }, { LanguageDesc }); + Option Version = Option::U8 ("Version", { "1.0", "1.1" }, { VersionDesc }); std::vector