[Stats] Optimize stat reuploading and maxlevel function

This commit is contained in:
momo5502 2017-02-28 11:40:33 +01:00
parent 4651c3476f
commit 1267a4a9f3
3 changed files with 24 additions and 16 deletions

View File

@ -4,15 +4,8 @@ namespace Components
{
bool Stats::IsMaxLevel()
{
// obtain statsbuffer (offset 4, first 4 bytes is statVersion.)
char* statsBuffer = Utils::Hook::Call<char *(int)>(0x4C49F0)(0) + 4;
// obtain experience from statsbuffer (offset 2056)
std::uint32_t experience = *reinterpret_cast<std::uint32_t*>(statsBuffer + 2056);
// 2516000 should be the max experience.
if (experience >= 2516000) return true;
return false;
return (Game::Live_GetXp(0) >= Game::CL_GetMaxXP());
}
void Stats::SendStats()
@ -26,10 +19,10 @@ namespace Components
// alloc
Game::msg_t msg;
memset(&msg, 0, sizeof(Game::msg_t));
ZeroMemory(&msg, sizeof(msg));
char* buffer = new char[2048];
memset(buffer, 0, 2048);
Utils::Memory::Allocator allocator;
char* buffer = allocator.allocateArray<char>(2048);
// init
Game::MSG_Init(&msg, buffer, 2048);
@ -43,7 +36,7 @@ namespace Components
}
// Client port?
Game::MSG_WriteShort(&msg, *(short*)0xA1E878);
Game::MSG_WriteShort(&msg, *reinterpret_cast<short*>(0xA1E878));
// Stat packet index
Game::MSG_WriteByte(&msg, i);
@ -60,10 +53,7 @@ namespace Components
}
// send statpacket
Game::NET_OutOfBandData(Game::NS_CLIENT, *(Game::netadr_t*)0xA1E888, msg.data, msg.cursize);
// free memory
delete[] buffer;
Network::SendRaw(Game::NS_CLIENT, *reinterpret_cast<Game::netadr_t*>(0xA1E888), std::string(msg.data, msg.cursize));
}
}
}

View File

@ -17,6 +17,7 @@ namespace Game
CL_DownloadsComplete_t CL_DownloadsComplete = CL_DownloadsComplete_t(0x42CE90);
CL_DrawStretchPicPhysical_t CL_DrawStretchPicPhysical = CL_DrawStretchPicPhysical_t(0x4FC120);
CL_GetConfigString_t CL_GetConfigString = CL_GetConfigString_t(0x44ADB0);
CL_GetMaxRank_t CL_GetMaxRank = CL_GetMaxRank_t(0x44BA30);
CL_GetRankForXP_t CL_GetRankForXP = CL_GetRankForXP_t(0x4FF8A0);
CL_GetRankIcon_t CL_GetRankIcon = CL_GetRankIcon_t(0x4A7B30);
CL_HandleRelayPacket_t CL_HandleRelayPacket = CL_HandleRelayPacket_t(0x5A8C70);
@ -231,6 +232,8 @@ namespace Game
Steam_JoinLobby_t Steam_JoinLobby = Steam_JoinLobby_t(0x49CF70);
StringTable_Lookup_t StringTable_Lookup = StringTable_Lookup_t(0x42F0E0);
SV_GameClientNum_Score_t SV_GameClientNum_Score = SV_GameClientNum_Score_t(0x469AC0);
SV_GameSendServerCommand_t SV_GameSendServerCommand = SV_GameSendServerCommand_t(0x4BC3A0);
SV_Cmd_TokenizeString_t SV_Cmd_TokenizeString = SV_Cmd_TokenizeString_t(0x4B5780);
@ -722,4 +725,11 @@ namespace Game
g_parse[1056 * *(reinterpret_cast<DWORD*>(g_parse) + 4224) + 1032] = parse != 0;
}
}
int CL_GetMaxXP()
{
StringTable* rankTable = DB_FindXAssetHeader(ASSET_TYPE_STRINGTABLE, "mp/rankTable.csv").stringTable;
const char* maxrank = StringTable_Lookup(rankTable, 0, "maxrank", 1);
return atoi(StringTable_Lookup(rankTable, 0, maxrank, 7));
}
}

View File

@ -38,6 +38,9 @@ namespace Game
typedef const char*(_cdecl* CL_GetConfigString_t)(int index);
extern CL_GetConfigString_t CL_GetConfigString;
typedef int(_cdecl* CL_GetMaxRank_t)();
extern CL_GetMaxRank_t CL_GetMaxRank;
typedef int(_cdecl* CL_GetRankForXP_t)(int xp);
extern CL_GetRankForXP_t CL_GetRankForXP;
@ -553,6 +556,9 @@ namespace Game
typedef void(__cdecl * Steam_JoinLobby_t)(SteamID, char);
extern Steam_JoinLobby_t Steam_JoinLobby;
typedef const char*(__cdecl * StringTable_Lookup_t)(StringTable *table, const int comparisonColumn, const char *value, const int valueColumn);
extern StringTable_Lookup_t StringTable_Lookup;
typedef int(__cdecl* SV_GameClientNum_Score_t)(int clientID);
extern SV_GameClientNum_Score_t SV_GameClientNum_Score;
@ -759,4 +765,6 @@ namespace Game
char* Com_GetParseThreadInfo();
void Com_SetParseNegativeNumbers(int parse);
int CL_GetMaxXP();
}