2022-11-09 05:11:50 +08:00
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace rage
|
|
|
|
{
|
2023-08-19 03:58:00 +08:00
|
|
|
class scrNativeCallContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
constexpr void reset()
|
|
|
|
{
|
|
|
|
m_arg_count = 0;
|
|
|
|
m_data_count = 0;
|
|
|
|
}
|
2022-11-09 05:11:50 +08:00
|
|
|
|
2023-08-19 03:58:00 +08:00
|
|
|
template <typename T>
|
|
|
|
constexpr void push_arg(T&& value)
|
|
|
|
{
|
|
|
|
static_assert(sizeof(T) <= sizeof(std::uint64_t));
|
|
|
|
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(reinterpret_cast<std::uint64_t*>(m_args) + (m_arg_count++)) = std::forward<T>(value);
|
|
|
|
}
|
2022-11-09 05:11:50 +08:00
|
|
|
|
2023-08-19 03:58:00 +08:00
|
|
|
template <typename T>
|
|
|
|
constexpr T& get_arg(std::size_t index)
|
|
|
|
{
|
|
|
|
static_assert(sizeof(T) <= sizeof(std::uint64_t));
|
|
|
|
return *reinterpret_cast<T*>(reinterpret_cast<std::uint64_t*>(m_args) + index);
|
|
|
|
}
|
2022-11-09 05:11:50 +08:00
|
|
|
|
2023-08-19 03:58:00 +08:00
|
|
|
template <typename T>
|
|
|
|
constexpr void set_arg(std::size_t index, T&& value)
|
|
|
|
{
|
|
|
|
static_assert(sizeof(T) <= sizeof(std::uint64_t));
|
|
|
|
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(reinterpret_cast<std::uint64_t*>(m_args) + index) = std::forward<T>(value);
|
|
|
|
}
|
2022-11-09 05:11:50 +08:00
|
|
|
|
2023-08-19 03:58:00 +08:00
|
|
|
template <typename T>
|
|
|
|
constexpr T* get_return_value()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<T*>(m_return_value);
|
|
|
|
}
|
2022-11-09 05:11:50 +08:00
|
|
|
|
2023-08-19 03:58:00 +08:00
|
|
|
template <typename T>
|
|
|
|
constexpr void set_return_value(T&& value)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<std::remove_cv_t<std::remove_reference_t<T>>*>(m_return_value) = std::forward<T>(value);
|
|
|
|
}
|
2023-12-20 22:49:40 +08:00
|
|
|
|
2023-08-19 03:58:00 +08:00
|
|
|
void* m_return_value;
|
|
|
|
std::uint32_t m_arg_count;
|
|
|
|
void* m_args;
|
|
|
|
std::int32_t m_data_count;
|
|
|
|
std::uint32_t m_data[48];
|
|
|
|
};
|
|
|
|
static_assert(sizeof(scrNativeCallContext) == 0xE0);
|
2022-11-10 04:13:12 +08:00
|
|
|
|
2023-09-04 02:25:35 +08:00
|
|
|
using scrNativeHash = std::uint64_t;
|
2023-08-19 03:58:00 +08:00
|
|
|
using scrNativePair = std::pair<scrNativeHash, scrNativeHash>;
|
|
|
|
using scrNativeHandler = void(*)(scrNativeCallContext*);
|
2023-09-04 02:25:35 +08:00
|
|
|
}
|