Invoker stuff (#1)

* feat: initialize classes repo

* feat(script): stuff for native invoker

* feat: add some more classes

* feat(player): complete CNetworkPlayerMgr

* feat(network): add some more stuff

* feat(network): add rlGamerInfo

* feat(player): add CPlayerInfo
This commit is contained in:
maybegreat48
2023-08-26 19:12:04 +00:00
committed by GitHub
parent d07e253439
commit a2a74e151a
21 changed files with 800 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <utility>
namespace rage
{
class scrNativeCallContext
{
public:
constexpr void reset()
{
m_arg_count = 0;
m_data_count = 0;
}
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);
}
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);
}
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);
}
template <typename T>
constexpr T* get_return_value()
{
return reinterpret_cast<T*>(m_return_value);
}
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);
}
protected:
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);
using scrNativeHash = std::int64_t;
using scrNativePair = std::pair<scrNativeHash, scrNativeHash>;
using scrNativeHandler = void(*)(scrNativeCallContext*);
}
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include "scrThreadContext.hpp"
namespace rage
{
class scrThread
{
public:
virtual ~scrThread() = default; // 0 (0x00)
virtual void Reset(std::uint32_t script_hash, void* args, std::uint32_t arg_count) = 0; // 1 (0x08)
virtual eThreadState Run() = 0; // 2 (0x10)
virtual eThreadState Tick(std::uint32_t ops_to_execute) = 0; // 3 (0x18)
virtual void Kill() = 0; // 4 (0x20)
public:
scrThreadContext m_Context; // 0x008
void* m_Stack; // 0x6B8
char m_padding[0x8]; // 0x6C0
uint32_t m_ArgsSize; // 0x6C8
uint32_t m_ArgsPointer; // 0x6CC
const char* m_ExitMessage; // 0x6D0
char m_padding2[0x8]; // 0x6D8
void* m_Handler; // 0x6E0
void* m_HandlerNetComponent; // 0x6E8
};
static_assert(sizeof(rage::scrThread) == 0x6F0);
}
+42
View File
@@ -0,0 +1,42 @@
#pragma once
#include <cstdint>
#include "../rage/joaat.hpp"
namespace rage
{
enum class eThreadState : std::uint32_t
{
idle,
running,
killed,
unk_3,
unk_4,
};
class scrThreadContext
{
public:
std::uint32_t m_ThreadId; // 0x00
joaat_t m_ScriptHash; // 0x04
eThreadState m_State; // 0x08
std::uint32_t m_ProgramCounter; // 0x0C
std::uint32_t m_FramePointer; // 0x10
std::uint32_t m_StackPointer; // 0x14
float m_TimerA; // 0x18
float m_TimerB; // 0x1C
float m_TimerC; // 0x20
char m_padding1[0x2C]; // 0x24
std::uint32_t m_StackSize; // 0x50
uint32_t m_SetjmpPC; // 0x54
uint32_t m_SetjmpFrame; // 0x58
uint32_t m_SetjmpStack; // 0x5C
uint32_t m_SetjmpUnk; // 0x60
uint32_t m_StackFrameCount; // 0x64 actually used in RDR2
uint32_t m_StackFrames[16]; // 0x68
void* m_SecureFrames[96]; // 0xA8
void* m_SecureStatics[96]; // 0x3A8
void* m_UnkSecureVar; // 0x6A8
};
static_assert(sizeof(scrThreadContext) == 0x6B0);
}
+119
View File
@@ -0,0 +1,119 @@
#pragma once
#include "../rage/vector.hpp"
#include <string>
#include <sstream>
#include <ostream>
namespace rage
{
class scrVector
{
public:
scrVector() = default;
scrVector(rage::fvector3 vec) :
x(vec.x), y(vec.y), z(vec.z)
{
}
scrVector(float x, float y, float z) :
x(x), y(y), z(z)
{
}
scrVector operator+(const scrVector& other)
{
scrVector vec;
vec.x = this->x + other.x;
vec.y = this->y + other.y;
vec.z = this->z + other.z;
return vec;
}
scrVector operator-(const scrVector& other)
{
scrVector vec;
vec.x = this->x - other.x;
vec.y = this->y - other.y;
vec.z = this->z - other.z;
return vec;
}
scrVector operator*(const scrVector& other)
{
scrVector vec;
vec.x = this->x * other.x;
vec.y = this->y * other.y;
vec.z = this->z * other.z;
return vec;
}
scrVector operator*(const float& other)
{
scrVector vec;
vec.x = this->x * other;
vec.y = this->y * other;
vec.z = this->z * other;
return vec;
}
bool operator==(const scrVector& other)
{
return this->x == other.x && this->y == other.y && this->z == other.z;
}
bool operator!=(const scrVector& other)
{
return this->x != other.x || this->y != other.y || this->z != other.z;
}
std::string to_string() const
{
std::stringstream ss;
ss << *this;
return ss.str();
}
friend std::ostream& operator<<(std::ostream& os, const scrVector& vec)
{
os << "(" << vec.x << ", " << vec.y << ", " << vec.z << ")";
return os;
}
alignas(8) float x{};
alignas(8) float y{};
alignas(8) float z{};
};
}
class Vector2 final
{
public:
Vector2() = default;
Vector2(float x, float y)
: x(x), y(y)
{
}
public:
alignas(8) float x;
alignas(8) float y;
};
class Vector4 final
{
public:
Vector4() = default;
Vector4(float x, float y, float z, float w)
: x(x), y(y), z(z), w(w)
{
}
public:
alignas(8) float x;
alignas(8) float y;
alignas(8) float z;
alignas(8) float w;
};
+40
View File
@@ -0,0 +1,40 @@
#pragma once
class CNetGamePlayer;
class CScriptParticipant
{
public:
char pad_0000[16]; //0x0000
class CNetGamePlayer* m_net_game_player;//0x0010
char pad_0018[2]; //0x0018
int16_t m_participant_index; //0x001A
char pad_001C[12]; //0x001C
};
static_assert(sizeof(CScriptParticipant) == 0x28);
#pragma pack(push, 8)
namespace rage
{
class scriptHandler;
class scriptHandlerNetComponent
{
public:
virtual ~scriptHandlerNetComponent() = default;
virtual bool _0x08(void*) = 0;
virtual void _0x10(CNetGamePlayer*) = 0;
virtual void* HandlePlayerLeft(CNetGamePlayer* player) = 0;
virtual void* SendHostMigrationEvent(CNetGamePlayer* player) = 0;
public:
scriptHandler* m_ScriptHandler; // 0x08
char m_Pad[0x28]; // 0x10
std::uint8_t m_LocalParticipantId; // 0x38
void* m_Pad2[4]; // 0x40
CScriptParticipant* m_Participants[32]; // 0x60
int m_Pad3[3]; // 0x160
std::uint8_t m_NumParticipants; // 0x168
};
static_assert(sizeof(rage::scriptHandlerNetComponent) == 0x170);
}
#pragma pack(pop)
+119
View File
@@ -0,0 +1,119 @@
#pragma once
#include <cstdint>
#include "scrVector.hpp"
#ifndef BOOL
#define BOOL int
#endif
using Vector3 = rage::scrVector;
typedef int Void;
typedef int Any;
typedef int uint;
typedef int Hash;
typedef int Entity;
typedef int Player;
typedef int FireId;
typedef int Ped;
typedef int Vehicle;
typedef int Cam;
typedef int CarGenerator;
typedef int Group;
typedef int Train;
typedef int Pickup;
typedef int Object;
typedef int Weapon;
typedef int Interior;
typedef int Blip;
typedef int Texture;
typedef int TextureDict;
typedef int CoverPoint;
typedef int Camera;
typedef int TaskSequence;
typedef int ColourIndex;
typedef int Sphere;
typedef int INT, ScrHandle;
typedef int AnimScene;
typedef int Volume;
typedef int ItemSet;
typedef int PropSet;
typedef int PopZone;
typedef int PersChar;
typedef int Prompt;
#define PLAYER_INDEX alignas(8) Player
#define ENTITY_INDEX alignas(8) Entity
#define PED_INDEX alignas(8) Ped
#define VEHICLE_INDEX alignas(8) Vehicle
#define INTERIOR_INDEX alignas(8) Interior
#define NETWORK_INDEX alignas(8) int
#define SCR_HASH alignas(8) Hash
#define SCR_INT alignas(8) int
#define SCR_BOOL alignas(8) BOOL
#define SCR_FLOAT alignas(8) float
#define SCR_VEC3 Vector3
template <int SIZE>
struct SCR_TEXT_LABEL
{
alignas(8) char Data[SIZE];
private:
alignas(8) char _PAD[SIZE];
public:
operator char* () { return Data; }
};
#define TEXT_LABEL_15 SCR_TEXT_LABEL<16>
#define TEXT_LABEL_23 SCR_TEXT_LABEL<24>
#define TEXT_LABEL_31 SCR_TEXT_LABEL<32>
#define TEXT_LABEL_63 SCR_TEXT_LABEL<64>
template <typename T, int SIZE>
struct SCR_ARRAY
{
SCR_INT Size;
alignas(8) T Data[SIZE];
T& operator [](int index)
{
return Data[index];
}
};
template <typename T>
struct SCR_BITSET
{
alignas(8) int Value;
bool IsSet(T val)
{
return Value & (1 << (int)val);
}
void Set(T val)
{
Value |= (1 << (int)val);
}
void Clear(T val)
{
Value &= ~(1 << (int)val);
}
};
struct Color3
{
SCR_INT R;
SCR_INT G;
SCR_INT B;
};
static_assert(sizeof(Color3) == 3 * 8);
// serialized bitbuffer data of rage::rlGamerHandle + some padding for last gen compatibility
struct GAMER_HANDLE
{
private:
uint64_t Data[13];
};
static_assert(sizeof(GAMER_HANDLE) == 13 * 8);