added fullbright
This commit is contained in:
1 parent
fafeee709f
commit
b1634d195c
21 files changed
+1263
-204
No files matched your search
@@ -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
|
||||
@@ -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";
|
||||
}
|
||||
@@ -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
|
||||
Reference in new issue
Block a user