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

Frontend Mach 1 #22

Merged
merged 8 commits into from
Sep 9, 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
80 changes: 40 additions & 40 deletions src/core/commands/HotkeySystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ namespace YimMenu

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

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

for (auto looped_command : looped_commands)
for (auto looped_command : LoopedCommands)
{
CommandLink link(true);
m_CommandHotkeys.insert(std::make_pair(looped_command->GetHash(), link));
Expand All @@ -31,11 +31,11 @@ namespace YimMenu
LOG(INFO) << "Registered " << m_CommandHotkeys.size() << " commands";
}

bool HotkeySystem::ListenAndApply(int& Hotkey, std::vector<int> blacklist)
bool HotkeySystem::ListenAndApply(int& Hotkey, std::vector<int> Blacklist)
{
static auto is_key_blacklisted = [blacklist](int key) -> bool {
for (auto key_ : blacklist)
if (key_ == key)
static auto IsKeyBlacklisted = [Blacklist](int Key) -> bool {
for (auto Key_ : Blacklist)
if (Key_ == Key)
return true;

return false;
Expand All @@ -44,7 +44,7 @@ namespace YimMenu
//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 && !is_key_blacklisted(i))
if ((GetKeyState(i) & 0x8000) && i != 1 && !IsKeyBlacklisted(i))
{
Hotkey = i;

Expand All @@ -55,76 +55,76 @@ namespace YimMenu
return false;
}
//Will return the keycode if there are no labels
std::string HotkeySystem::GetHotkeyLabel(int hotkey_modifier)
std::string HotkeySystem::GetHotkeyLabel(int HotkeyModifier)
{
char key_name[32];
GetKeyNameTextA(MapVirtualKey(hotkey_modifier, MAPVK_VK_TO_VSC) << 16, key_name, 32);
char KeyName[32];
GetKeyNameTextA(MapVirtualKey(HotkeyModifier, MAPVK_VK_TO_VSC) << 16, KeyName, 32);

if (std::string(key_name).empty())
strcpy(key_name, std::to_string(hotkey_modifier).data());
if (std::string(KeyName).empty())
strcpy(KeyName, std::to_string(HotkeyModifier).data());

return key_name;
return KeyName;
}

//Meant to be called in a loop
void HotkeySystem::CreateHotkey(std::vector<int>& Hotkey)
{
static auto is_key_unique = [this](int key, std::vector<int> list) -> bool {
for (auto& key_ : list)
if (GetHotkeyLabel(key_) == GetHotkeyLabel(key))
static auto IsKeyUnique = [this](int Key, std::vector<int> List) -> bool {
for (auto& Key_ : List)
if (GetHotkeyLabel(Key_) == GetHotkeyLabel(Key))
return false;

return true;
};

int pressed_key = 0;
ListenAndApply(pressed_key, Hotkey);
int PressedKey = 0;
ListenAndApply(PressedKey, Hotkey);


if (pressed_key > 1)
if (PressedKey > 1)
{
if (is_key_unique(pressed_key, Hotkey))
if (IsKeyUnique(PressedKey, Hotkey))
{
Hotkey.push_back(pressed_key);
Hotkey.push_back(PressedKey);
}
}
}

void HotkeySystem::FeatureCommandsHotkeyLoop()
{
for (auto& [hash, link] : m_CommandHotkeys)
for (auto& [Hash, Link] : m_CommandHotkeys)
{
if (link.Hotkey.empty() || link.Listening)
if (Link.Hotkey.empty() || Link.Listening)
continue;

bool allkeyspressed = true;
bool AllKeysPressed = true;

for (auto hotkey_modifier : link.Hotkey)
for (auto HotkeyModifier : Link.Hotkey)
{
if (!(GetAsyncKeyState(hotkey_modifier) & 0x8000))
if (!(GetAsyncKeyState(HotkeyModifier) & 0x8000))
{
allkeyspressed = false;
AllKeysPressed = false;
}
}

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

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

LOG(INFO) << "Hotkey detected for looped command " << looped_command->GetName();
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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/features/Features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ namespace YimMenu

void FeatureLoop()
{
g_HotkeySystem.RegisterCommands();

while (true)
{
UpdateSelfVars();
Expand Down Expand Up @@ -60,6 +58,8 @@ namespace YimMenu
PAD::DISABLE_CONTROL_ACTION(0, (Hash)eNativeInputs::INPUT_VEH_DRIVE_LOOK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)eNativeInputs::INPUT_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)eNativeInputs::INPUT_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)eNativeInputs::INPUT_NEXT_WEAPON, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)eNativeInputs::INPUT_PREV_WEAPON, 1);
}

ScriptMgr::Yield();
Expand Down
25 changes: 25 additions & 0 deletions src/game/features/mount/KeepHorseAgitationLow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "core/commands/LoopedCommand.hpp"
#include "game/features/Features.hpp"
#include "game/rdr/Enums.hpp"
#include "game/rdr/Natives.hpp"

namespace YimMenu::Features
{
class KeepHorseAgitationLow : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
if (!ENTITY::DOES_ENTITY_EXIST(Self::Mount))
return;

auto agitation = PED::_GET_PED_MOTIVATION(Self::Mount,(int) eMotivationState::AGITATION_STATE, 0);

if (agitation > 0)
PED::_SET_PED_MOTIVATION(Self::Mount, (int)eMotivationState::AGITATION_STATE, 0, 0);
}
};

static KeepHorseAgitationLow _KeepHorseAgitationLow{"keephorseagitationlow", "Keep Horse Agitation Low", "Keeps your horse from getting agitated"};
}
1 change: 0 additions & 1 deletion src/game/features/self/ClearCrimes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace YimMenu::Features
LAW::CLEAR_PLAYER_PAST_CRIMES(Self::Id); // does nothing
LAW::CLEAR_BOUNTY(Self::Id);
LAW::SET_BOUNTY(Self::Id, 0); // does nothing
LAW::SET_PLAYER_TURNED_IN_BOUNTY_IN_REGION(Self::Id, 0xA7A3F0C3);
PLAYER::CLEAR_PLAYER_WANTED_LEVEL(Self::Id); // does nothing
LAW::CLEAR_WANTED_SCORE(Self::Id); // also does nothing

Expand Down
29 changes: 29 additions & 0 deletions src/game/features/self/InfiniteAmmo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "core/commands/LoopedCommand.hpp"
#include "game/features/Features.hpp"
#include "game/rdr/Enums.hpp"
#include "game/rdr/Natives.hpp"

namespace YimMenu::Features
{
class InfiniteAmmo : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
Hash current_weapon{};
int max_ammo{};

WEAPON::GET_CURRENT_PED_WEAPON(Self::PlayerPed, &current_weapon, false, false, false);
WEAPON::GET_MAX_AMMO(Self::PlayerPed, &max_ammo, current_weapon);

auto current_weapon_ammo_type = WEAPON::_GET_CURRENT_PED_WEAPON_AMMO_TYPE(Self::PlayerPed, WEAPON::_GET_PED_WEAPON_OBJECT(Self::PlayerPed, false));
auto current_ammo = WEAPON::GET_PED_AMMO_BY_TYPE(Self::PlayerPed, current_weapon_ammo_type);

if (current_ammo < max_ammo)
WEAPON::SET_PED_AMMO_BY_TYPE(Self::PlayerPed, current_weapon_ammo_type, max_ammo);
}
};

static InfiniteAmmo _InfiniteAmmo{"infiniteammo", "Infinite Ammo", "You will never run out of ammo"};
}
28 changes: 28 additions & 0 deletions src/game/features/self/InfiniteClip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "core/commands/LoopedCommand.hpp"
#include "game/features/Features.hpp"
#include "game/rdr/Enums.hpp"
#include "game/rdr/Natives.hpp"

namespace YimMenu::Features
{
//WEAPON::_SET_PED_INFINITE_AMMO_CLIP Changes too many things to be considered, such as granting all ammo types.
class InfiniteClip : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
Hash current_weapon = WEAPON::_GET_PED_CURRENT_HELD_WEAPON(Self::PlayerPed);
int current_clip_ammo{};

WEAPON::GET_AMMO_IN_CLIP(Self::PlayerPed, &current_clip_ammo, current_weapon);

auto clip_size = WEAPON::GET_WEAPON_CLIP_SIZE(current_weapon);

if (current_clip_ammo < clip_size)
WEAPON::_REFILL_AMMO_IN_CURRENT_PED_WEAPON(Self::PlayerPed);
}
};

static InfiniteClip _InfiniteClip{"infiniteclip", "Infinite Clip", "Have an endless clip in your gun"};
}
22 changes: 22 additions & 0 deletions src/game/features/self/KeepClean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "core/commands/LoopedCommand.hpp"
#include "game/features/Features.hpp"
#include "game/rdr/Enums.hpp"
#include "game/rdr/Natives.hpp"

namespace YimMenu::Features
{
class KeepClean : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
PED::_SET_PED_DAMAGE_CLEANLINESS(Self::PlayerPed, ePedDamageCleanliness::PED_DAMAGE_CLEANLINESS_PERFECT);
PED::CLEAR_PED_WETNESS(Self::PlayerPed);
PED::CLEAR_PED_ENV_DIRT(Self::PlayerPed);
PED::CLEAR_PED_BLOOD_DAMAGE(Self::PlayerPed);
}
};

static KeepClean _KeepClean{"keepclean", "Keep Clean", "Keeps your character from being dirty"};
}
2 changes: 1 addition & 1 deletion src/game/frontend/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace YimMenu
GUI::GUI() :
m_IsOpen(false)
{
Renderer::AddRendererCallBack(Menu::Main, -1);
Menu::Init();
Renderer::AddWindowProcedureCallback([this](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
GUI::WndProc(hwnd, msg, wparam, lparam);
});
Expand Down
41 changes: 41 additions & 0 deletions src/game/frontend/imguiwidgets/toggle/imgui_offset_rect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include "imgui.h"

// Helper: ImOffsetRect A set of offsets to apply to an ImRect.
struct IMGUI_API ImOffsetRect
{
union
{
float Offsets[4];

struct
{
float Top;
float Left;
float Bottom;
float Right;
};
};

constexpr ImOffsetRect() : Top(0.0f), Left(0.0f), Bottom(0.0f), Right(0.0f) {}
constexpr ImOffsetRect(const ImVec2& topLeft, const ImVec2& bottomRight) : ImOffsetRect(topLeft.y, topLeft.x, bottomRight.y, bottomRight.x) {}
constexpr ImOffsetRect(const ImVec4& v) : ImOffsetRect(v.x, v.y, v.z, v.w) {}
constexpr ImOffsetRect(float top, float left, float bottom, float right) : Top(top), Left(left), Bottom(bottom), Right(right) {}
constexpr ImOffsetRect(float all) : Top(all), Left(all), Bottom(all), Right(all) {}

ImVec2 GetSize() const { return ImVec2(Left + Right, Top + Bottom); }
float GetWidth() const { return Left + Right; }
float GetHeight() const { return Top + Bottom; }
float GetAverage() const { return (Top + Left + Bottom + Right) / 4.0f; }
ImOffsetRect MirrorHorizontally() const { return ImOffsetRect(Top, Right, Bottom, Left); }
ImOffsetRect MirrorVertically() const { return ImOffsetRect(Bottom, Left, Top, Right); }
ImOffsetRect Mirror() const { return ImOffsetRect(Bottom, Right, Top, Left); }
};

// Helpers: ImOffsetRect operators
IM_MSVC_RUNTIME_CHECKS_OFF
static inline ImOffsetRect operator+(const ImOffsetRect& lhs, const ImOffsetRect& rhs) { return ImOffsetRect(lhs.Top + rhs.Top, lhs.Left + rhs.Left, lhs.Bottom + rhs.Bottom, lhs.Right + rhs.Right); }
static inline ImOffsetRect operator-(const ImOffsetRect& lhs, const ImOffsetRect& rhs) { return ImOffsetRect(lhs.Top - rhs.Top, lhs.Left - rhs.Left, lhs.Bottom - rhs.Bottom, lhs.Right - rhs.Right); }
static inline ImOffsetRect operator*(const ImOffsetRect& lhs, const ImOffsetRect& rhs) { return ImOffsetRect(lhs.Top * rhs.Top, lhs.Left * rhs.Left, lhs.Bottom * rhs.Bottom, lhs.Right * rhs.Right); }
IM_MSVC_RUNTIME_CHECKS_RESTORE
Loading