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