diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/cfg_u.cpp | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/src/core/hle/service/cfg_u.cpp b/src/core/hle/service/cfg_u.cpp index d6b586ea0..82bab5797 100644 --- a/src/core/hle/service/cfg_u.cpp +++ b/src/core/hle/service/cfg_u.cpp | |||
| @@ -11,33 +11,38 @@ | |||
| 11 | 11 | ||
| 12 | namespace CFG_U { | 12 | namespace CFG_U { |
| 13 | 13 | ||
| 14 | static const std::array<const char*, 187> country_codes = { | 14 | // TODO(Link Mauve): use a constexpr once MSVC starts supporting it. |
| 15 | nullptr, "JP", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 0-7 | 15 | #define C(code) ((code)[0] | ((code)[1] << 8)) |
| 16 | "AI", "AG", "AR", "AW", "BS", "BB", "BZ", "BO", // 8-15 | 16 | |
| 17 | "BR", "VG", "CA", "KY", "CL", "CO", "CR", "DM", // 16-23 | 17 | static const std::array<u16, 187> country_codes = { |
| 18 | "DO", "EC", "SV", "GF", "GD", "GP", "GT", "GY", // 24-31 | 18 | 0, C("JP"), 0, 0, 0, 0, 0, 0, // 0-7 |
| 19 | "HT", "HN", "JM", "MQ", "MX", "MS", "AN", "NI", // 32-39 | 19 | C("AI"), C("AG"), C("AR"), C("AW"), C("BS"), C("BB"), C("BZ"), C("BO"), // 8-15 |
| 20 | "PA", "PY", "PE", "KN", "LC", "VC", "SR", "TT", // 40-47 | 20 | C("BR"), C("VG"), C("CA"), C("KY"), C("CL"), C("CO"), C("CR"), C("DM"), // 16-23 |
| 21 | "TC", "US", "UY", "VI", "VE", nullptr, nullptr, nullptr, // 48-55 | 21 | C("DO"), C("EC"), C("SV"), C("GF"), C("GD"), C("GP"), C("GT"), C("GY"), // 24-31 |
| 22 | nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 56-63 | 22 | C("HT"), C("HN"), C("JM"), C("MQ"), C("MX"), C("MS"), C("AN"), C("NI"), // 32-39 |
| 23 | "AL", "AU", "AT", "BE", "BA", "BW", "BG", "HR", // 64-71 | 23 | C("PA"), C("PY"), C("PE"), C("KN"), C("LC"), C("VC"), C("SR"), C("TT"), // 40-47 |
| 24 | "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", // 72-79 | 24 | C("TC"), C("US"), C("UY"), C("VI"), C("VE"), 0, 0, 0, // 48-55 |
| 25 | "HU", "IS", "IE", "IT", "LV", "LS", "LI", "LT", // 80-87 | 25 | 0, 0, 0, 0, 0, 0, 0, 0, // 56-63 |
| 26 | "LU", "MK", "MT", "ME", "MZ", "NA", "NL", "NZ", // 88-95 | 26 | C("AL"), C("AU"), C("AT"), C("BE"), C("BA"), C("BW"), C("BG"), C("HR"), // 64-71 |
| 27 | "NO", "PL", "PT", "RO", "RU", "RS", "SK", "SI", // 96-103 | 27 | C("CY"), C("CZ"), C("DK"), C("EE"), C("FI"), C("FR"), C("DE"), C("GR"), // 72-79 |
| 28 | "ZA", "ES", "SZ", "SE", "CH", "TR", "GB", "ZM", // 104-111 | 28 | C("HU"), C("IS"), C("IE"), C("IT"), C("LV"), C("LS"), C("LI"), C("LT"), // 80-87 |
| 29 | "ZW", "AZ", "MR", "ML", "NE", "TD", "SD", "ER", // 112-119 | 29 | C("LU"), C("MK"), C("MT"), C("ME"), C("MZ"), C("NA"), C("NL"), C("NZ"), // 88-95 |
| 30 | "DJ", "SO", "AD", "GI", "GG", "IM", "JE", "MC", // 120-127 | 30 | C("NO"), C("PL"), C("PT"), C("RO"), C("RU"), C("RS"), C("SK"), C("SI"), // 96-103 |
| 31 | "TW", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 128-135 | 31 | C("ZA"), C("ES"), C("SZ"), C("SE"), C("CH"), C("TR"), C("GB"), C("ZM"), // 104-111 |
| 32 | "KR", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 136-143 | 32 | C("ZW"), C("AZ"), C("MR"), C("ML"), C("NE"), C("TD"), C("SD"), C("ER"), // 112-119 |
| 33 | "HK", "MO", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 144-151 | 33 | C("DJ"), C("SO"), C("AD"), C("GI"), C("GG"), C("IM"), C("JE"), C("MC"), // 120-127 |
| 34 | "ID", "SG", "TH", "PH", "MY", nullptr, nullptr, nullptr, // 152-159 | 34 | C("TW"), 0, 0, 0, 0, 0, 0, 0, // 128-135 |
| 35 | "CN", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 160-167 | 35 | C("KR"), 0, 0, 0, 0, 0, 0, 0, // 136-143 |
| 36 | "AE", "IN", "EG", "OM", "QA", "KW", "SA", "SY", // 168-175 | 36 | C("HK"), C("MO"), 0, 0, 0, 0, 0, 0, // 144-151 |
| 37 | "BH", "JO", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 176-183 | 37 | C("ID"), C("SG"), C("TH"), C("PH"), C("MY"), 0, 0, 0, // 152-159 |
| 38 | "SM", "VA", "BM", // 184-186 | 38 | C("CN"), 0, 0, 0, 0, 0, 0, 0, // 160-167 |
| 39 | C("AE"), C("IN"), C("EG"), C("OM"), C("QA"), C("KW"), C("SA"), C("SY"), // 168-175 | ||
| 40 | C("BH"), C("JO"), 0, 0, 0, 0, 0, 0, // 176-183 | ||
| 41 | C("SM"), C("VA"), C("BM") // 184-186 | ||
| 39 | }; | 42 | }; |
| 40 | 43 | ||
| 44 | #undef C | ||
| 45 | |||
| 41 | /** | 46 | /** |
| 42 | * CFG_User::GetCountryCodeString service function | 47 | * CFG_User::GetCountryCodeString service function |
| 43 | * Inputs: | 48 | * Inputs: |
| @@ -50,20 +55,14 @@ static void GetCountryCodeString(Service::Interface* self) { | |||
| 50 | u32* cmd_buffer = Service::GetCommandBuffer(); | 55 | u32* cmd_buffer = Service::GetCommandBuffer(); |
| 51 | u32 country_code_id = cmd_buffer[1]; | 56 | u32 country_code_id = cmd_buffer[1]; |
| 52 | 57 | ||
| 53 | if (country_code_id >= country_codes.size()) { | 58 | if (country_code_id >= country_codes.size() || 0 == country_codes[country_code_id]) { |
| 54 | ERROR_LOG(KERNEL, "requested country code id=%d is invalid", country_code_id); | 59 | ERROR_LOG(KERNEL, "requested country code id=%d is invalid", country_code_id); |
| 55 | cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; | 60 | cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; |
| 56 | return; | 61 | return; |
| 57 | } | 62 | } |
| 58 | 63 | ||
| 59 | const char* code = country_codes[country_code_id]; | 64 | cmd_buffer[1] = 0; |
| 60 | if (code != nullptr) { | 65 | cmd_buffer[2] = country_codes[country_code_id]; |
| 61 | cmd_buffer[1] = 0; | ||
| 62 | cmd_buffer[2] = code[0] | (code[1] << 8); | ||
| 63 | } else { | ||
| 64 | cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; | ||
| 65 | DEBUG_LOG(KERNEL, "requested country code id=%d is not set", country_code_id); | ||
| 66 | } | ||
| 67 | } | 66 | } |
| 68 | 67 | ||
| 69 | /** | 68 | /** |
| @@ -77,20 +76,25 @@ static void GetCountryCodeString(Service::Interface* self) { | |||
| 77 | static void GetCountryCodeID(Service::Interface* self) { | 76 | static void GetCountryCodeID(Service::Interface* self) { |
| 78 | u32* cmd_buffer = Service::GetCommandBuffer(); | 77 | u32* cmd_buffer = Service::GetCommandBuffer(); |
| 79 | u16 country_code = cmd_buffer[1]; | 78 | u16 country_code = cmd_buffer[1]; |
| 80 | u16 country_code_id = -1; | 79 | u16 country_code_id = 0; |
| 81 | 80 | ||
| 82 | for (u32 i = 0; i < country_codes.size(); ++i) { | 81 | // The following algorithm will fail if the first country code isn't 0. |
| 83 | const char* code_string = country_codes[i]; | 82 | _dbg_assert_(HLE, country_codes[0] == 0); |
| 84 | 83 | ||
| 85 | if (code_string != nullptr) { | 84 | for (size_t id = 0; id < country_codes.size(); ++id) { |
| 86 | u16 code = code_string[0] | (code_string[1] << 8); | 85 | if (country_codes[id] == country_code) { |
| 87 | if (code == country_code) { | 86 | country_code_id = id; |
| 88 | country_code_id = i; | 87 | break; |
| 89 | break; | ||
| 90 | } | ||
| 91 | } | 88 | } |
| 92 | } | 89 | } |
| 93 | 90 | ||
| 91 | if (0 == country_code_id) { | ||
| 92 | ERROR_LOG(KERNEL, "requested country code name=%c%c is invalid", country_code & 0xff, country_code >> 8); | ||
| 93 | cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; | ||
| 94 | cmd_buffer[2] = 0xFFFF; | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | |||
| 94 | cmd_buffer[1] = 0; | 98 | cmd_buffer[1] = 0; |
| 95 | cmd_buffer[2] = country_code_id; | 99 | cmd_buffer[2] = country_code_id; |
| 96 | } | 100 | } |