1.1 --- a/core/metamod.cpp Sun May 16 23:21:08 2010 -0400
1.2 +++ b/core/metamod.cpp Wed May 19 01:28:55 2010 -0500
1.3 @@ -2,7 +2,7 @@
1.4 * vim: set ts=4 sw=4 tw=99 noet :
1.5 * ======================================================
1.6 * Metamod:Source
1.7 - * Copyright (C) 2004-2009 AlliedModders LLC and authors.
1.8 + * Copyright (C) 2004-2010 AlliedModders LLC and authors.
1.9 * All rights reserved.
1.10 * ======================================================
1.11 *
1.12 @@ -33,6 +33,9 @@
1.13 #include "metamod_util.h"
1.14 #include "metamod_console.h"
1.15 #include "provider/provider_ep2.h"
1.16 +#if defined __linux__
1.17 +#include <sys/stat.h>
1.18 +#endif
1.19
1.20 using namespace SourceMM;
1.21 using namespace SourceHook;
1.22 @@ -288,56 +291,20 @@
1.23 {
1.24 continue;
1.25 }
1.26 - /* First find if it's an absolute path or not... */
1.27 - if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
1.28 +
1.29 + g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
1.30 +
1.31 + id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1.32 + if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1.33 {
1.34 - /* If we're in an absolute path, ignore our normal heuristics */
1.35 - id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
1.36 - if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1.37 - {
1.38 - mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
1.39 - }
1.40 - else
1.41 - {
1.42 - if (already)
1.43 - skipped++;
1.44 - else
1.45 - total++;
1.46 - }
1.47 + mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
1.48 }
1.49 else
1.50 {
1.51 - /* Attempt to find a file extension */
1.52 - ptr = UTIL_GetExtension(file);
1.53 - /* Add an extension if there's none there */
1.54 - if (!ptr)
1.55 - {
1.56 -#if defined WIN32 || defined _WIN32
1.57 - ext = ".dll";
1.58 -#elif defined __APPLE__
1.59 - ext = ".dylib";
1.60 -#else
1.61 - ext = "_i486.so";
1.62 -#endif
1.63 - }
1.64 + if (already)
1.65 + skipped++;
1.66 else
1.67 - {
1.68 - ext = "";
1.69 - }
1.70 - /* Format the new path */
1.71 - g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
1.72 - id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1.73 - if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1.74 - {
1.75 - mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
1.76 - }
1.77 - else
1.78 - {
1.79 - if (already)
1.80 - skipped++;
1.81 - else
1.82 - total++;
1.83 - }
1.84 + total++;
1.85 }
1.86 }
1.87 fclose(fp);
1.88 @@ -1099,6 +1066,50 @@
1.89 metamod_path.assign(path);
1.90 }
1.91
1.92 +size_t MetamodSource::GetFullPluginPath(const char *plugin, char *buffer, size_t len)
1.93 +{
1.94 + const char *pext, *ext;
1.95 + size_t num;
1.96 +
1.97 + /* First find if it's an absolute path or not... */
1.98 + if (plugin[0] == '/' || strncmp(&(plugin[1]), ":\\", 2) == 0)
1.99 + {
1.100 + return UTIL_Format(buffer, len, plugin);
1.101 + }
1.102 +
1.103 + /* Attempt to find a file extension */
1.104 + pext = UTIL_GetExtension(plugin);
1.105 + /* Add an extension if there's none there */
1.106 + if (!pext)
1.107 + {
1.108 +#if defined WIN32 || defined _WIN32
1.109 + ext = ".dll";
1.110 +#elif defined __APPLE__
1.111 + ext = ".dylib";
1.112 +#else
1.113 + ext = "_i486.so";
1.114 +#endif
1.115 + }
1.116 + else
1.117 + {
1.118 + ext = "";
1.119 + }
1.120 +
1.121 + /* Format the new path */
1.122 + num = PathFormat(buffer, len, "%s/%s%s", mod_path.c_str(), plugin, ext);
1.123 +
1.124 +#if defined __linux__
1.125 + /* If path was passed without extension and it doesn't exist with "_i486.so" try ".so" */
1.126 + struct stat s;
1.127 + if (!pext && stat(buffer, &s) != 0)
1.128 + {
1.129 + num = PathFormat(buffer, len, "%s/%s.so", mod_path.c_str(), plugin);
1.130 + }
1.131 +#endif
1.132 +
1.133 + return num;
1.134 +}
1.135 +
1.136 static bool
1.137 ProcessVDF(const char *path, bool &skipped)
1.138 {
1.139 @@ -1115,31 +1126,7 @@
1.140 if (alias[0] != '\0')
1.141 g_PluginMngr.SetAlias(alias, file);
1.142
1.143 - /* Attempt to find a file extension */
1.144 - if (UTIL_GetExtension(file) == NULL)
1.145 - {
1.146 - g_pMetamod->PathFormat(full_path,
1.147 - sizeof(full_path),
1.148 - "%s/%s%s",
1.149 - g_pMetamod->GetBaseDir(),
1.150 - file,
1.151 -#if defined WIN32 || defined _WIN32
1.152 - ".dll"
1.153 -#elif defined __APPLE__
1.154 - ".dylib"
1.155 -#else
1.156 - "_i486.so"
1.157 -#endif
1.158 - );
1.159 - }
1.160 - else
1.161 - {
1.162 - g_pMetamod->PathFormat(full_path,
1.163 - sizeof(full_path),
1.164 - "%s/%s",
1.165 - g_pMetamod->GetBaseDir(),
1.166 - file);
1.167 - }
1.168 + g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
1.169
1.170 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1.171 skipped = already;