Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions src/cs2fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class GameSessionConfiguration_t

SH_DECL_HOOK3_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool, bool, bool);
SH_DECL_HOOK0_void(IServerGameDLL, GameServerSteamAPIActivated, SH_NOATTRIB, 0);
SH_DECL_HOOK0_void(IServerGameDLL, GameServerSteamAPIDeactivated, SH_NOATTRIB, 0);
SH_DECL_HOOK1_void(IServerGameDLL, ApplyGameSettings, SH_NOATTRIB, 0, KeyValues*);
SH_DECL_HOOK4_void(IServerGameClients, ClientActive, SH_NOATTRIB, 0, CPlayerSlot, bool, const char*, uint64);
SH_DECL_HOOK5_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, CPlayerSlot, ENetworkDisconnectionReason, const char*, uint64, const char*);
Expand Down Expand Up @@ -102,8 +101,6 @@ IGameEventSystem* g_gameEventSystem = nullptr;
IGameEventManager2* g_gameEventManager = nullptr;
CGameEntitySystem* g_pEntitySystem = nullptr;
IVEngineServer2* g_pEngineServer2 = nullptr;
ISteamHTTP* g_http = nullptr;
CSteamGameServerAPIContext g_steamAPI;
CCSGameRules* g_pGameRules = nullptr; // Will be null between map end & new map startup, null check if necessary!
CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr = nullptr; // Will be null between map end & new map startup, null check if necessary!

Expand Down Expand Up @@ -190,7 +187,6 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool

SH_ADD_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameFramePost), true);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIActivated), false);
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIDeactivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIDeactivated), false);
SH_ADD_HOOK(IServerGameDLL, ApplyGameSettings, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_ApplyGameSettings), false);
SH_ADD_HOOK(IServerGameClients, ClientActive, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientActive), true);
SH_ADD_HOOK(IServerGameClients, ClientDisconnect, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientDisconnect), true);
Expand Down Expand Up @@ -400,10 +396,6 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
g_pVoteManager->VoteManager_Init();

g_pIdleSystem->Reset();

g_steamAPI.Init();
g_http = g_steamAPI.SteamHTTP();

g_playerManager->OnSteamAPIActivated();

if (g_cvarVoteManagerEnable.Get() && !g_pMapVoteSystem->IsMapListLoaded())
Expand All @@ -421,7 +413,6 @@ bool CS2Fixes::Unload(char* error, size_t maxlen)
{
SH_REMOVE_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameFramePost), true);
SH_REMOVE_HOOK(IServerGameDLL, GameServerSteamAPIActivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIActivated), false);
SH_REMOVE_HOOK(IServerGameDLL, GameServerSteamAPIDeactivated, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_GameServerSteamAPIDeactivated), false);
SH_REMOVE_HOOK(IServerGameDLL, ApplyGameSettings, g_pSource2Server, SH_MEMBER(this, &CS2Fixes::Hook_ApplyGameSettings), false);
SH_REMOVE_HOOK(IServerGameClients, ClientActive, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientActive), true);
SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, g_pSource2GameClients, SH_MEMBER(this, &CS2Fixes::Hook_ClientDisconnect), true);
Expand Down Expand Up @@ -669,9 +660,6 @@ void CS2Fixes::Hook_CTriggerGravityEndTouch(CBaseEntity* pOther)
}
void CS2Fixes::Hook_GameServerSteamAPIActivated()
{
g_steamAPI.Init();
g_http = g_steamAPI.SteamHTTP();

g_playerManager->OnSteamAPIActivated();

if (g_cvarVoteManagerEnable.Get() && !g_pMapVoteSystem->IsMapListLoaded())
Expand All @@ -680,13 +668,6 @@ void CS2Fixes::Hook_GameServerSteamAPIActivated()
RETURN_META(MRES_IGNORED);
}

void CS2Fixes::Hook_GameServerSteamAPIDeactivated()
{
g_http = nullptr;

RETURN_META(MRES_IGNORED);
}

void CS2Fixes::Hook_PostEvent(CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64* clients,
INetworkMessageInternal* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType)
{
Expand Down
3 changes: 0 additions & 3 deletions src/cs2fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ extern IGameEventSystem* g_gameEventSystem;
extern IGameEventManager2* g_gameEventManager;
extern CGameEntitySystem* g_pEntitySystem;
extern IVEngineServer2* g_pEngineServer2;
extern ISteamHTTP* g_http;
extern CSteamGameServerAPIContext g_steamAPI;
extern CCSGameRules* g_pGameRules;
extern CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr;
extern double g_flUniversalTime;
Expand All @@ -69,7 +67,6 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener, public ICS2Fixes

public: // hooks
void Hook_GameServerSteamAPIActivated();
void Hook_GameServerSteamAPIDeactivated();
void OnLevelInit(char const* pMapName,
char const* pMapEntities,
char const* pOldLevel,
Expand Down
20 changes: 10 additions & 10 deletions src/httpmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ void HTTPManager::TrackedRequest::OnHTTPRequestCompleted(HTTPRequestCompleted_t*
else
{
uint32 size;
g_http->GetHTTPResponseBodySize(arg->m_hRequest, &size);
GetSteamHTTP()->GetHTTPResponseBodySize(arg->m_hRequest, &size);

uint8* response = new uint8[size + 1];
g_http->GetHTTPResponseBodyData(arg->m_hRequest, response, size);
GetSteamHTTP()->GetHTTPResponseBodyData(arg->m_hRequest, response, size);
response[size] = 0; // Add null terminator

json jsonResponse;
Expand All @@ -101,8 +101,8 @@ void HTTPManager::TrackedRequest::OnHTTPRequestCompleted(HTTPRequestCompleted_t*
delete[] response;
}

if (g_http)
g_http->ReleaseHTTPRequest(arg->m_hRequest);
if (GetSteamHTTP())
GetSteamHTTP()->ReleaseHTTPRequest(arg->m_hRequest);

delete this;
}
Expand Down Expand Up @@ -141,14 +141,14 @@ void HTTPManager::GenerateRequest(EHTTPMethod method, const char* pszUrl, const
CompletedCallback callbackCompleted, ErrorCallback callbackError,
std::vector<HTTPHeader>* headers)
{
if (!g_http)
if (!GetSteamHTTP())
{
Panic("A web request was attempted before g_http was instantiated, returning early.\n");
Panic("A web request was attempted on null ISteamHTTP, returning early.\n");
return;
}

// Message("Sending HTTP:\n%s\n", pszText);
auto hReq = g_http->CreateHTTPRequest(method, pszUrl);
auto hReq = GetSteamHTTP()->CreateHTTPRequest(method, pszUrl);
int size = strlen(pszText);
// Message("HTTP request: %p\n", hReq);

Expand All @@ -157,7 +157,7 @@ void HTTPManager::GenerateRequest(EHTTPMethod method, const char* pszUrl, const
|| method == k_EHTTPMethodPUT
|| method == k_EHTTPMethodDELETE;

if (shouldHaveBody && !g_http->SetHTTPRequestRawPostBody(hReq, "application/json", (uint8*)pszText, size))
if (shouldHaveBody && !GetSteamHTTP()->SetHTTPRequestRawPostBody(hReq, "application/json", (uint8*)pszText, size))
{
// Message("Failed to SetHTTPRequestRawPostBody\n");
return;
Expand All @@ -168,10 +168,10 @@ void HTTPManager::GenerateRequest(EHTTPMethod method, const char* pszUrl, const

if (headers != nullptr)
for (HTTPHeader header : *headers)
g_http->SetHTTPRequestHeaderValue(hReq, header.GetName(), header.GetValue());
GetSteamHTTP()->SetHTTPRequestHeaderValue(hReq, header.GetName(), header.GetValue());

SteamAPICall_t hCall;
g_http->SendHTTPRequest(hReq, &hCall);
GetSteamHTTP()->SendHTTPRequest(hReq, &hCall);

new TrackedRequest(hReq, hCall, pszUrl, pszText, callbackCompleted, callbackError);
}
33 changes: 21 additions & 12 deletions src/map_votes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,13 +861,13 @@ void CMapVoteSystem::ForceNextMap(CCSPlayerController* pController, const char*

void CMapVoteSystem::PrintDownloadProgress()
{
if (GetDownloadQueueSize() == 0)
if (GetDownloadQueueSize() == 0 || !GetSteamUGC())
return;

uint64 iBytesDownloaded = 0;
uint64 iTotalBytes = 0;

if (!g_steamAPI.SteamUGC()->GetItemDownloadInfo(m_DownloadQueue.front(), &iBytesDownloaded, &iTotalBytes) || !iTotalBytes)
if (!GetSteamUGC()->GetItemDownloadInfo(m_DownloadQueue.front(), &iBytesDownloaded, &iTotalBytes) || !iTotalBytes)
return;

double flMBDownloaded = (double)iBytesDownloaded / 1024 / 1024;
Expand All @@ -881,7 +881,7 @@ void CMapVoteSystem::PrintDownloadProgress()

void CMapVoteSystem::OnMapDownloaded(DownloadItemResult_t* pResult)
{
if (std::find(m_DownloadQueue.begin(), m_DownloadQueue.end(), pResult->m_nPublishedFileId) == m_DownloadQueue.end())
if (std::find(m_DownloadQueue.begin(), m_DownloadQueue.end(), pResult->m_nPublishedFileId) == m_DownloadQueue.end() || !GetSteamUGC())
return;

// Some weird rate limiting that's been observed? Back off for a while then retry download
Expand All @@ -891,7 +891,7 @@ void CMapVoteSystem::OnMapDownloaded(DownloadItemResult_t* pResult)
Message("Addon %llu download failed with status code 3, retrying in 2 minutes\n", workshopID);

m_pRateLimitedDownloadTimer = CTimer::Create(120.0f, TIMERFLAG_NONE, [workshopID]() {
g_steamAPI.SteamUGC()->DownloadItem(workshopID, false);
GetSteamUGC()->DownloadItem(workshopID, false);

return -1.0f;
});
Expand All @@ -904,7 +904,7 @@ void CMapVoteSystem::OnMapDownloaded(DownloadItemResult_t* pResult)
if (GetDownloadQueueSize() == 0)
return;

g_steamAPI.SteamUGC()->DownloadItem(m_DownloadQueue.front(), false);
GetSteamUGC()->DownloadItem(m_DownloadQueue.front(), false);
}

void CMapVoteSystem::QueueMapDownload(PublishedFileId_t iWorkshopId)
Expand All @@ -915,7 +915,7 @@ void CMapVoteSystem::QueueMapDownload(PublishedFileId_t iWorkshopId)
m_DownloadQueue.push_back(iWorkshopId);

if (m_DownloadQueue.front() == iWorkshopId)
g_steamAPI.SteamUGC()->DownloadItem(iWorkshopId, false);
GetSteamUGC()->DownloadItem(iWorkshopId, false);
}

bool CMapVoteSystem::LoadMapList()
Expand Down Expand Up @@ -1388,17 +1388,24 @@ std::pair<int, std::shared_ptr<CMap>> CMapVoteSystem::GetMapInfoByIdentifiers(co

std::shared_ptr<CMapSystemWorkshopDetailsQuery> CMapSystemWorkshopDetailsQuery::Create(uint64 iWorkshopId, CCSPlayerController* pController, QueryCallback_t callbackSuccess)
{
if (!GetSteamUGC())
{
Panic("A workshop map query was attempted on null ISteamUGC, returning early.\n");
ClientPrint(pController, HUD_PRINTTALK, CHAT_PREFIX "Failed to query workshop map information for ID \x06%llu\x01.", iWorkshopId);
return nullptr;
}

uint64 iWorkshopIDArray[1] = {iWorkshopId};
UGCQueryHandle_t hQuery = g_steamAPI.SteamUGC()->CreateQueryUGCDetailsRequest(iWorkshopIDArray, 1);
UGCQueryHandle_t hQuery = GetSteamUGC()->CreateQueryUGCDetailsRequest(iWorkshopIDArray, 1);

if (hQuery == k_UGCQueryHandleInvalid)
{
ClientPrint(pController, HUD_PRINTTALK, CHAT_PREFIX "Failed to query workshop map information for ID \x06%llu\x01.", iWorkshopId);
return nullptr;
}

g_steamAPI.SteamUGC()->SetAllowCachedResponse(hQuery, 0);
SteamAPICall_t hCall = g_steamAPI.SteamUGC()->SendQueryUGCRequest(hQuery);
GetSteamUGC()->SetAllowCachedResponse(hQuery, 0);
SteamAPICall_t hCall = GetSteamUGC()->SendQueryUGCRequest(hQuery);

auto pQuery = std::make_shared<CMapSystemWorkshopDetailsQuery>(hQuery, iWorkshopId, pController, callbackSuccess);
g_pMapVoteSystem->AddWorkshopDetailsQuery(pQuery);
Expand All @@ -1415,7 +1422,7 @@ void CMapSystemWorkshopDetailsQuery::OnQueryCompleted(SteamUGCQueryCompleted_t*
// Only allow null controller if controller was originally null (console)
if (m_bConsole || pController)
{
if (bFailed || pCompletedQuery->m_eResult != k_EResultOK || pCompletedQuery->m_unNumResultsReturned < 1 || !g_steamAPI.SteamUGC()->GetQueryUGCResult(pCompletedQuery->m_handle, 0, &details) || details.m_eResult != k_EResultOK)
if (bFailed || pCompletedQuery->m_eResult != k_EResultOK || pCompletedQuery->m_unNumResultsReturned < 1 || !GetSteamUGC()->GetQueryUGCResult(pCompletedQuery->m_handle, 0, &details) || details.m_eResult != k_EResultOK)
{
ClientPrint(pController, HUD_PRINTTALK, CHAT_PREFIX "Failed to query workshop map information for ID \x06%llu\x01.", m_iWorkshopId);
}
Expand All @@ -1426,12 +1433,14 @@ void CMapSystemWorkshopDetailsQuery::OnQueryCompleted(SteamUGCQueryCompleted_t*
else
{
// Try to get a head start on downloading the map if needed
g_steamAPI.SteamUGC()->DownloadItem(m_iWorkshopId, false);
GetSteamUGC()->DownloadItem(m_iWorkshopId, false);
m_callbackSuccess(std::make_shared<CMap>(details.m_rgchTitle, m_iWorkshopId), pController);
}
}

g_steamAPI.SteamUGC()->ReleaseQueryUGCRequest(m_hQuery);
if (GetSteamUGC())
GetSteamUGC()->ReleaseQueryUGCRequest(m_hQuery);

g_pMapVoteSystem->RemoveWorkshopDetailsQuery(shared_from_this());
}

Expand Down
18 changes: 13 additions & 5 deletions src/mapmigrations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,23 @@ void CMapMigrations::UpdateMapUpdateTime(time_t timeMapUpdated)

std::shared_ptr<CMapMigrationWorkshopDetailsQuery> CMapMigrationWorkshopDetailsQuery::Create(uint64 iWorkshopId)
{
if (!GetSteamUGC())
{
Panic("Map migrations failed to find current map update time: null ISteamUGC\n");
return nullptr;
}

uint64 iWorkshopIDArray[1] = {iWorkshopId};
UGCQueryHandle_t hQuery = g_steamAPI.SteamUGC()->CreateQueryUGCDetailsRequest(iWorkshopIDArray, 1);
UGCQueryHandle_t hQuery = GetSteamUGC()->CreateQueryUGCDetailsRequest(iWorkshopIDArray, 1);

if (hQuery == k_UGCQueryHandleInvalid)
{
Panic("Map migrations failed to find current map update time: failed to query workshop map information for ID %llu\n", iWorkshopId);
return nullptr;
}

g_steamAPI.SteamUGC()->SetAllowCachedResponse(hQuery, 0);
SteamAPICall_t hCall = g_steamAPI.SteamUGC()->SendQueryUGCRequest(hQuery);
GetSteamUGC()->SetAllowCachedResponse(hQuery, 0);
SteamAPICall_t hCall = GetSteamUGC()->SendQueryUGCRequest(hQuery);

auto pQuery = std::make_shared<CMapMigrationWorkshopDetailsQuery>(hQuery, iWorkshopId);
g_pMapMigrations->AddWorkshopDetailsQuery(pQuery);
Expand All @@ -133,11 +139,13 @@ void CMapMigrationWorkshopDetailsQuery::OnQueryCompleted(SteamUGCQueryCompleted_
{
SteamUGCDetails_t details;

if (bFailed || pCompletedQuery->m_eResult != k_EResultOK || pCompletedQuery->m_unNumResultsReturned < 1 || !g_steamAPI.SteamUGC()->GetQueryUGCResult(pCompletedQuery->m_handle, 0, &details) || details.m_eResult != k_EResultOK)
if (bFailed || pCompletedQuery->m_eResult != k_EResultOK || pCompletedQuery->m_unNumResultsReturned < 1 || !GetSteamUGC()->GetQueryUGCResult(pCompletedQuery->m_handle, 0, &details) || details.m_eResult != k_EResultOK)
Panic("Map migrations failed to find current map update time: failed to query workshop map information for ID %llu\n", m_iWorkshopId);
else
g_pMapMigrations->UpdateMapUpdateTime(details.m_rtimeUpdated);

g_steamAPI.SteamUGC()->ReleaseQueryUGCRequest(m_hQuery);
if (GetSteamUGC())
GetSteamUGC()->ReleaseQueryUGCRequest(m_hQuery);

g_pMapMigrations->RemoveWorkshopDetailsQuery(shared_from_this());
}
16 changes: 16 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,20 @@ std::string StringToLower(std::string strValue)
strValue[i] = tolower(strValue[i]);

return strValue;
}

ISteamUGC* GetSteamUGC()
{
if (g_pEngineServer2->IsDedicatedServer())
return SteamGameServerUGC();
else
return SteamUGC();
}

ISteamHTTP* GetSteamHTTP()
{
if (g_pEngineServer2->IsDedicatedServer())
return SteamGameServerHTTP();
else
return SteamHTTP();
}
4 changes: 4 additions & 0 deletions src/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include "playerslot.h"
#include "steam/isteamugc.h"
#include "utlvector.h"
#include <string>

Expand All @@ -33,3 +34,6 @@ CServerSideClient* GetClientBySlot(CPlayerSlot slot);

uint32 GetSoundEventHash(const char* pszSoundEventName);
std::string StringToLower(std::string strValue);

ISteamUGC* GetSteamUGC();
ISteamHTTP* GetSteamHTTP();