added fullbright

This commit is contained in:
st committed 2026-10-13 02:04:50 -05:00
1 parent fafeee709f
commit b1634d195c
21 files changed
+1263 -204

No files matched your search

+9
View File
@@ -162,15 +162,24 @@
<ClCompile Include="main.cc" /> <ClCompile Include="main.cc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="game\hook.h" />
<ClInclude Include="game\signatures.h" />
<ClInclude Include="game\sigscan.h" />
<ClInclude Include="gui\clickgui.h" /> <ClInclude Include="gui\clickgui.h" />
<ClInclude Include="gui\fonts.h" />
<ClInclude Include="gui\theme.h" /> <ClInclude Include="gui\theme.h" />
<ClInclude Include="gui\widgets.h" />
<ClInclude Include="input.h" /> <ClInclude Include="input.h" />
<ClInclude Include="modules\crosshair.h" /> <ClInclude Include="modules\crosshair.h" />
<ClInclude Include="modules\fps_counter.h" /> <ClInclude Include="modules\fps_counter.h" />
<ClInclude Include="modules\fullbright.h" />
<ClInclude Include="modules\keystrokes.h" /> <ClInclude Include="modules\keystrokes.h" />
<ClInclude Include="modules\macro.h" />
<ClInclude Include="modules\module.h" /> <ClInclude Include="modules\module.h" />
<ClInclude Include="modules\module_manager.h" /> <ClInclude Include="modules\module_manager.h" />
<ClInclude Include="modules\optimizations.h" />
<ClInclude Include="modules\setting.h" /> <ClInclude Include="modules\setting.h" />
<ClInclude Include="modules\watermark.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
+9
View File
@@ -62,5 +62,14 @@
<ClInclude Include="gui\theme.h" /> <ClInclude Include="gui\theme.h" />
<ClInclude Include="modules\setting.h" /> <ClInclude Include="modules\setting.h" />
<ClInclude Include="modules\crosshair.h" /> <ClInclude Include="modules\crosshair.h" />
<ClInclude Include="gui\fonts.h" />
<ClInclude Include="gui\widgets.h" />
<ClInclude Include="modules\watermark.h" />
<ClInclude Include="modules\optimizations.h" />
<ClInclude Include="modules\macro.h" />
<ClInclude Include="game\sigscan.h" />
<ClInclude Include="game\hook.h" />
<ClInclude Include="game\signatures.h" />
<ClInclude Include="modules\fullbright.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+5
View File
@@ -0,0 +1,5 @@
#pragma once
inline const unsigned char k_font_data[] = {
0x00,0x01,0x00,0x00,0x00,0x0D,0x00,0x80,0x00,0x03,0x00,0x50,0x46,0x46,0x54,0x4D,0xAD,0x8D,0x69,0xF9,0x00,0x09,0xE8,0x54,0x00,0x00,0x00,0x1C,0x47,0x44,0x45,0x46,0x00,0x25,0x00,0x00,0x00,0x09,0xE8,0x3C,0x00,0x00,0x00,0x18,0x4F,0x53,0x2F,0x32,0x3D,0x7A,0x52,0x4B,0x00,0x00,0x01,0x58,0x00,0x00,0x00,0x60,0x63,0x6D,0x61,0x70,0x64,0xB9,0x3D,0x04,0x00,0x00,0x60,0x34,0x00,0x00,0x37,0xE4,0x67,0x61,0x73,0x70,0xFF,0xFF,0x00,0x03,0x00,0x09,0xE8,0x34,0x00,0x00,0x00,0x08,0x67,0x6C,0x79,0x66,0x4F,0x58,0x72,0xFB,0x00,0x00,0xF6,0x98,0x00,0x07,0xFF,0x2C,0x68,0x65,0x61,0x64,0x2F,0x42,0x8F,0x56,0x00,0x00,0x00,0xDC,0x00,0x00,0x00,0x36,0x68,0x68,0x65,0x61,0x0C,0xEE,0x1A,0xB3,0x00,0x00,0x01,0x14,0x00,0x00,0x00,0x24,0x68,0x6D,0x74,0x78,0xCC,0x17,0xA4,0x2E,0x00,0x00,0x01,0xB8,0x00,0x00,0x5E,0x7C,0x6C,0x6F,0x63,0x61,0x5C,0x7A,0x42,0xF8,0x00,0x00,0x98,0x18,0x00,0x00,0x5E,0x80,0x6D,0x61,0x78,0x70,0x17,0xC0,0x00,0xBA,0x00,0x00,0x01,0x38,0x00,0x00,0x00,0x20,0x6E,0x61,0x6D,0x65,0x93,0x60,0x3E,0x7F,0x00,0x08,0xF5,0xC4,0x00,0x00,0x10,0xC5,0x70,0x6F,0x73,0x74,0x56,0x1E,0x23,0xA4,0x00,0x09,0x06,0x8C,0x00,0x00,0xE1,0xA8,0x00,0x01,0x00,0x00,0x00,0x01,0x4C,0xCD,0xA5,0xF1,0x4D,0x95,0x5F,0x0F,0x3C,0xF5,0x00,0x0B,0x08,0x00,0x00,0x00,0x00,0x00,0xE4,0xAF,0x7C,0x00,0x00,0x00,0x00,0x00,0xE4,0xAF,0x7C,0x02,0xFF,0x62,0xFE,0x27,0x07,0x62,0x07,0x62,0x00,0x00,0x00,0x08,0x00,0x02,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x06,0x27,0xFE,0x27,0x00,0x00,0x08,0x00,0xFF,0x62,0xFC,0xEC,0x07,0x62,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0x9F,0x00,0x01,0x00,0x00,0x17,0x9F,0x00,0xB8,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x65,0x01,0xF4,0x00,0x05,0x00,0x00,0x08,0x00,0x08,0x00,0x00,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x00,0x00,0x04,0x00,0x00,0x9E,0x03,0x14,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE1,0x40,0x02,0xFF,0xFA,0xC7,0xFD,0xFB,0x06,0x64,0x80,0x34,0x06,0x00,0x20,0x40,0x4B,0x42,0x6E,0x50,0x01,0xC0,0x00,0x00,0xFF,0xFF,0x06,0x27,0xFE,0x27,0x00,0x00,0x06,0x27,0x01,0xD9,0x20,0x00,0x01,0x9F,0xDF,0xD7,0x00,0x00,0x03,0xB1,0x04,0xEC,0x00,0x00,0x00,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x04,0x4E,0x00,0x00,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x00,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x00,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x00,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x00,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x00,0x03,0xB1,0x00,0x00,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0xD9,0x03,0xB1,0x00,0x9E,0x03,0xB1,0x01,0x3B,0x03,0xB1,0x00,0x00,0x03,0xB1,0x01,0x3BLine truncated
};
inline const unsigned int k_font_size = 649328;
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include <windows.h>
#include <cstdint>
#include <string>
#include "MinHook.h"
#include "sigscan.h"
namespace game {
// messages show up in the Visual Studio output window, or in Sysinternals DebugView
inline void log(const std::string& msg) { OutputDebugStringA(("[amnesia] " + msg + "\n").c_str()); }
class game_hook {
public:
// creates the hook DISABLED; returns false if the signature is empty or not found
bool install(const char* name, const char* signature, void* detour, void** original) {
if (!signature || !*signature) { log(std::string(name) + ": no signature set"); return false; }
uint8_t* addr = sigscan::find(signature);
if (!addr) { log(std::string(name) + ": signature not found (game updated?)"); return false; }
if (MH_CreateHook(addr, detour, original) != MH_OK) { log(std::string(name) + ": MH_CreateHook failed"); return false; }
target_ = addr;
log(std::string(name) + ": hooked");
return true;
}
bool ok() const { return target_ != nullptr; }
void set_enabled(bool on) {
if (!target_) return;
if (on) MH_EnableHook(target_); else MH_DisableHook(target_);
}
private:
void* target_ = nullptr;
};
} // namespace game
+41
View File
@@ -0,0 +1,41 @@
#pragma once
// IDA-style patterns for Minecraft.Windows.exe ("48 8B ?? ?? 89 5C").
// Empty = that module reports itself unavailable instead of crashing.
// These are specific to one game version and must be re-found after every update.
namespace sigs {
// a function that returns the brightness setting as a float
inline constexpr const char* get_gamma =
"48 8B 49 58 66 66 66 2E 0F 1F 84 00 00 00 00 00 "
"48 89 C8 48 8B 49 08 48 8B 89 38 02 00 00 "
"48 85 C9 75 ED F3 0F 10 40 18 C3";
inline constexpr const char* gamma_writer =
"56 48 83 EC 30 48 8B 05 ?? ?? ?? ?? "
"48 31 E0 48 89 44 24 28 "
"48 8B 71 58 48 8B 4E 08 "
"48 83 B9 38 02 00 00 00";
inline constexpr const char* get_gamma_gameplay =
"48 83 EC 38 "
"48 8B 05 ?? ?? ?? ?? "
"48 31 E0 "
"48 89 44 24 30 "
"48 8B 01 "
"48 8B 40 08 "
"48 8D 54 24 28 "
"41 B8 32 00 00 00 "
"FF 15 ?? ?? ?? ?? "
"48 8B 4C 24 28 "
"48 89 C8 "
"48 8B 49 08 "
"48 8B 89 38 02 00 00 "
"48 85 C9 75 ED "
"F3 0F 10 40 18 "
"48 8B 4C 24 30 "
"48 31 E1 "
"48 3B 0D ?? ?? ?? ?? "
"75 05 "
"48 83 C4 38 C3";
}
+118
View File
@@ -0,0 +1,118 @@
#pragma once
#include <windows.h>
#include <cstdint>
#include <cstdlib>
#include <vector>
namespace sigscan {
struct pattern {
std::vector<uint8_t> bytes;
std::vector<bool> mask; // true = this byte must match
};
// IDA-style: "48 8B ?? ?? 89 5C"
inline bool parse(const char* ida, pattern& out) {
out.bytes.clear();
out.mask.clear();
for (const char* p = ida; *p;) {
if (*p == ' ') { ++p; continue; }
if (*p == '?') {
out.bytes.push_back(0);
out.mask.push_back(false);
++p;
if (*p == '?') ++p;
}
else {
if (!p[1]) return false;
const char buf[3] = { p[0], p[1], 0 };
char* end = nullptr;
const unsigned long v = strtoul(buf, &end, 16);
if (end != buf + 2) return false;
out.bytes.push_back((uint8_t)v);
out.mask.push_back(true);
p += 2;
}
}
return !out.bytes.empty();
}
inline uint8_t* scan_range(uint8_t* begin, uint8_t* end, const pattern& pat) {
const size_t n = pat.bytes.size();
if ((size_t)(end - begin) < n) return nullptr;
uint8_t* last = end - n;
for (uint8_t* p = begin; p <= last; ++p) {
size_t i = 0;
while (i < n && (!pat.mask[i] || p[i] == pat.bytes[i])) ++i;
if (i == n) return p;
}
return nullptr;
}
inline size_t count_matches(
uint8_t* begin,
uint8_t* end,
const pattern& pat)
{
size_t count = 0;
const size_t n = pat.bytes.size();
if (n == 0 || end < begin ||
static_cast<size_t>(end - begin) < n)
return 0;
for (uint8_t* p = begin; p <= end - n; ++p) {
size_t i = 0;
while (i < n &&
(!pat.mask[i] || p[i] == pat.bytes[i]))
++i;
if (i == n)
++count;
}
return count;
}
// searches the executable sections of the game's main module
inline uint8_t* find(const char* ida_pattern) {
pattern pat;
if (!parse(ida_pattern, pat)) return nullptr;
auto* base = (uint8_t*)GetModuleHandleW(nullptr);
auto* dos = (IMAGE_DOS_HEADER*)base;
auto* nt = (IMAGE_NT_HEADERS*)(base + dos->e_lfanew);
const IMAGE_SECTION_HEADER* sec = IMAGE_FIRST_SECTION(nt);
for (WORD i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++sec) {
if (!(sec->Characteristics & IMAGE_SCN_MEM_EXECUTE)) continue;
uint8_t* start = base + sec->VirtualAddress;
uint8_t* end = start + sec->Misc.VirtualSize;
for (uint8_t* p = start; p < end;) { // walk readable regions only
MEMORY_BASIC_INFORMATION mbi;
if (!VirtualQuery(p, &mbi, sizeof(mbi))) break;
uint8_t* region_end = (uint8_t*)mbi.BaseAddress + mbi.RegionSize;
if (region_end > end) region_end = end;
const bool readable = mbi.State == MEM_COMMIT && !(mbi.Protect & (PAGE_NOACCESS | PAGE_GUARD));
if (readable) {
if (uint8_t* hit = scan_range(p, region_end, pat)) return hit;
}
p = region_end;
}
}
return nullptr;
}
// for patterns that land on a RIP-relative instruction (e.g. a call or lea):
// rel_offset = byte offset of the 4-byte displacement, instr_len = length of the instruction
inline uint8_t* resolve_rip(uint8_t* instr, int rel_offset, int instr_len) {
const int32_t rel = *(int32_t*)(instr + rel_offset);
return instr + instr_len + rel;
}
} // namespace sigscan
+144 -93
View File
@@ -1,20 +1,16 @@
#pragma once #pragma once
#include <cfloat> #include <cfloat>
#include <cmath>
#include <string> #include <string>
#include "imgui.h" #include "imgui.h"
#include "fonts.h"
#include "theme.h" #include "theme.h"
#include "widgets.h"
#include "../input.h" #include "../input.h"
#include "../modules/module_manager.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) { inline std::string key_name(int vk) {
if (vk == 0) return "None"; if (vk == 0) return "none";
LONG lparam = (LONG)(MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_VSC) << 16); LONG lparam = (LONG)(MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_VSC) << 16);
switch (vk) { // extended keys need bit 24 set to get the right name switch (vk) { // extended keys need bit 24 set to get the right name
@@ -39,7 +35,7 @@ public:
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr; // never write imgui.ini into the game's folder io.IniFilename = nullptr; // never write imgui.ini into the game's folder
io.LogFilename = nullptr; io.LogFilename = nullptr;
load_fonts(); fonts::load();
theme::apply(); theme::apply();
} }
@@ -56,28 +52,36 @@ public:
open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f); 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 // dim + wordmark; call BEFORE modules().render() so the HUD stays above the dimming
void draw_backdrop() { void draw_backdrop() {
if (open_t_ <= 0.01f) return; if (open_t_ <= 0.01f) return;
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
ImDrawList* dl = ImGui::GetBackgroundDrawList(); ImDrawList* dl = ImGui::GetBackgroundDrawList();
const float a = open_t_;
dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize, dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize,
theme::u32(theme::with_alpha(theme::bg_dark(), 0.6f * open_t_))); theme::u32(theme::with_alpha(theme::bg(), k_backdrop_alpha * a)));
const char* title = "AMNESIA"; // title bar, like the launcher: cube + lowercase wordmark
const float tw = ImGui::CalcTextSize(title).x * k_title_size / ImGui::GetFontSize(); const ImVec2 logo_pos(26.f, 18.f);
const ImVec2 tp(io.DisplaySize.x * 0.5f - tw * 0.5f, 18.f); const float logo_h = 30.f;
dl->AddText(font_title_, k_title_size, ImVec2(tp.x + 3.f, tp.y + 3.f), const float logo_w = theme::draw_logo(dl, logo_pos, logo_h, a);
theme::u32(theme::with_alpha(theme::bg_dark(), open_t_)), title); const ImVec2 ts = fonts::text_size(fonts::heading, fonts::k_heading_size, "amnesia");
dl->AddText(font_title_, k_title_size, tp, dl->AddText(fonts::heading, fonts::k_heading_size,
theme::u32(theme::with_alpha(theme::accent_bright(), open_t_)), title); ImVec2(floorf(logo_pos.x + logo_w + 12.f), floorf(logo_pos.y + (logo_h - ts.y) * 0.5f)),
theme::u32(theme::with_alpha(theme::fg(), a)), "amnesia");
const char* hint = "Right-click a module for settings | drag HUD elements to move them"; // footer, like the launcher's status strip
const float hw = ImGui::CalcTextSize(hint).x; dl->AddText(fonts::label, fonts::k_label_size,
dl->AddText(ImVec2(io.DisplaySize.x * 0.5f - hw * 0.5f, tp.y + k_title_size + 8.f), ImVec2(28.f, io.DisplaySize.y - 30.f),
theme::u32(theme::with_alpha(theme::fg_muted(), open_t_)), hint); theme::u32(theme::with_alpha(theme::dim(), a)), "amnesia / v0.0.1");
const char* hint = "right click a module for settings | drag hud elements to move them | right shift or esc to close";
const ImVec2 hs = fonts::text_size(fonts::body, fonts::k_body_size, hint);
dl->AddText(fonts::body, fonts::k_body_size,
ImVec2(floorf(io.DisplaySize.x - hs.x - 28.f), io.DisplaySize.y - 32.f),
theme::u32(theme::with_alpha(theme::muted(), a)), hint);
} }
// the panels and the HUD drag editor // the panels and the HUD drag editor
@@ -99,30 +103,21 @@ public:
private: private:
static constexpr int k_menu_key = VK_RSHIFT; static constexpr int k_menu_key = VK_RSHIFT;
static constexpr float k_panel_w = 230.f; static constexpr float k_panel_w = 270.f;
static constexpr float k_main_size = 18.f; static constexpr float k_backdrop_alpha = 0.6f; // the launcher's overlay is 0.85; lower so you can see the game
static constexpr float k_title_size = 32.f;
static constexpr category k_categories[] = { category::hud, category::visual, category::utility }; static constexpr category k_categories[] = { category::hud, category::visual, category::utility };
ImFont* font_main_ = nullptr;
ImFont* font_title_ = nullptr;
float open_t_ = 0.f; float open_t_ = 0.f;
bool menu_key_was_down_ = false; bool menu_key_was_down_ = false;
bool esc_was_down_ = false; bool esc_was_down_ = false;
void load_fonts() { static const char* category_title(category c) {
ImGuiIO& io = ImGui::GetIO(); switch (c) {
#if AMNESIA_HAS_FONT case category::hud: return "hud";
ImFontConfig cfg; case category::visual: return "visual";
cfg.FontDataOwnedByAtlas = false; // the data lives in our DLL, ImGui must not free it case category::utility: return "utility";
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_; return "";
} }
void set_open(bool open) { void set_open(bool open) {
@@ -154,28 +149,49 @@ private:
// ---------------- panels ---------------- // ---------------- panels ----------------
void draw_panel(category cat, float default_x) { void draw_panel(category cat, float default_x) {
ImGui::SetNextWindowPos(ImVec2(default_x, 110.f), ImGuiCond_FirstUseEver); ImGui::SetNextWindowPos(ImVec2(default_x, 100.f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(k_panel_w, 0.f), ImGuiCond_Always); // fixed width, auto height ImGui::SetNextWindowSize(ImVec2(k_panel_w, 0.f), ImGuiCond_Always); // fixed width, auto height
ImGuiWindowFlags flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoSavedSettings; ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings;
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks
if (ImGui::Begin(category_name(cat), nullptr, flags)) { const std::string id = std::string("##panel_") + category_name(cat);
if (ImGui::Begin(id.c_str(), nullptr, flags)) {
// header: small uppercase muted label + SemiBold heading (drag the panel by this area)
/*fonts::push_font(fonts::label, fonts::k_label_size);
ImGui::TextColored(theme::muted(), "%s", category_name(cat));
ImGui::PopFont();*/
fonts::push_font(fonts::heading, fonts::k_heading_size);
ImGui::TextUnformatted(category_title(cat));
ImGui::PopFont();
ImGui::Dummy(ImVec2(0.f, 4.f));
for (auto& m : modules().all()) for (auto& m : modules().all())
if (m->cat() == cat) draw_module(*m); if (m->cat() == cat) draw_module(*m);
} }
ImGui::End(); ImGui::End();
} }
void draw_tooltip(const module& m) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(14.f, 12.f));
ImGui::BeginTooltip();
ImGui::TextUnformatted(m.description().c_str());
ImGui::TextColored(theme::muted(), "click to toggle | right click for settings");
ImGui::EndTooltip();
ImGui::PopStyleVar();
}
void draw_module(module& m) { void draw_module(module& m) {
ImGui::PushID(&m); ImGui::PushID(&m);
ImDrawList* dl = ImGui::GetWindowDrawList(); ImDrawList* dl = ImGui::GetWindowDrawList();
const float w = ImGui::GetContentRegionAvail().x; const float w = ImGui::GetContentRegionAvail().x;
const float h = ImGui::GetFontSize() + 14.f; const float h = 38.f;
const ImVec2 p = ImGui::GetCursorScreenPos(); const ImVec2 p = ImGui::GetCursorScreenPos();
const ImVec2 q(p.x + w, p.y + h);
ImGui::InvisibleButton("##row", ImVec2(w, h)); ImGui::InvisibleButton("##row", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered(); const bool hovered = ImGui::IsItemHovered();
@@ -185,35 +201,44 @@ private:
m.ui.expanded = !m.ui.expanded; m.ui.expanded = !m.ui.expanded;
m.ui.binding = false; m.ui.binding = false;
} }
if (hovered) if (hovered) draw_tooltip(m);
ImGui::SetTooltip("%s\n\nLMB: toggle | RMB: settings", m.description().c_str());
const float dt = ImGui::GetIO().DeltaTime; 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.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.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); 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); // off = secondary button, on = Primary (Accent fill, dark text)
base = theme::shade(base, 1.f + 0.15f * m.ui.hover_t); const ImVec4 fill_off = theme::mix(theme::raised(), theme::hover(), m.ui.hover_t);
theme::bevel_box(dl, p, ImVec2(p.x + w, p.y + h), base, active); const ImVec4 fill_on = theme::shade(theme::accent(), 1.f + 0.10f * m.ui.hover_t);
ImVec4 fill = theme::mix(fill_off, fill_on, m.ui.enable_t);
ImVec4 border = theme::mix(theme::line(), theme::accent(), m.ui.hover_t);
ImVec4 text_col = theme::mix(theme::fg(), theme::bg(), m.ui.enable_t);
if (active) { fill.w *= 0.7f; border.w *= 0.7f; text_col.w *= 0.7f; }
const ImVec4 text_col = theme::mix(theme::fg(), theme::bg_dark(), m.ui.enable_t); dl->AddRectFilled(p, q, theme::u32(fill), theme::k_radius_button);
const float text_y = p.y + (h - ImGui::GetFontSize()) * 0.5f; dl->AddRect(p, q, theme::u32(border), theme::k_radius_button, 0, 1.f);
theme::shadow_text(dl, ImVec2(p.x + 8.f, text_y), text_col, m.name().c_str());
if (m.toggle_key()) { const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, m.name().c_str());
const std::string k = "[" + key_name(m.toggle_key()) + "]"; dl->AddText(fonts::semibold, fonts::k_body_size,
const float kw = ImGui::CalcTextSize(k.c_str()).x; ImVec2(floorf(p.x + 16.f), floorf(p.y + (h - ts.y) * 0.5f)),
const ImVec4 kcol = theme::mix(theme::fg_muted(), theme::bg_dark(), m.ui.enable_t * 0.6f); theme::u32(text_col), m.name().c_str());
dl->AddText(ImVec2(p.x + w - kw - 8.f, text_y), theme::u32(kcol), k.c_str());
if (m.toggle_key()) { // keycap chip on the right
const std::string k = key_name(m.toggle_key());
const ImVec2 ks = fonts::text_size(fonts::label, fonts::k_label_size, k.c_str());
const float cw = ks.x + 14.f, ch = 20.f;
const ImVec2 c0(q.x - 12.f - cw, p.y + (h - ch) * 0.5f);
const ImVec2 c1(c0.x + cw, c0.y + ch);
dl->AddRectFilled(c0, c1, theme::u32(theme::with_alpha(theme::bg(), 0.55f)), 6.f);
dl->AddText(fonts::label, fonts::k_label_size,
ImVec2(floorf(c0.x + 7.f), floorf(c0.y + (ch - ks.y) * 0.5f)),
theme::u32(theme::muted()), k.c_str());
} }
if (m.ui.expand_t > 0.01f) { if (m.ui.expand_t > 0.01f) {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * m.ui.expand_t); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * m.ui.expand_t);
ImGui::Indent(6.f); draw_settings(m, w);
draw_bind_button(m);
for (auto& s : m.settings()) draw_setting(s);
ImGui::Unindent(6.f);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0.f, 2.f)); ImGui::Dummy(ImVec2(0.f, 2.f));
} }
@@ -221,12 +246,41 @@ private:
ImGui::PopID(); ImGui::PopID();
} }
void draw_bind_button(module& m) { // settings live in an inset card (Bg fill, Line border), drawn behind the widgets
std::string label; void draw_settings(module& m, float w) {
if (m.ui.binding) label = "Bind: press a key..."; ImDrawList* dl = ImGui::GetWindowDrawList();
else label = "Bind: [" + key_name(m.toggle_key()) + "]"; const ImVec2 start = ImGui::GetCursorScreenPos();
const float pad = 12.f;
const float inner_w = w - pad * 2.f;
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) m.ui.binding = !m.ui.binding; dl->ChannelsSplit(2);
dl->ChannelsSetCurrent(1);
ImGui::BeginGroup();
ImGui::Dummy(ImVec2(w, 2.f));
ImGui::Indent(pad);
draw_bind(m, inner_w);
for (auto& s : m.settings()) draw_setting(s, inner_w);
ImGui::Unindent(pad);
ImGui::Dummy(ImVec2(0.f, 2.f));
ImGui::EndGroup();
const ImVec2 gmin = ImGui::GetItemRectMin();
const ImVec2 gmax = ImGui::GetItemRectMax();
dl->ChannelsSetCurrent(0);
const ImVec2 a(start.x, gmin.y), b(start.x + w, gmax.y);
dl->AddRectFilled(a, b, theme::u32(theme::bg()), theme::k_radius_button);
dl->AddRect(a, b, theme::u32(theme::line()), theme::k_radius_button, 0, 1.f);
dl->ChannelsMerge();
}
void draw_bind(module& m, float w) {
ImGui::TextUnformatted("bind");
const std::string text = m.ui.binding ? std::string("press a key...") : key_name(m.toggle_key());
if (widgets::button("##bind", text.c_str(), false, w)) m.ui.binding = !m.ui.binding;
if (m.ui.binding) { if (m.ui.binding) {
for (int vk = 0x08; vk < 0xFF; ++vk) { // starts above the mouse buttons for (int vk = 0x08; vk < 0xFF; ++vk) { // starts above the mouse buttons
@@ -239,47 +293,44 @@ private:
} }
} }
void draw_setting(setting& s) { void draw_setting(setting& s, float w) {
ImGui::PushID(&s); ImGui::PushID(&s);
switch (s.type) { switch (s.type) {
case setting_type::toggle: { case setting_type::toggle:
const std::string label = s.name + ": " + (s.bool_value ? "ON" : "OFF"); widgets::checkbox(s.name.c_str(), &s.bool_value, w);
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; break;
}
case setting_type::slider_float: { case setting_type::slider_float:
const std::string fmt = s.name + ": %.2f"; ImGui::TextUnformatted(s.name.c_str());
ImGui::SetNextItemWidth(-FLT_MIN); ImGui::SetNextItemWidth(w);
ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, fmt.c_str()); ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, "%.2f");
break; break;
}
case setting_type::slider_int: { case setting_type::slider_int:
const std::string fmt = s.name + ": %d"; ImGui::TextUnformatted(s.name.c_str());
ImGui::SetNextItemWidth(-FLT_MIN); ImGui::SetNextItemWidth(w);
ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, fmt.c_str()); ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, "%d");
break; break;
}
case setting_type::mode: { case setting_type::mode:
if (!s.modes.empty()) { if (!s.modes.empty()) {
if (s.int_value < 0 || s.int_value >= (int)s.modes.size()) s.int_value = 0; 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]; ImGui::TextUnformatted(s.name.c_str());
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) if (widgets::button("##mode", s.modes[s.int_value].c_str(), false, w))
s.int_value = (s.int_value + 1) % (int)s.modes.size(); s.int_value = (s.int_value + 1) % (int)s.modes.size();
} }
break; break;
}
case setting_type::color: { case setting_type::color:
ImGui::ColorEdit4("##c", s.color, ImGui::ColorEdit4("##c", s.color,
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel |
ImGuiColorEditFlags_AlphaBar); ImGuiColorEditFlags_AlphaBar);
ImGui::SameLine(); ImGui::SameLine(0.f, 10.f);
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted(s.name.c_str()); ImGui::TextUnformatted(s.name.c_str());
break; break;
} }
}
ImGui::PopID(); ImGui::PopID();
} }
@@ -323,10 +374,10 @@ private:
m.hud_pos.y += io.MouseDelta.y; m.hud_pos.y += io.MouseDelta.y;
} }
const ImVec4 col = (hovered || active) ? theme::accent_bright() : theme::accent_dark(); const ImVec4 col = (hovered || active) ? theme::focus() : theme::hover();
ImGui::GetForegroundDrawList()->AddRect( ImGui::GetForegroundDrawList()->AddRect(
m.hud_pos, ImVec2(m.hud_pos.x + size.x, m.hud_pos.y + size.y), m.hud_pos, ImVec2(m.hud_pos.x + size.x, m.hud_pos.y + size.y),
theme::u32(col), 0.f, 0, 2.f); theme::u32(col), 10.f, 0, 1.5f);
} }
ImGui::End(); ImGui::End();
ImGui::PopStyleVar(2); ImGui::PopStyleVar(2);
+74
View File
@@ -0,0 +1,74 @@
#pragma once
#include <windows.h>
#include <string>
#include "imgui.h"
// optional fallback if the Segoe UI files can't be found
#if __has_include("../font_data.h")
#include "../font_data.h"
#define AMNESIA_HAS_FONT 1
#else
#define AMNESIA_HAS_FONT 0
#endif
namespace fonts {
inline constexpr float k_body_size = 14.f; // launcher base font size
inline constexpr float k_label_size = 11.f; // the small uppercase labels
inline constexpr float k_heading_size = 20.f;
inline ImFont* body = nullptr; // Segoe UI
inline ImFont* semibold = nullptr; // Segoe UI Semibold (buttons, module names)
inline ImFont* label = nullptr; // Segoe UI Bold
inline ImFont* heading = nullptr; // Segoe UI Semibold, larger
// PushFont changed signature in ImGui 1.92 (fonts became size-flexible)
inline void push_font(ImFont* font, float size) {
#if IMGUI_VERSION_NUM >= 19200
ImGui::PushFont(font, size);
#else
(void)size;
ImGui::PushFont(font);
#endif
}
inline ImVec2 text_size(ImFont* font, float size, const char* text) {
push_font(font, size);
const ImVec2 ts = ImGui::CalcTextSize(text);
ImGui::PopFont();
return ts;
}
inline bool windows_font_path(const char* file, std::string& out) {
char dir[MAX_PATH] = {};
const UINT n = GetWindowsDirectoryA(dir, MAX_PATH);
if (n == 0 || n >= MAX_PATH) return false;
out = std::string(dir) + "\\Fonts\\" + file;
return GetFileAttributesA(out.c_str()) != INVALID_FILE_ATTRIBUTES;
}
inline ImFont* load_one(ImGuiIO& io, const char* file, float size) {
std::string path;
if (windows_font_path(file, path)) {
if (ImFont* f = io.Fonts->AddFontFromFileTTF(path.c_str(), size)) return f;
}
#if AMNESIA_HAS_FONT
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
return io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, size, &cfg);
#else
return io.Fonts->AddFontDefault();
#endif
}
// after ImGui::CreateContext(), before the backends are initialized
inline void load() {
ImGuiIO& io = ImGui::GetIO();
body = load_one(io, "segoeui.ttf", k_body_size);
semibold = load_one(io, "seguisb.ttf", k_body_size);
label = load_one(io, "segoeuib.ttf", k_label_size);
heading = load_one(io, "seguisb.ttf", k_heading_size);
io.FontDefault = body;
}
} // namespace fonts
+67 -58
View File
@@ -1,9 +1,15 @@
#pragma once #pragma once
#include <utility> #include <cmath>
#include "imgui.h" #include "imgui.h"
namespace theme { namespace theme {
// radii straight from App.xaml
inline constexpr float k_radius_card = 20.f;
inline constexpr float k_radius_button = 12.f;
inline constexpr float k_radius_input = 10.f;
inline constexpr float k_radius_check = 6.f;
inline float clampf(float v, float lo, float hi) { return v < lo ? lo : (v > hi ? hi : v); } 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) { inline ImVec4 hex(unsigned int rgb, float a = 1.f) {
@@ -33,93 +39,96 @@ namespace theme {
return (v - target < 0.001f && target - v < 0.001f) ? target : v; return (v - target < 0.001f && target - v < 0.001f) ? target : v;
} }
// ---- "orphan" palette ---- // ---- names mirror App.xaml ----
inline ImVec4 bg_dark() { return hex(0x17141c); } inline ImVec4 bg() { return hex(0x17141c); } // Bg
inline ImVec4 bg() { return hex(0x2b2632); } inline ImVec4 surface() { return hex(0x2b2632); } // Surface
inline ImVec4 bg_raised() { return hex(0x38313c); } inline ImVec4 raised() { return hex(0x38313c); } // Raised
inline ImVec4 fg() { return hex(0xc9b5af); } inline ImVec4 fg() { return hex(0xc9b5af); } // Fg
inline ImVec4 fg_muted() { return hex(0x8372a0); } inline ImVec4 muted() { return hex(0x8372a0); } // Muted
inline ImVec4 fg_dim() { return hex(0x625577); } inline ImVec4 dim() { return hex(0x625577); } // Dim
inline ImVec4 accent() { return hex(0x8c79a5); } inline ImVec4 accent() { return hex(0x8c79a5); } // Accent
inline ImVec4 accent_dark() { return hex(0x74608e); } inline ImVec4 hover() { return hex(0x74608e); } // Hover
inline ImVec4 accent_bright() { return hex(0xbfa5ea); } inline ImVec4 line() { return hex(0x433a4f); } // Line
inline ImVec4 border() { return hex(0x433a4f); } inline ImVec4 focus() { return hex(0xd5c7eb); } // keyboard-focus ring
inline ImVec4 danger() { return hex(0xbc9ba1); } // error text
// Minecraft-button look: flat fill, light top/left edge, dark bottom/right edge // the isometric cube from the launcher's login screen; returns its width
inline void bevel_box(ImDrawList* dl, ImVec2 a, ImVec2 b, const ImVec4& base, bool pressed = false) { inline float draw_logo(ImDrawList* dl, ImVec2 pos, float height, float alpha = 1.f) {
const float t = 2.f; const float s = height / 199.f; // source art spans x 43..217, y 36..235
ImVec4 hi = shade(base, 1.35f), lo = shade(base, 0.6f); auto pt = [&](float x, float y) { return ImVec2(pos.x + (x - 43.f) * s, pos.y + (y - 36.f) * s); };
if (pressed) std::swap(hi, lo);
dl->AddRectFilled(a, b, u32(base)); const ImVec2 top[4] = { pt(130, 36), pt(217, 86), pt(130, 137), pt(43, 86) };
dl->AddRectFilled(a, ImVec2(b.x, a.y + t), u32(hi)); const ImVec2 left[4] = { pt(43, 86), pt(130, 137), pt(130, 235), pt(43, 184) };
dl->AddRectFilled(a, ImVec2(a.x + t, b.y), u32(hi)); const ImVec2 right[4] = { pt(130, 137), pt(217, 86), pt(217, 184), pt(130, 235) };
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 dl->AddConvexPolyFilled(top, 4, u32(with_alpha(accent(), alpha)));
inline void shadow_text(ImDrawList* dl, ImVec2 pos, const ImVec4& col, const char* text) { dl->AddConvexPolyFilled(left, 4, u32(with_alpha(dim(), alpha)));
dl->AddText(ImVec2(pos.x + 2.f, pos.y + 2.f), u32(with_alpha(bg_dark(), col.w)), text); dl->AddConvexPolyFilled(right, 4, u32(with_alpha(line(), alpha)));
dl->AddText(pos, u32(col), text); return 174.f * s;
} }
inline void apply() { inline void apply() {
ImGuiStyle& s = ImGui::GetStyle(); ImGuiStyle& s = ImGui::GetStyle();
s.WindowRounding = s.ChildRounding = s.FrameRounding = s.PopupRounding = 0.f; s.WindowRounding = k_radius_card;
s.ScrollbarRounding = s.GrabRounding = s.TabRounding = 0.f; s.ChildRounding = k_radius_button;
s.WindowBorderSize = 2.f; s.FrameRounding = k_radius_input;
s.PopupRounding = k_radius_button;
s.ScrollbarRounding = k_radius_input;
s.GrabRounding = k_radius_input;
s.TabRounding = k_radius_input;
s.WindowBorderSize = 1.f;
s.ChildBorderSize = 1.f; s.ChildBorderSize = 1.f;
s.PopupBorderSize = 2.f; s.PopupBorderSize = 1.f;
s.FrameBorderSize = 1.f; s.FrameBorderSize = 1.f;
s.WindowPadding = ImVec2(6.f, 6.f); s.WindowPadding = ImVec2(18.f, 18.f);
s.FramePadding = ImVec2(8.f, 5.f); s.FramePadding = ImVec2(12.f, 8.f);
s.ItemSpacing = ImVec2(6.f, 5.f); s.ItemSpacing = ImVec2(8.f, 8.f);
s.WindowTitleAlign = ImVec2(0.5f, 0.5f); s.ItemInnerSpacing = ImVec2(8.f, 6.f);
s.GrabMinSize = 12.f; s.GrabMinSize = 16.f;
s.ScrollbarSize = 10.f; s.ScrollbarSize = 10.f;
s.AntiAliasedLines = false; // crisp, blocky edges s.AntiAliasedLines = true;
s.AntiAliasedFill = false; s.AntiAliasedFill = true;
ImVec4* c = s.Colors; ImVec4* c = s.Colors;
const ImVec4 clear(0.f, 0.f, 0.f, 0.f); const ImVec4 clear(0.f, 0.f, 0.f, 0.f);
c[ImGuiCol_Text] = fg(); c[ImGuiCol_Text] = fg();
c[ImGuiCol_TextDisabled] = fg_dim(); c[ImGuiCol_TextDisabled] = dim();
c[ImGuiCol_WindowBg] = with_alpha(bg(), 0.96f); c[ImGuiCol_WindowBg] = with_alpha(surface(), 0.97f);
c[ImGuiCol_ChildBg] = clear; c[ImGuiCol_ChildBg] = clear;
c[ImGuiCol_PopupBg] = with_alpha(bg_dark(), 0.98f); c[ImGuiCol_PopupBg] = surface();
c[ImGuiCol_Border] = bg_dark(); c[ImGuiCol_Border] = line();
c[ImGuiCol_BorderShadow] = clear; c[ImGuiCol_BorderShadow] = clear;
c[ImGuiCol_FrameBg] = bg_raised(); c[ImGuiCol_FrameBg] = bg(); // inputs: Bg fill, Line border
c[ImGuiCol_FrameBgHovered] = shade(bg_raised(), 1.25f); c[ImGuiCol_FrameBgHovered] = mix(bg(), raised(), 0.6f);
c[ImGuiCol_FrameBgActive] = shade(bg_raised(), 1.45f); c[ImGuiCol_FrameBgActive] = raised();
c[ImGuiCol_TitleBg] = shade(accent_dark(), 0.75f); c[ImGuiCol_TitleBg] = surface();
c[ImGuiCol_TitleBgActive] = accent_dark(); c[ImGuiCol_TitleBgActive] = surface();
c[ImGuiCol_TitleBgCollapsed] = shade(accent_dark(), 0.75f); c[ImGuiCol_TitleBgCollapsed] = surface();
c[ImGuiCol_ScrollbarBg] = clear; c[ImGuiCol_ScrollbarBg] = clear;
c[ImGuiCol_ScrollbarGrab] = border(); c[ImGuiCol_ScrollbarGrab] = line();
c[ImGuiCol_ScrollbarGrabHovered] = fg_dim(); c[ImGuiCol_ScrollbarGrabHovered] = dim();
c[ImGuiCol_ScrollbarGrabActive] = fg_muted(); c[ImGuiCol_ScrollbarGrabActive] = muted();
c[ImGuiCol_CheckMark] = accent_bright(); c[ImGuiCol_CheckMark] = fg();
c[ImGuiCol_SliderGrab] = accent(); c[ImGuiCol_SliderGrab] = accent();
c[ImGuiCol_SliderGrabActive] = accent_bright(); c[ImGuiCol_SliderGrabActive] = focus();
c[ImGuiCol_Button] = bg_raised(); c[ImGuiCol_Button] = raised();
c[ImGuiCol_ButtonHovered] = shade(bg_raised(), 1.3f); c[ImGuiCol_ButtonHovered] = hover();
c[ImGuiCol_ButtonActive] = accent_dark(); c[ImGuiCol_ButtonActive] = hover();
c[ImGuiCol_Header] = accent_dark(); c[ImGuiCol_Header] = hover();
c[ImGuiCol_HeaderHovered] = accent(); c[ImGuiCol_HeaderHovered] = accent();
c[ImGuiCol_HeaderActive] = accent(); c[ImGuiCol_HeaderActive] = accent();
c[ImGuiCol_Separator] = border(); c[ImGuiCol_Separator] = line();
} }
} // namespace theme } // namespace theme
+94
View File
@@ -0,0 +1,94 @@
#pragma once
#include <cmath>
#include "imgui.h"
#include "fonts.h"
#include "theme.h"
namespace widgets {
inline constexpr float k_button_height = 36.f;
// the launcher's Button: Raised fill + Line border, hover -> Hover fill + Accent border,
// pressed -> 70% opacity. primary = Accent fill with dark text. width 0 = fill the row.
inline bool button(const char* id, const char* text, bool primary = false, float width = 0.f) {
ImDrawList* dl = ImGui::GetWindowDrawList();
const ImVec2 p = ImGui::GetCursorScreenPos();
const float w = width > 0.f ? width : ImGui::GetContentRegionAvail().x;
const float h = k_button_height;
ImGui::PushID(id);
const bool clicked = ImGui::InvisibleButton("##b", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered();
const bool held = ImGui::IsItemActive();
const ImGuiID key = ImGui::GetID("##hover_t");
ImGui::PopID();
ImGuiStorage* st = ImGui::GetStateStorage();
const float t = theme::approach(st->GetFloat(key, 0.f), hovered ? 1.f : 0.f,
ImGui::GetIO().DeltaTime * 16.f);
st->SetFloat(key, t);
ImVec4 fill = theme::mix(primary ? theme::accent() : theme::raised(), theme::hover(), t);
ImVec4 border = theme::mix(theme::line(), theme::accent(), t);
ImVec4 text_col = primary ? theme::bg() : theme::fg();
if (held) { fill.w *= 0.7f; border.w *= 0.7f; text_col.w *= 0.7f; }
const ImVec2 q(p.x + w, p.y + h);
dl->AddRectFilled(p, q, theme::u32(fill), theme::k_radius_button);
dl->AddRect(p, q, theme::u32(border), theme::k_radius_button, 0, 1.f);
const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, text);
dl->AddText(fonts::semibold, fonts::k_body_size,
ImVec2(floorf(p.x + (w - ts.x) * 0.5f), floorf(p.y + (h - ts.y) * 0.5f)),
theme::u32(text_col), text);
return clicked;
}
// the launcher's CheckBox: 20px box, radius 6, Bg fill + Line border; checked -> Hover fill + tick
inline bool checkbox(const char* label, bool* value, float width = 0.f) {
ImDrawList* dl = ImGui::GetWindowDrawList();
const ImVec2 p = ImGui::GetCursorScreenPos();
const float w = width > 0.f ? width : ImGui::GetContentRegionAvail().x;
const float box = 20.f;
const float h = 28.f;
ImGui::PushID(label);
const bool pressed = ImGui::InvisibleButton("##c", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered();
const ImGuiID hover_key = ImGui::GetID("##hover_t");
const ImGuiID on_key = ImGui::GetID("##on_t");
ImGui::PopID();
if (pressed) *value = !*value;
ImGuiStorage* st = ImGui::GetStateStorage();
const float dt = ImGui::GetIO().DeltaTime;
const float hover_t = theme::approach(st->GetFloat(hover_key, 0.f), hovered ? 1.f : 0.f, dt * 16.f);
const float on_t = theme::approach(st->GetFloat(on_key, *value ? 1.f : 0.f), *value ? 1.f : 0.f, dt * 14.f);
st->SetFloat(hover_key, hover_t);
st->SetFloat(on_key, on_t);
const ImVec2 b0(p.x, p.y + (h - box) * 0.5f);
const ImVec2 b1(b0.x + box, b0.y + box);
const ImVec4 fill = theme::mix(theme::bg(), theme::hover(), on_t);
const ImVec4 border = theme::mix(theme::line(), theme::accent(), hover_t > on_t ? hover_t : on_t);
dl->AddRectFilled(b0, b1, theme::u32(fill), theme::k_radius_check);
dl->AddRect(b0, b1, theme::u32(border), theme::k_radius_check, 0, 1.f);
if (on_t > 0.01f) { // vector tick, so we don't depend on the font having a check glyph
const ImU32 tick = theme::u32(theme::with_alpha(theme::fg(), on_t));
const ImVec2 a(b0.x + box * 0.27f, b0.y + box * 0.53f);
const ImVec2 b(b0.x + box * 0.43f, b0.y + box * 0.69f);
const ImVec2 c(b0.x + box * 0.74f, b0.y + box * 0.33f);
dl->AddLine(a, b, tick, 2.f);
dl->AddLine(b, c, tick, 2.f);
}
const ImVec2 ts = fonts::text_size(fonts::body, fonts::k_body_size, label);
dl->AddText(fonts::body, fonts::k_body_size,
ImVec2(floorf(b1.x + 10.f), floorf(p.y + (h - ts.y) * 0.5f)),
theme::u32(theme::fg()), label);
return pressed;
}
} // namespace widgets
+38 -10
View File
@@ -58,30 +58,58 @@ namespace input {
inline bool should_block(UINT msg) { inline bool should_block(UINT msg) {
switch (msg) { switch (msg) {
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: case WM_RBUTTONDOWN:
case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: 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_INPUT:
case WM_KEYDOWN: case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_CHAR: case WM_CHAR:
case WM_SYSCHAR:
return true; return true;
default: default:
return false; return false;
} }
} }
inline LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { inline LRESULT CALLBACK wnd_proc(
LRESULT handled = ImGui_ImplWin32_WndProcHandler(hwnd, msg, wp, lp); // ImGui always sees input HWND hwnd,
UINT msg,
WPARAM wp,
LPARAM lp
) {
// always feed imgui while the menu is open
if (g_menu_open.load()) {
ImGui_ImplWin32_WndProcHandler(hwnd, msg, wp, lp);
if (g_menu_open) {
if (handled) return handled;
if (should_block(msg)) { if (should_block(msg)) {
if (msg == WM_INPUT) return DefWindowProcW(hwnd, msg, wp, lp); // raw input needs cleanup if (msg == WM_LBUTTONDOWN || msg == WM_RBUTTONDOWN) {
OutputDebugStringA("[amnesia] blocking mouse button message\n");
}
if (msg == WM_INPUT) {
OutputDebugStringA("[amnesia] blocking raw input message\n");
return DefWindowProcW(hwnd, msg, wp, lp);
}
return 0; return 0;
} }
} }
// normal behavior when the menu is closed,
// plus key/button release events while it's open
return CallWindowProcW(o_wnd_proc, hwnd, msg, wp, lp); return CallWindowProcW(o_wnd_proc, hwnd, msg, wp, lp);
} }
+13 -3
View File
@@ -13,6 +13,10 @@
#include "modules/fps_counter.h" #include "modules/fps_counter.h"
#include "modules/keystrokes.h" #include "modules/keystrokes.h"
#include "modules/crosshair.h" #include "modules/crosshair.h"
#include "modules/watermark.h"
#include "modules/optimizations.h"
#include "modules/macro.h"
#include "modules/fullbright.h"
#pragma comment(lib, "d3d11.lib") #pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib") #pragma comment(lib, "dxgi.lib")
@@ -74,7 +78,9 @@ HRESULT __stdcall hk_present(IDXGISwapChain* sc, UINT sync, UINT flags) {
rtv->Release(); rtv->Release();
} }
return o_present(sc, sync, flags); const HRESULT result = o_present(sc, sync, flags);
if (g_init && !g_unloading) modules().frame_end();
return result;
} }
// make a throwaway swapchain just to read Present's address from the vtable // make a throwaway swapchain just to read Present's address from the vtable
@@ -110,15 +116,19 @@ static void* get_present_address() {
} }
DWORD WINAPI main_thread(LPVOID) { DWORD WINAPI main_thread(LPVOID) {
// register modules BEFORE the hook exists, so the render loop never sees the list mid-change MH_Initialize();
modules().add<fps_counter>()->set_enabled(true); modules().add<fps_counter>()->set_enabled(true);
modules().add<keystrokes>()->set_enabled(true); modules().add<keystrokes>()->set_enabled(true);
modules().add<watermark>()->set_enabled(true);
modules().add<crosshair>(); // off until you turn it on in the menu modules().add<crosshair>(); // off until you turn it on in the menu
modules().add<optimizations>();
modules().add<macro>();
modules().add<fullbright>(); // scans for its signature here; can take a couple of seconds
void* present = get_present_address(); void* present = get_present_address();
if (!present) { MessageBoxA(nullptr, "couldn't find Present!", "amnesia", MB_OK); return 1; } if (!present) { MessageBoxA(nullptr, "couldn't find Present!", "amnesia", MB_OK); return 1; }
MH_Initialize();
MH_CreateHook(present, &hk_present, (void**)&o_present); MH_CreateHook(present, &hk_present, (void**)&o_present);
MH_EnableHook(present); MH_EnableHook(present);
return 0; return 0;
+6 -6
View File
@@ -4,13 +4,13 @@
class crosshair : public module { class crosshair : public module {
public: public:
crosshair() crosshair()
: module("Crosshair", "Draws a custom crosshair at the center of the screen.", : module("crosshair", "draws a custom crosshair at the center of the screen",
category::visual, VK_F8) { category::visual, VK_F8) {
length_ = &add_float("Length", 8.f, 2.f, 30.f); length_ = &add_float("length", 8.f, 2.f, 30.f);
gap_ = &add_float("Gap", 4.f, 0.f, 20.f); gap_ = &add_float("gap", 4.f, 0.f, 20.f);
thickness_ = &add_float("Thickness", 2.f, 1.f, 8.f); thickness_ = &add_float("thickness", 2.f, 1.f, 8.f);
dot_ = &add_toggle("Center Dot", false); dot_ = &add_toggle("center dot", false);
color_ = &add_color("Color", 1.f, 1.f, 1.f, 0.9f); color_ = &add_color("color", 1.f, 1.f, 1.f, 0.9f);
} }
void on_render() override { void on_render() override {
+39 -15
View File
@@ -1,41 +1,65 @@
#pragma once #pragma once
#include <cstdio> #include <cstdio>
#include "module.h" #include "module.h"
#include "../gui/fonts.h"
#include "../gui/theme.h"
class fps_counter : public module { class fps_counter : public module {
public: public:
fps_counter() fps_counter()
: module("FPS Counter", "Shows your current frames per second.", category::hud, VK_F6) { : module("fps counter", "shows your current fps", category::hud, VK_F6) {
hud_pos = ImVec2(10.f, 10.f); hud_pos = ImVec2(10.f, 10.f);
background_ = &add_toggle("Background", true); background_ = &add_toggle("background", true);
scale_ = &add_float("Scale", 1.f, 0.6f, 2.5f); scale_ = &add_float("scale", 1.f, 0.7f, 2.5f);
color_ = &add_color("Text Color", 1.f, 1.f, 1.f); const ImVec4 fg = theme::fg();
color_ = &add_color("color", fg.x, fg.y, fg.z);
} }
bool is_hud() const override { return true; } bool is_hud() const override { return true; }
ImVec2 hud_size() const override { ImVec2 hud_size() const override {
const float s = scale_->float_value; const float s = scale_->float_value;
ImVec2 ts = ImGui::CalcTextSize("FPS: 000"); // fixed width so the box doesn't jitter const ImVec2 label = fonts::text_size(fonts::body, fonts::k_body_size, "fps");
return ImVec2(ts.x * s + pad * 2.f, ts.y * s + pad * 2.f); const ImVec2 value = fonts::text_size(fonts::semibold, fonts::k_body_size, "000"); // fixed width, no jitter
return ImVec2((pad_x * 2.f + label.x + gap + value.x) * s,
(pad_y * 2.f + value.y) * s);
} }
void on_render() override { void on_render() override {
char buf[32]; const float s = scale_->float_value;
snprintf(buf, sizeof(buf), "FPS: %.0f", ImGui::GetIO().Framerate); const float fs = fonts::k_body_size * s;
char buf[16];
snprintf(buf, sizeof(buf), "%.0f", ImGui::GetIO().Framerate);
ImDrawList* dl = ImGui::GetBackgroundDrawList(); ImDrawList* dl = ImGui::GetBackgroundDrawList();
ImVec2 size = hud_size(); const ImVec2 size = hud_size();
if (background_->bool_value) const ImVec2 q(hud_pos.x + size.x, hud_pos.y + size.y);
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, if (background_->bool_value) { // a launcher card: Surface fill, Line border
ImVec2(hud_pos.x + pad, hud_pos.y + pad), setting_color(*color_), buf); dl->AddRectFilled(hud_pos, q, theme::u32(theme::with_alpha(theme::surface(), 0.85f)), 10.f * s);
dl->AddRect(hud_pos, q, theme::u32(theme::line()), 10.f * s, 0, 1.f);
}
const ImVec2 label = fonts::text_size(fonts::body, fonts::k_body_size, "fps");
const float y = hud_pos.y + (size.y - label.y * s) * 0.5f;
float x = hud_pos.x + pad_x * s;
if (!background_->bool_value) { // no card: a soft shadow keeps it readable
const ImU32 shadow = theme::u32(theme::with_alpha(theme::bg(), 0.7f));
dl->AddText(fonts::body, fs, ImVec2(x + s, y + s), shadow, "fps");
dl->AddText(fonts::semibold, fs, ImVec2(x + (label.x + gap) * s + s, y + s), shadow, buf);
}
dl->AddText(fonts::body, fs, ImVec2(x, y), theme::u32(theme::muted()), "fps");
x += (label.x + gap) * s;
dl->AddText(fonts::semibold, fs, ImVec2(x, y), setting_color(*color_), buf);
} }
private: private:
static constexpr float pad = 6.f; static constexpr float pad_x = 12.f;
static constexpr float pad_y = 7.f;
static constexpr float gap = 6.f;
setting* background_ = nullptr; setting* background_ = nullptr;
setting* scale_ = nullptr; setting* scale_ = nullptr;
setting* color_ = nullptr; setting* color_ = nullptr;
+66
View File
@@ -0,0 +1,66 @@
#pragma once
#include "module.h"
#include "../game/hook.h"
#include "../game/signatures.h"
class fullbright : public module {
public:
fullbright() : module("fullbright", "maxes out brightness", category::visual) {
gamma_ = &add_float("strength", 10.f, 1.f, 25.f);
instance_ = this;
if (!hook_.install("get_gamma", sigs::get_gamma, (void*)&detour, (void**)&original_))
set_description("unavailable! no working signature for get_gamma (see game/signatures.h).");
if (!gameplay_hook_.install(
"get_gamma_gameplay",
sigs::get_gamma_gameplay,
reinterpret_cast<void*>(&gameplay_detour),
reinterpret_cast<void**>(&original_gameplay_))) {
game::log("get_gamma_gameplay: install failed");
}
}
void on_enable() override {
if (!hook_.ok() && !gameplay_hook_.ok()) {
set_enabled(false);
return;
}
if (hook_.ok())
hook_.set_enabled(true);
if (gameplay_hook_.ok())
gameplay_hook_.set_enabled(true);
}
void on_disable() override {
hook_.set_enabled(false);
gameplay_hook_.set_enabled(false);
}
private:
using get_gamma_fn = float(__fastcall*)(void* options);
static inline fullbright* instance_ = nullptr;
static inline get_gamma_fn original_ = nullptr;
using get_gamma_gameplay_fn = float(__fastcall*)(void* options);
static inline get_gamma_gameplay_fn original_gameplay_ = nullptr;
static float __fastcall detour(void* options) {
if (instance_ && instance_->enabled() && instance_->gamma_)
return instance_->gamma_->float_value;
return original_ ? original_(options) : 0.0f;
}
static float __fastcall gameplay_detour(void* options) {
if (instance_ && instance_->enabled() && instance_->gamma_)
return instance_->gamma_->float_value;
return original_gameplay_ ? original_gameplay_(options) : 0.0f;
}
setting* gamma_ = nullptr;
game::game_hook hook_;
game::game_hook gameplay_hook_;
};
+34 -19
View File
@@ -1,14 +1,18 @@
#pragma once #pragma once
#include <cmath>
#include "module.h" #include "module.h"
#include "../gui/fonts.h"
#include "../gui/theme.h"
class keystrokes : public module { class keystrokes : public module {
public: public:
keystrokes() keystrokes()
: module("Keystrokes", "Shows WASD and space bar presses.", category::hud, VK_F7) { : module("keystrokes", "shows your key presses", category::hud, VK_F7) {
hud_pos = ImVec2(10.f, 60.f); hud_pos = ImVec2(10.f, 60.f);
size_ = &add_float("Key Size", 40.f, 24.f, 64.f); size_ = &add_float("key size", 40.f, 28.f, 64.f);
space_ = &add_toggle("Space Bar", true); space_ = &add_toggle("space bar", true);
pressed_ = &add_color("Pressed Color", 1.f, 1.f, 1.f, 0.8f); const ImVec4 a = theme::accent();
pressed_ = &add_color("pressed color", a.x, a.y, a.z, 1.f);
} }
bool is_hud() const override { return true; } bool is_hud() const override { return true; }
@@ -24,33 +28,44 @@ public:
void on_render() override { void on_render() override {
const float s = size_->float_value; const float s = size_->float_value;
const float x = hud_pos.x, y = hud_pos.y; const float x = hud_pos.x, y = hud_pos.y;
const float dt = ImGui::GetIO().DeltaTime;
draw_key("W", 'W', x + s + gap, y, s, s); draw_key(0, "W", 'W', x + s + gap, y, s, s, dt);
draw_key("A", 'A', x, y + s + gap, s, s); draw_key(1, "A", 'A', x, y + s + gap, s, s, dt);
draw_key("S", 'S', x + s + gap, y + s + gap, s, s); draw_key(2, "S", 'S', x + s + gap, y + s + gap, s, s, dt);
draw_key("D", 'D', x + 2.f * (s + gap), y + s + gap, s, s); draw_key(3, "D", 'D', x + 2.f * (s + gap), y + s + gap, s, s, dt);
if (space_->bool_value) if (space_->bool_value)
draw_key("SPACE", VK_SPACE, x, y + 2.f * (s + gap), 3.f * s + 2.f * gap, s * 0.55f); draw_key(4, "_____", VK_SPACE, x, y + 2.f * (s + gap), 3.f * s + 2.f * gap, s * 0.55f, dt);
} }
private: private:
static constexpr float gap = 4.f; static constexpr float gap = 6.f;
setting* size_ = nullptr; setting* size_ = nullptr;
setting* space_ = nullptr; setting* space_ = nullptr;
setting* pressed_ = nullptr; setting* pressed_ = nullptr;
float press_t_[5] = {};
void draw_key(const char* label, int vk, float x, float y, float w, float h) const { // each key is a small launcher button: Raised -> Accent with dark text when pressed
void draw_key(int i, const char* label, int vk, float x, float y, float w, float h, float dt) {
ImDrawList* dl = ImGui::GetBackgroundDrawList(); ImDrawList* dl = ImGui::GetBackgroundDrawList();
const bool down = is_key_down(vk);
dl->AddRectFilled(ImVec2(x, y), ImVec2(x + w, y + h), press_t_[i] = theme::approach(press_t_[i], is_key_down(vk) ? 1.f : 0.f, dt * 20.f);
down ? setting_color(*pressed_) : IM_COL32(0, 0, 0, 130)); const float t = press_t_[i];
const ImVec4 pressed(pressed_->color[0], pressed_->color[1], pressed_->color[2], pressed_->color[3]);
const ImVec4 fill = theme::mix(theme::with_alpha(theme::raised(), 0.85f), pressed, t);
const ImVec4 border = theme::mix(theme::line(), theme::accent(), t);
const ImVec4 text = theme::mix(theme::fg(), theme::bg(), t);
const float r = h * 0.3f;
const ImVec2 a(x, y), b(x + w, y + h);
dl->AddRectFilled(a, b, theme::u32(fill), r);
dl->AddRect(a, b, theme::u32(border), r, 0, 1.f);
const float scale = size_->float_value / 40.f; const float scale = size_->float_value / 40.f;
ImVec2 ts = ImGui::CalcTextSize(label); const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, label);
ts.x *= scale; ts.y *= scale; dl->AddText(fonts::semibold, fonts::k_body_size * scale,
dl->AddText(ImGui::GetFont(), ImGui::GetFontSize() * scale, ImVec2(floorf(x + (w - ts.x * scale) * 0.5f), floorf(y + (h - ts.y * scale) * 0.5f)),
ImVec2(x + (w - ts.x) * 0.5f, y + (h - ts.y) * 0.5f), theme::u32(text), label);
down ? IM_COL32(0, 0, 0, 255) : IM_COL32(255, 255, 255, 255), label);
} }
}; };
+295
View File
@@ -0,0 +1,295 @@
#pragma once
#include <windows.h>
#include <cstdio>
#include <cstring>
#include <initializer_list>
#include <vector>
#include "module.h"
#include "../input.h"
#include "../gui/fonts.h"
#include "../gui/theme.h"
class macro : public module {
public:
macro()
: module("Macro", "Records clicks and key presses in menus (like villager trading) and replays them.",
category::utility) {
loops_ = &add_int("Loops (0 = until stopped)", 10, 0, 500);
speed_ = &add_float("Speed", 1.f, 0.25f, 3.f);
loop_delay_ = &add_int("Delay Between Loops (ms)", 300, 0, 5000);
show_status_ = &add_toggle("Show Status", true);
}
void on_disable() override { stop("disabled"); }
void on_render() override {
if (g_menu_open) {
if (mode_ != mode::idle) stop("menu opened");
return;
}
handle_hotkeys();
if (mode_ == mode::recording) record_frame();
else if (mode_ == mode::playing) play_frame();
draw_status();
}
private:
// the status text below names these keys, so update it if you rebind
static constexpr int k_record_key = VK_F9;
static constexpr int k_play_key = VK_F10;
static constexpr int k_stop_key = VK_END;
enum class mode { idle, recording, playing };
enum class ev { mouse_down, mouse_up, key_down, key_up };
struct event { ev type; int vk; float x, y; double t; };
setting* loops_ = nullptr;
setting* speed_ = nullptr;
setting* loop_delay_ = nullptr;
setting* show_status_ = nullptr;
mode mode_ = mode::idle;
std::vector<event> events_;
bool rec_key_was_down_ = false, play_key_was_down_ = false, stop_key_was_down_ = false;
bool prev_down_[256] = {}; // recording: edge detection
bool held_[256] = {}; // playback: what we're holding down, so stop can release it
double rec_start_ = 0.0, play_t0_ = 0.0;
size_t next_ = 0;
int loops_done_ = 0;
bool cursor_placed_ = false;
const char* status_ = "";
double status_until_ = 0.0;
static double now() {
static const double freq = [] { LARGE_INTEGER f; QueryPerformanceFrequency(&f); return (double)f.QuadPart; }();
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
return (double)c.QuadPart / freq;
}
// ---------------- control ----------------
void handle_hotkeys() {
const bool rec = is_key_down(k_record_key);
const bool play = is_key_down(k_play_key);
const bool stp = is_key_down(k_stop_key);
if (rec && !rec_key_was_down_) {
if (mode_ == mode::recording) stop("recording saved");
else if (mode_ == mode::idle) start_recording();
}
if (play && !play_key_was_down_) {
if (mode_ == mode::playing) stop("stopped");
else if (mode_ == mode::idle) start_playing();
}
if (stp && !stop_key_was_down_) stop("stopped");
rec_key_was_down_ = rec;
play_key_was_down_ = play;
stop_key_was_down_ = stp;
}
void say(const char* msg) { status_ = msg; status_until_ = now() + 2.5; }
void stop(const char* reason) {
if (mode_ == mode::playing) release_all();
if (mode_ != mode::idle) say(reason);
mode_ = mode::idle;
}
void start_recording() {
events_.clear();
for (int vk = 1; vk < 256; ++vk) prev_down_[vk] = is_key_down(vk); // held keys don't count as presses
rec_start_ = now();
mode_ = mode::recording;
}
void start_playing() {
if (events_.empty()) { say("nothing recorded yet"); return; }
std::memset(held_, 0, sizeof(held_));
next_ = 0;
loops_done_ = 0;
cursor_placed_ = false;
play_t0_ = now() + 0.3; // short grace period so you can let go of F10
mode_ = mode::playing;
}
// ---------------- recording ----------------
static bool cursor_fraction(float& fx, float& fy) {
POINT pt;
RECT rc;
if (!g_game_window || !GetCursorPos(&pt) || !ScreenToClient(g_game_window, &pt) ||
!GetClientRect(g_game_window, &rc)) return false;
const float w = (float)(rc.right - rc.left), h = (float)(rc.bottom - rc.top);
if (w <= 0.f || h <= 0.f) return false;
fx = pt.x / w;
fy = pt.y / h;
return true;
}
static bool recordable_key(int vk) {
if (vk == k_record_key || vk == k_play_key || vk == k_stop_key) return false;
if (vk == VK_SHIFT || vk == VK_CONTROL || vk == VK_MENU) return false; // use the left/right variants
if (vk == VK_RSHIFT) return false; // menu key
return true;
}
void record_frame() {
const double t = now() - rec_start_;
for (int vk : { VK_LBUTTON, VK_RBUTTON, VK_MBUTTON }) {
const bool down = is_key_down(vk);
if (down == prev_down_[vk]) continue;
prev_down_[vk] = down;
float fx = 0.f, fy = 0.f;
if (!cursor_fraction(fx, fy)) continue;
events_.push_back({ down ? ev::mouse_down : ev::mouse_up, vk, fx, fy, t });
}
for (int vk = 0x08; vk < 0xFF; ++vk) {
if (!recordable_key(vk)) continue;
const bool down = is_key_down(vk);
if (down == prev_down_[vk]) continue;
prev_down_[vk] = down;
events_.push_back({ down ? ev::key_down : ev::key_up, vk, 0.f, 0.f, t });
}
}
// ---------------- playback ----------------
void play_frame() {
if (!is_game_focused()) { stop("lost focus"); return; }
const double elapsed = (now() - play_t0_) * speed_->float_value;
if (next_ < events_.size() && events_[next_].t <= elapsed) {
const event& e = events_[next_];
const bool mouse = (e.type == ev::mouse_down || e.type == ev::mouse_up);
if (mouse && !cursor_placed_) { // frame 1: move the cursor, so the game sees the hover first
move_cursor(e.x, e.y);
cursor_placed_ = true;
return;
}
send(e); // frame 2: the click or key itself
cursor_placed_ = false;
++next_;
}
if (next_ >= events_.size()) {
++loops_done_;
const int target = loops_->int_value;
if (target != 0 && loops_done_ >= target) { stop("finished"); return; }
next_ = 0;
cursor_placed_ = false;
play_t0_ = now() + loop_delay_->int_value / 1000.0; // t0 in the future = wait before the next loop
}
}
static bool is_extended(int vk) {
switch (vk) {
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:
return true;
default:
return false;
}
}
static void move_cursor(float fx, float fy) {
RECT rc;
if (!g_game_window || !GetClientRect(g_game_window, &rc)) return;
POINT pt = { (LONG)(fx * (rc.right - rc.left)), (LONG)(fy * (rc.bottom - rc.top)) };
ClientToScreen(g_game_window, &pt);
const int vx = GetSystemMetrics(SM_XVIRTUALSCREEN), vy = GetSystemMetrics(SM_YVIRTUALSCREEN);
const int vw = GetSystemMetrics(SM_CXVIRTUALSCREEN), vh = GetSystemMetrics(SM_CYVIRTUALSCREEN);
if (vw <= 1 || vh <= 1) return;
INPUT in{};
in.type = INPUT_MOUSE;
in.mi.dx = (LONG)(((pt.x - vx) * 65535.0) / (vw - 1));
in.mi.dy = (LONG)(((pt.y - vy) * 65535.0) / (vh - 1));
in.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_VIRTUALDESK;
SendInput(1, &in, sizeof(INPUT));
}
static void send_button(int vk, bool down) {
INPUT in{};
in.type = INPUT_MOUSE;
switch (vk) {
case VK_LBUTTON: in.mi.dwFlags = down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; break;
case VK_RBUTTON: in.mi.dwFlags = down ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP; break;
case VK_MBUTTON: in.mi.dwFlags = down ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP; break;
default: return;
}
SendInput(1, &in, sizeof(INPUT));
}
static void send_key(int vk, bool down) {
INPUT in{};
in.type = INPUT_KEYBOARD;
in.ki.wVk = (WORD)vk;
in.ki.wScan = (WORD)MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_VSC);
in.ki.dwFlags = (down ? 0 : KEYEVENTF_KEYUP) | (is_extended(vk) ? KEYEVENTF_EXTENDEDKEY : 0);
SendInput(1, &in, sizeof(INPUT));
}
void send(const event& e) {
const bool down = (e.type == ev::mouse_down || e.type == ev::key_down);
if (e.type == ev::mouse_down || e.type == ev::mouse_up) send_button(e.vk, down);
else send_key(e.vk, down);
held_[e.vk] = down;
}
void release_all() { // never leave a key or button stuck down
for (int vk = 1; vk < 256; ++vk) {
if (!held_[vk]) continue;
if (vk == VK_LBUTTON || vk == VK_RBUTTON || vk == VK_MBUTTON) send_button(vk, false);
else send_key(vk, false);
held_[vk] = false;
}
}
// ---------------- status chip ----------------
void draw_status() {
if (!show_status_->bool_value) return;
char buf[128];
ImVec4 dot = theme::dim();
if (mode_ == mode::recording) {
snprintf(buf, sizeof(buf), "REC %d events | F9 to save", (int)events_.size());
dot = theme::danger();
}
else if (mode_ == mode::playing) {
if (loops_->int_value == 0)
snprintf(buf, sizeof(buf), "PLAYING loop %d | End to stop", loops_done_ + 1);
else
snprintf(buf, sizeof(buf), "PLAYING loop %d / %d | End to stop", loops_done_ + 1, loops_->int_value);
dot = theme::accent();
}
else if (now() < status_until_) {
snprintf(buf, sizeof(buf), "%s", status_);
}
else {
snprintf(buf, sizeof(buf), "Macro | F9 record F10 play End stop (%d events)", (int)events_.size());
}
ImDrawList* dl = ImGui::GetBackgroundDrawList();
const ImVec2 ts = fonts::text_size(fonts::body, fonts::k_body_size, buf);
const float pad_x = 14.f, h = ts.y + 14.f, w = ts.x + pad_x * 2.f + 16.f;
const ImVec2 p(floorf((ImGui::GetIO().DisplaySize.x - w) * 0.5f), 14.f);
const ImVec2 q(p.x + w, p.y + h);
dl->AddRectFilled(p, q, theme::u32(theme::with_alpha(theme::surface(), 0.9f)), 10.f);
dl->AddRect(p, q, theme::u32(theme::line()), 10.f, 0, 1.f);
dl->AddCircleFilled(ImVec2(p.x + pad_x + 4.f, p.y + h * 0.5f), 4.f, theme::u32(dot));
dl->AddText(fonts::body, fonts::k_body_size,
ImVec2(p.x + pad_x + 16.f, p.y + (h - ts.y) * 0.5f), theme::u32(theme::fg()), buf);
}
};
+3
View File
@@ -44,6 +44,9 @@ public:
virtual void on_enable() {} virtual void on_enable() {}
virtual void on_disable() {} virtual void on_disable() {}
virtual void on_render() {} // every frame while enabled, inside the ImGui frame virtual void on_render() {} // every frame while enabled, inside the ImGui frame
virtual void on_frame_end() {} // runs right after the game's Present returns (frame limiters go here)
void set_description(std::string d) { description_ = std::move(d); }
// HUD modules can be dragged around while the menu is open // HUD modules can be dragged around while the menu is open
virtual bool is_hud() const { return false; } virtual bool is_hud() const { return false; }
+5
View File
@@ -22,6 +22,11 @@ public:
if (m->enabled()) m->on_render(); if (m->enabled()) m->on_render();
} }
void frame_end() {
for (auto& m : modules_)
if (m->enabled()) m->on_frame_end();
}
void clear() { void clear() {
for (auto& m : modules_) m->set_enabled(false); for (auto& m : modules_) m->set_enabled(false);
modules_.clear(); modules_.clear();
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include <windows.h>
#include <mmsystem.h>
#include "module.h"
#pragma comment(lib, "winmm.lib")
class optimizations : public module {
public:
optimizations()
: module("Optimizations", "Frame limiter and Windows tweaks for smoother, cooler gameplay.",
category::utility) {
fps_limit_ = &add_int("FPS Limit (0 = off)", 0, 0, 360);
bg_limit_ = &add_int("Background FPS (0 = off)", 15, 0, 60);
priority_ = &add_toggle("High Priority", true);
timer_ = &add_toggle("Precise Timer", true);
throttle_ = &add_toggle("No Power Throttling", true);
}
void on_enable() override { next_frame_ = 0.0; }
void on_disable() override {
if (priority_on_) apply_priority(false);
if (timer_on_) apply_timer(false);
if (throttle_on_) apply_throttling(false);
}
void on_frame_end() override {
if (priority_->bool_value != priority_on_) apply_priority(priority_->bool_value);
if (timer_->bool_value != timer_on_) apply_timer(timer_->bool_value);
if (throttle_->bool_value != throttle_on_) apply_throttling(throttle_->bool_value);
limit_frame();
}
private:
setting* fps_limit_ = nullptr;
setting* bg_limit_ = nullptr;
setting* priority_ = nullptr;
setting* timer_ = nullptr;
setting* throttle_ = nullptr;
bool priority_on_ = false, timer_on_ = false, throttle_on_ = false;
DWORD original_priority_ = 0;
bool priority_saved_ = false;
double next_frame_ = 0.0;
static double now() {
static const double freq = [] { LARGE_INTEGER f; QueryPerformanceFrequency(&f); return (double)f.QuadPart; }();
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
return (double)c.QuadPart / freq;
}
void apply_priority(bool on) {
if (on) {
if (!priority_saved_) {
original_priority_ = GetPriorityClass(GetCurrentProcess());
priority_saved_ = true;
}
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
}
else if (priority_saved_) {
SetPriorityClass(GetCurrentProcess(), original_priority_);
}
priority_on_ = on;
}
void apply_timer(bool on) { // 1 ms sleep granularity, makes the limiter accurate
if (on) timeBeginPeriod(1); else timeEndPeriod(1);
timer_on_ = on;
}
void apply_throttling(bool disable_throttling) { // opt out of Windows' efficiency mode
PROCESS_POWER_THROTTLING_STATE state{};
state.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
state.ControlMask = disable_throttling ? PROCESS_POWER_THROTTLING_EXECUTION_SPEED : 0;
state.StateMask = 0; // 0 = throttling off; ControlMask 0 hands control back to Windows
SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &state, sizeof(state));
throttle_on_ = disable_throttling;
}
void limit_frame() {
const int cap = is_game_focused() ? fps_limit_->int_value : bg_limit_->int_value;
if (cap <= 0) { next_frame_ = 0.0; return; }
const double frame = 1.0 / cap;
const double t = now();
if (next_frame_ < t - frame * 4.0) next_frame_ = t; // fell far behind (alt-tab, hitch): resync
if (next_frame_ > t) { // sleep most of the wait, spin the last ~1.5 ms for accuracy
const double remaining = next_frame_ - t;
if (remaining > 0.002) Sleep((DWORD)((remaining - 0.0015) * 1000.0));
while (now() < next_frame_) YieldProcessor();
}
next_frame_ += frame;
}
};
+66
View File
@@ -0,0 +1,66 @@
#pragma once
#include <cstdio>
#include "module.h"
#include "../gui/fonts.h"
#include "../gui/theme.h"
class watermark : public module {
public:
watermark()
: module("watermark", "self-explanatory", category::hud, VK_F6) {
hud_pos = ImVec2(10.f, 10.f);
background_ = &add_toggle("background", true);
scale_ = &add_float("scale", 1.f, 0.7f, 2.5f);
const ImVec4 fg = theme::fg();
color_ = &add_color("color", fg.x, fg.y, fg.z);
}
bool is_hud() const override { return true; }
ImVec2 hud_size() const override {
const float s = scale_->float_value;
const ImVec2 label = fonts::text_size(fonts::body, fonts::k_body_size, "amnesia");
const ImVec2 value = fonts::text_size(fonts::semibold, fonts::k_body_size, "| welcome, ian | 000 fps | 0 ping"); // fixed width, no jitter
return ImVec2((pad_x * 2.f + label.x + gap + value.x) * s,
(pad_y * 2.f + value.y) * s);
}
void on_render() override {
const float s = scale_->float_value;
const float fs = fonts::k_body_size * s;
char buf[64];
snprintf(buf, sizeof(buf), "| welcome, ian | %.0f fps | 0 ping", ImGui::GetIO().Framerate);
ImDrawList* dl = ImGui::GetBackgroundDrawList();
const ImVec2 size = hud_size();
const ImVec2 q(hud_pos.x + size.x, hud_pos.y + size.y);
if (background_->bool_value) { // a launcher card: Surface fill, Line border
dl->AddRectFilled(hud_pos, q, theme::u32(theme::with_alpha(theme::surface(), 0.85f)), 10.f * s);
dl->AddRect(hud_pos, q, theme::u32(theme::line()), 10.f * s, 0, 1.f);
}
const ImVec2 label = fonts::text_size(fonts::body, fonts::k_body_size, "amnesia");
const float y = hud_pos.y + (size.y - label.y * s) * 0.5f;
float x = hud_pos.x + pad_x * s;
if (!background_->bool_value) { // no card: a soft shadow keeps it readable
const ImU32 shadow = theme::u32(theme::with_alpha(theme::bg(), 0.7f));
dl->AddText(fonts::body, fs, ImVec2(x + s, y + s), shadow, "amnesia");
dl->AddText(fonts::semibold, fs, ImVec2(x + (label.x + gap) * s + s - 5, y + s), shadow, buf);
}
dl->AddText(fonts::body, fs, ImVec2(x, y), theme::u32(theme::muted()), "amnesia");
x += (label.x + gap) * s;
dl->AddText(fonts::semibold, fs, ImVec2(x, y), setting_color(*color_), buf);
}
private:
static constexpr float pad_x = 12.f;
static constexpr float pad_y = 7.f;
static constexpr float gap = 6.f;
setting* background_ = nullptr;
setting* scale_ = nullptr;
setting* color_ = nullptr;
};