@@ -84,6 +84,7 @@ Callback* PolyHookPlugin::hookDetour(void* pFunc, DataType returnType, std::span
8484 return m_detours.emplace (pFunc, DHook{std::move (detour), std::move (callback)}).first ->second .callback .get ();
8585}
8686
87+ template <typename T>
8788Callback* PolyHookPlugin::hookVirtual (void * pClass, int index, DataType returnType, std::span<const DataType> arguments, uint8_t varIndex) {
8889 if (!pClass || index == -1 )
8990 return nullptr ;
@@ -115,7 +116,7 @@ Callback* PolyHookPlugin::hookVirtual(void* pClass, int index, DataType returnTy
115116
116117 redirectMap[index] = JIT;
117118
118- vtable = std::make_unique<VTableSwapHook >((uint64_t ) pClass, redirectMap, &origVFuncs);
119+ vtable = std::make_unique<T >((uint64_t ) pClass, redirectMap, &origVFuncs);
119120 if (!vtable->hook ()) {
120121 for (auto & [_, cb] : callbacks) {
121122 m_removals.push ({std::move (cb), Clock::now () + 1s});
@@ -130,8 +131,9 @@ Callback* PolyHookPlugin::hookVirtual(void* pClass, int index, DataType returnTy
130131 return callback.get ();
131132}
132133
134+ template <typename T>
133135Callback* PolyHookPlugin::hookVirtual (void * pClass, void * pFunc, DataType returnType, std::span<const DataType> arguments, uint8_t varIndex) {
134- return hookVirtual (pClass, getVirtualTableIndex (pFunc), returnType, arguments, varIndex);
136+ return hookVirtual<T> (pClass, getVirtualIndex (pFunc), returnType, arguments, varIndex);
135137}
136138
137139bool PolyHookPlugin::unhookDetour (void * pFunc) {
@@ -152,6 +154,7 @@ bool PolyHookPlugin::unhookDetour(void* pFunc) {
152154 return false ;
153155}
154156
157+ template <typename T>
155158bool PolyHookPlugin::unhookVirtual (void * pClass, int index) {
156159 if (!pClass || index == -1 )
157160 return false ;
@@ -175,7 +178,7 @@ bool PolyHookPlugin::unhookVirtual(void* pClass, int index) {
175178 return true ;
176179 }
177180
178- vtable = std::make_unique<VTableSwapHook >((uint64_t ) pClass, redirectMap, &origVFuncs);
181+ vtable = std::make_unique<T >((uint64_t ) pClass, redirectMap, &origVFuncs);
179182 if (!vtable->hook ()) {
180183 for (auto & [_, cb] : callbacks) {
181184 m_removals.push ({std::move (cb), Clock::now () + 1s});
@@ -191,8 +194,9 @@ bool PolyHookPlugin::unhookVirtual(void* pClass, int index) {
191194 return false ;
192195}
193196
197+ template <typename T>
194198bool PolyHookPlugin::unhookVirtual (void * pClass, void * pFunc) {
195- return unhookVirtual (pClass, getVirtualTableIndex (pFunc));
199+ return unhookVirtual<T> (pClass, getVirtualIndex (pFunc));
196200}
197201
198202Callback* PolyHookPlugin::findDetour (void * pFunc) const {
@@ -216,7 +220,7 @@ Callback* PolyHookPlugin::findVirtual(void* pClass, int index) const {
216220}
217221
218222Callback* PolyHookPlugin::findVirtual (void * pClass, void * pFunc) const {
219- return findVirtual (pClass, getVirtualTableIndex (pFunc));
223+ return findVirtual (pClass, getVirtualIndex (pFunc));
220224}
221225
222226void PolyHookPlugin::unhookAll () {
@@ -235,7 +239,7 @@ void PolyHookPlugin::unhookAllVirtual(void* pClass) {
235239 }
236240}
237241
238- int PolyHookPlugin::getVirtualTableIndex (void * pFunc, ProtFlag flag) const {
242+ int PolyHookPlugin::getVirtualIndex (void * pFunc, ProtFlag flag) const {
239243 constexpr size_t size = 12 ;
240244
241245 MemoryProtector protector ((uint64_t )pFunc, size, flag, *(MemAccessor*)this );
@@ -348,28 +352,40 @@ PLUGIFY_WARN_IGNORE(4190)
348352#endif
349353
350354extern " C" {
355+ // Detour
351356 PLUGIN_API Callback* HookDetour (void * pFunc, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
352357 return g_polyHookPlugin.hookDetour (pFunc, returnType, arguments, static_cast <uint8_t >(varIndex));
353358 }
354-
355- PLUGIN_API Callback* HookVirtual (void * pClass, int index, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
356- return g_polyHookPlugin.hookVirtual (pClass, index, returnType, arguments, static_cast <uint8_t >(varIndex));
357- }
358-
359- PLUGIN_API Callback* HookVirtualByFunc (void * pClass, void * pFunc, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
360- return g_polyHookPlugin.hookVirtual (pClass, pFunc, returnType, arguments, static_cast <uint8_t >(varIndex));
361- }
362-
363359 PLUGIN_API bool UnhookDetour (void * pFunc) {
364360 return g_polyHookPlugin.unhookDetour (pFunc);
365361 }
366362
367- PLUGIN_API bool UnhookVirtual (void * pClass, int index) {
368- return g_polyHookPlugin.unhookVirtual (pClass, index);
363+ // Virtual (VTableSwapHook)
364+ PLUGIN_API Callback* HookVirtualTable (void * pClass, int index, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
365+ return g_polyHookPlugin.hookVirtual <VTableSwapHook>(pClass, index, returnType, arguments, static_cast <uint8_t >(varIndex));
366+ }
367+ PLUGIN_API Callback* HookVirtualTable2 (void * pClass, void * pFunc, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
368+ return g_polyHookPlugin.hookVirtual <VTableSwapHook>(pClass, pFunc, returnType, arguments, static_cast <uint8_t >(varIndex));
369+ }
370+ PLUGIN_API bool UnhookVirtualTable (void * pClass, int index) {
371+ return g_polyHookPlugin.unhookVirtual <VTableSwapHook>(pClass, index);
372+ }
373+ PLUGIN_API bool UnhookVirtualTable2 (void * pClass, void * pFunc) {
374+ return g_polyHookPlugin.unhookVirtual <VTableSwapHook>(pClass, pFunc);
369375 }
370376
371- PLUGIN_API bool UnhookVirtualByFunc (void * pClass, void * pFunc) {
372- return g_polyHookPlugin.unhookVirtual (pClass, pFunc);
377+ // Virtual (VFuncSwapHook)
378+ PLUGIN_API Callback* HookVirtualFunc (void * pClass, int index, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
379+ return g_polyHookPlugin.hookVirtual <VFuncSwapHook>(pClass, index, returnType, arguments, static_cast <uint8_t >(varIndex));
380+ }
381+ PLUGIN_API Callback* HookVirtualFunc2 (void * pClass, void * pFunc, DataType returnType, const plg::vector<DataType>& arguments, int varIndex) {
382+ return g_polyHookPlugin.hookVirtual <VFuncSwapHook>(pClass, pFunc, returnType, arguments, static_cast <uint8_t >(varIndex));
383+ }
384+ PLUGIN_API bool UnhookVirtualFunc (void * pClass, int index) {
385+ return g_polyHookPlugin.unhookVirtual <VFuncSwapHook>(pClass, index);
386+ }
387+ PLUGIN_API bool UnhookVirtualFunc2 (void * pClass, void * pFunc) {
388+ return g_polyHookPlugin.unhookVirtual <VFuncSwapHook>(pClass, pFunc);
373389 }
374390
375391 PLUGIN_API Callback* FindDetour (void * pFunc) {
@@ -380,12 +396,12 @@ extern "C" {
380396 return g_polyHookPlugin.findVirtual (pClass, index);
381397 }
382398
383- PLUGIN_API Callback* FindVirtualByFunc (void * pClass, void * pFunc) {
399+ PLUGIN_API Callback* FindVirtual2 (void * pClass, void * pFunc) {
384400 return g_polyHookPlugin.findVirtual (pClass, pFunc);
385401 }
386402
387- PLUGIN_API int GetVTableIndex (void * pFunc) {
388- return g_polyHookPlugin.getVirtualTableIndex (pFunc);
403+ PLUGIN_API int GetVirtualIndex (void * pFunc) {
404+ return g_polyHookPlugin.getVirtualIndex (pFunc);
389405 }
390406
391407 PLUGIN_API void UnhookAll () {
0 commit comments