Skip to content

Commit

Permalink
Locale.txt improvements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Roberto-Nessy committed Mar 20, 2024
1 parent 5b13aa0 commit a668f2d
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 12 deletions.
3 changes: 2 additions & 1 deletion source/include/setting_descriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,5 @@ extern string_view skipMikauCutsceneDesc;
extern string_view skipBombersMinigameDesc;
extern string_view NARegionDesc;
extern string_view EURegionDesc;
extern string_view VersionDesc;
extern string_view VersionDesc;
extern string_view LanguageDesc;
12 changes: 12 additions & 0 deletions source/include/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions source/include/system.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <3ds.h>

void SystemInfoInit(void);
CFG_Region SystemInfo_GetRegion(void);
CFG_Language SystemInfo_GetLanguage(void);
2 changes: 2 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:&#@#",
Expand Down
34 changes: 29 additions & 5 deletions source/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ bool WriteAllPatches() {
/*-------------------
| LOCALE EMULATION |
-------------------*/

if (Settings::PlayOption.Value<u8>() == 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<u8>() != Settings::LANGUAGE_NONE) {
Handle localeOut;
//NA
if (!Settings::RegionSelect){
Expand All @@ -506,18 +506,42 @@ bool WriteAllPatches() {
}
}


std::vector<char> buffer = { 'U', 'S', 'A', ' ', 'E', 'N' };
// Change EN to appropriate language code if necessary
switch (Settings::LanguageSelect.Value<u8>()) {
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<char> buffer = { 'U', 'S', 'A', ' ', 'E', 'N' };
if (!R_SUCCEEDED(res = FSFILE_Write(localeOut, &bytesWritten, 0, buffer.data(), buffer.size(), FS_WRITE_FLUSH))) {
return false;
}
FSFILE_Close(localeOut);
}
//EU
if (Settings::RegionSelect){
std::vector<char> 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;
}
Expand Down
6 changes: 5 additions & 1 deletion source/setting_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"; //
"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"; //
48 changes: 43 additions & 5 deletions source/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<Option *> gameOptions = {
&PlayOption,
&Version,
&GenerateSpoilerLog,
&IngameSpoilers,
&RegionSelect,
&LanguageSelect,
};
//TODO MM3D LOGIC TRICKS
//Function to make defining logic tricks easier to read
Expand Down Expand Up @@ -1421,6 +1424,41 @@ namespace Settings {
// ShuffleOcaMusic.Hide();
// }

// Playing on console and selected game region does not match console region
if (!PlayOption && ((!RegionSelect && SystemInfo_GetRegion() != CFG_REGION_USA) || (RegionSelect && SystemInfo_GetRegion() != CFG_REGION_EUR))) {
LanguageSelect.Unhide();

if (LanguageSelect.Is(LANGUAGE_NONE)) {
switch(SystemInfo_GetLanguage()) {
case CFG_LANGUAGE_FR:
LanguageSelect.SetSelectedIndex(LANGUAGE_FRENCH);
break;
case CFG_LANGUAGE_ES:
LanguageSelect.SetSelectedIndex(LANGUAGE_SPANISH);
break;
case CFG_LANGUAGE_DE:
LanguageSelect.SetSelectedIndex(LANGUAGE_GERMAN);
break;
case CFG_LANGUAGE_IT:
LanguageSelect.SetSelectedIndex(LANGUAGE_ITALIAN);
break;
default:
LanguageSelect.SetSelectedIndex(LANGUAGE_ENGLISH);
}
}

if (LanguageSelect.Value<u8>() < LANGUAGE_ENGLISH) {
LanguageSelect.SetSelectedIndex((RegionSelect) ? LANGUAGE_ITALIAN : LANGUAGE_SPANISH);
}

if (LanguageSelect.Value<u8>() > ((RegionSelect) ? LANGUAGE_ITALIAN : LANGUAGE_SPANISH)) {
LanguageSelect.SetSelectedIndex(LANGUAGE_ENGLISH);
}
} else {
LanguageSelect.Hide();
LanguageSelect.SetSelectedIndex(LANGUAGE_NONE);
}

ResolveExcludedLocationConflicts();
}

Expand Down
14 changes: 14 additions & 0 deletions source/system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "system.hpp"

CFG_Region systemRegion;
CFG_Language systemLanguage;

void SystemInfoInit(void) {
cfguInit();
CFGU_SecureInfoGetRegion((u8*)&systemRegion);
CFGU_GetSystemLanguage((u8*)&systemLanguage);
cfguExit();
}

CFG_Region SystemInfo_GetRegion(void) { return systemRegion; }
CFG_Language SystemInfo_GetLanguage(void) { return systemLanguage; }

0 comments on commit a668f2d

Please sign in to comment.