Skip to content

ModDLL & Linux hsGD3DeviceSelector fixes #1596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ @interface AppDelegate : NSWindowController <NSApplicationDelegate,
}
void plClient::IChangeResolution(int width, int height) {}
void plClient::IUpdateProgressIndicator(plOperationProgress* progress) {}
void plClient::InitDLLs() {}
void plClient::ShutdownDLLs() {}
void plClient::ShowClientWindow() {}
void plClient::FlashWindow()
{
Expand Down
2 changes: 0 additions & 2 deletions Sources/Plasma/Apps/plClient/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down
58 changes: 58 additions & 0 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -158,6 +159,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

Expand Down Expand Up @@ -373,6 +377,60 @@ 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 = reinterpret_cast<pInitGlobalsFunc>(GetProcAddress(mod, "InitGlobals"));
#else
pInitGlobalsFunc initGlobals = reinterpret_cast<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(ST::format("Failed to free lib: {}", hsCOMError(hsLastWin32Error, GetLastError())).c_str());
#else
int ret = dlclose(mod);
if (ret)
hsStatusMessage(ST::format("Failed to free lib: {}", dlerror()).c_str());
#endif
}

fLoadedDLLs.clear();
}

void plClient::InitAuxInits()
{
// Use another init directory specified in Command line Arg -i
Expand Down
4 changes: 3 additions & 1 deletion Sources/Plasma/Apps/plClient/plClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ class plClient : public hsKeyedObject

int fNumPostLoadMsgs;
float fPostLoadMsgInc;


std::vector<hsLibraryHndl> fLoadedDLLs;

void ICompleteInit ();
void IOnAsyncInitComplete ();
void IHandlePatcherMsg (plResPatcherMsg * msg);
Expand Down
30 changes: 0 additions & 30 deletions Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
{
Expand Down
3 changes: 3 additions & 0 deletions Sources/Plasma/CoreLib/HeadSpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ 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;
#elif HS_BUILD_FOR_MACOS
typedef void* hsWindowHndl;
typedef void* hsWindowInst;
typedef void* hsLibraryHndl;
#else
typedef int32_t* hsWindowHndl;
typedef int32_t* hsWindowInst;
typedef void* hsLibraryHndl;
#endif // HS_BUILD_FOR_WIN32

//======================================
Expand Down
7 changes: 5 additions & 2 deletions Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ hsG3DDeviceModeRecord& hsG3DDeviceModeRecord::operator=(const hsG3DDeviceModeRec
///////////////////////////////////////////////////
///////////////////////////////////////////////////

std::list<hsG3DDeviceSelector::DeviceEnumerator> hsG3DDeviceSelector::sEnumerators;
std::list<hsG3DDeviceSelector::DeviceEnumerator>& hsG3DDeviceSelector::Enumerators() {
static std::list<hsG3DDeviceSelector::DeviceEnumerator> sEnumerators;
return sEnumerators;
}

hsG3DDeviceSelector::~hsG3DDeviceSelector()
{
Expand Down Expand Up @@ -354,7 +357,7 @@ void hsG3DDeviceSelector::Enumerate(hsWindowHndl winRef)
ITryDirect3DTnL(winRef);
#endif

for (const auto& enumerator : sEnumerators) {
for (const auto& enumerator : Enumerators()) {
enumerator(fRecords);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class hsG3DDeviceSelector : public hsRefCnt
typedef std::function<void(std::vector<hsG3DDeviceRecord>&)> DeviceEnumerator;

protected:
static std::list<DeviceEnumerator> sEnumerators;
static std::list<DeviceEnumerator>& Enumerators();

std::vector<hsG3DDeviceRecord> fRecords;

Expand All @@ -344,7 +344,7 @@ class hsG3DDeviceSelector : public hsRefCnt
void ISetFudgeFactors( uint8_t chipsetID, hsG3DDeviceRecord &record );

public:
static void AddDeviceEnumerator(const DeviceEnumerator& de) { sEnumerators.emplace_back(de); }
static void AddDeviceEnumerator(const DeviceEnumerator& de) { Enumerators().emplace_back(de); }

hsG3DDeviceSelector() { }
virtual ~hsG3DDeviceSelector();
Expand Down
Loading