diff --git a/classes.cpp b/classes.cpp index 798f004..c42bf7d 100644 --- a/classes.cpp +++ b/classes.cpp @@ -4,11 +4,13 @@ #include "base/fwRefAwareBaseImpl.hpp" #include "entity/fwEntity.hpp" #include "network/sync/object/CObjectCreationData.hpp" +#include "network/sync/ped/CPedAttachData.hpp" #include "network/sync/ped/CPedCreationData.hpp" #include "network/sync/ped/CPedTaskTreeData.hpp" #include "network/sync/physical/CPhysicalAttachData.hpp" #include "network/sync/pickup/CPickupCreationData.hpp" #include "network/sync/player/CPlayerAppearanceData.hpp" +#include "network/sync/player/CPlayerHealthData.hpp" #include "network/sync/vehicle/CVehicleCreationData.hpp" #include "network/sync/vehicle/CVehicleProximityMigrationData.hpp" #include "network/sync/CProjectBaseSyncDataNode.hpp" @@ -31,6 +33,7 @@ #include "ped/CPed.hpp" #include "rage/atArray.hpp" #include "rage/atPlayerBits.hpp" +#include "rage/datBitBuffer.hpp" #include "rage/joaat.hpp" #include "rage/rlJson.hpp" #include "rage/rlMetric.hpp" diff --git a/network/sync/ped/CPedAttachData.hpp b/network/sync/ped/CPedAttachData.hpp new file mode 100644 index 0000000..202c84a --- /dev/null +++ b/network/sync/ped/CPedAttachData.hpp @@ -0,0 +1,13 @@ +#pragma once +#include + +class CPedAttachData +{ +public: + char pad_0000[32]; //0x0000 + uint16_t m_AttachObjectId; //0x0020 + char pad_0022[15]; //0x0022 + bool m_IsAttached; //0x0031 + char pad_0032[14]; //0x0032 +}; //Size: 0x0040 +static_assert(sizeof(CPedAttachData) == 0x40); \ No newline at end of file diff --git a/network/sync/player/CPlayerHealthData.hpp b/network/sync/player/CPlayerHealthData.hpp new file mode 100644 index 0000000..9bcf163 --- /dev/null +++ b/network/sync/player/CPlayerHealthData.hpp @@ -0,0 +1,21 @@ +#pragma once +#include + +#pragma pack(push, 8) +class CPlayerHealthData +{ +public: + uint32_t m_Unused; //0x0000 + bool m_BulletProof; //0x0004 + bool m_FlameProof; //0x0005 + bool m_ExplosionProof; //0x0006 + bool m_CollisionProof; //0x0007 + bool m_MeleeProof; //0x0008 + bool m_SmokeProof; //0x0009 + bool m_SteamProof; //0x000A + bool m_Godmode; //0x000B +private: + char m_Pad[4]; +}; //Size: 0x0010 +static_assert(sizeof(CPlayerHealthData) == 0x10); +#pragma pack(pop) \ No newline at end of file diff --git a/rage/datBitBuffer.hpp b/rage/datBitBuffer.hpp new file mode 100644 index 0000000..95317da --- /dev/null +++ b/rage/datBitBuffer.hpp @@ -0,0 +1,192 @@ +#pragma once +#include + +namespace rage +{ + class datBitBuffer + { + public: + datBitBuffer(void* data, uint32_t size, bool read = false) + { + m_Data = data; + m_BitOffset = 0; + m_MaxBit = size * 8; + m_BitsRead = 0; + m_CurBit = 0; + m_HighestBitsRead = 0; + m_ErrorCallback = nullptr; + m_FlagBits = read ? 1 : 0; + } + + static void ReadBitsSingle(uint8_t* data, int* out, int size, int offset) + { + int v5; // r11d + int v6; // ebx + uint8_t* v7; // r14 + char v8; // cl + int v9; // r11d + unsigned int v10; // r8d + int v11; // esi + __int64 v12; // r9 + + v5 = offset; + v6 = 1; + v7 = &data[offset >> 3]; + v8 = offset & 7; + if (size > 0) + v5 = size + offset - 1; + v9 = (v5 >> 3) - (offset >> 3); + v10 = (unsigned __int8)(*v7 << v8); + v11 = 8; + if (size > 8) + { + v12 = 1i64; + do + { + if (v12 > v9) + break; + ++v6; + v10 = (v10 << 8) | (v7[v12++] << v8); + v11 += 8; + } while (v11 < size); + } + if (v6 <= v9) + v10 |= v7[v6] >> (8 - v8); + *out = v10 >> (((size + 7) & 0xF8) - size); + } + + static void WriteBitsSingle(uint8_t* data, int value, int size, int offset) + { + uint8_t* v4; // r10 + int v5; // r9d + unsigned int v6; // r11d + uint8_t* v7; // r10 + unsigned int v8; // r11d + int v9; // ebx + __int64 v10; // rdx + char v11; // cl + + v4 = &data[(__int64)offset >> 3]; + v5 = offset & 7; + v6 = value << (32 - size); + *v4 = ((v6 >> 24) >> v5) | *v4 & ~((unsigned int)(-1 << (32 - size)) >> 24 >> v5); + v7 = v4 + 1; + v8 = v6 << (8 - v5); + v9 = -1 << (32 - size) << (8 - v5); + if (8 - v5 < size) + { + v10 = ((unsigned int)(size - (8 - v5) - 1) >> 3) + 1; + do + { + v11 = (v8 >> 24) | *v7 & ~(v9 >> 24); + v8 <<= 8; + *v7++ = v11; + v9 <<= 8; + --v10; + } while (v10); + } + } + + inline bool IsReadBuffer() + { + return m_FlagBits & 1; + } + + inline bool IsSizeCalculator() + { + return m_FlagBits & 2; + } + + void Seek(int bits, bool read) + { + m_BitsRead += bits; + + if (read) + { + if (m_HighestBitsRead > m_CurBit) + m_CurBit = m_HighestBitsRead; + } + else + { + if (m_BitsRead > m_CurBit) + m_CurBit = m_BitsRead; + } + } + + inline bool ReadDword(int* out, int size) + { + if (IsSizeCalculator()) + return false; + + if (m_BitsRead + size > (IsReadBuffer() ? m_MaxBit : m_CurBit)) + return false; + + ReadBitsSingle(static_cast(m_Data), out, size, m_BitsRead + m_BitOffset); + Seek(size, true); + return true; + } + + inline bool WriteDword(int val, int size) + { + if (IsReadBuffer()) + return false; + + if (m_BitsRead + size > m_MaxBit) + return false; + + if (!IsSizeCalculator()) + WriteBitsSingle(static_cast(m_Data), val, size, m_BitsRead + m_BitOffset); + Seek(size, false); + return true; + } + + inline bool ReadQword(uint64_t* out, int size) + { + if (size <= 32) + return ReadDword(reinterpret_cast(out), size); + + return ReadDword(reinterpret_cast(out), 32) && !ReadDword(reinterpret_cast(out) + 1, size - 32); + } + + inline bool WriteQword(uint64_t value, int size) + { + if (size <= 32) + return WriteDword(value, size); + + int low = (int)(value) & 0xFFFFFFFF; + int high = (int)((uint64_t)value >> 32); + + return WriteDword(low, 32) && WriteDword(high, size - 32); + } + + // unsigned + template + T Read(int size) + { + static_assert(sizeof(T) <= 8); + + uint64_t data{}; + ReadQword(&data, size); + return T(data); + } + + // unsigned + template + void Write(T data, int size) + { + static_assert(sizeof(T) <= 8); + + WriteQword(uint64_t(data), size); + } + + public: + void* m_Data; //0x0000 + uint32_t m_BitOffset; //0x0008 + uint32_t m_MaxBit; //0x000C + uint32_t m_BitsRead; //0x0010 + uint32_t m_CurBit; //0x0014 + uint32_t m_HighestBitsRead; //0x0018 + void* m_ErrorCallback; //0x0020 + uint8_t m_FlagBits; //0x0028 + }; +} \ No newline at end of file diff --git a/rdr2.rcnet b/rdr2.rcnet index eddc6d2..f70fa38 100644 Binary files a/rdr2.rcnet and b/rdr2.rcnet differ