diff --git a/core/systems/LibrarySys.cpp b/core/systems/LibrarySys.cpp index 76e2f2df..af956f23 100644 --- a/core/systems/LibrarySys.cpp +++ b/core/systems/LibrarySys.cpp @@ -322,3 +322,23 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...) return mylen; } + +const char *LibrarySystem::GetFileExtension(const char *filename) +{ + size_t len = strlen(filename); + + for (size_t i = len - 1; i >= 0; i--) + { + if (filename[i] == PLATFORM_SEP_CHAR || filename[i] == PLATFORM_SEP_ALTCHAR) + { + return NULL; + } + + if (filename[i] == '.' && i != len - 1) + { + return &filename[++i]; + } + } + + return NULL; +} diff --git a/core/systems/LibrarySys.h b/core/systems/LibrarySys.h index 7b15e062..ff6223fa 100644 --- a/core/systems/LibrarySys.h +++ b/core/systems/LibrarySys.h @@ -74,6 +74,7 @@ public: bool IsPathDirectory(const char *path); void GetPlatformError(char *error, size_t maxlength); size_t PathFormat(char *buffer, size_t len, const char *fmt, ...); + const char *GetFileExtension(const char *filename); }; extern LibrarySystem g_LibSys; diff --git a/core/systems/PluginSys.cpp b/core/systems/PluginSys.cpp index 9fc1615a..c501f7fb 100644 --- a/core/systems/PluginSys.cpp +++ b/core/systems/PluginSys.cpp @@ -1661,19 +1661,24 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc char error[128]; bool wasloaded; const char *filename = g_RootMenu.GetArgument(3); - IPlugin *pl = LoadPlugin(filename, false, PluginType_MapUpdated, error, sizeof(error), &wasloaded); + + char pluginfile[256]; + const char *ext = g_LibSys.GetFileExtension(filename) ? "" : ".smx"; + UTIL_Format(pluginfile, sizeof(pluginfile), "%s%s", filename, ext); + + IPlugin *pl = LoadPlugin(pluginfile, false, PluginType_MapUpdated, error, sizeof(error), &wasloaded); if (wasloaded) { - g_RootMenu.ConsolePrint("[SM] Plugin %s is already loaded.", filename); + g_RootMenu.ConsolePrint("[SM] Plugin %s is already loaded.", pluginfile); return; } if (pl) { - g_RootMenu.ConsolePrint("[SM] Loaded plugin %s successfully.", filename); + g_RootMenu.ConsolePrint("[SM] Loaded plugin %s successfully.", pluginfile); } else { - g_RootMenu.ConsolePrint("[SM] Plugin %s failed to load: %s.", filename, error); + g_RootMenu.ConsolePrint("[SM] Plugin %s failed to load: %s.", pluginfile, error); } return; diff --git a/public/ILibrarySys.h b/public/ILibrarySys.h index 2af2d162..d8e2c407 100644 --- a/public/ILibrarySys.h +++ b/public/ILibrarySys.h @@ -29,7 +29,7 @@ namespace SourceMod { #define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys" - #define SMINTERFACE_LIBRARYSYS_VERSION 1 + #define SMINTERFACE_LIBRARYSYS_VERSION 2 class ILibrary { @@ -173,6 +173,14 @@ namespace SourceMod * @param ... Format string arguments. */ virtual size_t PathFormat(char *buffer, size_t maxlength, const char *pathfmt, ...) =0; + + /** + * @brief Returns a pointer to the extension in a filename. + * + * @param filename Name of file from which the extension should be extracted. + * @return Pointer to file extension. + */ + virtual const char *GetFileExtension(const char *filename) =0; }; }