diff --git a/metamod/src/game_support.cpp b/metamod/src/game_support.cpp index 3708b43..1bc161a 100644 --- a/metamod/src/game_support.cpp +++ b/metamod/src/game_support.cpp @@ -106,9 +106,22 @@ const game_modinfo_t g_known_games[] = { // Find a modinfo corresponding to the given game name. static const game_modinfo_t *lookup_game(const char *name) { + char temp[MAX_PATH]; + for (auto& known : g_known_games) { - if (known.name && !Q_stricmp(known.name, name)) - return &known; + if (known.name && !Q_stricmp(known.name, name)) { +#ifdef _WIN32 + const char* knowndll = known.win_dll; +#else + const char* knowndll = known.linux_so; +#endif + if (!knowndll) + continue; + + Q_snprintf(temp, sizeof temp, "dlls/%s", knowndll); + if (is_file_exists_in_gamedir(temp)) + return &known; + } } // no match found @@ -213,10 +226,6 @@ bool setup_gamedll(gamedll_t *gamedll) #endif } - // Neither override nor known-list found a gamedll. - if (!known && !g_config->m_gamedll) - return false; - // Use override-dll if specified. if (g_config->m_gamedll) { Q_strlcpy(gamedll->pathname, g_config->m_gamedll); diff --git a/metamod/src/utils.cpp b/metamod/src/utils.cpp index 88ece21..af421d4 100644 --- a/metamod/src/utils.cpp +++ b/metamod/src/utils.cpp @@ -114,6 +114,29 @@ char* realpath(const char* file_name, char* resolved_name) } #endif // _WIN32 +bool is_file_exists(const char* file) +{ + struct stat64 st; + int ret = stat64(file, &st); + if (ret != 0) { + META_DEBUG(5, "Unable to stat '%s': %s", file, strerror(errno)); + return false; + } + + int reg = S_ISREG(st.st_mode); + if (!reg) { + META_DEBUG(5, "Not a regular file: %s", file); + return false; + } + + if (!st.st_size) { + META_DEBUG(5, "Empty file: %s", file); + return false; + } + + return true; +} + // Checks for a non-empty file, relative to the gamedir if necessary. // Formerly used LOAD_FILE_FOR_ME, which provided a simple way to check for // a file under the gamedir, but which would _also_ look in the sibling @@ -138,28 +161,7 @@ bool is_file_exists_in_gamedir(const char* path) Q_snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path); } - struct stat64 st; - int ret = stat64(buf, &st); - if (ret != 0) { - META_DEBUG(5, "Unable to stat '%s': %s", buf, strerror(errno)); - return false; - } - - int reg = S_ISREG(st.st_mode); - if (!reg) { - META_DEBUG(5, "Not a regular file: %s", buf); - return false; - } - - if (!st.st_size) { - META_DEBUG(5, "Empty file: %s", buf); - return false; - } - - if (ret == 0 && reg) - return true; - - return false; + return is_file_exists(buf); } // Turns path into a full path: diff --git a/metamod/src/utils.h b/metamod/src/utils.h index 850419b..98c5428 100644 --- a/metamod/src/utils.h +++ b/metamod/src/utils.h @@ -31,6 +31,7 @@ void normalize_path(char *path); bool is_abs_path(const char *path); bool is_valid_path(const char *path); bool is_platform_postfix(const char *pf); +bool is_file_exists(const char *path); bool is_file_exists_in_gamedir(const char *path); char *full_gamedir_path(const char *path, char (&fullpath)[MAX_PATH]); bool mem_compare(const char* addr, const char* pattern, size_t len);