This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/invoker.cpp
Yimura 335e9325b0
feat(logger): use AsyncLogger instead of g3log (#882)
* feat(exception_handler): skip certain exception codes
* feat(zydis): Disable BUILD_DOXYGEN and FEATURE_ENCODER
* feat(cmake): link dbghelp
* feat(exception_handler): implement stack dumper
* feat(logger): differentiate between wine and non-wine
* feat(logger): add NO_COLOR env var support
* fix(logger): fix wine logging (#960)
* feat(exception_handler): added string logging of exception
* fix(logger): exception access violation NO_COLOR

--------

Co-authored-by: Aure7138 <100095051+Aure7138@users.noreply.github.com>
Co-authored-by: tupoy-ya <72797377+tupoy-ya@users.noreply.github.com>
2023-02-08 22:36:55 +00:00

62 lines
1.4 KiB
C++

#include "common.hpp"
#include "crossmap.hpp"
#include "invoker.hpp"
#include "pointers.hpp"
extern "C" void _call_asm(void* context, void* function, void* ret);
namespace big
{
native_call_context::native_call_context()
{
m_return_value = &m_return_stack[0];
m_args = &m_arg_stack[0];
}
void native_invoker::cache_handlers()
{
if (m_handlers_cached)
return;
for (const rage::scrNativeMapping& mapping : g_crossmap)
{
rage::scrNativeHandler handler = g_pointers->m_get_native_handler(
g_pointers->m_native_registration_table, mapping.second);
m_handler_cache.emplace(mapping.first, handler);
}
m_handlers_cached = true;
}
void native_invoker::begin_call()
{
m_call_context.reset();
}
void native_invoker::end_call(rage::scrNativeHash hash)
{
if (auto it = m_handler_cache.find(hash); it != m_handler_cache.end())
{
rage::scrNativeHandler handler = it->second;
[this, hash, handler]
{
__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."; }();
}
}();
}
else
{
[hash]() { LOG(WARNING) << "Failed to find " << HEX_TO_UPPER(hash) << " native's handler."; }();
}
}
}