Skip to content

Commit 867acf3

Browse files
committed
DFSteam no longer needs a console to unload
also replaced most of a macro with a template
1 parent bf67a84 commit 867acf3

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
@@ -1941,9 +1941,7 @@ int Core::Shutdown ( void )
19411941
allModules.clear();
19421942
Textures::cleanup();
19431943
DFSDL::cleanup();
1944-
1945-
// FIXME console has already been shut down at this point, so getConsole is returning a dead object
1946-
DFSteam::cleanup(getConsole());
1944+
DFSteam::cleanup();
19471945

19481946
memset(&(s_mods), 0, sizeof(s_mods));
19491947
d.reset();

‎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
@@ -35,17 +35,20 @@ bool (*g_SteamAPI_RestartAppIfNecessary)(uint32_t unOwnAppID) = nullptr;
3535
void* (*g_SteamInternal_FindOrCreateUserInterface)(int, const char*) = nullptr;
3636
bool (*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+
5972
bool 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

Comments
 (0)