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

[Solved] Help with m_pfnThink and m_pfnTouch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 08-04-2012 , 03:50   [Solved] Help with m_pfnThink and m_pfnTouch
Reply With Quote #1

Hello.
I am trying to set my own think and touch callbacks for entities in module, for example in HLSDK we can do it with macro:
PHP Code:
#define SetThink( a ) m_pfnThink = static_cast <void (CBaseEntity::*)(void)> (a)
#define SetTouch( a ) m_pfnTouch = static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a) 
My code is:
PHP Code:
#define m_pfnThink 4

#ifdef _WIN32
#define m_pfnTouch 5

#define PrivateToEdict(pPrivate) (*(entvars_t **)((char*)pPrivate + 4))->pContainingEntity
#elif __linux__
#define m_pfnTouch 6

#define PrivateToEdict(pPrivate) (*(entvars_t **)pPrivate)->pContainingEntity
#endif
...
...
// For example setting touch callback to entity in some function:
*((void**)pAmmoBox->pvPrivateData m_pfnTouch) = (void*)(Ammo_Touch);
...
...
#ifdef _WIN32
void __fastcall Ammo_Touch(void *pPrivateint ivoid *pPrivate2)
#elif __linux__
void Ammo_Touch(void *pPrivatevoid *pPrivate2)
#endif
{
       
print_srvconsole("AmmoBox Touch! (%d  %d) \n"
                     
ENTINDEX(PrivateToEdict(pPrivate)), ENTINDEX(PrivateToEdict(pPrivate2)));

On windows everything is okay, i can see "AmmoBox Touch! (100 500)" in server console when i'm touch entity, callback is working fine. But on linux, this code don't work. Any help?
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community

Last edited by KORD_12.7; 08-04-2012 at 04:52.
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-04-2012 , 04:26   Re: Help with m_pfnThink and m_pfnTouch
Reply With Quote #2

I had the same problem when I've coded the HornetGun.

Probably because of alignment, I got my answer after looking at IDA.

Code:
#ifdef __linux__     int m_pfnThink_ = 3;     int m_pfnTouch_ = 5; #else     int m_pfnThink_ = 4;     int m_pfnTouch_ = 5; #endif

Code:
inline void SetTouch_( edict_t* e, void* funcAddress ) {     #ifdef __linux__         *( ( long* )e->pvPrivateData + m_pfnTouch_ ) = funcAddress == NULL ? NULL : 0xFFFF0000;         *( ( long* )e->pvPrivateData + m_pfnTouch_ + 1 ) = ( long )( funcAddress );     #else         *( ( long* )e->pvPrivateData + m_pfnTouch_ ) = ( long )( funcAddress );     #endif } inline void SetThink_( edict_t* e, void* funcAddress ) {     #ifdef __linux__         *( ( long* )e->pvPrivateData + m_pfnThink_ ) = funcAddress == NULL ? NULL : 0xFFFF0000;         *( ( long* )e->pvPrivateData + m_pfnThink_ + 1 ) = ( long )( funcAddress );     #else         *( ( long* )e->pvPrivateData + m_pfnThink_ ) = ( long )( funcAddress );     #endif }


Tell me if it works.
__________________

Last edited by Arkshine; 08-04-2012 at 04:27.
Arkshine is offline
KORD_12.7
Senior Member
Join Date: Aug 2009
Location: Russia, Vladivostok
Old 08-04-2012 , 04:51   Re: Help with m_pfnThink and m_pfnTouch
Reply With Quote #3

Arkshine, thanks again, it's working like a charm.
__________________

Vi Veri Veniversum Vivus Vici
Russian Half-Life and Adrenaline Gamer community
KORD_12.7 is offline
Send a message via ICQ to KORD_12.7
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 22:48.


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