first commit
This commit is contained in:
commit
fafeee709f
17 files changed
+1312
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
build/
|
||||||
|
.vs/
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[submodule "vendor/minhook"]
|
||||||
|
path = vendor/minhook
|
||||||
|
url = https://github.com/TsudaKageyu/minhook
|
||||||
|
[submodule "vendor/imgui"]
|
||||||
|
path = vendor/imgui
|
||||||
|
url = https://github.com/ocornut/imgui
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{70af9aae-5221-4f03-a21f-c09f3ab61e31}</ProjectGuid>
|
||||||
|
<RootNamespace>amnesia</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<OutDir>$(SolutionDir)client\build\debug\</OutDir>
|
||||||
|
<IntDir>$(SolutionDir)client\build\debug\trash\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<OutDir>$(SolutionDir)client\build\release\</OutDir>
|
||||||
|
<IntDir>$(SolutionDir)client\build\release\trash\</IntDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;AMNESIA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;AMNESIA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;AMNESIA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>
|
||||||
|
</PrecompiledHeaderFile>
|
||||||
|
<AdditionalIncludeDirectories>$(SolutionDir)client\vendor\minhook\include;$(SolutionDir)client\vendor\imgui;$(SolutionDir)client\vendor\imgui\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;AMNESIA_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>
|
||||||
|
</PrecompiledHeaderFile>
|
||||||
|
<AdditionalIncludeDirectories>$(SolutionDir)client\vendor\minhook\include;$(SolutionDir)client\vendor\imgui;$(SolutionDir)client\vendor\imgui\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\vendor\imgui\backends\imgui_impl_dx11.cpp" />
|
||||||
|
<ClCompile Include="..\vendor\imgui\backends\imgui_impl_win32.cpp" />
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui.cpp" />
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui_draw.cpp" />
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui_tables.cpp" />
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui_widgets.cpp" />
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\buffer.c" />
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\hde\hde64.c" />
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\hook.c" />
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\trampoline.c" />
|
||||||
|
<ClCompile Include="main.cc" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="gui\clickgui.h" />
|
||||||
|
<ClInclude Include="gui\theme.h" />
|
||||||
|
<ClInclude Include="input.h" />
|
||||||
|
<ClInclude Include="modules\crosshair.h" />
|
||||||
|
<ClInclude Include="modules\fps_counter.h" />
|
||||||
|
<ClInclude Include="modules\keystrokes.h" />
|
||||||
|
<ClInclude Include="modules\module.h" />
|
||||||
|
<ClInclude Include="modules\module_manager.h" />
|
||||||
|
<ClInclude Include="modules\setting.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="src">
|
||||||
|
<UniqueIdentifier>{dc71201b-8065-4386-a454-7b7b3be2d41d}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="vendor">
|
||||||
|
<UniqueIdentifier>{2b7f4636-7954-4d03-b1a4-868978764606}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="vendor\minhook">
|
||||||
|
<UniqueIdentifier>{e1a33679-7e3d-4771-b84c-31279d2b750d}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="vendor\imgui">
|
||||||
|
<UniqueIdentifier>{b48810d3-a64b-46ee-857a-c6414295a729}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="vendor\imgui\backends">
|
||||||
|
<UniqueIdentifier>{ad1701e7-78f3-4112-bf2c-50367cf2d5b1}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\buffer.c">
|
||||||
|
<Filter>vendor\minhook</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\hook.c">
|
||||||
|
<Filter>vendor\minhook</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\trampoline.c">
|
||||||
|
<Filter>vendor\minhook</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\minhook\src\hde\hde64.c">
|
||||||
|
<Filter>vendor\minhook</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui.cpp">
|
||||||
|
<Filter>vendor\imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui_draw.cpp">
|
||||||
|
<Filter>vendor\imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui_tables.cpp">
|
||||||
|
<Filter>vendor\imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\imgui\imgui_widgets.cpp">
|
||||||
|
<Filter>vendor\imgui</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\imgui\backends\imgui_impl_dx11.cpp">
|
||||||
|
<Filter>vendor\imgui\backends</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\vendor\imgui\backends\imgui_impl_win32.cpp">
|
||||||
|
<Filter>vendor\imgui\backends</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="main.cc">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="modules\module.h" />
|
||||||
|
<ClInclude Include="modules\module_manager.h" />
|
||||||
|
<ClInclude Include="modules\fps_counter.h" />
|
||||||
|
<ClInclude Include="modules\keystrokes.h" />
|
||||||
|
<ClInclude Include="input.h" />
|
||||||
|
<ClInclude Include="gui\clickgui.h" />
|
||||||
|
<ClInclude Include="gui\theme.h" />
|
||||||
|
<ClInclude Include="modules\setting.h" />
|
||||||
|
<ClInclude Include="modules\crosshair.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ShowAllFiles>true</ShowAllFiles>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,340 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cfloat>
|
||||||
|
#include <string>
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "theme.h"
|
||||||
|
#include "../input.h"
|
||||||
|
#include "../modules/module_manager.h"
|
||||||
|
|
||||||
|
#if __has_include("../font_data.h")
|
||||||
|
#include "../font_data.h"
|
||||||
|
#define AMNESIA_HAS_FONT 1
|
||||||
|
#else
|
||||||
|
#define AMNESIA_HAS_FONT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline std::string key_name(int vk) {
|
||||||
|
if (vk == 0) return "None";
|
||||||
|
|
||||||
|
LONG lparam = (LONG)(MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_VSC) << 16);
|
||||||
|
switch (vk) { // extended keys need bit 24 set to get the right name
|
||||||
|
case VK_INSERT: case VK_DELETE: case VK_HOME: case VK_END:
|
||||||
|
case VK_PRIOR: case VK_NEXT:
|
||||||
|
case VK_LEFT: case VK_RIGHT: case VK_UP: case VK_DOWN:
|
||||||
|
case VK_RCONTROL: case VK_RMENU:
|
||||||
|
lparam |= (1 << 24);
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[64] = {};
|
||||||
|
if (GetKeyNameTextA(lparam, buf, sizeof(buf)) > 0) return buf;
|
||||||
|
return "Key " + std::to_string(vk);
|
||||||
|
}
|
||||||
|
|
||||||
|
class clickgui {
|
||||||
|
public:
|
||||||
|
// after ImGui::CreateContext(), before the backends are initialized
|
||||||
|
void init() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.IniFilename = nullptr; // never write imgui.ini into the game's folder
|
||||||
|
io.LogFilename = nullptr;
|
||||||
|
load_fonts();
|
||||||
|
theme::apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
// once per frame, after ImGui::NewFrame()
|
||||||
|
void update() {
|
||||||
|
const bool menu_down = is_key_down(k_menu_key);
|
||||||
|
if (menu_down && !menu_key_was_down_) set_open(!g_menu_open);
|
||||||
|
menu_key_was_down_ = menu_down;
|
||||||
|
|
||||||
|
const bool esc_down = is_key_down(VK_ESCAPE);
|
||||||
|
if (esc_down && !esc_was_down_ && g_menu_open && !any_binding()) set_open(false);
|
||||||
|
esc_was_down_ = esc_down;
|
||||||
|
|
||||||
|
open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// dim + title; call BEFORE modules().render() so the HUD stays above the dimming
|
||||||
|
void draw_backdrop() {
|
||||||
|
if (open_t_ <= 0.01f) return;
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
|
|
||||||
|
dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize,
|
||||||
|
theme::u32(theme::with_alpha(theme::bg_dark(), 0.6f * open_t_)));
|
||||||
|
|
||||||
|
const char* title = "AMNESIA";
|
||||||
|
const float tw = ImGui::CalcTextSize(title).x * k_title_size / ImGui::GetFontSize();
|
||||||
|
const ImVec2 tp(io.DisplaySize.x * 0.5f - tw * 0.5f, 18.f);
|
||||||
|
dl->AddText(font_title_, k_title_size, ImVec2(tp.x + 3.f, tp.y + 3.f),
|
||||||
|
theme::u32(theme::with_alpha(theme::bg_dark(), open_t_)), title);
|
||||||
|
dl->AddText(font_title_, k_title_size, tp,
|
||||||
|
theme::u32(theme::with_alpha(theme::accent_bright(), open_t_)), title);
|
||||||
|
|
||||||
|
const char* hint = "Right-click a module for settings | drag HUD elements to move them";
|
||||||
|
const float hw = ImGui::CalcTextSize(hint).x;
|
||||||
|
dl->AddText(ImVec2(io.DisplaySize.x * 0.5f - hw * 0.5f, tp.y + k_title_size + 8.f),
|
||||||
|
theme::u32(theme::with_alpha(theme::fg_muted(), open_t_)), hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the panels and the HUD drag editor
|
||||||
|
void draw() {
|
||||||
|
if (open_t_ <= 0.01f) return;
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, open_t_);
|
||||||
|
|
||||||
|
float x = 40.f;
|
||||||
|
for (category cat : k_categories) {
|
||||||
|
if (!has_modules(cat)) continue;
|
||||||
|
draw_panel(cat, x);
|
||||||
|
x += k_panel_w + 20.f;
|
||||||
|
}
|
||||||
|
draw_hud_editor();
|
||||||
|
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr int k_menu_key = VK_RSHIFT;
|
||||||
|
static constexpr float k_panel_w = 230.f;
|
||||||
|
static constexpr float k_main_size = 18.f;
|
||||||
|
static constexpr float k_title_size = 32.f;
|
||||||
|
static constexpr category k_categories[] = { category::hud, category::visual, category::utility };
|
||||||
|
|
||||||
|
ImFont* font_main_ = nullptr;
|
||||||
|
ImFont* font_title_ = nullptr;
|
||||||
|
float open_t_ = 0.f;
|
||||||
|
bool menu_key_was_down_ = false;
|
||||||
|
bool esc_was_down_ = false;
|
||||||
|
|
||||||
|
void load_fonts() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
#if AMNESIA_HAS_FONT
|
||||||
|
ImFontConfig cfg;
|
||||||
|
cfg.FontDataOwnedByAtlas = false; // the data lives in our DLL, ImGui must not free it
|
||||||
|
font_main_ = io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, k_main_size, &cfg);
|
||||||
|
font_title_ = io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, k_title_size, &cfg);
|
||||||
|
#endif
|
||||||
|
if (!font_main_) { // no font_data.h (or it failed): fall back to ImGui's built-in
|
||||||
|
font_main_ = io.Fonts->AddFontDefault();
|
||||||
|
font_title_ = font_main_;
|
||||||
|
}
|
||||||
|
io.FontDefault = font_main_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_open(bool open) {
|
||||||
|
if (open == g_menu_open) return;
|
||||||
|
g_menu_open = open;
|
||||||
|
ImGui::GetIO().MouseDrawCursor = open; // ImGui draws its own cursor while open
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
input::release_cursor();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
input::restore_cursor();
|
||||||
|
for (auto& m : modules().all()) m->ui.binding = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool any_binding() const {
|
||||||
|
for (auto& m : modules().all())
|
||||||
|
if (m->ui.binding) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has_modules(category cat) const {
|
||||||
|
for (auto& m : modules().all())
|
||||||
|
if (m->cat() == cat) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- panels ----------------
|
||||||
|
|
||||||
|
void draw_panel(category cat, float default_x) {
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(default_x, 110.f), ImGuiCond_FirstUseEver);
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(k_panel_w, 0.f), ImGuiCond_Always); // fixed width, auto height
|
||||||
|
|
||||||
|
ImGuiWindowFlags flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||||
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse |
|
||||||
|
ImGuiWindowFlags_NoSavedSettings;
|
||||||
|
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks
|
||||||
|
|
||||||
|
if (ImGui::Begin(category_name(cat), nullptr, flags)) {
|
||||||
|
for (auto& m : modules().all())
|
||||||
|
if (m->cat() == cat) draw_module(*m);
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_module(module& m) {
|
||||||
|
ImGui::PushID(&m);
|
||||||
|
|
||||||
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
|
const float w = ImGui::GetContentRegionAvail().x;
|
||||||
|
const float h = ImGui::GetFontSize() + 14.f;
|
||||||
|
const ImVec2 p = ImGui::GetCursorScreenPos();
|
||||||
|
|
||||||
|
ImGui::InvisibleButton("##row", ImVec2(w, h));
|
||||||
|
const bool hovered = ImGui::IsItemHovered();
|
||||||
|
const bool active = ImGui::IsItemActive();
|
||||||
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) m.toggle();
|
||||||
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||||
|
m.ui.expanded = !m.ui.expanded;
|
||||||
|
m.ui.binding = false;
|
||||||
|
}
|
||||||
|
if (hovered)
|
||||||
|
ImGui::SetTooltip("%s\n\nLMB: toggle | RMB: settings", m.description().c_str());
|
||||||
|
|
||||||
|
const float dt = ImGui::GetIO().DeltaTime;
|
||||||
|
m.ui.hover_t = theme::approach(m.ui.hover_t, hovered ? 1.f : 0.f, dt * 16.f);
|
||||||
|
m.ui.enable_t = theme::approach(m.ui.enable_t, m.enabled() ? 1.f : 0.f, dt * 12.f);
|
||||||
|
m.ui.expand_t = theme::approach(m.ui.expand_t, m.ui.expanded ? 1.f : 0.f, dt * 12.f);
|
||||||
|
|
||||||
|
ImVec4 base = theme::mix(theme::bg_raised(), theme::accent(), m.ui.enable_t);
|
||||||
|
base = theme::shade(base, 1.f + 0.15f * m.ui.hover_t);
|
||||||
|
theme::bevel_box(dl, p, ImVec2(p.x + w, p.y + h), base, active);
|
||||||
|
|
||||||
|
const ImVec4 text_col = theme::mix(theme::fg(), theme::bg_dark(), m.ui.enable_t);
|
||||||
|
const float text_y = p.y + (h - ImGui::GetFontSize()) * 0.5f;
|
||||||
|
theme::shadow_text(dl, ImVec2(p.x + 8.f, text_y), text_col, m.name().c_str());
|
||||||
|
|
||||||
|
if (m.toggle_key()) {
|
||||||
|
const std::string k = "[" + key_name(m.toggle_key()) + "]";
|
||||||
|
const float kw = ImGui::CalcTextSize(k.c_str()).x;
|
||||||
|
const ImVec4 kcol = theme::mix(theme::fg_muted(), theme::bg_dark(), m.ui.enable_t * 0.6f);
|
||||||
|
dl->AddText(ImVec2(p.x + w - kw - 8.f, text_y), theme::u32(kcol), k.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m.ui.expand_t > 0.01f) {
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * m.ui.expand_t);
|
||||||
|
ImGui::Indent(6.f);
|
||||||
|
draw_bind_button(m);
|
||||||
|
for (auto& s : m.settings()) draw_setting(s);
|
||||||
|
ImGui::Unindent(6.f);
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
ImGui::Dummy(ImVec2(0.f, 2.f));
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_bind_button(module& m) {
|
||||||
|
std::string label;
|
||||||
|
if (m.ui.binding) label = "Bind: press a key...";
|
||||||
|
else label = "Bind: [" + key_name(m.toggle_key()) + "]";
|
||||||
|
|
||||||
|
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) m.ui.binding = !m.ui.binding;
|
||||||
|
|
||||||
|
if (m.ui.binding) {
|
||||||
|
for (int vk = 0x08; vk < 0xFF; ++vk) { // starts above the mouse buttons
|
||||||
|
if (is_key_down(vk)) {
|
||||||
|
m.set_toggle_key(vk == VK_ESCAPE ? 0 : vk); // Esc clears the bind
|
||||||
|
m.ui.binding = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_setting(setting& s) {
|
||||||
|
ImGui::PushID(&s);
|
||||||
|
|
||||||
|
switch (s.type) {
|
||||||
|
case setting_type::toggle: {
|
||||||
|
const std::string label = s.name + ": " + (s.bool_value ? "ON" : "OFF");
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, s.bool_value ? theme::accent_bright() : theme::fg_muted());
|
||||||
|
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) s.bool_value = !s.bool_value;
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case setting_type::slider_float: {
|
||||||
|
const std::string fmt = s.name + ": %.2f";
|
||||||
|
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||||
|
ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, fmt.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case setting_type::slider_int: {
|
||||||
|
const std::string fmt = s.name + ": %d";
|
||||||
|
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||||
|
ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, fmt.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case setting_type::mode: {
|
||||||
|
if (!s.modes.empty()) {
|
||||||
|
if (s.int_value < 0 || s.int_value >= (int)s.modes.size()) s.int_value = 0;
|
||||||
|
const std::string label = s.name + ": " + s.modes[s.int_value];
|
||||||
|
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f)))
|
||||||
|
s.int_value = (s.int_value + 1) % (int)s.modes.size();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case setting_type::color: {
|
||||||
|
ImGui::ColorEdit4("##c", s.color,
|
||||||
|
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel |
|
||||||
|
ImGuiColorEditFlags_AlphaBar);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::TextUnformatted(s.name.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- HUD drag editor ----------------
|
||||||
|
|
||||||
|
void draw_hud_editor() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
for (auto& up : modules().all()) {
|
||||||
|
module& m = *up;
|
||||||
|
if (!m.enabled() || !m.is_hud()) continue;
|
||||||
|
|
||||||
|
const ImVec2 size = m.hud_size();
|
||||||
|
if (size.x <= 0.f || size.y <= 0.f) continue;
|
||||||
|
|
||||||
|
// keep it on screen
|
||||||
|
m.hud_pos.x = theme::clampf(m.hud_pos.x, 0.f, io.DisplaySize.x - size.x);
|
||||||
|
m.hud_pos.y = theme::clampf(m.hud_pos.y, 0.f, io.DisplaySize.y - size.y);
|
||||||
|
|
||||||
|
ImGui::SetNextWindowPos(m.hud_pos, ImGuiCond_Always);
|
||||||
|
ImGui::SetNextWindowSize(size, ImGuiCond_Always);
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
|
||||||
|
|
||||||
|
const std::string id = "##hud_" + m.name();
|
||||||
|
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||||
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar |
|
||||||
|
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings |
|
||||||
|
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoNav |
|
||||||
|
ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||||
|
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs;
|
||||||
|
|
||||||
|
if (ImGui::Begin(id.c_str(), nullptr, flags)) {
|
||||||
|
ImGui::InvisibleButton("##drag", size);
|
||||||
|
const bool hovered = ImGui::IsItemHovered();
|
||||||
|
const bool active = ImGui::IsItemActive();
|
||||||
|
|
||||||
|
if (active && ImGui::IsMouseDragging(ImGuiMouseButton_Left, 0.f)) {
|
||||||
|
m.hud_pos.x += io.MouseDelta.x;
|
||||||
|
m.hud_pos.y += io.MouseDelta.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ImVec4 col = (hovered || active) ? theme::accent_bright() : theme::accent_dark();
|
||||||
|
ImGui::GetForegroundDrawList()->AddRect(
|
||||||
|
m.hud_pos, ImVec2(m.hud_pos.x + size.x, m.hud_pos.y + size.y),
|
||||||
|
theme::u32(col), 0.f, 0, 2.f);
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleVar(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline clickgui& gui() {
|
||||||
|
static clickgui instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
+125
@@ -0,0 +1,125 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <utility>
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
namespace theme {
|
||||||
|
|
||||||
|
inline float clampf(float v, float lo, float hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
||||||
|
|
||||||
|
inline ImVec4 hex(unsigned int rgb, float a = 1.f) {
|
||||||
|
return ImVec4(((rgb >> 16) & 0xFF) / 255.f, ((rgb >> 8) & 0xFF) / 255.f, (rgb & 0xFF) / 255.f, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
// every color goes through the style alpha, so the whole menu fades together
|
||||||
|
inline ImU32 u32(const ImVec4& c) {
|
||||||
|
ImVec4 v = c;
|
||||||
|
v.w *= ImGui::GetStyle().Alpha;
|
||||||
|
return ImGui::ColorConvertFloat4ToU32(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ImVec4 with_alpha(ImVec4 c, float a) { c.w = a; return c; }
|
||||||
|
|
||||||
|
inline ImVec4 mix(const ImVec4& a, const ImVec4& b, float t) {
|
||||||
|
return ImVec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t,
|
||||||
|
a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ImVec4 shade(const ImVec4& c, float f) {
|
||||||
|
return ImVec4(clampf(c.x * f, 0.f, 1.f), clampf(c.y * f, 0.f, 1.f), clampf(c.z * f, 0.f, 1.f), c.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float approach(float v, float target, float rate) {
|
||||||
|
v += (target - v) * clampf(rate, 0.f, 1.f);
|
||||||
|
return (v - target < 0.001f && target - v < 0.001f) ? target : v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- "orphan" palette ----
|
||||||
|
inline ImVec4 bg_dark() { return hex(0x17141c); }
|
||||||
|
inline ImVec4 bg() { return hex(0x2b2632); }
|
||||||
|
inline ImVec4 bg_raised() { return hex(0x38313c); }
|
||||||
|
inline ImVec4 fg() { return hex(0xc9b5af); }
|
||||||
|
inline ImVec4 fg_muted() { return hex(0x8372a0); }
|
||||||
|
inline ImVec4 fg_dim() { return hex(0x625577); }
|
||||||
|
inline ImVec4 accent() { return hex(0x8c79a5); }
|
||||||
|
inline ImVec4 accent_dark() { return hex(0x74608e); }
|
||||||
|
inline ImVec4 accent_bright() { return hex(0xbfa5ea); }
|
||||||
|
inline ImVec4 border() { return hex(0x433a4f); }
|
||||||
|
|
||||||
|
// Minecraft-button look: flat fill, light top/left edge, dark bottom/right edge
|
||||||
|
inline void bevel_box(ImDrawList* dl, ImVec2 a, ImVec2 b, const ImVec4& base, bool pressed = false) {
|
||||||
|
const float t = 2.f;
|
||||||
|
ImVec4 hi = shade(base, 1.35f), lo = shade(base, 0.6f);
|
||||||
|
if (pressed) std::swap(hi, lo);
|
||||||
|
|
||||||
|
dl->AddRectFilled(a, b, u32(base));
|
||||||
|
dl->AddRectFilled(a, ImVec2(b.x, a.y + t), u32(hi));
|
||||||
|
dl->AddRectFilled(a, ImVec2(a.x + t, b.y), u32(hi));
|
||||||
|
dl->AddRectFilled(ImVec2(a.x, b.y - t), b, u32(lo));
|
||||||
|
dl->AddRectFilled(ImVec2(b.x - t, a.y), b, u32(lo));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minecraft-style drop shadow
|
||||||
|
inline void shadow_text(ImDrawList* dl, ImVec2 pos, const ImVec4& col, const char* text) {
|
||||||
|
dl->AddText(ImVec2(pos.x + 2.f, pos.y + 2.f), u32(with_alpha(bg_dark(), col.w)), text);
|
||||||
|
dl->AddText(pos, u32(col), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void apply() {
|
||||||
|
ImGuiStyle& s = ImGui::GetStyle();
|
||||||
|
|
||||||
|
s.WindowRounding = s.ChildRounding = s.FrameRounding = s.PopupRounding = 0.f;
|
||||||
|
s.ScrollbarRounding = s.GrabRounding = s.TabRounding = 0.f;
|
||||||
|
s.WindowBorderSize = 2.f;
|
||||||
|
s.ChildBorderSize = 1.f;
|
||||||
|
s.PopupBorderSize = 2.f;
|
||||||
|
s.FrameBorderSize = 1.f;
|
||||||
|
|
||||||
|
s.WindowPadding = ImVec2(6.f, 6.f);
|
||||||
|
s.FramePadding = ImVec2(8.f, 5.f);
|
||||||
|
s.ItemSpacing = ImVec2(6.f, 5.f);
|
||||||
|
s.WindowTitleAlign = ImVec2(0.5f, 0.5f);
|
||||||
|
s.GrabMinSize = 12.f;
|
||||||
|
s.ScrollbarSize = 10.f;
|
||||||
|
|
||||||
|
s.AntiAliasedLines = false; // crisp, blocky edges
|
||||||
|
s.AntiAliasedFill = false;
|
||||||
|
|
||||||
|
ImVec4* c = s.Colors;
|
||||||
|
const ImVec4 clear(0.f, 0.f, 0.f, 0.f);
|
||||||
|
|
||||||
|
c[ImGuiCol_Text] = fg();
|
||||||
|
c[ImGuiCol_TextDisabled] = fg_dim();
|
||||||
|
c[ImGuiCol_WindowBg] = with_alpha(bg(), 0.96f);
|
||||||
|
c[ImGuiCol_ChildBg] = clear;
|
||||||
|
c[ImGuiCol_PopupBg] = with_alpha(bg_dark(), 0.98f);
|
||||||
|
c[ImGuiCol_Border] = bg_dark();
|
||||||
|
c[ImGuiCol_BorderShadow] = clear;
|
||||||
|
|
||||||
|
c[ImGuiCol_FrameBg] = bg_raised();
|
||||||
|
c[ImGuiCol_FrameBgHovered] = shade(bg_raised(), 1.25f);
|
||||||
|
c[ImGuiCol_FrameBgActive] = shade(bg_raised(), 1.45f);
|
||||||
|
|
||||||
|
c[ImGuiCol_TitleBg] = shade(accent_dark(), 0.75f);
|
||||||
|
c[ImGuiCol_TitleBgActive] = accent_dark();
|
||||||
|
c[ImGuiCol_TitleBgCollapsed] = shade(accent_dark(), 0.75f);
|
||||||
|
|
||||||
|
c[ImGuiCol_ScrollbarBg] = clear;
|
||||||
|
c[ImGuiCol_ScrollbarGrab] = border();
|
||||||
|
c[ImGuiCol_ScrollbarGrabHovered] = fg_dim();
|
||||||
|
c[ImGuiCol_ScrollbarGrabActive] = fg_muted();
|
||||||
|
|
||||||
|
c[ImGuiCol_CheckMark] = accent_bright();
|
||||||
|
c[ImGuiCol_SliderGrab] = accent();
|
||||||
|
c[ImGuiCol_SliderGrabActive] = accent_bright();
|
||||||
|
|
||||||
|
c[ImGuiCol_Button] = bg_raised();
|
||||||
|
c[ImGuiCol_ButtonHovered] = shade(bg_raised(), 1.3f);
|
||||||
|
c[ImGuiCol_ButtonActive] = accent_dark();
|
||||||
|
|
||||||
|
c[ImGuiCol_Header] = accent_dark();
|
||||||
|
c[ImGuiCol_HeaderHovered] = accent();
|
||||||
|
c[ImGuiCol_HeaderActive] = accent();
|
||||||
|
c[ImGuiCol_Separator] = border();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace theme
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include "MinHook.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_win32.h"
|
||||||
|
|
||||||
|
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
|
inline std::atomic<bool> g_menu_open{ false };
|
||||||
|
|
||||||
|
namespace input {
|
||||||
|
|
||||||
|
using set_cursor_pos_fn = BOOL(WINAPI*)(int, int);
|
||||||
|
using clip_cursor_fn = BOOL(WINAPI*)(const RECT*);
|
||||||
|
|
||||||
|
inline WNDPROC o_wnd_proc = nullptr;
|
||||||
|
inline HWND hooked_window = nullptr;
|
||||||
|
inline set_cursor_pos_fn o_set_cursor_pos = nullptr;
|
||||||
|
inline clip_cursor_fn o_clip_cursor = nullptr;
|
||||||
|
|
||||||
|
// the clip rect the game had before the menu opened, and anything it asked for while the menu was open
|
||||||
|
inline RECT saved_clip{};
|
||||||
|
inline RECT wanted_clip{};
|
||||||
|
inline bool wanted_set = false;
|
||||||
|
inline bool wanted_null = false;
|
||||||
|
|
||||||
|
// the game re-centers and clips the cursor while you play; both are ignored while the menu is open
|
||||||
|
inline BOOL WINAPI hk_set_cursor_pos(int x, int y) {
|
||||||
|
if (g_menu_open) return TRUE;
|
||||||
|
return o_set_cursor_pos(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline BOOL WINAPI hk_clip_cursor(const RECT* rect) {
|
||||||
|
if (g_menu_open) {
|
||||||
|
wanted_set = true;
|
||||||
|
wanted_null = (rect == nullptr);
|
||||||
|
if (rect) wanted_clip = *rect;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return o_clip_cursor(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void release_cursor() {
|
||||||
|
GetClipCursor(&saved_clip);
|
||||||
|
wanted_set = false;
|
||||||
|
if (o_clip_cursor) o_clip_cursor(nullptr); else ClipCursor(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void restore_cursor() {
|
||||||
|
clip_cursor_fn clip = o_clip_cursor ? o_clip_cursor : ClipCursor;
|
||||||
|
if (wanted_set) clip(wanted_null ? nullptr : &wanted_clip);
|
||||||
|
else clip(&saved_clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
// messages the game must not see while the menu is open
|
||||||
|
// (key-up and button-up are deliberately let through so nothing gets stuck held down)
|
||||||
|
inline bool should_block(UINT msg) {
|
||||||
|
switch (msg) {
|
||||||
|
case WM_MOUSEMOVE:
|
||||||
|
case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
|
||||||
|
case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK:
|
||||||
|
case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK:
|
||||||
|
case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK:
|
||||||
|
case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL:
|
||||||
|
case WM_INPUT:
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
case WM_CHAR:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||||
|
LRESULT handled = ImGui_ImplWin32_WndProcHandler(hwnd, msg, wp, lp); // ImGui always sees input
|
||||||
|
|
||||||
|
if (g_menu_open) {
|
||||||
|
if (handled) return handled;
|
||||||
|
if (should_block(msg)) {
|
||||||
|
if (msg == WM_INPUT) return DefWindowProcW(hwnd, msg, wp, lp); // raw input needs cleanup
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CallWindowProcW(o_wnd_proc, hwnd, msg, wp, lp);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool install(HWND hwnd) {
|
||||||
|
if (!hwnd || !IsWindow(hwnd)) return false;
|
||||||
|
|
||||||
|
hooked_window = hwnd;
|
||||||
|
o_wnd_proc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)wnd_proc);
|
||||||
|
|
||||||
|
MH_CreateHookApi(L"user32", "SetCursorPos", (LPVOID)&hk_set_cursor_pos, (LPVOID*)&o_set_cursor_pos);
|
||||||
|
MH_CreateHookApi(L"user32", "ClipCursor", (LPVOID)&hk_clip_cursor, (LPVOID*)&o_clip_cursor);
|
||||||
|
MH_EnableHook(MH_ALL_HOOKS);
|
||||||
|
|
||||||
|
return o_wnd_proc != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// call after MH_DisableHook so no cursor hook is live while we unwind
|
||||||
|
inline void uninstall() {
|
||||||
|
if (g_menu_open) {
|
||||||
|
g_menu_open = false;
|
||||||
|
restore_cursor();
|
||||||
|
}
|
||||||
|
if (hooked_window && o_wnd_proc) {
|
||||||
|
SetWindowLongPtrW(hooked_window, GWLP_WNDPROC, (LONG_PTR)o_wnd_proc);
|
||||||
|
o_wnd_proc = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace input
|
||||||
+155
@@ -0,0 +1,155 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <d3d11.h>
|
||||||
|
#include <dxgi.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include "MinHook.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_dx11.h"
|
||||||
|
#include "imgui_impl_win32.h"
|
||||||
|
|
||||||
|
#include "input.h"
|
||||||
|
#include "gui/clickgui.h"
|
||||||
|
#include "modules/module_manager.h"
|
||||||
|
#include "modules/fps_counter.h"
|
||||||
|
#include "modules/keystrokes.h"
|
||||||
|
#include "modules/crosshair.h"
|
||||||
|
|
||||||
|
#pragma comment(lib, "d3d11.lib")
|
||||||
|
#pragma comment(lib, "dxgi.lib")
|
||||||
|
|
||||||
|
using present_fn = HRESULT(__stdcall*)(IDXGISwapChain*, UINT, UINT);
|
||||||
|
static present_fn o_present = nullptr;
|
||||||
|
|
||||||
|
static bool g_init = false;
|
||||||
|
static ID3D11Device* g_device = nullptr;
|
||||||
|
static ID3D11DeviceContext* g_ctx = nullptr;
|
||||||
|
static HMODULE g_module = nullptr;
|
||||||
|
static std::atomic<bool> g_unloading{ false };
|
||||||
|
|
||||||
|
HRESULT __stdcall hk_present(IDXGISwapChain* sc, UINT sync, UINT flags) {
|
||||||
|
if (g_unloading) return o_present(sc, sync, flags);
|
||||||
|
|
||||||
|
if (!g_init) {
|
||||||
|
// if the game isn't running D3D11 this fails, and we just skip drawing
|
||||||
|
if (FAILED(sc->GetDevice(__uuidof(ID3D11Device), (void**)&g_device)))
|
||||||
|
return o_present(sc, sync, flags);
|
||||||
|
|
||||||
|
g_device->GetImmediateContext(&g_ctx);
|
||||||
|
|
||||||
|
DXGI_SWAP_CHAIN_DESC desc;
|
||||||
|
sc->GetDesc(&desc);
|
||||||
|
g_game_window = desc.OutputWindow;
|
||||||
|
|
||||||
|
ImGui::CreateContext();
|
||||||
|
gui().init(); // fonts + theme, must run before the backends init
|
||||||
|
ImGui_ImplWin32_Init(desc.OutputWindow);
|
||||||
|
ImGui_ImplDX11_Init(g_device, g_ctx);
|
||||||
|
input::install(desc.OutputWindow); // window proc + cursor hooks
|
||||||
|
g_init = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grab the backbuffer fresh each frame so window resizes just work
|
||||||
|
ID3D11Texture2D* backbuffer = nullptr;
|
||||||
|
ID3D11RenderTargetView* rtv = nullptr;
|
||||||
|
sc->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backbuffer);
|
||||||
|
if (backbuffer) {
|
||||||
|
g_device->CreateRenderTargetView(backbuffer, nullptr, &rtv);
|
||||||
|
backbuffer->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rtv) {
|
||||||
|
ImGui_ImplDX11_NewFrame();
|
||||||
|
ImGui_ImplWin32_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
gui().update(); // menu key, esc, animations
|
||||||
|
if (!g_menu_open) modules().update_keys(); // toggle keys are ignored while the menu is open
|
||||||
|
gui().draw_backdrop();
|
||||||
|
modules().render();
|
||||||
|
gui().draw();
|
||||||
|
|
||||||
|
ImGui::Render();
|
||||||
|
g_ctx->OMSetRenderTargets(1, &rtv, nullptr);
|
||||||
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
rtv->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
return o_present(sc, sync, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
// make a throwaway swapchain just to read Present's address from the vtable
|
||||||
|
static void* get_present_address() {
|
||||||
|
WNDCLASSEXA wc{ sizeof(wc), CS_CLASSDC, DefWindowProcA, 0, 0,
|
||||||
|
GetModuleHandleA(nullptr), nullptr, nullptr, nullptr, nullptr, "dummyWnd", nullptr };
|
||||||
|
RegisterClassExA(&wc);
|
||||||
|
HWND hwnd = CreateWindowA("dummyWnd", "", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100,
|
||||||
|
nullptr, nullptr, wc.hInstance, nullptr);
|
||||||
|
|
||||||
|
DXGI_SWAP_CHAIN_DESC sd{};
|
||||||
|
sd.BufferCount = 1;
|
||||||
|
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||||
|
sd.OutputWindow = hwnd;
|
||||||
|
sd.SampleDesc.Count = 1;
|
||||||
|
sd.Windowed = TRUE;
|
||||||
|
|
||||||
|
IDXGISwapChain* sc = nullptr;
|
||||||
|
ID3D11Device* dev = nullptr;
|
||||||
|
ID3D11DeviceContext* ctx = nullptr;
|
||||||
|
void* present = nullptr;
|
||||||
|
|
||||||
|
if (SUCCEEDED(D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0,
|
||||||
|
nullptr, 0, D3D11_SDK_VERSION, &sd, &sc, &dev, nullptr, &ctx))) {
|
||||||
|
present = (*(void***)sc)[8]; // IDXGISwapChain::Present is vtable index 8
|
||||||
|
sc->Release(); dev->Release(); ctx->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
DestroyWindow(hwnd);
|
||||||
|
UnregisterClassA("dummyWnd", wc.hInstance);
|
||||||
|
return present;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD WINAPI main_thread(LPVOID) {
|
||||||
|
// register modules BEFORE the hook exists, so the render loop never sees the list mid-change
|
||||||
|
modules().add<fps_counter>()->set_enabled(true);
|
||||||
|
modules().add<keystrokes>()->set_enabled(true);
|
||||||
|
modules().add<crosshair>(); // off until you turn it on in the menu
|
||||||
|
|
||||||
|
void* present = get_present_address();
|
||||||
|
if (!present) { MessageBoxA(nullptr, "couldn't find Present!", "amnesia", MB_OK); return 1; }
|
||||||
|
|
||||||
|
MH_Initialize();
|
||||||
|
MH_CreateHook(present, &hk_present, (void**)&o_present);
|
||||||
|
MH_EnableHook(present);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) DWORD WINAPI unload(LPVOID) {
|
||||||
|
g_unloading = true; // hk_present stops drawing and just forwards
|
||||||
|
MH_DisableHook(MH_ALL_HOOKS); // Present + cursor hooks
|
||||||
|
input::uninstall(); // restores the game's window proc (and the cursor if the menu was open)
|
||||||
|
Sleep(300); // let any in-flight Present / window messages finish
|
||||||
|
|
||||||
|
modules().clear();
|
||||||
|
|
||||||
|
if (g_init) {
|
||||||
|
ImGui_ImplDX11_Shutdown();
|
||||||
|
ImGui_ImplWin32_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
if (g_ctx) { g_ctx->Release(); g_ctx = nullptr; }
|
||||||
|
if (g_device) { g_device->Release(); g_device = nullptr; }
|
||||||
|
g_init = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MH_Uninitialize();
|
||||||
|
FreeLibraryAndExitThread(g_module, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, LPVOID) {
|
||||||
|
if (reason == DLL_PROCESS_ATTACH) {
|
||||||
|
g_module = hmod;
|
||||||
|
DisableThreadLibraryCalls(hmod);
|
||||||
|
CreateThread(nullptr, 0, main_thread, nullptr, 0, nullptr);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
|
class crosshair : public module {
|
||||||
|
public:
|
||||||
|
crosshair()
|
||||||
|
: module("Crosshair", "Draws a custom crosshair at the center of the screen.",
|
||||||
|
category::visual, VK_F8) {
|
||||||
|
length_ = &add_float("Length", 8.f, 2.f, 30.f);
|
||||||
|
gap_ = &add_float("Gap", 4.f, 0.f, 20.f);
|
||||||
|
thickness_ = &add_float("Thickness", 2.f, 1.f, 8.f);
|
||||||
|
dot_ = &add_toggle("Center Dot", false);
|
||||||
|
color_ = &add_color("Color", 1.f, 1.f, 1.f, 0.9f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_render() override {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
|
const ImVec2 c(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
|
||||||
|
const float len = length_->float_value, gap = gap_->float_value;
|
||||||
|
const float h = thickness_->float_value * 0.5f;
|
||||||
|
const ImU32 col = setting_color(*color_);
|
||||||
|
|
||||||
|
dl->AddRectFilled(ImVec2(c.x - h, c.y - gap - len), ImVec2(c.x + h, c.y - gap), col); // top
|
||||||
|
dl->AddRectFilled(ImVec2(c.x - h, c.y + gap), ImVec2(c.x + h, c.y + gap + len), col); // bottom
|
||||||
|
dl->AddRectFilled(ImVec2(c.x - gap - len, c.y - h), ImVec2(c.x - gap, c.y + h), col); // left
|
||||||
|
dl->AddRectFilled(ImVec2(c.x + gap, c.y - h), ImVec2(c.x + gap + len, c.y + h), col); // right
|
||||||
|
if (dot_->bool_value)
|
||||||
|
dl->AddRectFilled(ImVec2(c.x - h, c.y - h), ImVec2(c.x + h, c.y + h), col);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
setting* length_ = nullptr;
|
||||||
|
setting* gap_ = nullptr;
|
||||||
|
setting* thickness_ = nullptr;
|
||||||
|
setting* dot_ = nullptr;
|
||||||
|
setting* color_ = nullptr;
|
||||||
|
};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdio>
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
|
class fps_counter : public module {
|
||||||
|
public:
|
||||||
|
fps_counter()
|
||||||
|
: module("FPS Counter", "Shows your current frames per second.", category::hud, VK_F6) {
|
||||||
|
hud_pos = ImVec2(10.f, 10.f);
|
||||||
|
background_ = &add_toggle("Background", true);
|
||||||
|
scale_ = &add_float("Scale", 1.f, 0.6f, 2.5f);
|
||||||
|
color_ = &add_color("Text Color", 1.f, 1.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_hud() const override { return true; }
|
||||||
|
|
||||||
|
ImVec2 hud_size() const override {
|
||||||
|
const float s = scale_->float_value;
|
||||||
|
ImVec2 ts = ImGui::CalcTextSize("FPS: 000"); // fixed width so the box doesn't jitter
|
||||||
|
return ImVec2(ts.x * s + pad * 2.f, ts.y * s + pad * 2.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_render() override {
|
||||||
|
char buf[32];
|
||||||
|
snprintf(buf, sizeof(buf), "FPS: %.0f", ImGui::GetIO().Framerate);
|
||||||
|
|
||||||
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
|
ImVec2 size = hud_size();
|
||||||
|
if (background_->bool_value)
|
||||||
|
dl->AddRectFilled(hud_pos, ImVec2(hud_pos.x + size.x, hud_pos.y + size.y),
|
||||||
|
IM_COL32(0, 0, 0, 120));
|
||||||
|
|
||||||
|
dl->AddText(ImGui::GetFont(), ImGui::GetFontSize() * scale_->float_value,
|
||||||
|
ImVec2(hud_pos.x + pad, hud_pos.y + pad), setting_color(*color_), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr float pad = 6.f;
|
||||||
|
setting* background_ = nullptr;
|
||||||
|
setting* scale_ = nullptr;
|
||||||
|
setting* color_ = nullptr;
|
||||||
|
};
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
|
class keystrokes : public module {
|
||||||
|
public:
|
||||||
|
keystrokes()
|
||||||
|
: module("Keystrokes", "Shows WASD and space bar presses.", category::hud, VK_F7) {
|
||||||
|
hud_pos = ImVec2(10.f, 60.f);
|
||||||
|
size_ = &add_float("Key Size", 40.f, 24.f, 64.f);
|
||||||
|
space_ = &add_toggle("Space Bar", true);
|
||||||
|
pressed_ = &add_color("Pressed Color", 1.f, 1.f, 1.f, 0.8f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_hud() const override { return true; }
|
||||||
|
|
||||||
|
ImVec2 hud_size() const override {
|
||||||
|
const float s = size_->float_value;
|
||||||
|
float w = 3.f * s + 2.f * gap;
|
||||||
|
float h = 2.f * s + gap;
|
||||||
|
if (space_->bool_value) h += gap + s * 0.55f;
|
||||||
|
return ImVec2(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_render() override {
|
||||||
|
const float s = size_->float_value;
|
||||||
|
const float x = hud_pos.x, y = hud_pos.y;
|
||||||
|
|
||||||
|
draw_key("W", 'W', x + s + gap, y, s, s);
|
||||||
|
draw_key("A", 'A', x, y + s + gap, s, s);
|
||||||
|
draw_key("S", 'S', x + s + gap, y + s + gap, s, s);
|
||||||
|
draw_key("D", 'D', x + 2.f * (s + gap), y + s + gap, s, s);
|
||||||
|
if (space_->bool_value)
|
||||||
|
draw_key("SPACE", VK_SPACE, x, y + 2.f * (s + gap), 3.f * s + 2.f * gap, s * 0.55f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr float gap = 4.f;
|
||||||
|
setting* size_ = nullptr;
|
||||||
|
setting* space_ = nullptr;
|
||||||
|
setting* pressed_ = nullptr;
|
||||||
|
|
||||||
|
void draw_key(const char* label, int vk, float x, float y, float w, float h) const {
|
||||||
|
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||||
|
const bool down = is_key_down(vk);
|
||||||
|
|
||||||
|
dl->AddRectFilled(ImVec2(x, y), ImVec2(x + w, y + h),
|
||||||
|
down ? setting_color(*pressed_) : IM_COL32(0, 0, 0, 130));
|
||||||
|
|
||||||
|
const float scale = size_->float_value / 40.f;
|
||||||
|
ImVec2 ts = ImGui::CalcTextSize(label);
|
||||||
|
ts.x *= scale; ts.y *= scale;
|
||||||
|
dl->AddText(ImGui::GetFont(), ImGui::GetFontSize() * scale,
|
||||||
|
ImVec2(x + (w - ts.x) * 0.5f, y + (h - ts.y) * 0.5f),
|
||||||
|
down ? IM_COL32(0, 0, 0, 255) : IM_COL32(255, 255, 255, 255), label);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <deque>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "setting.h"
|
||||||
|
|
||||||
|
enum class category { hud, visual, utility };
|
||||||
|
|
||||||
|
inline const char* category_name(category c) {
|
||||||
|
switch (c) {
|
||||||
|
case category::hud: return "HUD";
|
||||||
|
case category::visual: return "VISUAL";
|
||||||
|
case category::utility: return "UTILITY";
|
||||||
|
}
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline HWND g_game_window = nullptr;
|
||||||
|
|
||||||
|
inline bool is_game_focused() {
|
||||||
|
return g_game_window && GetForegroundWindow() == g_game_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only reports keys while Minecraft is the focused window
|
||||||
|
inline bool is_key_down(int vk) {
|
||||||
|
return is_game_focused() && (GetAsyncKeyState(vk) & 0x8000);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ImU32 setting_color(const setting& s) {
|
||||||
|
return ImGui::ColorConvertFloat4ToU32(ImVec4(s.color[0], s.color[1], s.color[2], s.color[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
class module {
|
||||||
|
public:
|
||||||
|
module(std::string name, std::string description, category cat, int toggle_key = 0)
|
||||||
|
: name_(std::move(name)), description_(std::move(description)),
|
||||||
|
cat_(cat), toggle_key_(toggle_key) {
|
||||||
|
}
|
||||||
|
virtual ~module() = default;
|
||||||
|
|
||||||
|
virtual void on_enable() {}
|
||||||
|
virtual void on_disable() {}
|
||||||
|
virtual void on_render() {} // every frame while enabled, inside the ImGui frame
|
||||||
|
|
||||||
|
// HUD modules can be dragged around while the menu is open
|
||||||
|
virtual bool is_hud() const { return false; }
|
||||||
|
virtual ImVec2 hud_size() const { return ImVec2(0.f, 0.f); }
|
||||||
|
|
||||||
|
void set_enabled(bool enabled) {
|
||||||
|
if (enabled == enabled_) return;
|
||||||
|
enabled_ = enabled;
|
||||||
|
if (enabled_) on_enable(); else on_disable();
|
||||||
|
}
|
||||||
|
void toggle() { set_enabled(!enabled_); }
|
||||||
|
|
||||||
|
bool enabled() const { return enabled_; }
|
||||||
|
const std::string& name() const { return name_; }
|
||||||
|
const std::string& description() const { return description_; }
|
||||||
|
category cat() const { return cat_; }
|
||||||
|
int toggle_key() const { return toggle_key_; }
|
||||||
|
void set_toggle_key(int vk) { toggle_key_ = vk; }
|
||||||
|
|
||||||
|
// called once per frame; toggles on the key's press edge
|
||||||
|
void update_key() {
|
||||||
|
bool down = toggle_key_ && is_key_down(toggle_key_);
|
||||||
|
if (down && !key_was_down_) toggle();
|
||||||
|
key_was_down_ = down;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- settings (a deque keeps references stable as more are added) ----
|
||||||
|
std::deque<setting>& settings() { return settings_; }
|
||||||
|
|
||||||
|
setting& add_toggle(std::string name, bool value) {
|
||||||
|
setting& s = settings_.emplace_back();
|
||||||
|
s.name = std::move(name);
|
||||||
|
s.type = setting_type::toggle;
|
||||||
|
s.bool_value = value;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
setting& add_float(std::string name, float value, float min_v, float max_v) {
|
||||||
|
setting& s = settings_.emplace_back();
|
||||||
|
s.name = std::move(name);
|
||||||
|
s.type = setting_type::slider_float;
|
||||||
|
s.float_value = value; s.float_min = min_v; s.float_max = max_v;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
setting& add_int(std::string name, int value, int min_v, int max_v) {
|
||||||
|
setting& s = settings_.emplace_back();
|
||||||
|
s.name = std::move(name);
|
||||||
|
s.type = setting_type::slider_int;
|
||||||
|
s.int_value = value; s.int_min = min_v; s.int_max = max_v;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
setting& add_mode(std::string name, std::vector<std::string> modes, int selected = 0) {
|
||||||
|
setting& s = settings_.emplace_back();
|
||||||
|
s.name = std::move(name);
|
||||||
|
s.type = setting_type::mode;
|
||||||
|
s.modes = std::move(modes);
|
||||||
|
s.int_value = selected;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
setting& add_color(std::string name, float r, float g, float b, float a = 1.f) {
|
||||||
|
setting& s = settings_.emplace_back();
|
||||||
|
s.name = std::move(name);
|
||||||
|
s.type = setting_type::color;
|
||||||
|
s.color[0] = r; s.color[1] = g; s.color[2] = b; s.color[3] = a;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- state used by the clickgui ----
|
||||||
|
ImVec2 hud_pos = ImVec2(10.f, 10.f);
|
||||||
|
|
||||||
|
struct ui_state {
|
||||||
|
bool expanded = false;
|
||||||
|
bool binding = false;
|
||||||
|
float hover_t = 0.f, enable_t = 0.f, expand_t = 0.f;
|
||||||
|
} ui;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
|
std::string description_;
|
||||||
|
category cat_;
|
||||||
|
int toggle_key_;
|
||||||
|
bool enabled_ = false;
|
||||||
|
bool key_was_down_ = false;
|
||||||
|
std::deque<setting> settings_;
|
||||||
|
};
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include "module.h"
|
||||||
|
|
||||||
|
class module_manager {
|
||||||
|
public:
|
||||||
|
template <typename T, typename... args_t>
|
||||||
|
T* add(args_t&&... args) {
|
||||||
|
auto m = std::make_unique<T>(std::forward<args_t>(args)...);
|
||||||
|
T* raw = m.get();
|
||||||
|
modules_.push_back(std::move(m));
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::unique_ptr<module>>& all() const { return modules_; }
|
||||||
|
|
||||||
|
void update_keys() { for (auto& m : modules_) m->update_key(); }
|
||||||
|
|
||||||
|
void render() {
|
||||||
|
for (auto& m : modules_)
|
||||||
|
if (m->enabled()) m->on_render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
for (auto& m : modules_) m->set_enabled(false);
|
||||||
|
modules_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::unique_ptr<module>> modules_;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline module_manager& modules() {
|
||||||
|
static module_manager instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
enum class setting_type { toggle, slider_float, slider_int, mode, color };
|
||||||
|
|
||||||
|
struct setting {
|
||||||
|
std::string name;
|
||||||
|
setting_type type = setting_type::toggle;
|
||||||
|
|
||||||
|
bool bool_value = false;
|
||||||
|
float float_value = 0.f, float_min = 0.f, float_max = 1.f;
|
||||||
|
int int_value = 0, int_min = 0, int_max = 10; // int_value doubles as the mode index
|
||||||
|
std::vector<std::string> modes;
|
||||||
|
float color[4] = { 1.f, 1.f, 1.f, 1.f };
|
||||||
|
};
|
||||||
+1
Submodule vendor/imgui added at 42a22377a4.
+1
Submodule vendor/minhook added at 8af6b4acae.
Reference in new issue
Block a user