Changed license in sourcehook_hookmangen_x86.h (agreed to by BAILOPAN and faluco)
Updated MSVC7 proj file
3 * ======================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
34 #include "metamod_util.h"
35 #include "metamod_console.h"
36 #include "metamod_plugins.h"
42 using namespace SourceMM;
43 using namespace SourceHook;
46 * @brief Console Command Implementations
47 * @file concommands.cpp
50 #define CONMSG g_Metamod.ConPrintf
51 #define CLIENT_CONMSG g_Metamod.ClientConPrintf
53 bool Command_Meta(IMetamodSourceCommandInfo *info)
55 unsigned int args = info->GetArgCount();
59 const char *command = info->GetArg(1);
60 if (strcmp(command, "credits") == 0)
62 CONMSG("Metamod:Source was developed by:\n");
63 CONMSG(" SourceHook: Pavol \"PM OnoTo\" Marko\n");
64 CONMSG(" GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
65 CONMSG(" GameDLL: Scott \"Damaged Soul\" Ehlert\n");
66 CONMSG("For more information, see the official website\n");
67 CONMSG("http://www.sourcemm.net/\n");
71 else if (strcmp(command, "version") == 0)
73 CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
74 CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
75 CONMSG("Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
76 CONMSG("SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
77 CONMSG("http://www.sourcemm.net/\n");
81 else if (strcmp(command, "game") == 0)
83 CONMSG("GameDLL Information\n");
84 CONMSG(" Description: %s\n", provider->GetGameDescription());
85 CONMSG(" Mod Path: %s\n", g_Metamod.GetBaseDir());
86 CONMSG(" DLL Path: %s\n", g_Metamod.GetGameBinaryPath());
87 CONMSG(" Interface: ServerGameDLL%03d\n", g_Metamod.GetGameDLLVersion());
89 int engine = g_Metamod.GetSourceEngineBuild();
90 if (engine == SOURCE_ENGINE_ORIGINAL)
92 CONMSG(" Engine: Original (pre-Episode 1)\n");
94 else if (engine == SOURCE_ENGINE_EPISODEONE)
96 CONMSG(" Engine: Episode 1 (2004)\n");
98 else if (engine == SOURCE_ENGINE_ORANGEBOX)
100 CONMSG(" Engine: Episode 2 (Orange Box, 2007)\n");
103 // Display user messages
104 int messages = g_Metamod.GetUserMessageCount();
112 CONMSG(" User Messages: %-32.31s %-5s %-5s\n", "Name", "Index", "Size");
114 for (int i = 0; i < messages; i++)
116 msgname = g_Metamod.GetUserMessage(i, &msgsize);
118 CONMSG(" %-32.31s %-5d %-5d\n", msgname, i, msgsize);
121 CONMSG(" %d user message%s in total\n", messages, (messages > 1) ? "s" : "");
125 CONMSG(" User Messages: None\n");
130 CONMSG(" User Messages: Failed to get list of user messages\n");
135 else if (strcmp(command, "refresh") == 0)
138 g_Metamod.PathFormat(full_path,
141 g_Metamod.GetBaseDir(),
142 g_Metamod.GetPluginsFile());
144 LoadPluginsFromFile(full_path);
148 else if (strcmp(command, "list") == 0)
150 CPluginManager::CPlugin *pl;
156 int plnum = g_PluginMngr.GetPluginCount();
160 CONMSG("No plugins loaded.\n");
163 CONMSG("Listing %d plugin%s:\n", plnum, (plnum > 1) ? "s" : "");
166 for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++)
176 if (pl->m_Status != Pl_Running)
178 len += UTIL_Format(buffer, sizeof(buffer), " [%02d] <%s>", pl->m_Id, g_PluginMngr.GetStatusText(pl));
180 len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", pl->m_Id);
183 if ((plapi = pl->m_API))
185 plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
186 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
188 if (IS_STR_FILLED(plapi->GetVersion()))
190 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
192 if (IS_STR_FILLED(plapi->GetAuthor()))
194 UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
198 CONMSG("%s\n", buffer);
203 else if (strcmp(command, "cmds") == 0)
207 int id = atoi(info->GetArg(2));
208 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
212 CONMSG("Plugin %d not found.\n", id);
218 CONMSG("Plugin %d is not loaded.\n", id);
222 CONMSG("Console commands for %s:\n", pl->m_API->GetName());
223 List<ConCommandBase *>::iterator ci;
226 for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
229 CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
235 CONMSG("Usage: meta cmds <id>\n");
240 else if (strcmp(command, "cvars") == 0)
244 int id = atoi(info->GetArg(2));
245 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
249 CONMSG("Plugin %d not found.\n", id);
255 CONMSG("Plugin %d is not loaded.\n", id);
259 CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
260 List<ConCommandBase *>::iterator ci;
263 for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
266 CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
272 CONMSG("Usage: meta cvars <id>\n");
277 else if (strcmp(command, "info") == 0)
281 int id = atoi(info->GetArg(2));
282 CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
285 CONMSG("Plugin %d not found.\n", id);
291 CONMSG("Plugin %d is not loaded.\n", id);
295 if (pl->m_Status == Pl_Paused)
297 CONMSG("Plugin %d is paused.\n", id);
299 else if (pl->m_Status == Pl_Running)
303 if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
309 CONMSG("Plugin %d is running.\n", id);
313 CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
316 CONMSG(" Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
317 CONMSG(" Version: %s\n", pl->m_API->GetVersion());
318 CONMSG(" Description: %s\n", pl->m_API->GetDescription());
319 CONMSG(" License: %s\n", pl->m_API->GetLicense());
320 CONMSG(" URL: %s\n", pl->m_API->GetURL());
321 CONMSG(" Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
323 CONMSG("File: %s\n\n", pl->m_File.c_str());
329 CONMSG("Usage: meta info <id>\n");
334 else if (strcmp(command, "pause") == 0)
338 int id = atoi(info->GetArg(2));
342 if (!g_PluginMngr.Pause(id, error, sizeof(error)))
344 CONMSG("Pause failed: %s\n", error);
348 CONMSG("Plugin %d has been paused.\n", id);
354 CONMSG("Usage: meta pause <id>\n");
359 else if (strcmp(command, "unpause") == 0)
363 int id = atoi(info->GetArg(2));
366 if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
368 CONMSG("Unpause failed: %s\n", error);
372 CONMSG("Plugin %d has been unpaused.\n", id);
378 CONMSG("Usage: meta unpause <id>\n");
383 else if (strcmp(command, "load") == 0)
387 const char *file = info->GetArg(2);
390 const char *alias = g_PluginMngr.LookupAlias(file);
396 if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
398 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s", file);
402 const char *ext = UTIL_GetExtension(file);
403 #if defined WIN32 || defined _WIN32
404 ext = ext ? "" : ".dll";
406 ext = ext ? "" : "_i486.so";
408 g_Metamod.PathFormat(full_path,
411 g_Metamod.GetBaseDir(),
418 CPluginManager::CPlugin *pl;
420 PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
421 pl = g_PluginMngr.FindById(id);
422 if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
424 CONMSG("Failed to load plugin %s (%s).\n", file, error);
430 CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
432 CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
439 CONMSG("Usage: meta load <path>\n");
444 else if ( (strcmp(command, "alias") == 0) ||
445 (strcmp(command, "aliases") == 0) )
449 const char *alias = info->GetArg(2);
450 const char *value = info->GetArg(3);
452 g_PluginMngr.SetAlias(alias, value);
453 if (value == NULL || value[0] == '\0')
455 CONMSG("Deleted alias: %s.\n", alias);
457 CONMSG("Set alias \"%s\" to: %s\n", alias, value);
462 const char *alias = info->GetArg(2);
463 const char *value = g_PluginMngr.LookupAlias(alias);
466 CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
468 CONMSG("Alias \"%s\" was not found.\n", alias);
473 List<CNameAlias *>::iterator iter, end;
476 iter = g_PluginMngr._alias_begin();
477 end = g_PluginMngr._alias_end();
481 CONMSG("%-10.9s %s\n", "Alias", "File");
483 for (; iter!=end; iter++)
486 CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
490 CONMSG("%d aliases total.\n", total);
494 CONMSG("No aliases found.\n");
499 else if (strcmp(command, "unload") == 0)
503 const char *file = info->GetArg(2);
507 if (id == 0 && isalpha(file[0]))
510 const char *alias = g_PluginMngr.LookupAlias(file);
517 /* first check if it's a known filename */
518 if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
520 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s", file);
524 const char *ext = UTIL_GetExtension(file);
525 #if defined WIN32 || defined _WIN32
526 ext = ext ? "" : ".dll";
528 ext = ext ? "" : "_i486.so";
530 g_Metamod.PathFormat(full_path,
533 g_Metamod.GetBaseDir(),
538 List<CPluginManager::CPlugin *>::iterator iter, end;
539 CPluginManager::CPlugin *pl;
540 iter = g_PluginMngr._begin();
541 end = g_PluginMngr._end();
542 for (; iter!=end; iter++)
545 if (strcmp(pl->m_File.c_str(), full_path) == 0)
553 CONMSG("Plugin \"%s\" not found.\n", full_path);
558 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
560 CONMSG("Unload failed: %s\n", error);
564 CONMSG("Plugin %d unloaded.\n", id);
568 CONMSG("Usage: meta unload <id>\n");
572 else if (strcmp(command, "force_unload") == 0)
576 int id = atoi(info->GetArg(2));
579 if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
581 CONMSG("Force unload failed: %s\n", error);
585 CONMSG("Plugin %d force unloaded.\n", id);
591 CONMSG("Usage: meta force_unload <id>\n");
596 else if (strcmp(command, "clear") == 0)
598 if (!g_PluginMngr.UnloadAll())
600 CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
604 CONMSG("All plugins unloaded.\n");
608 else if (strcmp(command, "retry") == 0)
612 int id = atoi(info->GetArg(2));
615 if (!g_PluginMngr.Retry(id, error, sizeof(error)))
617 CONMSG("Error reloading plugin: %s\n", error);
621 CONMSG("Plugin %d successfully reloaded.\n", id);
627 CONMSG("Usage: meta retry <id>\n");
634 CONMSG("Metamod:Source Menu\n");
635 CONMSG("usage: meta <command> [arguments]\n");
636 CONMSG(" alias - List or set an alias\n");
637 CONMSG(" clear - Unload all plugins forcefully\n");
638 CONMSG(" cmds - Show plugin commands\n");
639 CONMSG(" cvars - Show plugin cvars\n");
640 CONMSG(" credits - About Metamod:Source\n");
641 CONMSG(" force_unload - Forcefully unload a plugin\n");
642 CONMSG(" game - Information about GameDLL\n");
643 CONMSG(" info - Information about a plugin\n");
644 CONMSG(" list - List plugins\n");
645 CONMSG(" load - Load a plugin\n");
646 CONMSG(" pause - Pause a running plugin\n");
647 CONMSG(" refresh - Reparse plugins file\n");
648 CONMSG(" retry - Attempt to reload a plugin\n");
649 CONMSG(" unload - Unload a loaded plugin\n");
650 CONMSG(" unpause - Unpause a paused plugin\n");
651 CONMSG(" version - Version information\n");
656 bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
658 const char *cmd = info->GetArg(0);
660 if (strcmp(cmd, "meta") == 0)
662 unsigned int args = info->GetArgCount();
665 const char *subcmd = info->GetArg(1);
667 if (strcmp(subcmd, "credits") == 0)
669 CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
670 CLIENT_CONMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\n");
671 CLIENT_CONMSG(client, " GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
672 CLIENT_CONMSG(client, " GameDLL: Scott \"Damaged Soul\" Ehlert\n");
673 CLIENT_CONMSG(client, "For more information, see the official website\n");
674 CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
678 else if(strcmp(subcmd, "version") == 0)
680 CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
681 CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
682 CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
683 CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
684 CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
688 else if(strcmp(subcmd, "list") == 0)
690 CPluginManager::CPlugin *pl;
698 for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)
701 if (pl && pl->m_Status == Pl_Running)
704 if (!plapi || !plapi->QueryRunning(NULL, 0))
710 len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", plnum);
712 plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
713 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
715 if (IS_STR_FILLED(plapi->GetVersion()))
717 len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
719 if (IS_STR_FILLED(plapi->GetAuthor()))
721 UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
724 CLIENT_CONMSG(client, "%s\n", buffer);
730 CLIENT_CONMSG(client, "No active plugins loaded.\n");
737 CLIENT_CONMSG(client, "Metamod:Source Menu\n");
738 CLIENT_CONMSG(client, "usage: meta <command>\n");
739 CLIENT_CONMSG(client, " credits - About Metamod:Source\n");
740 CLIENT_CONMSG(client, " list - List plugins\n");
741 CLIENT_CONMSG(client, " version - Version information\n");