File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ Result<> Hook::Impl::enable() {
82
82
Result<> Hook::Impl::disable () {
83
83
if (!m_enabled)
84
84
return Ok ();
85
- GEODE_UNWRAP_INTO (auto handler, LoaderImpl::get ()->getHandler (m_address));
85
+ GEODE_UNWRAP_INTO (auto handler, LoaderImpl::get ()->getOrRemoveHandler (m_address));
86
86
tulip::hook::removeHook (handler, m_handle);
87
87
m_enabled = false ;
88
88
log::debug (" Disabled {} hook" , m_displayName);
Original file line number Diff line number Diff line change @@ -948,15 +948,29 @@ Result<tulip::hook::HandlerHandle> Loader::Impl::getHandler(void* address) {
948
948
if (!m_handlerHandles.count (address)) {
949
949
return Err (" Handler does not exist at address" );
950
950
}
951
- return Ok (m_handlerHandles[address]);
951
+ return Ok (m_handlerHandles[address]. first );
952
952
}
953
953
954
954
Result<tulip::hook::HandlerHandle> Loader::Impl::getOrCreateHandler (void * address, tulip::hook::HandlerMetadata const & metadata) {
955
955
if (m_handlerHandles.count (address)) {
956
- return Ok (m_handlerHandles[address]);
956
+ m_handlerHandles[address].second ++;
957
+ return Ok (m_handlerHandles[address].first );
957
958
}
958
959
GEODE_UNWRAP_INTO (auto handle, tulip::hook::createHandler (address, metadata));
959
- m_handlerHandles[address] = handle;
960
+ m_handlerHandles[address].first = handle;
961
+ m_handlerHandles[address].second = 1 ;
962
+ return Ok (handle);
963
+ }
964
+
965
+ Result<tulip::hook::HandlerHandle> Loader::Impl::getOrRemoveHandler (void * address) {
966
+ if (!m_handlerHandles.count (address)) {
967
+ return Err (" Handler does not exist at address" );
968
+ }
969
+ auto handle = m_handlerHandles[address].first ;
970
+ if (m_handlerHandles[address].second == 1 ) {
971
+ GEODE_UNWRAP (tulip::hook::removeHandler (handle));
972
+ }
973
+ m_handlerHandles[address].second --;
960
974
return Ok (handle);
961
975
}
962
976
Original file line number Diff line number Diff line change @@ -68,10 +68,11 @@ namespace geode {
68
68
Mod* takeNextMod ();
69
69
void releaseNextMod ();
70
70
71
- std::unordered_map<void *, tulip::hook::HandlerHandle> m_handlerHandles;
71
+ std::unordered_map<void *, std::pair< tulip::hook::HandlerHandle, size_t > > m_handlerHandles;
72
72
73
73
Result<tulip::hook::HandlerHandle> getHandler (void * address);
74
74
Result<tulip::hook::HandlerHandle> getOrCreateHandler (void * address, tulip::hook::HandlerMetadata const & metadata);
75
+ Result<tulip::hook::HandlerHandle> getOrRemoveHandler (void * address);
75
76
76
77
bool loadHooks ();
77
78
You can’t perform that action at this time.
0 commit comments