Skip to content

Commit

Permalink
feat: option to store all autosubmit keys in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
hero622 authored and ThisAMJ committed Aug 7, 2024
1 parent de5a7e1 commit 9e75871
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/Features/AutoSubmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Features/NetMessage.hpp"
#include "Features/Session.hpp"
#include "Features/Speedrun/SpeedrunTimer.hpp"
#include "Modules/Client.hpp"
#include "Modules/Engine.hpp"
#include "Modules/FileSystem.hpp"
#include "Modules/Server.hpp"
Expand Down Expand Up @@ -162,6 +163,8 @@ static void testApiKey() {

THREAD_PRINT("Downloaded %i maps!\n", g_map_ids.size());
}

client->EnableCustomLeaderboards();
}

std::optional<std::string> AutoSubmit::GetMapId(std::string map_name) {
Expand Down Expand Up @@ -421,7 +424,16 @@ void AutoSubmit::LoadApiKey(bool output_nonexist) {

{
std::ifstream f(filepath.value());
std::getline(f, base) && std::getline(f, key);
/* if they use p2 common, the file is going to be a list of endpoints */
while (!f.eof()) {
std::getline(f, base);
std::getline(f, key);
if (sar.game->Is(SourceGame_Portal2) && base == "board.portal2.sr") break;
if (sar.game->Is(SourceGame_PortalStoriesMel) && base == "mel.board.portal2.sr") break;
/* if we got here, no valid key */
base.clear();
key.clear();
}
}

key.erase(std::remove_if(key.begin(), key.end(), isspace), key.end());
Expand Down
18 changes: 10 additions & 8 deletions src/Modules/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,16 @@ DETOUR(Client::GetChapterProgress) {
}
Hook g_GetChapterProgressHook(&Client::GetChapterProgress_Hook);

void Client::EnableCustomLeaderboards() {
g_GetLeaderboardHook.SetFunc(Client::GetLeaderboard);
g_IsQueryingHook.SetFunc(Client::IsQuerying);
g_SetPanelStatsHook.SetFunc(Client::SetPanelStats);
g_StartSearchingHook.SetFunc(Client::StartSearching);
g_PurgeAndDeleteElementsHook.SetFunc(Client::PurgeAndDeleteElements);
g_SetPlayerDataHook.SetFunc(Client::SetPlayerData);
g_ActivateSelectedItemHook.SetFunc(Client::ActivateSelectedItem);
}

bool Client::Init() {
bool readJmp = false;

Expand Down Expand Up @@ -1293,14 +1303,6 @@ bool Client::Init() {
Client::SetPanelStats = Memory::Read<decltype(Client::SetPanelStats)>(CPortalLeaderboardPanel_OnThink + Offsets::SetPanelStats);
Client::StartSearching = Memory::Read<decltype(Client::StartSearching)>((uintptr_t)GetLeaderboard + Offsets::StartSearching);
Client::AddAvatarPanelItem = Memory::Read<decltype(Client::AddAvatarPanelItem)>((uintptr_t)SetPanelStats + Offsets::AddAvatarPanelItem);

g_GetLeaderboardHook.SetFunc(Client::GetLeaderboard);
g_IsQueryingHook.SetFunc(Client::IsQuerying);
g_SetPanelStatsHook.SetFunc(Client::SetPanelStats);
g_StartSearchingHook.SetFunc(Client::StartSearching);
g_PurgeAndDeleteElementsHook.SetFunc(Client::PurgeAndDeleteElements);
g_SetPlayerDataHook.SetFunc(Client::SetPlayerData);
g_ActivateSelectedItemHook.SetFunc(Client::ActivateSelectedItem);
}

#ifdef _WIN32
Expand Down
1 change: 1 addition & 0 deletions src/Modules/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Client : public Module {
int GetSplitScreenPlayerSlot(void *entity);
void ClFrameStageNotify(int stage);
void OpenChat();
void EnableCustomLeaderboards();

public:
// CAvatarPanelItem::ActivateSelectedItem
Expand Down

0 comments on commit 9e75871

Please sign in to comment.