Skip to content

Commit

Permalink
Basic online compatibility and a lot of other stuff 2 (#36)
Browse files Browse the repository at this point in the history
* feat(invoker): add an invoker

* feat(debug): add entrypoint dumper

* finishing touches

* feat(settings): add settings

* feat(anticheat_bypass): hook SendMetric

* feat(menu): basic online support

* feat(vc): add voice chat override

* feat(gui): GUI refactor

* fix: fix hotkeys

* feat(protections): add a basic remote TP protection (untested)

* fix: rewrite gadget protection

* fix: don't zero out entity ptr

* feat(protections): basic sync protections

* feat(protections): improve protections

* fix(renderer): add font support for Vulkan renderer

* feat(protections): improve protections

* feat: more protections

* feat(players): add a player service

* finishing touches

* fix merge

* fix: code review fixes

* Added tp to waypoint

* Notification service & some features

* Added expiry bar to notifications

* feat(protections): add an object model mismatch check

* Merge Marcezsa's patch

* Changed minisubmenu highlights

* Readded teleport util files

* Added half working spectate

* Fixed spectate

---------

Co-authored-by: maybegreat48 <email@hostname>
  • Loading branch information
DayibBaba and maybegreat48 authored Oct 13, 2023
1 parent 19e3121 commit d64971b
Show file tree
Hide file tree
Showing 130 changed files with 5,079 additions and 750 deletions.
9 changes: 7 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@
"unordered_set": "cpp",
"valarray": "cpp",
"variant": "cpp",
"xtree": "cpp"
"xtree": "cpp",
"codecvt": "cpp",
"coroutine": "cpp",
"resumable": "cpp",
"stack": "cpp"
},
"C_Cpp.default.configurationProvider": "maxmitti.cmake-tools-fork"
"C_Cpp.default.configurationProvider": "maxmitti.cmake-tools-fork",
"C_Cpp.errorSquiggles": "disabled"
}
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ target_include_directories(${PROJECT_NAME} PRIVATE
"${SRC_DIR}"
"${imgui_SOURCE_DIR}"
"${minhook_SOURCE_DIR}/include"
"${minhook_SOURCE_DIR}/src/hde"
"${rdr_classes_SOURCE_DIR}"
"${vulkan_SOURCE_DIR}/include"
)

message(STATUS "Setting up linked libraries")
target_link_libraries(${PROJECT_NAME} PRIVATE AsyncLogger imgui minhook nlohmann_json::nlohmann_json "${DEPS_DIR}/vulkan-1.lib")
target_link_libraries(${PROJECT_NAME} PRIVATE AsyncLogger imgui minhook nlohmann_json::nlohmann_json dbghelp "${DEPS_DIR}/vulkan-1.lib")
2 changes: 1 addition & 1 deletion cmake/rdr-classes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
rdr_classes
GIT_REPOSITORY https://github.com/YimMenu/RDR-Classes.git
GIT_TAG 6bf009fae77419a9a1e249ddb711987422cf9822
GIT_TAG 0132075d1c6a88066ce6f6225f168a49e76a51a3
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
1 change: 1 addition & 0 deletions src/common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

#include <AsyncLogger/Logger.hpp>
#include <MinHook.h>
Expand Down
25 changes: 23 additions & 2 deletions src/core/commands/BoolCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "BoolCommand.hpp"
#include "game/backend/FiberPool.hpp" // TODO: game import in core

namespace YimMenu
{
Expand All @@ -12,6 +13,16 @@ namespace YimMenu
SetState(!m_State);
}

void BoolCommand::SaveState(nlohmann::json& value)
{
value = m_State;
}

void BoolCommand::LoadState(nlohmann::json& value)
{
m_State = value;
}

bool BoolCommand::GetState()
{
return m_State;
Expand All @@ -20,10 +31,20 @@ namespace YimMenu
void BoolCommand::SetState(bool state)
{
if (state && !m_State)
OnEnable();
FiberPool::Push([this] {
OnEnable();
});
else if (!state && m_State)
OnDisable();
FiberPool::Push([this] {
OnDisable();
});

m_State = state;
MarkDirty();
}

void BoolCommand::Shutdown()
{
OnDisable();
}
}
3 changes: 3 additions & 0 deletions src/core/commands/BoolCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ namespace YimMenu
virtual void OnEnable(){};
virtual void OnDisable(){};
virtual void OnCall() override;
virtual void SaveState(nlohmann::json& value) override;
virtual void LoadState(nlohmann::json& value) override;

bool m_State = false;

public:
BoolCommand(std::string name, std::string label, std::string description);
bool GetState();
void SetState(bool state);
void Shutdown();
};
}
5 changes: 5 additions & 0 deletions src/core/commands/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ namespace YimMenu
{
OnCall();
}

void Command::MarkDirty()
{
Commands::MarkDirty();
}
}
5 changes: 4 additions & 1 deletion src/core/commands/Command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ namespace YimMenu

protected:
virtual void OnCall() = 0;

void MarkDirty();

public:
Command(std::string name, std::string label, std::string description, int num_args = 0);
void Call();

virtual void SaveState(nlohmann::json& value){};
virtual void LoadState(nlohmann::json& value){};

const std::string& GetName()
{
return m_Name;
Expand Down
32 changes: 32 additions & 0 deletions src/core/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace YimMenu
{
Commands::Commands() :
IStateSerializer("commands")
{
}

void Commands::AddCommandImpl(Command* command)
{
m_Commands.insert({command->GetHash(), command});
Expand All @@ -27,4 +32,31 @@ namespace YimMenu
return it->second;
return nullptr;
}

void Commands::SaveStateImpl(nlohmann::json& state)
{
for (auto& command : m_Commands)
{
if (!state.contains(command.second->GetName()))
state[command.second->GetName()] = nlohmann::json::object();

command.second->SaveState(state[command.second->GetName()]);
}
}

void Commands::LoadStateImpl(nlohmann::json& state)
{
for (auto& command : m_Commands)
{
if (state.contains(command.second->GetName()))
command.second->LoadState(state[command.second->GetName()]);
}
}

void Commands::ShutdownImpl()
{
for (auto& command : m_LoopedCommands)
if (command->GetState())
command->Shutdown();
}
}
19 changes: 17 additions & 2 deletions src/core/commands/Commands.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#pragma once
#include "util/Joaat.hpp"
#include "core/settings/IStateSerializer.hpp"

namespace YimMenu
{
class Command;
class LoopedCommand;

class Commands
class Commands :
private IStateSerializer
{
private:
std::unordered_map<joaat_t, Command*> m_Commands;
std::vector<LoopedCommand*> m_LoopedCommands;
Commands(){};
Commands();

public:
static void AddCommand(Command* command)
Expand Down Expand Up @@ -46,11 +48,24 @@ namespace YimMenu
return GetInstance().m_LoopedCommands;
}

static void MarkDirty()
{
GetInstance().MarkStateDirty();
}

static void Shutdown()
{
GetInstance().ShutdownImpl();
}

private:
void AddCommandImpl(Command* command);
void AddLoopedCommandImpl(LoopedCommand* command);
void RunLoopedCommandsImpl();
Command* GetCommandImpl(joaat_t hash);
virtual void SaveStateImpl(nlohmann::json& state) override;
virtual void LoadStateImpl(nlohmann::json& state) override;
void ShutdownImpl();

static Commands& GetInstance()
{
Expand Down
69 changes: 38 additions & 31 deletions src/core/commands/HotkeySystem.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
#include "HotkeySystem.hpp"

#include "game/rdr/Natives.hpp"
#include "game/rdr/Natives.hpp" // TODO: game import in core
#include "game/backend/ScriptMgr.hpp"
#include "Commands.hpp"
#include "LoopedCommand.hpp"

// TODO: hotkeys

// TODO: serialization isn't stable

namespace YimMenu
{
HotkeySystem::HotkeySystem() :
IStateSerializer("hotkeys")
{
}

void HotkeySystem::RegisterCommands()
{
auto Commands = Commands::GetCommands();
auto LoopedCommands = Commands::GetLoopedCommands();

for (auto [Hash, Command] : Commands)
{
CommandLink link(false);
CommandLink link;
m_CommandHotkeys.insert(std::make_pair(Command->GetHash(), link));
}

for (auto looped_command : LoopedCommands)
{
CommandLink link(true);
m_CommandHotkeys.insert(std::make_pair(looped_command->GetHash(), link));
}

LOG(INFO) << "Registered " << m_CommandHotkeys.size() << " commands";
}

Expand All @@ -41,7 +37,7 @@ namespace YimMenu
return false;
};

//VK_OEM_CLEAR Is about the limit in terms of virtual key codes
// VK_OEM_CLEAR Is about the limit in terms of virtual key codes
for (int i = 0; i < VK_OEM_CLEAR; i++)
{
if ((GetKeyState(i) & 0x8000) && i != 1 && !IsKeyBlacklisted(i))
Expand All @@ -54,7 +50,8 @@ namespace YimMenu

return false;
}
//Will return the keycode if there are no labels

// Will return the keycode if there are no labels
std::string HotkeySystem::GetHotkeyLabel(int HotkeyModifier)
{
char KeyName[32];
Expand All @@ -66,7 +63,7 @@ namespace YimMenu
return KeyName;
}

//Meant to be called in a loop
// Meant to be called in a loop
void HotkeySystem::CreateHotkey(std::vector<int>& Hotkey)
{
static auto IsKeyUnique = [this](int Key, std::vector<int> List) -> bool {
Expand All @@ -88,6 +85,8 @@ namespace YimMenu
Hotkey.push_back(PressedKey);
}
}

MarkStateDirty();
}

void HotkeySystem::FeatureCommandsHotkeyLoop()
Expand All @@ -109,27 +108,35 @@ namespace YimMenu

if (AllKeysPressed && GetForegroundWindow() == Pointers.Hwnd)
{
if (Link.Looped)
{
auto LoopedCommand_ = Commands::GetCommand<LoopedCommand>(Hash);

if (LoopedCommand_)
LoopedCommand_->SetState(!LoopedCommand_->GetState());

LOG(INFO) << "Hotkey detected for looped command " << LoopedCommand_->GetName();
}
else
auto Command = Commands::GetCommand(Hash);
if (Command)
{
auto Command = Commands::GetCommand(Hash);
if (Command)
{
Command->Call();
LOG(INFO) << "Hotkey detected for command " << Command->GetName();
}
Command->Call();
LOG(INFO) << "Hotkey detected for command " << Command->GetName();
}

ScriptMgr::Yield(100ms);
}
}
}

void HotkeySystem::SaveStateImpl(nlohmann::json& state)
{
for (auto& hotkey : m_CommandHotkeys)
{
if (!hotkey.second.Hotkey.empty())
{
state[std::to_string(hotkey.first).data()] = hotkey.second.Hotkey;
}
}
}

void HotkeySystem::LoadStateImpl(nlohmann::json& state)
{
for (auto& [key, value] : state.items())
{
if (m_CommandHotkeys.contains(std::atoi(key.data())))
m_CommandHotkeys[std::atoi(key.data())].Hotkey = value.get<std::vector<int>>();
}
}
}
Loading

0 comments on commit d64971b

Please sign in to comment.