Raised This Month: $ Target: $400
 0% 

MemHack - Switch TeamScore


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sleepwalker
Member
Join Date: Dec 2006
Old 01-22-2009 , 16:10   MemHack - Switch TeamScore
Reply With Quote #1

Would this code work? I only got one server and wouldn't like to test this code on that one if there is no way of it to work.

This is not all of the code but you would se all code necessary.
Code:
#include <amxmodx>
#include <memhack>

#define TEAMDATA_EBX        0x1E25D8    // unsigned dword (Value of EBX register at CHalflifeMultiplay::Think)
#define POINTER_TEAMDATA    0x3519A8    // unsigned dword (Pointer to team data?)
#define PLAYERCOUNT_T        0x5C        // signed byte
#define PLAYERCOUNT_CT        0x60        // signed byte
#define SCORE_T            0x82        // signed word
#define SCORE_CT        0x80        // signed word

#define MEMTYPE_CODE        0            // Code (usually .text segment, requires mprotect or VirtualProtect)
#define MEMTYPE_DATA        1            // Data (usually .data segment, writable by default)
#define MEMTYPE_RODATA        2            // Read-Only Data (usually .rodata on Linux, .rdata on Windows)

//=====================================================================================================
//== Check Teams
//=====================================================================================================
public check_team(team) {
    sTeam = team;
    if (sTeam = CS_TEAM_T || sTeam = CS_TEAM_CT) {
        return 1;
    }
}

//=====================================================================================================
//== Get Team Score
//=====================================================================================================
public get_team_score(team) {
    sTeam = team;
    // Validate team
    check_team(sTeam);

    // Get starting address of team data
    offset        = memhack_get_realaddr(TEAMDATA_EBX + POINTER_TEAMDATA, MEMTYPE_CODE);
    eax        = memhack_get_pointer(offset, MEM_DLLBASE, MEMTYPE_DATA);
    addrTeamData    = memhack_get_pointer(eax, MEM_DLLBASE, MEMTYPE_DATA);

    new score = 0;

    // Get score for specified team
    switch (sTeam) {
        case CS_TEAM_T:
            score = memhack_get_short(addrTeamData + SCORE_T);
            break;
        case CS_TEAM_CT:
            score = memhack_get_short(addrTeamData + SCORE_CT);
            break;
    }

    return score;
}

//=====================================================================================================
//== Set Team Score
//=====================================================================================================
public set_team_score(team, score) {
    sTeam    = team;
    sScore    = score;

    // Validate team
    check_team(sTeam);

    // Get starting address of team data
    offset        = memhack_get_realaddr(TEAMDATA_EBX + POINTER_TEAMDATA, MEMTYPE_CODE);
    eax        = memhack_get_pointer(offset, MEM_DLLBASE, MEMTYPE_DATA);
    addrTeamData    = memhack_get_pointer(eax, MEM_DLLBASE, MEMTYPE_DATA);

    // Set score for specified team and update scoreboard
    switch (sTeam) {
        case CS_TEAM_T:
            memhack_set_short(addrTeamData + SCORE_T, MEM_DLLBASE, sScore);

            message_begin(MSG_ALL, get_user_msgid("TeamScore"));
            write_string ("TERRORIST");
            write_short(sScore);
            message_end();

            break;
        case CS_TEAM_CT:
            memhack_set_short(addrTeamData + SCORE_T, MEM_DLLBASE, sScore);

            message_begin(MSG_ALL, get_user_msgid("TeamScore"));
            write_string ("CT");
            write_short(sScore);
            message_end();
            break;
    }
}
My first guess is that I need to convert all the hex to int.
Sleepwalker is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 01-22-2009 , 17:17   Re: MemHack - Switch TeamScore
Reply With Quote #2

Why don't you try this:
PHP Code:
    /**
     * Description:        Typically adds points to everybody on the entity's team.
     * Forward params:    function(this, points, bool:cangonegative);
     * Return type:        None.
     * Execute params:    ExecuteHam(Ham_AddPointsToTeam, this, points, bool:cangonegative);
     */
    
Ham_AddPointsToTeam
I'm not sure how it works though, but you can experiment a little and find it out.
__________________

Community / No support through PM
danielkza is offline
Sleepwalker
Member
Join Date: Dec 2006
Old 01-22-2009 , 17:47   Re: MemHack - Switch TeamScore
Reply With Quote #3

My guess is that this is what it does:
Quote:
Typically adds points to everybody on the entity's team.
So my guess is that all player get more points and not the Team.
Sleepwalker is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 01-22-2009 , 18:21   Re: MemHack - Switch TeamScore
Reply With Quote #4

Quote:
Originally Posted by Sleepwalker View Post
My guess is that this is what it does:


So my guess is that all player get more points and not the Team.
Just test it. It doesn't make much sense to have a function just for that, looping through players is the obvious way. If it works, then you're good. If it doesn't, then you can try fixing your current approach.
__________________

Community / No support through PM
danielkza is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 01-22-2009 , 23:34   Re: MemHack - Switch TeamScore
Reply With Quote #5

I wish I could help you with the MemHack stuff, but I don't know much about it. I have a few suggestions, though:

1.
Code:
if (sTeam = CS_TEAM_T || sTeam = CS_TEAM_CT) {
This code will assign a value to sTeam instead of check it. You should use == instead of =.

2. check_team doesn't do much in the way that you use. It will return a value, but nothing else will happen. You probably want to do something like
Code:
if(!check_team(sTeam)) return 0;
to stop the function if the team is invalid. Also, you'll want to add
Code:
return 0
to the end of the check_team function.

3. You don't need to redefine team and score as sTeam and sScore at the top of your functions, you can just reference team and score. But maybe you have another reason for doing this.

4. You should be able to start your own listen server to test the plugin if you don't want to test it on your live server.

Best of luck. Cheers!
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Sleepwalker
Member
Join Date: Dec 2006
Old 01-23-2009 , 07:34   Re: MemHack - Switch TeamScore
Reply With Quote #6

This plugin is for Linux x86.
It is other parameters for Windows and Linux x64. ;)

I have tried to convert from CsHack Module (C++) to AMXX with MemHack.
That is why it looks like it does ;D
Sleepwalker is offline
Sleepwalker
Member
Join Date: Dec 2006
Old 01-24-2009 , 05:34   Re: MemHack - Switch TeamScore
Reply With Quote #7

This is the C++ code that I have tried to convert with MemHack and Amxx:
Code:
// No more using a counter variable on TeamScore message :-)
static cell AMX_NATIVE_CALL get_team_score(AMX *amx, cell *params) /* cs_get_team_score(team) = 1 arg */
{
    // Returns the score of the specified team
    // params[1] = Team

    char team = params[1];

    // Validate team
    CHECK_TEAM(team);

    // Get starting address of team data
    #ifdef __linux__
        #ifdef __amd64__
            maddress offset = GetRealMemoryAddress(POINTER_TEAMDATA, MEMTYPE_CODE);
            maddress r15 = UTIL_ReadMemory_Pointer(offset, MEMTYPE_DATA, false);
            maddress addrTeamData = UTIL_ReadMemory_Pointer(r15, MEMTYPE_DATA, false);
        #else
            maddress offset = GetRealMemoryAddress(TEAMDATA_EBX + POINTER_TEAMDATA, MEMTYPE_CODE);
            maddress eax = UTIL_ReadMemory_Pointer(offset, MEMTYPE_DATA, false);
            maddress addrTeamData = UTIL_ReadMemory_Pointer(eax, MEMTYPE_DATA, false);
        #endif
    #else
        maddress addrTeamData = UTIL_ReadMemory_Pointer(POINTER_TEAMDATA);
    #endif
    short score = 0;

    // Get score for specified team
    switch (team) {
        case CS_TEAM_T:
            score = UTIL_ReadMemory_Word(addrTeamData + SCORE_T, MEMTYPE_DATA, false);
            break;
        case CS_TEAM_CT:
            score = UTIL_ReadMemory_Word(addrTeamData + SCORE_CT, MEMTYPE_DATA, false);
            break;
    }

    return score;
}

static cell AMX_NATIVE_CALL set_team_score(AMX *amx, cell *params) /* cs_set_team_score(team, score) = 2 args */
{
    // Sets the score of the specified team
    // params[1] = Team
    // params[2] = New score value

    char team = params[1];
    short score = params[2];

    // Validate team
    CHECK_TEAM(team);

    // Get starting address of team data
    #ifdef __linux__
        #ifdef __amd64__
            maddress offset = GetRealMemoryAddress(POINTER_TEAMDATA, MEMTYPE_CODE);
            maddress r15 = UTIL_ReadMemory_Pointer(offset, MEMTYPE_DATA, false);
            maddress addrTeamData = UTIL_ReadMemory_Pointer(r15, MEMTYPE_DATA, false);
        #else
            maddress offset = GetRealMemoryAddress(TEAMDATA_EBX + POINTER_TEAMDATA, MEMTYPE_CODE);
            maddress eax = UTIL_ReadMemory_Pointer(offset, MEMTYPE_DATA, false);
            maddress addrTeamData = UTIL_ReadMemory_Pointer(eax, MEMTYPE_DATA, false);
        #endif
    #else
        maddress addrTeamData = UTIL_ReadMemory_Pointer(POINTER_TEAMDATA);
    #endif

    // Set score for specified team and update scoreboard
    switch (team) {
        case CS_TEAM_T:
            UTIL_PatchMemory_Word(addrTeamData + SCORE_T, score, MEMTYPE_DATA, false);

            MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "TeamScore", NULL));
            WRITE_STRING("TERRORIST");
            WRITE_SHORT(score);
            MESSAGE_END();

            break;
        case CS_TEAM_CT:
            UTIL_PatchMemory_Word(addrTeamData + SCORE_CT, score, MEMTYPE_DATA, false);

            MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "TeamScore", NULL));
            WRITE_STRING("CT");
            WRITE_SHORT(score);
            MESSAGE_END();

            break;
    }

    return 1;
}
I have also converted HEX to INT cuz MemHack is made that way:
Code:
#define TEAMDATA_EBX        1975768        // 0x1E25D8    -- unsigned dword (Value of EBX register at CHalflifeMultiplay::Think)
#define POINTER_TEAMDATA    3479976        // 0x3519A8    -- unsigned dword (Pointer to team data?)
#define PLAYERCOUNT_T        92        // 0x5C        -- signed byte
#define PLAYERCOUNT_CT        96        // 0x60        -- signed byte
#define SCORE_T            130        // 0x82        -- signed word
#define SCORE_CT        128        // 0x80        -- signed word

Last edited by Sleepwalker; 01-24-2009 at 05:36.
Sleepwalker is offline
Sleepwalker
Member
Join Date: Dec 2006
Old 01-24-2009 , 08:50   Re: MemHack - Switch TeamScore
Reply With Quote #8

MemHack natives:
memhack_get_realaddr(TEAMDATA_EBX + POINTER_TEAMDATA, MEMTYPE_CODE);
Code:
static cell AMX_NATIVE_CALL memhack_get_realaddr(AMX *amx, cell *params)
{
	return (cell)GetRealMemoryAddress(NATIVE_MISC_ADDRESS,NATIVE_MISC_BASEADDRESS,NATIVE_MISC_FLAGS);
}
memhack_get_pointer(offset, MEM_DLLBASE, MEMTYPE_DATA);
Code:
static cell AMX_NATIVE_CALL memhack_get_pointer(AMX *amx, cell *params)
{
	maddress HackedMemory = UTIL_ReadMemory_Pointer(NATIVE_HACK_MEMORY);
	return (cell)(HackedMemory);
}
memhack_get_pointer(eax, MEM_DLLBASE, MEMTYPE_DATA);
Code:
static cell AMX_NATIVE_CALL memhack_get_pointer(AMX *amx, cell *params)
{
	maddress HackedMemory = UTIL_ReadMemory_Pointer(NATIVE_HACK_MEMORY);
	return (cell)(HackedMemory);
}
memhack_get_short(addrTeamData + SCORE_CT);
Code:
static cell AMX_NATIVE_CALL memhack_get_short(AMX *amx, cell *params)
{
	if(NATIVE_HACK_SIGNED)
	{
		short HackedMemory = UTIL_ReadMemory_Word(NATIVE_HACK_MEMORY);
		return (cell)(HackedMemory);
	}
	else
	{
		unsigned short HackedMemory = UTIL_ReadMemory_UnsignedWord(NATIVE_HACK_MEMORY);
		return (cell)(HackedMemory);
	}
}
memhack_set_short(addrTeamData + SCORE_T, MEM_DLLBASE, sScore);
Code:
static cell AMX_NATIVE_CALL memhack_set_short(AMX *amx, cell *params)
{
	if(NATIVE_PATCH_SIGNED)
	{
		return (cell)UTIL_PatchMemory_Word(NATIVE_PATCH_MEMORY, (short)(NATIVE_PATCH_PARAMETER), NATIVE_PATCH_FLAGS);
	}
	else
	{
		return (cell)UTIL_PatchMemory_UnsignedWord(NATIVE_PATCH_MEMORY, (unsigned short)(NATIVE_PATCH_PARAMETER), NATIVE_PATCH_FLAGS);
	}
}
Sleepwalker is offline
Reply


Thread Tools
Display Modes

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 01:52.


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