mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2024-12-22 20:17:24 +08:00
Cache native handlers
This commit is contained in:
parent
91c688b395
commit
9538705b21
@ -12,18 +12,15 @@ namespace big
|
|||||||
m_args = &m_arg_stack[0];
|
m_args = &m_arg_stack[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool native_invoker::map_native(rage::scrNativeHash *hash)
|
void native_invoker::cache_handlers()
|
||||||
{
|
{
|
||||||
for (auto const &mapping : g_crossmap)
|
for (const rage::scrNativeMapping &mapping : g_crossmap)
|
||||||
{
|
{
|
||||||
if (mapping.first == *hash)
|
rage::scrNativeHandler handler = g_pointers->m_get_native_handler(
|
||||||
{
|
g_pointers->m_native_registration_table, mapping.second);
|
||||||
*hash = mapping.second;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
m_handler_cache.emplace(mapping.first, handler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void native_invoker::begin_call()
|
void native_invoker::begin_call()
|
||||||
@ -33,9 +30,10 @@ namespace big
|
|||||||
|
|
||||||
void native_invoker::end_call(rage::scrNativeHash hash)
|
void native_invoker::end_call(rage::scrNativeHash hash)
|
||||||
{
|
{
|
||||||
map_native(&hash);
|
if (auto it = m_handler_cache.find(hash); it != m_handler_cache.end())
|
||||||
if (auto handler = g_pointers->m_get_native_handler(g_pointers->m_native_registration_table, hash))
|
|
||||||
{
|
{
|
||||||
|
rage::scrNativeHandler handler = it->second;
|
||||||
|
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
handler(&m_call_context);
|
handler(&m_call_context);
|
||||||
|
@ -19,7 +19,7 @@ namespace big
|
|||||||
explicit native_invoker() = default;
|
explicit native_invoker() = default;
|
||||||
~native_invoker() = default;
|
~native_invoker() = default;
|
||||||
|
|
||||||
bool map_native(rage::scrNativeHash *hash);
|
void cache_handlers();
|
||||||
|
|
||||||
void begin_call();
|
void begin_call();
|
||||||
void end_call(rage::scrNativeHash hash);
|
void end_call(rage::scrNativeHash hash);
|
||||||
@ -37,6 +37,7 @@ namespace big
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
native_call_context m_call_context;
|
native_call_context m_call_context;
|
||||||
|
std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> m_handler_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline native_invoker g_native_invoker;
|
inline native_invoker g_native_invoker;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "gta/script_thread.hpp"
|
#include "gta/script_thread.hpp"
|
||||||
#include "gta/tls_context.hpp"
|
#include "gta/tls_context.hpp"
|
||||||
#include "gta_util.hpp"
|
#include "gta_util.hpp"
|
||||||
|
#include "invoker.hpp"
|
||||||
#include "pointers.hpp"
|
#include "pointers.hpp"
|
||||||
#include "script_mgr.hpp"
|
#include "script_mgr.hpp"
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ namespace big
|
|||||||
void script_mgr::tick_internal()
|
void script_mgr::tick_internal()
|
||||||
{
|
{
|
||||||
static bool ensure_main_fiber = (ConvertThreadToFiber(nullptr), true);
|
static bool ensure_main_fiber = (ConvertThreadToFiber(nullptr), true);
|
||||||
|
static bool ensure_native_handlers = (g_native_invoker.cache_handlers(), true);
|
||||||
|
|
||||||
std::lock_guard lock(m_mutex);
|
std::lock_guard lock(m_mutex);
|
||||||
for (auto const &script : m_scripts)
|
for (auto const &script : m_scripts)
|
||||||
|
Loading…
Reference in New Issue
Block a user