diff --git a/dll/base.cpp b/dll/base.cpp index 21917211..d8902baf 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -27,7 +27,7 @@ randombytes(char * const buf, const size_t size) PRINT_DEBUG("BCryptGenRandom ERROR\n"); Sleep(100); } - + } std::string get_env_variable(std::string name) @@ -96,6 +96,10 @@ bool set_env_variable(std::string name, std::string value) std::recursive_mutex global_mutex; +// some arbitrary counter/time for reference +const std::chrono::time_point startup_counter = std::chrono::high_resolution_clock::now(); +const std::chrono::time_point startup_time = std::chrono::system_clock::now(); + #ifndef EMU_RELEASE_BUILD const std::string dbg_log_file = get_full_program_path() + "STEAM_LOG.txt"; #endif diff --git a/dll/base.h b/dll/base.h index 6a2bb6ba..d9fcbd0a 100644 --- a/dll/base.h +++ b/dll/base.h @@ -23,6 +23,8 @@ #define PUSH_BACK_IF_NOT_IN(vector, element) { if(std::find(vector.begin(), vector.end(), element) == vector.end()) vector.push_back(element); } extern std::recursive_mutex global_mutex; +extern const std::chrono::time_point startup_counter; +extern const std::chrono::time_point startup_time; std::string get_env_variable(std::string name); bool set_env_variable(std::string name, std::string value); diff --git a/dll/common_includes.h b/dll/common_includes.h index b199a5a1..e8e5bbc1 100644 --- a/dll/common_includes.h +++ b/dll/common_includes.h @@ -49,6 +49,7 @@ #define STEAM_API_EXPORTS +// OS specific includes + definitions #if defined(__WINDOWS__) #include #include @@ -59,22 +60,16 @@ #include // Include winsock2 before this, or winsock2 iphlpapi will be unavailable #include - #define MSG_NOSIGNAL 0 - + // we need this for BCryptGenRandom() in base.cpp #include - #ifndef EMU_RELEASE_BUILD - #include - extern const std::string dbg_log_file; - #define PRINT_DEBUG(a, ...) do {FILE *t = fopen(dbg_log_file.c_str(), "a"); fprintf(t, "%u " a, GetCurrentThreadId(), __VA_ARGS__); fclose(t); WSASetLastError(0);} while (0) - #endif + #define MSG_NOSIGNAL 0 EXTERN_C IMAGE_DOS_HEADER __ImageBase; #define PATH_SEPARATOR "\\" #ifdef EMU_EXPERIMENTAL_BUILD #include - #include "../detours/detours.h" #endif @@ -105,6 +100,10 @@ inline void reset_LastError() } #elif defined(__LINUX__) + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif // _GNU_SOURCE + #include #include @@ -127,21 +126,10 @@ inline void reset_LastError() #include #define PATH_MAX_STRING_SIZE 512 - - #ifndef EMU_RELEASE_BUILD - #include - extern const std::string dbg_log_file; - #define PRINT_DEBUG(...) {FILE *t = fopen(dbg_log_file.c_str(), "a"); fprintf(t, __VA_ARGS__); fclose(t);} - #endif #define PATH_SEPARATOR "/" - #define utf8_decode(a) a #define reset_LastError() #endif -//#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__) -#ifdef EMU_RELEASE_BUILD - #define PRINT_DEBUG(...) -#endif // C/C++ includes #include @@ -167,6 +155,39 @@ inline void reset_LastError() #include #include +// PRINT_DEBUG definition +// notice the extra call to WSASetLastError(0) in Windows def +#ifndef EMU_RELEASE_BUILD + //#define PRINT_DEBUG(...) fprintf(stdout, __VA_ARGS__) + extern const std::string dbg_log_file; + extern const std::chrono::time_point startup_counter; + #if defined(__WINDOWS__) + #define PRINT_DEBUG(a, ...) do { \ + auto ctr = std::chrono::high_resolution_clock::now(); \ + auto duration = ctr - startup_counter; \ + auto micro = std::chrono::duration_cast>(duration); \ + auto ms = std::chrono::duration_cast>(duration); \ + FILE *t = fopen(dbg_log_file.c_str(), "a"); \ + fprintf(t, "[%llu ms, %llu us] [tid %d] " a, ms.count(), micro.count(), GetCurrentThreadId(), __VA_ARGS__); \ + fclose(t); \ + WSASetLastError(0); \ + } while (0) + #elif defined(__LINUX__) + #include + #define PRINT_DEBUG(a, ...) do { \ + auto ctr = std::chrono::high_resolution_clock::now(); \ + auto duration = ctr - startup_counter; \ + auto micro = std::chrono::duration_cast>(duration); \ + auto ms = std::chrono::duration_cast>(duration); \ + FILE *t = fopen(dbg_log_file.c_str(), "a"); \ + fprintf(t, "[%llu ms, %llu us] [tid %d] " a, ms.count(), micro.count(), syscall(SYS_gettid), ##__VA_ARGS__); \ + fclose(t); \ + } while (0) + #endif +#else // EMU_RELEASE_BUILD + #define PRINT_DEBUG(...) +#endif // EMU_RELEASE_BUILD + inline std::string ascii_to_lowercase(std::string data) { std::transform(data.begin(), data.end(), data.begin(), [](unsigned char c){ return std::tolower(c); });