Raised This Month: $12 Target: $400
 3% 

[SM EXT] Calling a function with its signature.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-23-2016 , 07:46   [SM EXT] Calling a function with its signature.
Reply With Quote #1

I've been unable to find any good answer to this question, so I'm posting here, can someone show me a good example to call function with its signature. Thanks in advance.
__________________
Benoist3012 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-23-2016 , 08:08   Re: [SM EXT] Calling a function with its signature.
Reply With Quote #2

What function do you want to call? The process is different between static and member functions.
__________________
asherkin is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-23-2016 , 10:53   Re: [SM EXT] Calling a function with its signature.
Reply With Quote #3

Oh? Well I want to call the constructor "Path::Path" which a member function if I'm right. I believe an example for both would be appreciated.
__________________

Last edited by Benoist3012; 08-23-2016 at 10:53.
Benoist3012 is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-25-2016 , 15:21   Re: [SM EXT] Calling a function with its signature.
Reply With Quote #4

I too would like to know how to use a signature to call a function from an extension.

Preferably not by firing a forward to pawn to a plugin and have it do an SDKCall from there.
Potato Uno is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 08-25-2016 , 18:18   Re: [SM EXT] Calling a function with its signature.
Reply With Quote #5

A good way to learn is to look at some of the extensions from sourcemod. The cstrike and tf2 extension both make function calls using signatures and I believe some even using offsets (not 100% sure). I know for a fact the cstrike one handles both member calls and non member calls, although following some of the code is weird since in csgo the windows binary is ltcg'd which results in asm being required sometimes.

Ill try to quickly break one down.
https://github.com/alliedmodders/sou...tives.cpp#L339

First we need to create a wrapper for the call.
PHP Code:
static ICallWrapper *pWrapper NULL;

    if (!
pWrapper)
    {
        
REGISTER_NATIVE_ADDR("TerminateRound",
            
PassInfo pass[2]; \
            
pass[0].flags PASSFLAG_BYVAL; \
            
pass[0].type PassType_Basic; \
            
pass[0].size sizeof(float); \
            
pass[1].flags PASSFLAG_BYVAL; \
            
pass[1].type PassType_Basic; \
            
pass[1].size sizeof(int); \
            
pWrapper g_pBinTools->CreateCall(addrCallConv_ThisCallNULLpass2))
    } 
As can be seen it is a member call with 2 params a float and an int. The NULL represents the return you would create a similar PassInfo if you had a return (there is an example in the same file i linked).

PHP Code:
unsigned char vstk[sizeof(void *) + sizeof(float)+ sizeof(int)];
    
unsigned char *vptr vstk;

    *(
void **)vptr gamerules;
    
vptr += sizeof(void *);
    *(
float *)vptr sp_ctof(params[1]);
    
vptr += sizeof(float);
    *(
int*)vptr reason;

    
pWrapper->Execute(vstkNULL); 
Next is creating the stack for the function call and then assign it to the ptr. The size of the stack is |this| ptr (for member calls) + the size of all the arguments. First thing onto the stack is |this| then move forward the size of the pointer add the first param move forward again and add the second param. Then execute the call. The NULL in this case is the return pointer used if there is a return.

Hope that explains it.... sort of. It was a rather quick explanation.
Dr!fter is offline
Reply



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 06:27.


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