Improve protections again and player database (#606)
This commit is contained in:
@ -2,205 +2,4 @@
|
||||
#include <cstdint>
|
||||
#include "fwddec.hpp"
|
||||
#include "sysMemAllocator.hpp"
|
||||
|
||||
namespace rage
|
||||
{
|
||||
#pragma pack(push, 8)
|
||||
template <typename T>
|
||||
class atArray
|
||||
{
|
||||
public:
|
||||
atArray()
|
||||
{
|
||||
m_data = nullptr;
|
||||
m_count = 0;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
atArray(const atArray& right)
|
||||
{
|
||||
m_count = right.m_count;
|
||||
m_size = right.m_size;
|
||||
|
||||
m_data = (T*)rage::GetAllocator()->allocate(m_size * sizeof(T), 16, 0);
|
||||
std::uninitialized_copy(right.m_data, right.m_data + right.m_count, m_data);
|
||||
}
|
||||
|
||||
atArray(int capacity)
|
||||
{
|
||||
m_data = (T*)rage::GetAllocator()->allocate(capacity * sizeof(T), 16, 0);
|
||||
m_count = 0;
|
||||
m_size = capacity;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_count = 0;
|
||||
m_size = 0;
|
||||
|
||||
if (m_data)
|
||||
{
|
||||
rage::GetAllocator()->free(m_data);
|
||||
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void append(atArray<T> array_value)
|
||||
{
|
||||
auto value_array_size = array_value.size();
|
||||
auto old_capacity = m_count;
|
||||
|
||||
if ((value_array_size + m_count) > std::numeric_limits<uint16_t>::max())
|
||||
LOG(FATAL) << "RAGE atArray::append was given too large of an atArray to append";
|
||||
|
||||
auto size = (uint16_t)value_array_size;
|
||||
expand(m_count + size);
|
||||
m_size += size;
|
||||
|
||||
auto i = old_capacity;
|
||||
for (auto weapon_hash : array_value)
|
||||
{
|
||||
m_data[i] = weapon_hash;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void append(std::vector<T> value_array)
|
||||
{
|
||||
auto value_array_size = value_array.size();
|
||||
auto old_capacity = m_count;
|
||||
|
||||
if ((value_array_size + m_count) > std::numeric_limits<uint16_t>::max())
|
||||
LOG(FATAL) << "RAGE atArray::append was given too large of a vector to append";
|
||||
|
||||
auto size = (uint16_t)value_array_size;
|
||||
expand(m_count + size);
|
||||
m_size += size;
|
||||
|
||||
auto i = old_capacity;
|
||||
for (auto weapon_hash : value_array)
|
||||
{
|
||||
m_data[i] = weapon_hash;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void append(const std::initializer_list<T> value_array)
|
||||
{
|
||||
auto value_array_size = value_array.size();
|
||||
auto old_capacity = m_count;
|
||||
|
||||
if ((value_array_size + m_count) > std::numeric_limits<uint16_t>::max())
|
||||
LOG(FATAL) << "RAGE atArray::append was given too large of a list to append";
|
||||
|
||||
auto size = (uint16_t)value_array_size;
|
||||
expand(m_count + size);
|
||||
m_size += size;
|
||||
|
||||
auto i = old_capacity;
|
||||
for (const T* it = value_array.begin(); it != value_array.end(); ++it)
|
||||
{
|
||||
m_data[i] = *it;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void append(T value)
|
||||
{
|
||||
set(m_count, value);
|
||||
}
|
||||
|
||||
void set(uint16_t offset, const T& value)
|
||||
{
|
||||
if (offset >= m_count)
|
||||
{
|
||||
expand(offset + 1);
|
||||
}
|
||||
|
||||
if (offset >= m_size)
|
||||
{
|
||||
m_size = offset + 1;
|
||||
}
|
||||
|
||||
m_data[offset] = value;
|
||||
}
|
||||
|
||||
void expand(uint16_t newSize)
|
||||
{
|
||||
if (m_count >= newSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
T* newOffset = (T*)rage::GetAllocator()->allocate(newSize * sizeof(T), 16, 0);
|
||||
|
||||
// initialize the new entries
|
||||
std::uninitialized_fill(newOffset, newOffset + newSize, T());
|
||||
|
||||
// copy the existing entries
|
||||
if (m_data)
|
||||
{
|
||||
std::copy(m_data, m_data + m_size, newOffset);
|
||||
|
||||
rage::GetAllocator()->free(m_data);
|
||||
}
|
||||
|
||||
m_data = newOffset;
|
||||
m_count = newSize;
|
||||
}
|
||||
|
||||
T* begin() const
|
||||
{
|
||||
return &m_data[0];
|
||||
}
|
||||
|
||||
T* end() const
|
||||
{
|
||||
return &m_data[m_size];
|
||||
}
|
||||
|
||||
T* data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
std::uint16_t size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
std::uint16_t count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
T& operator[](std::uint16_t index) const
|
||||
{
|
||||
return m_data[index];
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& o, const atArray<T>& j)
|
||||
{
|
||||
o << "Array Size: " << j.size() << std::endl;
|
||||
for(int i = 0; i < j.size(); i++)
|
||||
{
|
||||
T item = j[i];
|
||||
if (std::is_pointer<T>())
|
||||
o << "\tArray Pointer: " << HEX_TO_UPPER(item) << " Item: [" << HEX_TO_UPPER(*(T*)item) << "]";
|
||||
else
|
||||
o << "\tArray Item: " << item;
|
||||
if (i != j.size() - 1)
|
||||
o << std::endl;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_data;
|
||||
std::uint16_t m_size;
|
||||
std::uint16_t m_count;
|
||||
};
|
||||
static_assert(sizeof(rage::atArray<Hash>) == 0x10, "rage::atArray is not properly sized");
|
||||
#pragma pack(pop)
|
||||
}
|
||||
#include <rage/atArray.hpp>
|
@ -3,38 +3,6 @@
|
||||
|
||||
constexpr auto MAX_PLAYERS = 32;
|
||||
|
||||
enum eObjType : uint16_t {
|
||||
carObjType = 0,
|
||||
bikeObjType = 1,
|
||||
boatObjType = 2,
|
||||
doorObjType = 3,
|
||||
heliObjType = 4,
|
||||
objType = 5,
|
||||
pedObjType = 6,
|
||||
pickupObjType = 7,
|
||||
pickupPlacementObjType = 8,
|
||||
planeObjType = 9,
|
||||
submarineObjType = 10,
|
||||
playerObjType = 11,
|
||||
trailerObjType = 12,
|
||||
trainObjType = 13,
|
||||
unkObjType14 = 14,
|
||||
unkObjType = 69
|
||||
};
|
||||
|
||||
enum eSyncReply : int64_t
|
||||
{
|
||||
NoSyncTreeFound = 1, // No sync tree found
|
||||
PlayerIsNotInOurRoamingBubble = 1, // Player is not in our roaming bubble
|
||||
WrongOwner = 2, // Wrong owner
|
||||
ObjectIsBeingReassinged = 2, // Object is being reassigned
|
||||
CantApplyData_NoNetworkObject = 4, // Can't apply data - no network object
|
||||
CantApplyData = 6, // Can't apply data
|
||||
CantApplyData_NoGameObject = 6, // Can't apply data - no game object
|
||||
CantApplyData_NetworkClosed = 7, // Can't apply data - network closed
|
||||
SuccessfullSync = 8
|
||||
};
|
||||
|
||||
enum class ControllerInputs : std::uint32_t
|
||||
{
|
||||
INPUT_NEXT_CAMERA,
|
||||
|
@ -6,12 +6,48 @@
|
||||
#pragma pack(push, 1)
|
||||
namespace rage
|
||||
{
|
||||
class CSyncDataBase
|
||||
{
|
||||
public:
|
||||
virtual ~CSyncDataBase() = default;
|
||||
virtual bool SerializeDword(uint32_t* dword, int size) = 0;
|
||||
virtual bool SerializeWord(uint16_t* word, int size) = 0;
|
||||
virtual bool SerializeByte(uint8_t* byte, int size) = 0;
|
||||
virtual bool SerializeInt32(int32_t* i, int size) = 0;
|
||||
virtual bool SerializeInt16(int16_t* i, int size) = 0;
|
||||
virtual bool SerializeSignedByte(int8_t* byte, int size) = 0;
|
||||
virtual bool SerializeBool(bool* flag) = 0;
|
||||
virtual bool SerializeInt64(int64_t* i, int size) = 0;
|
||||
virtual bool SerializeInt32Alt(int32_t* i, int size) = 0;
|
||||
virtual bool SerializeInt16Alt(int16_t* i, int size) = 0;
|
||||
virtual bool SerializeSignedByteAlt(int8_t* byte, int size) = 0;
|
||||
virtual bool SerializeQword(uint64_t* qword, int size) = 0;
|
||||
virtual bool SerializeDwordAlt(uint32_t* dword, int size) = 0;
|
||||
virtual bool SerializeWordAlt(uint16_t* word, int size) = 0;
|
||||
virtual bool SerializeByteAlt(uint8_t* byte, int size) = 0;
|
||||
virtual bool SerializeSignedFloat(float* flt, float divisor, int size) = 0;
|
||||
virtual bool SerializeFloat(float* flt, float divisor, int size) = 0;
|
||||
virtual bool SerializeNetworkId(uint16_t* net_id) = 0;
|
||||
virtual bool SerializeVector3(rage::fvector3* vec3, float divisor, int size) = 0;
|
||||
virtual bool SerializeQuaternion(void* unk) = 0; // i have no clue what that is
|
||||
virtual bool SerializeVector3SignedZComponent(rage::fvector3* vec3, float divisor, int size) = 0;
|
||||
virtual bool SerializeOrientation(rage::fvector4* vec4, float size) = 0; // yes, the size is a float
|
||||
virtual bool SerializeArray(void* array, int size) = 0;
|
||||
virtual bool SerializeString(char* str, int max_length) = 0;
|
||||
virtual bool IsSizeCalculator() = 0;
|
||||
virtual bool IsSizeCalculator2() = 0;
|
||||
|
||||
void* unk_0x8;
|
||||
void* syncLog;
|
||||
datBitBuffer* buffer;
|
||||
};
|
||||
|
||||
class netPlayer;
|
||||
|
||||
class datBitBuffer
|
||||
{
|
||||
public:
|
||||
datBitBuffer(uint8_t* data, uint32_t size) {
|
||||
datBitBuffer(void* data, uint32_t size) {
|
||||
m_data = data;
|
||||
m_bitOffset = 0;
|
||||
m_maxBit = size * 8;
|
||||
@ -46,7 +82,7 @@ namespace rage
|
||||
return 0;
|
||||
auto const bufPos = m_bitsRead + m_bitOffset;
|
||||
auto const initialBitOffset = bufPos & 0b111;
|
||||
auto const start = &m_data[bufPos / 8];
|
||||
auto const start = &((uint8_t*)m_data)[bufPos / 8];
|
||||
auto const next = &start[1];
|
||||
auto result = (start[0] << initialBitOffset) & 0xff;
|
||||
for (auto i = 0; i < ((numBits - 1) / 8); i++) {
|
||||
@ -139,7 +175,7 @@ namespace rage
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool WriteArray(uint8_t* array, int size) {
|
||||
bool WriteArray(void* array, int size) {
|
||||
return big::g_pointers->m_write_bitbuf_array(this, array, size, 0);
|
||||
}
|
||||
bool ReadArray(PVOID array, int size) {
|
||||
@ -167,8 +203,16 @@ namespace rage
|
||||
|
||||
return T(val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Write(T data, int length)
|
||||
{
|
||||
static_assert(sizeof(T) <= 8, "maximum of 64 bit write");
|
||||
|
||||
WriteQWord((uint64_t)data, length);
|
||||
}
|
||||
public:
|
||||
uint8_t* m_data; //0x0000
|
||||
void* m_data; //0x0000
|
||||
uint32_t m_bitOffset; //0x0008
|
||||
uint32_t m_maxBit; //0x000C
|
||||
uint32_t m_bitsRead; //0x0010
|
||||
|
@ -1,72 +1,3 @@
|
||||
#pragma once
|
||||
#include "fwddec.hpp"
|
||||
|
||||
namespace rage
|
||||
{
|
||||
class sysMemAllocator
|
||||
{
|
||||
public:
|
||||
virtual ~sysMemAllocator() = 0;
|
||||
|
||||
virtual void SetQuitOnFail(bool) = 0;
|
||||
virtual void* Allocate(size_t size, size_t align, int subAllocator) = 0;
|
||||
|
||||
inline void* allocate(size_t size, size_t align, int subAllocator)
|
||||
{
|
||||
return Allocate(size, align, subAllocator);
|
||||
}
|
||||
|
||||
virtual void* TryAllocate(size_t size, size_t align, int subAllocator) = 0;
|
||||
|
||||
virtual void Free(void* pointer) = 0;
|
||||
|
||||
virtual void free(void* pointer)
|
||||
{
|
||||
return Free(pointer);
|
||||
}
|
||||
|
||||
virtual void TryFree(void* pointer) = 0;
|
||||
|
||||
virtual void Resize(void* pointer, size_t size) = 0;
|
||||
|
||||
virtual sysMemAllocator* GetAllocator(int allocator) const = 0;
|
||||
|
||||
virtual sysMemAllocator* GetAllocator(int allocator) = 0;
|
||||
|
||||
virtual sysMemAllocator* GetPointerOwner(void* pointer) = 0;
|
||||
|
||||
virtual size_t GetSize(void* pointer) const = 0;
|
||||
|
||||
virtual size_t GetMemoryUsed(int memoryBucket) = 0;
|
||||
|
||||
virtual size_t GetMemoryAvailable() = 0;
|
||||
|
||||
public:
|
||||
|
||||
static sysMemAllocator* UpdateAllocatorValue()
|
||||
{
|
||||
//B9 ? ? ? ? 48 8B 0C 01 45 33 C9 49 8B D2 48
|
||||
auto g_gtaTlsEntry = *(sysMemAllocator**)(*(uintptr_t*)(__readgsqword(88)) + 0xC8); //This has been 0xC8 since 323, I'm not adding this signature to pointers...
|
||||
|
||||
if (g_gtaTlsEntry == nullptr)
|
||||
LOG(FATAL) << "Failed to find tlsEntry within GTA5.exe via __readgsqword";
|
||||
|
||||
*(sysMemAllocator**)(*(uintptr_t*)(__readgsqword(88)) + 0xC8) = g_gtaTlsEntry;
|
||||
*(sysMemAllocator**)(*(uintptr_t*)(__readgsqword(88)) + 0xC8 - 8) = g_gtaTlsEntry;
|
||||
|
||||
return g_gtaTlsEntry;
|
||||
}
|
||||
};
|
||||
|
||||
inline sysMemAllocator* GetAllocator()
|
||||
{
|
||||
sysMemAllocator* allocator = *(sysMemAllocator**)(*(uintptr_t*)(__readgsqword(88)) + 0xC8);
|
||||
|
||||
if (!allocator)
|
||||
{
|
||||
return sysMemAllocator::UpdateAllocatorValue();
|
||||
}
|
||||
|
||||
return allocator;
|
||||
}
|
||||
}
|
||||
#include <rage/sysMemAllocator.hpp>
|
Reference in New Issue
Block a user