Skip to content

Commit

Permalink
Protections, Updates, and More (#199)
Browse files Browse the repository at this point in the history
Bumped to current ImGui version
Call Hooks
Voice Chat Spoofing
New Protections
Log Backups
Blip Spoofing
General Optimizations
General Improvements
Updated Net Events list
and More
  • Loading branch information
Rxann authored Aug 10, 2024
1 parent c615522 commit f33722e
Show file tree
Hide file tree
Showing 101 changed files with 2,800 additions and 630 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20.x)

project(HorseMenu VERSION 0.0.1 DESCRIPTION "A new base using new C++ features optimised for speed and ease of use")
project(HorseMenu VERSION 0.0.1 DESCRIPTION "HorseMenu, a beta-stage mod menu for Red Dead Redemption 2 and Red Dead Online, inspired by YimMenu, that protects against crashes and enhances your experience.")

# libs
include(cmake/vulkan.cmake)
Expand Down
4 changes: 2 additions & 2 deletions cmake/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ message(STATUS "Setting up ${LIB_NAME}")

FetchContent_Declare(
${LIB_NAME}
GIT_REPOSITORY https://github.com/Spyral-Org/imgui.git
GIT_TAG 44d98bfd6d12caee43bea49fda71c8313c3e57e7
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG 8cc6eee295871bc8852c12372860a50b950d3f56
GIT_PROGRESS TRUE
)

Expand Down
2 changes: 1 addition & 1 deletion cmake/rdr-classes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ message(STATUS "RDR-Classes")
FetchContent_Declare(
RDR-Classes
GIT_REPOSITORY https://github.com/YimMenu/RDR-Classes.git
GIT_TAG ec19493aedc48e3fe0860342484058e48204dda2
GIT_TAG fe55483ceaaae7b14fad984a495b07272679bd5d
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(RDR-Classes)
Expand Down
1 change: 1 addition & 0 deletions src/common.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#define IMGUI_DEFINE_MATH_OPERATORS

#include <AsyncLogger/Logger.hpp>
#include <MinHook.h>
Expand Down
3 changes: 1 addition & 2 deletions src/core/filemgr/BaseObj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace YimMenu
{
public:
BaseObj(const std::filesystem::path& path);

[[nodiscard]] bool Exists() const;
const std::filesystem::path& Path() const;

Expand All @@ -17,7 +16,7 @@ namespace YimMenu
}

protected:
const std::filesystem::path m_Path;
std::filesystem::path m_Path;

};
}
109 changes: 109 additions & 0 deletions src/core/hooking/CallHook.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once
#include "BaseHook.hpp"
#include "core/memory/PointerCalculator.hpp"

#include <MinHook.h>
#include <string_view>

namespace YimMenu
{
class CallHookMemory
{
PointerCalculator m_Memory;
int m_Offset;

public:
CallHookMemory()
{
m_Memory = VirtualAlloc((void*)((uintptr_t)GetModuleHandle(0) + 0x20000000), 1024, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
m_Offset = 0;
}

~CallHookMemory()
{
VirtualFree(m_Memory.As<void*>(), 0, MEM_RELEASE);
m_Memory = nullptr;
}

void* AllocateJumpSeq(void* func)
{
m_Offset = m_Offset + ((16 - (m_Offset % 16)) % 16); // align

*m_Memory.Add(m_Offset).As<int16_t*>() = 0xB848;
*m_Memory.Add(m_Offset).Add(2).As<void**>() = func;
*m_Memory.Add(m_Offset).Add(10).As<int16_t*>() = 0xE0FF;

m_Offset += 12;

return m_Memory.Add(m_Offset).Sub(12).As<void*>();
}
};

inline CallHookMemory g_CallHookMemory;

template<typename T = int*>
class CallHook : public BaseHook
{
private:
void* m_DetourFunc;
void* m_TargetFunc;
void* m_OriginalFunc;
char m_OriginalBytes[5];
char m_PatchedBytes[5];

public:
CallHook(const std::string_view name, void* target, T detour);
virtual ~CallHook();

bool Enable() override;
bool Disable() override;
T Original() const;
};

template<typename T>
inline CallHook<T>::CallHook(const std::string_view name, void* target, T detour) :
BaseHook(name),
m_DetourFunc(detour),
m_TargetFunc(target)
{
auto seq = g_CallHookMemory.AllocateJumpSeq(detour);
m_PatchedBytes[0] = 0xE8;
*(int32_t*)&m_PatchedBytes[1] = (int32_t)((uint64_t)seq - (uint64_t)target - 5);
memcpy(m_OriginalBytes, target, 5);
m_OriginalFunc = PointerCalculator(target).Add(1).Rip().As<void*>();
}

template<typename T>
inline CallHook<T>::~CallHook()
{
Disable();
}

template<typename T>
inline bool CallHook<T>::Enable()
{
if (m_Enabled)
return false;

memcpy(m_TargetFunc, m_PatchedBytes, 5);
m_Enabled = true;
return true;
}

template<typename T>
inline bool CallHook<T>::Disable()
{
if (!m_Enabled)
return false;

memcpy(m_TargetFunc, m_OriginalBytes, 5);
m_Enabled = false;
return true;
}

template<typename T>
inline T CallHook<T>::Original() const
{
return reinterpret_cast<T>(m_OriginalFunc);
}
}
11 changes: 8 additions & 3 deletions src/core/hooking/Hooking.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Hooking.hpp"

#include "BaseHook.hpp"
#include "CallHook.hpp"
#include "DetourHook.hpp"
#include "VMTHook.hpp"
#include "core/memory/ModuleMgr.hpp"
Expand Down Expand Up @@ -50,11 +51,14 @@ namespace YimMenu
BaseHook::Add<Hooks::Protections::SerializeServerRPC>(new DetourHook("SerializeServerRPC", Pointers.SerializeServerRPC, Hooks::Protections::SerializeServerRPC));
BaseHook::Add<Hooks::Protections::ReceiveServerMessage>(new DetourHook("ReceiveServerMessage", Pointers.ReceiveServerMessage, Hooks::Protections::ReceiveServerMessage));
BaseHook::Add<Hooks::Protections::ReceiveArrayUpdate>(new DetourHook("ReceiveArrayUpdate", Pointers.ReceiveArrayUpdate, Hooks::Protections::ReceiveArrayUpdate));

BaseHook::Add<Hooks::Protections::CreatePoolItem>(new DetourHook("CreatePoolItem", Pointers.CreatePoolItem, Hooks::Protections::CreatePoolItem));

BaseHook::Add<Hooks::Protections::HandleCloneRemove>(new DetourHook("HandleCloneRemove", Pointers.HandleCloneRemove, Hooks::Protections::HandleCloneRemove));
BaseHook::Add<Hooks::Protections::PackCloneCreate>(new DetourHook("PackCloneCreate", Pointers.PackCloneCreate, Hooks::Protections::PackCloneCreate));

BaseHook::Add<Hooks::Voice::EnumerateAudioDevices>(new DetourHook("EnumerateAudioDevices", Pointers.EnumerateAudioDevices, Hooks::Voice::EnumerateAudioDevices));
BaseHook::Add<Hooks::Voice::DirectSoundCaptureCreate>(new DetourHook("DirectSoundCaptureCreate", Pointers.DirectSoundCaptureCreate, Hooks::Voice::DirectSoundCaptureCreate));
BaseHook::Add<Hooks::Voice::SendVoicePacket>(new CallHook("SendVoicePacket", Pointers.SendVoicePacket, Hooks::Voice::SendVoicePacket));
BaseHook::Add<Hooks::Voice::WriteVoiceInfoData>(new DetourHook("WriteVoiceInfoData", Pointers.WriteVoiceInfoData, Hooks::Voice::WriteVoiceInfoData));

BaseHook::Add<Hooks::Misc::ThrowFatalError>(new DetourHook("ThrowFatalError", Pointers.ThrowFatalError, Hooks::Misc::ThrowFatalError));
BaseHook::Add<Hooks::Misc::IsAnimSceneInScope>(new DetourHook("IsAnimSceneInScope", Pointers.IsAnimSceneInScope, Hooks::Misc::IsAnimSceneInScope));
Expand All @@ -66,10 +70,11 @@ namespace YimMenu

BaseHook::Add<Hooks::Info::HandleSessionEvent>(new DetourHook("HandleSessionEvent", Pointers.HandleSessionEvent, Hooks::Info::HandleSessionEvent));

BaseHook::Add<Hooks::Spoofing::WritePlayerHealthData>(new DetourHook("WritePlayerHealthData", Pointers.WritePlayerHealthData, Hooks::Spoofing::WritePlayerHealthData));
// BaseHook::Add<Hooks::Spoofing::WritePlayerHealthData>(new DetourHook("WritePlayerHealthData", Pointers.WritePlayerHealthData, Hooks::Spoofing::WritePlayerHealthData));
BaseHook::Add<Hooks::Spoofing::SendNetInfoToLobby>(new DetourHook("SendNetInfoToLobby", Pointers.SendNetInfoToLobby, Hooks::Spoofing::SendNetInfoToLobby));
BaseHook::Add<Hooks::Spoofing::WriteVPMData>(new DetourHook("WriteVehicleProximityMigrationData", Pointers.WriteVPMData, Hooks::Spoofing::WriteVPMData));
BaseHook::Add<Hooks::Spoofing::GetDiscriminator>(new DetourHook("GetDiscriminator", Pointers.GetDiscriminator, Hooks::Spoofing::GetDiscriminator));
BaseHook::Add<Hooks::Spoofing::WriteNodeData>(new DetourHook("WriteNodeData", Pointers.WriteNodeData, Hooks::Spoofing::WriteNodeData));

BaseHook::Add<Hooks::Toxic::BroadcastNetArray>(new DetourHook("BroadcastNetArray", Pointers.BroadcastNetArray, Hooks::Toxic::BroadcastNetArray));
}
Expand Down
35 changes: 32 additions & 3 deletions src/core/logger/LogHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#include "LogHelper.hpp"

#include "LogSink.hpp"

#include "core/filemgr/FileMgr.hpp"

namespace YimMenu
{
template<typename TP>
static std::time_t to_time_t(TP tp)
{
using namespace std::chrono;
auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
return system_clock::to_time_t(sctp);
}

void LogHelper::Destroy()
{
GetInstance().DestroyImpl();
}

bool LogHelper::Init(const std::string_view consoleName, const std::filesystem::path& file, const bool attachConsole)
bool LogHelper::Init(const std::string_view consoleName, File file, const bool attachConsole)
{
return GetInstance().InitImpl(consoleName, file, attachConsole);
}
Expand All @@ -31,7 +40,7 @@ namespace YimMenu
FreeConsole();
}

bool LogHelper::InitImpl(const std::string_view consoleName, const std::filesystem::path& file, const bool attachConsole)
bool LogHelper::InitImpl(const std::string_view consoleName, File file, const bool attachConsole)
{
m_ConsoleTitle = consoleName;
m_File = file;
Expand Down Expand Up @@ -59,6 +68,7 @@ namespace YimMenu
}
}

AttemptCreateBackup();
OpenOutputStreams();

Logger::Init();
Expand Down Expand Up @@ -108,4 +118,23 @@ namespace YimMenu
m_ConsoleOut.open("CONOUT$", std::ios_base::out | std::ios_base::app);
m_FileOut.open(m_File, std::ios::out | std::ios::trunc);
}

void LogHelper::AttemptCreateBackup()
{
if (m_File.Exists())
{
auto file_time = std::filesystem::last_write_time(m_File.Path());
auto time_t = to_time_t(file_time);
auto local_time = std::localtime(&time_t);

m_File.Move(std::format("./backup/{:0>2}-{:0>2}-{}-{:0>2}-{:0>2}-{:0>2}_{}",
local_time->tm_mon + 1,
local_time->tm_mday,
local_time->tm_year + 1900,
local_time->tm_hour,
local_time->tm_min,
local_time->tm_sec,
m_File.Path().filename().string().c_str()));
}
}
}
10 changes: 7 additions & 3 deletions src/core/logger/LogHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <fstream>
#include <iostream>

#include "core/filemgr/File.hpp"

namespace YimMenu
{
#define ADD_COLOR_TO_STREAM(color) "\x1b[" << int(color) << "m"
Expand All @@ -19,7 +21,7 @@ namespace YimMenu
LogHelper& operator=(LogHelper&&) = delete;

static void Destroy();
static bool Init(const std::string_view consoleName, const std::filesystem::path& file, const bool attachConsole = true);
static bool Init(const std::string_view consoleName, File file, const bool attachConsole = true);

static void ToggleConsole(bool toggle);

Expand All @@ -33,13 +35,15 @@ namespace YimMenu
}

void DestroyImpl();
bool InitImpl(const std::string_view consoleName, const std::filesystem::path& file, const bool attachConsole);
bool InitImpl(const std::string_view consoleName, File file, const bool attachConsole);

void ToggleConsoleImpl(bool toggle);

void CloseOutputStreams();
void OpenOutputStreams();

void AttemptCreateBackup();

private:
bool m_AttachConsole;
bool m_DidConsoleExist;
Expand All @@ -49,7 +53,7 @@ namespace YimMenu
HANDLE m_ConsoleHandle;

std::ofstream m_ConsoleOut;
std::filesystem::path m_File;
File m_File = std::filesystem::path();
std::ofstream m_FileOut;
};
}
28 changes: 10 additions & 18 deletions src/core/memory/BytePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,28 @@

namespace YimMenu
{
BytePatch::~BytePatch()
{
Restore();
}

void BytePatch::Apply() const
BytePatch::~BytePatch()
{
std::copy_n(m_Patch.get(), m_Size, reinterpret_cast<std::byte*>(m_Address));
Restore();
}

void BytePatch::Restore() const
void BytePatch::Apply() const
{
std::copy_n(m_Original.get(), m_Size, reinterpret_cast<std::byte*>(m_Address));
std::copy_n(m_Patch.get(), m_Size, reinterpret_cast<std::byte*>(m_Address));
}

void BytePatch::Remove() const
void BytePatch::Restore() const
{
if (const auto it = std::find(m_Patches.begin(), m_Patches.end(), this); it != m_Patches.end())
{
m_Patches.erase(it);
}
std::copy_n(m_Original.get(), m_Size, reinterpret_cast<std::byte*>(m_Address));
}

void BytePatch::RestoreAll()
bool operator==(const std::unique_ptr<BytePatch>& a, const BytePatch* b)
{
m_Patches.clear();
return a->m_Address == b->m_Address;
}

bool operator==(const std::unique_ptr<BytePatch>& a, const BytePatch* b)
BytePatch::operator bool()
{
return a->m_Address == b->m_Address;
return m_Active;
}
}
Loading

0 comments on commit f33722e

Please sign in to comment.