DHooks2 icon indicating copy to clipboard operation
DHooks2 copied to clipboard

Trace / breakpoint trap crash after plugin reload if extension has identical virtual hook

Open nosoop opened this issue 3 years ago • 0 comments

Took me a bit but I got this bug reproduced without hand-patched binary dependencies.

Dump available on Accelerator.

Steps to reproduce

  1. Have TF2Items and the provided plugin installed. The plugin can be late loaded.
  2. Connect a player. bot command works here.
  3. Reload the plugin.
  4. 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;
}

nosoop avatar Nov 15 '21 16:11 nosoop