@@ -35,17 +35,20 @@ bool (*g_SteamAPI_RestartAppIfNecessary)(uint32_t unOwnAppID) = nullptr;
3535void * (*g_SteamInternal_FindOrCreateUserInterface)(int , const char *) = nullptr ;
3636bool (*g_SteamAPI_ISteamApps_BIsAppInstalled)(void *iSteamApps, uint32_t appID) = nullptr ;
3737
38- static void bind_all (color_ostream& out, DFLibrary* handle) {
39- #define bind (name ) \
40- if (!handle) { \
41- g_##name = nullptr ; \
42- } else { \
43- g_##name = (decltype (g_##name))LookupPlugin (handle, #name); \
44- if (!g_##name) { \
45- WARN (dfsteam, out).print (" steam library function not found: " #name " \n " ); \
46- } \
38+ template <typename Ptr>
39+ static void bind_ (color_ostream& out, DFLibrary* handle, const char * name, Ptr& func_ptr) {
40+ if (!handle) {
41+ func_ptr = nullptr ;
42+ } else {
43+ func_ptr = (Ptr)LookupPlugin (handle, name);
44+ if (!func_ptr) {
45+ WARN (dfsteam, out).print (" steam library function not found: {}\n " , name);
4746 }
47+ }
48+ }
4849
50+ static void bind_all (color_ostream& out, DFLibrary* handle) {
51+ #define bind (name ) bind_(out, handle, #name, g_##name)
4952 bind (SteamAPI_Init);
5053 bind (SteamAPI_Shutdown);
5154 bind (SteamAPI_GetHSteamUser);
@@ -56,6 +59,16 @@ static void bind_all(color_ostream& out, DFLibrary* handle) {
5659#undef bind
5760}
5861
62+ static void unbind_all ()
63+ {
64+ g_SteamAPI_Init = nullptr ;
65+ g_SteamAPI_Shutdown = nullptr ;
66+ g_SteamAPI_GetHSteamUser = nullptr ;
67+ g_SteamInternal_FindOrCreateUserInterface = nullptr ;
68+ g_SteamAPI_RestartAppIfNecessary = nullptr ;
69+ g_SteamAPI_ISteamApps_BIsAppInstalled = nullptr ;
70+ }
71+
5972bool DFSteam::init (color_ostream& out) {
6073 char *steam_client_launch = getenv (" SteamClientLaunch" );
6174 if (!steam_client_launch || strncmp (steam_client_launch, " 1" , 2 ) != 0 ) {
@@ -84,7 +97,7 @@ bool DFSteam::init(color_ostream& out) {
8497 return true ;
8598}
8699
87- void DFSteam::cleanup (color_ostream& out ) {
100+ void DFSteam::cleanup () {
88101 if (!g_steam_handle)
89102 return ;
90103
@@ -94,7 +107,7 @@ void DFSteam::cleanup(color_ostream& out) {
94107 ClosePlugin (g_steam_handle);
95108 g_steam_handle = nullptr ;
96109
97- bind_all (out, nullptr );
110+ unbind_all ( );
98111 g_steam_initialized = false ;
99112}
100113
0 commit comments