@@ -54,17 +54,20 @@ bool (*g_SteamAPI_RestartAppIfNecessary)(uint32_t unOwnAppID) = nullptr;
5454void * (*g_SteamInternal_FindOrCreateUserInterface)(int , const char *) = nullptr ;
5555bool (*g_SteamAPI_ISteamApps_BIsAppInstalled)(void *iSteamApps, uint32_t appID) = nullptr ;
5656
57- static void bind_all (color_ostream& out, DFLibrary* handle) {
58- #define bind (name ) \
59- if (!handle) { \
60- g_##name = nullptr ; \
61- } else { \
62- g_##name = (decltype (g_##name))LookupPlugin (handle, #name); \
63- if (!g_##name) { \
64- WARN (dfsteam, out).print (" steam library function not found: " #name " \n " ); \
65- } \
57+ template <typename Ptr>
58+ static void bind_ (color_ostream& out, DFLibrary* handle, const char * name, Ptr& func_ptr) {
59+ if (!handle) {
60+ func_ptr = nullptr ;
61+ } else {
62+ func_ptr = (Ptr)LookupPlugin (handle, name);
63+ if (!func_ptr) {
64+ WARN (dfsteam, out).print (" steam library function not found: {}\n " , name);
6665 }
66+ }
67+ }
6768
69+ static void bind_all (color_ostream& out, DFLibrary* handle) {
70+ #define bind (name ) bind_(out, handle, #name, g_##name)
6871 bind (SteamAPI_Init);
6972 bind (SteamAPI_Shutdown);
7073 bind (SteamAPI_GetHSteamUser);
@@ -75,6 +78,16 @@ static void bind_all(color_ostream& out, DFLibrary* handle) {
7578#undef bind
7679}
7780
81+ static void unbind_all ()
82+ {
83+ g_SteamAPI_Init = nullptr ;
84+ g_SteamAPI_Shutdown = nullptr ;
85+ g_SteamAPI_GetHSteamUser = nullptr ;
86+ g_SteamInternal_FindOrCreateUserInterface = nullptr ;
87+ g_SteamAPI_RestartAppIfNecessary = nullptr ;
88+ g_SteamAPI_ISteamApps_BIsAppInstalled = nullptr ;
89+ }
90+
7891bool DFSteam::init (color_ostream& out) {
7992 char *steam_client_launch = getenv (" SteamClientLaunch" );
8093 if (!steam_client_launch || strncmp (steam_client_launch, " 1" , 2 ) != 0 ) {
@@ -103,7 +116,7 @@ bool DFSteam::init(color_ostream& out) {
103116 return true ;
104117}
105118
106- void DFSteam::cleanup (color_ostream& out ) {
119+ void DFSteam::cleanup () {
107120 if (!g_steam_handle)
108121 return ;
109122
@@ -113,7 +126,7 @@ void DFSteam::cleanup(color_ostream& out) {
113126 ClosePlugin (g_steam_handle);
114127 g_steam_handle = nullptr ;
115128
116- bind_all (out, nullptr );
129+ unbind_all ( );
117130 g_steam_initialized = false ;
118131}
119132
0 commit comments