Skip to content

Commit 323e9de

Browse files
committed
chore(modules): Downgrade Dynhook
1 parent 54c73f8 commit 323e9de

File tree

113 files changed

+2665
-5336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2665
-5336
lines changed

src/plugins/core/scripting.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
#include "cstrike15_usermessages.pb.h"
99
#include <google/protobuf/message.h>
1010

11+
#include <dynohook/platform.h>
1112
#include <dynohook/core.h>
1213
#include <dynohook/manager.h>
13-
#include <dynohook/conventions/x64_systemV_call.h>
14+
#ifdef _WIN32
15+
#include <dynohook/conventions/x64/x64MsFastcall.h>
16+
#else
17+
#include <dynohook/conventions/x64/x64SystemVcall.h>
18+
#endif
1419

1520
#include <any>
1621

@@ -122,12 +127,12 @@ class PluginEvent
122127
private:
123128
std::string plugin_name;
124129
IGameEvent *gameEvent;
125-
dyno::IHook *hookPtr;
130+
dyno::Hook *hookPtr;
126131

127132
std::any returnValue;
128133

129134
public:
130-
PluginEvent(std::string m_plugin_name, IGameEvent *m_gameEvent, dyno::IHook *m_hookPtr);
135+
PluginEvent(std::string m_plugin_name, IGameEvent *m_gameEvent, dyno::Hook *m_hookPtr);
131136
~PluginEvent();
132137

133138
std::string GetInvokingPlugin();

src/plugins/core/scripting/events.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
typedef IGameEventListener2 *(*GetLegacyGameEventListener)(CPlayerSlot slot);
66

7-
extern std::map<dyno::IHook *, std::vector<Hook>> hooksList;
7+
extern std::map<dyno::Hook *, std::vector<Hook>> hooksList;
88

9-
PluginEvent::PluginEvent(std::string m_plugin_name, IGameEvent *m_gameEvent, dyno::IHook *m_hookPtr)
9+
PluginEvent::PluginEvent(std::string m_plugin_name, IGameEvent *m_gameEvent, dyno::Hook *m_hookPtr)
1010
{
1111
this->plugin_name = m_plugin_name;
1212
this->gameEvent = m_gameEvent;
@@ -324,39 +324,39 @@ void PluginEvent::SetHookReturn(std::any value)
324324
try
325325
{
326326
if (value.type() == typeid(const char *))
327-
return this->hookPtr->setReturn(std::any_cast<const char *>(value));
327+
return this->hookPtr->setReturnValue(std::any_cast<const char *>(value));
328328
else if (value.type() == typeid(std::string))
329-
return this->hookPtr->setReturn(std::any_cast<std::string>(value).c_str());
329+
return this->hookPtr->setReturnValue(std::any_cast<std::string>(value).c_str());
330330
else if (value.type() == typeid(uint64))
331-
return this->hookPtr->setReturn(std::any_cast<uint64>(value));
331+
return this->hookPtr->setReturnValue(std::any_cast<uint64>(value));
332332
else if (value.type() == typeid(uint32))
333-
return this->hookPtr->setReturn(std::any_cast<uint32>(value));
333+
return this->hookPtr->setReturnValue(std::any_cast<uint32>(value));
334334
else if (value.type() == typeid(unsigned long))
335-
return this->hookPtr->setReturn(std::any_cast<unsigned long>(value));
335+
return this->hookPtr->setReturnValue(std::any_cast<unsigned long>(value));
336336
else if (value.type() == typeid(uint16))
337-
return this->hookPtr->setReturn(std::any_cast<uint16>(value));
337+
return this->hookPtr->setReturnValue(std::any_cast<uint16>(value));
338338
else if (value.type() == typeid(uint8))
339-
return this->hookPtr->setReturn(std::any_cast<uint8>(value));
339+
return this->hookPtr->setReturnValue(std::any_cast<uint8>(value));
340340
else if (value.type() == typeid(int64))
341-
return this->hookPtr->setReturn(std::any_cast<int64>(value));
341+
return this->hookPtr->setReturnValue(std::any_cast<int64>(value));
342342
else if (value.type() == typeid(int32))
343-
return this->hookPtr->setReturn(std::any_cast<int32>(value));
343+
return this->hookPtr->setReturnValue(std::any_cast<int32>(value));
344344
else if (value.type() == typeid(long))
345-
return this->hookPtr->setReturn(std::any_cast<long>(value));
345+
return this->hookPtr->setReturnValue(std::any_cast<long>(value));
346346
else if (value.type() == typeid(int16))
347-
return this->hookPtr->setReturn(std::any_cast<int16>(value));
347+
return this->hookPtr->setReturnValue(std::any_cast<int16>(value));
348348
else if (value.type() == typeid(int8))
349-
return this->hookPtr->setReturn(std::any_cast<int8>(value));
349+
return this->hookPtr->setReturnValue(std::any_cast<int8>(value));
350350
else if (value.type() == typeid(bool))
351-
return this->hookPtr->setReturn(std::any_cast<bool>(value));
351+
return this->hookPtr->setReturnValue(std::any_cast<bool>(value));
352352
else if (value.type() == typeid(float))
353-
return this->hookPtr->setReturn(std::any_cast<float>(value));
353+
return this->hookPtr->setReturnValue(std::any_cast<float>(value));
354354
else if (value.type() == typeid(void *))
355-
return this->hookPtr->setReturn(std::any_cast<void *>(value));
355+
return this->hookPtr->setReturnValue(std::any_cast<void *>(value));
356356
else if (value.type() == typeid(double))
357-
return this->hookPtr->setReturn(std::any_cast<double>(value));
357+
return this->hookPtr->setReturnValue(std::any_cast<double>(value));
358358
else if (value.type() == typeid(std::nullptr_t))
359-
return this->hookPtr->setReturn(0);
359+
return this->hookPtr->setReturnValue(0);
360360
else
361361
PRINTF("Unknown Data Type: %s\n", value.type().name());
362362
}
@@ -409,25 +409,25 @@ std::any PluginEvent::GetHookReturn()
409409
if (hk.retType.at(0) == 'p')
410410
{
411411
PluginMemory mem;
412-
mem.LoadFromPtr(this->hookPtr->getReturn<void *>());
412+
mem.LoadFromPtr(this->hookPtr->getReturnValue<void *>());
413413
return mem.GetPtr();
414414
}
415415
else if (hk.retType.at(0) == 'f')
416-
return this->hookPtr->getReturn<float>();
416+
return this->hookPtr->getReturnValue<float>();
417417
else if (hk.retType.at(0) == 'b')
418-
return this->hookPtr->getReturn<bool>();
418+
return this->hookPtr->getReturnValue<bool>();
419419
else if (hk.retType.at(0) == 'd')
420-
return this->hookPtr->getReturn<double>();
420+
return this->hookPtr->getReturnValue<double>();
421421
else if (hk.retType.at(0) == 'i')
422-
return this->hookPtr->getReturn<int32_t>();
422+
return this->hookPtr->getReturnValue<int32_t>();
423423
else if (hk.retType.at(0) == 'u')
424-
return this->hookPtr->getReturn<uint32_t>();
424+
return this->hookPtr->getReturnValue<uint32_t>();
425425
else if (hk.retType.at(0) == 's')
426-
return this->hookPtr->getReturn<const char *>();
426+
return this->hookPtr->getReturnValue<const char *>();
427427
else if (hk.retType.at(0) == 'I')
428-
return this->hookPtr->getReturn<int64_t>();
428+
return this->hookPtr->getReturnValue<int64_t>();
429429
else if (hk.retType.at(0) == 'U')
430-
return this->hookPtr->getReturn<uint64_t>();
430+
return this->hookPtr->getReturnValue<uint64_t>();
431431
else
432432
{
433433
PRINTF("Invalid argument in return value: '%c'.\n", hk.retType.at(0));

src/plugins/core/scripting/hooks.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
#include <dynohook/core.h>
55
#include <dynohook/manager.h>
6-
#include <dynohook/conventions/x64_systemV_call.h>
6+
7+
#ifdef _WIN32
8+
#include <dynohook/conventions/x64/x64MsFastcall.h>
9+
#else
10+
#include <dynohook/conventions/x64/x64SystemVcall.h>
11+
#endif
712

813
#include <dyncall/dyncall.h>
914

@@ -15,8 +20,10 @@ std::map<OutputPair_t, std::vector<std::string>> outputHooksList;
1520
void Hook_FireOutputInternal(CEntityIOOutput *const pThis, CEntityInstance *pActivator, CEntityInstance *pCaller, const CVariant *const value, float flDelay);
1621
FuncHook<decltype(Hook_FireOutputInternal)> TFireOutputInternal(Hook_FireOutputInternal, "FireOutputInternal");
1722

18-
std::map<dyno::IHook *, std::vector<Hook>> hooksList;
19-
std::map<std::string, dyno::IHook *> hooksMap;
23+
DCCallVM *pCallVM = dcNewCallVM(4096);
24+
25+
std::map<dyno::Hook *, std::vector<Hook>> hooksList;
26+
std::map<std::string, dyno::Hook *> hooksMap;
2027

2128
PluginHooks::PluginHooks(std::string plugin_name)
2229
{
@@ -69,10 +76,10 @@ std::vector<dyno::DataObject> ConvertDT(const std::vector<DataType_t> dataTypes)
6976
return converted;
7077
}
7178

72-
dyno::ReturnAction DynHookHandler(dyno::CallbackType hookType, dyno::IHook &hook)
79+
dyno::ReturnAction DynHookHandler(dyno::HookType hookType, dyno::Hook &hook)
7380
{
74-
dyno::IHook *hookPtr = &hook;
75-
std::string callbackType = (hookType == dyno::CallbackType::Pre ? "Pre" : "Post");
81+
dyno::Hook *hookPtr = &hook;
82+
std::string callbackType = (hookType == dyno::HookType::Pre ? "Pre" : "Post");
7683
if (hooksList.find(hookPtr) == hooksList.end())
7784
return dyno::ReturnAction::Ignored;
7885

@@ -121,10 +128,15 @@ std::string PluginHooks::AddHook(PluginMemory mem, std::string args_list, std::s
121128

122129
std::vector<DataType_t> argTypes = ParseArgsList(args_list);
123130

124-
dyno::IHookManager &manager = dyno::HookManager::Get();
125-
dyno::IHook *hook = manager.hookDetour(funcPtr, [argTypes, ret_type]
126-
{ return new dyno::x64SystemVcall(ConvertDT(argTypes), static_cast<dyno::DataType>(ParseArgsList(ret_type)[0])); })
127-
.get();
131+
dyno::HookManager &manager = dyno::HookManager::Get();
132+
dyno::Hook *hook = manager.hook(funcPtr, [argTypes, ret_type]
133+
{
134+
#ifdef _WIN32
135+
return new dyno::x64MsFastcall(ConvertDT(argTypes), static_cast<dyno::DataType>(ParseArgsList(ret_type)[0]));
136+
#else
137+
return new dyno::x64SystemVcall(ConvertDT(argTypes), static_cast<dyno::DataType>(ParseArgsList(ret_type)[0]));
138+
#endif
139+
});
128140

129141
if (hooksList.find(hook) == hooksList.end())
130142
hooksList.insert({hook, {}});
@@ -136,8 +148,8 @@ std::string PluginHooks::AddHook(PluginMemory mem, std::string args_list, std::s
136148
else
137149
hooksMap[id] = hook;
138150

139-
hook->addCallback(dyno::CallbackType::Pre, DynHookHandler);
140-
hook->addCallback(dyno::CallbackType::Post, DynHookHandler);
151+
hook->addCallback(dyno::HookType::Pre, (dyno::HookHandler *)&DynHookHandler);
152+
hook->addCallback(dyno::HookType::Post, (dyno::HookHandler *)&DynHookHandler);
141153
return id;
142154
}
143155

@@ -166,8 +178,6 @@ luabridge::LuaRef PluginHooks::CallHookLua(std::string hookId, std::string hookP
166178
args.push_back(main_obj.via.array.ptr[i]);
167179
}
168180

169-
DCCallVM *pCallVM = dcNewCallVM(4096);
170-
171181
dcReset(pCallVM);
172182
dcMode(pCallVM, DC_CALL_C_DEFAULT);
173183

@@ -177,7 +187,7 @@ luabridge::LuaRef PluginHooks::CallHookLua(std::string hookId, std::string hookP
177187
break;
178188

179189
if (hk.argsList.at(i) == 'p')
180-
dcArgPointer(pCallVM, (void *)(strtol(args[i].as<std::string>().c_str(), nullptr, 16)));
190+
dcArgPointer(pCallVM, (void *)strtol(args[i].as<std::string>().c_str(), nullptr, 16));
181191
else if (hk.argsList.at(i) == 'f')
182192
dcArgFloat(pCallVM, args[i].as<float>());
183193
else if (hk.argsList.at(i) == 'b')
@@ -231,8 +241,6 @@ luabridge::LuaRef PluginHooks::CallHookLua(std::string hookId, std::string hookP
231241
retval = nullptr;
232242
}
233243

234-
dcFree(pCallVM);
235-
236244
return LuaSerializeData(retval, L);
237245
}
238246

0 commit comments

Comments
 (0)