AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   hooking game start or messages (https://forums.alliedmods.net/showthread.php?t=300631)

killerZM 08-23-2017 15:27

hooking game start or messages
 
hi all
i am trying to hook round start
is this a right way ?

i made a forward and execute it here but when i try to send a text in(pawn code)
it give me arror
PHP Code:

void MessageBeginPost(int msg_destint type, const float *orgedict_t *ed)
{
    if (
type == AVPMessages.deathmsg && gpGlobals -> time 6)
    {
        
AVPMessages.message DeathMsg;
        
AVPMessages.byte 0;
    }
    else if (
type == AVPMessages.hltv && gpGlobals->time 6)
    {
        
AVPMessages.message HLTV;
        
AVPMessages.byte 0;
    }
    else if (
type == AVPMessages.bartime && gpGlobals->time 6)
    {
        
AVPMessages.message BarTime;
        
AVPMessages.byte 0;
    }
    else if (
type == AVPMessages.damage && gpGlobals->time 6)
    {
        
AVPMessages.message Damage;
        
AVPMessages.byte 0;
    }
    
RETURN_META(MRES_IGNORED);
}

void MessageEndPost(void)
{
    if (
AVPMessages.message)
        
AVPMessages.message 0;
    
RETURN_META(MRES_IGNORED);
}

void WriteByte_Post(int Byte)
{
    if (
AVPMessages.message)
        switch (
AVPMessages.message)
        {
        case 
HLTV:
        {
            
            
MF_Log("Errror");
            switch (++
AVPMessages.byte)
            {
            case 
1:
            {
                
AVPMessages.status Byte;
                break;
            }
            case 
2:
            {
                
//MF_ExecuteForward(AVPForwards.roundstart);
                
if (!AVPMessages.status && !Byte) {
                    
MF_Log("RoundSTart");
                    
SERVER_PRINT("Aliredators");
                    
MF_PrintSrvConsole("KILLED");
                }
                break;
            }
            }
            break;
        }
        case 
DeathMsg:
        {
            if (++
AVPMessages.byte == )
            {
                
                
MF_ExecuteForward(AVPForwards.death static_cast<cell>(Byte));
                
MF_PrintSrvConsole("KILLED");
                break;
            }
            break;
        }
        }
}

int RegUserMsgPost(const char pNameint)
{
    if (!
strcmp(pName"DeathMsg"))
        
AVPMessages.deathmsg META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"HLTV"))
        
AVPMessages.hltv META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"ScoreAttrib"))
        
AVPMessages.scoreattrib META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"ScoreInfo"))
        
AVPMessages.scoreinfo META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"TeamInfo"))
        
AVPMessages.teaminfo META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"SayText"))
        
AVPMessages.saytext META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"ScreenFade"))
        
AVPMessages.screenfade META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"ScreenShake"))
        
AVPMessages.screenshake META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"Crosshair"))
        
AVPMessages.crosshair META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"HideWeapon"))
        
AVPMessages.hideweapon META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"Damage"))
        
AVPMessages.damage META_RESULT_ORIG_RET(int);

    else if (!
strcmp(pName"BarTime"))
        
AVPMessages.bartime META_RESULT_ORIG_RET(int);

    
RETURN_META_VALUE(MRES_IGNORED0);



Beqa Gurgenidze 08-24-2017 05:36

Re: hooking game start or messages
 
Enable AlertMessage_Post to hook Round Start & Round End.

https://forums.alliedmods.net/showpo...40&postcount=4

Enable MessageBegin to hook Messages
Code:

void OnMessageBegin(int Dest, int Type, const float *pOrigin, edict_t *pPlayer)
{
        switch (Type)
        {
        case MESSAGE_HOSTAGEK:
                Ibreak;
        case MESSAGE_HOSTAGEPOS:
                break;
        case MESSAGE_HLTV:
                break;
        }

        RETURN_META(MRES_IGNORED);
}

Some messages for Counter-Strike 1.6:

Code:

#define MESSAGE_VOICEMASK 64
#define MESSAGE_REQSTATE 65
#define MESSAGE_CURWEAPON 66
#define MESSAGE_GEIGER 67
#define MESSAGE_FLASHLIGHT 68
#define MESSAGE_FLASHBAT 69
#define MESSAGE_HEALTH 70
#define MESSAGE_DAMAGE 71
#define MESSAGE_BATTERY 72
#define MESSAGE_TRAIN 73
#define MESSAGE_HUDTEXTPRO 74
#define MESSAGE_HUDTEXT 75
#define MESSAGE_SAYTEXT 76
#define MESSAGE_TEXTMSG 77
#define MESSAGE_WEAPONLIST 78
#define MESSAGE_RESETHUD 79
#define MESSAGE_INITHUD 80
#define MESSAGE_VIEWMODE 81
#define MESSAGE_GAMETITLE 82
#define MESSAGE_DEATHMSG 83
#define MESSAGE_SCOREATTRIB 84
#define MESSAGE_SCOREINFO 85
#define MESSAGE_TEAMINFO 86
#define MESSAGE_TEAMSCORE 87
#define MESSAGE_GAMEMODE 88
#define MESSAGE_MOTD 89
#define MESSAGE_SERVERNAME 90
#define MESSAGE_AMMOPICKUP 91
#define MESSAGE_WEAPPICKUP 92
#define MESSAGE_ITEMPICKUP 93
#define MESSAGE_HIDEWEAPON 94
#define MESSAGE_SETFOV 95
#define MESSAGE_SHOWMENU 96
#define MESSAGE_SCREENSHAKE 97
#define MESSAGE_SCREENFADE 98
#define MESSAGE_AMMOX 99
#define MESSAGE_SENDAUDIO 100
#define MESSAGE_ROUNDTIME 101
#define MESSAGE_MONEY 102
#define MESSAGE_ARMORTYPE 103
#define MESSAGE_BLINKACCT 104
#define MESSAGE_STATUSVALUE 105
#define MESSAGE_STATUSTEXT 106
#define MESSAGE_STATUSICON 107
#define MESSAGE_BARTIME 108
#define MESSAGE_RELOADSOUND 109
#define MESSAGE_CROSSHAIR 110
#define MESSAGE_NVGTOGGLE 111
#define MESSAGE_RADAR 112
#define MESSAGE_SPECTATOR 113
#define MESSAGE_VGUIMENU 114
#define MESSAGE_TUTORTEXT 115
#define MESSAGE_TUTORLINE 116
#define MESSAGE_TUTORSTATE 117
#define MESSAGE_TUTORCLOSE 118
#define MESSAGE_ALLOWSPEC 119
#define MESSAGE_BOMBDROP 120
#define MESSAGE_BOMBPICKUP 121
#define MESSAGE_CLCORPSE 122
#define MESSAGE_HOSTAGEPOS 123
#define MESSAGE_HOSTAGEK 124
#define MESSAGE_HLTV 125
#define MESSAGE_SPECHEALTH 126
#define MESSAGE_FORCECAM 127
#define MESSAGE_ADSTOP 128
#define MESSAGE_RECEIVEW 129
#define MESSAGE_CZCAREER 130
#define MESSAGE_CZCAREERHUD 131
#define MESSAGE_SHADOWIDX 132
#define MESSAGE_TASKTIME 133
#define MESSAGE_SCENARIO 134
#define MESSAGE_BOTVOICE 135
#define MESSAGE_BUYCLOSE 136
#define MESSAGE_SPECHEALTH2 137
#define MESSAGE_BARTIME2 138
#define MESSAGE_ITEMSTATUS 139
#define MESSAGE_LOCATION 140
#define MESSAGE_BOTPROGRESS 141
#define MESSAGE_BRASS 142
#define MESSAGE_FOG 143
#define MESSAGE_SHOWTIMER 144
#define MESSAGE_HUDTEXTARGS 145


killerZM 08-24-2017 10:42

Re: hooking game start or messages
 
so
but what if i want to do something when msg is hooked ?

Beqa Gurgenidze 08-24-2017 11:02

Re: hooking game start or messages
 
Quote:

Originally Posted by killerZM (Post 2544045)
so
but what if i want to do something when msg is hooked ?

Code:

void OnMessageBegin(int Dest, int Type, const float *pOrigin, edict_t *pPlayer)
{
        switch (Type)
        {
        case MESSAGE_HOSTAGEK:
                break; // <<< You Can Write Anything Here. This message already hooked.
        case MESSAGE_HOSTAGEPOS:
                break; // <<< You Can Write Anything Here. This message already hooked.
        case MESSAGE_HLTV:
                break; // <<< You Can Write Anything Here. This message already hooked.
        }

        RETURN_META(MRES_IGNORED);
}


killerZM 08-24-2017 12:13

Re: hooking game start or messages
 
ty

@edit
what if need to get message arguments ?

Beqa Gurgenidze 08-25-2017 01:55

Re: hooking game start or messages
 
Quote:

Originally Posted by killerZM (Post 2544060)
ty

@edit
what if need to get message arguments ?

then you need to hook WriteByte, WriteCoord etc.. + MessageEnd forwards.

then you need to create bool array where you will which message arguments are you getting from forward WriteXXXX.

Code:

bool MessageHooked[256];
Lets hook health message & get argument (1 Byte Argument) (https://wiki.alliedmods.net/Half-life_1_game_events)

Code:

#define MESSAGE_HEALTH 70

void OnMessageBegin(int Dest, int Type, const float *pOrigin, edict_t *pPlayer)
{
        switch (Type)
        {
        case MESSAGE_HEALTH:
        {
                MessageHooked[MESSAGE_HEALTH] = true;
                RETURN_META(MRES_IGNORED);
        }
        }

        RETURN_META(MRES_IGNORED);
}

void OnWriteByte(int Value)
{
        if (MessageHooked[MESSAGE_HEALTH])
        {
                // First Value = health
                // Wanna Change IT?
                // then do like this
                WRITE_BYTE(Value * 2);
                RETURN_META(MRES_SUPERCEDE);
        }

        RETURN_META(MRES_IGNORED);
}

void OnMessageEnd(void)
{
        MessageHooked[MESSAGE_HEALTH] = false;
        RETURN_META(MRES_IGNORED);
}

didnt checked this code, but must work.
ofc you must hook those forwards with g_pengfuncsTable;

killerZM 08-26-2017 15:51

Re: hooking game start or messages
 
u r smart but what is g_pengfuncTable ?

Beqa Gurgenidze 08-27-2017 08:57

Re: hooking game start or messages
 
Quote:

Originally Posted by killerZM (Post 2544521)
u r smart but what is g_pengfuncTable ?

enginefuncs_t *g_pengfuncsTable this is engine function hooker. you can hook with this engine functions. this is created in amxmodule.cpp/meta_api.cpp. and you can use this with extern:
Code:

extern enginefuncs_t *g_pengfuncsTable;
better hook functions earlier at starting server. theres also g_pengfuncsTable_Post variable, which hooks same functions but after this function is called (Post).

example of hooking PrecacheModel

Code:

int OnPrecacheModel_Post(const char *Resource)
{
        <Your Code Here>
       
        <Wanna Block Precache?, then use RETURN_META_VALUE(MRES_SUPERCEDE, NULL);>
        // ^^ Not tested but think must work
}

void <Function where you want to set hook for engine functions>(void)
{
g_pengfuncsTable_Post->pfnPrecacheModel = OnPrecacheModel_Post;
}


killerZM 08-27-2017 10:29

Re: hooking game start or messages
 
ty

another thing if possible
how to get damage and change it like ham_takedamage ?

how to make a menu

how to make a hud :)
sorry for much questions

Beqa Gurgenidze 08-28-2017 02:46

Re: hooking game start or messages
 
Quote:

Originally Posted by killerZM (Post 2544681)
ty

another thing if possible
how to get damage and change it like ham_takedamage ?

how to make a menu

how to make a hud :)
sorry for much questions

im actually working on this. ive started working on modules few weeks ago.


All times are GMT -4. The time now is 15:30.

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