refactor: take_control_of (#962)
This commit is contained in:
parent
f12cc48796
commit
f9b59da443
@ -109,6 +109,7 @@ namespace big::functions
|
|||||||
using send_network_damage = void(*)(CEntity* source, CEntity* target, rage::fvector3* position, int hit_component, bool override_default_damage, int weapon_type, float override_damage, int tire_index, int suspension_index, int flags,
|
using send_network_damage = void(*)(CEntity* source, CEntity* target, rage::fvector3* position, int hit_component, bool override_default_damage, int weapon_type, float override_damage, int tire_index, int suspension_index, int flags,
|
||||||
std::uint32_t action_result_hash, std::int16_t action_result_id, int action_unk, bool hit_weapon, bool hit_weapon_ammo_attachment, bool silenced, bool unk, rage::fvector3* impact_direction);
|
std::uint32_t action_result_hash, std::int16_t action_result_id, int action_unk, bool hit_weapon, bool hit_weapon_ammo_attachment, bool silenced, bool unk, rage::fvector3* impact_direction);
|
||||||
using request_ragdoll = void(*)(uint16_t object_id);
|
using request_ragdoll = void(*)(uint16_t object_id);
|
||||||
|
using request_control = void(*)(rage::netObject* net_object);
|
||||||
|
|
||||||
using get_connection_peer = rage::netConnectionPeer* (*)(rage::netConnectionManager* manager, int peer_id);
|
using get_connection_peer = rage::netConnectionPeer* (*)(rage::netConnectionManager* manager, int peer_id);
|
||||||
using send_remove_gamer_cmd = void(*)(rage::netConnectionManager* net_connection_mgr, rage::netConnectionPeer* player, int connection_id, rage::snMsgRemoveGamersFromSessionCmd* cmd, int flags);
|
using send_remove_gamer_cmd = void(*)(rage::netConnectionManager* net_connection_mgr, rage::netConnectionPeer* player, int connection_id, rage::snMsgRemoveGamersFromSessionCmd* cmd, int flags);
|
||||||
|
@ -213,12 +213,6 @@ namespace big
|
|||||||
m_write_player_game_state_data_node = ptr.as<functions::write_player_game_state_data_node>();
|
m_write_player_game_state_data_node = ptr.as<functions::write_player_game_state_data_node>();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request Control of Entity PATCH
|
|
||||||
main_batch.add("RCOE-Patch", "48 89 5C 24 ? 57 48 83 EC 20 8B D9 E8 ? ? ? ? ? ? ? ? 8B CB", [this](memory::handle ptr)
|
|
||||||
{
|
|
||||||
memory::byte_patch::make(ptr.add(0x13).as<std::uint16_t*>(), 0x9090)->apply();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Replay Interface
|
// Replay Interface
|
||||||
main_batch.add("RI", "0F B7 44 24 ? 66 89 44 4E", [this](memory::handle ptr)
|
main_batch.add("RI", "0F B7 44 24 ? 66 89 44 4E", [this](memory::handle ptr)
|
||||||
{
|
{
|
||||||
@ -580,11 +574,17 @@ namespace big
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Request Ragdoll
|
// Request Ragdoll
|
||||||
main_batch.add("RR", "E8 ? ? ? ? 09 B3 ? ? ? ? 48 8B 5C 24 ?", [this](memory::handle ptr)
|
main_batch.add("RR", "E8 ? ? ? ? 09 B3 ? ? ? ? 48 8B 5C 24", [this](memory::handle ptr)
|
||||||
{
|
{
|
||||||
m_request_ragdoll = ptr.add(1).rip().as<functions::request_ragdoll>();
|
m_request_ragdoll = ptr.add(1).rip().as<functions::request_ragdoll>();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Request Control
|
||||||
|
main_batch.add("RC", "E8 ? ? ? ? EB 3E 48 8B D3", [this](memory::handle ptr)
|
||||||
|
{
|
||||||
|
m_request_control = ptr.add(1).rip().as<functions::request_control>();
|
||||||
|
});
|
||||||
|
|
||||||
// Get Connection Peer & Send Remove Gamer Command
|
// Get Connection Peer & Send Remove Gamer Command
|
||||||
main_batch.add("GCP&SRGC", "8D 42 FF 83 F8 FD 77 3D", [this](memory::handle ptr)
|
main_batch.add("GCP&SRGC", "8D 42 FF 83 F8 FD 77 3D", [this](memory::handle ptr)
|
||||||
{
|
{
|
||||||
|
@ -191,6 +191,8 @@ namespace big
|
|||||||
|
|
||||||
functions::send_network_damage m_send_network_damage;
|
functions::send_network_damage m_send_network_damage;
|
||||||
functions::request_ragdoll m_request_ragdoll;
|
functions::request_ragdoll m_request_ragdoll;
|
||||||
|
functions::request_control m_request_control;
|
||||||
|
|
||||||
|
|
||||||
functions::get_connection_peer m_get_connection_peer{};
|
functions::get_connection_peer m_get_connection_peer{};
|
||||||
functions::send_remove_gamer_cmd m_send_remove_gamer_cmd{};
|
functions::send_remove_gamer_cmd m_send_remove_gamer_cmd{};
|
||||||
|
@ -56,25 +56,29 @@ namespace big::entity
|
|||||||
return (bool)hit;
|
return (bool)hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool network_has_control_of_entity(rage::netObject* net_object)
|
||||||
|
{
|
||||||
|
return net_object && !net_object->m_next_owner_id && (net_object->m_control_id == -1);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool take_control_of(Entity ent, int timeout = 300)
|
inline bool take_control_of(Entity ent, int timeout = 300)
|
||||||
{
|
{
|
||||||
if (NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(ent) || !*g_pointers->m_is_session_started)
|
auto ptr = g_pointers->m_handle_to_ptr(ent);
|
||||||
return true;
|
if (ptr)
|
||||||
|
|
||||||
for (int i = 0; !NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(ent) && i < timeout; i++)
|
|
||||||
{
|
{
|
||||||
NETWORK::NETWORK_REQUEST_CONTROL_OF_ENTITY(ent);
|
if (!*g_pointers->m_is_session_started || network_has_control_of_entity(ptr->m_net_object))
|
||||||
|
return true;
|
||||||
if (timeout != 0)
|
for (int i = 0; !network_has_control_of_entity(ptr->m_net_object) && i < timeout; i++)
|
||||||
script::get_current()->yield();
|
{
|
||||||
}
|
g_pointers->m_request_control(ptr->m_net_object);
|
||||||
|
if (timeout != 0)
|
||||||
if (!NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(ent))
|
script::get_current()->yield();
|
||||||
return false;
|
}
|
||||||
|
if (!network_has_control_of_entity(ptr->m_net_object))
|
||||||
int netHandle = NETWORK::NETWORK_GET_NETWORK_ID_FROM_ENTITY(ent);
|
return false;
|
||||||
NETWORK::SET_NETWORK_ID_CAN_MIGRATE(netHandle, true);
|
int netHandle = NETWORK::NETWORK_GET_NETWORK_ID_FROM_ENTITY(ent);
|
||||||
|
NETWORK::SET_NETWORK_ID_CAN_MIGRATE(netHandle, true);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -318,7 +318,7 @@ namespace big
|
|||||||
if (ImGui::Selectable(name.c_str(), item_selected))
|
if (ImGui::Selectable(name.c_str(), item_selected))
|
||||||
{
|
{
|
||||||
g_fiber_pool->queue_job([&mod, is_wheel_mod, wheel_stock_mod, wheel_custom] {
|
g_fiber_pool->queue_job([&mod, is_wheel_mod, wheel_stock_mod, wheel_custom] {
|
||||||
NETWORK::NETWORK_REQUEST_CONTROL_OF_ENTITY(self::veh);
|
entity::take_control_of(self::veh);
|
||||||
|
|
||||||
if (selected_slot >= 0)
|
if (selected_slot >= 0)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user