Skip to content

Commit 0ce4326

Browse files
committed
fix: Fall back on 'SteamAPI_Init' if 'SteamAPI_InitSafe' doesn't work.
1 parent 132910a commit 0ce4326

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:289abdcf9b70e7b16e4e5a6f343bb57f1fc8029f6fef0440ec5a00e9a219cadf
2+
oid sha256:969153308fe56d512c998509226a5a84918b8624c4691f06345a434396d136a7
33
size 122880
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:79a511b125f063220d067262b3386724505a714138315ac4685b5ea4ed67a30c
3-
size 603648
2+
oid sha256:fcd9618285bb1bf56c72f46f64e228cda95aa27e64ea2a0199d649dbfebd8c10
3+
size 604672
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:0e8b946198fb06daf11bdde1d608b5ec527b84d17f6956a88ce1eb41aa788520
2+
oid sha256:cf018202e613caa46f9f32301f728a6386cfb9b3c036b0f4b300725336f4e5e1
33
size 87040
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:e80c3babdc4090cb716d88ac36e979fbacf8f67fa668530724d7252cb20639ae
3-
size 466944
2+
oid sha256:361b0b0201d2b0afbf8f982cd529faa6cf148aeb7e9d303df7dff7854b61414f
3+
size 467968

lib/NativeCode/DynamicLibraryLoaderHelper/NativeRender/src/eos_helpers.cpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)