2022-12-06 16:12:02 +00:00
|
|
|
#pragma once
|
|
|
|
#include "core/enums.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "core/scr_globals.hpp"
|
2022-12-06 16:12:02 +00:00
|
|
|
#include "gta/net_object_mgr.hpp"
|
2022-12-08 13:35:41 +01:00
|
|
|
#include "gta/pickup_rewards.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "pointers.hpp"
|
2022-12-06 16:12:02 +00:00
|
|
|
#include "services/gta_data/gta_data_service.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "util/scripts.hpp"
|
|
|
|
#include "util/session.hpp"
|
2022-12-06 16:12:02 +00:00
|
|
|
#include "util/system.hpp"
|
2023-01-03 16:48:32 +00:00
|
|
|
|
2022-12-19 17:39:06 +00:00
|
|
|
#include <network/Network.hpp>
|
|
|
|
#include <network/netTime.hpp>
|
2023-01-03 16:48:32 +00:00
|
|
|
#include <script/globals/GPBD_FM_3.hpp>
|
2022-12-19 17:39:06 +00:00
|
|
|
#include <timeapi.h>
|
|
|
|
#pragma comment(lib, "winmm.lib")
|
2022-12-06 16:12:02 +00:00
|
|
|
|
|
|
|
namespace big::toxic
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
struct explosion_anti_cheat_bypass
|
|
|
|
{
|
|
|
|
inline static memory::byte_patch* m_can_blame_others;
|
|
|
|
inline static memory::byte_patch* m_can_use_blocked_explosions;
|
|
|
|
};
|
|
|
|
|
2022-12-06 16:12:02 +00:00
|
|
|
inline void blame_explode_coord(player_ptr to_blame, Vector3 pos, eExplosionTag explosion_type, float damage, bool is_audible, bool is_invisible, float camera_shake)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
explosion_anti_cheat_bypass::m_can_blame_others->apply();
|
|
|
|
explosion_anti_cheat_bypass::m_can_use_blocked_explosions->apply();
|
|
|
|
|
2023-04-16 18:28:49 +00:00
|
|
|
FIRE::ADD_OWNED_EXPLOSION(
|
|
|
|
(*g_pointers->m_gta.m_is_session_started && to_blame) ? PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(to_blame->id()) : 0,
|
|
|
|
pos.x,
|
|
|
|
pos.y,
|
|
|
|
pos.z,
|
|
|
|
(int)explosion_type,
|
|
|
|
damage,
|
|
|
|
is_audible,
|
|
|
|
is_invisible,
|
|
|
|
camera_shake);
|
2023-04-14 18:54:07 +02:00
|
|
|
|
|
|
|
explosion_anti_cheat_bypass::m_can_use_blocked_explosions->restore();
|
|
|
|
explosion_anti_cheat_bypass::m_can_blame_others->restore();
|
2022-12-06 16:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void blame_explode_player(player_ptr to_blame, player_ptr target, eExplosionTag explosion_type, float damage, bool is_audible, bool is_invisible, float camera_shake)
|
|
|
|
{
|
|
|
|
Vector3 coords = ENTITY::GET_ENTITY_COORDS(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(target->id()), true);
|
|
|
|
blame_explode_coord(to_blame, coords, explosion_type, damage, is_audible, is_invisible, camera_shake);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void start_activity(player_ptr target, eActivityType type)
|
|
|
|
{
|
|
|
|
const size_t arg_count = 4;
|
2023-03-01 21:27:15 +00:00
|
|
|
int64_t args[arg_count] = {(int64_t)eRemoteEvent::StartActivity, (int64_t)self::id, (int64_t)type, (int64_t) true};
|
2022-12-06 16:12:02 +00:00
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << target->id());
|
2022-12-06 16:12:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 17:39:06 +00:00
|
|
|
inline bool set_time(player_ptr target, uint32_t millis)
|
|
|
|
{
|
|
|
|
if (!g_player_service->get_self()->is_host())
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_error("MODIFY_TIME"_T.data(), "MODIFY_TIME_HOST_REQUIRED"_T.data());
|
2022-12-19 17:39:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target->player_time_value.has_value())
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_error("MODIFY_TIME"_T.data(), "MODIFY_TIME_NO_PLAYER_TIMESTAMP"_T.data());
|
2022-12-19 17:39:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
target->num_time_syncs_sent++;
|
|
|
|
|
|
|
|
rage::netTimeSyncMsg msg{};
|
2023-03-01 21:27:15 +00:00
|
|
|
msg.action = 1;
|
|
|
|
msg.counter = target->num_time_syncs_sent;
|
2023-04-14 18:54:07 +02:00
|
|
|
msg.token = (*g_pointers->m_gta.m_network_time)->m_time_token;
|
2023-03-01 21:27:15 +00:00
|
|
|
msg.timestamp = target->player_time_value.value()
|
|
|
|
+ (uint32_t)(std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now())
|
|
|
|
- target->player_time_value_received_time.value())
|
|
|
|
.count();
|
2022-12-19 17:39:06 +00:00
|
|
|
msg.increment = millis;
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
auto peer = g_pointers->m_gta.m_get_connection_peer(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr,
|
2023-03-01 21:27:15 +00:00
|
|
|
(int)target->get_session_player()->m_player_data.m_peer_id_2);
|
2022-12-19 17:39:06 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < 100; j++)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
g_pointers->m_gta.m_sync_network_time(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr,
|
2023-03-01 21:27:15 +00:00
|
|
|
peer,
|
2023-04-14 18:54:07 +02:00
|
|
|
(*g_pointers->m_gta.m_network_time)->m_connection_identifier,
|
2023-03-01 21:27:15 +00:00
|
|
|
&msg,
|
2023-04-16 18:28:49 +00:00
|
|
|
0x1000000); // repeatedly spamming the event will eventually cause certain bounds checks to disable for some reason
|
2022-12-19 17:39:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void warp_time_forward(player_ptr target, uint32_t millis)
|
|
|
|
{
|
|
|
|
if (!target->player_time_value.has_value())
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_error("WARP_TIME_TITLE"_T.data(), "MODIFY_TIME_NO_PLAYER_TIMESTAMP"_T.data());
|
2022-12-19 17:39:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
if (set_time(target,
|
|
|
|
target->time_difference.value() + millis
|
|
|
|
+ (uint32_t)(std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now())
|
|
|
|
- target->player_time_value_received_time.value())
|
|
|
|
.count()))
|
2022-12-19 17:39:06 +00:00
|
|
|
target->time_difference.value() += millis;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set_time_all(uint32_t millis)
|
|
|
|
{
|
|
|
|
if (!g_player_service->get_self()->is_host())
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_error("MODIFY_TIME"_T.data(), "MODIFY_TIME_HOST_REQUIRED"_T.data());
|
2022-12-19 17:39:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::uint32_t largest_counter = 9999;
|
2023-03-01 21:27:15 +00:00
|
|
|
g_player_service->iterate([&largest_counter](const player_entry& plyr) {
|
2022-12-19 17:39:06 +00:00
|
|
|
if (plyr.second->num_time_syncs_sent > largest_counter)
|
|
|
|
largest_counter = plyr.second->num_time_syncs_sent;
|
|
|
|
});
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
(*g_pointers->m_gta.m_network_time)->m_time_offset = millis - timeGetTime();
|
2022-12-19 17:39:06 +00:00
|
|
|
|
|
|
|
rage::netTimeSyncMsg msg{};
|
2023-03-01 21:27:15 +00:00
|
|
|
g_player_service->iterate([&largest_counter, &msg, millis](const player_entry& plyr) {
|
2022-12-19 17:39:06 +00:00
|
|
|
if (!plyr.second->player_time_value.has_value())
|
|
|
|
{
|
|
|
|
LOG(WARNING) << "Skipping " << plyr.second->get_name() << " in time warp";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
largest_counter++;
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
msg.action = 1;
|
|
|
|
msg.counter = largest_counter;
|
2023-04-14 18:54:07 +02:00
|
|
|
msg.token = (*g_pointers->m_gta.m_network_time)->m_time_token;
|
2023-03-01 21:27:15 +00:00
|
|
|
msg.timestamp = plyr.second->player_time_value.value()
|
|
|
|
+ (uint32_t)(std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now())
|
|
|
|
- plyr.second->player_time_value_received_time.value())
|
|
|
|
.count();
|
2022-12-19 17:39:06 +00:00
|
|
|
msg.increment = millis;
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
auto peer = g_pointers->m_gta.m_get_connection_peer(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr,
|
2023-03-01 21:27:15 +00:00
|
|
|
(int)plyr.second->get_session_player()->m_player_data.m_peer_id_2);
|
2022-12-19 17:39:06 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < 25; j++)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
g_pointers->m_gta.m_sync_network_time(gta_util::get_network()->m_game_session_ptr->m_net_connection_mgr,
|
2023-03-01 21:27:15 +00:00
|
|
|
peer,
|
2023-04-14 18:54:07 +02:00
|
|
|
(*g_pointers->m_gta.m_network_time)->m_connection_identifier,
|
2023-03-01 21:27:15 +00:00
|
|
|
&msg,
|
|
|
|
0x1000000);
|
2022-12-19 17:39:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
plyr.second->num_time_syncs_sent = largest_counter + 32;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void warp_time_forward_all(uint32_t millis)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
set_time_all((*g_pointers->m_gta.m_network_time)->m_time + millis);
|
2022-12-19 17:39:06 +00:00
|
|
|
}
|
2022-12-06 16:12:02 +00:00
|
|
|
}
|