diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2f5b163 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/amtl"] + path = third_party/amtl + url = https://github.com/alliedmodders/amtl diff --git a/AMBuildScript b/AMBuildScript index f8fe5c6..d75b1b2 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -334,6 +334,7 @@ class MMSConfig(object): cxx.defines += [ 'MMS_USE_VERSIONLIB' ] cxx.includes += [ os.path.join(builder.sourcePath, 'public'), + os.path.join(builder.sourcePath, 'third_party', 'amtl'), ] if self.use_auto_versioning(): cxx.defines += ['MMS_GENERATED_BUILD'] diff --git a/core/metamod.cpp b/core/metamod.cpp index d3de091..94466cf 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -40,13 +40,6 @@ #endif #define X64_SUFFIX ".x64" -#if defined(WIN32) || defined(_WIN32) -#define BINARY_EXT ".dll" -#elif defined(__linux__) -#define BINARY_EXT ".so" -#elif defined(__APPLE__) -#define BINARY_EXT ".dylib" -#endif using namespace SourceMM; using namespace SourceHook; diff --git a/core/metamod_plugins.cpp b/core/metamod_plugins.cpp index f33ff4a..01dd510 100644 --- a/core/metamod_plugins.cpp +++ b/core/metamod_plugins.cpp @@ -24,6 +24,10 @@ */ #include + +#include + +#include #include "metamod_oslink.h" #include "metamod.h" #include "metamod_plugins.h" @@ -414,7 +418,7 @@ struct Unloader : public SourceHook::Impl::UnloadListener CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source, char *error, size_t maxlen) { - FILE *fp; + std::unique_ptr fp(nullptr, ::fclose); CPlugin *pl; pl = new CPlugin(); @@ -426,21 +430,29 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source m_Plugins.push_back(pl); m_LastId++; - //Check if the file even exists - fp = fopen(file, "r"); - if (!fp) + if (ke::EndsWith(file, BINARY_EXT)) + { + //Check if the file even exists + fp.reset(fopen(file, "r")); + if (!fp) + { + if (error) + { + UTIL_Format(error, maxlen, "File not found: %s", file); + } + pl->m_Status = Pl_NotFound; + } + } + else { if (error) - { - UTIL_Format(error, maxlen, "File not found: %s", file); - } + UTIL_Format(error, maxlen, "File type not supported"); pl->m_Status = Pl_NotFound; } if (fp) { - fclose(fp); - fp = NULL; + fp.reset(); //Load the file pl->m_Lib = dlmount(file); diff --git a/core/metamod_util.h b/core/metamod_util.h index cf946e0..234b804 100644 --- a/core/metamod_util.h +++ b/core/metamod_util.h @@ -30,6 +30,14 @@ #include +#if defined(WIN32) || defined(_WIN32) +#define BINARY_EXT ".dll" +#elif defined(__linux__) +#define BINARY_EXT ".so" +#elif defined(__APPLE__) +#define BINARY_EXT ".dylib" +#endif + /** * @brief Utility functions * @file util.h diff --git a/third_party/amtl b/third_party/amtl new file mode 160000 index 0000000..ad9d5c3 --- /dev/null +++ b/third_party/amtl @@ -0,0 +1 @@ +Subproject commit ad9d5c33534dcfd902e2aeb0744df1a227b1c6d3