2019-03-21 20:18:31 +01:00
|
|
|
#pragma once
|
|
|
|
#include "gta/script_thread.hpp"
|
|
|
|
#include "gta/tls_context.hpp"
|
|
|
|
#include "pointers.hpp"
|
2023-01-03 16:48:32 +00:00
|
|
|
|
2022-12-06 16:12:02 +00:00
|
|
|
#include <ped/CPedFactory.hpp>
|
|
|
|
#include <network/CNetworkPlayerMgr.hpp>
|
|
|
|
#include <script/scrProgramTable.hpp>
|
2019-03-21 20:18:31 +01:00
|
|
|
|
|
|
|
namespace big::gta_util
|
|
|
|
{
|
|
|
|
inline CPed *get_local_ped()
|
|
|
|
{
|
|
|
|
if (auto ped_factory = *g_pointers->m_ped_factory)
|
|
|
|
{
|
|
|
|
return ped_factory->m_local_ped;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-10-28 16:54:33 +02:00
|
|
|
inline CVehicle* get_local_vehicle()
|
|
|
|
{
|
|
|
|
if (const auto ped = get_local_ped(); ped)
|
|
|
|
{
|
|
|
|
if (const auto veh = ped->m_vehicle; veh)
|
|
|
|
{
|
|
|
|
return veh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
inline CPlayerInfo *get_local_playerinfo()
|
|
|
|
{
|
|
|
|
if (auto ped_factory = *g_pointers->m_ped_factory)
|
|
|
|
{
|
|
|
|
if (auto ped = ped_factory->m_local_ped)
|
|
|
|
{
|
2021-07-25 22:24:22 +02:00
|
|
|
return ped->m_player_info;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-01-31 18:27:35 +01:00
|
|
|
inline CNetworkPlayerMgr* get_network_player_mgr()
|
|
|
|
{
|
|
|
|
return *g_pointers->m_network_player_mgr;
|
|
|
|
}
|
|
|
|
|
2022-09-12 18:44:47 +00:00
|
|
|
inline Network* get_network()
|
|
|
|
{
|
2022-10-25 22:21:36 +02:00
|
|
|
return *g_pointers->m_network;
|
2022-09-12 18:44:47 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
template <typename F, typename ...Args>
|
|
|
|
void execute_as_script(rage::joaat_t script_hash, F &&callback, Args &&...args)
|
|
|
|
{
|
|
|
|
auto tls_ctx = rage::tlsContext::get();
|
|
|
|
for (auto thread : *g_pointers->m_script_threads)
|
|
|
|
{
|
|
|
|
if (!thread || !thread->m_context.m_thread_id || thread->m_context.m_script_hash != script_hash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto og_thread = tls_ctx->m_script_thread;
|
|
|
|
|
|
|
|
tls_ctx->m_script_thread = thread;
|
|
|
|
tls_ctx->m_is_script_thread_active = true;
|
|
|
|
|
|
|
|
std::invoke(std::forward<F>(callback), std::forward<Args>(args)...);
|
|
|
|
|
|
|
|
tls_ctx->m_script_thread = og_thread;
|
|
|
|
tls_ctx->m_is_script_thread_active = og_thread != nullptr;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 01:43:04 +01:00
|
|
|
|
|
|
|
inline GtaThread* find_script_thread(rage::joaat_t hash)
|
|
|
|
{
|
|
|
|
for (auto thread : *g_pointers->m_script_threads)
|
|
|
|
{
|
|
|
|
if (thread
|
|
|
|
&& thread->m_context.m_thread_id
|
|
|
|
&& thread->m_handler
|
|
|
|
&& thread->m_script_hash == hash)
|
|
|
|
{
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-12-06 16:12:02 +00:00
|
|
|
|
|
|
|
inline rage::scrProgram* find_script_program(rage::joaat_t hash)
|
|
|
|
{
|
|
|
|
for (auto& script : *g_pointers->m_script_program_table)
|
|
|
|
{
|
|
|
|
if (script.m_program && script.m_program->m_name_hash == hash)
|
|
|
|
return script.m_program;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|