@@ -44,7 +44,17 @@ namespace pew::eos
4444 {
4545 return eos_library_helpers::eos_platform_handle;
4646 }
47-
47+
48+ typedef bool (__cdecl* SteamAPI_Init_t)();
49+
50+ /* *
51+ * @brief Initializes the steam api using the given function name.
52+ * @param steam_dll_handle Pointer to the steam dll
53+ * @param function_name The name of the function to initialize with.
54+ * @return True if the steam api was initialized, false otherwise.
55+ */
56+ static bool initialize_steam_api (void * steam_dll_handle, const std::string& function_name);
57+
4858 /* *
4959 * @brief Loads and initializes the Steam API DLL using a string path.
5060 *
@@ -245,35 +255,41 @@ namespace pew::eos
245255 " attempting to load a pointer to the SteamAPI_Init function from "
246256 " within it." );
247257
248- // TODO: Typedef should be moved outside the scope of the function?
249- typedef bool (__cdecl* SteamAPI_Init_t)();
258+ // Usage
259+ if (!initialize_steam_api (steam_dll_handle, " SteamAPI_InitSafe" ))
260+ {
261+ // Retry with "SteamAPI_Init" if "SteamAPI_InitSafe" fails.
262+ initialize_steam_api (steam_dll_handle, " SteamAPI_Init" );
263+ }
264+ }
250265
251- // Get a pointer to the SteamAPI_Init function within the steam
252- // library.
253- const auto SteamAPI_Init_Fn = pew::eos::eos_library_helpers::load_function_with_name<SteamAPI_Init_t>(steam_dll_handle, " SteamAPI_InitSafe" );
266+ static bool initialize_steam_api (void * steam_dll_handle, const std::string& function_name)
267+ {
268+ // Get a pointer to the specified SteamAPI_Init function within the steam library.
269+ const auto SteamAPI_Init_Fn = pew::eos::eos_library_helpers::load_function_with_name<SteamAPI_Init_t>(steam_dll_handle, function_name.c_str ());
254270
255- // If the SteamAPI_Init function pointer is null, then it was not
256- // correctly retrieved from the steam library. Log an error and stop
271+ // If the function pointer is null, log an error and return false.
257272 if (SteamAPI_Init_Fn == nullptr )
258273 {
259274 logging::log_error (
260- " Could not load a pointer to the SteamAPI_Init "
261- " function within the loaded steam library handle." );
262- return ;
275+ " Could not load a pointer to the " + function_name +
276+ " function within the loaded steam library handle." );
277+ return false ;
263278 }
264279
280+ // Attempt to initialize Steam and log the result.
265281 if (SteamAPI_Init_Fn ())
266282 {
267- logging::log_inform (" SteamAPI_Init returned true. "
268- " Steam has been initialized. " ) ;
283+ logging::log_inform (function_name + " returned true. Steam has been initialized. " );
284+ return true ;
269285 }
270286 else
271287 {
272- logging::log_error (
273- " SteamAPI_Init returned false. Steam was not able "
274- " to be initialized." );
288+ logging::log_error (function_name + " returned false. Steam was not able to be initialized." );
289+ return false ;
275290 }
276291 }
292+
277293
278294 void apply_steam_settings (EOS_Platform_Options& platform_options)
279295 {
0 commit comments