From ae44d5c2bc7e67d15f6e946d51a6430560c5ee74 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 17 Sep 2018 14:23:35 +0200 Subject: [PATCH] Adds minimal Steam fiddling protection --- CMakeLists.txt | 2 +- src/main.c | 13 +++++++++---- src/steam/steamworks_api_wrapper.c | 6 ++++++ src/steam/steamworks_api_wrapper.h | 2 ++ steamworks_c_wrapper/src/steamworks_c_wrapper.cpp | 5 +++++ steamworks_c_wrapper/src/steamworks_c_wrapper.h | 3 +++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30d089a..5d1b658 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") set(breakhack_MAJOR_VERSION 1) set(breakhack_MINOR_VERSION 1) -set(breakhack_PATCH_VERSION 3) +set(breakhack_PATCH_VERSION 4) set(breakhack_RELEASE_TYPE "") include(FindLua) diff --git a/src/main.c b/src/main.c index bd84a83..5ac7bb9 100644 --- a/src/main.c +++ b/src/main.c @@ -526,16 +526,21 @@ resetGame(void) static bool init(void) { +#ifdef STEAM_BUILD + if (!steam_restart_needed()) { + steam_init(); + } else { + error("%s needs to be started through Steam", GAME_TITLE); + return false; + } +#endif // STEAM_BUILD + if (!initSDL()) { return false; } else if (!initGame()) { return false; } -#ifdef STEAM_BUILD - steam_init(); -#endif // STEAM_BUILD - settings_init(); hiscore_init(); initMainMenu(); diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 05f1a51..8c6844c 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -58,6 +58,12 @@ leaderboard_received(Sint64 hLeaderboard, const char *name) m_hKillsLeaderboard = hLeaderboard; } +bool +steam_restart_needed() +{ + return c_SteamAPI_RestartAppIfNecessary(); +} + void steam_init() { diff --git a/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h index fcd8d75..58fc507 100644 --- a/src/steam/steamworks_api_wrapper.h +++ b/src/steam/steamworks_api_wrapper.h @@ -25,6 +25,8 @@ typedef struct Achievement { int m_iIconImage; } Achievement; +bool steam_restart_needed(void); + void steam_init(void); void steam_shutdown(void); diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index e8acf1c..bf9d6d5 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -47,6 +47,11 @@ c_SteamAPI_GetAppID() return m_AppId; } +bool c_SteamAPI_RestartAppIfNecessary() +{ + return SteamAPI_RestartAppIfNecessary(931040); +} + void c_SteamAPI_RunCallbacks(void) { diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index acebea2..a493a0a 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -26,6 +26,9 @@ c_SteamAPI_Init(void); int64_t c_SteamAPI_GetAppID(void); +bool +c_SteamAPI_RestartAppIfNecessary(void); + void c_SteamAPI_RunCallbacks(void);