From 0306cbc1363db979db81859f26514be13c45b49c Mon Sep 17 00:00:00 2001 From: illusion98 <37698908+illusion98@users.noreply.github.com> Date: Sun, 27 Oct 2019 01:46:24 -0500 Subject: [PATCH] Forgot to fix this --- src/xenia/kernel/xam/xam_locale.cc | 83 +++++++++++++++++++----------- src/xenia/kernel/xam/xam_net.cc | 6 ++- src/xenia/kernel/xam/xam_user.cc | 13 ++++- 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/src/xenia/kernel/xam/xam_locale.cc b/src/xenia/kernel/xam/xam_locale.cc index 1c6c465ce..9cd5125df 100644 --- a/src/xenia/kernel/xam/xam_locale.cc +++ b/src/xenia/kernel/xam/xam_locale.cc @@ -17,15 +17,12 @@ #include "xenia/kernel/xthread.h" #include "xenia/xbox.h" +DECLARE_int32(user_country); + // TODO(gibbed): put these forward decls in a header somewhere. namespace xe { namespace kernel { -namespace xboxkrnl { -X_STATUS xeExGetXConfigSetting(uint16_t category, uint16_t setting, - void* buffer, uint16_t buffer_size, - uint16_t* required_size); -} // namespace xboxkrnl namespace xam { uint32_t xeXGetGameRegion(); } // namespace xam @@ -75,7 +72,8 @@ const wchar_t* xeXamGetOnlineCountryString(uint8_t id) { L"PG", L"PN", L"RE", L"RW", L"WS", L"SM", L"ST", L"SN", L"RS", L"SC", L"SL", L"SB", L"SO", L"LK", L"SH", L"KN", L"LC", L"PM", L"VC", L"SR", L"SZ", L"TJ", L"TZ", L"TL", L"TG", L"TK", L"TO", - L"TM", L"TC", L"TV", L"UG", + L"TM", L"TC", L"TV", L"UG", L"VU", L"VA", nullptr, L"VG", L"WF", + L"EH", L"ZM", L"ZZ", }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : nullptr; @@ -94,6 +92,7 @@ const wchar_t* xeXamGetCountryString(uint8_t id) { L"PH", L"PK", L"PL", L"PR", L"PT", L"PY", L"QA", L"RO", L"RU", L"SA", L"SE", L"SG", L"SI", L"SK", nullptr, L"SV", L"SY", L"TH", L"TN", L"TR", L"TT", L"TW", L"UA", L"US", L"UY", L"UZ", L"VE", L"VN", L"YE", L"ZA", + L"ZW", L"ZZ", }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : nullptr; @@ -102,7 +101,7 @@ const wchar_t* xeXamGetCountryString(uint8_t id) { const wchar_t* xeXamGetLanguageString(uint8_t id) { static const wchar_t* const table[] = { L"zz", L"en", L"ja", L"de", L"fr", L"es", L"it", L"ko", L"zh", - L"pt", nullptr, L"pl", L"ru", L"sv", L"tr", L"nb", L"nl", + L"pt", nullptr, L"pl", L"ru", L"sv", L"tr", L"nb", L"nl", L"zh", }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : nullptr; @@ -122,9 +121,19 @@ const wchar_t* xeXamGetLocaleString(uint8_t id) { uint8_t xeXamGetLocaleFromOnlineCountry(uint8_t id) { static uint8_t const table[] = { - 0, 43, 0, 0, 40, 2, 1, 0, 3, 0, 0, 0, 0, 4, 0, - 0, 5, 0, 33, 6, 7, 8, 0, 9, 13, 10, 0, 0, 0, 0, - 0, 31, 11, 0, 12, 35, 0, 14, 0, 15, 0, 0, 16, + 0, 43, 0, 0, 40, 2, 1, 0, 3, 0, 0, 0, 0, 4, 0, 0, 5, 0, 33, + 6, 7, 8, 0, 9, 13, 10, 0, 0, 0, 0, 0, 31, 11, 0, 12, 35, 0, 14, + 0, 15, 0, 0, 16, 0, 18, 42, 17, 0, 0, 0, 19, 0, 0, 20, 0, 0, 21, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 23, 25, + 24, 0, 0, 0, 0, 0, 26, 0, 27, 0, 0, 0, 37, 41, 32, 28, 0, 29, 0, + 0, 0, 0, 0, 39, 0, 34, 0, 36, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 38, }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : 0; @@ -132,9 +141,9 @@ uint8_t xeXamGetLocaleFromOnlineCountry(uint8_t id) { uint8_t xeXamGetLanguageFromOnlineLanguage(uint8_t id) { static uint8_t const table[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 11, 12, 1, 1, 15, 16, 13, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 14, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 11, 12, 1, 1, 15, 16, 13, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 14, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : 0; @@ -156,13 +165,21 @@ const wchar_t* xeXamGetOnlineLanguageString(uint8_t id) { uint8_t xeXamGetCountryFromOnlineCountry(uint8_t id) { static uint8_t const table[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 0, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 0, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : 0; @@ -170,9 +187,12 @@ uint8_t xeXamGetCountryFromOnlineCountry(uint8_t id) { uint8_t xeXamGetLocaleFromCountry(uint8_t id) { static uint8_t const table[] = { - 0, 43, 0, 0, 40, 2, 1, 0, 3, 0, 0, 0, 0, 4, 0, - 0, 5, 0, 33, 6, 7, 8, 0, 9, 13, 10, 0, 0, 0, 0, - 0, 31, 11, 0, 12, 35, 0, 14, 0, 15, 0, 0, 16, + 0, 43, 0, 0, 40, 2, 1, 0, 3, 0, 0, 0, 0, 4, 0, 0, 5, 0, 33, + 6, 7, 8, 0, 9, 13, 10, 0, 0, 0, 0, 0, 31, 11, 0, 12, 35, 0, 14, + 0, 15, 0, 0, 16, 0, 18, 42, 17, 0, 0, 0, 19, 0, 0, 20, 0, 0, 21, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 23, 25, + 24, 0, 0, 0, 0, 0, 26, 0, 27, 0, 0, 0, 37, 41, 32, 28, 0, 29, 0, + 0, 0, 0, 0, 39, 0, 34, 0, 36, 0, 0, 0, 0, 0, 30, 0, 38, }; #pragma warning(suppress : 6385) return id < xe::countof(table) ? table[id] : 0; @@ -181,16 +201,17 @@ uint8_t xeXamGetLocaleFromCountry(uint8_t id) { // Helpers. uint8_t xeXamGetLocaleEx(uint8_t max_country_id, uint8_t max_locale_id) { - uint8_t country_id; - if (XSUCCEEDED(xboxkrnl::xeExGetXConfigSetting( - 3, 14, &country_id, sizeof(country_id), nullptr))) { - if (country_id <= max_country_id) { - uint8_t locale_id = xeXamGetLocaleFromCountry(country_id); - if (locale_id <= max_locale_id) { - return locale_id; - } + // TODO(gibbed): rework when XConfig is cleanly implemented. + uint8_t country_id = static_cast(cvars::user_country); + /*if (XSUCCEEDED(xboxkrnl::xeExGetXConfigSetting( + 3, 14, &country_id, sizeof(country_id), nullptr))) {*/ + if (country_id <= max_country_id) { + uint8_t locale_id = xeXamGetLocaleFromCountry(country_id); + if (locale_id <= max_locale_id) { + return locale_id; } } + /*}*/ // couldn't find locale, fallback from game region. auto game_region = xeXGetGameRegion(); diff --git a/src/xenia/kernel/xam/xam_net.cc b/src/xenia/kernel/xam/xam_net.cc index cd623973e..46165dd90 100644 --- a/src/xenia/kernel/xam/xam_net.cc +++ b/src/xenia/kernel/xam/xam_net.cc @@ -286,8 +286,10 @@ dword_result_t NetDll_WSARecvFrom(dword_t caller, dword_t socket, // //evt->Set(0, false); //} } - - return 0; + + // we're not going to be receiving packets any time soon + // return error so we don't wait on that - Cancerous + return -1; } DECLARE_XAM_EXPORT1(NetDll_WSARecvFrom, kNetworking, kStub); diff --git a/src/xenia/kernel/xam/xam_user.cc b/src/xenia/kernel/xam/xam_user.cc index 2e1e30a8a..cd932695a 100644 --- a/src/xenia/kernel/xam/xam_user.cc +++ b/src/xenia/kernel/xam/xam_user.cc @@ -168,8 +168,19 @@ dword_result_t XamUserGetName(dword_t user_index, lpstring_t buffer, if (user_index) { return X_ERROR_NO_SUCH_USER; } + + if (!buffer_len) { + return X_ERROR_SUCCESS; + } + const auto& user_profile = kernel_state()->user_profile(); - std::strncpy(buffer, user_profile->name().data(), buffer_len); + const auto& user_name = user_profile->name(); + + // Real XAM will only copy a maximum of 15 characters out. + size_t copy_length = std::min( + {size_t(15), user_name.size(), static_cast(buffer_len) - 1}); + std::memcpy(buffer, user_name.data(), copy_length); + buffer[copy_length] = '\0'; return X_ERROR_SUCCESS; } DECLARE_XAM_EXPORT1(XamUserGetName, kUserProfiles, kImplemented);