DHooks2
DHooks2 copied to clipboard
Trace / breakpoint trap crash after plugin reload if extension has identical virtual hook
Took me a bit but I got this bug reproduced without hand-patched binary dependencies.
Dump available on Accelerator.
Steps to reproduce
- Have TF2Items and the provided plugin installed. The plugin can be late loaded.
- Connect a player.
botcommand works here. - Reload the plugin.
- Add another player. Observed result is server crashing with a "Trace / breakpoint trap" message.
Source code
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <dhooks>
#pragma newdecls required
Handle g_DHookGiveNamedItem;
public void OnPluginStart() {
Handle hGameConf = LoadGameConfigFile("tf2.items");
if (!hGameConf) {
SetFailState("Failed to load gamedata (tf2.items).");
}
g_DHookGiveNamedItem = DHookCreate(GameConfGetOffset(hGameConf, "GiveNamedItem"),
HookType_Entity, ReturnType_Unknown, ThisPointer_CBaseEntity,
.callback = OnGivePlayerItemPre);
DHookAddParam(g_DHookGiveNamedItem, HookParamType_CharPtr);
DHookAddParam(g_DHookGiveNamedItem, HookParamType_Int);
DHookAddParam(g_DHookGiveNamedItem, HookParamType_Int);
DHookAddParam(g_DHookGiveNamedItem, HookParamType_Bool);
delete hGameConf;
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i)) {
OnClientPutInServer(i);
}
}
}
public void OnClientPutInServer(int client) {
DHookEntity(g_DHookGiveNamedItem, false, client);
}
MRESReturn OnGivePlayerItemPre(int client, Handle hReturn, Handle hParams) {
return MRES_Ignored;
}