1
0
Fork 0
mirror of https://github.com/Detanup01/gbe_fork.git synced 2025-08-12 18:35:35 +02:00

fixing code for linux.

add auto load if exists
add check if null.
This commit is contained in:
Detanup01 2025-02-06 18:26:14 +01:00 committed by GitHub
parent d7fe629407
commit e02c94271b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 12 deletions

View file

@ -279,7 +279,7 @@ unsigned int file_size_(const std::string &full_path)
#ifdef EMU_EXPERIMENTAL_BUILD #ifdef EMU_EXPERIMENTAL_BUILD
#include "pdk/pdk.h"
static std::vector<void*> loaded_libs{}; static std::vector<void*> loaded_libs{};
static void load_dlls() 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::string path(Local_Storage::get_game_settings_path() + "load_dlls" + PATH_SEPARATOR);
std::vector<std::string> paths(Local_Storage::get_filenames_path(path)); 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); std::string full_path(path + p);
if (!common_helpers::ends_with_i(full_path, LIB_EXTENSION)) continue; 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); dlopen(full_path.c_str(), RTLD_NOW | RTLD_LOCAL);
#endif #endif
if (lib_handle != nullptr) { if (lib_handle != nullptr)
{
loaded_libs.push_back(reinterpret_cast<void *>(lib_handle)); loaded_libs.push_back(reinterpret_cast<void *>(lib_handle));
PDK::LoadPlugin(lib_handle);
PRINT_DEBUG(" LOADED"); PRINT_DEBUG(" LOADED");
} else { }
else
{
#ifdef __WINDOWS__ #ifdef __WINDOWS__
PRINT_DEBUG(" FAILED, error code 0x%X", GetLastError()); PRINT_DEBUG(" FAILED, error code 0x%X", GetLastError());
#else #else
@ -322,7 +327,9 @@ static void load_dlls()
static void unload_dlls() static void unload_dlls()
{ {
for (auto lib_handle : loaded_libs) { for (auto lib_handle : loaded_libs)
{
PDK::UnloLoadPlugin(lib_handle);
#ifdef __WINDOWS__ #ifdef __WINDOWS__
FreeLibrary(reinterpret_cast<HMODULE>(lib_handle)); FreeLibrary(reinterpret_cast<HMODULE>(lib_handle));
#else #else
@ -333,7 +340,8 @@ static void unload_dlls()
#ifdef __WINDOWS__ #ifdef __WINDOWS__
struct ips_test { struct ips_test
{
uint32_t ip_from; uint32_t ip_from;
uint32_t ip_to; uint32_t ip_to;
}; };

View file

@ -3,16 +3,34 @@
typedef void (*__cdecl PluginCall)(); 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(); load();
PRINT_DEBUG("Loaded plugin file"); 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(); load();
PRINT_DEBUG("Loaded plugin file"); PRINT_DEBUG("Loaded plugin file");
} }

View file

@ -11,8 +11,8 @@ class PDK
static inline std::map<void* /* interfaceMaker */, const char* /* interfaceVersion */> interfaceMap; static inline std::map<void* /* interfaceMaker */, const char* /* interfaceVersion */> interfaceMap;
static void LoadPlugin(HMODULE handle); static void LoadPlugin(void* handle);
static void UnloLoadPlugin(HMODULE handle); static void UnloLoadPlugin(void* handle);
public: public:
/// <summary> /// <summary>