Raised This Month: $ Target: $400
 0% 

Like what, manual callclasses!


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-14-2006 , 15:07   Like what, manual callclasses!
Reply With Quote #1

Hello people, it's me again.

Today I've decided to implement manual callclasses.

What you need: In fact, the only thing you need to use the new manual callclasses is the newest sourcehook.h from CVS (the one commited today ). You don't need to update sourcemm or anything.

How to use them:

The first thing you need to do is request a manual callclass:

Code:
SourceHook::ManualCallClass *mcc = SH_GET_MCALLCLASS(ptr, size);
Here, ptr is the interface pointer, size is the interface size. Make sure that size is at least sizeof(void*). In fact, almost everyone should use sizeof(void*). I'll say more about size soon.

When you're done with the callclass, release it using SH_RELEASE_CALLCLASS as with normal callclasses.

Assuming that you have declared a manual hook:
Code:
SH_DECL_MANUALHOOK0_void(Some_Hook, vtable index, vtable offset, this ptr offset);
you can now call the original function using:
Code:
SH_MCALL(mcc, Some_Hook)();
You may also want to call a function without having a hook declaration. This is also possible. You first need a MFP that corresponds to that function. The class doesn't matter. I always use SourceHook::EmptyClass, but you can use whatever you want. Let's say your function returns an int and takes 2 parameters, const char * and bool:
Code:
typedef int (SourceHook::EmptyClass::*MFP_MyFunc)(const char *, bool);
Now you can call the function using:
Code:
int ret = SH_MCALL2(mcc, MFP_MyFunc(), vtable index, vtable offset, this pointer offset)("hello", true);
Yes, I know that 99% (probably 100%) of all users will use 0 for vtable offset and this pointer offset. I still included them because someone may find it useful one day. Writing two zeros isn't that much of a problem either.

So, what about the size thing passed to SH_GET_MCALLCLASS ? Well, it should be larger than the maximal sum of vtable offset and this ptr offset you use on that callclass. Whatever, you most likely just need to use sizeof(void*), so that the callclass includes the first machine word (which is usually the vtable pointer) of the object.

Have fun, report problems, if everything works, please say that it works for you.

If you feel like it, you can add info about its usage to the wiki, otherwise I'll do it once I find my password.

Thanks,
your PM.
__________________
hello, i am pm
PM is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode