The hook wont refire after you change the params if thats what you mean. The hook fires pre the params are changed the function is then called (but doesnt fire the hook) then the value is returned. Ill give it more testing soon.
Yea, I am getting that side of things. It just doesn't seem to call the function when MRES_ChangedHandled is returned.
I just verified MRES_Handled is the same. It doesn't call the function or fire the posthook.
While a return of MRES_Override or MRES_ChangedOverride does call the function and gives this output:
Fun fact: In TF2, if you attempt to change the classname of a weapon in GiveNamedItem (like TF2Items does), the game will reject that change and give the user nothing instead.
Looks like the string is corrupting on it's way to call the real function.
This hook is in the test plugin so I know it works, however when i tested in csgo it worked but crashed after a few seconds, but it didnt appear dhooks related, it couldnt find the sequence for animations. Here was my output
What I then did (Cause i saw you did this again ) is removed the ByRef. The pointer isnt byref its byval, my byref code could be broken, but im not sure. After removing the ByRef the output was the same but i no longer got the crash from GetSequence after a while and no GetSequence spam in the server console.
// OTHER STUFF U DONT CARE ABOUT UNLES YOU DOUBT MY IMPLEMENTATION :D public void OnPluginStart() { if (!HookOnSetModel()) { SetFailState("Unable to hook SetModel using DHooks"); return; } }
public void OnConfigsExecuted() { // Late loading here is the best place for (int client = 1; client < MaxClients; client++) { if (!IsClientInGame(client)) continue;
OnClientPutInServer(client); } }
public void OnClientPutInServer(client) { if (IsFakeClient(client)) return;
I also tested the GiveNamedItem one now (a simplified version)
output
Dr!fter connected.
Steve connected.
Tom connected.
Nate connected.
==============-----------------> OnGiveNamedItemResetTo(classname=weapon_knife )
===============---------------------> OnGiveNamedItemPost(classname=weapon_knife_bu tterfly, entity=38
==============-----------------> OnGiveNamedItem(classname=weapon_hkp2000)
===============---------------------> OnGiveNamedItemPost(classname=weapon_hkp2000, entity=389)
Ethan connected.
Dustin connected.
Dean connected.
Wyatt connected.
Orin connected.
Nick connected.
==============-----------------> OnGiveNamedItemResetTo(classname=weapon_knife )
===============---------------------> OnGiveNamedItemPost(classname=weapon_knife_bu tterfly, entity=455)
==============-----------------> OnGiveNamedItem(classname=weapon_hkp2000)
===============---------------------> OnGiveNamedItemPost(classname=weapon_hkp2000, entity=456)
Note, I wasnt able to pick up the knife, but I know that CanUse returns false for this. So hooking CanUse on post and returing true if its your knife should do the trick. I think its canUse I tested this a long time ago.
/* * This is a prehook to change the classnames of the item being spawned if required. * -- This stops the animation glitch of some knives as the item is forced to spawn with the correct classtype */ public MRESReturn OnGiveNamedItem(int client, Handle hReturn, Handle hParams) { // Get classname and skip processing if it's not a weapon char classname[64]; DHookGetParamString(hParams, 1, classname, sizeof(classname)); if (StrContains(classname, "weapon_") != 0) return MRES_Ignored;
// Update the classname to weapon_knife_butterly and if successful ... if(StrEqual("weapon_knife", classname)) { PrintToConsole(client, "==============-----------------> OnGiveNamedItemResetTo(classname=%s)", classname);
// Set classname param and let GiveNamedItem process DHookSetParamString(hParams, 1, "weapon_knife_butterfly"); return MRES_ChangedHandled; }
public MRESReturn OnGiveNamedItemPost(int client, Handle hReturn, Handle hParams) { // Get classname and skip processing if it's not a butterfly knife char classname[64]; DHookGetParamString(hParams, 1, classname, sizeof(classname)); if (StrContains(classname, "weapon_") != 0) return MRES_Ignored;
// Skip if the named item index is 0 (this was blocked by the prehook) int weapon = DHookGetReturn(hReturn); PrintToConsole(client, "===============---------------------> OnGiveNamedItemPost(classname=%s, entity=%d)", classname, weapon);
// Skip if it's not a butterfly knife if (StrContains(classname, "weapon_knife_butterfly") != 0) return MRES_Ignored;
// Get definition index int defindex = GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
// Skip if item definitions is already a butterfly knife if (515 == defindex) return MRES_Ignored;
// Set knife definition index to a butterfly knife SetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex", 515); return MRES_Ignored; }
// OTHER STUFF U DONT CARE ABOUT UNLES YOU DOUBT MY IMPLEMENTATION :D public void OnPluginStart() { if (!HookOnGiveNamedItem()) { SetFailState("Unable to hook GiveNamedItem using DHooks"); return; } }
public void OnConfigsExecuted() { // Late loading here is the best place for (int client = 1; client < MaxClients; client++) { if (!IsClientInGame(client)) continue;
OnClientPutInServer(client); } }
public void OnClientPutInServer(client) { if (IsFakeClient(client)) return;