Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions loader/include/Geode/loader/Hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ namespace geode {
* @param priority Priority
*/
void setPriority(int32_t priority);

/**
* Get the name of the modify class this hook belongs to, or `std::nullopt` if unavailable.
* This is the final, user-specified (or auto generated) name of the modify class, not the name of the modified class.
* This will not work for manual hooks or hooks in mods compiled with an older version of Geode.
* @returns Name of the modify class this hook belongs to
*/
std::optional<std::string_view> getModifyClassName() const;

/**
* Set the name of the modify class this hook belongs to.
* For internal usage only.
*/
void setModifyClassName(std::string name);
};

class GEODE_DLL Patch final {
Expand Down
7 changes: 7 additions & 0 deletions loader/include/Geode/modify/Modify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Geode/loader/Mod.hpp>
#include <iostream>
#include <tulip/TulipHook.hpp>
#include <arc/future/PollableMetadata.hpp>

#define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressInline_, Convention_, ClassName_, FunctionName_, ...) \
do { \
Expand Down Expand Up @@ -411,6 +412,7 @@ namespace geode::modifier {
ModifyDerived::Derived::onModify(*this);
std::vector<std::string> added;
for (auto& [uuid, hook] : m_hooks) {
hook->setModifyClassName(std::string{ModifyDerived::Derived::SELF_NAME});
auto res = Mod::get()->claimHook(hook);
if (!res) {
log::error("Failed to claim hook {}: {}", hook->getDisplayName(), res.unwrapErr());
Expand Down Expand Up @@ -461,6 +463,11 @@ namespace geode {
public:
using Self = Derived;

static inline constexpr std::string_view SELF_NAME = [] {
auto [ptr, size] = arc::getTypename<Self>();
return std::string_view{ptr, size};
}();

// abusing the internal stuff
// basically we dont want modify to invoke base ctors and dtors
Modify() : Base(CutoffConstructor, sizeof(Base)) {}
Expand Down
8 changes: 8 additions & 0 deletions loader/src/loader/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ int32_t Hook::getPriority() const {
void Hook::setPriority(int32_t priority) {
return m_impl->setPriority(priority);
}

std::optional<std::string_view> Hook::getModifyClassName() const {
return m_impl->getModifyClassName();
}

void Hook::setModifyClassName(std::string name) {
return m_impl->setModifyClassName(std::move(name));
}
10 changes: 10 additions & 0 deletions loader/src/loader/HookImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ void Hook::Impl::setPriority(int32_t priority) {
}
}

std::optional<std::string_view> Hook::Impl::getModifyClassName() const {
return m_modifyClassName.transform([](auto& s) {
return std::string_view{s};
});
}

void Hook::Impl::setModifyClassName(std::string name) {
m_modifyClassName = std::move(name);
}

Result<> Hook::Impl::updateHookMetadata() {
if (!m_enabled) return Ok();
GEODE_UNWRAP_INTO(auto handler, LoaderImpl::get()->getHandler(m_address));
Expand Down
4 changes: 4 additions & 0 deletions loader/src/loader/HookImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Hook::Impl final : ModPatch {
void* m_address;
void* m_detour;
std::string m_displayName;
std::optional<std::string> m_modifyClassName;
tulip::hook::HandlerMetadata m_handlerMetadata;
tulip::hook::HookMetadata m_hookMetadata;
tulip::hook::HookHandle m_handle = 0;
Expand All @@ -60,6 +61,9 @@ class Hook::Impl final : ModPatch {
int32_t getPriority() const;
void setPriority(int32_t priority);

std::optional<std::string_view> getModifyClassName() const;
void setModifyClassName(std::string name);

Result<> updateHookMetadata();

friend class Hook;
Expand Down
Loading