Using SourceHook
Ive seen some sourcecode I believe it was for sdktools...used for hooking into IVoiceServer.
Ive tried taking the source and hooking into the IVoiceServer myself In my plugin...but I cant get it to work. As soon as I try to do the hook..it crashs I call SH_ADD_HOOK_MEMFUNC(IVoiceServer, SetClientListening, g_pVoiceServer, &g_EmtpyServerPlugin,&CEmptyServerPlugin::OnS etClientListening, false); but am having trouble. Can anyone help me out to be able to hook into the setclientlistening functions so I can set up a proper mute function? |
Re: Using SourceHook
That line looks fine..
Probably need to see the full code to try spot the problem. |
Re: Using SourceHook
I scrapped out the code from sdktools source that I have from somewhere.
I changed it a bit because I dont have a IPluginContext pointer (passing null to test but each use of it is checked). PHP Code:
|
Re: Using SourceHook
Params arrays have the first index (0) as the number of params.
Notice you set t[0] = 4; then int index=params[1]; t[1] is uninitialised.. You don't need the sp_nativeinfo_t since thats just to register the commands as natives. |
Re: Using SourceHook
i actually have it
t[0]=4; t[1]=4; I call the function and step thru it until it does the sh_add_hook_memfunc and it then crashs at the SH_DECL_HOOK3(IVoiceServer, SetClientListening, SH_NOATTRIB, 0, bool, int, int, bool); line of code |
Re: Using SourceHook
Thought that sounded too easy.
One of the pointers you are passing maybe? g_pVoiceServer? |
Re: Using SourceHook
i verified its not null ...
and its appears good in :Load |
Re: Using SourceHook
When I Call the SH_ADD_HOOK_MEMFUNC(IVoiceServer, SetClientListening, g_pVoiceServer,&g_EmtpyServerPlugin,&CEmptySe rverPlugin::OnSetClientListening, false);
g_pVoiceServer is valid, g_EmptyServerPlugin is My main plugin class and is valid as well.. I still dont see why it crashs... with a breakpoint on SH_DECL_HOOK3 it appears to be hooking in ...i see it going thru the macro's etc for fastdelegate etc.. but 3rd time it goes thru sh_decl_hook3 it crashs does the class that I pass in for handler_inst have to be derived from a specific class or something? |
Re: Using SourceHook
The problem is with my not initializing source hook variable
SourceHook::ISourceHook *g_SHPtr How do I initialize sourcehook correctly. Im trying to follow the wiki at http://wiki.alliedmods.net/SourceHoo...t#Simple_Hooks but Im not having much luck. |
Re: Using SourceHook
Is this a metamod plugin or a VSP?
The embedding section on that wiki page suggests that multiple versions of sourcehook in the same process will probably conflict, so not entirely sure how you'd add it to a VSP if metamod is running. If it's metamod you need something like this in your metamod load function: g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); g_PLID = id; or look at the PLUGIN_SAVEVARS() macro in ISmmPlugin.h |
Re: Using SourceHook
its a vsp..
Im trying to find the lastest single version of sourcehook. to learn this on. Ill check out the PLUGIN_SAVEVARS() macro in ISmmPlugin.h |
Re: Using SourceHook
PLUGIN_SAVEVARS() relies on the metamod load forward to get all the pointers, which you won't have.
Have you followed the embedding SourceHook bit at the bottom of that wiki page? |
Re: Using SourceHook
Thats where I'll start ...thanks for the pointer in the right direction.
|
Re: Using SourceHook
where can I download the latest versions of sourcehook...I may have 2 different versions and its not helping matters.
|
Re: Using SourceHook
http://hg.alliedmods.net/mmsource-ce...35/sourcehook/
Click one of the bz2/zip links or use mercurial to check out a copy. |
Re: Using SourceHook
You should really consider using MM:S, conflicting copies of SourceHook in the same address space is really problematic. ESTools does this and it causes conflicts with SourceMod.
One thing to do is what Mani does. VSP version with SourceHook embedded, MM:S version without. This works pretty nicely as the API stays the same. The whole point of SourceHook is to unify hooking (making it easier through macros is just a side effect). If there's multiple SourceHooks, the original purpose is lost :| |
Re: Using SourceHook
Id love to be able to do it that way..
Im still learning alot of this stuff and I dont know if the sourcehook files I have are mixed versions or not.. I have ones that Ive downloaded or have bits and pieces of from other plugins.. At the very least it would be great to get sourcehook going...then once thats working and I (hopefully) better understand its use then I can think about going full mm...but for now I having issues just to get the simple logprint hook to work. So until thats working correctly for me..... |
Re: Using SourceHook
I've had no luck at all getting sourcehook to not crash.
I tried it in both my orangebox version and non orangebox versions. I followed the embedding portion on http://wiki.alliedmods.net/SourceHook_Development without any luck. I included the files ..everything compiles fine. I try just to hook logprint and as soon as I give it a int log_hook = SH_ADD_HOOK(IVEngineServer, LogPrint, engine, SH_STATIC(Hook_LogPrint), false); command it crashs. |
Re: Using SourceHook
With what error? Maybe a call stack would help. Is g_SHPtr valid? Is engine valid? Also make sure g_PLID doesn't change (though that wouldn't crash).
When it crashes on AddHook, it might mean: 1) g_SHPtr is not a valid pointer to a CSourceHookImpl instance 2) Dereferencing the virtual table and the function entry failed. This could be the passed interface pointer not actually being of the same type as the class used for SH_DECL_HOOK 3) If something went wrong it could be a memory access error (vtables are read-only memory, SourceHook uses VirtualProtect to make it read-write, this might fail on some (security) systems). 4) Something I didn't think of at the moment went wrong. |
Re: Using SourceHook
Thanks ..it was g_SHPtr...I mistakenly defined a local copy so the global didnt get set.
Now back to trying to trap the ivoiceserver. Thanks |
Re: Using SourceHook
Im now trying to hook
the WeaponCanUse virtual function SH_DECL_MANUALHOOK1(WeaponCanUseHook, 0, 0, 0, bool, CBaseCombatWeapon *); declared globally i added into clientactive: int Offset=216; SH_MANUALHOOK_RECONFIGURE(WeaponCanUseHook, Offset, 0, 0); SH_ADD_MANUALHOOK_MEMFUNC(WeaponCanUseHook, pBase, &g_EmtpyServerPlugin, &CEmptyServerPlugin::WeaponCanUseFunction, false); and have: bool CEmptyServerPlugin::WeaponCanUseFunction(CBas eCombatWeapon *pWeapon) { RETURN_META_VALUE(MRES_IGNORED, false); } and it appears to hook etc...but when the WeaponCanUseFunction is called it comes up with and ESP problem with parameters not being stored correctly across the function call and Dont know what Im doing wrong. I want to hook if someone can use a specific weapon . What am I doing incorrectly? |
Re: Using SourceHook
Im not sure what I did..but I redid it and now it seems to be working correctly.
Not sure what was wrong..maybe I had the offset wrong or something |
Re: Using SourceHook
Yes, I've had that error when I have the wrong offset or if the function parameters or call type are defined wrong.
|
Re: Using SourceHook
Does anyone know if theres something I need to do with sourcehook and linux.
Ive added a soucehook into the g_VoiceServer to trap the voice comms and it works great in windows. I have one linux box that its being tested on and when I do the sh_add_hook_memfunc it returns a 1 (or number of times Ive hooked it) but the OnSetClientListening function never gets called on the linux box. I would think that if the return value was ok..like it appears to be ..that the hook is in place..or is the return value of 1 when I hook it once incorrect? |
Re: Using SourceHook
anyone know why a hook would work in windows but not in linux???
|
| All times are GMT -4. The time now is 18:40. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.