1.1 --- a/loader/loader.cpp Mon Feb 16 18:13:31 2009 -0500
1.2 +++ b/loader/loader.cpp Wed Feb 18 01:38:23 2009 -0600
1.3 @@ -35,6 +35,11 @@
1.4 #include "serverplugin.h"
1.5 #include "gamedll.h"
1.6 #include "utility.h"
1.7 +#include "valve_commandline.h"
1.8 +
1.9 +#undef GetCommandLine
1.10 +
1.11 +typedef ICommandLine *(*GetCommandLine)();
1.12
1.13 static HMODULE mm_library = NULL;
1.14 static char mm_fatal_logfile[PLATFORM_MAX_PATH] = "metamod-fatal.log";
1.15 @@ -64,11 +69,12 @@
1.16 fclose(fp);
1.17 }
1.18
1.19 -static const char *backend_names[3] =
1.20 +static const char *backend_names[] =
1.21 {
1.22 "1.ep1",
1.23 "2.ep2",
1.24 - "2.l4d"
1.25 + "2.l4d",
1.26 + "2.darkm"
1.27 };
1.28
1.29 #if defined _WIN32
1.30 @@ -163,8 +169,76 @@
1.31 return mm_GetLibAddress(mm_library, name);
1.32 }
1.33
1.34 +#if defined _WIN32
1.35 +#define TIER0_NAME "bin\\tier0.dll"
1.36 +#define VSTDLIB_NAME "bin\\vstdlib.dll"
1.37 +#elif defined __linux__
1.38 +#define TIER0_NAME "bin/tier0_i486.so"
1.39 +#define VSTDLIB_NAME "bin/vstdlib_i486.so"
1.40 +#endif
1.41 +
1.42 +const char *
1.43 +mm_GetGameName()
1.44 +{
1.45 + void *lib;
1.46 + char error[255];
1.47 + GetCommandLine valve_cmdline;
1.48 + char lib_path[PLATFORM_MAX_PATH];
1.49 + const char *game_name;
1.50 +
1.51 + if (!mm_ResolvePath(TIER0_NAME, lib_path, sizeof(lib_path)))
1.52 + {
1.53 + mm_LogFatal("Could not find path for: " TIER0_NAME);
1.54 + return NULL;
1.55 + }
1.56 +
1.57 + if ((lib = mm_LoadLibrary(lib_path, error, sizeof(error))) == NULL)
1.58 + {
1.59 + mm_LogFatal("Could not load %s: %s", lib_path, error);
1.60 + return NULL;
1.61 + }
1.62 +
1.63 + valve_cmdline = (GetCommandLine)mm_GetLibAddress(lib, "CommandLine_Tier0");
1.64 + if (valve_cmdline == NULL)
1.65 + {
1.66 + /* We probably have a Ship engine. */
1.67 + mm_UnloadLibrary(lib);
1.68 + if (!mm_ResolvePath(VSTDLIB_NAME, lib_path, sizeof(lib_path)))
1.69 + {
1.70 + mm_LogFatal("Could not find path for: " VSTDLIB_NAME);
1.71 + return NULL;
1.72 + }
1.73 +
1.74 + if ((lib = mm_LoadLibrary(lib_path, error, sizeof(error))) == NULL)
1.75 + {
1.76 + mm_LogFatal("Could not load %s: %s", lib_path, error);
1.77 + return NULL;
1.78 + }
1.79 +
1.80 + valve_cmdline = (GetCommandLine)mm_GetLibAddress(lib, "CommandLine");
1.81 + }
1.82 +
1.83 + mm_UnloadLibrary(lib);
1.84 +
1.85 + if (valve_cmdline == NULL)
1.86 + {
1.87 + mm_LogFatal("Could not locate any command line functionality");
1.88 + return NULL;
1.89 + }
1.90 +
1.91 + game_name = valve_cmdline()->ParmValue("-game");
1.92 +
1.93 + /* This probably means that the game directory is actually the current directory */
1.94 + if (!game_name)
1.95 + {
1.96 + game_name = ".";
1.97 + }
1.98 +
1.99 + return game_name;
1.100 +}
1.101 +
1.102 MetamodBackend
1.103 -mm_DetermineBackend(QueryValveInterface engineFactory)
1.104 +mm_DetermineBackend(QueryValveInterface engineFactory, const char *game_name)
1.105 {
1.106 /* Check for L4D */
1.107 if (engineFactory("VEngineServer022", NULL) != NULL &&
1.108 @@ -180,11 +254,16 @@
1.109 {
1.110 return MMBackend_Episode2;
1.111 }
1.112 - /* Check for EP1 */
1.113 + /* Check for Episode One/Old Engine */
1.114 else if (engineFactory("VModelInfoServer001", NULL) != NULL &&
1.115 (engineFactory("VEngineCvar003", NULL) != NULL ||
1.116 engineFactory("VEngineCvar002", NULL) != NULL))
1.117 {
1.118 + /* Check for Dark Messiah which has a weird directory structure */
1.119 + if (strcmp(game_name, ".") == 0)
1.120 + {
1.121 + return MMBackend_DarkMessiah;
1.122 + }
1.123 return MMBackend_Episode1;
1.124 }
1.125 }