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

some questions ( CString, CVector, Ham )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 08-01-2009 , 16:21   some questions ( CString, CVector, Ham )
Reply With Quote #1

1# I have to use CString.h or string.h

2# I have to use CVector.h or vector.h

3# How work Ham with Metamod. Because I see that RegisterHam work diferent than Fakemeta or Engine.

Metamod dont exec func in Ham ( Well the function like Player Pre Think ).


Plis, sorry my english.
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-01-2009 , 21:40   Re: some questions ( CString, CVector, Ham )
Reply With Quote #2

about 1#,2#, if you want your plugins compiled only in windows, you can use stl, if you want them to be compiled in both win and linux, use the library amxx supplied.
about #3, you mean why ham don't hook engine or dll function?
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 08-02-2009 , 17:03   Re: some questions ( CString, CVector, Ham )
Reply With Quote #3

Quote:
Originally Posted by jim_yang View Post
about 1#,2#, if you want your plugins compiled only in windows, you can use stl, if you want them to be compiled in both win and linux, use the library amxx supplied.
Thanks

Quote:
Originally Posted by jim_yang View Post
about #3, you mean why ham don't hook engine or dll function?
Well. If I see moduleconfig that dont define any HL Func
PHP Code:
// #define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */ 
But the module use PreThink.

How Ham Hook HL or Metamod events?

Else: I have to use define of ARRAYSIZE of winnt or eiface?
__________________

Last edited by AntiBots; 08-02-2009 at 17:09.
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Shadows In Rain
Senior Member
Join Date: Apr 2010
Location: Russia::Siberia
Old 07-31-2011 , 09:17   Re: some questions ( CString, CVector, Ham )
Reply With Quote #4

Quote:
Originally Posted by jim_yang View Post
if you want your plugins compiled only in windows, you can use stl, if you want them to be compiled in both win and linux, use the library amxx supplied.
LOLWUT? STL is part of C++ standart library. It comes with almost compilers.

http://en.wikipedia.org/wiki/Standard_Template_Library
http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library
http://en.wikipedia.org/wiki/Core_language

Also, files with extension ".h" are deprecated, use files without ".h" (read links):
#include <string>
#include <vector>
__________________
I'm using Google translator, yarrr. |.◕‿‿◕.|
Shadows In Rain is offline
Send a message via ICQ to Shadows In Rain
jim_yang
Veteran Member
Join Date: Aug 2006
Old 07-31-2011 , 09:29   Re: some questions ( CString, CVector, Ham )
Reply With Quote #5

Quote:
Originally Posted by Shadows In Rain View Post
LOLWUT? STL is part of C++ standart library. It comes with almost compilers.

http://en.wikipedia.org/wiki/Standard_Template_Library
http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library
http://en.wikipedia.org/wiki/Core_language

Also, files with extension ".h" are deprecated, use files without ".h" (read links):
#include <string>
#include <vector>
You get me wrong or my poor English sucking.
Of course I know what you try to say.
Quote:
Originally Posted by BAILOPAN View Post
I recommend not using STL in plugins if you intend to distribute as binaries on Linux. It requires linking to libstdc++ which is a world of hurt (in fact, it's really only safe if you use the exact GCC version Valve does, gcc-3.4).
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-02-2009 , 22:59   Re: some questions ( CString, CVector, Ham )
Reply With Quote #6

Hamsandwish hooks the virtual functions(vfuncs) of a class, to explain clearly, I'll give an example.
Here is the Class Hierachy:
Code:
CBaseEntity
    CBaseDelay
        CBaseToggle
            CBaseItem
            CBaseMonster
                CBaseCycler
                CBasePlayer
                CBaseGroup
You can see that CBaseEntity is the base class of all other entity classes.
Here is part of vfuncs from CBasePlayer class
Code:
0    CBasePlayer::Spawn(void)
1    CBasePlayer::Precache(void)
2    CBaseEntity::Restart(void)
3    CBaseMonster::KeyValue(KeyValueData_s *)
4    CBasePlayer::Save(CSave &)
5    CBasePlayer::Restore(CRestore &)
6    CBasePlayer::ObjectCaps(void)
7    CBaseEntity::Activate(void)
8    CBaseEntity::SetObjectCollisionBox(void)
9    CBasePlayer::Classify(void)
10   CBaseEntity::DeathNotice(entvars_s *)
11   CBasePlayer::TraceAttack(entvars_s *,float,Vector,TraceResult *,int)
12   CBasePlayer::TakeDamage(entvars_s *,entvars_s *,float,int)
You can see that some functions from CBasePlayer override the original function from CBaseEntity
Code:
RegisterHam(Ham_TakeDamage, "player", "my_hook_func", 0 or 1) //pre or post
To hook the function CBasePlayer::TakeDamage, ham first spawn an entity with given classname, because different classes have different TakeDamage function, so we should specify which class we want to hook.
Virtual table(vtbl) stores in each object of a class, it stores the virtual function's address(pointer). When an obj call its virtual function, it will look up the vtbl to find its real address in memory.
Code:
CBasePlayer *pPlayer;
pPlayer->Spawn();
Numver 0 - 12 above is the index of these vfuncs in vtbl. You can find these numbers in hamdata.ini from configs folder
Ham does the followings to hook CBasePlayer::TakeDamage function:
(1)spawn a "player" entity
(2)get its vtbl address
(3)get its vtbl index from hamdata(actually this have been done when ham init)
(4)get the vfunc address
(5)generate a trampoline function
(6)changed the original vfunc address in vtbl to the trampoline function address(hooking started)
about the trampoline function, it looks like this:
Code:
Tramp()
{
    //prehook
    return_value = my_hook_func(original parameters)
    if(return_value == HAM_SUPERSEDE)
        return
    
    //call the original function
    this->TakeDamage(modified parameters from our prehook function)
    
    //posthook
    my_hook_func()
}
I'm not good at explaining things because of my poor English, so I didn't explain the c++ part, such as class, hierachy, virtual function..., you can find these in any c++ book.
===================
if you want to use ARRAYSIZE, use the hlsdk version
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 09-08-2009 , 21:25   Re: some questions ( CString, CVector, Ham )
Reply With Quote #7

@jim: I can use Trampoline.h from Ham, Or I have to make a new?

Is you have time, only show how to hook Ham_Spawn, Example.
Only the code, without explain.
I was traing but sometimes work and others no.

Thanks!!!
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-09-2009 , 04:15   Re: some questions ( CString, CVector, Ham )
Reply With Quote #8

Code:
#include "amxxmodule.h"
#include <windows.h>
#define HOOK_Spawn 0
void *pOriginalFunction = NULL;
void Hook_Spawn()
{
    //save this pointer
    void *pthis;
    __asm mov pthis, ecx;
    //pre hook
    SERVER_PRINT("::Spawn(void) prehook!\n");
    //call original function
    __asm mov ecx, pthis;
    __asm call [pOriginalFunction];
    //post hook
    SERVER_PRINT("::Spawn(void) posthook!\n");
}
void Hook()
{
    //get classname of the entity you want to hook
    const char *classname = CMD_ARGV(1);
    edict_t *pEdict = CREATE_ENTITY();
    CALL_GAME_ENTITY(PLID, classname, &pEdict->v);
    if(pEdict->pvPrivateData == NULL)
    {
        REMOVE_ENTITY(pEdict);
        return;
    }
    //get this pointer
    void *pthis = pEdict->pvPrivateData;
    //get vtable
    void **vtbl = *(void ***)pthis;
    REMOVE_ENTITY(pEdict);
    if(vtbl == NULL)
        return;
    
    int **ivtbl = (int **)vtbl;
    //get the original function
    pOriginalFunction = (void *)ivtbl[HOOK_Spawn];
    
    //patch original function to our function
    DWORD oldflags;
    if(VirtualProtect(&ivtbl[HOOK_Spawn], sizeof(int *), PAGE_READWRITE, &oldflags))
    {
        ivtbl[HOOK_Spawn] = (int *)Hook_Spawn;
    }
}
void OnMetaAttach()
{
    REG_SVR_COMMAND("hook", Hook);
}
ecx store this pointer, you need to do some calculate to get the edict_t *
in windows this calc is
Code:
mov eax, [ecx + 4];  get this->pev
mov eax, [eax + 520]; get pev->pContainingEntity
mov pEdict, eax
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
pRoxxxDD
Junior Member
Join Date: Feb 2011
Location: Ukraine
Old 07-31-2011 , 08:16   Re: some questions ( CString, CVector, Ham )
Reply With Quote #9

Quote:
Originally Posted by jim_yang View Post
[code]
Code:
mov eax, [ecx + 4];  get this->pev
mov eax, [eax + 520]; get pev->pContainingEntity
mov pEdict, eax
Can you explain it ?
__________________
pRoxxxDD is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 09-10-2009 , 12:45   Re: some questions ( CString, CVector, Ham )
Reply With Quote #10

Wow Jim, Work perfect. Also the edict_t

Now I am Traing to Transport Trampoline from Ham to my Module. First Test Work
__________________

Last edited by AntiBots; 09-10-2009 at 18:34.
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
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 19:40.


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