From c803572e248998cc9d197f84661fea56bebf7346 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 18 Dec 2024 01:19:11 -0500 Subject: [PATCH] Internal Changes --- data/out.h | 68 +++++++++++++++++++++++++++++---------------------- src/method.ts | 5 ++-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/data/out.h b/data/out.h index d622b2c..30b2561 100644 --- a/data/out.h +++ b/data/out.h @@ -15,20 +15,33 @@ #include #include +// 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 -template -class __Function; -template -class __VirtualFunctionInfo { - __VirtualFunctionInfo(T *const addr_, void *const parent_): - addr(addr_), - parent(parent_) {} +struct __VirtualFunctionInfo { + // Constructors + template + __VirtualFunctionInfo(Ret (**const addr_)(Self, Args...), Ret (*const parent_)(Super, Args...)): + addr((void **) addr_), + parent((void *) parent_) {} + template + __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>; }; // Thunks @@ -36,25 +49,32 @@ typedef void *(*thunk_enabler_t)(void *target, void *thunk); extern thunk_enabler_t thunk_enabler; // Function Information +template +class __Function; template class __Function { + // Prevent Copying + __PREVENT_COPY(__Function); + __PREVENT_DESTRUCTION(__Function); + public: // Types - using ptr_type = Ret (*)(Args...); - using type = std::function; - using overwrite_type = std::function; + typedef Ret (*ptr_type)(Args...); + typedef std::function type; + typedef std::function 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 + __Function(const std::string name_, const ptr_type thunk_, ptr_type *const func_, const Parent parent): func(__VirtualFunctionInfo(func_, parent)), - enabled(std::get<__VirtualFunctionInfo>(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>(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> func; + std::variant 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 }} diff --git a/src/method.ts b/src/method.ts index d251def..9cbf7c7 100644 --- a/src/method.ts +++ b/src/method.ts @@ -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;