From 5cf552dc8c2a25f1bafbb13d820bfc2a03e0f943 Mon Sep 17 00:00:00 2001 From: s1lent Date: Tue, 18 Jul 2017 06:06:15 +0700 Subject: [PATCH] =?UTF-8?q?Recognize=20some=20gamedll=20Closes=20#14=20Add?= =?UTF-8?q?ed=20platform=20toolset=20selector=20for=20VS2013/VS2015/VS2017?= =?UTF-8?q?=20Added=20lookup=20gamedll=20with=20postfix,=20=D0=B5.g=20=5Fi?= =?UTF-8?q?386.so?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ metamod/msvc/metamod.vcxproj | 13 ++++++-- metamod/src/conf_meta.cpp | 7 ++-- metamod/src/game_support.cpp | 64 +++++++++++++++++++++++++++++++----- metamod/src/metamod.cpp | 6 ---- metamod/src/metamod.h | 34 +++++++++---------- metamod/src/utils.h | 34 +++++++++++++++++++ 7 files changed, 126 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 8c0bc65..870c6ac 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,12 @@ **/msvc/*.opensdf **/msvc/*.user **/msvc/*.suo +**/msvc/*.db +**/msvc/*.opendb **/msvc/*.aps **/msvc/*.pch **/msvc/*.txt +**/msvc/.vs **/msvc/start*.bat **/msvc/ipch **/PublishPath*.txt diff --git a/metamod/msvc/metamod.vcxproj b/metamod/msvc/metamod.vcxproj index 77621ad..f96f00c 100644 --- a/metamod/msvc/metamod.vcxproj +++ b/metamod/msvc/metamod.vcxproj @@ -14,16 +14,21 @@ {02832A39-E902-46B7-8D47-911C37CF41B0} + 8.1 DynamicLibrary - v120_xp + v120_xp + v140_xp + v141_xp true DynamicLibrary - v120_xp + v120_xp + v140_xp + v141_xp @@ -110,6 +115,8 @@ Force build to run Pre-Build event + build.always.run + build.always.run @@ -182,6 +189,8 @@ Force build to run Pre-Build event + build.always.run + build.always.run diff --git a/metamod/src/conf_meta.cpp b/metamod/src/conf_meta.cpp index 3051bf7..609d7a0 100644 --- a/metamod/src/conf_meta.cpp +++ b/metamod/src/conf_meta.cpp @@ -105,8 +105,11 @@ bool MConfig::load(const char* fn) } META_DEBUG(2, "Loading from config file: %s", loadfile); - for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) { - if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) + for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) + { + trimbuf(line); + + if (line[0] == '\0' || line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) continue; char* optname = strtok(line, " \t\r\n"); diff --git a/metamod/src/game_support.cpp b/metamod/src/game_support.cpp index 28f1e54..397eb6b 100644 --- a/metamod/src/game_support.cpp +++ b/metamod/src/game_support.cpp @@ -5,14 +5,24 @@ //! To add support for another mod add an entry here, and add all the //! exported entities to link_func.cpp const game_modinfo_t g_known_games[] = { - // name/gamedir linux_so win_dll desc + // name/gamedir linux_so win_dll desc // // Previously enumerated in this sourcefile, the list is now kept in a // separate file, generated based on game information stored in a // convenient db. { "valve", "hl.so", "hl.dll", "Half-Life" }, + { "bshift", "bshift.so", "hl.dll", "Half-Life: Blue Shift" }, + { "ag", "ag.so", "ag.dll", "Adrenaline Gamer" }, { "cstrike", "cs.so", "mp.dll", "Counter-Strike" }, { "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" }, + { "czeror", "cz.so", "cz.dll", "Counter-Strike:Condition Zero Deleted Scenes" }, + { "ricochet", "ricochet.so", "mp.dll", "Ricochet" }, + { "dmc", "dmc.so", "dmc.dll", "Deathmatch Classic" }, + { "dod", "dod.so", "dod.dll", "Day of Defeat" }, + { "tfc", "tfc.so", "tfc.dll", "Team Fortress Classic" }, + { "gearbox", "opfor.so", "opfor.dll", "Opposing Force" }, + { "ns", "ns.so", "ns.dll", "Natural Selection" }, + { "nsp", "ns.so", "ns.dll", "Natural Selection Beta" }, // End of list terminator: { nullptr, nullptr, nullptr, nullptr } @@ -30,6 +40,37 @@ static const game_modinfo_t *lookup_game(const char *name) return nullptr; } +bool lookup_game_postfixes(gamedll_t *gamedll) +{ + char pathname[PATH_MAX]; + static char postfix_path[PATH_MAX] = ""; + + strlcpy(pathname, gamedll->pathname); + + // find extensions and skip + char *pos = strrchr(pathname, '.'); + if (pos) { + *pos = '\0'; + } + + for (size_t i = 0; i < arraysize(g_platform_postfixes); i++) + { + postfix_path[0] = '\0'; + strlcat(postfix_path, pathname); + strlcat(postfix_path, g_platform_postfixes[i]); + + if (is_file_exists_in_gamedir(postfix_path)) { + strlcpy(gamedll->pathname, postfix_path); + strlcpy(gamedll->real_pathname, postfix_path); + gamedll->file = postfix_path; + + return true; + } + } + + return false; +} + // Installs gamedll from Steam cache bool install_gamedll(char *from, const char *to) { @@ -103,8 +144,7 @@ bool setup_gamedll(gamedll_t *gamedll) // Use override-dll if specified. if (g_config->m_gamedll) { - Q_strncpy(gamedll->pathname, g_config->m_gamedll, sizeof gamedll->pathname - 1); - gamedll->pathname[sizeof gamedll->pathname - 1] = '\0'; + strlcpy(gamedll->pathname, g_config->m_gamedll); // If the path is relative, the gamedll file will be missing and // it might be found in the cache file. @@ -115,7 +155,7 @@ bool setup_gamedll(gamedll_t *gamedll) // If we could successfully install the gamedll from the cache we // rectify the pathname to be a full pathname. if (install_gamedll(gamedll->pathname, szInstallPath)) { - Q_strncpy(gamedll->pathname, szInstallPath, sizeof(gamedll->pathname)); + strlcpy(gamedll->pathname, szInstallPath); } } @@ -145,8 +185,7 @@ bool setup_gamedll(gamedll_t *gamedll) Q_snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s", gamedll->gamedir, knownfn); } else { - Q_strncpy(gamedll->real_pathname, gamedll->pathname, sizeof gamedll->real_pathname - 1); - gamedll->real_pathname[sizeof gamedll->real_pathname - 1] = '\0'; + strlcpy(gamedll->real_pathname, gamedll->pathname); } if (override) { @@ -157,8 +196,17 @@ bool setup_gamedll(gamedll_t *gamedll) META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name, gamedll->file); } else if (known) { - Q_strncpy(gamedll->desc, known->desc, sizeof gamedll->desc - 1); - gamedll->desc[sizeof gamedll->desc - 1] = '\0'; + strlcpy(gamedll->desc, known->desc); + +#if !defined(_WIN32) + if (!is_file_exists_in_gamedir(gamedll->pathname)) + { + // trying lookup gamedll with postfixes ie _i386.so + if (lookup_game_postfixes(gamedll)) { + META_DEBUG(3, "dll: Trying lookup to gamedll with postfixes was a success. Game '%s'", gamedll->pathname); + } + } +#endif META_LOG("Recognized game '%s'; using dllfile '%s'", gamedll->name, gamedll->file); } diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp index 027dde4..fa62311 100644 --- a/metamod/src/metamod.cpp +++ b/metamod/src/metamod.cpp @@ -120,12 +120,6 @@ void metamod_startup() g_config->set("gamedll", cp); } - cp = LOCALINFO("mm_pluginsfile"); - if (cp && *cp != '\0') { - META_LOG("Pluginsfile specified via localinfo: %s", cp); - g_config->set("plugins_file", cp); - } - cp = LOCALINFO("mm_execcfg"); if (cp && *cp != '\0') { META_LOG("Execcfg specified via localinfo: %s", cp); diff --git a/metamod/src/metamod.h b/metamod/src/metamod.h index 7c03e94..6584dd8 100644 --- a/metamod/src/metamod.h +++ b/metamod/src/metamod.h @@ -1,16 +1,16 @@ #pragma once -#include "meta_api.h" // META_RES, etc -#include "mlist.h" // MPluginList, etc -#include "mreg.h" // MRegCmdList, etc -#include "conf_meta.h" // MConfig -#include "osdep.h" // NAME_MAX, etc -#include "mplayer.h" // MPlayerList -#include "engine_t.h" // engine_t, Engine +#include "meta_api.h" // META_RES, etc +#include "mlist.h" // MPluginList, etc +#include "mreg.h" // MRegCmdList, etc +#include "conf_meta.h" // MConfig +#include "osdep.h" // NAME_MAX, etc +#include "mplayer.h" // MPlayerList +#include "engine_t.h" // engine_t, Engine -#define PLUGINS_INI "plugins.ini" // file that lists plugins to load at startup -#define EXEC_CFG "exec.cfg" // file that contains commands to metamod plugins at startup -#define CONFIG_INI "config.ini" // generic config file +#define PLUGINS_INI "plugins.ini" // file that lists plugins to load at startup +#define EXEC_CFG "exec.cfg" // file that contains commands to metamod plugins at startup +#define CONFIG_INI "config.ini" // generic config file // cvar to contain version extern cvar_t g_meta_version; @@ -18,14 +18,14 @@ extern cvar_t g_meta_version; // Info about the game dll/mod. struct gamedll_t { - char name[NAME_MAX]; // ie "cstrike" (from gamedir) - char desc[NAME_MAX]; // ie "Counter-Strike" - char gamedir[PATH_MAX]; // ie "/home/willday/half-life/cstrike" - char pathname[PATH_MAX]; // ie "/home/willday/half-life/cstrike/dlls/cs_i386.so" - char const* file; // ie "cs_i386.so" - char real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc + char name[NAME_MAX]; // ie "cstrike" (from gamedir) + char desc[NAME_MAX]; // ie "Counter-Strike" + char gamedir[PATH_MAX]; // ie "/home/willday/half-life/cstrike" + char pathname[PATH_MAX]; // ie "/home/willday/half-life/cstrike/dlls/cs_i386.so" + char const* file; // ie "cs_i386.so" + char real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc CSysModule sys_module; - gamedll_funcs_t funcs; // dllapi_table, newapi_table + gamedll_funcs_t funcs; // dllapi_table, newapi_table }; extern gamedll_t g_GameDLL; diff --git a/metamod/src/utils.h b/metamod/src/utils.h index 92368af..10cdde4 100644 --- a/metamod/src/utils.h +++ b/metamod/src/utils.h @@ -64,6 +64,40 @@ bool is_no(const char* str); const char* LOCALINFO(char* key); +template +char *strlcpy(char (&dest)[N], const char *src) { + Q_strncpy(dest, src, N - 1); + dest[N - 1] = '\0'; + return dest; +} + +inline char *strnlcpy(char *dest, const char *src, size_t n) { + Q_strncpy(dest, src, n - 1); + dest[n - 1] = '\0'; + return dest; +} + +template +size_t strlcat(char (&dest)[N], const char *src) +{ + size_t dstlen = Q_strlen(dest); + size_t size = N - dstlen + 1; + + if (!size) { + return dstlen; + } + + size_t srclen = Q_strlen(src); + if (srclen > size) { + srclen = size; + } + + Q_memcpy(dest + dstlen, src, srclen); + dest[dstlen + srclen] = '\0'; + + return dstlen + srclen; +} + #ifdef _WIN32 char *mm_strtok_r(char *s, const char *delim, char **ptrptr); char *realpath(const char *file_name, char *resolved_name);