Skip to content

Commit

Permalink
fix: only show top 3 times, fix linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
hero622 committed Nov 1, 2023
1 parent 5d89595 commit fa5c33c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Features/AutoSubmitMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void testApiKey() {
THREAD_PRINT("Downloaded %i maps!\n", g_map_ids.size());
}

std::optional<std::string> AutoSubmitMod::GetMapId(std::string &map_name) {
std::optional<std::string> AutoSubmitMod::GetMapId(std::string map_name) {
auto it = g_map_ids.find(map_name);
if (it == g_map_ids.end()) {
return {};
Expand Down
2 changes: 1 addition & 1 deletion src/Features/AutoSubmitMod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace AutoSubmitMod {
void LoadApiKey(bool output_nonexist);
void FinishRun(float final_time, const char *demopath, std::optional<std::string> rename_if_pb, std::optional<std::string> replay_append_if_pb);
std::optional<std::string> GetMapId(std::string &map_name);
std::optional<std::string> GetMapId(std::string map_name);
std::optional<int> GetCurrentPbScore(std::string &map_id);
json11::Json::object GetMapJson(std::string &map_id);
}; // namespace AutoSubmitMod
67 changes: 34 additions & 33 deletions src/Modules/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,21 +533,24 @@ DETOUR(Client::SetPanelStats) {
auto map_id = AutoSubmitMod::GetMapId(std::string(m_pLeaderboard->m_szMapName));
auto json = AutoSubmitMod::GetMapJson(*map_id);

std::map<int, std::pair<std::string, json11::Json>> times;
std::vector<std::pair<std::string, json11::Json>> times;
for (auto score : json) {
auto scoreData = score.second["scoreData"];
int time = atoi(scoreData["score"].string_value().c_str());
times.push_back(score);

times.insert({time, score});
std::sort(times.begin(), times.end(), [](std::pair<std::string, json11::Json> a, std::pair<std::string, json11::Json> b) {
return atoi(a.second["scoreData"]["score"].string_value().c_str()) < atoi(b.second["scoreData"]["score"].string_value().c_str());
});
}

for (const auto &time : times) {
for (int i = 0; i < std::min((int)times.size(), 3); ++i) {
const auto &time = times[i];

PortalLeaderboardItem_t data;
data.m_xuid = atoll(time.second.first.c_str());
data.m_iScore = time.first;
strncpy(data.m_szName, time.second.second["userData"]["boardname"].string_value().c_str(), sizeof(data.m_szName));
data.m_xuid = atoll(time.first.c_str());
data.m_iScore = atoi(time.second["scoreData"]["score"].string_value().c_str());
strncpy(data.m_szName, time.second["userData"]["boardname"].string_value().c_str(), sizeof(data.m_szName));

client->AddAvatarPanelItem(m_pLeaderboard, m_pStatList, &data, data.m_iScore, 1, -1, 0, 81, -1, 0);
client->AddAvatarPanelItem(m_pLeaderboard, m_pStatList, &data, data.m_iScore, 1, -1, i, 81, -1, 0);
}

return 0;
Expand Down Expand Up @@ -693,30 +696,6 @@ bool Client::Init() {

g_AddShadowToReceiverHook.SetFunc(Client::AddShadowToReceiver);

if (!sar.game->Is(SourceGame_Portal2)) {
#ifdef _WIN32
Client::StartSearching = (decltype(Client::StartSearching))Memory::Scan(client->Name(), "55 8B EC 83 EC 14 53 56 57 8B F9 33 DB C6 87");
#else
Client::StartSearching = (decltype(Client::StartSearching))Memory::Scan(client->Name(), "55 89 E5 57 56 8D 75 DC 53 83 EC 2C 8B 5D 08 8D 83");
#endif

g_StartSearchingHook.SetFunc(Client::StartSearching);

#ifdef _WIN32
Client::AddAvatarPanelItem = (decltype(Client::AddAvatarPanelItem))Memory::Scan(client->Name(), "55 8B EC 83 EC 08 56 57 68 ? ? ? ? E8");
#else
Client::AddAvatarPanelItem = (decltype(Client::AddAvatarPanelItem))Memory::Scan(client->Name(), "55 89 E5 57 56 53 83 EC 4C 8B 45 14 C7 04 24");
#endif

#ifdef _WIN32
Client::SetPanelStats = (decltype(Client::SetPanelStats))Memory::Scan(client->Name(), "55 8B EC 83 EC 68 53 8B D9 8B 83");
#else
Client::SetPanelStats = (decltype(Client::SetPanelStats))Memory::Scan(client->Name(), "55 89 E5 57 56 53 81 EC ? ? ? ? 65 A1 ? ? ? ? 89 45 E4 31 C0 8B 5D 08 8B 83 ? ? ? ? 85 C0 0F 85");
#endif

g_SetPanelStatsHook.SetFunc(Client::SetPanelStats);
}

// Get at gamerules
{
uintptr_t cbk = (uintptr_t)Command("+mouse_menu").ThisPtr()->m_pCommandCallback;
Expand Down Expand Up @@ -752,6 +731,28 @@ bool Client::Init() {
this->g_ChapterMPContextNames = Memory::Deref<ChapterContextData_t *>(GetNumChapters + 91);
}
#endif

#ifdef _WIN32
Client::StartSearching = (decltype(Client::StartSearching))Memory::Scan(client->Name(), "55 8B EC 83 EC 14 53 56 57 8B F9 33 DB C6 87");
#else
Client::StartSearching = (decltype(Client::StartSearching))Memory::Scan(client->Name(), "55 89 E5 57 56 8D 75 DC 53 83 EC 2C 8B 5D 08 8D 83");
#endif

g_StartSearchingHook.SetFunc(Client::StartSearching);

#ifdef _WIN32
Client::AddAvatarPanelItem = (decltype(Client::AddAvatarPanelItem))Memory::Scan(client->Name(), "55 8B EC 83 EC 08 56 57 68 ? ? ? ? E8");
#else
Client::AddAvatarPanelItem = (decltype(Client::AddAvatarPanelItem))Memory::Scan(client->Name(), "55 89 E5 57 56 53 83 EC 4C 8B 45 14 C7 04 24");
#endif

#ifdef _WIN32
Client::SetPanelStats = (decltype(Client::SetPanelStats))Memory::Scan(client->Name(), "55 8B EC 83 EC 68 53 8B D9 8B 83");
#else
Client::SetPanelStats = (decltype(Client::SetPanelStats))Memory::Scan(client->Name(), "55 89 E5 57 56 53 81 EC ? ? ? ? 65 A1 ? ? ? ? 89 45 E4 31 C0 8B 5D 08 8B 83 ? ? ? ? 85 C0 0F 85");
#endif

g_SetPanelStatsHook.SetFunc(Client::SetPanelStats);
}

cl_showpos = Variable("cl_showpos");
Expand Down

0 comments on commit fa5c33c

Please sign in to comment.