2022-08-09 14:39:55 -04:00
|
|
|
#include "hooking.hpp"
|
2022-11-19 01:49:36 +00:00
|
|
|
#include "fiber_pool.hpp"
|
2022-08-09 14:39:55 -04:00
|
|
|
#include "services/players/player_service.hpp"
|
2022-11-19 01:49:36 +00:00
|
|
|
#include "services/player_database/player_database_service.hpp"
|
2022-08-09 14:39:55 -04:00
|
|
|
#include "util/notify.hpp"
|
2022-11-19 01:49:36 +00:00
|
|
|
#include "packet.hpp"
|
|
|
|
#include "gta_util.hpp"
|
|
|
|
#include <network/Network.hpp>
|
2022-08-09 14:39:55 -04:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
void* hooks::assign_physical_index(CNetworkPlayerMgr* netPlayerMgr, CNetGamePlayer* player, uint8_t new_index)
|
|
|
|
{
|
2022-10-19 22:27:01 +02:00
|
|
|
const auto* net_player_data = player->get_net_data();
|
2022-10-30 19:32:51 +01:00
|
|
|
|
2022-10-19 22:27:01 +02:00
|
|
|
if (new_index == static_cast<uint8_t>(-1))
|
|
|
|
{
|
2022-11-21 15:42:12 +00:00
|
|
|
g->m_spoofed_peer_ids.erase(player->get_net_data()->m_host_token);
|
2022-08-09 14:39:55 -04:00
|
|
|
g_player_service->player_leave(player);
|
2022-10-19 22:27:01 +02:00
|
|
|
|
|
|
|
if (net_player_data)
|
2022-08-09 14:39:55 -04:00
|
|
|
{
|
|
|
|
if (g->notifications.player_leave.log)
|
|
|
|
LOG(INFO) << "Player left '" << net_player_data->m_name
|
2022-10-19 22:27:01 +02:00
|
|
|
<< "' freeing slot #" << (int)player->m_player_id
|
|
|
|
<< " with Rockstar ID: " << net_player_data->m_gamer_handle_2.m_rockstar_id;
|
2022-08-09 14:39:55 -04:00
|
|
|
|
|
|
|
if (g->notifications.player_leave.notify)
|
2022-10-24 14:08:37 +02:00
|
|
|
g_notification_service->push("Player Left", std::format("{} freeing slot #{} with Rockstar ID: {}", net_player_data->m_name, player->m_player_id, net_player_data->m_gamer_handle_2.m_rockstar_id));
|
2022-08-09 14:39:55 -04:00
|
|
|
}
|
2022-10-19 22:27:01 +02:00
|
|
|
|
2022-11-21 15:42:12 +00:00
|
|
|
return g_hooking->get_original<hooks::assign_physical_index>()(netPlayerMgr, player, new_index);
|
2022-08-09 14:39:55 -04:00
|
|
|
}
|
|
|
|
|
2022-11-21 15:42:12 +00:00
|
|
|
const auto result = g_hooking->get_original<hooks::assign_physical_index>()(netPlayerMgr, player, new_index);
|
2022-08-09 14:39:55 -04:00
|
|
|
g_player_service->player_join(player);
|
2022-10-19 22:27:01 +02:00
|
|
|
if (net_player_data)
|
2022-08-09 14:39:55 -04:00
|
|
|
{
|
2022-10-19 22:27:01 +02:00
|
|
|
if (g->notifications.player_join.above_map && *g_pointers->m_is_session_started) // prevent loading screen spam
|
2022-08-09 14:39:55 -04:00
|
|
|
notify::player_joined(player);
|
|
|
|
|
|
|
|
if (g->notifications.player_join.log)
|
|
|
|
LOG(INFO) << "Player joined '" << net_player_data->m_name
|
2022-10-19 22:27:01 +02:00
|
|
|
<< "' allocating slot #" << (int)player->m_player_id
|
|
|
|
<< " with Rockstar ID: " << net_player_data->m_gamer_handle_2.m_rockstar_id;
|
2022-08-09 14:39:55 -04:00
|
|
|
|
|
|
|
if (g->notifications.player_join.notify)
|
2022-10-24 14:08:37 +02:00
|
|
|
g_notification_service->push("Player Joined", std::format("{} taking slot #{} with Rockstar ID: {}", net_player_data->m_name, player->m_player_id, net_player_data->m_gamer_handle_2.m_rockstar_id));
|
2022-11-19 01:49:36 +00:00
|
|
|
|
|
|
|
auto id = player->m_player_id;
|
|
|
|
g_fiber_pool->queue_job([id]
|
|
|
|
{
|
|
|
|
if (auto plyr = g_player_service->get_by_id(id))
|
|
|
|
{
|
|
|
|
if (auto entry = g_player_database_service->get_player_by_rockstar_id(plyr->get_net_data()->m_gamer_handle_2.m_rockstar_id))
|
|
|
|
{
|
|
|
|
plyr->is_modder = entry->is_modder;
|
|
|
|
plyr->block_join = entry->block_join;
|
|
|
|
plyr->block_join_reason = plyr->block_join_reason;
|
|
|
|
|
|
|
|
if (strcmp(plyr->get_name(), entry->name.data()))
|
|
|
|
{
|
|
|
|
g_notification_service->push("Players", std::format("{} changed their name to {}", entry->name, plyr->get_name()));
|
|
|
|
entry->name = plyr->get_name();
|
|
|
|
g_player_database_service->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto snplyr = plyr->get_session_player())
|
|
|
|
{
|
|
|
|
packet msg{};
|
|
|
|
msg.write_message(rage::eNetMessage::MsgSessionEstablishedRequest);
|
|
|
|
msg.write<uint64_t>(gta_util::get_network()->m_game_session_ptr->m_rline_session.m_session_id, 64);
|
|
|
|
msg.send(snplyr->m_msg_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-08-09 14:39:55 -04:00
|
|
|
}
|
2022-10-19 22:27:01 +02:00
|
|
|
return result;
|
2022-08-09 14:39:55 -04:00
|
|
|
}
|
2022-10-30 19:32:51 +01:00
|
|
|
}
|