Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native invoker #11

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(cmake/async-logger.cmake)
include(cmake/imgui.cmake)
include(cmake/json.cmake)
include(cmake/minhook.cmake)
include(cmake/rdr-classes.cmake)

# source
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
Expand All @@ -25,7 +26,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
"${SRC_DIR}"
"${imgui_SOURCE_DIR}"
"${minhook_SOURCE_DIR}/include"
"${gtav_classes_SOURCE_DIR}"
"${rdr_classes_SOURCE_DIR}"
)

message(STATUS "Setting up linked libraries")
Expand Down
14 changes: 0 additions & 14 deletions cmake/gtav-classes.cmake

This file was deleted.

14 changes: 14 additions & 0 deletions cmake/rdr-classes.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include(FetchContent)

FetchContent_Declare(
rdr_classes
GIT_REPOSITORY https://github.com/YimMenu/RDR-Classes.git
GIT_TAG a2a74e151a1ade7683be07e966b47aaa00a28848
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)
message("RDR-Classes")
if(NOT rdr_classes_POPULATED)
FetchContent_Populate(rdr_classes)
endif()
4 changes: 2 additions & 2 deletions src/core/renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace YimMenu
return false;
}

m_FrameContext.reserve(m_SwapChainDesc.BufferCount);
m_FrameContext.resize(m_SwapChainDesc.BufferCount);

D3D12_DESCRIPTOR_HEAP_DESC DescriptorDesc{ D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, m_SwapChainDesc.BufferCount, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE };
if (const auto result = m_Device->CreateDescriptorHeap(&DescriptorDesc, __uuidof(ID3D12DescriptorHeap), (void**)m_DescriptorHeap.GetAddressOf()); result < 0)
Expand All @@ -102,7 +102,7 @@ namespace YimMenu
return false;
}

for (size_t i{}; i != m_SwapChainDesc.BufferCount; ++i)
for (size_t i{}; i < m_SwapChainDesc.BufferCount; ++i)
{
m_FrameContext[i].CommandAllocator = m_CommandAllocator.Get();
}
Expand Down
36 changes: 36 additions & 0 deletions src/game/frontend/menu/Menu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "Menu.hpp"

#include "core/memory/ModuleMgr.hpp"
#include "game/pointers/Pointers.hpp"
#include "util/Joaat.hpp"
#include "game/rdr/natives.hpp"
#include "core/filemgr/FileMgr.hpp"

namespace YimMenu
{
void Menu::Main()
Expand All @@ -9,6 +15,36 @@ namespace YimMenu

if (ImGui::Begin("Test"))
{
if (ImGui::Button("Suicide"))
{
auto player_ped = PLAYER::PLAYER_PED_ID();
ENTITY::SET_ENTITY_HEALTH(player_ped, 0, 0);
}

if (ImGui::Button("Get Coords"))
{
auto coords = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), false, false);

LOG(INFO) << coords.x << "x\t" << coords.y << "y\t" << coords.z << "z";
}

if (ImGui::Button("Dump Entrypoints"))
{
DWORD64 base_address = (DWORD64)GetModuleHandleA(0);

const auto file_path = FileMgr::GetProjectFile("./entrypoints.txt");
auto file = std::ofstream(file_path.Path(), std::ios::out | std::ios::trunc);

for (auto& entry : g_Crossmap)
{
auto address = Pointers.GetNativeHandler(entry);

file << std::hex << std::uppercase << "0x" << entry << " : RDR2.exe + 0x" << (DWORD64)address - base_address << std::endl;
}

file.close();
}

if (ImGui::Button("Unload"))
g_Running = false;
}
Expand Down
12 changes: 11 additions & 1 deletion src/game/pointers/Pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace YimMenu
const auto rdr2 = ModuleMgr.Get("RDR2.exe"_J);
if (!rdr2)
{
LOG(FATAL) << "Could not find " << rdr2->Name() << ", is this RDR2?";
LOG(FATAL) << "Could not find RDR2.exe, is this RDR2?";

return false;
}
Expand All @@ -39,6 +39,16 @@ namespace YimMenu
WndProc = ptr.As<PVOID>();
});

constexpr auto getNativeHandlerPtrn = Pattern<"E8 ? ? ? ? 42 8B 9C FE">("GetNativeHandler");
scanner.Add(getNativeHandlerPtrn, [this](PointerCalculator ptr) {
GetNativeHandler = ptr.Add(1).Rip().As<Functions::GetNativeHandler>();
});

constexpr auto fixVectorsPtrn = Pattern<"8B 41 18 4C 8B C1 85">("FixVectors");
scanner.Add(fixVectorsPtrn, [this](PointerCalculator ptr) {
FixVectors = ptr.As<Functions::FixVectors>();
});

if (!scanner.Scan())
{
LOG(FATAL) << "Some patterns could not be found, unloading.";
Expand Down
5 changes: 5 additions & 0 deletions src/game/pointers/Pointers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#include <dxgi1_4.h>
#include <d3d12.h>
#include "game/rdr/RenderingInfo.hpp"
#include <script/scrNativeHandler.hpp>

namespace YimMenu
{
namespace Functions
{
using GetRendererInfo = RenderingInfo*(*)();
using GetNativeHandler = rage::scrNativeHandler (*)(rage::scrNativeHash hash);
using FixVectors = void (*)(rage::scrNativeCallContext* call_ctx);
}

struct PointerData
Expand All @@ -20,6 +23,8 @@ namespace YimMenu
std::int64_t** ScriptGlobals;
void* NativeRegistrationTable;
PVOID WndProc;
Functions::GetNativeHandler GetNativeHandler;
Functions::FixVectors FixVectors;
};

struct Pointers : PointerData
Expand Down
Loading