diff --git a/dll/auth.cpp b/dll/auth.cpp index bcf143de..322ec1e2 100644 --- a/dll/auth.cpp +++ b/dll/auth.cpp @@ -1,5 +1,21 @@ #include "auth.h" +static inline int generate_random_int() { + int a; + randombytes((char *)&a, sizeof(a)); + return a; +} + +static uint32 generate_steam_ticket_id() { + /* not random starts with 2? */ + static uint32 a = 1; + ++a; + // this must never return 0, it is reserved for "k_HAuthTicketInvalid" when the auth APIs fail + if (a == 0) ++a; + return a; +} + + static void steam_auth_manager_ticket_callback(void *object, Common_Message *msg) { PRINT_DEBUG("steam_auth_manager_ticket_callback\n"); diff --git a/dll/base.cpp b/dll/base.cpp index 3fa763c5..4a935f4e 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -19,8 +19,7 @@ #ifdef __WINDOWS__ -static void -randombytes(char * const buf, const size_t size) +void randombytes(char *buf, size_t size) { // NT_SUCCESS is: return value >= 0, including Ntdef.h causes so many errors while (BCryptGenRandom(NULL, (PUCHAR) buf, (ULONG) size, BCRYPT_USE_SYSTEM_PREFERRED_RNG) < 0) { @@ -51,7 +50,7 @@ bool set_env_variable(std::string name, std::string value) static int fd = -1; -static void randombytes(char *buf, size_t size) +void randombytes(char *buf, size_t size) { int i; @@ -104,29 +103,7 @@ const std::chrono::time_point startup_time = std::chr const std::string dbg_log_file = get_full_program_path() + "STEAM_LOG.txt"; #endif -SteamAPICall_t generate_steam_api_call_id() { - static SteamAPICall_t a; - randombytes((char *)&a, sizeof(a)); - ++a; - if (a == 0) ++a; - return a; -} - -int generate_random_int() { - int a; - randombytes((char *)&a, sizeof(a)); - return a; -} - -uint32 generate_steam_ticket_id() { - /* not random starts with 2? */ - static uint32 a = 1; - ++a; - if (a == 0) ++a; - return a; -} - -static unsigned generate_account_id() +unsigned generate_account_id() { int a; randombytes((char *)&a, sizeof(a)); @@ -135,16 +112,24 @@ static unsigned generate_account_id() return a; } -CSteamID generate_steam_id_user() -{ - return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeIndividual); -} - CSteamID generate_steam_anon_user() { return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeAnonUser); } +SteamAPICall_t generate_steam_api_call_id() { + static SteamAPICall_t a; + randombytes((char *)&a, sizeof(a)); + ++a; + if (a == 0) ++a; + return a; +} + +CSteamID generate_steam_id_user() +{ + return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeIndividual); +} + CSteamID generate_steam_id_server() { return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeGameServer); @@ -160,22 +145,6 @@ CSteamID generate_steam_id_lobby() return CSteamID(generate_account_id(), k_EChatInstanceFlagLobby | k_EChatInstanceFlagMMSLobby, k_EUniversePublic, k_EAccountTypeChat); } -std::string uint8_vector_to_hex_string(std::vector& v) -{ - std::string result; - result.reserve(v.size() * 2); // two digits per character - - static constexpr char hex[] = "0123456789ABCDEF"; - - for (uint8_t c : v) - { - result.push_back(hex[c / 16]); - result.push_back(hex[c % 16]); - } - - return result; -} - bool check_timedout(std::chrono::high_resolution_clock::time_point old, double timeout) { if (timeout == 0.0) return true; diff --git a/dll/base.h b/dll/base.h index e656a7b7..779c3a29 100644 --- a/dll/base.h +++ b/dll/base.h @@ -26,6 +26,7 @@ extern std::recursive_mutex global_mutex; extern const std::chrono::time_point startup_counter; extern const std::chrono::time_point startup_time; +void randombytes(char *buf, size_t size); std::string get_env_variable(std::string name); bool set_env_variable(std::string name, std::string value); bool check_timedout(std::chrono::high_resolution_clock::time_point old, double timeout); @@ -94,15 +95,13 @@ struct Steam_Call_Result { int iCallback; }; -uint32 generate_steam_ticket_id(); -int generate_random_int(); +unsigned generate_account_id(); +CSteamID generate_steam_anon_user(); SteamAPICall_t generate_steam_api_call_id(); CSteamID generate_steam_id_user(); -CSteamID generate_steam_anon_user(); CSteamID generate_steam_id_server(); CSteamID generate_steam_id_anonserver(); CSteamID generate_steam_id_lobby(); -std::string uint8_vector_to_hex_string(std::vector& v); std::string get_full_lib_path(); std::string get_full_program_path(); std::string get_current_path(); @@ -306,7 +305,6 @@ public: } }; - struct Steam_Call_Back { std::vector callbacks; std::vector> results; diff --git a/dll/common_includes.h b/dll/common_includes.h index 60aeface..31ffccf1 100644 --- a/dll/common_includes.h +++ b/dll/common_includes.h @@ -217,6 +217,22 @@ static inline void thisThreadYieldFor(std::chrono::microseconds u) PRINT_DEBUG("Thread finished waiting\n"); } +static std::string uint8_vector_to_hex_string(std::vector& v) +{ + std::string result; + result.reserve(v.size() * 2); // two digits per character + + static constexpr char hex[] = "0123456789ABCDEF"; + + for (uint8_t c : v) + { + result.push_back(hex[c / 16]); + result.push_back(hex[c % 16]); + } + + return result; +} + // Emulator includes // add them here after the inline functions definitions #include "net.pb.h"