/** ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** * Copyright 2021 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ #include "xenia/kernel/xam/apps/xgi_app.h" #include "xenia/base/logging.h" #include "xenia/base/threading.h" namespace xe { namespace kernel { namespace xam { namespace apps { struct X_XUSER_ACHIEVEMENT { xe::be user_idx; xe::be achievement_id; }; XgiApp::XgiApp(KernelState* kernel_state) : App(kernel_state, 0xFB) {} // http://mb.mirage.org/bugzilla/xliveless/main.c X_HRESULT XgiApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr, uint32_t buffer_length) { // NOTE: buffer_length may be zero or valid. auto buffer = memory_->TranslateVirtual(buffer_ptr); switch (message) { case 0x000B0006: { assert_true(!buffer_length || buffer_length == 24); // dword r3 user index // dword (unwritten?) // qword 0 // dword r4 context enum // dword r5 value uint32_t user_index = xe::load_and_swap(buffer + 0); uint32_t context_id = xe::load_and_swap(buffer + 16); uint32_t context_value = xe::load_and_swap(buffer + 20); XELOGD("XGIUserSetContextEx({:08X}, {:08X}, {:08X})", user_index, context_id, context_value); const util::XdbfGameData title_xdbf = kernel_state_->title_xdbf(); if (title_xdbf.is_valid()) { const auto context = title_xdbf.GetContext(context_id); const XLanguage title_language = title_xdbf.GetExistingLanguage( static_cast(XLanguage::kEnglish)); const std::string desc = title_xdbf.GetStringTableEntry(title_language, context.string_id); XELOGD("XGIUserSetContextEx: {} - Set to value: {}", desc, context_value); UserProfile* user_profile = kernel_state_->user_profile(user_index); if (user_profile) { user_profile->contexts_[context_id] = context_value; } } return X_E_SUCCESS; } case 0x000B0007: { uint32_t user_index = xe::load_and_swap(buffer + 0); uint32_t property_id = xe::load_and_swap(buffer + 16); uint32_t value_size = xe::load_and_swap(buffer + 20); uint32_t value_ptr = xe::load_and_swap(buffer + 24); XELOGD("XGIUserSetPropertyEx({:08X}, {:08X}, {}, {:08X})", user_index, property_id, value_size, value_ptr); const util::XdbfGameData title_xdbf = kernel_state_->title_xdbf(); if (title_xdbf.is_valid()) { const auto property = title_xdbf.GetContext(property_id); const XLanguage title_language = title_xdbf.GetExistingLanguage( static_cast(XLanguage::kEnglish)); const std::string desc = title_xdbf.GetStringTableEntry(title_language, property.string_id); XELOGD("XGIUserSetPropertyEx: Setting property: {}", desc); } return X_E_SUCCESS; } case 0x000B0008: { assert_true(!buffer_length || buffer_length == 8); uint32_t achievement_count = xe::load_and_swap(buffer + 0); uint32_t achievements_ptr = xe::load_and_swap(buffer + 4); XELOGD("XGIUserWriteAchievements({:08X}, {:08X})", achievement_count, achievements_ptr); auto* achievement = (X_XUSER_ACHIEVEMENT*)memory_->TranslateVirtual(achievements_ptr); for (uint32_t i = 0; i < achievement_count; i++, achievement++) { kernel_state_->achievement_manager()->EarnAchievement( achievement->user_idx, 0, achievement->achievement_id); } return X_E_SUCCESS; } case 0x000B0010: { assert_true(!buffer_length || buffer_length == 28); // Sequence: // - XamSessionCreateHandle // - XamSessionRefObjByHandle // - [this] // - CloseHandle uint32_t session_ptr = xe::load_and_swap(buffer + 0x0); uint32_t flags = xe::load_and_swap(buffer + 0x4); uint32_t num_slots_public = xe::load_and_swap(buffer + 0x8); uint32_t num_slots_private = xe::load_and_swap(buffer + 0xC); uint32_t user_xuid = xe::load_and_swap(buffer + 0x10); uint32_t session_info_ptr = xe::load_and_swap(buffer + 0x14); uint32_t nonce_ptr = xe::load_and_swap(buffer + 0x18); XELOGD( "XGISessionCreateImpl({:08X}, {:08X}, {}, {}, {:08X}, {:08X}, " "{:08X})", session_ptr, flags, num_slots_public, num_slots_private, user_xuid, session_info_ptr, nonce_ptr); return X_E_SUCCESS; } case 0x000B0011: { // TODO(PermaNull): reverse buffer contents. XELOGD("XGISessionDelete"); return X_STATUS_SUCCESS; } case 0x000B0012: { assert_true(buffer_length == 0x14); uint32_t session_ptr = xe::load_and_swap(buffer + 0x0); uint32_t user_count = xe::load_and_swap(buffer + 0x4); uint32_t unk_0 = xe::load_and_swap(buffer + 0x8); uint32_t user_index_array = xe::load_and_swap(buffer + 0xC); uint32_t private_slots_array = xe::load_and_swap(buffer + 0x10); assert_zero(unk_0); XELOGD("XGISessionJoinLocal({:08X}, {}, {}, {:08X}, {:08X})", session_ptr, user_count, unk_0, user_index_array, private_slots_array); return X_E_SUCCESS; } case 0x000B0014: { // Gets 584107FB in game. // get high score table? XELOGD("XGI_unknown"); return X_STATUS_SUCCESS; } case 0x000B0015: { // send high scores? XELOGD("XGI_unknown"); return X_STATUS_SUCCESS; } case 0x000B0021: { struct XLeaderboard { xe::be titleId; xe::be xuids_count; xe::be xuids_guest_address; xe::be specs_count; xe::be specs_guest_address; xe::be results_size; xe::be results_guest_address; }* data = reinterpret_cast(buffer); if (!data->results_guest_address) { return 1; } } case 0x000B0036: { // Called after opening xbox live arcade and clicking on xbox live v5759 // to 5787 and called after clicking xbox live in the game library from // v6683 to v6717 XELOGD("XGIUnkB0036, unimplemented"); return X_E_FAIL; } case 0x000B003D: { // Games used in: // - 5451082a (netplay build). XELOGD("XGIUnkB003D, unimplemented"); return X_E_FAIL; } case 0x000B0041: { assert_true(!buffer_length || buffer_length == 32); // 00000000 2789fecc 00000000 00000000 200491e0 00000000 200491f0 20049340 uint32_t user_index = xe::load_and_swap(buffer + 0); uint32_t context_ptr = xe::load_and_swap(buffer + 16); auto context = context_ptr ? memory_->TranslateVirtual(context_ptr) : nullptr; uint32_t context_id = context ? xe::load_and_swap(context + 0) : 0; XELOGD("XGIUserGetContext({:08X}, {:08X}{:08X}))", user_index, context_ptr, context_id); uint32_t value = 0; if (context) { UserProfile* user_profile = kernel_state_->user_profile(user_index); if (user_profile) { if (user_profile->contexts_.find(context_id) != user_profile->contexts_.cend()) { value = user_profile->contexts_[context_id]; } } xe::store_and_swap(context + 4, value); } return X_E_FAIL; } case 0x000B0071: { XELOGD("XGI 0x000B0071, unimplemented"); return X_E_SUCCESS; } } XELOGE( "Unimplemented XGI message app={:08X}, msg={:08X}, arg1={:08X}, " "arg2={:08X}", app_id(), message, buffer_ptr, buffer_length); return X_E_FAIL; } } // namespace apps } // namespace xam } // namespace kernel } // namespace xe