Skip to content

Commit c2cbf6e

Browse files
Print symbol if error has occurred
1 parent 35a7d75 commit c2cbf6e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ endif()
1111

1212
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1313

14-
set(MODLOADER_VERSION "Preview 1")
14+
set(MODLOADER_VERSION "Preview 2")
1515

1616
add_subdirectory(dep/funchook)
1717

include/modloader/hook.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ extern "C" {
99

1010
typedef void modloader_hook_t;
1111

12+
void* modloader_dlsym_print_error(const char *sym);
13+
1214
modloader_hook_t* modloader_hook(void *sym, void *hook, void **orig);
1315

1416
void modloader_destroy_hook(modloader_hook_t*);
@@ -48,7 +50,7 @@ class AutoHook {
4850
}
4951

5052

51-
AutoHook(const char *sym, void *hook, void **orig) : AutoHook(dlsym(RTLD_DEFAULT, sym), hook, orig) {
53+
AutoHook(const char *sym, void *hook, void **orig) : AutoHook(modloader_dlsym_print_error(sym), hook, orig) {
5254
}
5355

5456
// workaround for a warning

src/hook.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ using namespace modloader;
99

1010
extern "C" {
1111

12+
void *modloader_dlsym_print_error(const char *sym) {
13+
void *ptr = dlsym(RTLD_DEFAULT, sym);
14+
if (!ptr)
15+
Log::error("Hook", "Unknown symbol %s", sym);
16+
return ptr;
17+
}
18+
1219
modloader_hook_t *modloader_hook(void *sym, void *hook, void **orig) {
1320
funchook_t *h = funchook_create();
1421
if (!h)

0 commit comments

Comments
 (0)