2019-03-21 20:18:31 +01:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "crossmap.hpp"
|
|
|
|
#include "invoker.hpp"
|
|
|
|
#include "pointers.hpp"
|
|
|
|
|
2021-05-18 23:03:42 +02:00
|
|
|
extern "C" void _call_asm(void* context, void* function, void* ret);
|
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
native_call_context::native_call_context()
|
|
|
|
{
|
|
|
|
m_return_value = &m_return_stack[0];
|
|
|
|
m_args = &m_arg_stack[0];
|
|
|
|
}
|
|
|
|
|
2019-07-29 23:19:21 +02:00
|
|
|
void native_invoker::cache_handlers()
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2022-09-30 20:41:26 +02:00
|
|
|
if (m_handlers_cached)
|
|
|
|
return;
|
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
for (const rage::scrNativeMapping& mapping : g_crossmap)
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2019-07-29 23:19:21 +02:00
|
|
|
rage::scrNativeHandler handler = g_pointers->m_get_native_handler(
|
|
|
|
g_pointers->m_native_registration_table, mapping.second);
|
|
|
|
m_handler_cache.emplace(mapping.first, handler);
|
|
|
|
}
|
2022-09-30 20:41:26 +02:00
|
|
|
|
|
|
|
m_handlers_cached = true;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void native_invoker::begin_call()
|
|
|
|
{
|
|
|
|
m_call_context.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void native_invoker::end_call(rage::scrNativeHash hash)
|
|
|
|
{
|
2019-07-29 23:19:21 +02:00
|
|
|
if (auto it = m_handler_cache.find(hash); it != m_handler_cache.end())
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2019-07-29 23:19:21 +02:00
|
|
|
rage::scrNativeHandler handler = it->second;
|
|
|
|
|
2023-02-01 19:49:12 +01:00
|
|
|
[this, hash, handler]
|
2021-07-23 00:47:55 +02:00
|
|
|
{
|
2023-02-01 19:49:12 +01:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
_call_asm(&m_call_context, handler, g_pointers->m_native_return);
|
|
|
|
// handler(&m_call_context);
|
|
|
|
g_pointers->m_fix_vectors(&m_call_context);
|
|
|
|
}
|
|
|
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
[hash]() { LOG(WARNING) << "Exception caught while trying to call " << hash << " native."; }();
|
|
|
|
}
|
|
|
|
}();
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
[hash]() { LOG(WARNING) << "Failed to find " << HEX_TO_UPPER(hash) << " native's handler."; }();
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|