diff --git a/source/common.hxx b/source/common.hxx index bdcc8ebf..27957249 100644 --- a/source/common.hxx +++ b/source/common.hxx @@ -6,7 +6,6 @@ #include "injector/injector.hpp" #include "injector/calling.hpp" #include "injector/hooking.hpp" -#include "injector/assembly.hpp" #include "includes/assembly2.hpp" #include "injector/utility.hpp" #include "Hooking.Patterns.h" diff --git a/source/extrainfo.ixx b/source/extrainfo.ixx index 7eb0c775..0ee50fdc 100644 --- a/source/extrainfo.ixx +++ b/source/extrainfo.ixx @@ -25,7 +25,7 @@ public: { struct MS_PAUSED_HOOK { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { static std::wstring extra = L""; regs.eax += 0x78; @@ -50,7 +50,7 @@ public: regs.eax = (uintptr_t)extra.c_str(); } } - }; injector::MakeInline2(pattern.get_first(0)); + }; injector::MakeInline(pattern.get_first(0)); } } }; diff --git a/source/fixes.ixx b/source/fixes.ixx index 1ef0d58b..48e4aa00 100644 --- a/source/fixes.ixx +++ b/source/fixes.ixx @@ -206,7 +206,7 @@ public: static auto nTimeToWaitBeforeCenteringCameraOnFootPad = FusionFixSettings.GetRef("PREF_PADCAMCENTERDELAY"); struct OnFootCamCenteringHook { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { static float f = 0.0f; f = regs.xmm1.f32[0]; @@ -241,10 +241,10 @@ public: }; if (reg != 0x48) - injector::MakeInline2(pattern.get_first(0), pattern.get_first(6)); + injector::MakeInline(pattern.get_first(0), pattern.get_first(6)); else { - injector::MakeInline2(pattern.get_first(-2), pattern.get_first(6)); + injector::MakeInline(pattern.get_first(-2), pattern.get_first(6)); injector::WriteMemory(pattern.get_first(3), 0xDB85, true); } } diff --git a/source/frameratevigilante.ixx b/source/frameratevigilante.ixx index d589c2e4..85ebf686 100644 --- a/source/frameratevigilante.ixx +++ b/source/frameratevigilante.ixx @@ -30,13 +30,13 @@ public: { struct FramerateVigilanteHook1 { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { float f = std::clamp(*(float*)(regs.ebp + 0x08), 1.0f / 150.0f, FLT_MAX); *(float*)(regs.ebp + 0x08) = f; regs.xmm0.f32[0] = f; } - }; injector::MakeInline2(pattern.get_first(0)); + }; injector::MakeInline(pattern.get_first(0)); } else { @@ -57,11 +57,11 @@ public: static auto f1032790 = *pattern.get_first(4); struct LoadingTextSpeed { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { regs.xmm0.f32[0] = (*f1032790) / 10.0f; } - }; injector::MakeInline2(pattern.get_first(0), pattern.get_first(8)); + }; injector::MakeInline(pattern.get_first(0), pattern.get_first(8)); } pattern = hook::pattern("F3 0F 59 05 ? ? ? ? F3 0F 59 05 ? ? ? ? F3 0F 59 05 ? ? ? ? F3 0F 58 05 ? ? ? ? F3 0F 11 05"); @@ -69,11 +69,11 @@ public: { struct LoadingTextSpeed2 { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { regs.xmm0.f32[0] *= (1000.0f) / 10.0f; } - }; injector::MakeInline2(pattern.get_first(0), pattern.get_first(8)); + }; injector::MakeInline(pattern.get_first(0), pattern.get_first(8)); } pattern = hook::pattern("F3 0F 58 0D ? ? ? ? 0F 5B C0 F3 0F 11 0D"); @@ -81,11 +81,11 @@ public: { struct LoadingTextSparks { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { regs.xmm1.f32[0] += (0.085f) / 10.0f; } - }; injector::MakeInline2(pattern.get_first(0), pattern.get_first(8)); + }; injector::MakeInline(pattern.get_first(0), pattern.get_first(8)); } }; } diff --git a/source/ikeeponwalking.ixx b/source/ikeeponwalking.ixx index e9f0edd5..f776e942 100644 --- a/source/ikeeponwalking.ixx +++ b/source/ikeeponwalking.ixx @@ -27,7 +27,7 @@ public: pattern = hook::pattern("80 F9 7F 76 57"); struct SprintHook { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { if ((*(uint8_t*)(regs.eax + 4) ^ *(uint8_t*)(regs.eax + 6)) <= 127) { @@ -58,7 +58,7 @@ public: else if (shouldRun && !GetAsyncKeyState(nWalkKey)) // hold *(float*)(regs.esp + (flag ? 0x18 : 0x1C)) = 1.0f; } - }; injector::MakeInline2(pattern.get_first(0)); + }; injector::MakeInline(pattern.get_first(0)); pattern = find_pattern("77 5F 8B 8E", "77 46 8B 8F"); static raw_mem GamepadCB(pattern.get_first(0), { 0x90, 0x90 }); // NOP diff --git a/source/includes/assembly2.hpp b/source/includes/assembly2.hpp index 240a6ccd..92a52b79 100644 --- a/source/includes/assembly2.hpp +++ b/source/includes/assembly2.hpp @@ -5,30 +5,29 @@ namespace injector { - // Lowest level stuff (actual assembly) goes on the following namespace - // PRIVATE! Skip this, not interesting for you. - namespace injector_asm2 + using reg_pack = SafetyHookContext; + namespace injector_asm { // Wrapper functor, so the assembly can use some templating template struct wrapper { - static void call(SafetyHookContext* regs) + static void call(reg_pack* regs) { T fun; fun(*regs); } }; - // Constructs a SafetyHookContext and calls the wrapper functor + // Constructs a reg_pack and calls the wrapper functor template // where W is of type wrapper - inline void make_SafetyHookContext_and_call(memory_pointer_tr at) + inline void make_reg_pack_and_call(memory_pointer_tr at) { - static std::unique_ptr pack; - auto m = safetyhook::create_mid(at.get(), [](SafetyHookContext& ctx) + static std::vector pack; + auto m = safetyhook::create_mid(at.get(), [](reg_pack& ctx) { W::call(&ctx); }); - pack.reset(new SafetyHookMid(std::move(m))); + pack.emplace_back(std::move(m)); } }; @@ -37,12 +36,12 @@ namespace injector * Makes inline assembly (but not assembly, an actual functor of type FuncT) at address */ template - void MakeInline2(memory_pointer_tr at) + void MakeInline(memory_pointer_tr at) { MakeNOP(at, 5); - typedef injector_asm2::wrapper functor; + typedef injector_asm::wrapper functor; if(false) functor::call(nullptr); // To instantiate the template, if not done _asm will fail - injector_asm2::make_SafetyHookContext_and_call(at); + injector_asm::make_reg_pack_and_call(at); } /* @@ -50,10 +49,10 @@ namespace injector * Same as above, but it NOPs everything between at and end (exclusive), then performs MakeInline */ template - void MakeInline2(memory_pointer_tr at, memory_pointer_tr end) + void MakeInline(memory_pointer_tr at, memory_pointer_tr end) { MakeRangedNOP(at, end); - MakeInline2(at); + MakeInline(at); } /* @@ -62,7 +61,7 @@ namespace injector * On this case the functor can be passed as argument since there will be one func instance for each at,end not just for each FuncT */ template - void MakeInline2(FuncT func) + void MakeInline(FuncT func) { static std::unique_ptr static_func; static_func.reset(new FuncT(std::move(func))); @@ -70,12 +69,12 @@ namespace injector // Encapsulates the call to static_func struct Caps { - void operator()(SafetyHookContext& regs) + void operator()(reg_pack& regs) { (*static_func)(regs); } }; // Does the actual MakeInline - return MakeInline2(lazy_pointer::get(), lazy_pointer::get()); + return MakeInline(lazy_pointer::get(), lazy_pointer::get()); } /* @@ -83,8 +82,51 @@ namespace injector * Same as above, but (end) is calculated by the length of a call instruction */ template - void MakeInline2(FuncT func) + void MakeInline(FuncT func) { - return MakeInline2(func); + MakeNOP(at, 5); + return MakeInline(func); + } +}; + +namespace injector +{ + static inline constexpr auto JMPSIZE = 14; + static inline constexpr auto CALLSIZE = 16; + + inline injector::memory_pointer_raw MakeAbsCALL64(injector::memory_pointer_tr at, injector::memory_pointer_raw dest, bool vp = true) + { + injector::WriteMemory(at, 0x15FF, vp); + injector::WriteMemory(at + sizeof(uint16_t), 2, vp); + injector::WriteMemory(at + sizeof(uint16_t) + sizeof(uint32_t), 0x08EB, vp); + injector::WriteMemory(at + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint16_t), dest.as_int(), vp); + return at.as_int() + CALLSIZE; + } + + inline injector::memory_pointer_raw MakeAbsJMP64(injector::memory_pointer_tr at, injector::memory_pointer_raw dest, bool vp = true) + { + injector::WriteMemory(at, 0x25FF, vp); + injector::WriteMemory(at + sizeof(uint16_t), 0, vp); + injector::WriteMemory(at + sizeof(uint16_t) + sizeof(uint32_t), dest.as_int(), vp); + return at.as_int() + JMPSIZE; + } + + inline injector::memory_pointer_raw ReadRelativeAddress(memory_pointer_tr at, size_t sizeof_addr = 4, bool vp = true) + { + uintptr_t base = (uintptr_t)GetModuleHandleA(NULL); + switch (sizeof_addr) + { + case 1: return (base + ReadMemory(at, vp)); + case 2: return (base + ReadMemory(at, vp)); + case 4: return (base + ReadMemory(at, vp)); + } + return nullptr; + } + + inline bool UnprotectMemory(memory_pointer_tr addr, size_t size) + { + DWORD out_oldprotect = 0; + return VirtualProtect(addr.get(), size, PAGE_EXECUTE_READWRITE, &out_oldprotect) != 0; } }; + diff --git a/source/rawinput.ixx b/source/rawinput.ixx index b9ca1f24..c996a2f8 100644 --- a/source/rawinput.ixx +++ b/source/rawinput.ixx @@ -228,7 +228,7 @@ public: static auto reg = *pattern.get_first(3); struct CCamFpsWeaponHook { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { auto inv = FusionFixSettings.Get("PREF_INVERT_MOUSE"); static auto ri = FusionFixSettings.GetRef("PREF_RAWINPUT"); @@ -246,14 +246,14 @@ public: } regs.xmm0.f32[0] = *(float*)(ptr + 0x144); } - }; injector::MakeInline2(pattern.get_first(0), pattern.get_first(8)); + }; injector::MakeInline(pattern.get_first(0), pattern.get_first(8)); // First Person Vehicle Camera pattern = find_pattern("F3 0F 10 86 ? ? ? ? F3 0F 10 0D ? ? ? ? 0F 2F C8 76 0F F3 0F 10 0D ? ? ? ? 0F 2F C1", "F3 0F 10 87 ? ? ? ? F3 0F 10 0D ? ? ? ? 0F 2F C8 76 0D F3 0F 10 0D ? ? ? ? 0F 2F C1 77 03 0F 28 C1 F3 0F 11 87"); static auto reg2 = *pattern.get_first(3); struct CCamFollowVehicleHook { - void operator()(SafetyHookContext& regs) + void operator()(injector::reg_pack& regs) { auto inv = FusionFixSettings.Get("PREF_INVERT_MOUSE"); static auto ri = FusionFixSettings.GetRef("PREF_RAWINPUT"); @@ -266,7 +266,7 @@ public: } regs.xmm0.f32[0] = *(float*)(ptr + 0x1B0); } - }; injector::MakeInline2(pattern.get_first(0), pattern.get_first(8)); + }; injector::MakeInline(pattern.get_first(0), pattern.get_first(8)); // Script {