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

VirtualTable pointer


Post New Thread Reply   
 
Thread Tools Display Modes
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-30-2015 , 08:49   Re: VirtualTable pointer
Reply With Quote #11

So, if I make vphooks for two CCSPlayer instances, the hook will fires for each of them twice (4 times in total)?
kadet.89 is offline
Send a message via Skype™ to kadet.89
donrevan
AlliedModders Donor
Join Date: Jul 2010
Old 05-30-2015 , 17:13   Re: VirtualTable pointer
Reply With Quote #12

I updated my snippet. Two different CCSPlayer instances share the same vtable so vphooking both results in the hook callback being executed twice.

Last edited by donrevan; 05-30-2015 at 17:15.
donrevan is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-31-2015 , 15:01   Re: VirtualTable pointer
Reply With Quote #13

PHP Code:
SH_ADD_MANUALVPHOOK(SetEntityModelHookpEntitySH_MEMBER(&g_interface, &Sample::SetEntityModel), false); 
I've just tried to use this hook and it only fires for the hooked instance. But SH_ADD_VPHOOK works just fine for every instance

Last edited by kadet.89; 05-31-2015 at 15:02.
kadet.89 is offline
Send a message via Skype™ to kadet.89
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 06-02-2015 , 01:25   Re: VirtualTable pointer
Reply With Quote #14

Quote:
Originally Posted by kadet.89 View Post
PHP Code:
SH_ADD_MANUALVPHOOK(SetEntityModelHookpEntitySH_MEMBER(&g_interface, &Sample::SetEntityModel), false); 
I've just tried to use this hook and it only fires for the hooked instance. But SH_ADD_VPHOOK works just fine for every instance
https://mxr.alliedmods.net/sourcemod...ension.cpp#714 Works for me, hum. Do you have any code?
KyleS is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 06-07-2015 , 14:19   Re: VirtualTable pointer
Reply With Quote #15

PHP Code:
SH_DECL_MANUALHOOK1_void(SetEntityModelHook000, const char *);
.....

bool Sample::SDK_OnLoad(char *errorsize_t maxlengthbool late)
{
....
    if(!
g_pGameConf->GetOffset("SetEntityModel", &offset) || !offset) {
        
g_pSM->LogError(myself"SetEntityModel offset is broken");
        return 
false;
    }
    
SH_MANUALHOOK_RECONFIGURE(SetEntityModelHookoffset00);
}
void Sample::OnClientPutInServer(int client)
{
    
CBaseEntity *pEntity gamehelpers->ReferenceToEntity(client);
    
setmodelhooks[client] = SH_ADD_MANUALVPHOOK(SetEntityModelHookpEntitySH_MEMBER(&g_interface, &Sample::SetEntityModel), false);
}
... 
I have to hook it for every player

Last edited by kadet.89; 06-07-2015 at 14:20.
kadet.89 is offline
Send a message via Skype™ to kadet.89
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 06-07-2015 , 14:36   Re: VirtualTable pointer
Reply With Quote #16

Quote:
Originally Posted by kadet.89 View Post
PHP Code:
SH_DECL_MANUALHOOK1_void(SetEntityModelHook000, const char *);
.....

bool Sample::SDK_OnLoad(char *errorsize_t maxlengthbool late)
{
....
    if(!
g_pGameConf->GetOffset("SetEntityModel", &offset) || !offset) {
        
g_pSM->LogError(myself"SetEntityModel offset is broken");
        return 
false;
    }
    
SH_MANUALHOOK_RECONFIGURE(SetEntityModelHookoffset00);
}
void Sample::OnClientPutInServer(int client)
{
    
CBaseEntity *pEntity gamehelpers->ReferenceToEntity(client);
    
setmodelhooks[client] = SH_ADD_MANUALVPHOOK(SetEntityModelHookpEntitySH_MEMBER(&g_interface, &Sample::SetEntityModel), false);
}
... 
I have to hook it for every player
Ensure you're compiling against core. core-legacy could have issues...
KyleS is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 06-08-2015 , 12:47   Re: VirtualTable pointer
Reply With Quote #17

Yes, I compile my extension against core

mmsource\core\sourcehook\sourcehook.h
PHP Code:
#define SH_ADD_MANUALVPHOOK(hookname, ifaceptr, handler, post) \
    
__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), SourceHook::ISourceHook::Hook_VP, post, handler) 

Last edited by kadet.89; 06-08-2015 at 13:08.
kadet.89 is offline
Send a message via Skype™ to kadet.89
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 04-02-2016 , 19:57   Re: VirtualTable pointer
Reply With Quote #18

Hi,

< Small question in the same topic, to avoid to create another thread... >

@donrevan:
You showed a small example for Windows at #4.
For Linux, retrieving the memory address of "_ZTV9CCSPlayer" is enough to access the virtual table of a player?

Something like:

PHP Code:
void  *pVtable  NULL;
void **ppVtable NULL;;

pGameConfig->GetMemSig("CCSPlayerVTable", &pVTable); // <= _ZTV9CCSPlayer
ppVtable = (void **) pVtable// Ugly cast (reinterpret?)

// Here we can access to the virtual table with the offsets..
ppVtable[OffsetSpawn]...
ppVtable[OffsetTakeDamage]... 
Is it correct?
__________________
micapat is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-03-2016 , 07:18   Re: VirtualTable pointer
Reply With Quote #19

No, the vtable symbol does not point to the start of the function list.
If the class has no virtual bases and is the primary vtable, it's 8 bytes after where the symbol points.
Unless you have a very good reason not to, you should get it from an instance.
__________________
asherkin is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 04-03-2016 , 08:03   Re: VirtualTable pointer
Reply With Quote #20

OK. It was just to know another method to find the vtable :>.
__________________
micapat 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 18:25.


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