Skip to content

Commit 56e0239

Browse files
committed
DFSteam no longer needs a console to unload
also replaced most of a macro with a template
1 parent 593c4ec commit 56e0239

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

library/Core.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,9 +1946,7 @@ int Core::Shutdown ( void )
19461946
// invalidate all modules
19471947
Textures::cleanup();
19481948
DFSDL::cleanup();
1949-
1950-
// FIXME console has already been shut down at this point, so getConsole is returning a dead object
1951-
DFSteam::cleanup(getConsole());
1949+
DFSteam::cleanup();
19521950

19531951
d.reset();
19541952

library/include/modules/DFSteam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool init(DFHack::color_ostream& out);
2424
/**
2525
* Call this when DFHack is being unloaded.
2626
*/
27-
void cleanup(DFHack::color_ostream& out);
27+
void cleanup();
2828

2929
DFHACK_EXPORT void launchSteamDFHackIfNecessary(DFHack::color_ostream& out);
3030

library/modules/DFSteam.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ bool (*g_SteamAPI_RestartAppIfNecessary)(uint32_t unOwnAppID) = nullptr;
5454
void* (*g_SteamInternal_FindOrCreateUserInterface)(int, const char*) = nullptr;
5555
bool (*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+
7891
bool 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

Comments
 (0)