Skip to content

Commit

Permalink
Merge pull request #498 from MAFINS/patch-typeSafe
Browse files Browse the repository at this point in the history
Code clean up
  • Loading branch information
MAFINS authored Jan 29, 2023
2 parents 8d3857e + efe5e77 commit 4112be5
Show file tree
Hide file tree
Showing 93 changed files with 1,641 additions and 1,689 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/master_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: fbactions/setup-winsdk@v1
with:
winsdk-build-version: 18362

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
uses: microsoft/setup-msbuild@v1.1
#with: vs-version: '[16.4, 16.5)'

- name: Build
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: fbactions/setup-winsdk@v1
with:
winsdk-build-version: 18362

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
uses: microsoft/setup-msbuild@v1.1
#with: vs-version: '[16.4, 16.5)'

- name: Build
Expand Down
34 changes: 17 additions & 17 deletions Solution/source/Memory/GTAmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
HMODULE g_MainModule = 0;
MODULEINFO g_MainModuleInfo = { 0 };

template<typename R> R GetMultilayerPointer(void* base, std::vector<DWORD>& offsets)
template<typename R> R GetMultilayerPointer(void* base, const std::vector<DWORD>& offsets)
{
DWORD64 addr = (UINT64)base;
if (!addr)
Expand Down Expand Up @@ -250,7 +250,7 @@ int GTAmemory::modelNum1;
unsigned short GTAmemory::modelHashEntries;
std::array<std::vector<unsigned int>, 0x20> GTAmemory::vehicleModels;

unsigned int(*GTAmemory::_getHashKey)(char* stringPtr, unsigned int initialHash);
unsigned int(*GTAmemory::_getHashKey)(const char* stringPtr, unsigned int initialHash);
UINT64(*GTAmemory::_entityAddressFunc)(int handle);
UINT64(*GTAmemory::_playerAddressFunc)(int handle);
UINT64(*GTAmemory::_ptfxAddressFunc)(int handle);
Expand Down Expand Up @@ -784,7 +784,7 @@ void GTAmemory::Init()
checkpointPoolAddress = reinterpret_cast<UINT64 *>(*reinterpret_cast<int *>(address + 17) + address + 21);

address = FindPattern("\x48\x8B\x0B\x33\xD2\xE8\x00\x00\x00\x00\x89\x03", "xxxxxx????xx");
_getHashKey = reinterpret_cast<unsigned int(*)(char*, unsigned int)>(*reinterpret_cast<int*>(address + 6) + address + 10);
_getHashKey = reinterpret_cast<unsigned int(*)(const char*, unsigned int)>(*reinterpret_cast<int*>(address + 6) + address + 10);

address = FindPattern("\x48\x63\xC1\x48\x8D\x0D\x00\x00\x00\x00\xF3\x0F\x10\x04\x81\xF3\x0F\x11\x05\x00\x00\x00\x00", "xxxxxx????xxxxxxxxx????");
_writeWorldGravityAddress = reinterpret_cast<float *>(*reinterpret_cast<int *>(address + 6) + address + 10);
Expand Down Expand Up @@ -1093,22 +1093,22 @@ void GTAmemory::GetVehicleHandles(std::vector<Entity>& result)
}
void GTAmemory::GetVehicleHandles(std::vector<Entity>& result, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Vehicle);
auto pool = EntityPoolTask(EntityPoolTask::Type::Vehicle);
pool._modelHashes = modelHashes;
pool._modelCheck = !modelHashes.empty();
pool.Run(result);
}
void GTAmemory::GetVehicleHandles(std::vector<Entity>& result, const Vector3& position, float radius)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Vehicle);
auto pool = EntityPoolTask(EntityPoolTask::Type::Vehicle);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
pool.Run(result);
}
void GTAmemory::GetVehicleHandles(std::vector<Entity>& result, const Vector3& position, float radius, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Vehicle);
auto pool = EntityPoolTask(EntityPoolTask::Type::Vehicle);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
Expand All @@ -1123,22 +1123,22 @@ void GTAmemory::GetPedHandles(std::vector<Entity>& result)
}
void GTAmemory::GetPedHandles(std::vector<Entity>& result, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Ped);
auto pool = EntityPoolTask(EntityPoolTask::Type::Ped);
pool._modelHashes = modelHashes;
pool._modelCheck = !modelHashes.empty();
pool.Run(result);
}
void GTAmemory::GetPedHandles(std::vector<Entity>& result, const Vector3& position, float radius)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Ped);
auto pool = EntityPoolTask(EntityPoolTask::Type::Ped);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
pool.Run(result);
}
void GTAmemory::GetPedHandles(std::vector<Entity>& result, const Vector3& position, float radius, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Ped);
auto pool = EntityPoolTask(EntityPoolTask::Type::Ped);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
Expand All @@ -1153,22 +1153,22 @@ void GTAmemory::GetPropHandles(std::vector<Entity>& result)
}
void GTAmemory::GetPropHandles(std::vector<Entity>& result, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Prop);
auto pool = EntityPoolTask(EntityPoolTask::Type::Prop);
pool._modelHashes = modelHashes;
pool._modelCheck = !modelHashes.empty();
pool.Run(result);
}
void GTAmemory::GetPropHandles(std::vector<Entity>& result, const Vector3& position, float radius)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Prop);
auto pool = EntityPoolTask(EntityPoolTask::Type::Prop);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
pool.Run(result);
}
void GTAmemory::GetPropHandles(std::vector<Entity>& result, const Vector3& position, float radius, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Prop);
auto pool = EntityPoolTask(EntityPoolTask::Type::Prop);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
Expand All @@ -1183,22 +1183,22 @@ void GTAmemory::GetEntityHandles(std::vector<Entity>& result)
}
void GTAmemory::GetEntityHandles(std::vector<Entity>& result, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Ped | EntityPoolTask::Type::Vehicle | EntityPoolTask::Type::Prop);
auto pool = EntityPoolTask(EntityPoolTask::Type::Ped | EntityPoolTask::Type::Vehicle | EntityPoolTask::Type::Prop);
pool._modelHashes = modelHashes;
pool._modelCheck = !modelHashes.empty();
pool.Run(result);
}
void GTAmemory::GetEntityHandles(std::vector<Entity>& result, const Vector3& position, float radius)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Ped | EntityPoolTask::Type::Vehicle | EntityPoolTask::Type::Prop);
auto pool = EntityPoolTask(EntityPoolTask::Type::Ped | EntityPoolTask::Type::Vehicle | EntityPoolTask::Type::Prop);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
pool.Run(result);
}
void GTAmemory::GetEntityHandles(std::vector<Entity>& result, const Vector3& position, float radius, std::vector<DWORD> modelHashes)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::Ped | EntityPoolTask::Type::Vehicle | EntityPoolTask::Type::Prop);
auto pool = EntityPoolTask(EntityPoolTask::Type::Ped | EntityPoolTask::Type::Vehicle | EntityPoolTask::Type::Prop);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
Expand All @@ -1209,12 +1209,12 @@ void GTAmemory::GetEntityHandles(std::vector<Entity>& result, const Vector3& pos

void GTAmemory::GetPickupObjectHandles(std::vector<int>& result)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::PickupObject);
auto pool = EntityPoolTask(EntityPoolTask::Type::PickupObject);
pool.Run(result);
}
void GTAmemory::GetPickupObjectHandles(std::vector<int>& result, const Vector3& position, float radius)
{
auto& pool = EntityPoolTask(EntityPoolTask::Type::PickupObject);
auto pool = EntityPoolTask(EntityPoolTask::Type::PickupObject);
pool._position = position;
pool._radiusSquared = radius * radius;
pool._posCheck = true;
Expand Down
44 changes: 22 additions & 22 deletions Solution/source/Memory/GTAmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class BlipList
class GTAmemory final
{
public:
static unsigned int(*_getHashKey)(char* stringPtr, unsigned int initialHash);
static unsigned int(*_getHashKey)(const char* stringPtr, unsigned int initialHash);
static UINT64(*_entityAddressFunc)(int handle);
static UINT64(*_playerAddressFunc)(int handle);
static UINT64(*_ptfxAddressFunc)(int handle);
Expand Down Expand Up @@ -172,14 +172,14 @@ class GTAmemory final
static UINT64 _gxtLabelFromHashAddr1;
// Zorg
static char*(__fastcall *_gxtLabelFromHashFuncAddr)(UINT64 address, unsigned int hash);
static inline char* GTAmemory::GetGXTEntry(unsigned int labelHash)
static inline char* GetGXTEntry(unsigned int labelHash)
{
return _gxtLabelFromHashFuncAddr(_gxtLabelFromHashAddr1, labelHash);
}

static std::array<std::vector<unsigned int>, 0x20> const& VehicleModels()
{
return GTAmemory::vehicleModels;
return vehicleModels;
}
static bool IsModelAPed(unsigned int modelHash);

Expand All @@ -199,75 +199,75 @@ class GTAmemory final
return reinterpret_cast<T*>(getGlobalPtr(globalId));
}

static inline char GTAmemory::ReadSByte(UINT64 address)
static inline char ReadSByte(UINT64 address)
{
return *(char*)address;
}
static inline unsigned char GTAmemory::ReadByte(UINT64 address)
static inline unsigned char ReadByte(UINT64 address)
{
return *(unsigned char*)address;
}
static inline short GTAmemory::ReadShort(UINT64 address)
static inline short ReadShort(UINT64 address)
{
return *(short*)address;
}
static inline unsigned short GTAmemory::ReadUShort(UINT64 address)
static inline unsigned short ReadUShort(UINT64 address)
{
return *(unsigned short*)address;
}
static inline int GTAmemory::ReadInt(UINT64 address)
static inline int ReadInt(UINT64 address)
{
return *(int*)address;
}
static inline unsigned int GTAmemory::ReadUInt(UINT64 address)
static inline unsigned int ReadUInt(UINT64 address)
{
return *(unsigned int*)address;
}
static inline float GTAmemory::ReadFloat(UINT64 address)
static inline float ReadFloat(UINT64 address)
{
return *(float*)address;
}
static inline std::string GTAmemory::ReadString(UINT64 address)
static inline std::string ReadString(UINT64 address)
{
return (char*)address;
}
static Vector3 GTAmemory::ReadVector3(UINT64 address);
static Vector3 ReadVector3(UINT64 address);
/*static inline Matrix GTAmemory::ReadMatrix(UINT64 address)
{
return *(Matrix*)address;
}*/
static inline void GTAmemory::WriteSByte(UINT64 address, char value)
static inline void WriteSByte(UINT64 address, char value)
{
*(char*)address = value;
}
static inline void GTAmemory::WriteByte(UINT64 address, unsigned char value)
static inline void WriteByte(UINT64 address, unsigned char value)
{
*(unsigned char*)address = value;
}
static inline void GTAmemory::WriteShort(UINT64 address, short value)
static inline void WriteShort(UINT64 address, short value)
{
*(short*)address = value;
}
static inline void GTAmemory::WriteUShort(UINT64 address, unsigned short value)
static inline void WriteUShort(UINT64 address, unsigned short value)
{
*(unsigned short*)address = value;
}
static inline void GTAmemory::WriteInt(UINT64 address, int value)
static inline void WriteInt(UINT64 address, int value)
{
*(int*)address = value;
}
static inline void GTAmemory::WriteUInt(UINT64 address, unsigned int value)
static inline void WriteUInt(UINT64 address, unsigned int value)
{
*(unsigned int*)address = value;
}
static inline void GTAmemory::WriteFloat(UINT64 address, float value)
static inline void WriteFloat(UINT64 address, float value)
{
*(float*)address = value;
}
static void GTAmemory::WriteVector3(UINT64 address, const Vector3& value);
static inline unsigned int GTAmemory::GetHashKey(const std::string& toHash)
static void WriteVector3(UINT64 address, const Vector3& value);
static inline unsigned int GetHashKey(const std::string& toHash)
{
return GTAmemory::_getHashKey(const_cast<char*>(toHash.c_str()), 0);
return _getHashKey(toHash.c_str(), 0);
}

static UINT64 GetEntityAddress(int handle);
Expand Down
8 changes: 4 additions & 4 deletions Solution/source/Menu/FolderPreviewBmps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace sub
decltype(vFolderBmps)::iterator SearchBmps(const std::string& filePath)
{
auto& map = vFolderBmps;
auto& last = map.end();
auto& it = std::lower_bound(map.begin(), last, filePath,
auto last = map.end();
auto it = std::lower_bound(map.begin(), last, filePath,
[](const std::pair<std::string, DxHookIMG::DxTexture>& a, const std::string& b)
-> bool { return a.first < b; });

Expand Down Expand Up @@ -75,7 +75,7 @@ namespace sub

for (auto& newBmp : newBmps)
{
auto& it = SearchBmps(newBmp.first);
auto it = SearchBmps(newBmp.first);
if (it == vFolderBmps.end())
{
newBmp.second.Load(newBmp.first);
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace sub
{
const std::string path = folderPath + "\\" + previewPng;

auto& it = SearchBmps(path);
auto it = SearchBmps(path);
if (it != vFolderBmps.end())
{
Vector2 res = { 0.1f, 0.0889f };
Expand Down
Loading

0 comments on commit 4112be5

Please sign in to comment.