From b3156e5ecac2fd5150fdfb0c170337c408817f82 Mon Sep 17 00:00:00 2001 From: Miran Date: Tue, 12 Mar 2024 01:47:56 +0100 Subject: [PATCH 1/2] Let LoadLibrary API resolve library paths itself. --- cleo_plugins/MemoryOperations/MemoryOperations.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cleo_plugins/MemoryOperations/MemoryOperations.cpp b/cleo_plugins/MemoryOperations/MemoryOperations.cpp index 8220dcf7..2ac5c329 100644 --- a/cleo_plugins/MemoryOperations/MemoryOperations.cpp +++ b/cleo_plugins/MemoryOperations/MemoryOperations.cpp @@ -2,6 +2,7 @@ #include "CLEO_Utils.h" #include "plugin.h" #include "CTheScripts.h" +#include #include using namespace CLEO; @@ -361,7 +362,15 @@ class MemoryOperations //0AA2=2, load_dynamic_library %1s% store_to %2d% // IF and SET static OpcodeResult __stdcall opcode_0AA2(CLEO::CRunningScript* thread) { - OPCODE_READ_PARAM_FILEPATH(path); + OPCODE_READ_PARAM_STRING(srcPath); + char path[MAX_PATH]; + strncpy(path, srcPath, sizeof(path)); + + // if just filename let LoadLibrary resolve it itself + if (std::filesystem::path(path).has_parent_path()) + { + CLEO_ResolvePath(thread, path, sizeof(path)); + } auto ptr = LoadLibrary(path); if (ptr != nullptr) From 1f5e45082f5f6244a38c106f23b1d7f4870c02f0 Mon Sep 17 00:00:00 2001 From: Miran Date: Tue, 12 Mar 2024 01:53:37 +0100 Subject: [PATCH 2/2] fixup! Let LoadLibrary API resolve library paths itself. --- cleo_plugins/MemoryOperations/MemoryOperations.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cleo_plugins/MemoryOperations/MemoryOperations.cpp b/cleo_plugins/MemoryOperations/MemoryOperations.cpp index 2ac5c329..648cd134 100644 --- a/cleo_plugins/MemoryOperations/MemoryOperations.cpp +++ b/cleo_plugins/MemoryOperations/MemoryOperations.cpp @@ -362,14 +362,16 @@ class MemoryOperations //0AA2=2, load_dynamic_library %1s% store_to %2d% // IF and SET static OpcodeResult __stdcall opcode_0AA2(CLEO::CRunningScript* thread) { - OPCODE_READ_PARAM_STRING(srcPath); - char path[MAX_PATH]; - strncpy(path, srcPath, sizeof(path)); - - // if just filename let LoadLibrary resolve it itself + OPCODE_READ_PARAM_STRING(path); + + // get absolute path + // in case of just filename let LoadLibrary resolve it itself + char buff[MAX_PATH]; if (std::filesystem::path(path).has_parent_path()) { - CLEO_ResolvePath(thread, path, sizeof(path)); + strncpy(buff, path, sizeof(buff)); + CLEO_ResolvePath(thread, buff, sizeof(buff)); + path = buff; } auto ptr = LoadLibrary(path);