Internal Changes
This commit is contained in:
parent
308a36b4ba
commit
c803572e24
66
data/out.h
66
data/out.h
@ -15,20 +15,33 @@
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
|
||||
// Internal Macros
|
||||
#define __PREVENT_DESTRUCTION(self) \
|
||||
~self() = delete
|
||||
#define __PREVENT_CONSTRUCTION(self) \
|
||||
self() = delete; \
|
||||
__PREVENT_DESTRUCTION(self)
|
||||
#define __PREVENT_COPY(self) \
|
||||
self(const self &) = delete; \
|
||||
self &operator=(const self &) = delete
|
||||
|
||||
// Virtual Function Information
|
||||
struct __VirtualFunctionInfo {
|
||||
// Constructors
|
||||
template <typename Ret, typename Self, typename Super, typename... Args>
|
||||
__VirtualFunctionInfo(Ret (**const addr_)(Self, Args...), Ret (*const parent_)(Super, Args...)):
|
||||
addr((void **) addr_),
|
||||
parent((void *) parent_) {}
|
||||
template <typename T>
|
||||
class __Function;
|
||||
template <typename T>
|
||||
class __VirtualFunctionInfo {
|
||||
__VirtualFunctionInfo(T *const addr_, void *const parent_):
|
||||
addr(addr_),
|
||||
parent(parent_) {}
|
||||
__VirtualFunctionInfo(T **const addr_, const std::nullptr_t parent_):
|
||||
__VirtualFunctionInfo(addr_, (T *) parent_) {}
|
||||
// Method
|
||||
[[nodiscard]] bool can_overwrite() const {
|
||||
return ((void *) *addr) != parent;
|
||||
return *addr != parent;
|
||||
}
|
||||
T *const addr;
|
||||
// Properties
|
||||
void **const addr;
|
||||
void *const parent;
|
||||
friend class __Function<std::remove_pointer_t<T>>;
|
||||
};
|
||||
|
||||
// Thunks
|
||||
@ -36,25 +49,32 @@ typedef void *(*thunk_enabler_t)(void *target, void *thunk);
|
||||
extern thunk_enabler_t thunk_enabler;
|
||||
|
||||
// Function Information
|
||||
template <typename T>
|
||||
class __Function;
|
||||
template <typename Ret, typename... Args>
|
||||
class __Function<Ret(Args...)> {
|
||||
// Prevent Copying
|
||||
__PREVENT_COPY(__Function);
|
||||
__PREVENT_DESTRUCTION(__Function);
|
||||
|
||||
public:
|
||||
// Types
|
||||
using ptr_type = Ret (*)(Args...);
|
||||
using type = std::function<Ret(Args...)>;
|
||||
using overwrite_type = std::function<Ret(const type &, Args...)>;
|
||||
typedef Ret (*ptr_type)(Args...);
|
||||
typedef std::function<Ret(Args...)> type;
|
||||
typedef std::function<Ret(const type &, Args...)> overwrite_type;
|
||||
|
||||
// Normal Function
|
||||
__Function(const char *const name_, const ptr_type func_, const ptr_type thunk_):
|
||||
__Function(const std::string name_, const ptr_type thunk_, const ptr_type func_):
|
||||
func(func_),
|
||||
enabled(true),
|
||||
name(name_),
|
||||
backup(func_),
|
||||
thunk(thunk_) {}
|
||||
// Virtual Function
|
||||
__Function(const char *const name_, ptr_type *const func_, void *const parent, const ptr_type thunk_):
|
||||
template <typename Parent>
|
||||
__Function(const std::string name_, const ptr_type thunk_, ptr_type *const func_, const Parent parent):
|
||||
func(__VirtualFunctionInfo(func_, parent)),
|
||||
enabled(std::get<__VirtualFunctionInfo<ptr_type>>(func).can_overwrite()),
|
||||
enabled(std::get<__VirtualFunctionInfo>(func).can_overwrite()),
|
||||
name(name_),
|
||||
backup(*get_vtable_addr()),
|
||||
thunk(thunk_) {}
|
||||
@ -91,7 +111,7 @@ public:
|
||||
}
|
||||
}
|
||||
[[nodiscard]] ptr_type *get_vtable_addr() const {
|
||||
return std::get<__VirtualFunctionInfo<ptr_type>>(func).addr;
|
||||
return (ptr_type *) std::get<__VirtualFunctionInfo>(func).addr;
|
||||
}
|
||||
[[nodiscard]] type get_thunk_target() const {
|
||||
if (thunk_target) {
|
||||
@ -103,7 +123,7 @@ public:
|
||||
|
||||
private:
|
||||
// Current Function
|
||||
std::variant<ptr_type, __VirtualFunctionInfo<ptr_type>> func;
|
||||
std::variant<ptr_type, __VirtualFunctionInfo> func;
|
||||
[[nodiscard]] bool is_virtual() const {
|
||||
return func.index() == 1;
|
||||
}
|
||||
@ -111,7 +131,7 @@ private:
|
||||
public:
|
||||
// State
|
||||
const bool enabled;
|
||||
const char *const name;
|
||||
const std::string name;
|
||||
|
||||
// Backup Of Original Function Pointer
|
||||
const ptr_type backup;
|
||||
@ -137,16 +157,6 @@ typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
|
||||
// Internal Macros
|
||||
#define __PREVENT_DESTRUCTION(self) \
|
||||
~self() = delete
|
||||
#define __PREVENT_CONSTRUCTION(self) \
|
||||
self() = delete; \
|
||||
__PREVENT_DESTRUCTION(self)
|
||||
#define __PREVENT_COPY(self) \
|
||||
self(const self &) = delete; \
|
||||
self &operator=(const self &) = delete
|
||||
|
||||
// Forward Declarations
|
||||
{{ forwardDeclarations }}
|
||||
|
||||
|
@ -56,13 +56,14 @@ export class Method {
|
||||
out += `${type} *const ${this.getName()}`;
|
||||
if (code) {
|
||||
out += ` = new ${type}(${JSON.stringify(this.getName('::'))}, `;
|
||||
out += `${INTERNAL}thunk<&${this.getName()}>, `;
|
||||
if (isVirtual) {
|
||||
const parentMethod = parentSelf ? `(void *) ${this.#getVirtualCall(parentSelf)}` : 'nullptr';
|
||||
const parentMethod = parentSelf ? this.#getVirtualCall(parentSelf) : 'nullptr';
|
||||
out += `&${this.#getVirtualCall()}, ${parentMethod}`;
|
||||
} else {
|
||||
out += `(${this.#getRawType()} *) ${toHex(this.address)}`;
|
||||
}
|
||||
out += `, ${INTERNAL}thunk<&${this.getName()}>)`;
|
||||
out += ')';
|
||||
}
|
||||
out += ';\n';
|
||||
return out;
|
||||
|
Loading…
Reference in New Issue
Block a user