Let me see your code.
Lets say I need to hook g_pEngine->pfnPlaySound
g_pEngine->pfnPlaySound = myfunc ( do I need to pass cl_enginefunc_s struct to it or not? )
because return g_pEngine->pfnPlaySound(soound,vol,pitch ) leed to crash . I suppose myfunc shoud be structure* void.
Can someone explain how to do it properly
Let me see your code.
- - - Updated - - -Code:void HookFunction(){ g_pClient->HUD_Redraw = HUD_Redraw; g_pClient->HUD_Frame = HUD_Frame; g_pEngine->pfnPlaySound = plays; //here and void [or what??] plays(const char *sound,float vol, float pitch) { ConsolePrintColor(22, 222, 22, "hook sound %s \n",sound); return g_pEngine->pfnPlaySound(sound, vol, pitch); //wrong }
I found return g_Engine.pfnPlaySound(sound, vol, pitch); is correct
I have another question
if I hook simple command like disconnect
Code:pcmd_t hookdisc; hookdisc = CommandByName("disconnect"); hookdisc->function = (xcommand_t)mydisconnect; void mydisconnect() { how to return original function ? because if I do engine-> clientcmd disconenct it will be infinite loop
Last edited by cspp; 07-07-2019 at 05:47 AM.
First of all, you can't return a void.
Are you sure that your sound parameters are correct?.
Code:int plays(const char *sound,float vol, float pitch) { if(g_pEngine) ConsolePrintColor(22, 222, 22, "Engine Found \n",sound); return g_pEngine->pfnPlaySound(sound, vol, pitch); //wrong }
yes because original func (pfnPlaySound) is void.
so
works well.Code:void plays(const char *sound,float vol, float pitch) { if(!blockplaysound) return g_Engine.pfnPlaySound(sound, vol, pitch); }
Last edited by cspp; 07-08-2019 at 09:06 AM. Reason: updated
Okay, i'm gonna mark this thread as solved. Contact me if you want to re-open it again.
//Solved.