-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up cross-platform ModDLL loading
- Loading branch information
Showing
7 changed files
with
61 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,6 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
void plClient::IResizeNativeDisplayDevice(int width, int height, bool windowed) {} | ||
void plClient::IChangeResolution(int width, int height) {} | ||
void plClient::IUpdateProgressIndicator(plOperationProgress* progress) {} | ||
void plClient::InitDLLs() {} | ||
void plClient::ShutdownDLLs() {} | ||
void plClient::ShowClientWindow() {} | ||
void plClient::FlashWindow() {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
|
||
#include "pnDispatch/plDispatch.h" | ||
#include "pnDispatch/plDispatchLogBase.h" | ||
#include "pnFactory/plFactory.h" | ||
#include "pnKeyedObject/plFixedKey.h" | ||
#include "pnKeyedObject/plKey.h" | ||
#include "pnMessage/plAudioSysMsg.h" | ||
|
@@ -154,6 +155,9 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
#include "pfPython/cyMisc.h" | ||
#include "pfPython/cyPythonInterface.h" | ||
|
||
#ifdef HS_BUILD_FOR_UNIX | ||
# include <dlfcn.h> // For ModDLL loading | ||
#endif | ||
|
||
#define MSG_LOADING_BAR | ||
|
||
|
@@ -369,6 +373,58 @@ bool plClient::Shutdown() | |
return false; | ||
} | ||
|
||
void plClient::InitDLLs() { | ||
hsStatusMessage("Init dlls client\n"); | ||
|
||
std::vector<plFileName> dlls = plFileSystem::ListDir("ModDLL", | ||
#if defined(HS_BUILD_FOR_WIN32) | ||
"*.dll" | ||
#elif defined(HS_BUILD_FOR_APPLE) | ||
"*.dylib" | ||
#else | ||
"*.so" | ||
#endif | ||
); | ||
|
||
for (auto iter = dlls.begin(); iter != dlls.end(); ++iter) | ||
{ | ||
#ifdef HS_BUILD_FOR_WIN32 | ||
hsLibraryHndl mod = LoadLibraryW(iter->WideString().data()); | ||
#else | ||
hsLibraryHndl mod = dlopen(iter->AsString().c_str(), RTLD_LAZY | RTLD_LOCAL); | ||
#endif | ||
|
||
if (mod) | ||
{ | ||
#ifdef HS_BUILD_FOR_WIN32 | ||
pInitGlobalsFunc initGlobals = (pInitGlobalsFunc)GetProcAddress(mod, "InitGlobals"); | ||
#else | ||
pInitGlobalsFunc initGlobals = (pInitGlobalsFunc)dlsym(mod, "InitGlobals"); | ||
#endif | ||
|
||
(*initGlobals)(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(), | ||
hsTimer::GetTheTimer(), plNetClientApp::GetInstance()); | ||
fLoadedDLLs.emplace_back(mod); | ||
} | ||
} | ||
} | ||
|
||
void plClient::ShutdownDLLs() | ||
{ | ||
for (hsLibraryHndl mod : fLoadedDLLs) | ||
{ | ||
#ifdef HS_BUILD_FOR_WIN32 | ||
BOOL ret = FreeLibrary(mod); | ||
if (!ret) | ||
hsStatusMessage("Failed to free lib\n"); | ||
#else | ||
dlclose(mod); | ||
#endif | ||
} | ||
|
||
fLoadedDLLs.clear(); | ||
} | ||
|
||
void plClient::InitAuxInits() | ||
{ | ||
// Use another init directory specified in Command line Arg -i | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,12 +51,10 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
#include "plClient.h" | ||
#include "plWinDpi/plWinDpi.h" | ||
|
||
#include "pnFactory/plFactory.h" | ||
#include "pnNetCommon/plNetApp.h" | ||
#include "plProgressMgr/plProgressMgr.h" | ||
|
||
extern ITaskbarList3* gTaskbarList; | ||
static std::vector<HMODULE> fLoadedDLLs; | ||
|
||
void plClient::IResizeNativeDisplayDevice(int width, int height, bool windowed) | ||
{ | ||
|
@@ -146,34 +144,6 @@ void plClient::IUpdateProgressIndicator(plOperationProgress* progress) | |
} | ||
} | ||
|
||
void plClient::InitDLLs() | ||
{ | ||
hsStatusMessage("Init dlls client\n"); | ||
std::vector<plFileName> dlls = plFileSystem::ListDir("ModDLL", "*.dll"); | ||
for (auto iter = dlls.begin(); iter != dlls.end(); ++iter) | ||
{ | ||
HMODULE hMod = LoadLibraryW(iter->WideString().data()); | ||
if (hMod) | ||
{ | ||
pInitGlobalsFunc initGlobals = (pInitGlobalsFunc)GetProcAddress(hMod, "InitGlobals"); | ||
(*initGlobals)(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(), | ||
hsTimer::GetTheTimer(), plNetClientApp::GetInstance()); | ||
fLoadedDLLs.emplace_back(hMod); | ||
} | ||
} | ||
} | ||
|
||
void plClient::ShutdownDLLs() | ||
{ | ||
for (HMODULE dll : fLoadedDLLs) | ||
{ | ||
BOOL ret = FreeLibrary(dll); | ||
if (!ret) | ||
hsStatusMessage("Failed to free lib\n"); | ||
} | ||
fLoadedDLLs.clear(); | ||
} | ||
|
||
// Show the client window | ||
void plClient::ShowClientWindow() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,11 +71,13 @@ You can contact Cyan Worlds, Inc. by email [email protected] | |
typedef HWND hsWindowHndl; | ||
typedef HINSTANCE hsWindowInst; | ||
typedef HINSTANCE HMODULE; | ||
typedef HMODULE hsLibraryHndl; | ||
typedef long HRESULT; | ||
typedef void* HANDLE; | ||
#else | ||
typedef int32_t* hsWindowHndl; | ||
typedef int32_t* hsWindowInst; | ||
typedef void* hsLibraryHndl; | ||
#endif // HS_BUILD_FOR_WIN32 | ||
|
||
//====================================== | ||
|