Skip to content

Commit

Permalink
[XAM] Implemented XSessionSearchByID
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianCassar committed Dec 26, 2023
1 parent f84fcd0 commit 5239881
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/xenia/kernel/XLiveAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ class XLiveAPI {
xe::be<uint32_t> xoverlapped;
};

struct XSessionSearchID {
XNKID* session_id;
xe::be<uint32_t> user_index;
xe::be<uint32_t> results_buffer;
xe::be<uint32_t> search_results;
xe::be<uint32_t> xoverlapped;
};

struct XSessionDetails {
xe::be<uint32_t> session_handle;
xe::be<uint32_t> details_buffer_size;
Expand Down
67 changes: 66 additions & 1 deletion src/xenia/kernel/xam/apps/xgi_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ X_HRESULT XgiApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr,
}
case 0x000B001B: {
XELOGI("XSessionSearchByID unimplemented");
return X_E_SUCCESS;
return SessionSearchByID(buffer);
}
case 0x000B0065: {
XELOGI("XSessionSearchWeighted unimplemented");
Expand Down Expand Up @@ -1080,6 +1080,71 @@ X_HRESULT XgiApp::SessionSearch(uint8_t* buffer_ptr, bool extended) {
return X_E_SUCCESS;
}

X_HRESULT XgiApp::SessionSearchByID(uint8_t* buffer_ptr) {
XLiveAPI::XSessionSearchID* data =
reinterpret_cast<XLiveAPI::XSessionSearchID*>(buffer_ptr);

if (!data->results_buffer) {
data->results_buffer = sizeof(XSESSION_SEARCHRESULT);
return ERROR_INSUFFICIENT_BUFFER;
}

const auto sessionId = XNKIDtoUint64(data->session_id);

if (!sessionId) {
return ERROR_SUCCESS;
}

const XLiveAPI::SessionJSON session = XLiveAPI::XSessionGet(sessionId);

// FIX ME:
if (session.hostAddress.empty()) {
return ERROR_SUCCESS;
}

const uint32_t session_search_result_data_address =
data->search_results + sizeof(XSESSION_SEARCHRESULT_HEADER);

XSESSION_SEARCHRESULT* result =
memory_->TranslateVirtual<XSESSION_SEARCHRESULT*>(
data->search_results + sizeof(XSESSION_SEARCHRESULT_HEADER));

const uint32_t result_guest_address =
session_search_result_data_address + sizeof(XSESSION_SEARCHRESULT);

XSESSION_SEARCHRESULT* resultHostPtr =
memory_->TranslateVirtual<XSESSION_SEARCHRESULT*>(result_guest_address);

result->filled_priv_slots = session.filledPrivateSlotsCount;
result->filled_public_slots = session.filledPublicSlotsCount;
result->open_priv_slots = session.openPrivateSlotsCount;
result->open_public_slots = session.openPublicSlotsCount;

memcpy(&result->info.sessionID, session.sessionid.c_str(), 8);
memcpy(&result->info.hostAddress.abEnet, session.macAddress.c_str(), 6);
memcpy(&result->info.hostAddress.abOnline, session.macAddress.c_str(), 6);

for (int j = 0; j < sizeof(XLiveAPI::XNKEY); j++) {
result->info.keyExchangeKey.ab[j] = j;
}

inet_pton(AF_INET, session.hostAddress.c_str(),
&resultHostPtr->info.hostAddress.ina.s_addr);

inet_pton(AF_INET, session.hostAddress.c_str(),
&resultHostPtr->info.hostAddress.inaOnline.s_addr);

resultHostPtr->info.hostAddress.wPortOnline = session.port;

XSESSION_SEARCHRESULT_HEADER* resultsHeader =
memory_->TranslateVirtual<XSESSION_SEARCHRESULT_HEADER*>(
data->search_results);

resultsHeader->search_results_count = 1;
resultsHeader->search_results_ptr = session_search_result_data_address;

return X_E_SUCCESS;
}
} // namespace apps
} // namespace xam
} // namespace kernel
Expand Down
1 change: 1 addition & 0 deletions src/xenia/kernel/xam/apps/xgi_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class XgiApp : public App {

private:
X_HRESULT SessionSearch(uint8_t* buffer_ptr, bool extended = false);
X_HRESULT SessionSearchByID(uint8_t* buffer_ptr);
};

} // namespace apps
Expand Down

0 comments on commit 5239881

Please sign in to comment.