Skip to content

Commit e02c942

Browse files
authored
fixing code for linux.
add auto load if exists add check if null.
1 parent d7fe629 commit e02c942

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

dll/base.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ unsigned int file_size_(const std::string &full_path)
279279

280280

281281
#ifdef EMU_EXPERIMENTAL_BUILD
282-
282+
#include "pdk/pdk.h"
283283
static std::vector<void*> loaded_libs{};
284284

285285
static void load_dlls()
@@ -295,7 +295,8 @@ static void load_dlls()
295295
std::string path(Local_Storage::get_game_settings_path() + "load_dlls" + PATH_SEPARATOR);
296296

297297
std::vector<std::string> paths(Local_Storage::get_filenames_path(path));
298-
for (auto & p: paths) {
298+
for (auto & p: paths)
299+
{
299300
std::string full_path(path + p);
300301
if (!common_helpers::ends_with_i(full_path, LIB_EXTENSION)) continue;
301302

@@ -307,10 +308,14 @@ static void load_dlls()
307308
dlopen(full_path.c_str(), RTLD_NOW | RTLD_LOCAL);
308309
#endif
309310

310-
if (lib_handle != nullptr) {
311+
if (lib_handle != nullptr)
312+
{
311313
loaded_libs.push_back(reinterpret_cast<void *>(lib_handle));
314+
PDK::LoadPlugin(lib_handle);
312315
PRINT_DEBUG(" LOADED");
313-
} else {
316+
}
317+
else
318+
{
314319
#ifdef __WINDOWS__
315320
PRINT_DEBUG(" FAILED, error code 0x%X", GetLastError());
316321
#else
@@ -322,7 +327,9 @@ static void load_dlls()
322327

323328
static void unload_dlls()
324329
{
325-
for (auto lib_handle : loaded_libs) {
330+
for (auto lib_handle : loaded_libs)
331+
{
332+
PDK::UnloLoadPlugin(lib_handle);
326333
#ifdef __WINDOWS__
327334
FreeLibrary(reinterpret_cast<HMODULE>(lib_handle));
328335
#else
@@ -333,7 +340,8 @@ static void unload_dlls()
333340

334341
#ifdef __WINDOWS__
335342

336-
struct ips_test {
343+
struct ips_test
344+
{
337345
uint32_t ip_from;
338346
uint32_t ip_to;
339347
};

pdk/pdk.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,34 @@
33

44
typedef void (*__cdecl PluginCall)();
55

6-
void PDK::LoadPlugin(HMODULE handle)
6+
void PDK::LoadPlugin(void* handle)
77
{
8-
PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_Load");
8+
#ifdef __WINDOWS__
9+
HMODULE mod = reinterpret_cast<HMODULE>(handle);
10+
PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_Load");
11+
#else
12+
PluginCall load = (PluginCall)dlsym(mod, "GBE_Load");
13+
#endif
14+
if (load == NULL)
15+
{
16+
return;
17+
}
918
load();
1019
PRINT_DEBUG("Loaded plugin file");
1120
}
1221

13-
void PDK::UnloLoadPlugin(HMODULE handle)
22+
void PDK::UnloLoadPlugin(void* handle)
1423
{
15-
PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_UnLoad");
24+
#ifdef __WINDOWS__
25+
HMODULE mod = reinterpret_cast<HMODULE>(handle);
26+
PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_UnLoad");
27+
#else
28+
PluginCall load = (PluginCall)dlsym(mod, "GBE_UnLoad");
29+
#endif
30+
if (load == NULL)
31+
{
32+
return;
33+
}
1634
load();
1735
PRINT_DEBUG("Loaded plugin file");
1836
}

pdk/pdk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class PDK
1111
static inline std::map<void* /* interfaceMaker */, const char* /* interfaceVersion */> interfaceMap;
1212

1313

14-
static void LoadPlugin(HMODULE handle);
15-
static void UnloLoadPlugin(HMODULE handle);
14+
static void LoadPlugin(void* handle);
15+
static void UnloLoadPlugin(void* handle);
1616
public:
1717

1818
/// <summary>

0 commit comments

Comments
 (0)