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.hpp

48 lines
897 B
C++
Raw Normal View History

2019-03-21 20:18:31 +01:00
#pragma once
#include "common.hpp"
#include "gta/natives.hpp"
namespace big
{
class native_call_context : public rage::scrNativeCallContext
{
public:
native_call_context();
2019-03-21 20:18:31 +01:00
private:
std::uint64_t m_return_stack[10];
std::uint64_t m_arg_stack[100];
};
class native_invoker
{
public:
explicit native_invoker() = default;
~native_invoker() = default;
2019-03-21 20:18:31 +01:00
2019-07-29 23:19:21 +02:00
void cache_handlers();
2019-03-21 20:18:31 +01:00
void begin_call();
void end_call(rage::scrNativeHash hash);
template<typename T>
void push_arg(T&& value)
2019-03-21 20:18:31 +01:00
{
m_call_context.push_arg(std::forward<T>(value));
}
template<typename T>
T& get_return_value()
2019-03-21 20:18:31 +01:00
{
return *m_call_context.get_return_value<T>();
}
public:
2019-03-21 20:18:31 +01:00
native_call_context m_call_context;
2019-07-29 23:19:21 +02:00
std::unordered_map<rage::scrNativeHash, rage::scrNativeHandler> m_handler_cache;
2022-09-30 20:41:26 +02:00
bool m_handlers_cached = false;
2019-03-21 20:18:31 +01:00
};
inline native_invoker g_native_invoker;
}