-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a feature to invert
shift
when selecting easings.
- Loading branch information
1 parent
5160981
commit f6b1fa0
Showing
6 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
|
||
#define NOMINMAX | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
|
||
//--------------------------------------------------------------------- | ||
|
||
namespace memory | ||
{ | ||
class ProtectHelper { | ||
uintptr_t const addr; | ||
size_t const sz; | ||
DWORD old_protect; | ||
|
||
public: | ||
template<class V> requires(!std::is_pointer_v<V>) | ||
ProtectHelper(V address, size_t size) : addr{ static_cast<uintptr_t>(address) }, sz{ size } { | ||
::VirtualProtect(as_ptr(), sz, PAGE_EXECUTE_READWRITE, &old_protect); | ||
} | ||
template<class T> | ||
ProtectHelper(T* address, size_t size = sizeof(T)) : | ||
ProtectHelper{ reinterpret_cast<uintptr_t>(address), size } {} | ||
~ProtectHelper() { | ||
::VirtualProtect(as_ptr(), sz, old_protect, &old_protect); | ||
} | ||
|
||
template<class T> | ||
T& as_ref(ptrdiff_t offset = 0) const { | ||
return *as_ptr<T>(offset); | ||
} | ||
template<class T = void> | ||
T* as_ptr(ptrdiff_t offset = 0) const { | ||
return reinterpret_cast<T*>(addr + offset); | ||
} | ||
size_t size() const { return sz; } | ||
|
||
template<class T, size_t N> | ||
void copy(T const(&src)[N], ptrdiff_t offset = 0) const { | ||
copy(&src[0], N, offset); | ||
} | ||
template<class T> | ||
void copy(T const* src, size_t count_elem, ptrdiff_t offset = 0) const { | ||
if constexpr (!std::is_void_v<T>) count_elem *= sizeof(T); | ||
std::memcpy(as_ptr(offset), src, count_elem); | ||
} | ||
|
||
static void write(auto address, auto data) { | ||
ProtectHelper(address, sizeof(data)).as_ref<decltype(data)>() = data; | ||
} | ||
template<class T, size_t N> | ||
static void copy(auto address, T const(&data)[N]) { | ||
ProtectHelper(address, sizeof(data)).copy(data); | ||
} | ||
}; | ||
|
||
// ff 15 xx xx xx xx // call dword ptr ds:[xxxxxxxx] | ||
// v | ||
// e8 yy yy yy yy // call yyyyyyyy | ||
// 90 // nop | ||
inline void hook_api_call(auto* address, auto* hook_func) | ||
{ | ||
auto const | ||
addr = reinterpret_cast<uintptr_t>(address), | ||
proc = reinterpret_cast<uintptr_t>(hook_func); | ||
|
||
uint8_t code[6]; | ||
code[0] = 0xe8; // call | ||
*reinterpret_cast<uintptr_t*>(&code[1]) = proc - (addr + 5); | ||
code[5] = 0x90; // nop | ||
|
||
ProtectHelper::copy(addr, code); | ||
} | ||
} | ||
|
||
//--------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters