Skip to content

Commit

Permalink
New Kick, Features, and More (#210)
Browse files Browse the repository at this point in the history
New Kick - ICE Kick
Logger Improvements
Color Commands
Node and Vtable Hooks
Improved Protections
Enhancements, Improvements, and Various Refactors
  • Loading branch information
Rxann authored Sep 8, 2024
1 parent f33722e commit f98fec8
Show file tree
Hide file tree
Showing 118 changed files with 4,055 additions and 1,100 deletions.
6 changes: 3 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ AlignConsecutiveAssignments: 'true'
AlignEscapedNewlines: Left
AlignOperands: 'false'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllArgumentsOnNextLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: None
AllowShortFunctionsOnASingleLine: 'true'
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AlwaysBreakAfterReturnType: None
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 fe55483ceaaae7b14fad984a495b07272679bd5d
GIT_TAG a61459d3b100408f736f32046ed2545dc729e617
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(RDR-Classes)
Expand Down
6 changes: 6 additions & 0 deletions src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ using namespace al;

namespace YimMenu
{
const inline auto SYNC = std::make_shared<al::LogStream>("SYNC");
const inline auto NET_EVENT = std::make_shared<al::LogStream>("NET_EVENT");
const inline auto NETWORK = std::make_shared<al::LogStream>("NETWORK");
const inline auto GAME = std::make_shared<al::LogStream>("GAME");
const inline auto MENU = std::make_shared<al::LogStream>("MENU");

using namespace std::chrono_literals;
using namespace std::string_literals;

Expand Down
2 changes: 2 additions & 0 deletions src/core/commands/BoolCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "BoolCommand.hpp"
#include "game/backend/FiberPool.hpp" // TODO: game import in core
#include "Commands.hpp"

namespace YimMenu
{
BoolCommand::BoolCommand(std::string name, std::string label, std::string description, bool def_value) :
Command(name, label, description, 0),
m_State(def_value)
{
Commands::AddBoolCommand(this);
}

void BoolCommand::OnCall()
Expand Down
4 changes: 2 additions & 2 deletions src/core/commands/BoolCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace YimMenu
class BoolCommand : public Command
{
protected:
virtual void OnEnable(){};
virtual void OnDisable(){};
virtual void OnEnable() {};
virtual void OnDisable() {};
virtual void OnCall() override;
virtual void SaveState(nlohmann::json& value) override;
virtual void LoadState(nlohmann::json& value) override;
Expand Down
46 changes: 46 additions & 0 deletions src/core/commands/ColorCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "ColorCommand.hpp"
#include "game/backend/FiberPool.hpp" // TODO: game import in core

namespace YimMenu
{
void ColorCommand::OnCall()
{
}

void ColorCommand::SaveState(nlohmann::json& value)
{
value = {m_ColorState.x, m_ColorState.y, m_ColorState.z, m_ColorState.w};
}

void ColorCommand::LoadState(nlohmann::json& value)
{
if (value.is_array() && value.size() == 4)
{
m_ColorState = ImVec4(value[0], value[1], value[2], value[3]);
}
else
{
m_ColorState = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
}
}

ColorCommand::ColorCommand(std::string name, std::string label, std::string description, ImVec4 color) :
Command(name, label, description, 0),
m_ColorState(color)
{
}

ImVec4 ColorCommand::GetState()
{
return m_ColorState;
}

void ColorCommand::SetColorState(ImVec4 state)
{
FiberPool::Push([this] {
OnChange();
});
m_ColorState = state;
MarkDirty();
}
}
22 changes: 22 additions & 0 deletions src/core/commands/ColorCommand.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include "Command.hpp"
#include "imgui.h"

namespace YimMenu
{
class ColorCommand : public Command
{
protected:
virtual void OnChange(){};
virtual void OnCall() override;
virtual void SaveState(nlohmann::json& value) override;
virtual void LoadState(nlohmann::json& value) override;

ImVec4 m_ColorState = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);

public:
ColorCommand(std::string name, std::string label, std::string description, ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImVec4 GetState();
void SetColorState(ImVec4 state);
};
}
9 changes: 7 additions & 2 deletions src/core/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ namespace YimMenu
m_Commands.insert({command->GetHash(), command});
}

void Commands::AddBoolCommandImpl(BoolCommand* command)
{
m_BoolCommands.push_back(command);
}

void Commands::AddLoopedCommandImpl(LoopedCommand* command)
{
m_LoopedCommands.push_back(command);
}

void Commands::EnableLoopedCommandsImpl()
void Commands::EnableBoolCommandsImpl()
{
for (auto& command : m_LoopedCommands)
for (auto& command : m_BoolCommands)
if (command->GetState())
command->Initialize();
}
Expand Down
15 changes: 11 additions & 4 deletions src/core/commands/Commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ namespace YimMenu
{
class Command;
class LoopedCommand;
class BoolCommand;

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

public:
Expand All @@ -21,6 +23,11 @@ namespace YimMenu
GetInstance().AddCommandImpl(command);
}

static void AddBoolCommand(BoolCommand* command)
{
GetInstance().AddBoolCommandImpl(command);
}

static void AddLoopedCommand(LoopedCommand* command)
{
GetInstance().AddLoopedCommandImpl(command);
Expand All @@ -31,10 +38,9 @@ namespace YimMenu
GetInstance().RunLoopedCommandsImpl();
}

// TODO: what about bool commands?
static void EnableLoopedCommands()
static void EnableBoolCommands()
{
GetInstance().EnableLoopedCommandsImpl();
GetInstance().EnableBoolCommandsImpl();
}

template<typename T = Command>
Expand Down Expand Up @@ -65,8 +71,9 @@ namespace YimMenu

private:
void AddCommandImpl(Command* command);
void AddBoolCommandImpl(BoolCommand* command);
void AddLoopedCommandImpl(LoopedCommand* command);
void EnableLoopedCommandsImpl();
void EnableBoolCommandsImpl();
void RunLoopedCommandsImpl();
Command* GetCommandImpl(joaat_t hash);
virtual void SaveStateImpl(nlohmann::json& state) override;
Expand Down
2 changes: 1 addition & 1 deletion src/core/commands/HotkeySystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace YimMenu
}
}

if (AllKeysPressed && GetForegroundWindow() == Pointers.Hwnd && std::chrono::system_clock::now() - m_LastHotkeyTriggerTime > 100ms)
if (AllKeysPressed && GetForegroundWindow() == *Pointers.Hwnd && std::chrono::system_clock::now() - m_LastHotkeyTriggerTime > 100ms)
{
auto Command = Commands::GetCommand(Hash);
if (Command)
Expand Down
43 changes: 22 additions & 21 deletions src/core/frontend/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "core/logger/LogHelper.hpp"
#include "game/backend/FiberPool.hpp" // TODO: game import in core
#include "util/Joaat.hpp"

#include <mutex>

Expand All @@ -13,24 +14,30 @@ namespace YimMenu
if (title.empty() || message.empty())
return {};

auto message_id = Joaat(title + message);

auto exists = std::find_if(m_Notifications.begin(), m_Notifications.end(), [&](auto& notification) {
return notification.second.GetIdentifier() == std::string(title + message);
return notification.second.m_Identifier == message_id;
});

if (exists != m_Notifications.end())
{
exists->second.m_CreatedOn = std::chrono::system_clock::now();
return {};
}

Notification notification{};
notification.m_Title = title;
notification.m_Message = message;
notification.m_Type = type;
notification.m_created_on = std::chrono::system_clock::now();
notification.m_CreatedOn = std::chrono::system_clock::now();
notification.m_Duration = duration;
notification.m_Identifier = message_id;

if (context_function)
{
notification.m_context_function = context_function;
notification.m_context_function_name = context_function_name.empty() ? "Context Function" : context_function_name;
notification.m_ContextFunc = context_function;
notification.m_ContextFuncName = context_function_name.empty() ? "Context Function" : context_function_name;
}

std::lock_guard<std::mutex> lock(m_mutex);
Expand All @@ -44,9 +51,9 @@ namespace YimMenu
std::lock_guard<std::mutex> lock(m_mutex);
for (auto& [id, n] : m_Notifications)
{
if (id == notification.GetIdentifier())
if (n.m_Identifier == notification.m_Identifier)
{
n.erasing = true;
n.m_Erasing = true;
return true;
}
}
Expand All @@ -63,18 +70,15 @@ namespace YimMenu
ImGui::SetNextWindowSize(cardSize, ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(x_pos + notification.m_AnimationOffset, y_pos + 10), ImGuiCond_Always);

std::string windowTitle = "Notification " + std::to_string(position + 1);
ImGui::Begin(windowTitle.c_str(), nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
std::string windowTitle = std::to_string(position);
ImGui::Begin(windowTitle.c_str(), nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoFocusOnAppearing);

auto timeElapsed =
(float)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - notification.m_created_on)
.count();
auto timeElapsed = (float)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - notification.m_CreatedOn).count();

auto depletionProgress = 1.0f - (timeElapsed / (float)notification.m_Duration);

ImGui::ProgressBar(depletionProgress, ImVec2(-1, 3.5f), "");

auto style = ImGui::GetStyle();
// TODO: Add icon for type instead of colored text
if (notification.m_Type == NotificationType::Info)
{
Expand Down Expand Up @@ -103,12 +107,12 @@ namespace YimMenu

ImGui::TextWrapped("%s", notification.m_Message.c_str());

if (notification.m_context_function)
if (notification.m_ContextFunc)
{
ImGui::Spacing();
if (ImGui::Selectable(notification.m_context_function_name.c_str()))
if (ImGui::Selectable(notification.m_ContextFuncName.c_str()))
FiberPool::Push([notification] {
notification.m_context_function();
notification.m_ContextFunc();
});
}

Expand All @@ -126,7 +130,7 @@ namespace YimMenu
{
DrawNotification(notification, position);

if (!notification.erasing)
if (!notification.m_Erasing)
{
if (notification.m_AnimationOffset < 0)
notification.m_AnimationOffset += m_CardAnimationSpeed;
Expand All @@ -143,10 +147,7 @@ namespace YimMenu
}


if ((float)std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - notification.m_created_on)
.count()
>= notification.m_Duration)
if ((float)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - notification.m_CreatedOn).count() >= notification.m_Duration)
keys_to_erase.push_back(id);

position++;
Expand All @@ -158,4 +159,4 @@ namespace YimMenu
m_Notifications.erase(key);
}
}
}
}
14 changes: 5 additions & 9 deletions src/core/frontend/Notifications.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ namespace YimMenu
NotificationType m_Type;
std::string m_Title;
std::string m_Message;
std::chrono::time_point<std::chrono::system_clock> m_created_on;
std::chrono::time_point<std::chrono::system_clock> m_CreatedOn;
int m_Duration;
std::function<void()> m_context_function;
std::string m_context_function_name;
std::function<void()> m_ContextFunc;
std::string m_ContextFuncName;
float m_AnimationOffset = -m_CardSizeX;
bool erasing = false;

std::string GetIdentifier()
{
return std::string(m_Title).append(m_Message);
}
bool m_Erasing = false;
std::uint32_t m_Identifier;
};

class Notifications
Expand Down
5 changes: 5 additions & 0 deletions src/core/frontend/manager/Category.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace YimMenu
m_Items.push_back(std::move(item));
}

void PrependItem(std::shared_ptr<UIItem>&& item)
{
m_Items.insert(m_Items.begin(), std::move(item));
}

void Draw();
int GetLength();

Expand Down
2 changes: 1 addition & 1 deletion src/core/hooking/DetourHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace YimMenu

if (const auto result = MH_CreateHook(m_TargetFunc, m_DetourFunc, &m_OriginalFunc); result != MH_OK)
{
throw std::runtime_error("Failed to create hook!");
throw std::runtime_error(std::format("Failed to create hook '{}' at 0x{:X} (error: {})", name, uintptr_t(m_TargetFunc), MH_StatusToString(result)));
}
}

Expand Down
Loading

0 comments on commit f98fec8

Please sign in to comment.