Update gamedata for CS:S update.
2 * vim: set ts=4 sw=4 tw=99 noet:
3 * =============================================================================
5 * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
33 #include "sourcemod.h"
34 #include "sourcemm_api.h"
35 #include "sm_globals.h"
36 #include "sm_autonatives.h"
37 #include "logic/intercom.h"
38 #include "LibrarySys.h"
39 #include "sm_stringutil.h"
41 #include "sm_srvcmds.h"
43 #include "logic_bridge.h"
44 #include "PlayerManager.h"
45 #include "AdminCache.h"
46 #include "HalfLife2.h"
47 #include "CoreConfig.h"
48 #include "IDBDriver.h"
49 #if SOURCE_ENGINE == SE_DOTA
50 #include "convar_sm_dota.h"
51 #elif SOURCE_ENGINE >= SE_ALIENSWARM
52 #include "convar_sm_swarm.h"
53 #elif SOURCE_ENGINE >= SE_LEFT4DEAD
54 #include "convar_sm_l4d.h"
55 #elif SOURCE_ENGINE >= SE_ORANGEBOX
56 #include "convar_sm_ob.h"
58 #include "convar_sm.h"
62 #define MATCHMAKINGDS_SUFFIX ""
63 #define MATCHMAKINGDS_EXT "dll"
64 #elif defined __APPLE__
65 #define MATCHMAKINGDS_SUFFIX ""
66 #define MATCHMAKINGDS_EXT "dylib"
67 #elif defined __linux__
68 #if SOURCE_ENGINE < SE_LEFT4DEAD2
69 #define MATCHMAKINGDS_SUFFIX "_i486"
71 #define MATCHMAKINGDS_SUFFIX ""
73 #define MATCHMAKINGDS_EXT "so"
76 static ILibrary *g_pLogic = NULL;
77 static LogicInitFunction logic_init_fn;
79 IThreader *g_pThreader;
80 ITextParsers *textparsers;
82 ITranslator *translator;
83 IScriptManager *scripts;
85 IExtensionSys *extsys;
86 IHandleSys *handlesys;
87 IForwardManager *forwardsys;
89 class VEngineServer_Logic : public IVEngineServer_Logic
92 virtual bool IsMapValid(const char *map)
94 return !!engine->IsMapValid(map);
97 virtual void ServerCommand(const char *cmd)
99 engine->ServerCommand(cmd);
103 static VEngineServer_Logic logic_engine;
106 class VFileSystem_Logic : public IFileSystem_Logic
109 const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle)
111 return filesystem->FindFirstEx(pWildCard, pPathID, pHandle);
113 const char *FindNext(FileFindHandle_t handle)
115 return filesystem->FindNext(handle);
117 void FindClose(FileFindHandle_t handle)
119 filesystem->FindClose(handle);
121 FileHandle_t Open(const char *pFileName, const char *pOptions, const char *pathID = 0)
123 return filesystem->Open(pFileName, pOptions, pathID);
125 void Close(FileHandle_t file)
127 filesystem->Close(file);
129 char *ReadLine(char *pOutput, int maxChars, FileHandle_t file)
131 return filesystem->ReadLine(pOutput, maxChars, file);
133 bool EndOfFile(FileHandle_t file)
135 return filesystem->EndOfFile(file);
137 bool FileExists(const char *pFileName, const char *pPathID = 0)
139 return filesystem->FileExists(pFileName, pPathID);
141 unsigned int Size(const char *pFileName, const char *pPathID = 0)
143 return filesystem->Size(pFileName, pPathID);
147 static VFileSystem_Logic logic_filesystem;
150 static ConVar *find_convar(const char *name)
152 return icvar->FindVar(name);
155 static void log_error(const char *fmt, ...)
160 g_Logger.LogErrorEx(fmt, ap);
164 static void log_fatal(const char *fmt, ...)
169 g_Logger.LogFatalEx(fmt, ap);
173 static void log_message(const char *fmt, ...)
177 g_Logger.LogMessageEx(fmt, ap);
181 static void log_to_file(FILE *fp, const char *fmt, ...)
185 g_Logger.LogToOpenFileEx(fp, fmt, ap);
189 static void log_to_game(const char *message)
191 Engine_LogPrintWrapper(message);
194 static const char *get_cvar_string(ConVar* cvar)
196 return cvar->GetString();
199 static bool get_game_name(char *buffer, size_t maxlength)
201 KeyValues *pGameInfo = new KeyValues("GameInfo");
202 if (g_HL2.KVLoadFromFile(pGameInfo, basefilesystem, "gameinfo.txt"))
205 if ((str = pGameInfo->GetString("game", NULL)) != NULL)
207 strncopy(buffer, str, maxlength);
208 pGameInfo->deleteThis();
212 pGameInfo->deleteThis();
216 static const char *get_game_description()
218 return SERVER_CALL(GetGameDescription)();
221 static const char *get_source_engine_name()
223 #if !defined SOURCE_ENGINE
224 # error "Unknown engine type"
226 #if SOURCE_ENGINE == SE_EPISODEONE
228 #elif SOURCE_ENGINE == SE_DARKMESSIAH
229 return "darkmessiah";
230 #elif SOURCE_ENGINE == SE_ORANGEBOX
232 #elif SOURCE_ENGINE == SE_BLOODYGOODTIME
233 return "bloodygoodtime";
234 #elif SOURCE_ENGINE == SE_EYE
236 #elif SOURCE_ENGINE == SE_CSS
238 #elif SOURCE_ENGINE == SE_HL2DM
240 #elif SOURCE_ENGINE == SE_DODS
242 #elif SOURCE_ENGINE == SE_SDK2013
244 #elif SOURCE_ENGINE == SE_TF2
246 #elif SOURCE_ENGINE == SE_LEFT4DEAD
248 #elif SOURCE_ENGINE == SE_NUCLEARDAWN
249 return "nucleardawn";
250 #elif SOURCE_ENGINE == SE_CONTAGION
252 #elif SOURCE_ENGINE == SE_LEFT4DEAD2
254 #elif SOURCE_ENGINE == SE_ALIENSWARM
256 #elif SOURCE_ENGINE == SE_PORTAL2
258 #elif SOURCE_ENGINE == SE_BLADE
260 #elif SOURCE_ENGINE == SE_INSURGENCY
262 #elif SOURCE_ENGINE == SE_CSGO
264 #elif SOURCE_ENGINE == SE_DOTA
269 static bool symbols_are_hidden()
271 #if (SOURCE_ENGINE == SE_CSS) \
272 || (SOURCE_ENGINE == SE_HL2DM) \
273 || (SOURCE_ENGINE == SE_DODS) \
274 || (SOURCE_ENGINE == SE_SDK2013) \
275 || (SOURCE_ENGINE == SE_TF2) \
276 || (SOURCE_ENGINE == SE_LEFT4DEAD) \
277 || (SOURCE_ENGINE == SE_NUCLEARDAWN) \
278 || (SOURCE_ENGINE == SE_LEFT4DEAD2) \
279 || (SOURCE_ENGINE == SE_INSURGENCY) \
280 || (SOURCE_ENGINE == SE_BLADE) \
281 || (SOURCE_ENGINE == SE_CSGO) \
282 || (SOURCE_ENGINE == SE_DOTA)
289 static const char* get_core_config_value(const char* key)
291 return g_CoreConfig.GetCoreConfigValue(key);
294 static bool is_map_loading()
296 return g_SourceMod.IsMapLoading();
299 static bool is_map_running()
301 return g_SourceMod.IsMapRunning();
304 static DatabaseInfo keyvalues_to_dbinfo(KeyValues *kv)
307 info.database = kv->GetString("database", "");
308 info.driver = kv->GetString("driver", "default");
309 info.host = kv->GetString("host", "");
310 info.maxTimeout = kv->GetInt("timeout", 0);
311 info.pass = kv->GetString("pass", "");
312 info.port = kv->GetInt("port", 0);
313 info.user = kv->GetString("user", "");
317 int read_cmd_argc(const CCommand &args)
322 static const char *read_cmd_arg(const CCommand &args, int arg)
324 return args.Arg(arg);
327 static int load_mms_plugin(const char *file, bool *ok, char *error, size_t maxlength)
330 PluginId id = g_pMMPlugins->Load(file, g_PLID, ignore_already, error, maxlength);
334 #ifndef METAMOD_PLAPI_VERSION
340 #ifndef METAMOD_PLAPI_VERSION
341 g_pMMPlugins->Query(id, filep, status, source)
343 g_pMMPlugins->Query(id, NULL, &status, NULL)
345 && status < Pl_Paused))
357 static void unload_mms_plugin(int id)
360 g_pMMPlugins->Unload(id, true, ignore, sizeof(ignore));
363 void do_global_plugin_loads()
365 g_SourceMod.DoGlobalPluginLoads();
368 #if defined METAMOD_PLAPI_VERSION
369 #if SOURCE_ENGINE == SE_LEFT4DEAD
370 #define GAMEFIX "2.l4d"
371 #elif SOURCE_ENGINE == SE_LEFT4DEAD2
372 #define GAMEFIX "2.l4d2"
373 #elif SOURCE_ENGINE == SE_NUCLEARDAWN
374 #define GAMEFIX "2.nd"
375 #elif SOURCE_ENGINE == SE_ALIENSWARM
376 #define GAMEFIX "2.swarm"
377 #elif SOURCE_ENGINE == SE_ORANGEBOX
378 #define GAMEFIX "2.ep2"
379 #elif SOURCE_ENGINE == SE_BLOODYGOODTIME
380 #define GAMEFIX "2.bgt"
381 #elif SOURCE_ENGINE == SE_EYE
382 #define GAMEFIX "2.eye"
383 #elif SOURCE_ENGINE == SE_CSS
384 #define GAMEFIX "2.css"
385 #elif SOURCE_ENGINE == SE_HL2DM
386 #define GAMEFIX "2.hl2dm"
387 #elif SOURCE_ENGINE == SE_DODS
388 #define GAMEFIX "2.dods"
389 #elif SOURCE_ENGINE == SE_SDK2013
390 #define GAMEFIX "2.sdk2013"
391 #elif SOURCE_ENGINE == SE_TF2
392 #define GAMEFIX "2.tf2"
393 #elif SOURCE_ENGINE == SE_DARKMESSIAH
394 #define GAMEFIX "2.darkm"
395 #elif SOURCE_ENGINE == SE_PORTAL2
396 #define GAMEFIX "2.portal2"
397 #elif SOURCE_ENGINE == SE_BLADE
398 #define GAMEFIX "2.blade"
399 #elif SOURCE_ENGINE == SE_INSURGENCY
400 #define GAMEFIX "2.insurgency"
401 #elif SOURCE_ENGINE == SE_CSGO
402 #define GAMEFIX "2.csgo"
403 #elif SOURCE_ENGINE == SE_DOTA
404 #define GAMEFIX "2.dota"
405 #elif SOURCE_ENGINE == SE_CONTAGION
406 #define GAMEFIX "2.contagion"
408 #define GAMEFIX "2.ep1"
409 #endif //(SOURCE_ENGINE == SE_LEFT4DEAD) || (SOURCE_ENGINE == SE_LEFT4DEAD2)
410 #else //METAMOD_PLAPI_VERSION
411 #define GAMEFIX "1.ep1"
412 #endif //METAMOD_PLAPI_VERSION
414 static ServerGlobals serverGlobals;
416 static sm_core_t core_bridge =
421 reinterpret_cast<IVEngineServer*>(&logic_engine),
422 reinterpret_cast<IFileSystem*>(&logic_filesystem),
445 get_game_description,
446 get_source_engine_name,
448 get_core_config_value,
455 do_global_plugin_loads,
456 SM_AreConfigsExecuted,
463 void InitLogicBridge()
465 serverGlobals.universalTime = g_pUniversalTime;
466 serverGlobals.frametime = &gpGlobals->frametime;
467 serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick;
469 core_bridge.engineFactory = (void *)g_SMAPI->GetEngineFactory(false);
470 core_bridge.serverFactory = (void *)g_SMAPI->GetServerFactory(false);
471 core_bridge.listeners = SMGlobalClass::head;
474 char path[PLATFORM_MAX_PATH];
476 g_LibSys.PathFormat(path, sizeof(path), "%s/bin/matchmaking_ds%s.%s", g_SMAPI->GetBaseDir(), MATCHMAKINGDS_SUFFIX, MATCHMAKINGDS_EXT);
478 if ((mmlib = g_LibSys.OpenLibrary(path, NULL, 0)))
480 core_bridge.matchmakingDSFactory = mmlib->GetSymbolAddress("CreateInterface");
481 mmlib->CloseLibrary();
484 logic_init_fn(&core_bridge, &logicore);
486 /* Add SMGlobalClass instances */
487 SMGlobalClass* glob = SMGlobalClass::head;
488 while (glob->m_pGlobalClassNext != NULL)
490 glob = glob->m_pGlobalClassNext;
492 assert(glob->m_pGlobalClassNext == NULL);
493 glob->m_pGlobalClassNext = logicore.head;
495 g_pThreader = logicore.threader;
496 g_pSourcePawn2->SetProfiler(logicore.profiler);
497 translator = logicore.translator;
498 scripts = logicore.scripts;
499 sharesys = logicore.sharesys;
500 extsys = logicore.extsys;
501 g_pCoreIdent = logicore.core_ident;
502 handlesys = logicore.handlesys;
503 forwardsys = logicore.forwardsys;
506 bool StartLogicBridge(char *error, size_t maxlength)
508 char file[PLATFORM_MAX_PATH];
510 /* Now it's time to load the logic binary */
511 g_SMAPI->PathFormat(file,
513 "%s/bin/sourcemod.logic." PLATFORM_LIB_EXT,
514 g_SourceMod.GetSourceModPath());
517 g_pLogic = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
521 if (error && maxlength)
523 UTIL_Format(error, maxlength, "failed to load %s: %s", file, myerror);
528 LogicLoadFunction llf = (LogicLoadFunction)g_pLogic->GetSymbolAddress("logic_load");
531 g_pLogic->CloseLibrary();
532 if (error && maxlength)
534 UTIL_Format(error, maxlength, "could not find logic_load function");
539 GetITextParsers getitxt = (GetITextParsers)g_pLogic->GetSymbolAddress("get_textparsers");
540 textparsers = getitxt();
542 logic_init_fn = llf(SM_LOGIC_MAGIC);
547 void ShutdownLogicBridge()
549 g_pLogic->CloseLibrary();