3
0
Fork 0
forked from suyu/suyu

CFG:U: Store country codes as u16 instead of char pointers, and return the correct error in GetCountryCodeID.

This commit is contained in:
Emmanuel Gil Peyrot 2014-12-01 16:56:41 +00:00
parent ae3c6e82f7
commit 5a3b1b5f44

View file

@ -11,33 +11,38 @@
namespace CFG_U { namespace CFG_U {
static const std::array<const char*, 187> country_codes = { // TODO(Link Mauve): use a constexpr once MSVC starts supporting it.
nullptr, "JP", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 0-7 #define C(code) ((code)[0] | ((code)[1] << 8))
"AI", "AG", "AR", "AW", "BS", "BB", "BZ", "BO", // 8-15
"BR", "VG", "CA", "KY", "CL", "CO", "CR", "DM", // 16-23 static const std::array<u16, 187> country_codes = {
"DO", "EC", "SV", "GF", "GD", "GP", "GT", "GY", // 24-31 0, C("JP"), 0, 0, 0, 0, 0, 0, // 0-7
"HT", "HN", "JM", "MQ", "MX", "MS", "AN", "NI", // 32-39 C("AI"), C("AG"), C("AR"), C("AW"), C("BS"), C("BB"), C("BZ"), C("BO"), // 8-15
"PA", "PY", "PE", "KN", "LC", "VC", "SR", "TT", // 40-47 C("BR"), C("VG"), C("CA"), C("KY"), C("CL"), C("CO"), C("CR"), C("DM"), // 16-23
"TC", "US", "UY", "VI", "VE", nullptr, nullptr, nullptr, // 48-55 C("DO"), C("EC"), C("SV"), C("GF"), C("GD"), C("GP"), C("GT"), C("GY"), // 24-31
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 56-63 C("HT"), C("HN"), C("JM"), C("MQ"), C("MX"), C("MS"), C("AN"), C("NI"), // 32-39
"AL", "AU", "AT", "BE", "BA", "BW", "BG", "HR", // 64-71 C("PA"), C("PY"), C("PE"), C("KN"), C("LC"), C("VC"), C("SR"), C("TT"), // 40-47
"CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", // 72-79 C("TC"), C("US"), C("UY"), C("VI"), C("VE"), 0, 0, 0, // 48-55
"HU", "IS", "IE", "IT", "LV", "LS", "LI", "LT", // 80-87 0, 0, 0, 0, 0, 0, 0, 0, // 56-63
"LU", "MK", "MT", "ME", "MZ", "NA", "NL", "NZ", // 88-95 C("AL"), C("AU"), C("AT"), C("BE"), C("BA"), C("BW"), C("BG"), C("HR"), // 64-71
"NO", "PL", "PT", "RO", "RU", "RS", "SK", "SI", // 96-103 C("CY"), C("CZ"), C("DK"), C("EE"), C("FI"), C("FR"), C("DE"), C("GR"), // 72-79
"ZA", "ES", "SZ", "SE", "CH", "TR", "GB", "ZM", // 104-111 C("HU"), C("IS"), C("IE"), C("IT"), C("LV"), C("LS"), C("LI"), C("LT"), // 80-87
"ZW", "AZ", "MR", "ML", "NE", "TD", "SD", "ER", // 112-119 C("LU"), C("MK"), C("MT"), C("ME"), C("MZ"), C("NA"), C("NL"), C("NZ"), // 88-95
"DJ", "SO", "AD", "GI", "GG", "IM", "JE", "MC", // 120-127 C("NO"), C("PL"), C("PT"), C("RO"), C("RU"), C("RS"), C("SK"), C("SI"), // 96-103
"TW", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 128-135 C("ZA"), C("ES"), C("SZ"), C("SE"), C("CH"), C("TR"), C("GB"), C("ZM"), // 104-111
"KR", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 136-143 C("ZW"), C("AZ"), C("MR"), C("ML"), C("NE"), C("TD"), C("SD"), C("ER"), // 112-119
"HK", "MO", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 144-151 C("DJ"), C("SO"), C("AD"), C("GI"), C("GG"), C("IM"), C("JE"), C("MC"), // 120-127
"ID", "SG", "TH", "PH", "MY", nullptr, nullptr, nullptr, // 152-159 C("TW"), 0, 0, 0, 0, 0, 0, 0, // 128-135
"CN", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 160-167 C("KR"), 0, 0, 0, 0, 0, 0, 0, // 136-143
"AE", "IN", "EG", "OM", "QA", "KW", "SA", "SY", // 168-175 C("HK"), C("MO"), 0, 0, 0, 0, 0, 0, // 144-151
"BH", "JO", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // 176-183 C("ID"), C("SG"), C("TH"), C("PH"), C("MY"), 0, 0, 0, // 152-159
"SM", "VA", "BM", // 184-186 C("CN"), 0, 0, 0, 0, 0, 0, 0, // 160-167
C("AE"), C("IN"), C("EG"), C("OM"), C("QA"), C("KW"), C("SA"), C("SY"), // 168-175
C("BH"), C("JO"), 0, 0, 0, 0, 0, 0, // 176-183
C("SM"), C("VA"), C("BM") // 184-186
}; };
#undef C
/** /**
* CFG_User::GetCountryCodeString service function * CFG_User::GetCountryCodeString service function
* Inputs: * Inputs:
@ -50,20 +55,14 @@ static void GetCountryCodeString(Service::Interface* self) {
u32* cmd_buffer = Service::GetCommandBuffer(); u32* cmd_buffer = Service::GetCommandBuffer();
u32 country_code_id = cmd_buffer[1]; u32 country_code_id = cmd_buffer[1];
if (country_code_id >= country_codes.size()) { if (country_code_id >= country_codes.size() || 0 == country_codes[country_code_id]) {
ERROR_LOG(KERNEL, "requested country code id=%d is invalid", country_code_id); ERROR_LOG(KERNEL, "requested country code id=%d is invalid", country_code_id);
cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw;
return; return;
} }
const char* code = country_codes[country_code_id]; cmd_buffer[1] = 0;
if (code != nullptr) { cmd_buffer[2] = country_codes[country_code_id];
cmd_buffer[1] = 0;
cmd_buffer[2] = code[0] | (code[1] << 8);
} else {
cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw;
DEBUG_LOG(KERNEL, "requested country code id=%d is not set", country_code_id);
}
} }
/** /**
@ -77,20 +76,25 @@ static void GetCountryCodeString(Service::Interface* self) {
static void GetCountryCodeID(Service::Interface* self) { static void GetCountryCodeID(Service::Interface* self) {
u32* cmd_buffer = Service::GetCommandBuffer(); u32* cmd_buffer = Service::GetCommandBuffer();
u16 country_code = cmd_buffer[1]; u16 country_code = cmd_buffer[1];
u16 country_code_id = -1; u16 country_code_id = 0;
for (u32 i = 0; i < country_codes.size(); ++i) { // The following algorithm will fail if the first country code isn't 0.
const char* code_string = country_codes[i]; _dbg_assert_(HLE, country_codes[0] == 0);
if (code_string != nullptr) { for (size_t id = 0; id < country_codes.size(); ++id) {
u16 code = code_string[0] | (code_string[1] << 8); if (country_codes[id] == country_code) {
if (code == country_code) { country_code_id = id;
country_code_id = i; break;
break;
}
} }
} }
if (0 == country_code_id) {
ERROR_LOG(KERNEL, "requested country code name=%c%c is invalid", country_code & 0xff, country_code >> 8);
cmd_buffer[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw;
cmd_buffer[2] = 0xFFFF;
return;
}
cmd_buffer[1] = 0; cmd_buffer[1] = 0;
cmd_buffer[2] = country_code_id; cmd_buffer[2] = country_code_id;
} }