Add session browser (#633)

This commit is contained in:
maybegreat48
2022-11-24 21:49:05 +00:00
committed by GitHub
parent d0b523873d
commit 88aa1f8e56
34 changed files with 809 additions and 208 deletions

View File

@ -31,6 +31,7 @@ namespace big
SESSION,
SPOOFING,
PLAYER_DATABASE,
SESSION_BROWSER,
SETTINGS,
CONTEXT_MENU_SETTINGS,
@ -80,6 +81,7 @@ namespace big
{ tabs::SPOOFING, { "Spoofing", view::spoofing }},
{ tabs::SESSION, { "Session", view::session }},
{ tabs::PLAYER_DATABASE, { "Player Database", view::player_database }},
{ tabs::SESSION_BROWSER, { "Session Browser", view::session_browser }},
}}},
{tabs::SETTINGS, { "Settings", view::settings, {
{ tabs::CONTEXT_MENU_SETTINGS, { "Context Menu", view::context_menu_settings}},

View File

@ -0,0 +1,108 @@
#include "matchmaking_service.hpp"
#include "script.hpp"
#include "pointers.hpp"
#include "hooking.hpp"
#include <network/Network.hpp>
namespace big
{
matchmaking_service::matchmaking_service()
{
g_matchmaking_service = this;
}
matchmaking_service::~matchmaking_service()
{
g_matchmaking_service = nullptr;
}
bool matchmaking_service::matchmake(std::optional<int> constraint)
{
for (auto& session : m_found_sessions)
{
session.is_valid = true;
}
NetworkGameFilterMatchmakingComponent component{};
strcpy(component.m_filter_name, "Group");
component.m_game_mode = 0;
component.m_num_parameters = 0;
if (g->session_browser.region_filter_enabled)
{
component.SetParameter("MMATTR_REGION", 0, g->session_browser.region_filter);
}
if (constraint)
{
component.SetParameter("MMATTR_DISCRIMINATOR", 1, constraint.value());
}
int state = 0;
static rage::rlSessionInfo result_sessions[MAX_SESSIONS_TO_FIND];
m_active = true;
if (g_hooking->get_original<hooks::start_matchmaking_find_sessions>()(0, 1, &component, MAX_SESSIONS_TO_FIND, result_sessions, &m_num_sessions_found, &state))
{
while (state == 1)
script::get_current()->yield();
if (state == 3)
{
for (int i = 0; i < m_num_sessions_found; i++)
{
m_found_sessions[i].info = result_sessions[i];
if (constraint && m_found_sessions[i].attributes.player_count >= 30)
m_found_sessions[i].is_valid = false;
if (g->session_browser.language_filter_enabled && m_found_sessions[i].attributes.language != g->session_browser.language_filter)
m_found_sessions[i].is_valid = false;
if (g->session_browser.player_count_filter_enabled && (m_found_sessions[i].attributes.player_count < g->session_browser.player_count_filter_minimum ||
m_found_sessions[i].attributes.player_count > g->session_browser.player_count_filter_maximum))
{
m_found_sessions[i].is_valid = false;
}
}
if (g->session_browser.sort_method != 0)
{
std::qsort(m_found_sessions, m_num_sessions_found, sizeof(session), [](const void* a1, const void* a2) -> int
{
std::strong_ordering result;
if (g->session_browser.sort_method == 1)
{
result = (((session*)(a1))->attributes.player_count <=> ((session*)(a2))->attributes.player_count);
}
if (result == 0)
return 0;
if (result > 0)
return g->session_browser.sort_direction ? -1 : 1;
if (result < 0)
return g->session_browser.sort_direction ? 1 : -1;
std::unreachable();
});
}
m_active = false;
return true;
}
}
else
{
m_active = false;
return false;
}
m_active = false;
return false;
}
}

View File

@ -0,0 +1,50 @@
#pragma once
namespace big
{
class matchmaking_service
{
public:
constexpr static int MAX_SESSIONS_TO_FIND = 1400;
struct session_attributes
{
int discriminator;
int player_count;
int region;
int language;
};
struct session
{
rage::rlSessionInfo info;
session_attributes attributes;
bool is_valid;
};
private:
int m_num_sessions_found = 0;
bool m_active = false;
session m_found_sessions[MAX_SESSIONS_TO_FIND];
public:
matchmaking_service();
~matchmaking_service();
bool matchmake(std::optional<int> constraint = std::nullopt);
inline int get_num_found_sessions()
{
return m_num_sessions_found;
}
inline session* get_found_sessions()
{
return m_found_sessions;
}
inline bool is_active()
{
return m_active;
}
};
inline matchmaking_service* g_matchmaking_service;
}