#pragma once #include "gta/array.hpp" #include "gta/script_thread.hpp" #include "gta/tls_context.hpp" #include "ped/CPedFactory.hpp" #include "pointers.hpp" 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; } inline CPlayerInfo *get_local_playerinfo() { if (auto ped_factory = *g_pointers->m_ped_factory) { if (auto ped = ped_factory->m_local_ped) { return ped->m_player_info; } } return nullptr; } inline CNetworkPlayerMgr* get_network_player_mgr() { return *g_pointers->m_network_player_mgr; } inline Network* get_network() { return *g_pointers->m_network; } template 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(callback), std::forward(args)...); tls_ctx->m_script_thread = og_thread; tls_ctx->m_is_script_thread_active = og_thread != nullptr; return; } } 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; } }