Skip to content

Commit

Permalink
Pools and Context Menu Additions (#147)
Browse files Browse the repository at this point in the history
Added Pools to go with the new RDR-Classes and change the context menu to use the pools.
  • Loading branch information
tyackman authored Jun 14, 2024
1 parent 0e7b6eb commit f739bfc
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/game/frontend/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "game/backend/Players.hpp"
#include "game/pointers/Pointers.hpp"
#include "game/rdr/Enums.hpp"

#include "util/Helpers.hpp"

namespace YimMenu::Features
{
Expand All @@ -21,7 +21,7 @@ namespace YimMenu
return std::abs(screenPos.x - 0.5) + std::abs(screenPos.y - 0.5);
}

inline int GetEntityHandleClosestToMiddleOfScreen(bool includePlayers, bool includePeds = false, bool includeVehicles = false, bool includeObjects = false)
inline int GetEntityHandleClosestToMiddleOfScreen(bool includePlayers, bool includePeds, bool includeVehicles = false, bool includeObjects = false)
{
int closestHandle{};
float distance = 1;
Expand All @@ -47,6 +47,15 @@ namespace YimMenu
}
}

if (includePeds)
{
for (Ped ped : Helpers::GetAllPeds())
{
if (ped.IsValid() || ped.GetPointer<void*>())
updateClosestEntity(ped.GetHandle());
}
}

return closestHandle;
}

Expand All @@ -60,7 +69,7 @@ namespace YimMenu

if (m_Enabled)
{
auto handle = GetEntityHandleClosestToMiddleOfScreen(true);
auto handle = GetEntityHandleClosestToMiddleOfScreen(true, true);

static auto switchToMenu = [&](ContextOperationsMenu menu) -> void {
if (m_CurrentOperationsMenu != menu)
Expand Down
8 changes: 8 additions & 0 deletions src/game/frontend/ContextMenus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,13 @@ namespace YimMenu
true,
false);
}},
{"Copy Hash",
[&](Entity entity) {
Hash modelHash = ENTITY::GET_ENTITY_MODEL(entity.GetHandle());

ImGui::SetClipboardText(std::format("0x{:08X}", (joaat_t)modelHash).c_str());
LOG(INFO) << std::format("Copied hash 0x{:08X}", (joaat_t)modelHash).c_str();
Notifications::Show("Context Menu", std::format("Copied hash 0x{:08X}", (joaat_t)modelHash).c_str(), NotificationType::Info);
}},
});
}
25 changes: 25 additions & 0 deletions src/game/pointers/Pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,31 @@ namespace YimMenu
SendNetInfoToLobby = ptr.As<Functions::SendNetInfoToLobby>();
});

constexpr auto pedPoolPtrn = Pattern<"0F 28 F0 48 85 DB 74 56 8A 05 ? ? ? ? 84 C0 75 05">("PedPool");
scanner.Add(pedPoolPtrn, [this](PointerCalculator ptr) {
PedPool = ptr.Add(10).Rip().As<PoolEncryption*>();
});

constexpr auto objectPoolPtrn = Pattern<"3C 05 75 67">("ObjectPool");
scanner.Add(objectPoolPtrn, [this](PointerCalculator ptr) {
ObjectPool = ptr.Add(20).Rip().As<PoolEncryption*>();
});

constexpr auto vehiclePoolPtrn = Pattern<"48 83 EC 20 8A 05 ? ? ? ? 45 33 E4">("VehiclePool");
scanner.Add(vehiclePoolPtrn, [this](PointerCalculator ptr) {
VehiclePool = ptr.Add(6).Rip().As<PoolEncryption*>();
});

constexpr auto pickupPoolPtrn = Pattern<"0F 84 ? ? ? ? 8A 05 ? ? ? ? 48 85">("PickupPool");
scanner.Add(pickupPoolPtrn, [this](PointerCalculator ptr) {
PickupPool = ptr.Add(8).Rip().As<PoolEncryption*>();
});

constexpr auto fwScriptGuidCreateGuidPtrn = Pattern<"E8 ? ? ? ? B3 01 8B 15">("FwScriptGuidCreateGuid");
scanner.Add(fwScriptGuidCreateGuidPtrn, [this](PointerCalculator ptr) {
FwScriptGuidCreateGuid = ptr.Sub(141).As<uint32_t (*)(void*)>();
});

if (!scanner.Scan())
{
LOG(FATAL) << "Some patterns could not be found, unloading.";
Expand Down
7 changes: 7 additions & 0 deletions src/game/pointers/Pointers.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "game/rdr/GraphicsOptions.hpp"
#include "game/rdr/RenderingInfo.hpp"
#include <rage/pools.hpp>

#include <d3d12.h>
#include <dxgi1_4.h>
Expand Down Expand Up @@ -56,6 +57,12 @@ namespace YimMenu
Functions::GetLocalPed GetLocalPed;
Functions::SendNetInfoToLobby SendNetInfoToLobby;

PoolEncryption* PedPool;
PoolEncryption* ObjectPool;
PoolEncryption* VehiclePool;
PoolEncryption* PickupPool;
uint32_t (*FwScriptGuidCreateGuid)(void*);

// Security
PVOID SendMetric;
bool* RageSecurityInitialized;
Expand Down
143 changes: 143 additions & 0 deletions src/util/Helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include <rage/fwBasePool.hpp>
#include <script/types.hpp>
#include "game/pointers/Pointers.hpp"
#include "game/rdr/natives.hpp"

namespace YimMenu::Helpers
{
rage::fwBasePool* GetPedPool()
{
if (Pointers.PedPool->m_IsSet)
{
uint64_t x = _rotl64(Pointers.PedPool->m_Second, 30);
return reinterpret_cast<rage::fwBasePool*>(~_rotl64(_rotl64(x ^ Pointers.PedPool->m_First, ((x & 0xFF) & 31) + 3), 32));
}

return nullptr;
}

rage::fwBasePool* GetObjectPool()
{
if (Pointers.ObjectPool->m_IsSet)
{
uint64_t x = _rotl64(Pointers.ObjectPool->m_Second, 30);
return reinterpret_cast<rage::fwBasePool*>(~_rotl64(_rotl64(x ^ Pointers.ObjectPool->m_First, 32), ((x & 0xFF) & 31) + 2));
}

return nullptr;
}

rage::fwBasePool* GetVehiclePool()
{
if (Pointers.VehiclePool->m_IsSet)
{
uint64_t x = _rotl64(Pointers.VehiclePool->m_Second, 31);
return reinterpret_cast<rage::fwBasePool*>(~_rotl64(_rotl64(x ^ Pointers.VehiclePool->m_First, 32), ((x & 0xFF) & 31) + 4));
}

return nullptr;
}

rage::fwBasePool* GetPickupPool()
{
if (Pointers.PickupPool->m_IsSet)
{
uint64_t x = _rotl64(Pointers.PickupPool->m_Second, 30);
return reinterpret_cast<rage::fwBasePool*>(~_rotl64(_rotl64(Pointers.PickupPool->m_First ^ x, 32), ((x & 0xFF) & 31) + 2));
}

return nullptr;
}

inline std::vector<Ped> GetAllPeds()
{
std::vector<Ped> result;

if (const rage::fwBasePool* pool = GetPedPool())
{
for (uint32_t i = 0; i < pool->m_Size; i++)
{
if (pool->IsValid(i))
{
if (void* obj = pool->GetAt(i))
{
uint32_t ent = Pointers.FwScriptGuidCreateGuid(obj);
if (ENTITY::DOES_ENTITY_EXIST(ent))
result.push_back(ent);
}
}
}
}

return result;
}

inline std::vector<Object> GetAllObjects()
{
std::vector<Object> result;

if (const rage::fwBasePool* pool = GetObjectPool())
{
for (uint32_t i = 0; i < pool->m_Size; i++)
{
if (pool->IsValid(i))
{
if (void* obj = pool->GetAt(i))
{
uint32_t ent = Pointers.FwScriptGuidCreateGuid(obj);
if (ENTITY::DOES_ENTITY_EXIST(ent))
result.push_back(ent);
}
}
}
}

return result;
}

inline std::vector<Vehicle> GetAllVehicles()
{
std::vector<Vehicle> result;

if (const rage::fwBasePool* pool = GetVehiclePool())
{
for (uint32_t i = 0; i < pool->m_Size; i++)
{
if (pool->IsValid(i))
{
if (void* obj = pool->GetAt(i))
{
uint32_t ent = Pointers.FwScriptGuidCreateGuid(obj);
if (ENTITY::DOES_ENTITY_EXIST(ent))
result.push_back(ent);
}
}
}
}

return result;
}

inline std::vector<Pickup> GetAllPickups()
{
std::vector<Pickup> result;

if (const rage::fwBasePool* pool = GetPickupPool())
{
for (uint32_t i = 0; i < pool->m_Size; i++)
{
if (pool->IsValid(i))
{
if (void* obj = pool->GetAt(i))
{
uint32_t ent = Pointers.FwScriptGuidCreateGuid(obj);
if (ENTITY::DOES_ENTITY_EXIST(ent))
result.push_back(ent);
}
}
}
}

return result;
}
}

0 comments on commit f739bfc

Please sign in to comment.