/goldsrc-reversed-steam_api

Reverse-Engineered steam_api module that ships with the GoldSource engine.

Primary LanguageC++

GoldSrc reverse-engineered steam_api module

This repository contains *original* source code for the steam_api module that is used within GoldSource engine.

Disclaimer

I've posted this code for educational purposes only, thus it is not compileable, unless you set up the entire project including linkage and all include files necessary. Meaning that if you know what you're doing - you can easily compile and run this module by yourself.

While reversing this module, originality is retained and no changes are made or added to the existing code.

Corectness

Bugs may exist. The code was tested on the newest version of the game and everything works as should, thus it's more likely that the code is sufficient and bug-proof enough to work without any issues. However there still may be some edge cases that I've either wasn't able to test properly or that I've missed. So testing and feedback is much appreciated.

Information

The module serves a purpose of a communication pipeline between the game and some services from the internal steamclient API.

It is also responsible for loading all the steamclient interfaces (ISteamClient, ISteamUtils, IsteamHTTP, etc..) for a particular module that calls SteamAPI_Init() function.

Where is the API referenced inside the engine

The Download Manager and CMultipleCallResults class

One reference would be inside the DLM. Upon receiving files from the server to be downloaded, the DLM schedules these files to be downloaded simultaneously. The hardcoded limit for GS is 5 at the time inside the queue.

Requesting a file to be downloaded

// inside DownloadManager::StartNewDownload()
if (SteamHTTP()->SendHTTPRequest(..., &hSteamAPICall))
{
    // Add call for the steamAPI to process it
    m_HTTPRequestCompleted.AddCall(hSteamAPICall);
}
else
{
    // Handle error and release request
}

First a download request is requested from the SteamHTTP interface. If the request has been accepted, an API call we got from the request can be passed into the CMultipleCallResults class that then calls the internal API of steam_api module.

Adding an APICall to the CallbackManager

template <class T, class P>
inline void CMultipleCallResults<T, P>::AddCall(SteamAPICall_t hSteamAPICall)
{
    // ...

    m_mapAPICalls.Insert(hSteamAPICall);

    SteamAPI_RegisterCallResult(this, hSteamAPICall);
}

This is where the communication between the engine and steam_api occurs. The steam_api's Callback Manager class takes care of these APICall handles and does some more communcation with steamclient API before calling the DownloadManager::OnHTTPRequestCompleted() dispatch routine.