Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Recognize some gamedll Closes #14
Added platform toolset selector for VS2013/VS2015/VS2017
Added lookup gamedll with postfix, е.g _i386.so
  • Loading branch information
s1lentq committed Jul 17, 2017
1 parent 0e59dfe commit 4f83560
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 37 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -8,13 +8,16 @@
**/msvc/*.opensdf **/msvc/*.opensdf
**/msvc/*.user **/msvc/*.user
**/msvc/*.suo **/msvc/*.suo
**/msvc/*.db
**/msvc/*.opendb
**/msvc/*.aps **/msvc/*.aps
**/msvc/*.pch **/msvc/*.pch
**/msvc/*.txt **/msvc/*.txt
**/msvc/.vs
**/msvc/start*.bat **/msvc/start*.bat
**/msvc/ipch **/msvc/ipch
**/PublishPath*.txt **/PublishPath*.txt
**/*.log **/*.log

db
publish publish
**/appversion.h **/appversion.h
13 changes: 11 additions & 2 deletions metamod/msvc/metamod.vcxproj
Expand Up @@ -14,16 +14,21 @@
<ProjectGuid>{02832A39-E902-46B7-8D47-911C37CF41B0}</ProjectGuid> <ProjectGuid>{02832A39-E902-46B7-8D47-911C37CF41B0}</ProjectGuid>
<SccProjectName /> <SccProjectName />
<SccLocalPath /> <SccLocalPath />
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140_xp</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141_xp</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -110,6 +115,8 @@
</CustomBuildStep> </CustomBuildStep>
<CustomBuildStep> <CustomBuildStep>
<Message>Force build to run Pre-Build event</Message> <Message>Force build to run Pre-Build event</Message>
<Outputs>build.always.run</Outputs>
<Inputs>build.always.run</Inputs>
</CustomBuildStep> </CustomBuildStep>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -182,6 +189,8 @@
</CustomBuildStep> </CustomBuildStep>
<CustomBuildStep> <CustomBuildStep>
<Message>Force build to run Pre-Build event</Message> <Message>Force build to run Pre-Build event</Message>
<Outputs>build.always.run</Outputs>
<Inputs>build.always.run</Inputs>
</CustomBuildStep> </CustomBuildStep>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions metamod/src/conf_meta.cpp
Expand Up @@ -105,8 +105,11 @@ bool MConfig::load(const char* fn)
} }


META_DEBUG(2, "Loading from config file: %s", loadfile); META_DEBUG(2, "Loading from config file: %s", loadfile);
for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) { for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++)
if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) {
trimbuf(line);

if (line[0] == '\0' || line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2))
continue; continue;


char* optname = strtok(line, " \t\r\n"); char* optname = strtok(line, " \t\r\n");
Expand Down
64 changes: 56 additions & 8 deletions metamod/src/game_support.cpp
Expand Up @@ -5,14 +5,24 @@
//! To add support for another mod add an entry here, and add all the //! To add support for another mod add an entry here, and add all the
//! exported entities to link_func.cpp //! exported entities to link_func.cpp
const game_modinfo_t g_known_games[] = { 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 // Previously enumerated in this sourcefile, the list is now kept in a
// separate file, generated based on game information stored in a // separate file, generated based on game information stored in a
// convenient db. // convenient db.
{ "valve", "hl.so", "hl.dll", "Half-Life" }, { "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" }, { "cstrike", "cs.so", "mp.dll", "Counter-Strike" },
{ "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" }, { "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: // End of list terminator:
{ nullptr, nullptr, nullptr, nullptr } { nullptr, nullptr, nullptr, nullptr }
Expand All @@ -30,6 +40,37 @@ static const game_modinfo_t *lookup_game(const char *name)
return nullptr; 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 // Installs gamedll from Steam cache
bool install_gamedll(char *from, const char *to) bool install_gamedll(char *from, const char *to)
{ {
Expand Down Expand Up @@ -103,8 +144,7 @@ bool setup_gamedll(gamedll_t *gamedll)


// Use override-dll if specified. // Use override-dll if specified.
if (g_config->m_gamedll) { if (g_config->m_gamedll) {
Q_strncpy(gamedll->pathname, g_config->m_gamedll, sizeof gamedll->pathname - 1); strlcpy(gamedll->pathname, g_config->m_gamedll);
gamedll->pathname[sizeof gamedll->pathname - 1] = '\0';


// If the path is relative, the gamedll file will be missing and // If the path is relative, the gamedll file will be missing and
// it might be found in the cache file. // it might be found in the cache file.
Expand All @@ -115,7 +155,7 @@ bool setup_gamedll(gamedll_t *gamedll)
// If we could successfully install the gamedll from the cache we // If we could successfully install the gamedll from the cache we
// rectify the pathname to be a full pathname. // rectify the pathname to be a full pathname.
if (install_gamedll(gamedll->pathname, szInstallPath)) { if (install_gamedll(gamedll->pathname, szInstallPath)) {
Q_strncpy(gamedll->pathname, szInstallPath, sizeof(gamedll->pathname)); strlcpy(gamedll->pathname, szInstallPath);
} }
} }


Expand Down Expand Up @@ -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); Q_snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s", gamedll->gamedir, knownfn);
} }
else { else {
Q_strncpy(gamedll->real_pathname, gamedll->pathname, sizeof gamedll->real_pathname - 1); strlcpy(gamedll->real_pathname, gamedll->pathname);
gamedll->real_pathname[sizeof gamedll->real_pathname - 1] = '\0';
} }


if (override) { if (override) {
Expand All @@ -157,8 +196,17 @@ bool setup_gamedll(gamedll_t *gamedll)
META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name, gamedll->file); META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name, gamedll->file);
} }
else if (known) { else if (known) {
Q_strncpy(gamedll->desc, known->desc, sizeof gamedll->desc - 1); strlcpy(gamedll->desc, known->desc);
gamedll->desc[sizeof gamedll->desc - 1] = '\0';
#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); META_LOG("Recognized game '%s'; using dllfile '%s'", gamedll->name, gamedll->file);
} }
Expand Down
6 changes: 0 additions & 6 deletions metamod/src/metamod.cpp
Expand Up @@ -120,12 +120,6 @@ void metamod_startup()
g_config->set("gamedll", cp); 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"); cp = LOCALINFO("mm_execcfg");
if (cp && *cp != '\0') { if (cp && *cp != '\0') {
META_LOG("Execcfg specified via localinfo: %s", cp); META_LOG("Execcfg specified via localinfo: %s", cp);
Expand Down
36 changes: 18 additions & 18 deletions metamod/src/metamod.h
@@ -1,31 +1,31 @@
#pragma once #pragma once


#include "meta_api.h" // META_RES, etc #include "meta_api.h" // META_RES, etc
#include "mlist.h" // MPluginList, etc #include "mlist.h" // MPluginList, etc
#include "mreg.h" // MRegCmdList, etc #include "mreg.h" // MRegCmdList, etc
#include "conf_meta.h" // MConfig #include "conf_meta.h" // MConfig
#include "osdep.h" // NAME_MAX, etc #include "osdep.h" // NAME_MAX, etc
#include "mplayer.h" // MPlayerList #include "mplayer.h" // MPlayerList
#include "engine_t.h" // engine_t, Engine #include "engine_t.h" // engine_t, Engine


#define PLUGINS_INI "plugins.ini" // file that lists plugins to load at startup #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 EXEC_CFG "exec.cfg" // file that contains commands to metamod plugins at startup
#define CONFIG_INI "config.ini" // generic config file #define CONFIG_INI "config.ini" // generic config file


// cvar to contain version // cvar to contain version
extern cvar_t g_meta_version; extern cvar_t g_meta_version;


// Info about the game dll/mod. // Info about the game dll/mod.
struct gamedll_t struct gamedll_t
{ {
char name[NAME_MAX]; // ie "cstrike" (from gamedir) char name[NAME_MAX]; // ie "cstrike" (from gamedir)
char desc[NAME_MAX]; // ie "Counter-Strike" char desc[NAME_MAX]; // ie "Counter-Strike"
char gamedir[PATH_MAX]; // ie "/home/willday/half-life/cstrike" 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 pathname[PATH_MAX]; // ie "/home/willday/half-life/cstrike/dlls/cs_i386.so"
char const* file; // ie "cs_i386.so" char const* file; // ie "cs_i386.so"
char real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc char real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc
CSysModule sys_module; CSysModule sys_module;
gamedll_funcs_t funcs; // dllapi_table, newapi_table gamedll_funcs_t funcs; // dllapi_table, newapi_table
}; };


extern gamedll_t g_GameDLL; extern gamedll_t g_GameDLL;
Expand Down
34 changes: 34 additions & 0 deletions metamod/src/utils.h
Expand Up @@ -64,6 +64,40 @@ bool is_no(const char* str);


const char* LOCALINFO(char* key); const char* LOCALINFO(char* key);


template <size_t N>
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 N>
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 #ifdef _WIN32
char *mm_strtok_r(char *s, const char *delim, char **ptrptr); char *mm_strtok_r(char *s, const char *delim, char **ptrptr);
char *realpath(const char *file_name, char *resolved_name); char *realpath(const char *file_name, char *resolved_name);
Expand Down

0 comments on commit 4f83560

Please sign in to comment.