Fix multiple crashes. (#3035)

This commit is contained in:
gir489 2024-05-03 11:28:21 -04:00 committed by GitHub
parent 9652ce70de
commit e18efc6180
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 11 deletions

View File

@ -83,15 +83,18 @@ namespace big
buffer.m_flagBits = 1; buffer.m_flagBits = 1;
rage::eNetMessage msgType; rage::eNetMessage msgType;
player_ptr player; player_ptr player = nullptr;
for (uint32_t i = 0; i < gta_util::get_network()->m_game_session_ptr->m_player_count; i++) for (uint32_t i = 0; i < gta_util::get_network()->m_game_session_ptr->m_player_count; i++)
{ {
if (gta_util::get_network()->m_game_session_ptr->m_players[i]->m_player_data.m_peer_id_2 == frame->m_peer_id) if (auto player_iter = gta_util::get_network()->m_game_session_ptr->m_players[i])
{ {
player = g_player_service->get_by_host_token( if (frame && player_iter->m_player_data.m_peer_id_2 == frame->m_peer_id)
gta_util::get_network()->m_game_session_ptr->m_players[i]->m_player_data.m_host_token); {
break; player = g_player_service->get_by_host_token(
gta_util::get_network()->m_game_session_ptr->m_players[i]->m_player_data.m_host_token);
break;
}
} }
} }

View File

@ -5,7 +5,8 @@ namespace big
{ {
void hooks::received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token) void hooks::received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token)
{ {
if (dst->m_player_info->m_ped->m_net_object->m_object_id == object_id) [[unlikely]] if (!dst || !dst->m_player_info || !dst->m_player_info->m_ped || !dst->m_player_info->m_ped->m_net_object
|| dst->m_player_info->m_ped->m_net_object->m_object_id == object_id) [[unlikely]]
{ {
notify::crash_blocked(src, "player ped removal"); notify::crash_blocked(src, "player ped removal");
return; return;

View File

@ -38,24 +38,42 @@ namespace big
player_ptr player_service::get_by_msg_id(uint32_t msg_id) const player_ptr player_service::get_by_msg_id(uint32_t msg_id) const
{ {
for (const auto& [_, player] : m_players) for (const auto& [_, player] : m_players)
if (player->get_net_game_player()->m_msg_id == msg_id) {
return player; if (auto net_game_player = player->get_net_game_player())
{
if (net_game_player->m_msg_id == msg_id)
{
return player;
}
}
}
return nullptr; return nullptr;
} }
player_ptr player_service::get_by_id(uint32_t id) const player_ptr player_service::get_by_id(uint32_t id) const
{ {
for (const auto& [_, player] : m_players) for (const auto& [_, player] : m_players)
if (player->id() == id) {
if (player && player->id() == id)
{
return player; return player;
}
}
return nullptr; return nullptr;
} }
player_ptr player_service::get_by_host_token(uint64_t token) const player_ptr player_service::get_by_host_token(uint64_t token) const
{ {
for (const auto& [_, player] : m_players) for (const auto& [_, player] : m_players)
if (player->get_net_data()->m_host_token == token) {
return player; if (auto net_data = player->get_net_data())
{
if (net_data->m_host_token == token)
{
return player;
}
}
}
return nullptr; return nullptr;
} }