#pragma once #include #include #include namespace memory { class handle { public: handle(void* ptr = nullptr); explicit handle(std::uintptr_t ptr); template std::enable_if_t, T> as(); template std::enable_if_t, T> as(); template std::enable_if_t, T> as(); template handle add(T offset); template handle sub(T offset); handle rip(); explicit operator bool(); friend bool operator==(handle a, handle b); friend bool operator!=(handle a, handle b); private: void* ptr; }; inline handle::handle(void* ptr) : ptr(ptr) {} inline handle::handle(std::uintptr_t ptr) : ptr(reinterpret_cast(ptr)) {} template inline std::enable_if_t, T> handle::as() { return static_cast(ptr); } template inline std::enable_if_t, T> handle::as() { return *static_cast>>(ptr); } template inline std::enable_if_t, T> handle::as() { return reinterpret_cast(ptr); } template inline handle handle::add(T offset) { return handle(as() + offset); } template inline handle handle::sub(T offset) { return handle(as() - offset); } inline handle handle::rip() { return add(as()).add(4); } inline bool operator==(handle a, handle b) { return a.ptr == b.ptr; } inline bool operator!=(handle a, handle b) { return a.ptr != b.ptr; } inline handle::operator bool() { return ptr != nullptr; } }