From 722e3276338609dc980b15d2aeb38263300318fd Mon Sep 17 00:00:00 2001 From: Ryan <80224521+Rxann@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:20:42 -0400 Subject: [PATCH] ScrProgram, CNetObjectMgr, and More (#17) * template(copied from gta) * untested * gethost * CNetObjectMgr --- base/pgBase.hpp | 37 ++++++++++++ classes.cpp | 2 + network/CNetObjectMgr.hpp | 31 ++++++++++ script/scrProgram.hpp | 87 ++++++++++++++++++++++++++++ script/scriptHandlerNetComponent.hpp | 11 +++- 5 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 base/pgBase.hpp create mode 100644 network/CNetObjectMgr.hpp create mode 100644 script/scrProgram.hpp diff --git a/base/pgBase.hpp b/base/pgBase.hpp new file mode 100644 index 0000000..f539d9e --- /dev/null +++ b/base/pgBase.hpp @@ -0,0 +1,37 @@ +#pragma once +#include + +namespace rage +{ + +class pgBase +{ +public: + virtual ~pgBase() = default; + virtual int ReturnZero() = 0; + virtual void Error() = 0; + + void *unk_0000; // 0x0000 +}; // Size: 0x0008 +static_assert(sizeof(pgBase) == 0x10); + +class pgBaseMetaDataType +{ +public: + virtual ~pgBaseMetaDataType() = default; + virtual void Lookup(uint32_t hash) = 0; +}; // Size: 0x0008 + +class pgBaseMetaDataDebugNameType : public pgBaseMetaDataType +{ +public: + virtual ~pgBaseMetaDataDebugNameType() = default; + char pad_0000[64]; +}; // Size: 0x0072 + +class pgBaseRefCounted : public pgBase +{ +public: + virtual ~pgBaseRefCounted() = default; +}; // Size: 0x0008 +} \ No newline at end of file diff --git a/classes.cpp b/classes.cpp index 8ef54ae..47ea757 100644 --- a/classes.cpp +++ b/classes.cpp @@ -2,6 +2,7 @@ #include "base/fwExtensibleBase.hpp" #include "base/fwRefAwareBase.hpp" #include "base/fwRefAwareBaseImpl.hpp" +#include "base/pgBase.hpp" #include "entity/fwEntity.hpp" #include "network/CNetGamePlayer.hpp" #include "network/CNetworkPlayerMgr.hpp" @@ -52,4 +53,5 @@ #include "script/scriptHandlerNetComponent.hpp" #include "script/scriptId.hpp" #include "script/scriptIdBase.hpp" +#include "script/scrProgram.hpp" #include "script/types.hpp" diff --git a/network/CNetObjectMgr.hpp b/network/CNetObjectMgr.hpp new file mode 100644 index 0000000..29744a7 --- /dev/null +++ b/network/CNetObjectMgr.hpp @@ -0,0 +1,31 @@ +#pragma once +#include "CNetGamePlayer.hpp" +#include "netObject.hpp" +#include "rage/datBitBuffer.hpp" + +#include + +#pragma pack(push, 8) +class CNetworkObjectMgr +{ +public: + virtual ~CNetworkObjectMgr() = default; + virtual void _0x8() = 0; + virtual void Initialize() = 0; // 0x10 + virtual void Shutdown() = 0; + virtual void Update(bool) = 0; + virtual void AddEntity(void *, void *) = 0; + virtual void UnregisterNetworkObject_(void *unk, bool force) = 0; + virtual void UnregisterNetworkObject(rage::netObject *object, int reason, bool force1, bool force2) = 0; + virtual void ChangeOwner(rage::netObject *object, CNetGamePlayer *player, int migrationType, bool unk) = 0; + virtual void HandleJoiningPlayer(CNetGamePlayer *player) = 0; + virtual void HandleLeavingPlayer(CNetGamePlayer *player) = 0; + virtual void _0x50(CNetGamePlayer *player) = 0; + virtual void _0x58() = 0; + virtual void _0x60() = 0; + virtual int _0x68() = 0; + virtual void PackCloneCreate(rage::netObject *object, CNetGamePlayer *player, rage::datBitBuffer *buffer) = 0; + virtual bool PackCloneRemove(rage::netObject *object, CNetGamePlayer *player, bool) = 0; + virtual void PackCloneSync(rage::netObject *object, CNetGamePlayer *player) = 0; +}; +#pragma pack(pop) \ No newline at end of file diff --git a/script/scrProgram.hpp b/script/scrProgram.hpp new file mode 100644 index 0000000..f58b7e1 --- /dev/null +++ b/script/scrProgram.hpp @@ -0,0 +1,87 @@ +#pragma once +#include "base/pgBase.hpp" +#include "scrNativeHandler.hpp" + +#include + +namespace rage +{ +class scrProgram : public pgBase +{ +public: + std::uint8_t **m_CodeBlocks; // 0x10 + std::uint32_t m_Hash; // 0x18 + std::uint32_t m_CodeSize; // 0x1C + std::uint32_t m_ArgCount; // 0x20 + std::uint32_t m_LocalCount; // 0x24 + std::uint32_t m_GlobalCount; // 0x28 + std::uint32_t m_NativeCount; // 0x2C + void *m_LocalData; // 0x30 + void **m_GlobalData; // 0x38 + scrNativeHandler *m_NativeEntrypoints; // 0x40 + std::uint32_t m_ProcCount; // 0x48 + char pad_004C[4]; // 0x4C + const char **m_ProcNames; // 0x50 + std::uint32_t m_NameHash; // 0x58 + std::uint32_t m_RefCount; // 0x5C + const char *m_Name; // 0x60 + const char **m_StringsData; // 0x68 + std::uint32_t m_StringsCount; // 0x70 + char m_Breakpoints[0x0C]; // 0x74 This is an atMap, which we don't have the + // class for ATM. + + bool is_valid() const { return m_CodeSize != 0; } + + std::uint32_t GetNumCodePages() const { return (m_CodeSize + 0x3FFF) >> 14; } + + std::uint32_t GetCodePageSize(std::uint32_t page) const { + auto num = GetNumCodePages(); + if (page < num) { + if (page == num - 1) + return m_CodeSize & 0x3FFF; + return 0x4000; + } + + return 0; + } + + std::uint32_t GetFullCodeSize() const { + auto numPages = GetNumCodePages(); + if (!numPages) + return 0; + if (numPages == 1) + --numPages; + + return (numPages * 0x4000) + (m_CodeSize & 0x3FFF); + } + + std::uint8_t *GetCodePage(std::uint32_t page) const { + return m_CodeBlocks[page]; + } + + std::uint8_t *GetCodeAddress(std::uint32_t index) const { + if (index < m_CodeSize) + return &m_CodeBlocks[index >> 14][index & 0x3FFF]; + + return nullptr; + } + + const char *GetString(std::uint32_t index) const { + if (index < m_StringsCount) + return &m_StringsData[index >> 14][index & 0x3FFF]; + + return nullptr; + } + + scrNativeHandler *GetAddressOfNativeEntrypoint(scrNativeHandler entrypoint) { + for (std::uint32_t i = 0; i < m_NativeCount; ++i) { + if (m_NativeEntrypoints[i] == entrypoint) { + return m_NativeEntrypoints + i; + } + } + + return nullptr; + } +}; +static_assert(sizeof(scrProgram) == 0x80); +} \ No newline at end of file diff --git a/script/scriptHandlerNetComponent.hpp b/script/scriptHandlerNetComponent.hpp index 4a700e9..0453865 100644 --- a/script/scriptHandlerNetComponent.hpp +++ b/script/scriptHandlerNetComponent.hpp @@ -28,12 +28,21 @@ namespace rage public: scriptHandler* m_ScriptHandler; // 0x08 - char m_Pad[0x28]; // 0x10 + char m_Pad[0x20]; // 0x10 + CScriptParticipant *m_Host; // 0x30 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 + + inline CNetGamePlayer* GetHost() + { + if(!m_Host) + return nullptr; + + return m_Host->m_net_game_player; + } }; static_assert(sizeof(rage::scriptHandlerNetComponent) == 0x170); }