mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-03-03 17:15:26 +03:00
Fix #33
This commit is contained in:
parent
e0e3266711
commit
35eada44d0
@ -106,9 +106,22 @@ const game_modinfo_t g_known_games[] = {
|
|||||||
// Find a modinfo corresponding to the given game name.
|
// Find a modinfo corresponding to the given game name.
|
||||||
static const game_modinfo_t *lookup_game(const char *name)
|
static const game_modinfo_t *lookup_game(const char *name)
|
||||||
{
|
{
|
||||||
|
char temp[MAX_PATH];
|
||||||
|
|
||||||
for (auto& known : g_known_games) {
|
for (auto& known : g_known_games) {
|
||||||
if (known.name && !Q_stricmp(known.name, name))
|
if (known.name && !Q_stricmp(known.name, name)) {
|
||||||
return &known;
|
#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
|
// no match found
|
||||||
@ -213,10 +226,6 @@ bool setup_gamedll(gamedll_t *gamedll)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Neither override nor known-list found a gamedll.
|
|
||||||
if (!known && !g_config->m_gamedll)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Use override-dll if specified.
|
// Use override-dll if specified.
|
||||||
if (g_config->m_gamedll) {
|
if (g_config->m_gamedll) {
|
||||||
Q_strlcpy(gamedll->pathname, g_config->m_gamedll);
|
Q_strlcpy(gamedll->pathname, g_config->m_gamedll);
|
||||||
|
@ -114,6 +114,29 @@ char* realpath(const char* file_name, char* resolved_name)
|
|||||||
}
|
}
|
||||||
#endif // _WIN32
|
#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.
|
// 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
|
// 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
|
// 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);
|
Q_snprintf(buf, sizeof buf, "%s/%s", g_GameDLL.gamedir, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat64 st;
|
return is_file_exists(buf);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turns path into a full path:
|
// Turns path into a full path:
|
||||||
|
@ -31,6 +31,7 @@ void normalize_path(char *path);
|
|||||||
bool is_abs_path(const char *path);
|
bool is_abs_path(const char *path);
|
||||||
bool is_valid_path(const char *path);
|
bool is_valid_path(const char *path);
|
||||||
bool is_platform_postfix(const char *pf);
|
bool is_platform_postfix(const char *pf);
|
||||||
|
bool is_file_exists(const char *path);
|
||||||
bool is_file_exists_in_gamedir(const char *path);
|
bool is_file_exists_in_gamedir(const char *path);
|
||||||
char *full_gamedir_path(const char *path, char (&fullpath)[MAX_PATH]);
|
char *full_gamedir_path(const char *path, char (&fullpath)[MAX_PATH]);
|
||||||
bool mem_compare(const char* addr, const char* pattern, size_t len);
|
bool mem_compare(const char* addr, const char* pattern, size_t len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user