mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2025-03-28 14:56:24 +01:00
fixing code for linux.
add auto load if exists add check if null.
This commit is contained in:
parent
d7fe629407
commit
e02c94271b
3 changed files with 38 additions and 12 deletions
20
dll/base.cpp
20
dll/base.cpp
|
@ -279,7 +279,7 @@ unsigned int file_size_(const std::string &full_path)
|
|||
|
||||
|
||||
#ifdef EMU_EXPERIMENTAL_BUILD
|
||||
|
||||
#include "pdk/pdk.h"
|
||||
static std::vector<void*> loaded_libs{};
|
||||
|
||||
static void load_dlls()
|
||||
|
@ -295,7 +295,8 @@ static void load_dlls()
|
|||
std::string path(Local_Storage::get_game_settings_path() + "load_dlls" + PATH_SEPARATOR);
|
||||
|
||||
std::vector<std::string> paths(Local_Storage::get_filenames_path(path));
|
||||
for (auto & p: paths) {
|
||||
for (auto & p: paths)
|
||||
{
|
||||
std::string full_path(path + p);
|
||||
if (!common_helpers::ends_with_i(full_path, LIB_EXTENSION)) continue;
|
||||
|
||||
|
@ -307,10 +308,14 @@ static void load_dlls()
|
|||
dlopen(full_path.c_str(), RTLD_NOW | RTLD_LOCAL);
|
||||
#endif
|
||||
|
||||
if (lib_handle != nullptr) {
|
||||
if (lib_handle != nullptr)
|
||||
{
|
||||
loaded_libs.push_back(reinterpret_cast<void *>(lib_handle));
|
||||
PDK::LoadPlugin(lib_handle);
|
||||
PRINT_DEBUG(" LOADED");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
PRINT_DEBUG(" FAILED, error code 0x%X", GetLastError());
|
||||
#else
|
||||
|
@ -322,7 +327,9 @@ static void load_dlls()
|
|||
|
||||
static void unload_dlls()
|
||||
{
|
||||
for (auto lib_handle : loaded_libs) {
|
||||
for (auto lib_handle : loaded_libs)
|
||||
{
|
||||
PDK::UnloLoadPlugin(lib_handle);
|
||||
#ifdef __WINDOWS__
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(lib_handle));
|
||||
#else
|
||||
|
@ -333,7 +340,8 @@ static void unload_dlls()
|
|||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
struct ips_test {
|
||||
struct ips_test
|
||||
{
|
||||
uint32_t ip_from;
|
||||
uint32_t ip_to;
|
||||
};
|
||||
|
|
26
pdk/pdk.cpp
26
pdk/pdk.cpp
|
@ -3,16 +3,34 @@
|
|||
|
||||
typedef void (*__cdecl PluginCall)();
|
||||
|
||||
void PDK::LoadPlugin(HMODULE handle)
|
||||
void PDK::LoadPlugin(void* handle)
|
||||
{
|
||||
PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_Load");
|
||||
#ifdef __WINDOWS__
|
||||
HMODULE mod = reinterpret_cast<HMODULE>(handle);
|
||||
PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_Load");
|
||||
#else
|
||||
PluginCall load = (PluginCall)dlsym(mod, "GBE_Load");
|
||||
#endif
|
||||
if (load == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
load();
|
||||
PRINT_DEBUG("Loaded plugin file");
|
||||
}
|
||||
|
||||
void PDK::UnloLoadPlugin(HMODULE handle)
|
||||
void PDK::UnloLoadPlugin(void* handle)
|
||||
{
|
||||
PluginCall load = (PluginCall)GetProcAddress(handle, "GBE_UnLoad");
|
||||
#ifdef __WINDOWS__
|
||||
HMODULE mod = reinterpret_cast<HMODULE>(handle);
|
||||
PluginCall load = (PluginCall)GetProcAddress(mod, "GBE_UnLoad");
|
||||
#else
|
||||
PluginCall load = (PluginCall)dlsym(mod, "GBE_UnLoad");
|
||||
#endif
|
||||
if (load == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
load();
|
||||
PRINT_DEBUG("Loaded plugin file");
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ class PDK
|
|||
static inline std::map<void* /* interfaceMaker */, const char* /* interfaceVersion */> interfaceMap;
|
||||
|
||||
|
||||
static void LoadPlugin(HMODULE handle);
|
||||
static void UnloLoadPlugin(HMODULE handle);
|
||||
static void LoadPlugin(void* handle);
|
||||
static void UnloLoadPlugin(void* handle);
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Reference in a new issue