fix: fix force script host

This commit is contained in:
Mr-X-GTA 2024-12-23 21:41:23 +01:00
parent e3126ad303
commit 2421512c38
2 changed files with 26 additions and 12 deletions

View File

@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
gtav_classes gtav_classes
GIT_REPOSITORY https://github.com/Mr-X-GTA/GTAV-Classes-1.git GIT_REPOSITORY https://github.com/Mr-X-GTA/GTAV-Classes-1.git
GIT_TAG 9ca0cb74882505d7d2c382e9a588972fd4589775 GIT_TAG e803b20ec3d6cf20d6b254c915e088bd010f006e
GIT_PROGRESS TRUE GIT_PROGRESS TRUE
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND "" BUILD_COMMAND ""

View File

@ -6,6 +6,7 @@
#include "gta_util.hpp" #include "gta_util.hpp"
#include "misc.hpp" #include "misc.hpp"
#include "natives.hpp" #include "natives.hpp"
#include "packet.hpp"
#include "script.hpp" #include "script.hpp"
#include "script_local.hpp" #include "script_local.hpp"
#include "services/players/player_service.hpp" #include "services/players/player_service.hpp"
@ -63,21 +64,34 @@ namespace big::scripts
{ {
if (auto launcher = gta_util::find_script_thread(hash); launcher && launcher->m_net_component) if (auto launcher = gta_util::find_script_thread(hash); launcher && launcher->m_net_component)
{ {
for (int i = 0; !((CGameScriptHandlerNetComponent*)launcher->m_net_component)->is_local_player_host(); i++) auto net_component = reinterpret_cast<CGameScriptHandlerNetComponent*>(launcher->m_net_component);
if (net_component->is_local_player_host())
{ {
if (i > 200) return true;
return false;
((CGameScriptHandlerNetComponent*)launcher->m_net_component)
->send_host_migration_event(g_player_service->get_self()->get_net_game_player());
script::get_current()->yield(10ms);
if (!launcher->m_stack || !launcher->m_net_component)
return false;
} }
net_component->do_host_migration(g_player_service->get_self()->get_net_game_player(), 0xFFFF, true);
packet pack;
pack.write_message(rage::eNetMessage::MsgScriptVerifyHostAck);
net_component->m_script_handler->get_id()->serialize(&pack.m_buffer);
pack.write<bool>(true, 1);
pack.write<bool>(true, 1);
pack.write<std::uint16_t>(0xFFFF, 16);
for (auto& player : g_player_service->players())
{
if (player.second->get_net_game_player())
{
pack.send(player.second->get_net_game_player()->m_msg_id);
}
}
return true;
} }
return true; return false;
} }
inline int launcher_index_from_hash(rage::joaat_t script_hash) inline int launcher_index_from_hash(rage::joaat_t script_hash)