From f739bfcb6d430c0a2511704fd7e247c67f61fbd9 Mon Sep 17 00:00:00 2001 From: tyackman <38179522+tyackman@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:09:27 -0500 Subject: [PATCH] Pools and Context Menu Additions (#147) Added Pools to go with the new RDR-Classes and change the context menu to use the pools. --- src/game/frontend/ContextMenu.cpp | 15 ++- src/game/frontend/ContextMenus.hpp | 8 ++ src/game/pointers/Pointers.cpp | 25 +++++ src/game/pointers/Pointers.hpp | 7 ++ src/util/Helpers.hpp | 143 +++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 src/util/Helpers.hpp diff --git a/src/game/frontend/ContextMenu.cpp b/src/game/frontend/ContextMenu.cpp index 07a9530c..2aec08a7 100644 --- a/src/game/frontend/ContextMenu.cpp +++ b/src/game/frontend/ContextMenu.cpp @@ -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 { @@ -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; @@ -47,6 +47,15 @@ namespace YimMenu } } + if (includePeds) + { + for (Ped ped : Helpers::GetAllPeds()) + { + if (ped.IsValid() || ped.GetPointer()) + updateClosestEntity(ped.GetHandle()); + } + } + return closestHandle; } @@ -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) diff --git a/src/game/frontend/ContextMenus.hpp b/src/game/frontend/ContextMenus.hpp index e97fbb69..ad142d44 100644 --- a/src/game/frontend/ContextMenus.hpp +++ b/src/game/frontend/ContextMenus.hpp @@ -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); + }}, }); } \ No newline at end of file diff --git a/src/game/pointers/Pointers.cpp b/src/game/pointers/Pointers.cpp index 70447e90..29065a9b 100644 --- a/src/game/pointers/Pointers.cpp +++ b/src/game/pointers/Pointers.cpp @@ -268,6 +268,31 @@ namespace YimMenu SendNetInfoToLobby = ptr.As(); }); + 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(); + }); + + constexpr auto objectPoolPtrn = Pattern<"3C 05 75 67">("ObjectPool"); + scanner.Add(objectPoolPtrn, [this](PointerCalculator ptr) { + ObjectPool = ptr.Add(20).Rip().As(); + }); + + 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(); + }); + + constexpr auto pickupPoolPtrn = Pattern<"0F 84 ? ? ? ? 8A 05 ? ? ? ? 48 85">("PickupPool"); + scanner.Add(pickupPoolPtrn, [this](PointerCalculator ptr) { + PickupPool = ptr.Add(8).Rip().As(); + }); + + constexpr auto fwScriptGuidCreateGuidPtrn = Pattern<"E8 ? ? ? ? B3 01 8B 15">("FwScriptGuidCreateGuid"); + scanner.Add(fwScriptGuidCreateGuidPtrn, [this](PointerCalculator ptr) { + FwScriptGuidCreateGuid = ptr.Sub(141).As(); + }); + if (!scanner.Scan()) { LOG(FATAL) << "Some patterns could not be found, unloading."; diff --git a/src/game/pointers/Pointers.hpp b/src/game/pointers/Pointers.hpp index 6f199d20..b42534ca 100644 --- a/src/game/pointers/Pointers.hpp +++ b/src/game/pointers/Pointers.hpp @@ -1,6 +1,7 @@ #pragma once #include "game/rdr/GraphicsOptions.hpp" #include "game/rdr/RenderingInfo.hpp" +#include #include #include @@ -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; diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp new file mode 100644 index 00000000..618e7367 --- /dev/null +++ b/src/util/Helpers.hpp @@ -0,0 +1,143 @@ +#include +#include