@@ -432,8 +432,8 @@ class CVTFMHook : public CVTMHook<R, T, Args...>
432432{
433433public:
434434 using Base_t = CVTMHook<R, T, Args...>;
435- using Function_t = R (*)( T, Args...);
436- using Callback_t = std::function<R (T, Args...)>;
435+ using Function_t = std::function< R (T, Args...)> ;
436+ using Functions_t = std::vector<std:: function<R (T, Args...)> >;
437437
438438 // AddHook (by index):
439439 // Installs or appends a callback for a given vtable index.
@@ -452,9 +452,20 @@ class CVTFMHook : public CVTMHook<R, T, Args...>
452452 // b) Retrieves `callbacks`, which is a std::vector<Function_t> stored in sm_vcallbacks.
453453 // c) Iterates through each callback in the vector and invokes it with (pClass, args...).
454454 template <auto METHOD>
455- void AddHook (CVirtualTable pVTable, Callback_t funcCallback) { return AddHook (pVTable, GetVirtualIndex<METHOD>(), funcCallback); }
456- void AddHook (CVirtualTable pVTable, std::ptrdiff_t nIndex, Callback_t funcCallback)
455+ void AddHook (CVirtualTable pVTable, Function_t funcCallback) { return AddHook (pVTable, GetVirtualIndex<METHOD>(), funcCallback); }
456+ void AddHook (CVirtualTable pVTable, std::ptrdiff_t nIndex, Function_t funcCallback)
457457 {
458+ auto found = sm_vcallbacks.find (pVTable);
459+
460+ if (found != sm_vcallbacks.cend ())
461+ {
462+ found->second .push_back (std::move (funcCallback));
463+ }
464+ else
465+ {
466+ sm_vcallbacks.emplace (pVTable, Functions_t{std::move (funcCallback)});
467+ }
468+
458469 Base_t::AddHook (pVTable, nIndex,
459470 +[](T pClass, Args... args) -> R
460471 {
@@ -490,7 +501,7 @@ class CVTFMHook : public CVTMHook<R, T, Args...>
490501 }
491502
492503protected:
493- inline static std::map<CVirtualTable, std::vector<Function_t> > sm_vcallbacks;
504+ inline static std::map<CVirtualTable, Functions_t > sm_vcallbacks;
494505}; // class CVTFHookSet<R, T, Args...>
495506
496507// ========================================================================================
0 commit comments