I'm having a server crash with my feeble attempts to learn how to use DHooks. I'm trying to hook the act of hitting a building with a wrench in TF2. I found the following:
Code:
CBaseObject::OnWrenchHit(CTFPlayer*, CTFWrench*, Vector)
My gamedata looks like this:
Code:
"Games"
{
"tf"
{
"Offsets"
{
"OnWrenchHit"
{
"windows" "356"
"linux" "358"
"mac" "358"
}
}
}
}
And my actual code looks like this:
Code:
public OnPluginStart()
{
AddNormalSoundHook(Hook_EntitySound);
new Handle:temp = LoadGameConfigFile("tf2.blunderatts");
if(temp == INVALID_HANDLE)
{
SetFailState("Why you no has gamedata?");
}
new offset;
offset = GameConfGetOffset(temp, "OnWrenchHit");
hOnWrenchHit = DHookCreate(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnWrenchHit);
DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
DHookAddParam(hOnWrenchHit, HookParamType_CBaseEntity);
DHookAddParam(hOnWrenchHit, HookParamType_Int);
CloseHandle(temp);
}
public OnEntityCreated(entity, const String:classname[])
{
if (StrEqual(classname, "obj_dispenser")
|| StrEqual(classname, "obj_sentrygun")
|| StrEqual(classname, "obj_teleporter"))
{
SDKHook(entity, SDKHook_SpawnPost, OnSpawnPost);
}
}
public void OnSpawnPost(entity)
{
DHookEntity(hOnWrenchHit, false, entity);
}
public MRESReturn OnWrenchHit(pThis, Handle:hParams)
{
PrintToChatAll("Hit with wrench.");
//PrintToChatAll("DHooksHacks = Building %d, Player %d", pThis, DHookGetParam(hParams, 1));
}
The moment an active building is struck with a wrench, the server crashes without even reaching the PrintToChatAll. I tested removing Teleporters from the list, and then the server wouldn't crash when hitting a Teleporter, even when having another building active. I've tried a few different Return Types and have put in the Handle:hReturn when necessary, but no dice. Given the specificness of the crash, it sounds like I'm on the right track. But I'm completely new to DHooks, so I just need a shove in the right direction.
Thanks in advance!