From f147638f993d804567959bf9193f52ba7eb89190 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Tue, 25 Jan 2022 15:51:00 -0500 Subject: [PATCH] Basic offline steamhttp emulation. --- Readme_release.txt | 7 +++ dll/steam_http.cpp | 44 ++++++++++++++++--- .../accounts.starbreeze.com/iam/oauth/token | 1 + 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 files_example/steam_settings.EXAMPLE/http.EXAMPLE/accounts.starbreeze.com/iam/oauth/token diff --git a/Readme_release.txt b/Readme_release.txt index ed4727a8..33467851 100644 --- a/Readme_release.txt +++ b/Readme_release.txt @@ -109,6 +109,13 @@ Build id: Add a steam_settings\build_id.txt with the build id if the game doesn't show the correct build id and you want the emu to give it the correct one. An example can be found in steam_settings.EXAMPLE +SteamHTTP: +Add a steam_settings\http folder. The folder should contain the domain name and path to the files that will be returned by steamHTTP like so: +For example this url: https://en.wikipedia.org/wiki/Main_Page +Would be: steam_settings\http\en.wikipedia.org\wiki\Main_Page +The Main_Page file would contain the data returned by the steamHTTP api when it tries to access: https://en.wikipedia.org/wiki/Main_Page +An example that was made for payday 2 can be found in steam_settings.EXAMPLE + Support for CPY steam_api(64).dll cracks: See the build in the experimental folder. diff --git a/dll/steam_http.cpp b/dll/steam_http.cpp index f3088a5b..71bf5414 100644 --- a/dll/steam_http.cpp +++ b/dll/steam_http.cpp @@ -39,9 +39,32 @@ Steam_Http_Request *Steam_HTTP::get_request(HTTPRequestHandle hRequest) HTTPRequestHandle Steam_HTTP::CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, const char *pchAbsoluteURL ) { PRINT_DEBUG("CreateHTTPRequest %i %s\n", eHTTPRequestMethod, pchAbsoluteURL); + if (!pchAbsoluteURL) return INVALID_HTTPREQUEST_HANDLE; + std::string url = pchAbsoluteURL; + unsigned url_index = 0; + if (url.rfind("https://", 0) == 0) { + url_index = sizeof("https://") - 1; + } else if (url.rfind("http://", 0) == 0) { + url_index = sizeof("http://") - 1; + } + + struct Steam_Http_Request request; + if (url_index) { + if (url[url.size() - 1] == '/') url += "index.html"; + std::string file_path = Local_Storage::get_game_settings_path() + "http/" + url.substr(url_index); + unsigned long long file_size = file_size_(file_path); + if (file_size) { + request.response.resize(file_size); + long long read = Local_Storage::get_file_data(file_path, (char *)request.response.data(), file_size, 0); + if (read < 0) read = 0; + if (read != file_size) request.response.resize(read); + } + } + + std::lock_guard lock(global_mutex); static HTTPRequestHandle h; ++h; - struct Steam_Http_Request request; + request.handle = h; request.context_value = 0; @@ -84,7 +107,7 @@ bool Steam_HTTP::SetHTTPRequestNetworkActivityTimeout( HTTPRequestHandle hReques // return false if the handle is invalid or the request is already sent. bool Steam_HTTP::SetHTTPRequestHeaderValue( HTTPRequestHandle hRequest, const char *pchHeaderName, const char *pchHeaderValue ) { - PRINT_DEBUG("SetHTTPRequestHeaderValue\n"); + PRINT_DEBUG("SetHTTPRequestHeaderValue %s %s\n", pchHeaderName, pchHeaderValue); Steam_Http_Request *request = get_request(hRequest); if (!request) { return false; @@ -122,12 +145,18 @@ bool Steam_HTTP::SendHTTPRequest( HTTPRequestHandle hRequest, SteamAPICall_t *pC return false; } - struct HTTPRequestCompleted_t data; + struct HTTPRequestCompleted_t data = {}; data.m_hRequest = request->handle; data.m_ulContextValue = request->context_value; - data.m_bRequestSuccessful = false; - data.m_eStatusCode = k_EHTTPStatusCode404NotFound; - data.m_unBodySize = request->response.size(); + if (request->response.size() == 0) { + data.m_bRequestSuccessful = false; + data.m_eStatusCode = k_EHTTPStatusCode404NotFound; + data.m_unBodySize = request->response.size(); + } else { + data.m_bRequestSuccessful = true; + data.m_eStatusCode = k_EHTTPStatusCode200OK; + data.m_unBodySize = request->response.size(); + } if (pCallHandle) { *pCallHandle = callback_results->addCallResult(data.k_iCallback, &data, sizeof(data), 0.1); @@ -245,6 +274,7 @@ bool Steam_HTTP::GetHTTPStreamingResponseBodyData( HTTPRequestHandle hRequest, u bool Steam_HTTP::ReleaseHTTPRequest( HTTPRequestHandle hRequest ) { PRINT_DEBUG("ReleaseHTTPRequest\n"); + std::lock_guard lock(global_mutex); auto c = std::begin(requests); while (c != std::end(requests)) { @@ -275,7 +305,7 @@ bool Steam_HTTP::GetHTTPDownloadProgressPct( HTTPRequestHandle hRequest, float * // parameter will set the content-type header for the request so the server may know how to interpret the body. bool Steam_HTTP::SetHTTPRequestRawPostBody( HTTPRequestHandle hRequest, const char *pchContentType, uint8 *pubBody, uint32 unBodyLen ) { - PRINT_DEBUG("SetHTTPRequestRawPostBody\n"); + PRINT_DEBUG("SetHTTPRequestRawPostBody %s\n", pchContentType); Steam_Http_Request *request = get_request(hRequest); if (!request) { return false; diff --git a/files_example/steam_settings.EXAMPLE/http.EXAMPLE/accounts.starbreeze.com/iam/oauth/token b/files_example/steam_settings.EXAMPLE/http.EXAMPLE/accounts.starbreeze.com/iam/oauth/token new file mode 100644 index 00000000..d5f929cd --- /dev/null +++ b/files_example/steam_settings.EXAMPLE/http.EXAMPLE/accounts.starbreeze.com/iam/oauth/token @@ -0,0 +1 @@ +{"access_token":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","bans":null,"display_name":"","expires_in":3600,"is_comply":true,"jflgs":0,"namespace":"PD2","namespace_roles":null,"permissions":[],"platform_id":"","platform_user_id":"","roles":null,"scope":"account commerce social publishing analytics","token_type":"Bearer","user_id":"","xuid":""} \ No newline at end of file