diff --git a/dll/dll/steam_apps.h b/dll/dll/steam_apps.h index bdf5cdbd..e44e004a 100644 --- a/dll/dll/steam_apps.h +++ b/dll/dll/steam_apps.h @@ -33,6 +33,9 @@ public ISteamApps class Settings *settings{}; class SteamCallResults *callback_results{}; class SteamCallBacks *callbacks{}; + + void FillProofOfPurchaseKey( AppProofOfPurchaseKeyResponse_t& data, AppId_t nAppID, bool ok_result, std::string key = "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" ); + void FillProofOfPurchaseKey( AppProofOfPurchaseKeyResponse007_t& data, AppId_t nAppID, bool ok_result, std::string key = "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" ); public: Steam_Apps(Settings *settings, class SteamCallResults *callback_results, class SteamCallBacks *callbacks); @@ -83,6 +86,7 @@ public: // You'll receive an AppProofOfPurchaseKeyResponse_t callback when // the key is available (which may be immediately). void RequestAppProofOfPurchaseKey( AppId_t nAppID ); + void RequestAppProofOfPurchaseKey_OLD( AppId_t nAppID ); bool GetCurrentBetaName( char *pchName, int cchNameBufferSize ); // returns current beta branch name, 'public' is the default branch bool MarkContentCorrupt( bool bMissingFilesOnly ); // signal Steam that game files seems corrupt or missing diff --git a/dll/steam_apps.cpp b/dll/steam_apps.cpp index 88dc3a9e..18f35965 100644 --- a/dll/steam_apps.cpp +++ b/dll/steam_apps.cpp @@ -18,6 +18,50 @@ #include "dll/steam_apps.h" #include "sha/sha1.hpp" + +void Steam_Apps::FillProofOfPurchaseKey( AppProofOfPurchaseKeyResponse_t& data, AppId_t nAppID, bool ok_result, std::string key ) +{ + data.m_nAppID = nAppID; + if (ok_result) { + // TODO maybe read this from a config file "purchased_keys.txt": + // 480=AAAAA-BBBBB-CCCCC-DDDDD + // 218620=XYZFJ-13370-98765 + size_t min_len = key.size() < k_cubAppProofOfPurchaseKeyMax + ? key.size() + : k_cubAppProofOfPurchaseKeyMax - 1; // -1 because we need space for null + data.m_eResult = EResult::k_EResultOK; + data.m_cchKeyLength = static_cast(min_len); + memcpy(data.m_rgchKey, key.c_str(), min_len); + data.m_rgchKey[min_len] = 0; + } else { + data.m_eResult = EResult::k_EResultFail; + data.m_cchKeyLength = 0; + data.m_rgchKey[0] = 0; + data.m_rgchKey[1] = 0; + } +} + +void Steam_Apps::FillProofOfPurchaseKey( AppProofOfPurchaseKeyResponse007_t& data, AppId_t nAppID, bool ok_result, std::string key ) +{ + data.m_nAppID = nAppID; + if (ok_result) { + // TODO maybe read this from a config file "purchased_keys.txt": + // 480=AAAAA-BBBBB-CCCCC-DDDDD + // 218620=XYZFJ-13370-98765 + size_t min_len = key.size() < k_cubAppProofOfPurchaseKeyMax + ? key.size() + : k_cubAppProofOfPurchaseKeyMax - 1; // -1 because we need space for null + data.m_eResult = EResult::k_EResultOK; + memcpy(data.m_rgchKey, key.c_str(), min_len); + data.m_rgchKey[min_len] = 0; + } else { + data.m_eResult = EResult::k_EResultFail; + data.m_rgchKey[0] = 0; + data.m_rgchKey[1] = 0; + } +} + + Steam_Apps::Steam_Apps(Settings *settings, class SteamCallResults *callback_results, class SteamCallBacks *callbacks) { this->settings = settings; @@ -220,28 +264,6 @@ void Steam_Apps::UninstallDLC( AppId_t nAppID ) } -static void FillProofOfPurchaseKey( AppProofOfPurchaseKeyResponse_t& data, AppId_t nAppID, bool ok_result, std::string key = "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" ) -{ - data.m_nAppID = nAppID; - if (ok_result) { - // TODO maybe read this from a config file "purchased_keys.txt": - // 480=AAAAA-BBBBB-CCCCC-DDDDD - // 218620=XYZFJ-13370-98765 - size_t min_len = key.size() < k_cubAppProofOfPurchaseKeyMax - ? key.size() < k_cubAppProofOfPurchaseKeyMax - : k_cubAppProofOfPurchaseKeyMax - 1; // -1 because we need space for null - data.m_eResult = EResult::k_EResultOK; - data.m_cchKeyLength = static_cast(min_len); - memcpy(data.m_rgchKey, key.c_str(), min_len); - data.m_rgchKey[min_len] = 0; - } else { - data.m_eResult = EResult::k_EResultFail; - data.m_cchKeyLength = 0; - data.m_rgchKey[0] = 0; - data.m_rgchKey[1] = 0; - } -} - // Request legacy cd-key for yourself or owned DLC. If you are interested in this // data then make sure you provide us with a list of valid keys to be distributed // to users when they purchase the game, before the game ships. @@ -268,6 +290,28 @@ void Steam_Apps::RequestAppProofOfPurchaseKey( AppId_t nAppID ) callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); } +void Steam_Apps::RequestAppProofOfPurchaseKey_OLD( AppId_t nAppID ) +{ + PRINT_DEBUG_TODO(); + std::lock_guard lock(global_mutex); + + AppProofOfPurchaseKeyResponse007_t data{}; + data.m_nAppID = nAppID; + + // check Steam_Apps::BIsAppInstalled() + if (nAppID == 0 || nAppID == UINT32_MAX) { + FillProofOfPurchaseKey(data, nAppID, false); + } else if (nAppID == settings->get_local_game_id().AppID() || settings->hasDLC(nAppID)) { + FillProofOfPurchaseKey(data, nAppID, true); + } else { + //TODO what to do here? + FillProofOfPurchaseKey(data, nAppID, false); + } + + callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); +} + + // returns current beta branch name, 'public' is the default branch // "true if the user is on a beta branch; otherwise, false" // https://partner.steamgames.com/doc/api/ISteamApps @@ -423,15 +467,15 @@ void Steam_Apps::RequestAllProofOfPurchaseKeys() // DLCs const auto count = settings->DLCCount(); - for (unsigned int i = 0; i < settings->DLCCount(); i++) { - AppId_t app_id; - bool available; - std::string name; - settings->getDLC(i, app_id, available, name); - - AppProofOfPurchaseKeyResponse_t data{}; - FillProofOfPurchaseKey(data, app_id, true); - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); + for (unsigned i = 0; i < settings->DLCCount(); i++) { + AppId_t app_id{}; + bool available{}; + std::string name{}; + if (settings->getDLC(i, app_id, available, name)) { + AppProofOfPurchaseKeyResponse_t data{}; + FillProofOfPurchaseKey(data, app_id, true); + callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); + } } // termination entry @@ -454,7 +498,7 @@ SteamAPICall_t Steam_Apps::GetFileDetails( const char* pszFileName ) if (file_exists_(pszFileName)) { data.m_eResult = k_EResultOK; // std::ifstream stream(std::filesystem::u8path(pszFileName), std::ios::binary); - SHA1 checksum; + SHA1 checksum{}; checksum.update(stream); checksum.final().copy((char *)data.m_FileSHA, sizeof(data.m_FileSHA)); data.m_ulFileSize = file_size_(pszFileName); diff --git a/sdk/steam/isteamapps005.h b/sdk/steam/isteamapps005.h index 6b318b21..feecd9e0 100644 --- a/sdk/steam/isteamapps005.h +++ b/sdk/steam/isteamapps005.h @@ -44,7 +44,7 @@ public: // to users when they purchase the game, before the game ships. // You'll receive an AppProofOfPurchaseKeyResponse_t callback when // the key is available (which may be immediately). - virtual void RequestAppProofOfPurchaseKey( AppId_t nAppID ) = 0; + virtual void RequestAppProofOfPurchaseKey_OLD( AppId_t nAppID ) = 0; virtual bool GetCurrentBetaName( char *pchName, int cchNameBufferSize ) = 0; // returns current beta branch name, 'public' is the default branch virtual bool MarkContentCorrupt( bool bMissingFilesOnly ) = 0; // signal Steam that game files seems corrupt or missing diff --git a/sdk/steam/isteamapps006.h b/sdk/steam/isteamapps006.h index 1e2d2736..9f35cd78 100644 --- a/sdk/steam/isteamapps006.h +++ b/sdk/steam/isteamapps006.h @@ -44,7 +44,7 @@ public: // to users when they purchase the game, before the game ships. // You'll receive an AppProofOfPurchaseKeyResponse_t callback when // the key is available (which may be immediately). - virtual void RequestAppProofOfPurchaseKey( AppId_t nAppID ) = 0; + virtual void RequestAppProofOfPurchaseKey_OLD( AppId_t nAppID ) = 0; virtual bool GetCurrentBetaName( char *pchName, int cchNameBufferSize ) = 0; // returns current beta branch name, 'public' is the default branch virtual bool MarkContentCorrupt( bool bMissingFilesOnly ) = 0; // signal Steam that game files seems corrupt or missing diff --git a/sdk/steam/isteamapps007.h b/sdk/steam/isteamapps007.h index 6028e1f8..5ebd0018 100644 --- a/sdk/steam/isteamapps007.h +++ b/sdk/steam/isteamapps007.h @@ -44,7 +44,7 @@ public: // to users when they purchase the game, before the game ships. // You'll receive an AppProofOfPurchaseKeyResponse_t callback when // the key is available (which may be immediately). - virtual void RequestAppProofOfPurchaseKey( AppId_t nAppID ) = 0; + virtual void RequestAppProofOfPurchaseKey_OLD( AppId_t nAppID ) = 0; virtual bool GetCurrentBetaName( char *pchName, int cchNameBufferSize ) = 0; // returns current beta branch name, 'public' is the default branch virtual bool MarkContentCorrupt( bool bMissingFilesOnly ) = 0; // signal Steam that game files seems corrupt or missing @@ -69,4 +69,18 @@ public: virtual int GetAppBuildId() = 0; }; + + +//----------------------------------------------------------------------------- +// Purpose: response to RegisterActivationCode() +//----------------------------------------------------------------------------- +struct AppProofOfPurchaseKeyResponse007_t +{ + enum { k_iCallback = k_iSteamAppsCallbacks + 13 }; + EResult m_eResult; + uint32 m_nAppID; + char m_rgchKey[ k_cubAppProofOfPurchaseKeyMax ]; +}; + + #endif //ISTEAMAPPS007_H