From a99a1f569bc6f72ca9dfdbe64f025ae069c8e679 Mon Sep 17 00:00:00 2001
From: altalk23 <45172705+altalk23@users.noreply.github.com>
Date: Mon, 1 Jan 2024 00:39:34 +0300
Subject: [PATCH] generatedaddress no more

---
 loader/include/Geode/modify/Addresses.hpp |  6 +-
 loader/include/Geode/modify/Modify.hpp    | 99 ++++++++++++-----------
 2 files changed, 54 insertions(+), 51 deletions(-)

diff --git a/loader/include/Geode/modify/Addresses.hpp b/loader/include/Geode/modify/Addresses.hpp
index bea14fdf..4406b4f6 100644
--- a/loader/include/Geode/modify/Addresses.hpp
+++ b/loader/include/Geode/modify/Addresses.hpp
@@ -4,8 +4,8 @@
 #include <tulip/TulipHook.hpp>
 
 namespace geode::modifier {
-    template <uint32_t Id>
-    GEODE_HIDDEN uintptr_t address();
+    // template <uint32_t Id>
+    // GEODE_HIDDEN uintptr_t address();
 
-    Result<tulip::hook::HandlerMetadata> handlerMetadataForAddress(uintptr_t address);
+    // Result<tulip::hook::HandlerMetadata> handlerMetadataForAddress(uintptr_t address);
 }
diff --git a/loader/include/Geode/modify/Modify.hpp b/loader/include/Geode/modify/Modify.hpp
index f0affb59..bc3f1a7b 100644
--- a/loader/include/Geode/modify/Modify.hpp
+++ b/loader/include/Geode/modify/Modify.hpp
@@ -8,58 +8,61 @@
 #include <iostream>
 #include <tulip/TulipHook.hpp>
 
-#define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressIndex_, Convention_, ClassName_, FunctionName_, ...) \
-    do {                                                                                            \
-        if constexpr (Unique::different<                                                            \
-                          Resolve<__VA_ARGS__>::func(&Base::FunctionName_),                         \
-                          Resolve<__VA_ARGS__>::func(&Derived::FunctionName_)>()) {                 \
-            if (address<AddressIndex_>() == 0) {                                                    \
-                log::error(                                                                         \
-                    "Address of {} returned nullptr, can't hook", #ClassName_ "::" #FunctionName_   \
-                );                                                                                  \
-                break;                                                                              \
-            }                                                                                       \
-            auto hook = Hook::create(                                                               \
-                Mod::get(),                                                                         \
-                reinterpret_cast<void*>(address<AddressIndex_>()),                                  \
-                AsStaticFunction_##FunctionName_<                                                   \
-                    Derived,                                                                        \
-                    decltype(Resolve<__VA_ARGS__>::func(&Derived::FunctionName_))>::value,          \
-                #ClassName_ "::" #FunctionName_,                                                    \
-                tulip::hook::TulipConvention::Convention_                                           \
-            );                                                                                      \
-            this->m_hooks[#ClassName_ "::" #FunctionName_] = hook;                                  \
-        }                                                                                           \
+#define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressInline_, Convention_, ClassName_, FunctionName_, ...) \
+    do {                                                                                             \
+        if constexpr (Unique::different<                                                             \
+                          Resolve<__VA_ARGS__>::func(&Base::FunctionName_),                          \
+                          Resolve<__VA_ARGS__>::func(&Derived::FunctionName_)>()) {                  \
+            static auto address = AddressInline_;                                                    \
+            if (address == 0) {                                                                      \
+                log::error(                                                                          \
+                    "Address of {} returned nullptr, can't hook", #ClassName_ "::" #FunctionName_    \
+                );                                                                                   \
+                break;                                                                               \
+            }                                                                                        \
+            auto hook = Hook::create(                                                                \
+                Mod::get(),                                                                          \
+                reinterpret_cast<void*>(address),                                                    \
+                AsStaticFunction_##FunctionName_<                                                    \
+                    Derived,                                                                         \
+                    decltype(Resolve<__VA_ARGS__>::func(&Derived::FunctionName_))>::value,           \
+                #ClassName_ "::" #FunctionName_,                                                     \
+                tulip::hook::TulipConvention::Convention_                                            \
+            );                                                                                       \
+            this->m_hooks[#ClassName_ "::" #FunctionName_] = hook;                                   \
+        }                                                                                            \
     } while (0);
 
-#define GEODE_APPLY_MODIFY_FOR_CONSTRUCTOR(AddressIndex_, Convention_, ClassName_, ...)  \
-    do {                                                                                 \
-        if constexpr (HasConstructor<Derived>) {                                         \
-            auto hook = Hook::create(                                                    \
-                Mod::get(),                                                              \
-                reinterpret_cast<void*>(address<AddressIndex_>()),                       \
-                AsStaticFunction_##constructor<                                          \
-                    Derived,                                                             \
-                    decltype(Resolve<__VA_ARGS__>::func(&Derived::constructor))>::value, \
-                #ClassName_ "::" #ClassName_,                                            \
-                tulip::hook::TulipConvention::Convention_                                \
-            );                                                                           \
-            this->m_hooks[#ClassName_ "::" #ClassName_] = hook;                          \
-        }                                                                                \
+#define GEODE_APPLY_MODIFY_FOR_CONSTRUCTOR(AddressInline_, Convention_, ClassName_, ...)  \
+    do {                                                                                  \
+        if constexpr (HasConstructor<Derived>) {                                          \
+            static auto address = AddressInline_;                                         \
+            auto hook = Hook::create(                                                     \
+                Mod::get(),                                                               \
+                reinterpret_cast<void*>(address),                                         \
+                AsStaticFunction_##constructor<                                           \
+                    Derived,                                                              \
+                    decltype(Resolve<__VA_ARGS__>::func(&Derived::constructor))>::value,  \
+                #ClassName_ "::" #ClassName_,                                             \
+                tulip::hook::TulipConvention::Convention_                                 \
+            );                                                                            \
+            this->m_hooks[#ClassName_ "::" #ClassName_] = hook;                           \
+        }                                                                                 \
     } while (0);
 
-#define GEODE_APPLY_MODIFY_FOR_DESTRUCTOR(AddressIndex_, Convention_, ClassName_)                               \
-    do {                                                                                                        \
-        if constexpr (HasDestructor<Derived>) {                                                                 \
-            auto hook = Hook::create(                                                                           \
-                Mod::get(),                                                                                     \
-                reinterpret_cast<void*>(address<AddressIndex_>()),                                              \
-                AsStaticFunction_##destructor<Derived, decltype(Resolve<>::func(&Derived::destructor))>::value, \
-                #ClassName_ "::" #ClassName_,                                                                   \
-                tulip::hook::TulipConvention::Convention_                                                       \
-            );                                                                                                  \
-            this->m_hooks[#ClassName_ "::" #ClassName_] = hook;                                                 \
-        }                                                                                                       \
+#define GEODE_APPLY_MODIFY_FOR_DESTRUCTOR(AddressInline_, Convention_, ClassName_)                               \
+    do {                                                                                                         \
+        if constexpr (HasDestructor<Derived>) {                                                                  \
+            static auto address = AddressInline_;                                                                \
+            auto hook = Hook::create(                                                                            \
+                Mod::get(),                                                                                      \
+                reinterpret_cast<void*>(address),                                                                \
+                AsStaticFunction_##destructor<Derived, decltype(Resolve<>::func(&Derived::destructor))>::value,  \
+                #ClassName_ "::" #ClassName_,                                                                    \
+                tulip::hook::TulipConvention::Convention_                                                        \
+            );                                                                                                   \
+            this->m_hooks[#ClassName_ "::" #ClassName_] = hook;                                                  \
+        }                                                                                                        \
     } while (0);
 
 namespace geode::modifier {