Clean up logic source.

This commit is contained in:
Asher Baker 2015-10-29 16:29:51 +00:00
parent 1a09f2b6df
commit 1ba85dac9c
74 changed files with 4812 additions and 4812 deletions

View File

@ -32,59 +32,59 @@ binary.sources += [
'smn_adt_array.cpp', 'smn_adt_array.cpp',
'smn_sorting.cpp', 'smn_sorting.cpp',
'smn_maplists.cpp', 'smn_maplists.cpp',
'ADTFactory.cpp', 'adtfactory.cpp',
'smn_adt_stack.cpp', 'smn_adt_stack.cpp',
'thread/ThreadWorker.cpp', 'thread/threadworker.cpp',
'thread/BaseWorker.cpp', 'thread/baseworker.cpp',
'ThreadSupport.cpp', 'threadsupport.cpp',
'smn_float.cpp', 'smn_float.cpp',
'TextParsers.cpp', 'textparsers.cpp',
'smn_textparse.cpp', 'smn_textparse.cpp',
'smn_adt_trie.cpp', 'smn_adt_trie.cpp',
'smn_functions.cpp', 'smn_functions.cpp',
'smn_timers.cpp', 'smn_timers.cpp',
'smn_players.cpp', 'smn_players.cpp',
'MemoryUtils.cpp', 'memoryutils.cpp',
'smn_admin.cpp', 'smn_admin.cpp',
'smn_banning.cpp', 'smn_banning.cpp',
'smn_filesystem.cpp', 'smn_filesystem.cpp',
'stringutil.cpp', 'stringutil.cpp',
'Translator.cpp', 'translator.cpp',
'PhraseCollection.cpp', 'phrasecollection.cpp',
'smn_lang.cpp', 'smn_lang.cpp',
'smn_string.cpp', 'smn_string.cpp',
'smn_handles.cpp', 'smn_handles.cpp',
'smn_datapacks.cpp', 'smn_datapacks.cpp',
'smn_gameconfigs.cpp', 'smn_gameconfigs.cpp',
'smn_fakenatives.cpp', 'smn_fakenatives.cpp',
'GameConfigs.cpp', 'gameconfigs.cpp',
'sm_crc32.cpp', 'sm_crc32.cpp',
'smn_profiler.cpp', 'smn_profiler.cpp',
'ShareSys.cpp', 'sharesys.cpp',
'PluginSys.cpp', 'pluginsys.cpp',
'HandleSys.cpp', 'handlesys.cpp',
'NativeOwner.cpp', 'nativeowner.cpp',
'ExtensionSys.cpp', 'extensionsys.cpp',
'DebugReporter.cpp', 'debugreporter.cpp',
'Database.cpp', 'database.cpp',
'smn_database.cpp', 'smn_database.cpp',
'ForwardSys.cpp', 'forwardsys.cpp',
'AdminCache.cpp', 'admincache.cpp',
'sm_trie.cpp', 'sm_trie.cpp',
'smn_console.cpp', 'smn_console.cpp',
'ProfileTools.cpp', 'profiletools.cpp',
'Logger.cpp', 'logger.cpp',
'smn_core.cpp', 'smn_core.cpp',
'smn_menus.cpp', 'smn_menus.cpp',
'sprintf.cpp', 'sprintf.cpp',
'LibrarySys.cpp', 'librarysys.cpp',
'RootConsoleMenu.cpp', 'rootconsolemenu.cpp',
'CDataPack.cpp', 'cdatapack.cpp',
'frame_tasks.cpp', 'frame_tasks.cpp',
] ]
if builder.target_platform == 'windows': if builder.target_platform == 'windows':
binary.sources += ['thread/WinThreads.cpp'] binary.sources += ['thread/winthreads.cpp']
else: else:
binary.sources += ['thread/PosixThreads.cpp'] binary.sources += ['thread/posixthreads.cpp']
SM.binaries += [builder.Add(binary)] SM.binaries += [builder.Add(binary)]

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,8 +29,8 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "ADTFactory.h" #include "adtfactory.h"
#include "ShareSys.h" #include "sharesys.h"
ADTFactory g_AdtFactory; ADTFactory g_AdtFactory;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -31,7 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "CDataPack.h" #include "cdatapack.h"
#include <am-utility.h> #include <am-utility.h>
#include <am-vector.h> #include <am-vector.h>
@ -88,7 +88,7 @@ void CDataPack::CheckSize(size_t typesize)
{ {
m_capacity *= 2; m_capacity *= 2;
} while (pos + typesize > m_capacity); } while (pos + typesize > m_capacity);
m_pBase = (char *)realloc(m_pBase, m_capacity); m_pBase = (char *)realloc(m_pBase, m_capacity);
m_curptr = m_pBase + pos; m_curptr = m_pBase + pos;
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -34,28 +34,28 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include "common_logic.h" #include "common_logic.h"
#include "TextParsers.h" #include "textparsers.h"
#include "sm_crc32.h" #include "sm_crc32.h"
#include "MemoryUtils.h" #include "memoryutils.h"
#include "stringutil.h" #include "stringutil.h"
#include "ThreadSupport.h" #include "threadsupport.h"
#include "Translator.h" #include "translator.h"
#include "GameConfigs.h" #include "gameconfigs.h"
#include "DebugReporter.h" #include "debugreporter.h"
#include "PluginSys.h" #include "pluginsys.h"
#include "ShareSys.h" #include "sharesys.h"
#include "NativeOwner.h" #include "nativeowner.h"
#include "HandleSys.h" #include "handlesys.h"
#include "ExtensionSys.h" #include "extensionsys.h"
#include "ForwardSys.h" #include "forwardsys.h"
#include "AdminCache.h" #include "admincache.h"
#include "ProfileTools.h" #include "profiletools.h"
#include "Logger.h" #include "logger.h"
#include "frame_tasks.h" #include "frame_tasks.h"
#include "sprintf.h" #include "sprintf.h"
#include "LibrarySys.h" #include "librarysys.h"
#include "RootConsoleMenu.h" #include "rootconsolemenu.h"
#include "CDataPack.h" #include "cdatapack.h"
#include <bridge/include/BridgeAPI.h> #include <bridge/include/BridgeAPI.h>
#include <bridge/include/IProviderCallbacks.h> #include <bridge/include/IProviderCallbacks.h>
@ -180,7 +180,7 @@ static void logic_init(CoreProvider* core, sm_logic_t* _logic)
g_ShareSys.Initialize(); g_ShareSys.Initialize();
g_pCoreIdent = g_ShareSys.CreateCoreIdentity(); g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
_logic->core_ident = g_pCoreIdent; _logic->core_ident = g_pCoreIdent;
} }
@ -215,12 +215,12 @@ void *operator new(size_t size)
return malloc(size); return malloc(size);
} }
void *operator new[](size_t size) void *operator new[](size_t size)
{ {
return malloc(size); return malloc(size);
} }
void operator delete(void *ptr) void operator delete(void *ptr)
{ {
free(ptr); free(ptr);
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,11 +29,11 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "Database.h" #include "database.h"
#include "ISourceMod.h" #include <ISourceMod.h>
#include "HandleSys.h" #include "handlesys.h"
#include "ExtensionSys.h" #include "extensionsys.h"
#include "PluginSys.h" #include "pluginsys.h"
#include <stdlib.h> #include <stdlib.h>
#include <IThreader.h> #include <IThreader.h>
#include <bridge/include/ILogger.h> #include <bridge/include/ILogger.h>
@ -45,7 +45,7 @@
DBManager g_DBMan; DBManager g_DBMan;
static bool s_OneTimeThreaderErrorMsg = false; static bool s_OneTimeThreaderErrorMsg = false;
DBManager::DBManager() DBManager::DBManager()
: m_Terminate(false), : m_Terminate(false),
m_ParseLevel(0), m_ParseLevel(0),
m_ParseState(0), m_ParseState(0),
@ -65,7 +65,7 @@ void DBManager::OnSourceModAllInitialized()
g_HandleSys.InitAccessDefaults(NULL, &sec); g_HandleSys.InitAccessDefaults(NULL, &sec);
sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY; sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY;
sec.access[HandleAccess_Clone] |= HANDLE_RESTRICT_IDENTITY; sec.access[HandleAccess_Clone] |= HANDLE_RESTRICT_IDENTITY;
m_DriverType = g_HandleSys.CreateType("IDriver", this, 0, NULL, &sec, g_pCoreIdent, NULL); m_DriverType = g_HandleSys.CreateType("IDriver", this, 0, NULL, &sec, g_pCoreIdent, NULL);
m_DatabaseType = g_HandleSys.CreateType("IDatabase", this, 0, NULL, NULL, g_pCoreIdent, NULL); m_DatabaseType = g_HandleSys.CreateType("IDatabase", this, 0, NULL, NULL, g_pCoreIdent, NULL);
@ -74,7 +74,7 @@ void DBManager::OnSourceModAllInitialized()
g_pSM->BuildPath(Path_SM, m_Filename, sizeof(m_Filename), "configs/databases.cfg"); g_pSM->BuildPath(Path_SM, m_Filename, sizeof(m_Filename), "configs/databases.cfg");
g_PluginSys.AddPluginsListener(this); g_PluginSys.AddPluginsListener(this);
g_pSM->AddGameFrameHook(&FrameHook); g_pSM->AddGameFrameHook(&FrameHook);
} }
@ -243,7 +243,7 @@ SMCResult DBManager::ReadSMC_LeavingSection(const SMCStates *states)
cdb->info.host = cdb->host.c_str(); cdb->info.host = cdb->host.c_str();
cdb->info.user = cdb->user.c_str(); cdb->info.user = cdb->user.c_str();
cdb->info.pass = cdb->pass.c_str(); cdb->info.pass = cdb->pass.c_str();
/* Save it.. */ /* Save it.. */
m_confs.push_back(cdb); m_confs.push_back(cdb);
@ -318,7 +318,7 @@ void DBManager::AddDriver(IDBDriver *pDriver)
{ {
/* Let's kill the worker. Join the thread and let the queries flush. /* Let's kill the worker. Join the thread and let the queries flush.
* This is kind of stupid but we just want to unload safely. * This is kind of stupid but we just want to unload safely.
* Rather than recreate the worker, we'll wait until someone throws * Rather than recreate the worker, we'll wait until someone throws
* another query through. * another query through.
*/ */
KillWorkerThread(); KillWorkerThread();
@ -329,8 +329,8 @@ void DBManager::AddDriver(IDBDriver *pDriver)
void DBManager::RemoveDriver(IDBDriver *pDriver) void DBManager::RemoveDriver(IDBDriver *pDriver)
{ {
/* Again, we're forced to kill the worker. How rude! /* Again, we're forced to kill the worker. How rude!
* Doing this flushes the queue, and thus we don't need to * Doing this flushes the queue, and thus we don't need to
* clean anything else. * clean anything else.
*/ */
KillWorkerThread(); KillWorkerThread();
@ -616,8 +616,8 @@ void DBManager::ThreadMain()
ke::AutoLock lock(&m_ThinkLock); ke::AutoLock lock(&m_ThinkLock);
m_ThinkQueue.push(op); m_ThinkQueue.push(op);
} }
if (!m_Terminate) if (!m_Terminate)
{ {
ke::AutoUnlock unlock(&m_QueueEvent); ke::AutoUnlock unlock(&m_QueueEvent);
@ -664,7 +664,7 @@ void DBManager::OnSourceModIdentityDropped(IdentityToken_t *pToken)
KillWorkerThread(); KillWorkerThread();
/* Run all of the think operations. /* Run all of the think operations.
* Unlike the driver unloading example, we'll let these calls go through, * Unlike the driver unloading example, we'll let these calls go through,
* since a plugin unloading is far more normal. * since a plugin unloading is far more normal.
*/ */
Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin(); Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin();
@ -702,7 +702,7 @@ void DBManager::OnPluginUnloaded(IPlugin *plugin)
plugin->SetProperty("DisallowDBThreads", NULL); plugin->SetProperty("DisallowDBThreads", NULL);
/* Run all of the think operations. /* Run all of the think operations.
* Unlike the driver unloading example, we'll let these calls go through, * Unlike the driver unloading example, we'll let these calls go through,
* since a plugin unloading is far more normal. * since a plugin unloading is far more normal.
*/ */
Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin(); Queue<IDBThreadOperation *>::iterator iter = m_ThinkQueue.begin();

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -31,8 +31,8 @@
#include <IPluginSys.h> #include <IPluginSys.h>
#include <stdarg.h> #include <stdarg.h>
#include "DebugReporter.h" #include "debugreporter.h"
#include "Logger.h" #include "logger.h"
#include <am-string.h> #include <am-string.h>
DebugReport g_DbgReporter; DebugReport g_DbgReporter;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -30,11 +30,11 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include "ExtensionSys.h" #include "extensionsys.h"
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include "common_logic.h" #include "common_logic.h"
#include "PluginSys.h" #include "pluginsys.h"
#include <am-utility.h> #include <am-utility.h>
#include <am-string.h> #include <am-string.h>
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
@ -120,8 +120,8 @@ CLocalExtension::CLocalExtension(const char *filename)
} }
/* First see if there is an engine specific build! */ /* First see if there is an engine specific build! */
g_pSM->BuildPath(Path_SM, g_pSM->BuildPath(Path_SM,
path, path,
PLATFORM_MAX_PATH, PLATFORM_MAX_PATH,
"extensions/auto.%s/%s." PLATFORM_LIB_EXT, "extensions/auto.%s/%s." PLATFORM_LIB_EXT,
filename, filename,
@ -253,10 +253,10 @@ bool CLocalExtension::Reload(char *error, size_t maxlength)
{ {
if (m_pLib == NULL) // FIXME: just load it instead? if (m_pLib == NULL) // FIXME: just load it instead?
return false; return false;
m_pAPI->OnExtensionUnload(); m_pAPI->OnExtensionUnload();
Unload(); Unload();
return Load(error, maxlength); return Load(error, maxlength);
} }
@ -282,7 +282,7 @@ bool CExtension::PerformAPICheck(char *error, size_t maxlength)
snprintf(error, maxlength, "No IExtensionInterface instance provided"); snprintf(error, maxlength, "No IExtensionInterface instance provided");
return false; return false;
} }
if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION) if (m_pAPI->GetExtensionVersion() > SMINTERFACE_EXTENSIONAPI_VERSION)
{ {
snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION); snprintf(error, maxlength, "Extension version is too new to load (%d, max is %d)", m_pAPI->GetExtensionVersion(), SMINTERFACE_EXTENSIONAPI_VERSION);
@ -574,7 +574,7 @@ void CExtensionManager::TryAutoload()
strcpy(&file[len - 9], ".ext"); strcpy(&file[len - 9], ".ext");
LoadAutoExtension(file); LoadAutoExtension(file);
pDir->NextEntry(); pDir->NextEntry();
} }
} }
@ -611,7 +611,7 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOn
{ {
logger->LogError("[SM] Unable to load extension \"%s\": %s", path, error); logger->LogError("[SM] Unable to load extension \"%s\": %s", path, error);
} }
p->SetError(error); p->SetError(error);
} }
@ -921,8 +921,8 @@ void CExtensionManager::MarkAllLoaded()
void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload) void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
{ {
/* This function doesn't really need to do anything now. We make sure the /* This function doesn't really need to do anything now. We make sure the
* other extension is loaded, but handling of dependencies is really done * other extension is loaded, but handling of dependencies is really done
* by the interface fetcher. * by the interface fetcher.
*/ */
if (required || autoload) if (required || autoload)
@ -998,13 +998,13 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
ke::SafeSprintf(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "", ke::SafeSprintf(path, sizeof(path), "%s%s%s", filename, !strstr(filename, ".ext") ? ".ext" : "",
!strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : ""); !strstr(filename, "." PLATFORM_LIB_EXT) ? "." PLATFORM_LIB_EXT : "");
if (FindExtensionByFile(path) != NULL) if (FindExtensionByFile(path) != NULL)
{ {
rootmenu->ConsolePrint("[SM] Extension %s is already loaded.", path); rootmenu->ConsolePrint("[SM] Extension %s is already loaded.", path);
return; return;
} }
if (LoadExtension(path, error, sizeof(error))) if (LoadExtension(path, error, sizeof(error)))
{ {
rootmenu->ConsolePrint("[SM] Loaded extension %s successfully.", path); rootmenu->ConsolePrint("[SM] Loaded extension %s successfully.", path);
@ -1012,7 +1012,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
{ {
rootmenu->ConsolePrint("[SM] Extension %s failed to load: %s", path, error); rootmenu->ConsolePrint("[SM] Extension %s failed to load: %s", path, error);
} }
return; return;
} }
else if (strcmp(cmd, "info") == 0) else if (strcmp(cmd, "info") == 0)
@ -1135,7 +1135,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
return; return;
} }
if (!pExt->IsLoaded() if (!pExt->IsLoaded()
|| (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size())) || (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
{ {
char filename[PLATFORM_MAX_PATH]; char filename[PLATFORM_MAX_PATH];
@ -1224,7 +1224,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
rootmenu->ConsolePrint("[SM] Usage: sm exts reload <#>"); rootmenu->ConsolePrint("[SM] Usage: sm exts reload <#>");
return; return;
} }
const char *arg = command->Arg(3); const char *arg = command->Arg(3);
unsigned int num = atoi(arg); unsigned int num = atoi(arg);
CExtension *pExt = FindByOrder(num); CExtension *pExt = FindByOrder(num);
@ -1234,14 +1234,14 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num); rootmenu->ConsolePrint("[SM] Extension number %d was not found.", num);
return; return;
} }
if (pExt->IsLoaded()) if (pExt->IsLoaded())
{ {
char filename[PLATFORM_MAX_PATH]; char filename[PLATFORM_MAX_PATH];
char error[255]; char error[255];
snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename()); snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
if (pExt->Reload(error, sizeof(error))) if (pExt->Reload(error, sizeof(error)))
{ {
rootmenu->ConsolePrint("[SM] Extension %s is now reloaded.", filename); rootmenu->ConsolePrint("[SM] Extension %s is now reloaded.", filename);
@ -1250,16 +1250,16 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand
{ {
rootmenu->ConsolePrint("[SM] Extension %s failed to reload: %s", filename, error); rootmenu->ConsolePrint("[SM] Extension %s failed to reload: %s", filename, error);
} }
return; return;
} }
else else
{ {
rootmenu->ConsolePrint("[SM] Extension %s is not loaded.", pExt->GetFilename()); rootmenu->ConsolePrint("[SM] Extension %s is not loaded.", pExt->GetFilename());
return; return;
} }
} }
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -39,8 +39,8 @@
#include "common_logic.h" #include "common_logic.h"
#include <IPluginSys.h> #include <IPluginSys.h>
#include <IRootConsoleMenu.h> #include <IRootConsoleMenu.h>
#include "NativeOwner.h" #include "nativeowner.h"
#include "ShareSys.h" #include "sharesys.h"
#include <bridge/include/IExtensionBridge.h> #include <bridge/include/IExtensionBridge.h>
class CPlayer; class CPlayer;
@ -56,7 +56,7 @@ struct sm_extnative_t
const sp_nativeinfo_t *info; const sp_nativeinfo_t *info;
}; };
class CExtension : class CExtension :
public IExtension, public IExtension,
public CNativeOwner public CNativeOwner
{ {
@ -135,7 +135,7 @@ public:
bool IsSameFile(const char *file); bool IsSameFile(const char *file);
}; };
class CExtensionManager : class CExtensionManager :
public IExtensionSys, public IExtensionSys,
public SMGlobalClass, public SMGlobalClass,
public IPluginsListener, public IPluginsListener,
@ -148,7 +148,7 @@ public: //SMGlobalClass
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModShutdown(); void OnSourceModShutdown();
public: //IExtensionManager public: //IExtensionManager
IExtension *LoadExtension(const char *path, IExtension *LoadExtension(const char *path,
char *error, char *error,
size_t maxlength); size_t maxlength);
bool UnloadExtension(IExtension *pExt); bool UnloadExtension(IExtension *pExt);

View File

@ -7,7 +7,7 @@
// This program is free software; you can redistribute it and/or modify it under // This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License, version 3.0, as published by the // the terms of the GNU General Public License, version 3.0, as published by the
// Free Software Foundation. // Free Software Foundation.
// //
// This program is distributed in the hope that it will be useful, but WITHOUT // This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -28,8 +28,8 @@
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "ForwardSys.h" #include "forwardsys.h"
#include "DebugReporter.h" #include "debugreporter.h"
#include "common_logic.h" #include "common_logic.h"
#include <bridge/include/IScriptManager.h> #include <bridge/include/IScriptManager.h>
#include <amtl/am-string.h> #include <amtl/am-string.h>
@ -52,7 +52,7 @@ IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned
{ {
va_list ap; va_list ap;
va_start(ap, types); va_start(ap, types);
CForward *fwd = CForward::CreateForward(name, et, num_params, types, ap); CForward *fwd = CForward::CreateForward(name, et, num_params, types, ap);
va_end(ap); va_end(ap);
@ -192,7 +192,7 @@ CForward *CForward::CreateForward(const char *name, ExecType et, unsigned int nu
{ {
return NULL; return NULL;
} }
if (types == NULL && num_params) if (types == NULL && num_params)
{ {
for (unsigned int i=0; i<num_params; i++) for (unsigned int i=0; i<num_params; i++)
@ -274,7 +274,7 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
} }
else if (type == Param_Float || type == Param_Cell) else if (type == Param_Float || type == Param_Cell)
{ {
err = func->PushCellByRef(&param->val); err = func->PushCellByRef(&param->val);
} }
else else
{ {
@ -291,14 +291,14 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
if (err != SP_ERROR_NONE) if (err != SP_ERROR_NONE)
{ {
g_DbgReporter.GenerateError(func->GetParentContext(), g_DbgReporter.GenerateError(func->GetParentContext(),
func->GetFunctionID(), func->GetFunctionID(),
err, err,
"Failed to push parameter while executing forward"); "Failed to push parameter while executing forward");
continue; continue;
} }
} }
/* Call the function and deal with the return value. */ /* Call the function and deal with the return value. */
if ((err=func->Execute(&cur_result)) == SP_ERROR_NONE) if ((err=func->Execute(&cur_result)) == SP_ERROR_NONE)
{ {

View File

@ -7,7 +7,7 @@
// This program is free software; you can redistribute it and/or modify it under // This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License, version 3.0, as published by the // the terms of the GNU General Public License, version 3.0, as published by the
// Free Software Foundation. // Free Software Foundation.
// //
// This program is distributed in the hope that it will be useful, but WITHOUT // This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -31,8 +31,8 @@
#include <IForwardSys.h> #include <IForwardSys.h>
#include <IPluginSys.h> #include <IPluginSys.h>
#include "common_logic.h" #include "common_logic.h"
#include "ISourceMod.h" #include <ISourceMod.h>
#include "ReentrantList.h" #include <ReentrantList.h>
typedef ReentrantList<IPluginFunction *>::iterator FuncIter; typedef ReentrantList<IPluginFunction *>::iterator FuncIter;
@ -62,10 +62,10 @@ public: //IChangeableForward
virtual bool AddFunction(IPluginContext *ctx, funcid_t index); virtual bool AddFunction(IPluginContext *ctx, funcid_t index);
virtual bool RemoveFunction(IPluginContext *ctx, funcid_t index); virtual bool RemoveFunction(IPluginContext *ctx, funcid_t index);
public: public:
static CForward *CreateForward(const char *name, static CForward *CreateForward(const char *name,
ExecType et, ExecType et,
unsigned int num_params, unsigned int num_params,
const ParamType *types, const ParamType *types,
va_list ap); va_list ap);
bool IsFunctionRegistered(IPluginFunction *func); bool IsFunctionRegistered(IPluginFunction *func);
private: private:
@ -96,22 +96,22 @@ protected:
int m_errstate; int m_errstate;
}; };
class CForwardManager : class CForwardManager :
public IForwardManager, public IForwardManager,
public IPluginsListener, public IPluginsListener,
public SMGlobalClass public SMGlobalClass
{ {
friend class CForward; friend class CForward;
public: //IForwardManager public: //IForwardManager
IForward *CreateForward(const char *name, IForward *CreateForward(const char *name,
ExecType et, ExecType et,
unsigned int num_params, unsigned int num_params,
const ParamType *types, const ParamType *types,
...); ...);
IChangeableForward *CreateForwardEx(const char *name, IChangeableForward *CreateForwardEx(const char *name,
ExecType et, ExecType et,
int num_params, int num_params,
const ParamType *types, const ParamType *types,
...); ...);
IForward *FindForward(const char *name, IChangeableForward **ifchng); IForward *FindForward(const char *name, IChangeableForward **ifchng);
void ReleaseForward(IForward *forward); void ReleaseForward(IForward *forward);

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -32,7 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sh_list.h> #include <sh_list.h>
#include <sh_string.h> #include <sh_string.h>
#include "GameConfigs.h" #include "gameconfigs.h"
#include "stringutil.h" #include "stringutil.h"
#include <IGameHelpers.h> #include <IGameHelpers.h>
#include <ILibrarySys.h> #include <ILibrarySys.h>
@ -41,7 +41,7 @@
#include <ISourceMod.h> #include <ISourceMod.h>
#include "common_logic.h" #include "common_logic.h"
#include "sm_crc32.h" #include "sm_crc32.h"
#include "MemoryUtils.h" #include "memoryutils.h"
#include <am-string.h> #include <am-string.h>
#include <bridge/include/ILogger.h> #include <bridge/include/ILogger.h>
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
@ -275,7 +275,7 @@ SMCResult CGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *n
if (strcmp(name, "server") != 0) if (strcmp(name, "server") != 0)
{ {
ke::SafeSprintf(error, sizeof(error), "Unrecognized library \"%s\"", name); ke::SafeSprintf(error, sizeof(error), "Unrecognized library \"%s\"", name);
} }
else if (!s_ServerBinCRC_Ok) else if (!s_ServerBinCRC_Ok)
{ {
FILE *fp; FILE *fp;
@ -506,7 +506,7 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
if (((strcmp(m_Game, "*") != 0) && strcmp(m_Game, "#default") != 0) if (((strcmp(m_Game, "*") != 0) && strcmp(m_Game, "#default") != 0)
&& (!m_Offsets.retrieve(m_offset))) && (!m_Offsets.retrieve(m_offset)))
{ {
logger->LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")", logger->LogError("[SM] Unable to find property %s.%s (file \"%s\") (mod \"%s\")",
m_Class, m_Class,
m_Prop, m_Prop,
m_CurFile, m_CurFile,
@ -559,8 +559,8 @@ SMCResult CGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
void *final_addr = NULL; void *final_addr = NULL;
if (addrInBase == NULL) if (addrInBase == NULL)
{ {
logger->LogError("[SM] Unrecognized library \"%s\" (gameconf \"%s\")", logger->LogError("[SM] Unrecognized library \"%s\" (gameconf \"%s\")",
s_TempSig.library, s_TempSig.library,
m_CurFile); m_CurFile);
} }
else if (s_TempSig.sig[0]) else if (s_TempSig.sig[0])
@ -831,7 +831,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
const char *msg = textparsers->GetSMCErrorString(err); const char *msg = textparsers->GetSMCErrorString(err);
logger->LogError("[SM] Error parsing master gameconf file \"%s\":", path); logger->LogError("[SM] Error parsing master gameconf file \"%s\":", path);
logger->LogError("[SM] Error %d on line %d, col %d: %s", logger->LogError("[SM] Error %d on line %d, col %d: %s",
err, err,
state.line, state.line,
state.col, state.col,
@ -867,7 +867,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
customDir->NextEntry(); customDir->NextEntry();
continue; continue;
} }
const char *curFile = customDir->GetEntryName(); const char *curFile = customDir->GetEntryName();
/* Only allow .txt files */ /* Only allow .txt files */
@ -875,7 +875,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength)
if (len > 4 && strcmp(&curFile[len-4], ".txt") != 0) if (len > 4 && strcmp(&curFile[len-4], ".txt") != 0)
{ {
customDir->NextEntry(); customDir->NextEntry();
continue; continue;
} }
ke::SafeSprintf(path, sizeof(path), "%s/custom/%s", m_File, curFile); ke::SafeSprintf(path, sizeof(path), "%s/custom/%s", m_File, curFile);
@ -919,7 +919,7 @@ bool CGameConfig::EnterFile(const char *file, char *error, size_t maxlength)
const char *msg = textparsers->GetSMCErrorString(err); const char *msg = textparsers->GetSMCErrorString(err);
logger->LogError("[SM] Error parsing gameconfig file \"%s\":", m_CurFile); logger->LogError("[SM] Error parsing gameconfig file \"%s\":", m_CurFile);
logger->LogError("[SM] Error %d on line %d, col %d: %s", logger->LogError("[SM] Error %d on line %d, col %d: %s",
err, err,
state.line, state.line,
state.col, state.col,
@ -1049,7 +1049,7 @@ void GameConfigManager::OnSourceModAllInitialized()
{ {
/* NOW initialize the game file */ /* NOW initialize the game file */
CGameConfig *pGameConf = (CGameConfig *)g_pGameConf; CGameConfig *pGameConf = (CGameConfig *)g_pGameConf;
char error[255]; char error[255];
if (!pGameConf->Reparse(error, sizeof(error))) if (!pGameConf->Reparse(error, sizeof(error)))
{ {

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,13 +29,13 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "HandleSys.h" #include "handlesys.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "common_logic.h" #include "common_logic.h"
#include "ShareSys.h" #include "sharesys.h"
#include "ExtensionSys.h" #include "extensionsys.h"
#include "PluginSys.h" #include "pluginsys.h"
#include <am-string.h> #include <am-string.h>
#include <bridge/include/ILogger.h> #include <bridge/include/ILogger.h>
@ -71,11 +71,11 @@ HandleSystem::~HandleSystem()
} }
HandleType_t HandleSystem::CreateType(const char *name, HandleType_t HandleSystem::CreateType(const char *name,
IHandleTypeDispatch *dispatch, IHandleTypeDispatch *dispatch,
HandleType_t parent, HandleType_t parent,
const TypeAccess *typeAccess, const TypeAccess *typeAccess,
const HandleAccess *hndlAccess, const HandleAccess *hndlAccess,
IdentityToken_t *ident, IdentityToken_t *ident,
HandleError *err) HandleError *err)
{ {
@ -202,7 +202,7 @@ HandleType_t HandleSystem::CreateType(const char *name,
} }
QHandleType *pType = &m_Types[index]; QHandleType *pType = &m_Types[index];
pType->dispatch = dispatch; pType->dispatch = dispatch;
if (name && name[0] != '\0') if (name && name[0] != '\0')
{ {
@ -265,9 +265,9 @@ HandleError HandleSystem::TryAllocHandle(unsigned int *handle)
return HandleError_None; return HandleError_None;
} }
HandleError HandleSystem::MakePrimHandle(HandleType_t type, HandleError HandleSystem::MakePrimHandle(HandleType_t type,
QHandle **in_pHandle, QHandle **in_pHandle,
unsigned int *in_index, unsigned int *in_index,
Handle_t *in_handle, Handle_t *in_handle,
IdentityToken_t *owner, IdentityToken_t *owner,
bool identity) bool identity)
@ -291,7 +291,7 @@ HandleError HandleSystem::MakePrimHandle(HandleType_t type,
} }
QHandle *pHandle = &m_Handles[handle]; QHandle *pHandle = &m_Handles[handle];
assert(pHandle->set == false); assert(pHandle->set == false);
if (++m_HSerial >= HANDLESYS_MAX_SERIALS) if (++m_HSerial >= HANDLESYS_MAX_SERIALS)
@ -322,7 +322,7 @@ HandleError HandleSystem::MakePrimHandle(HandleType_t type,
*in_index = handle; *in_index = handle;
*in_handle = hash; *in_handle = hash;
/* Decode the identity token /* Decode the identity token
* For now, we don't allow nested ownership * For now, we don't allow nested ownership
*/ */
if (owner && !identity) if (owner && !identity)
@ -365,10 +365,10 @@ void HandleSystem::SetTypeSecurityOwner(HandleType_t type, IdentityToken_t *pTok
m_Types[type].typeSec.ident = pToken; m_Types[type].typeSec.ident = pToken;
} }
Handle_t HandleSystem::CreateHandleInt(HandleType_t type, Handle_t HandleSystem::CreateHandleInt(HandleType_t type,
void *object, void *object,
const HandleSecurity *pSec, const HandleSecurity *pSec,
HandleError *err, HandleError *err,
const HandleAccess *pAccess, const HandleAccess *pAccess,
bool identity) bool identity)
{ {
@ -384,7 +384,7 @@ Handle_t HandleSystem::CreateHandleInt(HandleType_t type,
owner = NULL; owner = NULL;
} }
if (!type if (!type
|| type >= HANDLESYS_TYPEARRAY_SIZE || type >= HANDLESYS_TYPEARRAY_SIZE
|| m_Types[type].dispatch == NULL) || m_Types[type].dispatch == NULL)
{ {
@ -470,8 +470,8 @@ bool HandleSystem::TypeCheck(HandleType_t intype, HandleType_t outtype)
} }
HandleError HandleSystem::GetHandle(Handle_t handle, HandleError HandleSystem::GetHandle(Handle_t handle,
IdentityToken_t *ident, IdentityToken_t *ident,
QHandle **in_pHandle, QHandle **in_pHandle,
unsigned int *in_index, unsigned int *in_index,
bool ignoreFree) bool ignoreFree)
{ {
@ -647,7 +647,7 @@ HandleError HandleSystem::FreeHandle(QHandle *pHandle, unsigned int index)
{ {
if (pHandle->is_destroying) if (pHandle->is_destroying)
{ {
/* Someone tried to free this recursively. /* Someone tried to free this recursively.
* We'll just ignore this safely. * We'll just ignore this safely.
*/ */
return HandleError_None; return HandleError_None;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -34,7 +34,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <sm_platform.h> #include <sm_platform.h>
#include "LibrarySys.h" #include "librarysys.h"
#include <amtl/am-string.h> #include <amtl/am-string.h>
#include <amtl/os/am-path.h> #include <amtl/os/am-path.h>
#include <amtl/os/am-fsutil.h> #include <amtl/os/am-fsutil.h>
@ -299,7 +299,7 @@ size_t LibrarySystem::GetFileFromPath(char *buffer, size_t maxlength, const char
i <= length - 1; i <= length - 1;
i--) i--)
{ {
if (path[i] == '/' if (path[i] == '/'
#if defined PLATFORM_WINDOWS #if defined PLATFORM_WINDOWS
|| path[i] == '\\' || path[i] == '\\'
#endif #endif

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -31,7 +31,7 @@
#include <time.h> #include <time.h>
#include <cstdarg> #include <cstdarg>
#include "Logger.h" #include "logger.h"
#include <sourcemod_version.h> #include <sourcemod_version.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <am-string.h> #include <am-string.h>
@ -44,10 +44,10 @@ Logger g_Logger;
* :TODO: This should be creating the log folder if it doesn't exist * :TODO: This should be creating the log folder if it doesn't exist
*/ */
ConfigResult Logger::OnSourceModConfigChanged(const char *key, ConfigResult Logger::OnSourceModConfigChanged(const char *key,
const char *value, const char *value,
ConfigSource source, ConfigSource source,
char *error, char *error,
size_t maxlength) size_t maxlength)
{ {
if (strcasecmp(key, "Logging") == 0) if (strcasecmp(key, "Logging") == 0)
@ -73,7 +73,7 @@ ConfigResult Logger::OnSourceModConfigChanged(const char *key,
return ConfigResult_Accept; return ConfigResult_Accept;
} else if (strcasecmp(key, "LogMode") == 0) { } else if (strcasecmp(key, "LogMode") == 0) {
if (strcasecmp(value, "daily") == 0) if (strcasecmp(value, "daily") == 0)
{ {
m_Mode = LoggingMode_Daily; m_Mode = LoggingMode_Daily;
} else if (strcasecmp(value, "map") == 0) { } else if (strcasecmp(value, "map") == 0) {
@ -115,7 +115,7 @@ void Logger::_NewMapFile()
/* Append "Log file closed" to previous log file */ /* Append "Log file closed" to previous log file */
_CloseFile(); _CloseFile();
char _filename[256]; char _filename[256];
int i = 0; int i = 0;
@ -535,7 +535,7 @@ void Logger::LogFatal(const char *msg, ...)
void Logger::LogFatalEx(const char *msg, va_list ap) void Logger::LogFatalEx(const char *msg, va_list ap)
{ {
/* :TODO: make this print all pretty-like /* :TODO: make this print all pretty-like
* In fact, the pretty log printing function should be abstracted. * In fact, the pretty log printing function should be abstracted.
* It's already implemented twice which is bad. * It's already implemented twice which is bad.
*/ */

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -27,7 +27,7 @@
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
*/ */
#include "MemoryUtils.h" #include "memoryutils.h"
#ifdef PLATFORM_LINUX #ifdef PLATFORM_LINUX
#include <fcntl.h> #include <fcntl.h>
#include <link.h> #include <link.h>
@ -144,7 +144,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
return GetProcAddress((HMODULE)handle, symbol); return GetProcAddress((HMODULE)handle, symbol);
#elif defined PLATFORM_LINUX #elif defined PLATFORM_LINUX
struct link_map *dlmap; struct link_map *dlmap;
@ -165,7 +165,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
symtab_hdr = NULL; symtab_hdr = NULL;
strtab_hdr = NULL; strtab_hdr = NULL;
table = NULL; table = NULL;
/* See if we already have a symbol table for this library */ /* See if we already have a symbol table for this library */
for (size_t i = 0; i < m_SymTables.size(); i++) for (size_t i = 0; i < m_SymTables.size(); i++)
{ {
@ -280,7 +280,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
return symbol_entry ? symbol_entry->address : NULL; return symbol_entry ? symbol_entry->address : NULL;
#elif defined PLATFORM_APPLE #elif defined PLATFORM_APPLE
uintptr_t dlbase, linkedit_addr; uintptr_t dlbase, linkedit_addr;
uint32_t image_count; uint32_t image_count;
struct mach_header *file_hdr; struct mach_header *file_hdr;
@ -294,20 +294,20 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
LibSymbolTable *libtable; LibSymbolTable *libtable;
SymbolTable *table; SymbolTable *table;
Symbol *symbol_entry; Symbol *symbol_entry;
dlbase = 0; dlbase = 0;
image_count = m_ImageList->infoArrayCount; image_count = m_ImageList->infoArrayCount;
linkedit_hdr = NULL; linkedit_hdr = NULL;
symtab_hdr = NULL; symtab_hdr = NULL;
table = NULL; table = NULL;
/* Loop through mach-o images in process. /* Loop through mach-o images in process.
* We can skip index 0 since that is just the executable. * We can skip index 0 since that is just the executable.
*/ */
for (uint32_t i = 1; i < image_count; i++) for (uint32_t i = 1; i < image_count; i++)
{ {
const struct dyld_image_info &info = m_ImageList->infoArray[i]; const struct dyld_image_info &info = m_ImageList->infoArray[i];
/* "Load" each one until we get a matching handle */ /* "Load" each one until we get a matching handle */
void *h = dlopen(info.imageFilePath, RTLD_NOLOAD); void *h = dlopen(info.imageFilePath, RTLD_NOLOAD);
if (h == handle) if (h == handle)
@ -316,16 +316,16 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
dlclose(h); dlclose(h);
break; break;
} }
dlclose(h); dlclose(h);
} }
if (!dlbase) if (!dlbase)
{ {
/* Uh oh, we couldn't find a matching handle */ /* Uh oh, we couldn't find a matching handle */
return NULL; return NULL;
} }
/* See if we already have a symbol table for this library */ /* See if we already have a symbol table for this library */
for (size_t i = 0; i < m_SymTables.size(); i++) for (size_t i = 0; i < m_SymTables.size(); i++)
{ {
@ -336,7 +336,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
break; break;
} }
} }
/* If we don't have a symbol table for this library, then create one */ /* If we don't have a symbol table for this library, then create one */
if (table == NULL) if (table == NULL)
{ {
@ -347,20 +347,20 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
table = &libtable->table; table = &libtable->table;
m_SymTables.push_back(libtable); m_SymTables.push_back(libtable);
} }
/* See if the symbol is already cached in our table */ /* See if the symbol is already cached in our table */
symbol_entry = table->FindSymbol(symbol, strlen(symbol)); symbol_entry = table->FindSymbol(symbol, strlen(symbol));
if (symbol_entry != NULL) if (symbol_entry != NULL)
{ {
return symbol_entry->address; return symbol_entry->address;
} }
/* If symbol isn't in our table, then we have to locate it in memory */ /* If symbol isn't in our table, then we have to locate it in memory */
file_hdr = (struct mach_header *)dlbase; file_hdr = (struct mach_header *)dlbase;
loadcmds = (struct load_command *)(dlbase + sizeof(struct mach_header)); loadcmds = (struct load_command *)(dlbase + sizeof(struct mach_header));
loadcmd_count = file_hdr->ncmds; loadcmd_count = file_hdr->ncmds;
/* Loop through load commands until we find the ones for the symbol table */ /* Loop through load commands until we find the ones for the symbol table */
for (uint32_t i = 0; i < loadcmd_count; i++) for (uint32_t i = 0; i < loadcmd_count; i++)
{ {
@ -388,7 +388,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
/* Load commands are not of a fixed size which is why we add the size */ /* Load commands are not of a fixed size which is why we add the size */
loadcmds = (struct load_command *)((uintptr_t)loadcmds + loadcmds->cmdsize); loadcmds = (struct load_command *)((uintptr_t)loadcmds + loadcmds->cmdsize);
} }
if (!linkedit_hdr || !symtab_hdr || !symtab_hdr->symoff || !symtab_hdr->stroff) if (!linkedit_hdr || !symtab_hdr || !symtab_hdr->symoff || !symtab_hdr->stroff)
{ {
/* Uh oh, no symbol table */ /* Uh oh, no symbol table */
@ -399,7 +399,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
symtab = (struct nlist *)(linkedit_addr + symtab_hdr->symoff - linkedit_hdr->fileoff); symtab = (struct nlist *)(linkedit_addr + symtab_hdr->symoff - linkedit_hdr->fileoff);
strtab = (const char *)(linkedit_addr + symtab_hdr->stroff - linkedit_hdr->fileoff); strtab = (const char *)(linkedit_addr + symtab_hdr->stroff - linkedit_hdr->fileoff);
symbol_count = symtab_hdr->nsyms; symbol_count = symtab_hdr->nsyms;
/* Iterate symbol table starting from the position we were at last time */ /* Iterate symbol table starting from the position we were at last time */
for (uint32_t i = libtable->last_pos; i < symbol_count; i++) for (uint32_t i = libtable->last_pos; i < symbol_count; i++)
{ {
@ -407,13 +407,13 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
/* Ignore the prepended underscore on all symbols, so +1 here */ /* Ignore the prepended underscore on all symbols, so +1 here */
const char *sym_name = strtab + sym.n_un.n_strx + 1; const char *sym_name = strtab + sym.n_un.n_strx + 1;
Symbol *cur_sym; Symbol *cur_sym;
/* Skip symbols that are undefined */ /* Skip symbols that are undefined */
if (sym.n_sect == NO_SECT) if (sym.n_sect == NO_SECT)
{ {
continue; continue;
} }
/* Caching symbols as we go along */ /* Caching symbols as we go along */
cur_sym = table->InternSymbol(sym_name, strlen(sym_name), (void *)(dlbase + sym.n_value)); cur_sym = table->InternSymbol(sym_name, strlen(sym_name), (void *)(dlbase + sym.n_value));
if (strcmp(symbol, sym_name) == 0) if (strcmp(symbol, sym_name) == 0)
@ -423,7 +423,7 @@ void *MemoryUtils::ResolveSymbol(void *handle, const char *symbol)
break; break;
} }
} }
return symbol_entry ? symbol_entry->address : NULL; return symbol_entry ? symbol_entry->address : NULL;
#endif #endif
@ -540,7 +540,7 @@ bool MemoryUtils::GetLibraryInfo(const void *libPtr, DynLibInfo &lib)
if (hdr.p_type == PT_LOAD && hdr.p_flags == (PF_X|PF_R)) if (hdr.p_type == PT_LOAD && hdr.p_flags == (PF_X|PF_R))
{ {
/* From glibc, elf/dl-load.c: /* From glibc, elf/dl-load.c:
* c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1) * c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1)
* & ~(GLRO(dl_pagesize) - 1)); * & ~(GLRO(dl_pagesize) - 1));
* *
* In glibc, the segment file size is aligned up to the nearest page size and * In glibc, the segment file size is aligned up to the nearest page size and
@ -592,15 +592,15 @@ bool MemoryUtils::GetLibraryInfo(const void *libPtr, DynLibInfo &lib)
cmd_count = file->ncmds; cmd_count = file->ncmds;
seg = (struct segment_command *)(baseAddr + sizeof(struct mach_header)); seg = (struct segment_command *)(baseAddr + sizeof(struct mach_header));
/* Add up memory sizes of mapped segments */ /* Add up memory sizes of mapped segments */
for (uint32_t i = 0; i < cmd_count; i++) for (uint32_t i = 0; i < cmd_count; i++)
{ {
if (seg->cmd == LC_SEGMENT) if (seg->cmd == LC_SEGMENT)
{ {
lib.memorySize += seg->vmsize; lib.memorySize += seg->vmsize;
} }
seg = (struct segment_command *)((uintptr_t)seg + seg->cmdsize); seg = (struct segment_command *)((uintptr_t)seg + seg->cmdsize);
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -28,9 +28,9 @@
* *
* Version: $Id$ * Version: $Id$
*/ */
#include "NativeOwner.h" #include "nativeowner.h"
#include "ShareSys.h" #include "sharesys.h"
#include "PluginSys.h" #include "pluginsys.h"
CNativeOwner::CNativeOwner() : m_nMarkSerial(0) CNativeOwner::CNativeOwner() : m_nMarkSerial(0)
{ {

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -36,7 +36,7 @@
#include <am-linkedlist.h> #include <am-linkedlist.h>
#include <am-vector.h> #include <am-vector.h>
#include "common_logic.h" #include "common_logic.h"
#include "Native.h" #include "native.h"
#include <bridge/include/IScriptManager.h> #include <bridge/include/IScriptManager.h>
struct Native; struct Native;
@ -46,7 +46,7 @@ using namespace SourceMod;
struct WeakNative struct WeakNative
{ {
WeakNative(IPlugin *plugin, uint32_t index) : WeakNative(IPlugin *plugin, uint32_t index) :
pl(plugin), idx(index) pl(plugin), idx(index)
{ {
pl = plugin; pl = plugin;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -30,8 +30,8 @@
*/ */
#include "common_logic.h" #include "common_logic.h"
#include "PhraseCollection.h" #include "phrasecollection.h"
#include "Translator.h" #include "translator.h"
#include "sprintf.h" #include "sprintf.h"
#include <am-string.h> #include <am-string.h>
@ -57,7 +57,7 @@ IPhraseFile *CPhraseCollection::AddPhraseFile(const char *filename)
/* No compat shim here. The user should have read the doc. */ /* No compat shim here. The user should have read the doc. */
ke::SafeSprintf(full_name, sizeof(full_name), "%s.txt", filename); ke::SafeSprintf(full_name, sizeof(full_name), "%s.txt", filename);
fid = g_Translator.FindOrAddPhraseFile(full_name); fid = g_Translator.FindOrAddPhraseFile(full_name);
pFile = g_Translator.GetFileByIndex(fid); pFile = g_Translator.GetFileByIndex(fid);

View File

@ -31,18 +31,18 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "PluginSys.h" #include "pluginsys.h"
#include "ShareSys.h" #include "sharesys.h"
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <IHandleSys.h> #include <IHandleSys.h>
#include <IForwardSys.h> #include <IForwardSys.h>
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include "ExtensionSys.h" #include "extensionsys.h"
#include "GameConfigs.h" #include "gameconfigs.h"
#include "common_logic.h" #include "common_logic.h"
#include "Translator.h" #include "translator.h"
#include "Logger.h" #include "logger.h"
#include "frame_tasks.h" #include "frame_tasks.h"
#include <am-string.h> #include <am-string.h>
#include <bridge/include/IVEngineServerBridge.h> #include <bridge/include/IVEngineServerBridge.h>
@ -694,7 +694,7 @@ void CPlugin::DropEverything()
* to centralize that here, i'm omitting it for now. Thus, * to centralize that here, i'm omitting it for now. Thus,
* the code below to walk the plugins list will suffice. * the code below to walk the plugins list will suffice.
*/ */
/* Other plugins could be holding weak references that were /* Other plugins could be holding weak references that were
* added by us. We need to clean all of those up now. * added by us. We need to clean all of those up now.
*/ */
@ -767,7 +767,7 @@ CPluginManager::CPluginManager()
m_AllPluginsLoaded = false; m_AllPluginsLoaded = false;
m_MyIdent = NULL; m_MyIdent = NULL;
m_LoadingLocked = false; m_LoadingLocked = false;
m_bBlockBadPlugins = true; m_bBlockBadPlugins = true;
} }
@ -1186,12 +1186,12 @@ CPlugin *CPluginManager::CompileAndPrep(const char *path)
bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin) bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin)
{ {
unsigned char *pCodeHash = pPlugin->GetRuntime()->GetCodeHash(); unsigned char *pCodeHash = pPlugin->GetRuntime()->GetCodeHash();
char codeHashBuf[40]; char codeHashBuf[40];
ke::SafeSprintf(codeHashBuf, 40, "plugin_"); ke::SafeSprintf(codeHashBuf, 40, "plugin_");
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
ke::SafeSprintf(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]); ke::SafeSprintf(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]);
const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf); const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf);
if (!bulletinUrl) if (!bulletinUrl)
return true; return true;
@ -1253,7 +1253,7 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
pListener = (*iter); pListener = (*iter);
pListener->OnPluginLoaded(pPlugin); pListener->OnPluginLoaded(pPlugin);
} }
/* Tell this plugin to finish initializing itself */ /* Tell this plugin to finish initializing itself */
pPlugin->Call_OnPluginStart(); pPlugin->Call_OnPluginStart();
@ -1294,7 +1294,7 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
/* :TODO: optimize? does this even matter? */ /* :TODO: optimize? does this even matter? */
pPlugin->GetPhrases()->AddPhraseFile("core.phrases"); pPlugin->GetPhrases()->AddPhraseFile("core.phrases");
/* Go through all other already loaded plugins and tell this plugin, that their libraries are loaded */ /* Go through all other already loaded plugins and tell this plugin, that their libraries are loaded */
for (List<CPlugin *>::iterator pl_iter = m_plugins.begin(); pl_iter != m_plugins.end(); pl_iter++) for (List<CPlugin *>::iterator pl_iter = m_plugins.begin(); pl_iter != m_plugins.end(); pl_iter++)
{ {
@ -1434,7 +1434,7 @@ void CPluginManager::UnloadPluginImpl(CPlugin *pPlugin)
pListener = (*iter); pListener = (*iter);
pListener->OnPluginDestroyed(pPlugin); pListener->OnPluginDestroyed(pPlugin);
} }
/* Tell the plugin to delete itself */ /* Tell the plugin to delete itself */
delete pPlugin; delete pPlugin;
} }
@ -1722,7 +1722,7 @@ void CPluginManager::OnSourceModAllInitialized()
rootmenu->AddRootConsoleCommand3("plugins", "Manage Plugins", this); rootmenu->AddRootConsoleCommand3("plugins", "Manage Plugins", this);
g_ShareSys.AddInterface(NULL, GetOldAPI()); g_ShareSys.AddInterface(NULL, GetOldAPI());
m_pOnLibraryAdded = forwardsys->CreateForward("OnLibraryAdded", ET_Ignore, 1, NULL, Param_String); m_pOnLibraryAdded = forwardsys->CreateForward("OnLibraryAdded", ET_Ignore, 1, NULL, Param_String);
m_pOnLibraryRemoved = forwardsys->CreateForward("OnLibraryRemoved", ET_Ignore, 1, NULL, Param_String); m_pOnLibraryRemoved = forwardsys->CreateForward("OnLibraryRemoved", ET_Ignore, 1, NULL, Param_String);
} }
@ -1736,7 +1736,7 @@ void CPluginManager::OnSourceModShutdown()
handlesys->RemoveType(g_PluginType, m_MyIdent); handlesys->RemoveType(g_PluginType, m_MyIdent);
g_ShareSys.DestroyIdentType(g_PluginIdent); g_ShareSys.DestroyIdentType(g_PluginIdent);
g_ShareSys.DestroyIdentity(m_MyIdent); g_ShareSys.DestroyIdentity(m_MyIdent);
forwardsys->ReleaseForward(m_pOnLibraryAdded); forwardsys->ReleaseForward(m_pOnLibraryAdded);
forwardsys->ReleaseForward(m_pOnLibraryRemoved); forwardsys->ReleaseForward(m_pOnLibraryRemoved);
} }
@ -2130,14 +2130,14 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
{ {
rootmenu->ConsolePrint(" Timestamp: %s", pl->m_DateTime); rootmenu->ConsolePrint(" Timestamp: %s", pl->m_DateTime);
} }
unsigned char *pCodeHash = pl->m_pRuntime->GetCodeHash(); unsigned char *pCodeHash = pl->m_pRuntime->GetCodeHash();
unsigned char *pDataHash = pl->m_pRuntime->GetDataHash(); unsigned char *pDataHash = pl->m_pRuntime->GetDataHash();
char combinedHash[33]; char combinedHash[33];
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
ke::SafeSprintf(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]); ke::SafeSprintf(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]);
rootmenu->ConsolePrint(" Hash: %s", combinedHash); rootmenu->ConsolePrint(" Hash: %s", combinedHash);
} }
else else
@ -2314,7 +2314,7 @@ void CPluginManager::_SetPauseState(CPlugin *pl, bool paused)
{ {
pListener = (*iter); pListener = (*iter);
pListener->OnPluginPauseChange(pl, paused); pListener->OnPluginPauseChange(pl, paused);
} }
} }
void CPluginManager::AddFunctionsToForward(const char *name, IChangeableForward *pForward) void CPluginManager::AddFunctionsToForward(const char *name, IChangeableForward *pForward)
@ -2434,7 +2434,7 @@ SMPlugin *CPluginManager::FindPluginByConsoleArg(const char *arg)
int id; int id;
char *end; char *end;
CPlugin *pl; CPlugin *pl;
id = strtol(arg, &end, 10); id = strtol(arg, &end, 10);
if (*end == '\0') if (*end == '\0')

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -46,11 +46,11 @@
#include <IRootConsoleMenu.h> #include <IRootConsoleMenu.h>
#include <sm_stringhashmap.h> #include <sm_stringhashmap.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
#include "ITranslator.h" #include <ITranslator.h>
#include "IGameConfigs.h" #include <IGameConfigs.h>
#include "NativeOwner.h" #include "nativeowner.h"
#include "ShareSys.h" #include "sharesys.h"
#include "PhraseCollection.h" #include "phrasecollection.h"
#include <am-string.h> #include <am-string.h>
#include <bridge/include/IScriptManager.h> #include <bridge/include/IScriptManager.h>
#include <am-function.h> #include <am-function.h>
@ -62,12 +62,12 @@ using namespace SourceHook;
/** /**
* NOTES: * NOTES:
* *
* UPDATE 2008-03-11: These comments are horribly out of date. They paint a good overall * UPDATE 2008-03-11: These comments are horribly out of date. They paint a good overall
* picture of how PluginSys works, but things like dependencies and fake natives have * picture of how PluginSys works, but things like dependencies and fake natives have
* complicated things quite a bit. * complicated things quite a bit.
* *
* Currently this system needs a lot of work but it's good skeletally. Plugin creation * Currently this system needs a lot of work but it's good skeletally. Plugin creation
* is done without actually compiling anything. This is done by Load functions in the * is done without actually compiling anything. This is done by Load functions in the
* manager. This will need a rewrite when we add context switching. * manager. This will need a rewrite when we add context switching.
* *
* The plugin object itself has a few things to note. The most important is that it stores * The plugin object itself has a few things to note. The most important is that it stores
@ -78,8 +78,8 @@ using namespace SourceHook;
* However, the state itself being set prevents any runtime action. * However, the state itself being set prevents any runtime action.
* Plugin_BadLoad --> The plugin failed to load entirely and nothing can be done to save it. * Plugin_BadLoad --> The plugin failed to load entirely and nothing can be done to save it.
* *
* If a plugin fails to load externally, it is never added to the internal tracker. However, * If a plugin fails to load externally, it is never added to the internal tracker. However,
* plugins that failed to load from the internal loading mechanism are always tracked. This * plugins that failed to load from the internal loading mechanism are always tracked. This
* allows users to see which automatically loaded plugins failed, and makes the interface a bit * allows users to see which automatically loaded plugins failed, and makes the interface a bit
* more flexible. * more flexible.
* *
@ -124,7 +124,7 @@ enum APLRes
APLRes_SilentFailure APLRes_SilentFailure
}; };
class CPlugin : class CPlugin :
public SMPlugin, public SMPlugin,
public CNativeOwner public CNativeOwner
{ {
@ -169,7 +169,7 @@ public:
* Creates a plugin object with default values. * Creates a plugin object with default values.
* If an error buffer is specified, and an error occurs, the error will be copied to the buffer * If an error buffer is specified, and an error occurs, the error will be copied to the buffer
* and NULL will be returned. * and NULL will be returned.
* If an error buffer is not specified, the error will be copied to an internal buffer and * If an error buffer is not specified, the error will be copied to an internal buffer and
* a valid (but error-stated) CPlugin will be returned. * a valid (but error-stated) CPlugin will be returned.
*/ */
static CPlugin *Create(const char *file); static CPlugin *Create(const char *file);
@ -305,7 +305,7 @@ private:
ke::AString info_url_; ke::AString info_url_;
}; };
class CPluginManager : class CPluginManager :
public IScriptManager, public IScriptManager,
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch, public IHandleTypeDispatch,
@ -334,7 +334,7 @@ public:
}; };
friend class CPluginManager::CPluginIterator; friend class CPluginManager::CPluginIterator;
public: //IScriptManager public: //IScriptManager
IPlugin *LoadPlugin(const char *path, IPlugin *LoadPlugin(const char *path,
bool debug, bool debug,
PluginType type, PluginType type,
char error[], char error[],
@ -393,12 +393,12 @@ public:
* csdm/ban csdm/ban * csdm/ban csdm/ban
* ban csdm/ban * ban csdm/ban
* csdm/ban optional/csdm/ban * csdm/ban optional/csdm/ban
* All of these will return true for an alias match. * All of these will return true for an alias match.
* Wildcards are allowed in the filename. * Wildcards are allowed in the filename.
*/ */
bool TestAliasMatch(const char *alias, const char *localdir); bool TestAliasMatch(const char *alias, const char *localdir);
/** /**
* Returns whether anything loaded will be a late load. * Returns whether anything loaded will be a late load.
*/ */
bool IsLateLoadTime() const; bool IsLateLoadTime() const;
@ -415,13 +415,13 @@ public:
int GetOrderOfPlugin(IPlugin *pl); int GetOrderOfPlugin(IPlugin *pl);
/** /**
* Internal version of FindPluginByContext() * Internal version of FindPluginByContext()
*/ */
CPlugin *GetPluginByCtx(const sp_context_t *ctx); CPlugin *GetPluginByCtx(const sp_context_t *ctx);
/** /**
* Gets status text for a status code * Gets status text for a status code
*/ */
const char *GetStatusText(PluginStatus status); const char *GetStatusText(PluginStatus status);
@ -517,10 +517,10 @@ private:
List<FakeNative *> m_Natives; List<FakeNative *> m_Natives;
bool m_LoadingLocked; bool m_LoadingLocked;
// Config // Config
bool m_bBlockBadPlugins; bool m_bBlockBadPlugins;
// Forwards // Forwards
IForward *m_pOnLibraryAdded; IForward *m_pOnLibraryAdded;
IForward *m_pOnLibraryRemoved; IForward *m_pOnLibraryRemoved;

View File

@ -1,191 +1,191 @@
// vim: set ts=4 sw=4 tw=99 noet : // vim: set ts=4 sw=4 tw=99 noet :
// ============================================================================= // =============================================================================
// SourceMod // SourceMod
// Copyright (C) 2004-2014 AlliedModders LLC. All rights reserved. // Copyright (C) 2004-2014 AlliedModders LLC. All rights reserved.
// ============================================================================= // =============================================================================
// //
// This program is free software; you can redistribute it and/or modify it under // This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License, version 3.0, as published by the // the terms of the GNU General Public License, version 3.0, as published by the
// Free Software Foundation. // Free Software Foundation.
// //
// This program is distributed in the hope that it will be useful, but WITHOUT // This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details. // details.
// //
// You should have received a copy of the GNU General Public License along with // You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>. // this program. If not, see <http://www.gnu.org/licenses/>.
// //
// As a special exception, AlliedModders LLC gives you permission to link the // As a special exception, AlliedModders LLC gives you permission to link the
// code of this program (as well as its derivative works) to "Half-Life 2," the // code of this program (as well as its derivative works) to "Half-Life 2," the
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software // "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
// by the Valve Corporation. You must obey the GNU General Public License in // by the Valve Corporation. You must obey the GNU General Public License in
// all respects for all other code used. Additionally, AlliedModders LLC grants // all respects for all other code used. Additionally, AlliedModders LLC grants
// this exception to all derivative works. AlliedModders LLC defines further // this exception to all derivative works. AlliedModders LLC defines further
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), // exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
// or <http://www.sourcemod.net/license.php>. // or <http://www.sourcemod.net/license.php>.
#include "ProfileTools.h" #include "profiletools.h"
#include <stdarg.h> #include <stdarg.h>
#include <am-string.h> #include <am-string.h>
ProfileToolManager g_ProfileToolManager; ProfileToolManager g_ProfileToolManager;
ProfileToolManager::ProfileToolManager() ProfileToolManager::ProfileToolManager()
: active_(nullptr), : active_(nullptr),
default_(nullptr) default_(nullptr)
{ {
} }
void void
ProfileToolManager::OnSourceModAllInitialized() ProfileToolManager::OnSourceModAllInitialized()
{ {
rootmenu->AddRootConsoleCommand3("prof", "Profiling", this); rootmenu->AddRootConsoleCommand3("prof", "Profiling", this);
} }
void void
ProfileToolManager::OnSourceModShutdown() ProfileToolManager::OnSourceModShutdown()
{ {
rootmenu->RemoveRootConsoleCommand("prof", this); rootmenu->RemoveRootConsoleCommand("prof", this);
} }
IProfilingTool * IProfilingTool *
ProfileToolManager::FindToolByName(const char *name) ProfileToolManager::FindToolByName(const char *name)
{ {
for (size_t i = 0; i < tools_.length(); i++) { for (size_t i = 0; i < tools_.length(); i++) {
if (strcmp(tools_[i]->Name(), name) == 0) if (strcmp(tools_[i]->Name(), name) == 0)
return tools_[i]; return tools_[i];
} }
return nullptr; return nullptr;
} }
static void static void
render_help(const char *fmt, ...) render_help(const char *fmt, ...)
{ {
char buffer[2048]; char buffer[2048];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap); ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap); va_end(ap);
rootmenu->ConsolePrint("%s", buffer); rootmenu->ConsolePrint("%s", buffer);
} }
void void
ProfileToolManager::StartFromConsole(IProfilingTool *tool) ProfileToolManager::StartFromConsole(IProfilingTool *tool)
{ {
if (active_) { if (active_) {
rootmenu->ConsolePrint("A profile is already active using %s.", active_->Name()); rootmenu->ConsolePrint("A profile is already active using %s.", active_->Name());
return; return;
} }
active_ = tool; active_ = tool;
if (!active_->Start()) { if (!active_->Start()) {
rootmenu->ConsolePrint("Failed to attach to or start %s.", active_->Name()); rootmenu->ConsolePrint("Failed to attach to or start %s.", active_->Name());
active_ = nullptr; active_ = nullptr;
return; return;
} }
g_pSourcePawn2->SetProfilingTool(active_); g_pSourcePawn2->SetProfilingTool(active_);
g_pSourcePawn2->EnableProfiling(); g_pSourcePawn2->EnableProfiling();
rootmenu->ConsolePrint("Started profiling with %s.", active_->Name()); rootmenu->ConsolePrint("Started profiling with %s.", active_->Name());
default_ = active_; default_ = active_;
} }
void void
ProfileToolManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *args) ProfileToolManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *args)
{ {
if (tools_.length() == 0) { if (tools_.length() == 0) {
rootmenu->ConsolePrint("No profiling tools are enabled."); rootmenu->ConsolePrint("No profiling tools are enabled.");
return; return;
} }
if (args->ArgC() >= 3) { if (args->ArgC() >= 3) {
cmdname = args->Arg(2); cmdname = args->Arg(2);
if (strcmp(cmdname, "list") == 0) { if (strcmp(cmdname, "list") == 0) {
rootmenu->ConsolePrint("Profiling tools:"); rootmenu->ConsolePrint("Profiling tools:");
for (size_t i = 0; i < tools_.length(); i++) { for (size_t i = 0; i < tools_.length(); i++) {
rootmenu->DrawGenericOption(tools_[i]->Name(), tools_[i]->Description()); rootmenu->DrawGenericOption(tools_[i]->Name(), tools_[i]->Description());
} }
return; return;
} }
if (strcmp(cmdname, "stop") == 0) { if (strcmp(cmdname, "stop") == 0) {
if (!active_) { if (!active_) {
rootmenu->ConsolePrint("No profiler is active."); rootmenu->ConsolePrint("No profiler is active.");
return; return;
} }
g_pSourcePawn2->DisableProfiling(); g_pSourcePawn2->DisableProfiling();
g_pSourcePawn2->SetProfilingTool(nullptr); g_pSourcePawn2->SetProfilingTool(nullptr);
active_->Stop(render_help); active_->Stop(render_help);
active_ = nullptr; active_ = nullptr;
return; return;
} }
if (strcmp(cmdname, "dump") == 0) { if (strcmp(cmdname, "dump") == 0) {
if (active_) { if (active_) {
// if we have an active profiler, dump it // if we have an active profiler, dump it
active_->Dump(); active_->Dump();
return; return;
} }
} }
if (args->ArgC() < 4) { if (args->ArgC() < 4) {
if (strcmp(cmdname, "start") == 0) { if (strcmp(cmdname, "start") == 0) {
if (!default_) { if (!default_) {
default_ = FindToolByName("vprof"); default_ = FindToolByName("vprof");
if (!default_ && tools_.length() > 0) if (!default_ && tools_.length() > 0)
default_ = tools_[0]; default_ = tools_[0];
if (!default_) { if (!default_) {
rootmenu->ConsolePrint("Could not find any profiler to use."); rootmenu->ConsolePrint("Could not find any profiler to use.");
return; return;
} }
} }
StartFromConsole(default_); StartFromConsole(default_);
return; return;
} }
} }
if (args->ArgC() < 4) { if (args->ArgC() < 4) {
rootmenu->ConsolePrint("You must specify a profiling tool name."); rootmenu->ConsolePrint("You must specify a profiling tool name.");
return; return;
} }
const char *toolname = args->Arg(3); const char *toolname = args->Arg(3);
if (strcmp(cmdname, "start") == 0) { if (strcmp(cmdname, "start") == 0) {
IProfilingTool *tool = FindToolByName(toolname); IProfilingTool *tool = FindToolByName(toolname);
if (!tool) { if (!tool) {
rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname); rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname);
return; return;
} }
StartFromConsole(tool); StartFromConsole(tool);
return; return;
} }
if (strcmp(cmdname, "dump") == 0) { if (strcmp(cmdname, "dump") == 0) {
IProfilingTool *tool = FindToolByName(toolname); IProfilingTool *tool = FindToolByName(toolname);
if (!tool) { if (!tool) {
rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname); rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname);
return; return;
} }
tool->Dump(); tool->Dump();
return; return;
} }
if (strcmp(cmdname, "help") == 0) { if (strcmp(cmdname, "help") == 0) {
IProfilingTool *tool = FindToolByName(toolname); IProfilingTool *tool = FindToolByName(toolname);
if (!tool) { if (!tool) {
rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname); rootmenu->ConsolePrint("No tool with the name \"%s\" was found.", toolname);
return; return;
} }
tool->RenderHelp(render_help); tool->RenderHelp(render_help);
return; return;
} }
} }
rootmenu->ConsolePrint("Profiling commands:"); rootmenu->ConsolePrint("Profiling commands:");
rootmenu->DrawGenericOption("list", "List all available profiling tools."); rootmenu->DrawGenericOption("list", "List all available profiling tools.");
rootmenu->DrawGenericOption("start", "Start a profile with a given tool."); rootmenu->DrawGenericOption("start", "Start a profile with a given tool.");
rootmenu->DrawGenericOption("stop", "Stop the current profile session."); rootmenu->DrawGenericOption("stop", "Stop the current profile session.");
rootmenu->DrawGenericOption("dump", "Dumps output from the current profile session."); rootmenu->DrawGenericOption("dump", "Dumps output from the current profile session.");
rootmenu->DrawGenericOption("help", "Display help text for a profiler."); rootmenu->DrawGenericOption("help", "Display help text for a profiler.");
} }

View File

@ -1,289 +1,289 @@
// vim: set ts=4 sw=4 tw=99 noet : // vim: set ts=4 sw=4 tw=99 noet :
// ============================================================================= // =============================================================================
// SourceMod // SourceMod
// Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. // Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
// ============================================================================= // =============================================================================
// //
// This program is free software; you can redistribute it and/or modify it under // This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License, version 3.0, as published by the // the terms of the GNU General Public License, version 3.0, as published by the
// Free Software Foundation. // Free Software Foundation.
// //
// This program is distributed in the hope that it will be useful, but WITHOUT // This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details. // details.
// //
// You should have received a copy of the GNU General Public License along with // You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>. // this program. If not, see <http://www.gnu.org/licenses/>.
// //
// As a special exception, AlliedModders LLC gives you permission to link the // As a special exception, AlliedModders LLC gives you permission to link the
// code of this program (as well as its derivative works) to "Half-Life 2," the // code of this program (as well as its derivative works) to "Half-Life 2," the
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software // "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
// by the Valve Corporation. You must obey the GNU General Public License in // by the Valve Corporation. You must obey the GNU General Public License in
// all respects for all other code used. Additionally, AlliedModders LLC grants // all respects for all other code used. Additionally, AlliedModders LLC grants
// this exception to all derivative works. AlliedModders LLC defines further // this exception to all derivative works. AlliedModders LLC defines further
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), // exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
// or <http://www.sourcemod.net/license.php>. // or <http://www.sourcemod.net/license.php>.
#include "RootConsoleMenu.h" #include "rootconsolemenu.h"
#include <amtl/am-string.h> #include <amtl/am-string.h>
#include <sourcemod_version.h> #include <sourcemod_version.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
#include "HandleSys.h" #include "handlesys.h"
RootConsoleMenu g_RootMenu; RootConsoleMenu g_RootMenu;
// Some top-level commands that are just thrown in here. // Some top-level commands that are just thrown in here.
static bool sm_dump_handles(int client, const ICommandArgs *args); static bool sm_dump_handles(int client, const ICommandArgs *args);
RootConsoleMenu::RootConsoleMenu() RootConsoleMenu::RootConsoleMenu()
{ {
} }
RootConsoleMenu::~RootConsoleMenu() RootConsoleMenu::~RootConsoleMenu()
{ {
List<ConsoleEntry *>::iterator iter; List<ConsoleEntry *>::iterator iter;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{ {
delete (*iter); delete (*iter);
} }
m_Menu.clear(); m_Menu.clear();
} }
void RootConsoleMenu::OnSourceModStartup(bool late) void RootConsoleMenu::OnSourceModStartup(bool late)
{ {
AddRootConsoleCommand3("version", "Display version information", this); AddRootConsoleCommand3("version", "Display version information", this);
AddRootConsoleCommand3("credits", "Display credits listing", this); AddRootConsoleCommand3("credits", "Display credits listing", this);
bridge->DefineCommand("sm_dump_handles", "Dumps Handle usage to a file for finding Handle leaks", bridge->DefineCommand("sm_dump_handles", "Dumps Handle usage to a file for finding Handle leaks",
sm_dump_handles); sm_dump_handles);
bridge->DefineCommand("sm", "SourceMod Menu", [this] (int client, const ICommandArgs *args) -> bool { bridge->DefineCommand("sm", "SourceMod Menu", [this] (int client, const ICommandArgs *args) -> bool {
GotRootCmd(args); GotRootCmd(args);
return true; return true;
}); });
} }
void RootConsoleMenu::OnSourceModAllInitialized() void RootConsoleMenu::OnSourceModAllInitialized()
{ {
sharesys->AddInterface(NULL, this); sharesys->AddInterface(NULL, this);
} }
void RootConsoleMenu::OnSourceModShutdown() void RootConsoleMenu::OnSourceModShutdown()
{ {
RemoveRootConsoleCommand("credits", this); RemoveRootConsoleCommand("credits", this);
RemoveRootConsoleCommand("version", this); RemoveRootConsoleCommand("version", this);
} }
void RootConsoleMenu::ConsolePrint(const char *fmt, ...) void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
bridge->ConsolePrintVa(fmt, ap); bridge->ConsolePrintVa(fmt, ap);
va_end(ap); va_end(ap);
} }
bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler) bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{ {
return false; return false;
} }
bool RootConsoleMenu::AddRootConsoleCommand2(const char *cmd, const char *text, IRootConsoleCommand *pHandler) bool RootConsoleMenu::AddRootConsoleCommand2(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{ {
return false; return false;
} }
bool RootConsoleMenu::AddRootConsoleCommand3(const char *cmd, bool RootConsoleMenu::AddRootConsoleCommand3(const char *cmd,
const char *text, const char *text,
IRootConsoleCommand *pHandler) IRootConsoleCommand *pHandler)
{ {
if (m_Commands.contains(cmd)) if (m_Commands.contains(cmd))
return false; return false;
/* Sort this into the menu */ /* Sort this into the menu */
List<ConsoleEntry *>::iterator iter = m_Menu.begin(); List<ConsoleEntry *>::iterator iter = m_Menu.begin();
ConsoleEntry *pEntry; ConsoleEntry *pEntry;
bool inserted = false; bool inserted = false;
while (iter != m_Menu.end()) while (iter != m_Menu.end())
{ {
pEntry = (*iter); pEntry = (*iter);
if (strcmp(cmd, pEntry->command.c_str()) < 0) if (strcmp(cmd, pEntry->command.c_str()) < 0)
{ {
ConsoleEntry *pNew = new ConsoleEntry; ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd); pNew->command.assign(cmd);
pNew->description.assign(text); pNew->description.assign(text);
pNew->cmd = pHandler; pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew); m_Commands.insert(cmd, pNew);
m_Menu.insert(iter, pNew); m_Menu.insert(iter, pNew);
inserted = true; inserted = true;
break; break;
} }
iter++; iter++;
} }
if (!inserted) if (!inserted)
{ {
ConsoleEntry *pNew = new ConsoleEntry; ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd); pNew->command.assign(cmd);
pNew->description.assign(text); pNew->description.assign(text);
pNew->cmd = pHandler; pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew); m_Commands.insert(cmd, pNew);
m_Menu.push_back(pNew); m_Menu.push_back(pNew);
} }
return true; return true;
} }
bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler) bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
{ {
m_Commands.remove(cmd); m_Commands.remove(cmd);
List<ConsoleEntry *>::iterator iter; List<ConsoleEntry *>::iterator iter;
ConsoleEntry *pEntry; ConsoleEntry *pEntry;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{ {
pEntry = (*iter); pEntry = (*iter);
if (pEntry->command.compare(cmd) == 0) if (pEntry->command.compare(cmd) == 0)
{ {
delete pEntry; delete pEntry;
m_Menu.erase(iter); m_Menu.erase(iter);
break; break;
} }
} }
return true; return true;
} }
void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text) void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
{ {
char buffer[255]; char buffer[255];
size_t len, cmdlen = strlen(cmd); size_t len, cmdlen = strlen(cmd);
len = ke::SafeSprintf(buffer, sizeof(buffer), " %s", cmd); len = ke::SafeSprintf(buffer, sizeof(buffer), " %s", cmd);
if (cmdlen < 16) if (cmdlen < 16)
{ {
size_t num = 16 - cmdlen; size_t num = 16 - cmdlen;
for (size_t i = 0; i < num; i++) for (size_t i = 0; i < num; i++)
{ {
buffer[len++] = ' '; buffer[len++] = ' ';
} }
len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text); len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
ConsolePrint("%s", buffer); ConsolePrint("%s", buffer);
} }
} }
const char *RootConsoleMenu::GetInterfaceName() const char *RootConsoleMenu::GetInterfaceName()
{ {
return SMINTERFACE_ROOTCONSOLE_NAME; return SMINTERFACE_ROOTCONSOLE_NAME;
} }
unsigned int RootConsoleMenu::GetInterfaceVersion() unsigned int RootConsoleMenu::GetInterfaceVersion()
{ {
return SMINTERFACE_ROOTCONSOLE_VERSION; return SMINTERFACE_ROOTCONSOLE_VERSION;
} }
void RootConsoleMenu::GotRootCmd(const ICommandArgs *cmd) void RootConsoleMenu::GotRootCmd(const ICommandArgs *cmd)
{ {
unsigned int argnum = cmd->ArgC(); unsigned int argnum = cmd->ArgC();
if (argnum >= 2) if (argnum >= 2)
{ {
const char *cmdname = cmd->Arg(1); const char *cmdname = cmd->Arg(1);
ConsoleEntry *entry; ConsoleEntry *entry;
if (m_Commands.retrieve(cmdname, &entry)) if (m_Commands.retrieve(cmdname, &entry))
{ {
entry->cmd->OnRootConsoleCommand(cmdname, cmd); entry->cmd->OnRootConsoleCommand(cmdname, cmd);
return; return;
} }
} }
ConsolePrint("SourceMod Menu:"); ConsolePrint("SourceMod Menu:");
ConsolePrint("Usage: sm <command> [arguments]"); ConsolePrint("Usage: sm <command> [arguments]");
List<ConsoleEntry *>::iterator iter; List<ConsoleEntry *>::iterator iter;
ConsoleEntry *pEntry; ConsoleEntry *pEntry;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{ {
pEntry = (*iter); pEntry = (*iter);
DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str()); DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
} }
} }
void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
if (strcmp(cmdname, "credits") == 0) if (strcmp(cmdname, "credits") == 0)
{ {
ConsolePrint(" SourceMod was developed by AlliedModders, LLC."); ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
ConsolePrint(" Development would not have been possible without the following people:"); ConsolePrint(" Development would not have been possible without the following people:");
ConsolePrint(" David \"BAILOPAN\" Anderson"); ConsolePrint(" David \"BAILOPAN\" Anderson");
ConsolePrint(" Matt \"pRED\" Woodrow"); ConsolePrint(" Matt \"pRED\" Woodrow");
ConsolePrint(" Scott \"DS\" Ehlert"); ConsolePrint(" Scott \"DS\" Ehlert");
ConsolePrint(" Fyren"); ConsolePrint(" Fyren");
ConsolePrint(" Nicholas \"psychonic\" Hastings"); ConsolePrint(" Nicholas \"psychonic\" Hastings");
ConsolePrint(" Asher \"asherkin\" Baker"); ConsolePrint(" Asher \"asherkin\" Baker");
ConsolePrint(" Borja \"faluco\" Ferrer"); ConsolePrint(" Borja \"faluco\" Ferrer");
ConsolePrint(" Pavol \"PM OnoTo\" Marko"); ConsolePrint(" Pavol \"PM OnoTo\" Marko");
ConsolePrint(" Special thanks to Liam, ferret, and Mani"); ConsolePrint(" Special thanks to Liam, ferret, and Mani");
ConsolePrint(" Special thanks to Viper and SteamFriends"); ConsolePrint(" Special thanks to Viper and SteamFriends");
ConsolePrint(" http://www.sourcemod.net/"); ConsolePrint(" http://www.sourcemod.net/");
} }
else if (strcmp(cmdname, "version") == 0) else if (strcmp(cmdname, "version") == 0)
{ {
ConsolePrint(" SourceMod Version Information:"); ConsolePrint(" SourceMod Version Information:");
ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION); ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION);
if (g_pSourcePawn2->IsJitEnabled()) if (g_pSourcePawn2->IsJitEnabled())
ConsolePrint(" SourcePawn Engine: %s (build %s)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString()); ConsolePrint(" SourcePawn Engine: %s (build %s)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
else else
ConsolePrint(" SourcePawn Engine: %s (build %s NO JIT)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString()); ConsolePrint(" SourcePawn Engine: %s (build %s NO JIT)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
ConsolePrint(" SourcePawn API: v1 = %d, v2 = %d", g_pSourcePawn->GetEngineAPIVersion(), g_pSourcePawn2->GetAPIVersion()); ConsolePrint(" SourcePawn API: v1 = %d, v2 = %d", g_pSourcePawn->GetEngineAPIVersion(), g_pSourcePawn2->GetAPIVersion());
ConsolePrint(" Compiled on: %s", SOURCEMOD_BUILD_TIME); ConsolePrint(" Compiled on: %s", SOURCEMOD_BUILD_TIME);
#if defined(SM_GENERATED_BUILD) #if defined(SM_GENERATED_BUILD)
ConsolePrint(" Built from: https://github.com/alliedmodders/sourcemod/commit/%s", SOURCEMOD_SHA); ConsolePrint(" Built from: https://github.com/alliedmodders/sourcemod/commit/%s", SOURCEMOD_SHA);
ConsolePrint(" Build ID: %s:%s", SOURCEMOD_LOCAL_REV, SOURCEMOD_SHA); ConsolePrint(" Build ID: %s:%s", SOURCEMOD_LOCAL_REV, SOURCEMOD_SHA);
#endif #endif
ConsolePrint(" http://www.sourcemod.net/"); ConsolePrint(" http://www.sourcemod.net/");
} }
} }
static bool sm_dump_handles(int client, const ICommandArgs *args) static bool sm_dump_handles(int client, const ICommandArgs *args)
{ {
if (args->ArgC() < 2) { if (args->ArgC() < 2) {
bridge->ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs"); bridge->ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
return true; return true;
} }
if (strcmp(args->Arg(1), "log") == 0) { if (strcmp(args->Arg(1), "log") == 0) {
auto write_handles_to_game = [] (const char *str) -> void auto write_handles_to_game = [] (const char *str) -> void
{ {
char buffer[1024]; char buffer[1024];
size_t len = ke::SafeSprintf(buffer, sizeof(buffer)-2, "%s", str); size_t len = ke::SafeSprintf(buffer, sizeof(buffer)-2, "%s", str);
buffer[len] = '\n'; buffer[len] = '\n';
buffer[len+1] = '\0'; buffer[len+1] = '\0';
bridge->LogToGame(buffer); bridge->LogToGame(buffer);
}; };
g_HandleSys.Dump(write_handles_to_game); g_HandleSys.Dump(write_handles_to_game);
return true; return true;
} }
FILE *fp = nullptr; FILE *fp = nullptr;
auto write_handles_to_log = [&fp] (const char *str) -> void auto write_handles_to_log = [&fp] (const char *str) -> void
{ {
fprintf(fp, "%s\n", str); fprintf(fp, "%s\n", str);
}; };
char filename[PLATFORM_MAX_PATH]; char filename[PLATFORM_MAX_PATH];
const char *arg = args->Arg(1); const char *arg = args->Arg(1);
g_pSM->BuildPath(Path_Game, filename, sizeof(filename), "%s", arg); g_pSM->BuildPath(Path_Game, filename, sizeof(filename), "%s", arg);
fp = fopen(filename, "wt"); fp = fopen(filename, "wt");
if (!fp) { if (!fp) {
bridge->ConsolePrint("Failed to open \"%s\" for writing", filename); bridge->ConsolePrint("Failed to open \"%s\" for writing", filename);
return true; return true;
} }
g_HandleSys.Dump(write_handles_to_log); g_HandleSys.Dump(write_handles_to_log);
fclose(fp); fclose(fp);
return true; return true;
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,12 +29,12 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "ShareSys.h" #include "sharesys.h"
#include "ExtensionSys.h" #include "extensionsys.h"
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include "common_logic.h" #include "common_logic.h"
#include "PluginSys.h" #include "pluginsys.h"
#include "HandleSys.h" #include "handlesys.h"
#include <assert.h> #include <assert.h>
using namespace ke; using namespace ke;
@ -150,15 +150,15 @@ bool ShareSystem::AddInterface(IExtension *myself, SMInterface *iface)
info.owner = myself; info.owner = myself;
info.iface = iface; info.iface = iface;
m_Interfaces.push_back(info); m_Interfaces.push_back(info);
return true; return true;
} }
bool ShareSystem::RequestInterface(const char *iface_name, bool ShareSystem::RequestInterface(const char *iface_name,
unsigned int iface_vers, unsigned int iface_vers,
IExtension *myself, IExtension *myself,
SMInterface **pIface) SMInterface **pIface)
{ {
/* See if the interface exists */ /* See if the interface exists */
@ -445,7 +445,7 @@ void ShareSystem::DropCapabilityProvider(IExtension *myself, IFeatureProvider *p
m_caps.remove(r); m_caps.remove(r);
} }
FeatureStatus ShareSystem::TestFeature(IPluginRuntime *pRuntime, FeatureType feature, FeatureStatus ShareSystem::TestFeature(IPluginRuntime *pRuntime, FeatureType feature,
const char *name) const char *name)
{ {
switch (feature) switch (feature)

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -41,7 +41,7 @@
#include <sm_stringhashmap.h> #include <sm_stringhashmap.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
#include "common_logic.h" #include "common_logic.h"
#include "Native.h" #include "native.h"
using namespace SourceHook; using namespace SourceHook;
@ -84,7 +84,7 @@ public:
ShareSystem(); ShareSystem();
public: //IShareSys public: //IShareSys
bool AddInterface(IExtension *myself, SMInterface *pIface); bool AddInterface(IExtension *myself, SMInterface *pIface);
bool RequestInterface(const char *iface_name, bool RequestInterface(const char *iface_name,
unsigned int iface_vers, unsigned int iface_vers,
IExtension *myself, IExtension *myself,
SMInterface **pIface); SMInterface **pIface);

View File

@ -31,7 +31,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "cellarray.h"
#include "stringutil.h" #include "stringutil.h"
#include <IHandleSys.h> #include <IHandleSys.h>

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -31,14 +31,14 @@
#include <stdlib.h> #include <stdlib.h>
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "cellarray.h"
#include "handle_helpers.h" #include "handle_helpers.h"
#include "stringutil.h" #include "stringutil.h"
#include <IHandleSys.h> #include <IHandleSys.h>
HandleType_t htCellStack; HandleType_t htCellStack;
class CellStackHelpers : class CellStackHelpers :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch public IHandleTypeDispatch
{ {
@ -89,7 +89,7 @@ static cell_t PushStackCell(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -112,7 +112,7 @@ static cell_t PushStackString(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -138,7 +138,7 @@ static cell_t PushStackArray(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -172,7 +172,7 @@ static cell_t PopStackCell(IPluginContext *pContext, const cell_t *params)
cell_t *blk, *buffer; cell_t *blk, *buffer;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -218,7 +218,7 @@ static cell_t PopStackString(IPluginContext *pContext, const cell_t *params)
cell_t *blk, *pWritten; cell_t *blk, *pWritten;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -249,7 +249,7 @@ static cell_t PopStackArray(IPluginContext *pContext, const cell_t *params)
CellArray *array; CellArray *array;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -282,7 +282,7 @@ static cell_t IsStackEmpty(IPluginContext *pContext, const cell_t *params)
CellArray *array; CellArray *array;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array)) if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -298,7 +298,7 @@ static cell_t IsStackEmpty(IPluginContext *pContext, const cell_t *params)
static cell_t ArrayStack_Pop(IPluginContext *pContext, const cell_t *params) static cell_t ArrayStack_Pop(IPluginContext *pContext, const cell_t *params)
{ {
OpenHandle<CellArray> array(pContext, params[1], htCellStack); OpenHandle<CellArray> array(pContext, params[1], htCellStack);
if (!array.Ok()) if (!array.Ok())
return 0; return 0;
@ -325,7 +325,7 @@ static cell_t ArrayStack_Pop(IPluginContext *pContext, const cell_t *params)
static cell_t ArrayStack_PopString(IPluginContext *pContext, const cell_t *params) static cell_t ArrayStack_PopString(IPluginContext *pContext, const cell_t *params)
{ {
OpenHandle<CellArray> array(pContext, params[1], htCellStack); OpenHandle<CellArray> array(pContext, params[1], htCellStack);
if (!array.Ok()) if (!array.Ok())
return 0; return 0;
@ -347,7 +347,7 @@ static cell_t ArrayStack_PopString(IPluginContext *pContext, const cell_t *param
static cell_t ArrayStack_PopArray(IPluginContext *pContext, const cell_t *params) static cell_t ArrayStack_PopArray(IPluginContext *pContext, const cell_t *params)
{ {
OpenHandle<CellArray> array(pContext, params[1], htCellStack); OpenHandle<CellArray> array(pContext, params[1], htCellStack);
if (!array.Ok()) if (!array.Ok())
return 0; return 0;

View File

@ -1,355 +1,355 @@
/** /**
* vim: set ts=4 sw=4 tw=99 noet : * vim: set ts=4 sw=4 tw=99 noet :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#include "common_logic.h" #include "common_logic.h"
#include "AdminCache.h" #include "admincache.h"
#include <IGameHelpers.h> #include <IGameHelpers.h>
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <ITranslator.h> #include <ITranslator.h>
#include "sprintf.h" #include "sprintf.h"
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
#include <bridge/include/IVEngineServerBridge.h> #include <bridge/include/IVEngineServerBridge.h>
static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params) static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
{ {
if (params[1] == 0) if (params[1] == 0)
{ {
return 1; return 1;
} }
char *cmd; char *cmd;
pContext->LocalToString(params[2], &cmd); pContext->LocalToString(params[2], &cmd);
/* Match up with an admin command if possible */ /* Match up with an admin command if possible */
FlagBits bits = params[3]; FlagBits bits = params[3];
bool found_command = false; bool found_command = false;
if (params[0] < 4 || !params[4]) if (params[0] < 4 || !params[4])
{ {
found_command = bridge->LookForCommandAdminFlags(cmd, &bits); found_command = bridge->LookForCommandAdminFlags(cmd, &bits);
} }
if (!found_command) if (!found_command)
{ {
adminsys->GetCommandOverride(cmd, Override_Command, &bits); adminsys->GetCommandOverride(cmd, Override_Command, &bits);
} }
return adminsys->CheckClientCommandAccess(params[1], cmd, bits) ? 1 : 0; return adminsys->CheckClientCommandAccess(params[1], cmd, bits) ? 1 : 0;
} }
static cell_t CheckAccess(IPluginContext *pContext, const cell_t *params) static cell_t CheckAccess(IPluginContext *pContext, const cell_t *params)
{ {
char *cmd; char *cmd;
pContext->LocalToString(params[2], &cmd); pContext->LocalToString(params[2], &cmd);
/* Match up with an admin command if possible */ /* Match up with an admin command if possible */
FlagBits bits = params[3]; FlagBits bits = params[3];
bool found_command = false; bool found_command = false;
if (params[0] < 4 || !params[4]) if (params[0] < 4 || !params[4])
{ {
found_command = bridge->LookForCommandAdminFlags(cmd, &bits); found_command = bridge->LookForCommandAdminFlags(cmd, &bits);
} }
if (!found_command) if (!found_command)
{ {
adminsys->GetCommandOverride(cmd, Override_Command, &bits); adminsys->GetCommandOverride(cmd, Override_Command, &bits);
} }
return g_Admins.CheckAdminCommandAccess(params[1], cmd, bits) ? 1 : 0; return g_Admins.CheckAdminCommandAccess(params[1], cmd, bits) ? 1 : 0;
} }
static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params) static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
{ {
char buffer[1024]; char buffer[1024];
char *fmt; char *fmt;
int arg = 2; int arg = 2;
pCtx->LocalToString(params[1], &fmt); pCtx->LocalToString(params[1], &fmt);
size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg); size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
buffer[res++] = '\n'; buffer[res++] = '\n';
buffer[res] = '\0'; buffer[res] = '\0';
bridge->ConPrint(buffer); bridge->ConPrint(buffer);
return 1; return 1;
} }
static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params) static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
{ {
int index = params[1]; int index = params[1];
if ((index < 0) || (index > playerhelpers->GetMaxClients())) if ((index < 0) || (index > playerhelpers->GetMaxClients()))
{ {
return pCtx->ThrowNativeError("Client index %d is invalid", index); return pCtx->ThrowNativeError("Client index %d is invalid", index);
} }
IGamePlayer *pPlayer = NULL; IGamePlayer *pPlayer = NULL;
if (index != 0) if (index != 0)
{ {
pPlayer = playerhelpers->GetGamePlayer(index); pPlayer = playerhelpers->GetGamePlayer(index);
if (!pPlayer->IsInGame()) if (!pPlayer->IsInGame())
{ {
return pCtx->ThrowNativeError("Client %d is not in game", index); return pCtx->ThrowNativeError("Client %d is not in game", index);
} }
/* Silent fail on bots, engine will crash */ /* Silent fail on bots, engine will crash */
if (pPlayer->IsFakeClient()) if (pPlayer->IsFakeClient())
{ {
return 0; return 0;
} }
} }
char buffer[1024]; char buffer[1024];
char *fmt; char *fmt;
int arg = 3; int arg = 3;
pCtx->LocalToString(params[2], &fmt); pCtx->LocalToString(params[2], &fmt);
size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg); size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
buffer[res++] = '\n'; buffer[res++] = '\n';
buffer[res] = '\0'; buffer[res] = '\0';
if (index != 0) if (index != 0)
{ {
pPlayer->PrintToConsole(buffer); pPlayer->PrintToConsole(buffer);
} }
else { else {
bridge->ConPrint(buffer); bridge->ConPrint(buffer);
} }
return 1; return 1;
} }
static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params) static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params)
{ {
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
char buffer[1024]; char buffer[1024];
size_t len; size_t len;
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 1); len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 1);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
/* One byte for null terminator, one for newline */ /* One byte for null terminator, one for newline */
buffer[len++] = '\n'; buffer[len++] = '\n';
buffer[len] = '\0'; buffer[len] = '\0';
engine->ServerCommand(buffer); engine->ServerCommand(buffer);
return 1; return 1;
} }
static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params) static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params)
{ {
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
char buffer[1024]; char buffer[1024];
size_t len; size_t len;
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 1); len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 1);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
/* One byte for null terminator, one for newline */ /* One byte for null terminator, one for newline */
buffer[len++] = '\n'; buffer[len++] = '\n';
buffer[len] = '\0'; buffer[len] = '\0';
engine->InsertServerCommand(buffer); engine->InsertServerCommand(buffer);
return 1; return 1;
} }
static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params) static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
{ {
engine->ServerExecute(); engine->ServerExecute();
return 1; return 1;
} }
static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params) static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
{ {
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
if (!pPlayer) if (!pPlayer)
{ {
return pContext->ThrowNativeError("Client index %d is invalid", params[1]); return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
} }
if (!pPlayer->IsConnected()) if (!pPlayer->IsConnected())
{ {
return pContext->ThrowNativeError("Client %d is not connected", params[1]); return pContext->ThrowNativeError("Client %d is not connected", params[1]);
} }
g_pSM->SetGlobalTarget(params[1]); g_pSM->SetGlobalTarget(params[1]);
char buffer[256]; char buffer[256];
size_t len; size_t len;
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
engine->ClientCommand(pPlayer->GetEdict(), buffer); engine->ClientCommand(pPlayer->GetEdict(), buffer);
return 1; return 1;
} }
static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params) static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
{ {
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
if (!pPlayer) if (!pPlayer)
{ {
return pContext->ThrowNativeError("Client index %d is invalid", params[1]); return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
} }
if (!pPlayer->IsConnected()) if (!pPlayer->IsConnected())
{ {
return pContext->ThrowNativeError("Client %d is not connected", params[1]); return pContext->ThrowNativeError("Client %d is not connected", params[1]);
} }
g_pSM->SetGlobalTarget(params[1]); g_pSM->SetGlobalTarget(params[1]);
char buffer[256]; char buffer[256];
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
engine->FakeClientCommand(pPlayer->GetEdict(), buffer); engine->FakeClientCommand(pPlayer->GetEdict(), buffer);
return 1; return 1;
} }
static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params) static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params)
{ {
g_pSM->SetGlobalTarget(params[1]); g_pSM->SetGlobalTarget(params[1]);
/* Build the format string */ /* Build the format string */
char buffer[1024]; char buffer[1024];
size_t len; size_t len;
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 2); len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 2);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
/* If we're printing to the server, shortcut out */ /* If we're printing to the server, shortcut out */
if (params[1] == 0) if (params[1] == 0)
{ {
/* Print */ /* Print */
buffer[len++] = '\n'; buffer[len++] = '\n';
buffer[len] = '\0'; buffer[len] = '\0';
bridge->ConPrint(buffer); bridge->ConPrint(buffer);
return 1; return 1;
} }
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
if (!pPlayer) if (!pPlayer)
{ {
return pContext->ThrowNativeError("Client index %d is invalid", params[1]); return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
} }
if (!pPlayer->IsConnected()) if (!pPlayer->IsConnected())
{ {
return pContext->ThrowNativeError("Client %d is not connected", params[1]); return pContext->ThrowNativeError("Client %d is not connected", params[1]);
} }
unsigned int replyto = playerhelpers->GetReplyTo(); unsigned int replyto = playerhelpers->GetReplyTo();
if (replyto == SM_REPLY_CONSOLE) if (replyto == SM_REPLY_CONSOLE)
{ {
buffer[len++] = '\n'; buffer[len++] = '\n';
buffer[len] = '\0'; buffer[len] = '\0';
pPlayer->PrintToConsole(buffer); pPlayer->PrintToConsole(buffer);
} }
else if (replyto == SM_REPLY_CHAT) { else if (replyto == SM_REPLY_CHAT) {
if (len >= 191) if (len >= 191)
{ {
len = 191; len = 191;
} }
buffer[len] = '\0'; buffer[len] = '\0';
gamehelpers->TextMsg(params[1], TEXTMSG_DEST_CHAT, buffer); gamehelpers->TextMsg(params[1], TEXTMSG_DEST_CHAT, buffer);
} }
return 1; return 1;
} }
static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params) static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
{ {
return playerhelpers->GetReplyTo(); return playerhelpers->GetReplyTo();
} }
static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params) static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
{ {
return playerhelpers->SetReplyTo(params[1]); return playerhelpers->SetReplyTo(params[1]);
} }
static cell_t AddServerTag(IPluginContext *pContext, const cell_t *params) static cell_t AddServerTag(IPluginContext *pContext, const cell_t *params)
{ {
return 0; return 0;
} }
static cell_t RemoveServerTag(IPluginContext *pContext, const cell_t *params) static cell_t RemoveServerTag(IPluginContext *pContext, const cell_t *params)
{ {
return 0; return 0;
} }
REGISTER_NATIVES(consoleNatives) REGISTER_NATIVES(consoleNatives)
{ {
{"CheckCommandAccess", CheckCommandAccess}, {"CheckCommandAccess", CheckCommandAccess},
{"CheckAccess", CheckAccess}, {"CheckAccess", CheckAccess},
{"PrintToServer", sm_PrintToServer}, {"PrintToServer", sm_PrintToServer},
{"PrintToConsole", sm_PrintToConsole}, {"PrintToConsole", sm_PrintToConsole},
{"ServerCommand", sm_ServerCommand}, {"ServerCommand", sm_ServerCommand},
{"InsertServerCommand", sm_InsertServerCommand}, {"InsertServerCommand", sm_InsertServerCommand},
{"ServerExecute", sm_ServerExecute}, {"ServerExecute", sm_ServerExecute},
{"ClientCommand", sm_ClientCommand}, {"ClientCommand", sm_ClientCommand},
{"FakeClientCommand", FakeClientCommand}, {"FakeClientCommand", FakeClientCommand},
{"ReplyToCommand", ReplyToCommand}, {"ReplyToCommand", ReplyToCommand},
{"GetCmdReplySource", GetCmdReplyTarget}, {"GetCmdReplySource", GetCmdReplyTarget},
{"SetCmdReplySource", SetCmdReplyTarget}, {"SetCmdReplySource", SetCmdReplyTarget},
{"AddServerTag", AddServerTag}, {"AddServerTag", AddServerTag},
{"RemoveServerTag", RemoveServerTag}, {"RemoveServerTag", RemoveServerTag},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -33,7 +33,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "common_logic.h" #include "common_logic.h"
#include "Logger.h" #include "logger.h"
#include <ISourceMod.h> #include <ISourceMod.h>
#include <ITranslator.h> #include <ITranslator.h>
@ -48,15 +48,15 @@
#include <unistd.h> #include <unistd.h>
#include <sys/times.h> #include <sys/times.h>
#endif #endif
#include <IForwardSys.h> #include <IForwardSys.h>
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
#include <bridge/include/IScriptManager.h> #include <bridge/include/IScriptManager.h>
#include <bridge/include/IExtensionBridge.h> #include <bridge/include/IExtensionBridge.h>
using namespace SourceMod; using namespace SourceMod;
using namespace SourcePawn; using namespace SourcePawn;
HandleType_t g_PlIter; HandleType_t g_PlIter;
@ -64,7 +64,7 @@ IForward *g_OnLogAction = NULL;
static ConVar *sm_datetime_format = NULL; static ConVar *sm_datetime_format = NULL;
class CoreNativeHelpers : class CoreNativeHelpers :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch public IHandleTypeDispatch
{ {
@ -77,16 +77,16 @@ public:
g_PlIter = handlesys->CreateType("PluginIterator", this, 0, NULL, NULL, g_pCoreIdent, NULL); g_PlIter = handlesys->CreateType("PluginIterator", this, 0, NULL, NULL, g_pCoreIdent, NULL);
g_OnLogAction = forwardsys->CreateForward("OnLogAction", g_OnLogAction = forwardsys->CreateForward("OnLogAction",
ET_Hook, ET_Hook,
5, 5,
NULL, NULL,
Param_Cell, Param_Cell,
Param_Cell, Param_Cell,
Param_Cell, Param_Cell,
Param_Cell, Param_Cell,
Param_String); Param_String);
sm_datetime_format = bridge->FindConVar("sm_datetime_format"); sm_datetime_format = bridge->FindConVar("sm_datetime_format");
} }
void OnHandleDestroy(HandleType_t type, void *object) void OnHandleDestroy(HandleType_t type, void *object)
@ -132,21 +132,21 @@ void LogAction(Handle_t hndl, int type, int client, int target, const char *mess
g_Logger.LogMessage("[%s] %s", logtag, message); g_Logger.LogMessage("[%s] %s", logtag, message);
} }
static cell_t ThrowError(IPluginContext *pContext, const cell_t *params) static cell_t ThrowError(IPluginContext *pContext, const cell_t *params)
{ {
char buffer[512]; char buffer[512];
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
pContext->ReportError("%s", buffer); pContext->ReportError("%s", buffer);
return 0; return 0;
} }
@ -164,8 +164,8 @@ static cell_t GetTime(IPluginContext *pContext, const cell_t *params)
#if defined SUBPLATFORM_SECURECRT #if defined SUBPLATFORM_SECURECRT
void _ignore_invalid_parameter( void _ignore_invalid_parameter(
const wchar_t * expression, const wchar_t * expression,
const wchar_t * function, const wchar_t * function,
const wchar_t * file, const wchar_t * file,
unsigned int line, unsigned int line,
uintptr_t pReserved uintptr_t pReserved
) )
@ -398,16 +398,16 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
{ {
char buffer[2048]; char buffer[2048];
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1);
if (eh.HasException()) { if (eh.HasException()) {
pPlugin->SetErrorState(Plugin_Failed, "%s", str); pPlugin->SetErrorState(Plugin_Failed, "%s", str);
return 0; return 0;
} }
pPlugin->SetErrorState(Plugin_Failed, "%s", buffer); pPlugin->SetErrorState(Plugin_Failed, "%s", buffer);
pContext->ReportFatalError("%s", buffer); pContext->ReportFatalError("%s", buffer);
return 0; return 0;
} }
} }
@ -475,7 +475,7 @@ static cell_t MarkNativeAsOptional(IPluginContext *pContext, const cell_t *param
return 0; return 0;
} }
pContext->GetRuntime()->UpdateNativeBinding(idx, nullptr, SP_NTVFLAG_OPTIONAL, nullptr); pContext->GetRuntime()->UpdateNativeBinding(idx, nullptr, SP_NTVFLAG_OPTIONAL, nullptr);
return 1; return 1;
} }
@ -517,12 +517,12 @@ static cell_t sm_LogAction(IPluginContext *pContext, const cell_t *params)
{ {
char buffer[2048]; char buffer[2048];
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 3); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 3);
if (eh.HasException()) if (eh.HasException())
return 0; return 0;
} }
IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext()); IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());
@ -546,15 +546,15 @@ static cell_t LogToFile(IPluginContext *pContext, const cell_t *params)
} }
char buffer[2048]; char buffer[2048];
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (eh.HasException()) { if (eh.HasException()) {
fclose(fp); fclose(fp);
return 0; return 0;
} }
} }
IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext()); IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());
@ -580,15 +580,15 @@ static cell_t LogToFileEx(IPluginContext *pContext, const cell_t *params)
} }
char buffer[2048]; char buffer[2048];
{ {
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (eh.HasException()) { if (eh.HasException()) {
fclose(fp); fclose(fp);
return 0; return 0;
} }
} }
g_Logger.LogToOpenFile(fp, "%s", buffer); g_Logger.LogToOpenFile(fp, "%s", buffer);
@ -603,12 +603,12 @@ static cell_t GetExtensionFileStatus(IPluginContext *pContext, const cell_t *par
pContext->LocalToString(params[1], &str); pContext->LocalToString(params[1], &str);
IExtension *pExtension = extsys->FindExtensionByFile(str); IExtension *pExtension = extsys->FindExtensionByFile(str);
if (!pExtension) if (!pExtension)
{ {
return -2; return -2;
} }
if (!pExtension->IsLoaded()) if (!pExtension->IsLoaded())
{ {
return -1; return -1;
@ -627,7 +627,7 @@ static cell_t GetExtensionFileStatus(IPluginContext *pContext, const cell_t *par
static cell_t FindPluginByNumber(IPluginContext *pContext, const cell_t *params) static cell_t FindPluginByNumber(IPluginContext *pContext, const cell_t *params)
{ {
IPlugin *pPlugin = scripts->FindPluginByOrder(params[1]); IPlugin *pPlugin = scripts->FindPluginByOrder(params[1]);
if (pPlugin == NULL) if (pPlugin == NULL)
{ {
return BAD_HANDLE; return BAD_HANDLE;
@ -660,27 +660,27 @@ static cell_t RequireFeature(IPluginContext *pContext, const cell_t *params)
if (sharesys->TestFeature(pContext->GetRuntime(), type, name) != FeatureStatus_Available) if (sharesys->TestFeature(pContext->GetRuntime(), type, name) != FeatureStatus_Available)
{ {
char buffer[255]; char buffer[255];
char *msg = buffer; char *msg = buffer;
char default_message[255]; char default_message[255];
SMPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext()); SMPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 3); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 3);
if (eh.HasException()) if (eh.HasException())
buffer[0] = '\0'; buffer[0] = '\0';
if (buffer[0] == '\0') { if (buffer[0] == '\0') {
g_pSM->Format(default_message, sizeof(default_message), "Feature \"%s\" not available", name); g_pSM->Format(default_message, sizeof(default_message), "Feature \"%s\" not available", name);
msg = default_message; msg = default_message;
} }
pPlugin->SetErrorState(Plugin_Error, "%s", msg); pPlugin->SetErrorState(Plugin_Error, "%s", msg);
if (!eh.HasException()) if (!eh.HasException())
pContext->ReportFatalError("%s", msg); pContext->ReportFatalError("%s", msg);
return 0; return 0;
} }
return 1; return 1;
} }
@ -788,4 +788,4 @@ REGISTER_NATIVES(coreNatives)
{"LoadFromAddress", LoadFromAddress}, {"LoadFromAddress", LoadFromAddress},
{"StoreToAddress", StoreToAddress}, {"StoreToAddress", StoreToAddress},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -30,11 +30,11 @@
*/ */
#include "common_logic.h" #include "common_logic.h"
#include "Database.h" #include "database.h"
#include "ExtensionSys.h" #include "extensionsys.h"
#include "stringutil.h" #include "stringutil.h"
#include "ISourceMod.h" #include <ISourceMod.h>
#include "AutoHandleRooter.h" #include <AutoHandleRooter.h>
#include "common_logic.h" #include "common_logic.h"
#include <amtl/am-string.h> #include <amtl/am-string.h>
#include <amtl/am-vector.h> #include <amtl/am-vector.h>
@ -68,7 +68,7 @@ struct Transaction
ke::Vector<Entry> entries; ke::Vector<Entry> entries;
}; };
class DatabaseHelpers : class DatabaseHelpers :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch public IHandleTypeDispatch
{ {
@ -134,7 +134,7 @@ inline HandleError ReadQueryHndl(Handle_t hndl, IPluginContext *pContext, IQuery
sec.pIdentity = g_pCoreIdent; sec.pIdentity = g_pCoreIdent;
HandleError ret; HandleError ret;
if ((ret = handlesys->ReadHandle(hndl, hStmtType, &sec, (void **)query)) != HandleError_None) if ((ret = handlesys->ReadHandle(hndl, hStmtType, &sec, (void **)query)) != HandleError_None)
{ {
ret = handlesys->ReadHandle(hndl, hCombinedQueryType, &sec, (void **)&c); ret = handlesys->ReadHandle(hndl, hCombinedQueryType, &sec, (void **)&c);
@ -185,13 +185,13 @@ inline HandleError ReadDbOrStmtHndl(Handle_t hndl, IPluginContext *pContext, IDa
class TQueryOp : public IDBThreadOperation class TQueryOp : public IDBThreadOperation
{ {
public: public:
TQueryOp(IDatabase *db, IPluginFunction *pf, const char *query, cell_t data) : TQueryOp(IDatabase *db, IPluginFunction *pf, const char *query, cell_t data) :
m_pDatabase(db), m_pFunction(pf), m_Query(query), m_Data(data), m_pDatabase(db), m_pFunction(pf), m_Query(query), m_Data(data),
me(scripts->FindPluginByContext(pf->GetParentContext()->GetContext())), me(scripts->FindPluginByContext(pf->GetParentContext()->GetContext())),
m_pQuery(NULL) m_pQuery(NULL)
{ {
/* We always increase the reference count because this is potentially /* We always increase the reference count because this is potentially
* asynchronous. Otherwise the original handle could be closed while * asynchronous. Otherwise the original handle could be closed while
* we're still latched onto it. * we're still latched onto it.
*/ */
m_pDatabase->IncReferenceCount(); m_pDatabase->IncReferenceCount();
@ -251,11 +251,11 @@ public:
access.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY|HANDLE_RESTRICT_OWNER; access.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY|HANDLE_RESTRICT_OWNER;
Handle_t qh = BAD_HANDLE; Handle_t qh = BAD_HANDLE;
if (m_pQuery) if (m_pQuery)
{ {
CombinedQuery *c = new CombinedQuery(m_pQuery, m_pDatabase); CombinedQuery *c = new CombinedQuery(m_pQuery, m_pDatabase);
qh = handlesys->CreateHandle(hCombinedQueryType, c, me->GetIdentity(), g_pCoreIdent, NULL); qh = handlesys->CreateHandle(hCombinedQueryType, c, me->GetIdentity(), g_pCoreIdent, NULL);
if (qh != BAD_HANDLE) if (qh != BAD_HANDLE)
{ {
@ -347,7 +347,7 @@ public:
void RunThinkPart() void RunThinkPart()
{ {
Handle_t hndl = BAD_HANDLE; Handle_t hndl = BAD_HANDLE;
if (m_pDatabase) if (m_pDatabase)
{ {
if ((hndl = g_DBMan.CreateHandle(DBHandle_Database, m_pDatabase, me->GetIdentity())) if ((hndl = g_DBMan.CreateHandle(DBHandle_Database, m_pDatabase, me->GetIdentity()))
@ -388,7 +388,7 @@ static cell_t SQL_Connect(IPluginContext *pContext, const cell_t *params)
bool persistent = params[2] ? true : false; bool persistent = params[2] ? true : false;
pContext->LocalToString(params[1], &conf); pContext->LocalToString(params[1], &conf);
pContext->LocalToString(params[3], &err); pContext->LocalToString(params[3], &err);
IDBDriver *driver; IDBDriver *driver;
IDatabase *db; IDatabase *db;
if (!g_DBMan.Connect(conf, &driver, &db, persistent, err, maxlength)) if (!g_DBMan.Connect(conf, &driver, &db, persistent, err, maxlength))
@ -437,9 +437,9 @@ static cell_t ConnectToDbAsync(IPluginContext *pContext, const cell_t *params, A
} }
if (!driver) if (!driver)
{ {
g_pSM->Format(error, g_pSM->Format(error,
sizeof(error), sizeof(error),
"Could not find driver \"%s\"", "Could not find driver \"%s\"",
pInfo->driver[0] == '\0' ? g_DBMan.GetDefaultDriverName() : pInfo->driver); pInfo->driver[0] == '\0' ? g_DBMan.GetDefaultDriverName() : pInfo->driver);
} else if (!driver->IsThreadSafe()) { } else if (!driver->IsThreadSafe()) {
g_pSM->Format(error, g_pSM->Format(error,
@ -511,7 +511,7 @@ static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid driver Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid driver Handle %x (error: %d)", params[1], err);
} }
} }
char *host, *user, *pass, *database, *error; char *host, *user, *pass, *database, *error;
size_t maxlength = (size_t)params[7]; size_t maxlength = (size_t)params[7];
bool persistent = params[8] ? true : false; bool persistent = params[8] ? true : false;
@ -531,7 +531,7 @@ static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
info.pass = pass; info.pass = pass;
info.port = port; info.port = port;
info.user = user; info.user = user;
IDatabase *db = driver->Connect(&info, persistent, error, maxlength); IDatabase *db = driver->Connect(&info, persistent, error, maxlength);
if (db) if (db)
@ -552,7 +552,7 @@ static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
return hndl; return hndl;
} }
return BAD_HANDLE; return BAD_HANDLE;
} }
@ -769,7 +769,7 @@ static cell_t SQL_Query(IPluginContext *pContext, const cell_t *params)
pContext->LocalToString(params[2], &query); pContext->LocalToString(params[2], &query);
IQuery *qr; IQuery *qr;
if (params[0] >= 3 && params[3] != -1) if (params[0] >= 3 && params[3] != -1)
{ {
qr = db->DoQueryEx(query, params[3]); qr = db->DoQueryEx(query, params[3]);
@ -1435,7 +1435,7 @@ static cell_t SQL_ConnectCustom(IPluginContext *pContext, const cell_t *params)
IDatabase *db; IDatabase *db;
pContext->LocalToString(params[2], &buffer); pContext->LocalToString(params[2], &buffer);
db = driver->Connect(&info, params[4] ? true : false, buffer, params[3]); db = driver->Connect(&info, params[4] ? true : false, buffer, params[3]);
if (db == NULL) if (db == NULL)
{ {
@ -1515,7 +1515,7 @@ class TTransactOp : public IDBThreadOperation
public: public:
TTransactOp(IDatabase *db, Transaction *txn, Handle_t txnHandle, IdentityToken_t *ident, TTransactOp(IDatabase *db, Transaction *txn, Handle_t txnHandle, IdentityToken_t *ident,
IPluginFunction *onSuccess, IPluginFunction *onError, cell_t data) IPluginFunction *onSuccess, IPluginFunction *onError, cell_t data)
: :
db_(db), db_(db),
txn_(txn), txn_(txn),
ident_(ident), ident_(ident),

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -32,11 +32,11 @@
#include "common_logic.h" #include "common_logic.h"
#include <IHandleSys.h> #include <IHandleSys.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include "CDataPack.h" #include "cdatapack.h"
HandleType_t g_DataPackType; HandleType_t g_DataPackType;
class DataPackNatives : class DataPackNatives :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch public IHandleTypeDispatch
{ {

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -33,8 +33,8 @@
#include <sh_string.h> #include <sh_string.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include "common_logic.h" #include "common_logic.h"
#include "ShareSys.h" #include "sharesys.h"
#include "PluginSys.h" #include "pluginsys.h"
#include "sprintf.h" #include "sprintf.h"
using namespace SourceHook; using namespace SourceHook;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -39,7 +39,7 @@
#include <ISourceMod.h> #include <ISourceMod.h>
#include <ITranslator.h> #include <ITranslator.h>
#include "common_logic.h" #include "common_logic.h"
#include "Logger.h" #include "logger.h"
#include "sprintf.h" #include "sprintf.h"
#include <am-utility.h> #include <am-utility.h>
#include "handle_helpers.h" #include "handle_helpers.h"
@ -231,7 +231,7 @@ struct ValveDirectory
bool bHandledFirstPath; bool bHandledFirstPath;
}; };
class FileNatives : class FileNatives :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch, public IHandleTypeDispatch,
public IPluginsListener public IPluginsListener
@ -309,29 +309,29 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
pContext->ThrowNativeErrorEx(err, NULL); pContext->ThrowNativeErrorEx(err, NULL);
return 0; return 0;
} }
if (!path[0]) if (!path[0])
{ {
return pContext->ThrowNativeError("Invalid path. An empty path string is not valid, use \".\" to refer to the current working directory."); return pContext->ThrowNativeError("Invalid path. An empty path string is not valid, use \".\" to refer to the current working directory.");
} }
Handle_t handle = 0; Handle_t handle = 0;
if (params[0] >= 2 && params[2]) if (params[0] >= 2 && params[2])
{ {
size_t len = strlen(path); size_t len = strlen(path);
char wildcardedPath[PLATFORM_MAX_PATH]; char wildcardedPath[PLATFORM_MAX_PATH];
snprintf(wildcardedPath, sizeof(wildcardedPath), "%s%s*", path, (path[len-1] != '/' && path[len-1] != '\\') ? "/" : ""); snprintf(wildcardedPath, sizeof(wildcardedPath), "%s%s*", path, (path[len-1] != '/' && path[len-1] != '\\') ? "/" : "");
char *pathID; char *pathID;
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE) if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
{ {
pContext->ThrowNativeErrorEx(err, NULL); pContext->ThrowNativeErrorEx(err, NULL);
return 0; return 0;
} }
ValveDirectory *valveDir = new ValveDirectory; ValveDirectory *valveDir = new ValveDirectory;
const char *pFirst = bridge->filesystem->FindFirstEx(wildcardedPath, pathID, &valveDir->hndl); const char *pFirst = bridge->filesystem->FindFirstEx(wildcardedPath, pathID, &valveDir->hndl);
if (!pFirst) if (!pFirst)
{ {
@ -343,7 +343,7 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
valveDir->bHandledFirstPath = false; valveDir->bHandledFirstPath = false;
strncpy(valveDir->szFirstPath, pFirst, sizeof(valveDir->szFirstPath)); strncpy(valveDir->szFirstPath, pFirst, sizeof(valveDir->szFirstPath));
} }
handle = handlesys->CreateHandle(g_ValveDirType, valveDir, pContext->GetIdentity(), g_pCoreIdent, NULL); handle = handlesys->CreateHandle(g_ValveDirType, valveDir, pContext->GetIdentity(), g_pCoreIdent, NULL);
} }
else else
@ -359,7 +359,7 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
handle = handlesys->CreateHandle(g_DirType, pDir, pContext->GetIdentity(), g_pCoreIdent, NULL); handle = handlesys->CreateHandle(g_DirType, pDir, pContext->GetIdentity(), g_pCoreIdent, NULL);
} }
return handle; return handle;
} }
@ -410,7 +410,7 @@ static cell_t sm_ReadDirEntry(IPluginContext *pContext, const cell_t *params)
else if ((herr=handlesys->ReadHandle(hndl, g_ValveDirType, &sec, &pTempDir)) == HandleError_None) else if ((herr=handlesys->ReadHandle(hndl, g_ValveDirType, &sec, &pTempDir)) == HandleError_None)
{ {
ValveDirectory *valveDir = (ValveDirectory *)pTempDir; ValveDirectory *valveDir = (ValveDirectory *)pTempDir;
const char *pEntry = NULL; const char *pEntry = NULL;
if (!valveDir->bHandledFirstPath) if (!valveDir->bHandledFirstPath)
{ {
@ -423,15 +423,15 @@ static cell_t sm_ReadDirEntry(IPluginContext *pContext, const cell_t *params)
{ {
pEntry = bridge->filesystem->FindNext(valveDir->hndl); pEntry = bridge->filesystem->FindNext(valveDir->hndl);
} }
valveDir->bHandledFirstPath = true; valveDir->bHandledFirstPath = true;
// No more entries // No more entries
if (!pEntry) if (!pEntry)
{ {
return 0; return 0;
} }
if ((err=pContext->StringToLocalUTF8(params[2], params[3], pEntry, NULL)) if ((err=pContext->StringToLocalUTF8(params[2], params[3], pEntry, NULL))
!= SP_ERROR_NONE) != SP_ERROR_NONE)
{ {
@ -450,7 +450,7 @@ static cell_t sm_ReadDirEntry(IPluginContext *pContext, const cell_t *params)
*filetype = 1; *filetype = 1;
} else { } else {
*filetype = 2; *filetype = 2;
} }
} }
else else
{ {
@ -558,7 +558,7 @@ static cell_t sm_FileExists(IPluginContext *pContext, const cell_t *params)
char *pathID = szDefaultPath; char *pathID = szDefaultPath;
if (params[0] >= 3) if (params[0] >= 3)
pContext->LocalToStringNULL(params[3], &pathID); pContext->LocalToStringNULL(params[3], &pathID);
return bridge->filesystem->FileExists(name, pathID) ? 1 : 0; return bridge->filesystem->FileExists(name, pathID) ? 1 : 0;
} }
@ -594,12 +594,12 @@ static cell_t sm_RenameFile(IPluginContext *pContext, const cell_t *params)
char *newpath, *oldpath; char *newpath, *oldpath;
pContext->LocalToString(params[1], &newpath); pContext->LocalToString(params[1], &newpath);
pContext->LocalToString(params[2], &oldpath); pContext->LocalToString(params[2], &oldpath);
if (params[0] >= 3 && params[3] == 1) if (params[0] >= 3 && params[3] == 1)
{ {
char *pathID; char *pathID;
pContext->LocalToStringNULL(params[4], &pathID); pContext->LocalToStringNULL(params[4], &pathID);
bridge->filesystem->RenameFile(oldpath, newpath, pathID); bridge->filesystem->RenameFile(oldpath, newpath, pathID);
return 1; return 1;
} }
@ -630,7 +630,7 @@ static cell_t sm_DirExists(IPluginContext *pContext, const cell_t *params)
{ {
char *pathID; char *pathID;
pContext->LocalToStringNULL(params[3], &pathID); pContext->LocalToStringNULL(params[3], &pathID);
return bridge->filesystem->IsDirectory(name, pathID) ? 1 : 0; return bridge->filesystem->IsDirectory(name, pathID) ? 1 : 0;
} }
@ -672,7 +672,7 @@ static cell_t sm_FileSize(IPluginContext *pContext, const cell_t *params)
char *pathID = szDefaultPath; char *pathID = szDefaultPath;
if (params[0] >= 3) if (params[0] >= 3)
pContext->LocalToStringNULL(params[3], &pathID); pContext->LocalToStringNULL(params[3], &pathID);
if (!bridge->filesystem->FileExists(name, pathID)) if (!bridge->filesystem->FileExists(name, pathID))
return -1; return -1;
return bridge->filesystem->Size(name, pathID); return bridge->filesystem->Size(name, pathID);
@ -726,23 +726,23 @@ static cell_t sm_CreateDirectory(IPluginContext *pContext, const cell_t *params)
{ {
char *name; char *name;
pContext->LocalToString(params[1], &name); pContext->LocalToString(params[1], &name);
if (params[0] >= 3 && params[3] == 1) if (params[0] >= 3 && params[3] == 1)
{ {
char *pathID; char *pathID;
pContext->LocalToStringNULL(params[4], &pathID); pContext->LocalToStringNULL(params[4], &pathID);
if (bridge->filesystem->IsDirectory(name, pathID)) if (bridge->filesystem->IsDirectory(name, pathID))
return 0; return 0;
bridge->filesystem->CreateDirHierarchy(name, pathID); bridge->filesystem->CreateDirHierarchy(name, pathID);
if (bridge->filesystem->IsDirectory(name, pathID)) if (bridge->filesystem->IsDirectory(name, pathID))
return 1; return 1;
return 0; return 0;
} }
char realpath[PLATFORM_MAX_PATH]; char realpath[PLATFORM_MAX_PATH];
g_pSM->BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name); g_pSM->BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name);
@ -961,7 +961,7 @@ static cell_t sm_ReadFile(IPluginContext *pContext, const cell_t *params)
cell_t *data; cell_t *data;
pContext->LocalToPhysAddr(params[2], &data); pContext->LocalToPhysAddr(params[2], &data);
size_t read = 0; size_t read = 0;
switch (params[4]) { switch (params[4]) {
case 4: case 4:
@ -1006,7 +1006,7 @@ static cell_t sm_ReadFileString(IPluginContext *pContext, const cell_t *params)
char *buffer; char *buffer;
pContext->LocalToString(params[2], &buffer); pContext->LocalToString(params[2], &buffer);
cell_t num_read = 0; cell_t num_read = 0;
if (params[4] != -1) { if (params[4] != -1) {
if (size_t(params[4]) > size_t(params[3])) { if (size_t(params[4]) > size_t(params[3])) {
@ -1107,7 +1107,7 @@ static cell_t sm_AddGameLogHook(IPluginContext *pContext, const cell_t *params)
} }
s_FileNatives.AddLogHook(pFunction); s_FileNatives.AddLogHook(pFunction);
return 1; return 1;
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -33,7 +33,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "common_logic.h" #include "common_logic.h"
#include "MersenneTwister.h" #include "mersennetwister.h"
#include <IPluginSys.h> #include <IPluginSys.h>
#include <am-utility.h> #include <am-utility.h>
#include <am-float.h> #include <am-float.h>
@ -350,11 +350,11 @@ public:
delete mtrand; delete mtrand;
} }
} }
MTRand *RandObjForPlugin(IPluginContext *ctx) MTRand *RandObjForPlugin(IPluginContext *ctx)
{ {
IPlugin *plugin = pluginsys->FindPluginByContext(ctx->GetContext()); IPlugin *plugin = pluginsys->FindPluginByContext(ctx->GetContext());
MTRand *mtrand; MTRand *mtrand;
if (!plugin->GetProperty("core.logic.mtrand", (void**)&mtrand)) if (!plugin->GetProperty("core.logic.mtrand", (void**)&mtrand))
{ {
mtrand = new MTRand(); mtrand = new MTRand();

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -31,13 +31,13 @@
#include "common_logic.h" #include "common_logic.h"
#include <IHandleSys.h> #include <IHandleSys.h>
#include "GameConfigs.h" #include "gameconfigs.h"
HandleType_t g_GameConfigsType; HandleType_t g_GameConfigsType;
class GameConfigsNatives : class GameConfigsNatives :
public IHandleTypeDispatch, public IHandleTypeDispatch,
public SMGlobalClass public SMGlobalClass
{ {
public: public:
void OnSourceModAllInitialized() void OnSourceModAllInitialized()

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -30,7 +30,7 @@
*/ */
#include "common_logic.h" #include "common_logic.h"
#include "Translator.h" #include "translator.h"
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include <IPluginSys.h> #include <IPluginSys.h>
#include <ISourceMod.h> #include <ISourceMod.h>
@ -108,12 +108,12 @@ static cell_t sm_GetLanguageInfo(IPluginContext *pContext, const cell_t *params)
static cell_t sm_SetClientLanguage(IPluginContext *pContext, const cell_t *params) static cell_t sm_SetClientLanguage(IPluginContext *pContext, const cell_t *params)
{ {
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
if (!player || !player->IsConnected()) if (!player || !player->IsConnected())
{ {
return pContext->ThrowNativeError("Invalid client index %d", params[1]); return pContext->ThrowNativeError("Invalid client index %d", params[1]);
} }
player->SetLanguageId(params[2]); player->SetLanguageId(params[2]);
return 1; return 1;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -32,7 +32,7 @@
#include <sh_list.h> #include <sh_list.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "cellarray.h"
#include <IGameHelpers.h> #include <IGameHelpers.h>
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include <ITextParsers.h> #include <ITextParsers.h>
@ -143,7 +143,7 @@ public:
SMCError error; SMCError error;
time_t fileTime; time_t fileTime;
SMCStates states = {0, 0}; SMCStates states = {0, 0};
fileFound = libsys->FileTime(m_ConfigFile, FileTime_LastChange, &fileTime); fileFound = libsys->FileTime(m_ConfigFile, FileTime_LastChange, &fileTime);
/* If the file is found and hasn't changed, bail out now. */ /* If the file is found and hasn't changed, bail out now. */
@ -152,8 +152,8 @@ public:
return; return;
} }
/* If the file wasn't found, and we already have entries, we bail out too. /* If the file wasn't found, and we already have entries, we bail out too.
* This case lets us optimize when a user deletes the config file, so we * This case lets us optimize when a user deletes the config file, so we
* don't reparse every single time the function is called. * don't reparse every single time the function is called.
*/ */
if (!fileFound && m_MapLists.size() > 0) if (!fileFound && m_MapLists.size() > 0)
@ -174,7 +174,7 @@ public:
strncopy(pDefList->name, "mapcyclefile", sizeof(pDefList->name)); strncopy(pDefList->name, "mapcyclefile", sizeof(pDefList->name));
GetMapCycleFilePath(pDefList->path, sizeof(pDefList->path)); GetMapCycleFilePath(pDefList->path, sizeof(pDefList->path));
pDefList->last_modified_time = 0; pDefList->last_modified_time = 0;
pDefList->pArray = NULL; pDefList->pArray = NULL;
pDefList->serial = 0; pDefList->serial = 0;
@ -328,12 +328,12 @@ public:
bool success, free_new_array; bool success, free_new_array;
free_new_array = false; free_new_array = false;
if ((success = GetMapList(&pNewArray, name, &change_serial)) == false) if ((success = GetMapList(&pNewArray, name, &change_serial)) == false)
{ {
if ((flags & MAPLIST_FLAG_NO_DEFAULT) != MAPLIST_FLAG_NO_DEFAULT) if ((flags & MAPLIST_FLAG_NO_DEFAULT) != MAPLIST_FLAG_NO_DEFAULT)
{ {
/* If this list failed, and it's not the default, try the default. /* If this list failed, and it's not the default, try the default.
*/ */
if (strcmp(name, "default") != 0) if (strcmp(name, "default") != 0)
{ {
@ -401,9 +401,9 @@ public:
} }
else else
{ {
qsort(pNewArray->base(), qsort(pNewArray->base(),
pNewArray->size(), pNewArray->size(),
pNewArray->blocksize() * sizeof(cell_t), pNewArray->blocksize() * sizeof(cell_t),
sort_maps_in_adt_array); sort_maps_in_adt_array);
} }
@ -514,7 +514,7 @@ private:
{ {
continue; continue;
} }
if (strcmp(bridge->GetSourceEngineName(), "insurgency") == 0) if (strcmp(bridge->GetSourceEngineName(), "insurgency") == 0)
{ {
// Insurgency (presumably?) doesn't allow spaces in map names // Insurgency (presumably?) doesn't allow spaces in map names

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -33,9 +33,9 @@
#include <sh_stack.h> #include <sh_stack.h>
#include <IMenuManager.h> #include <IMenuManager.h>
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include "DebugReporter.h" #include "debugreporter.h"
#if defined MENU_DEBUG #if defined MENU_DEBUG
#include "Logger.h" #include "logger.h"
#endif #endif
#include <ISourceMod.h> #include <ISourceMod.h>
#include <stdlib.h> #include <stdlib.h>
@ -46,7 +46,7 @@
#endif #endif
/** /**
* And God said, "let there be menus," and behold, there were menus. * And God said, "let there be menus," and behold, there were menus.
* God saw the menus and they were good. And the evening and the morning * God saw the menus and they were good. And the evening and the morning
* were the third day. * were the third day.
*/ */
@ -158,7 +158,7 @@ private:
* GLOBAL CLASS FOR HELPERS * GLOBAL CLASS FOR HELPERS
*/ */
class MenuNativeHelpers : class MenuNativeHelpers :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch, public IHandleTypeDispatch,
public IPluginsListener public IPluginsListener
@ -211,7 +211,7 @@ public:
* It is extremely important that unloaded plugins don't crash. * It is extremely important that unloaded plugins don't crash.
* Thus, if a plugin unloads, we run through every handler we have. * Thus, if a plugin unloads, we run through every handler we have.
* This means we do almost no runtime work for keeping track of * This means we do almost no runtime work for keeping track of
* our panel handlers (we don't have to store a list of the running * our panel handlers (we don't have to store a list of the running
* ones), but when push comes to shove, we have to scan them all * ones), but when push comes to shove, we have to scan them all
* in case any of them are active. * in case any of them are active.
*/ */
@ -329,7 +329,7 @@ static unsigned int *s_CurSelectPosition = NULL;
/** /**
* MENU HANDLER WRAPPER * MENU HANDLER WRAPPER
*/ */
CMenuHandler::CMenuHandler(IPluginFunction *pBasic, int flags) : CMenuHandler::CMenuHandler(IPluginFunction *pBasic, int flags) :
m_pBasic(pBasic), m_Flags(flags), m_pVoteResults(NULL) m_pBasic(pBasic), m_Flags(flags), m_pVoteResults(NULL)
{ {
/* :TODO: We can probably cache the handle ahead of time */ /* :TODO: We can probably cache the handle ahead of time */
@ -350,7 +350,7 @@ void CMenuHandler::OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *panel)
HandleSecurity sec; HandleSecurity sec;
sec.pIdentity = g_pCoreIdent; sec.pIdentity = g_pCoreIdent;
sec.pOwner = m_pBasic->GetParentContext()->GetIdentity(); sec.pOwner = m_pBasic->GetParentContext()->GetIdentity();
HandleAccess access; HandleAccess access;
handlesys->InitAccessDefaults(NULL, &access); handlesys->InitAccessDefaults(NULL, &access);
access.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY|HANDLE_RESTRICT_OWNER; access.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY|HANDLE_RESTRICT_OWNER;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -37,9 +37,9 @@
#include <ITranslator.h> #include <ITranslator.h>
#include <sh_string.h> #include <sh_string.h>
#include <sh_list.h> #include <sh_list.h>
#include "GameConfigs.h" #include "gameconfigs.h"
#include "CellArray.h" #include "cellarray.h"
#include "AutoHandleRooter.h" #include <AutoHandleRooter.h>
#include "stringutil.h" #include "stringutil.h"
#include <bridge/include/IPlayerInfoBridge.h> #include <bridge/include/IPlayerInfoBridge.h>
#include <bridge/include/ILogger.h> #include <bridge/include/ILogger.h>
@ -64,7 +64,7 @@ static const int kActivityAdmins = 4; // Show admin activity to admins anonymo
static const int kActivityAdminsNames = 8; // If 4 is specified, admin names will be shown. static const int kActivityAdminsNames = 8; // If 4 is specified, admin names will be shown.
static const int kActivityRootNames = 16; // Always show admin names to root users. static const int kActivityRootNames = 16; // Always show admin names to root users.
class PlayerLogicHelpers : class PlayerLogicHelpers :
public SMGlobalClass, public SMGlobalClass,
public IPluginsListener, public IPluginsListener,
public ICommandTargetProcessor public ICommandTargetProcessor
@ -357,9 +357,9 @@ static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authTyp
{ {
return pCtx->ThrowNativeError("Client %d is not connected", index); return pCtx->ThrowNativeError("Client %d is not connected", index);
} }
const char *authstr; const char *authstr;
switch (authType) switch (authType)
{ {
case AuthIdType::Engine: case AuthIdType::Engine:
@ -377,7 +377,7 @@ static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authTyp
{ {
return 0; return 0;
} }
pCtx->StringToLocal(local_addr, bytes, authstr); pCtx->StringToLocal(local_addr, bytes, authstr);
break; break;
case AuthIdType::Steam3: case AuthIdType::Steam3:
@ -386,30 +386,30 @@ static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authTyp
{ {
return 0; return 0;
} }
pCtx->StringToLocal(local_addr, bytes, authstr); pCtx->StringToLocal(local_addr, bytes, authstr);
break; break;
case AuthIdType::SteamId64: case AuthIdType::SteamId64:
{ {
if (pPlayer->IsFakeClient() || gamehelpers->IsLANServer()) if (pPlayer->IsFakeClient() || gamehelpers->IsLANServer())
{ {
return 0; return 0;
} }
uint64_t steamId = pPlayer->GetSteamId64(validate); uint64_t steamId = pPlayer->GetSteamId64(validate);
if (steamId == 0) if (steamId == 0)
{ {
return 0; return 0;
} }
char szAuth[64]; char szAuth[64];
snprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId); snprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId);
pCtx->StringToLocal(local_addr, bytes, szAuth); pCtx->StringToLocal(local_addr, bytes, szAuth);
} }
break; break;
} }
return 1; return 1;
} }
@ -421,7 +421,7 @@ static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
{ {
validate = !!params[4]; validate = !!params[4];
} }
return SteamIdToLocal(pCtx, params[1], AuthIdType::Steam2, params[2], (size_t)params[3], validate); return SteamIdToLocal(pCtx, params[1], AuthIdType::Steam2, params[2], (size_t)params[3], validate);
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -36,7 +36,7 @@
#include <stdint.h> #include <stdint.h>
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include "ProfileTools.h" #include "profiletools.h"
#include <string.h> #include <string.h>
struct Profiler struct Profiler
@ -60,7 +60,7 @@ struct Profiler
HandleType_t g_ProfilerType = 0; HandleType_t g_ProfilerType = 0;
class ProfilerHelpers : class ProfilerHelpers :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch public IHandleTypeDispatch
{ {

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -33,26 +33,26 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "cellarray.h"
#include <IHandleSys.h> #include <IHandleSys.h>
/*********************************** /***********************************
* About the double array hack * * About the double array hack *
*************************** ***************************
Double arrays in Pawn are vectors offset by the current offset. For example: Double arrays in Pawn are vectors offset by the current offset. For example:
new array[2][2] new array[2][2]
In this array, index 0 contains the offset from the current offset which In this array, index 0 contains the offset from the current offset which
results in the final vector [2] (at [0][2]). Meaning, to dereference [1][2], results in the final vector [2] (at [0][2]). Meaning, to dereference [1][2],
it is equivalent to: it is equivalent to:
address = &array[1] + array[1] + 2 * sizeof(cell) address = &array[1] + array[1] + 2 * sizeof(cell)
The fact that each offset is from the _current_ position rather than the _base_ The fact that each offset is from the _current_ position rather than the _base_
position is very important. It means that if you to try to swap vector positions, position is very important. It means that if you to try to swap vector positions,
the offsets will no longer match, because their current position has changed. A the offsets will no longer match, because their current position has changed. A
simple and ingenious way around this is to back up the positions in a separate array, simple and ingenious way around this is to back up the positions in a separate array,
then to overwrite each position in the old array with absolute indices. Pseudo C++ code: then to overwrite each position in the old array with absolute indices. Pseudo C++ code:
@ -72,7 +72,7 @@
for (int i=0; i<2; i++) for (int i=0; i<2; i++)
{ {
//get the # of the vector we want to relocate in //get the # of the vector we want to relocate in
cell vector_index = array[i]; cell vector_index = array[i];
//get the real address of this vector //get the real address of this vector
char *real_address = (char *)array + (vector_index * sizeof(cell)) + old_offsets[vector_index]; char *real_address = (char *)array + (vector_index * sizeof(cell)) + old_offsets[vector_index];
//calc and store the new distance offset //calc and store the new distance offset
@ -97,7 +97,7 @@ void sort_random(cell_t *array, cell_t size)
{ {
int n = rand() % (i + 1); int n = rand() % (i + 1);
if (array[i] != array[n]) if (array[i] != array[n])
{ {
array[i] ^= array[n]; array[i] ^= array[n];
array[n] ^= array[i]; array[n] ^= array[i];
@ -127,7 +127,7 @@ static cell_t sm_SortIntegers(IPluginContext *pContext, const cell_t *params)
if (type == Sort_Ascending) if (type == Sort_Ascending)
{ {
qsort(array, array_size, sizeof(cell_t), sort_ints_asc); qsort(array, array_size, sizeof(cell_t), sort_ints_asc);
} }
else if (type == Sort_Descending) else if (type == Sort_Descending)
{ {
qsort(array, array_size, sizeof(cell_t), sort_ints_desc); qsort(array, array_size, sizeof(cell_t), sort_ints_desc);
@ -144,7 +144,7 @@ int sort_floats_asc(const void *float1, const void *float2)
{ {
float r1 = *(float *)float1; float r1 = *(float *)float1;
float r2 = *(float *)float2; float r2 = *(float *)float2;
if (r1 < r2) if (r1 < r2)
{ {
return -1; return -1;
@ -201,7 +201,7 @@ int sort_strings_asc(const void *blk1, const void *blk2)
{ {
cell_t reloc1 = *(cell_t *)blk1; cell_t reloc1 = *(cell_t *)blk1;
cell_t reloc2 = *(cell_t *)blk2; cell_t reloc2 = *(cell_t *)blk2;
char *str1 = ((char *)(&g_CurStringArray[reloc1]) + g_CurRebaseMap[reloc1]); char *str1 = ((char *)(&g_CurStringArray[reloc1]) + g_CurRebaseMap[reloc1]);
char *str2 = ((char *)(&g_CurStringArray[reloc2]) + g_CurRebaseMap[reloc2]); char *str2 = ((char *)(&g_CurStringArray[reloc2]) + g_CurRebaseMap[reloc2]);
@ -248,7 +248,7 @@ static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params)
if (type == Sort_Ascending) if (type == Sort_Ascending)
{ {
qsort(array, array_size, sizeof(cell_t), sort_strings_asc); qsort(array, array_size, sizeof(cell_t), sort_strings_asc);
} }
else if (type == Sort_Descending) else if (type == Sort_Descending)
{ {
qsort(array, array_size, sizeof(cell_t), sort_strings_desc); qsort(array, array_size, sizeof(cell_t), sort_strings_desc);
@ -392,11 +392,11 @@ static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params)
g_SortInfo.hndl = params[4]; g_SortInfo.hndl = params[4];
g_SortInfo.array_addr = params[1]; g_SortInfo.array_addr = params[1];
g_SortInfo.eh = &eh; g_SortInfo.eh = &eh;
/** Same process as in strings, back up the old indices for later fixup */ /** Same process as in strings, back up the old indices for later fixup */
g_SortInfo.array_base = array; g_SortInfo.array_base = array;
g_SortInfo.array_remap = phys_addr; g_SortInfo.array_remap = phys_addr;
for (int i=0; i<array_size; i++) for (int i=0; i<array_size; i++)
{ {
phys_addr[i] = array[i]; phys_addr[i] = array[i];
@ -417,7 +417,7 @@ static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params)
pContext->HeapPop(amx_addr); pContext->HeapPop(amx_addr);
g_SortInfo = oldinfo; g_SortInfo = oldinfo;
return 1; return 1;
} }
@ -458,14 +458,14 @@ static cell_t sm_SortADTArray(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&cArray))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
} }
cell_t order = params[2]; cell_t order = params[2];
if (order == Sort_Random) if (order == Sort_Random)
{ {
sort_adt_random(cArray); sort_adt_random(cArray);
@ -495,7 +495,7 @@ static cell_t sm_SortADTArray(IPluginContext *pContext, const cell_t *params)
{ {
qsort(array, arraysize, blocksize * sizeof(cell_t), sort_floats_asc); qsort(array, arraysize, blocksize * sizeof(cell_t), sort_floats_asc);
} }
else else
{ {
qsort(array, arraysize, blocksize * sizeof(cell_t), sort_floats_desc); qsort(array, arraysize, blocksize * sizeof(cell_t), sort_floats_desc);
} }
@ -506,7 +506,7 @@ static cell_t sm_SortADTArray(IPluginContext *pContext, const cell_t *params)
{ {
qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_strings_asc); qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_strings_asc);
} }
else else
{ {
qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_strings_desc); qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_strings_desc);
} }
@ -549,7 +549,7 @@ static cell_t sm_SortADTArrayCustom(IPluginContext *pContext, const cell_t *para
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&cArray))
!= HandleError_None) != HandleError_None)
{ {
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
@ -574,7 +574,7 @@ static cell_t sm_SortADTArrayCustom(IPluginContext *pContext, const cell_t *para
g_SortInfoADT.array_hndl = params[1]; g_SortInfoADT.array_hndl = params[1];
g_SortInfoADT.hndl = params[3]; g_SortInfoADT.hndl = params[3];
g_SortInfoADT.eh = &eh; g_SortInfoADT.eh = &eh;
qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_custom); qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_custom);
g_SortInfoADT = oldinfo; g_SortInfoADT = oldinfo;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -35,7 +35,7 @@
#include <ITimerSystem.h> #include <ITimerSystem.h>
#include <IPluginSys.h> #include <IPluginSys.h>
#include <sh_stack.h> #include <sh_stack.h>
#include "DebugReporter.h" #include "debugreporter.h"
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
using namespace SourceHook; using namespace SourceHook;
@ -45,7 +45,7 @@ using namespace SourceHook;
HandleType_t g_TimerType; HandleType_t g_TimerType;
struct TimerInfo struct TimerInfo
{ {
ITimer *Timer; ITimer *Timer;
IPluginFunction *Hook; IPluginFunction *Hook;
@ -160,8 +160,8 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
{ {
if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None) if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None)
{ {
g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(),
SP_ERROR_NATIVE, SP_ERROR_NATIVE,
"Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE", "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE",
usrhndl, herr); usrhndl, herr);
} }
@ -171,9 +171,9 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
{ {
if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None) if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None)
{ {
g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(),
SP_ERROR_NATIVE, SP_ERROR_NATIVE,
"Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace", "Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace",
pInfo->TimerHandle, herr); pInfo->TimerHandle, herr);
} }
} }
@ -220,7 +220,7 @@ static cell_t smn_CreateTimer(IPluginContext *pCtx, const cell_t *params)
hndl = handlesys->CreateHandle(g_TimerType, pInfo, pCtx->GetIdentity(), g_pCoreIdent, NULL); hndl = handlesys->CreateHandle(g_TimerType, pInfo, pCtx->GetIdentity(), g_pCoreIdent, NULL);
/* If we can't get a handle, the timer isn't refcounted against the plugin and /* If we can't get a handle, the timer isn't refcounted against the plugin and
* we need to bail out to prevent a crash. * we need to bail out to prevent a crash.
*/ */
if (hndl == BAD_HANDLE) if (hndl == BAD_HANDLE)

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -35,7 +35,7 @@
#include <sm_platform.h> #include <sm_platform.h>
#include "stringutil.h" #include "stringutil.h"
#include <am-string.h> #include <am-string.h>
#include "TextParsers.h" #include "textparsers.h"
// We're in logic so we don't have this from the SDK. // We're in logic so we don't have this from the SDK.
#ifndef MIN #ifndef MIN
@ -98,7 +98,7 @@ unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search
} }
/** /**
* NOTE: Do not edit this for the love of god unless you have * NOTE: Do not edit this for the love of god unless you have
* read the test cases and understand the code behind each one. * read the test cases and understand the code behind each one.
* While I don't guarantee there aren't mistakes, I do guarantee * While I don't guarantee there aren't mistakes, I do guarantee
* that plugins will end up relying on tiny idiosyncrasies of this * that plugins will end up relying on tiny idiosyncrasies of this
@ -107,7 +107,7 @@ unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search
* There are explicitly more cases than the AMX Mod X version because * There are explicitly more cases than the AMX Mod X version because
* we're not doing a blind copy. Each case is specifically optimized * we're not doing a blind copy. Each case is specifically optimized
* for what needs to be done. Even better, we don't have to error on * for what needs to be done. Even better, we don't have to error on
* bad buffer sizes. Instead, this function will smartly cut off the * bad buffer sizes. Instead, this function will smartly cut off the
* string in a way that pushes old data out. * string in a way that pushes old data out.
*/ */
char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive) char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive)
@ -127,7 +127,7 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se
*/ */
if (maxLen == 1) if (maxLen == 1)
{ {
/* If the search matches and the replace length is 0, /* If the search matches and the replace length is 0,
* we can just terminate the string and be done. * we can just terminate the string and be done.
*/ */
if ((caseSensitive ? strcmp(subject, search) : strcasecmp(subject, search)) == 0 && replaceLen == 0) if ((caseSensitive ? strcmp(subject, search) : strcasecmp(subject, search)) == 0 && replaceLen == 0)
@ -302,7 +302,7 @@ size_t UTIL_DecodeHexString(unsigned char *buffer, size_t maxlength, const char
void UTIL_StripExtension(const char *in, char *out, int outSize) void UTIL_StripExtension(const char *in, char *out, int outSize)
{ {
// Find the last dot. If it's followed by a dot or a slash, then it's part of a // Find the last dot. If it's followed by a dot or a slash, then it's part of a
// directory specifier like ../../somedir/./blah. // directory specifier like ../../somedir/./blah.
// scan backward for '.' // scan backward for '.'
@ -348,7 +348,7 @@ char *UTIL_TrimWhitespace(char *str, size_t &len)
} }
/* Replace first whitespace char (at the end) with null terminator. /* Replace first whitespace char (at the end) with null terminator.
* If there is none, we're just replacing the null terminator. * If there is none, we're just replacing the null terminator.
*/ */
*(end + 1) = '\0'; *(end + 1) = '\0';

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -35,7 +35,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "TextParsers.h" #include "textparsers.h"
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include <am-string.h> #include <am-string.h>
@ -200,7 +200,7 @@ SMCError TextParsers::ParseSMCStream(const char *stream,
return result; return result;
} }
/** /**
* Raw parsing of streams with helper functions * Raw parsing of streams with helper functions
*/ */
@ -286,7 +286,7 @@ const char *rotate(StringInfo info[3])
info[1] = info[0]; info[1] = info[0];
info[0] = StringInfo(); info[0] = StringInfo();
} }
return NULL; return NULL;
} }
@ -322,9 +322,9 @@ char *lowstring(StringInfo info[3])
return NULL; return NULL;
} }
SMCError TextParsers::ParseStream_SMC(void *stream, SMCError TextParsers::ParseStream_SMC(void *stream,
STREAMREADER srdr, STREAMREADER srdr,
ITextListener_SMC *smc, ITextListener_SMC *smc,
SMCStates *pStates) SMCStates *pStates)
{ {
char *reparse_point = NULL; char *reparse_point = NULL;
@ -353,11 +353,11 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
/** /**
* The stream reader reads in as much as it can fill the buffer with. * The stream reader reads in as much as it can fill the buffer with.
* It then processes the buffer. If the buffer cannot be fully processed, for example, * It then processes the buffer. If the buffer cannot be fully processed, for example,
* a line is left hanging with no newline, then the contents of the buffer is shifted * a line is left hanging with no newline, then the contents of the buffer is shifted
* down, and the buffer is filled from the stream reader again. * down, and the buffer is filled from the stream reader again.
* *
* What makes this particularly annoying is that we cache pointers everywhere, so when * What makes this particularly annoying is that we cache pointers everywhere, so when
* the shifting process takes place, all those pointers must be shifted as well. * the shifting process takes place, all those pointers must be shifted as well.
*/ */
while (srdr(stream, parse_point, sizeof(in_buf) - (parse_point - in_buf) - 1, &read)) while (srdr(stream, parse_point, sizeof(in_buf) - (parse_point - in_buf) - 1, &read))
@ -370,9 +370,9 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
/* Check for BOM markings, which is only relevant on the first line. /* Check for BOM markings, which is only relevant on the first line.
* Not worth it, but it could be moved out of the loop. * Not worth it, but it could be moved out of the loop.
*/ */
if (states.line == 1 && if (states.line == 1 &&
in_buf[0] == (char)0xEF && in_buf[0] == (char)0xEF &&
in_buf[1] == (char)0xBB && in_buf[1] == (char)0xBB &&
in_buf[2] == (char)0xBF) in_buf[2] == (char)0xBF)
{ {
/* Move EVERYTHING down :\ */ /* Move EVERYTHING down :\ */
@ -413,7 +413,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
ignoring = false; ignoring = false;
} }
/* Pass the raw line onto the listener. We terminate the line so the receiver /* Pass the raw line onto the listener. We terminate the line so the receiver
* doesn't get tons of useless info. We restore the newline after. * doesn't get tons of useless info. We restore the newline after.
*/ */
parse_point[i] = '\0'; parse_point[i] = '\0';
@ -448,8 +448,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
states.col = 0; states.col = 0;
states.line++; states.line++;
line_begin = &parse_point[i+1]; //Note: safe because this gets relocated later line_begin = &parse_point[i+1]; //Note: safe because this gets relocated later
} }
else if (ignoring) else if (ignoring)
{ {
if (in_quote) if (in_quote)
{ {
@ -470,8 +470,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
err = SMCError_InvalidTokens; err = SMCError_InvalidTokens;
goto failed; goto failed;
} }
} }
else if (c == '\\') else if (c == '\\')
{ {
strings[0].special = true; strings[0].special = true;
if (i == (read - 1)) if (i == (read - 1))
@ -480,8 +480,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
break; break;
} }
} }
} }
else if (ml_comment) else if (ml_comment)
{ {
if (c == '*') if (c == '*')
{ {
@ -503,8 +503,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
} }
} }
} }
} }
else else
{ {
/* Check if we're whitespace or not */ /* Check if we're whitespace or not */
if (!g_ws_chartable[(unsigned char)c]) if (!g_ws_chartable[(unsigned char)c])
@ -538,8 +538,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
ignoring = true; ignoring = true;
eol_comment = true; eol_comment = true;
restage = true; restage = true;
} }
else if (parse_point[i+1] == '*') else if (parse_point[i+1] == '*')
{ {
/* inline comment - start ignoring */ /* inline comment - start ignoring */
ignoring = true; ignoring = true;
@ -551,15 +551,15 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
*/ */
restage = true; restage = true;
} }
} }
else else
{ {
ignoring = true; ignoring = true;
eol_comment = true; eol_comment = true;
restage = true; restage = true;
} }
} }
else if (c == '{') else if (c == '{')
{ {
/* If we are staging a string, we must rotate here */ /* If we are staging a string, we must rotate here */
if (strings[0].ptr) if (strings[0].ptr)
@ -576,7 +576,7 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
{ {
err = SMCError_InvalidSection1; err = SMCError_InvalidSection1;
goto failed; goto failed;
} }
else if (strings[1].ptr == NULL) else if (strings[1].ptr == NULL)
{ {
err = SMCError_InvalidSection2; err = SMCError_InvalidSection2;
@ -590,8 +590,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
} }
strings[1] = emptystring; strings[1] = emptystring;
curlevel++; curlevel++;
} }
else if (c == '}') else if (c == '}')
{ {
/* Unlike our matching friend, this can be on the same line as something prior */ /* Unlike our matching friend, this can be on the same line as something prior */
if (rotate(strings) != NULL) if (rotate(strings) != NULL)
@ -615,13 +615,13 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
err = (res == SMCResult_HaltFail) ? SMCError_Custom : SMCError_Okay; err = (res == SMCResult_HaltFail) ? SMCError_Custom : SMCError_Okay;
goto failed; goto failed;
} }
} }
else if (strings[1].ptr) else if (strings[1].ptr)
{ {
err = SMCError_InvalidSection3; err = SMCError_InvalidSection3;
goto failed; goto failed;
} }
else if (!curlevel) else if (!curlevel)
{ {
err = SMCError_InvalidSection4; err = SMCError_InvalidSection4;
goto failed; goto failed;
@ -634,8 +634,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
goto failed; goto failed;
} }
curlevel--; curlevel--;
} }
else if (c == '"') else if (c == '"')
{ {
/* If we get a quote mark, we always restage, but we need to do it beforehand */ /* If we get a quote mark, we always restage, but we need to do it beforehand */
if (strings[0].ptr) if (strings[0].ptr)
@ -650,8 +650,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
strings[0].ptr = &parse_point[i]; strings[0].ptr = &parse_point[i];
in_quote = true; in_quote = true;
ignoring = true; ignoring = true;
} }
else if (!strings[0].ptr) else if (!strings[0].ptr)
{ {
/* If we have no string, we must start one */ /* If we have no string, we must start one */
strings[0].ptr = &parse_point[i]; strings[0].ptr = &parse_point[i];
@ -665,8 +665,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
goto failed; goto failed;
} }
} }
} }
else else
{ {
/* If we're eating a string and get whitespace, we need to restage. /* If we're eating a string and get whitespace, we need to restage.
* (Note that if we are quoted, this is being ignored) * (Note that if we are quoted, this is being ignored)
@ -683,8 +683,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
/* There's no string, so we must move this one down and eat up another */ /* There's no string, so we must move this one down and eat up another */
strings[0].end = &parse_point[i]; strings[0].end = &parse_point[i];
rotate(strings); rotate(strings);
} }
else if (!strings[1].quoted) else if (!strings[1].quoted)
{ {
err = SMCError_InvalidTokens; err = SMCError_InvalidTokens;
goto failed; goto failed;
@ -728,8 +728,8 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
parse_point = &parse_point[read]; parse_point = &parse_point[read];
parse_point -= bytes; parse_point -= bytes;
} }
} }
else if (read == sizeof(in_buf) - 1) else if (read == sizeof(in_buf) - 1)
{ {
err = SMCError_TokenOverflow; err = SMCError_TokenOverflow;
goto failed; goto failed;
@ -741,15 +741,15 @@ SMCError TextParsers::ParseStream_SMC(void *stream,
{ {
err = SMCError_InvalidSection5; err = SMCError_InvalidSection5;
goto failed; goto failed;
} }
else if (strings[0].ptr || strings[1].ptr) else if (strings[0].ptr || strings[1].ptr)
{ {
err = SMCError_InvalidTokens; err = SMCError_InvalidTokens;
goto failed; goto failed;
} }
smc->ReadSMC_ParseEnd(false, false); smc->ReadSMC_ParseEnd(false, false);
if (pStates != NULL) if (pStates != NULL)
{ {
*pStates = states; *pStates = states;
@ -770,7 +770,7 @@ failed:
/** /**
* INI parser * INI parser
*/ */
bool TextParsers::ParseFile_INI(const char *file, ITextListener_INI *ini_listener, unsigned int *line, unsigned int *col) bool TextParsers::ParseFile_INI(const char *file, ITextListener_INI *ini_listener, unsigned int *line, unsigned int *col)
@ -806,9 +806,9 @@ bool TextParsers::ParseFile_INI(const char *file, ITextListener_INI *ini_listene
//:TODO: this will only run once, so find a nice way to move it out of the while loop //:TODO: this will only run once, so find a nice way to move it out of the while loop
/* If this is the first line, check the first three bytes for BOM */ /* If this is the first line, check the first three bytes for BOM */
if (curline == 1 && if (curline == 1 &&
buffer[0] == (char)0xEF && buffer[0] == (char)0xEF &&
buffer[1] == (char)0xBB && buffer[1] == (char)0xBB &&
buffer[2] == (char)0xBF) buffer[2] == (char)0xBF)
{ {
/* We have a UTF-8 marked file... skip these bytes */ /* We have a UTF-8 marked file... skip these bytes */
@ -1073,7 +1073,7 @@ event_failed:
const char *TextParsers::GetSMCErrorString(SMCError err) const char *TextParsers::GetSMCErrorString(SMCError err)
{ {
static const char *s_errors[] = static const char *s_errors[] =
{ {
NULL, NULL,
"Stream failed to open", "Stream failed to open",

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,9 +29,9 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "BaseWorker.h" #include "baseworker.h"
BaseWorker::BaseWorker(IThreadWorkerCallbacks *hooks) : BaseWorker::BaseWorker(IThreadWorkerCallbacks *hooks) :
m_perFrame(SM_DEFAULT_THREADS_PER_FRAME), m_perFrame(SM_DEFAULT_THREADS_PER_FRAME),
m_state(Worker_Stopped), m_state(Worker_Stopped),
m_pHooks(hooks) m_pHooks(hooks)
@ -287,7 +287,7 @@ bool SWThreadHandle::WaitForThread()
return false; return false;
} }
SWThreadHandle::SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread) : SWThreadHandle::SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread) :
m_state(Thread_Paused), m_params(*p), m_parent(parent), pThread(thread) m_state(Thread_Paused), m_params(*p), m_parent(parent), pThread(thread)
{ {
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -33,7 +33,7 @@
#define _INCLUDE_SOURCEMOD_BASEWORKER_H #define _INCLUDE_SOURCEMOD_BASEWORKER_H
#include "sh_list.h" #include "sh_list.h"
#include "ThreadSupport.h" #include "threadsupport.h"
#define SM_DEFAULT_THREADS_PER_FRAME 1 #define SM_DEFAULT_THREADS_PER_FRAME 1

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -30,8 +30,8 @@
*/ */
#include <unistd.h> #include <unistd.h>
#include "PosixThreads.h" #include "posixthreads.h"
#include "ThreadWorker.h" #include "threadworker.h"
IThreadWorker *PosixThreader::MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded) IThreadWorker *PosixThreader::MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded)
{ {
@ -128,7 +128,7 @@ IEventSignal *PosixThreader::MakeEventSignal()
* Thread Handles * * Thread Handles *
******************/ ******************/
PosixThreader::ThreadHandle::ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params) : PosixThreader::ThreadHandle::ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params) :
m_parent(parent), m_params(*params), m_run(run), m_state(Thread_Paused) m_parent(parent), m_params(*params), m_run(run), m_state(Thread_Paused)
{ {
} }

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,7 +29,7 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "ThreadWorker.h" #include "threadworker.h"
ThreadWorker::ThreadWorker(IThreadWorkerCallbacks *hooks) : BaseWorker(hooks), ThreadWorker::ThreadWorker(IThreadWorkerCallbacks *hooks) : BaseWorker(hooks),
m_Threader(NULL), m_Threader(NULL),
@ -39,7 +39,7 @@ ThreadWorker::ThreadWorker(IThreadWorkerCallbacks *hooks) : BaseWorker(hooks),
m_state = Worker_Invalid; m_state = Worker_Invalid;
} }
ThreadWorker::ThreadWorker(IThreadWorkerCallbacks *hooks, IThreader *pThreader, unsigned int thinktime) : ThreadWorker::ThreadWorker(IThreadWorkerCallbacks *hooks, IThreader *pThreader, unsigned int thinktime) :
BaseWorker(hooks), BaseWorker(hooks),
m_Threader(pThreader), m_Threader(pThreader),
me(NULL), me(NULL),
@ -52,7 +52,7 @@ ThreadWorker::~ThreadWorker()
{ {
if (m_state != Worker_Stopped || m_state != Worker_Invalid) if (m_state != Worker_Stopped || m_state != Worker_Invalid)
Stop(true); Stop(true);
if (m_ThreadQueue.size()) if (m_ThreadQueue.size())
Flush(true); Flush(true);
} }
@ -106,7 +106,7 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle)
// If the state changed, loop back and process the new state. // If the state changed, loop back and process the new state.
if (m_state != oldstate) if (m_state != oldstate)
continue; continue;
// If the thread queue is now empty, wait for a signal. Otherwise, if // If the thread queue is now empty, wait for a signal. Otherwise, if
// we're on a delay, wait for either a notification or a timeout to // we're on a delay, wait for either a notification or a timeout to
// process the next item. If the queue has items and we don't have a // process the next item. If the queue has items and we don't have a

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -32,7 +32,7 @@
#ifndef _INCLUDE_SOURCEMOD_THREADWORKER_H #ifndef _INCLUDE_SOURCEMOD_THREADWORKER_H
#define _INCLUDE_SOURCEMOD_THREADWORKER_H #define _INCLUDE_SOURCEMOD_THREADWORKER_H
#include "BaseWorker.h" #include "baseworker.h"
#define DEFAULT_THINK_TIME_MS 20 #define DEFAULT_THINK_TIME_MS 20

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -30,8 +30,8 @@
*/ */
#define _WIN32_WINNT 0x0400 #define _WIN32_WINNT 0x0400
#include "WinThreads.h" #include "winthreads.h"
#include "ThreadWorker.h" #include "threadworker.h"
IThreadWorker *WinThreader::MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded) IThreadWorker *WinThreader::MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded)
{ {
@ -86,7 +86,7 @@ void WinThreader::ThreadHandle::Run()
if (m_state == Thread_Paused) if (m_state == Thread_Paused)
suspend_.Wait(); suspend_.Wait();
} }
m_run->RunThread(this); m_run->RunThread(this);
m_state = Thread_Done; m_state = Thread_Done;
m_run->OnTerminate(this, false); m_run->OnTerminate(this, false);
@ -130,7 +130,7 @@ IEventSignal *WinThreader::MakeEventSignal()
* Thread Handles * * Thread Handles *
******************/ ******************/
WinThreader::ThreadHandle::ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params) : WinThreader::ThreadHandle::ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params) :
m_parent(parent), m_run(run), m_params(*params), m_parent(parent), m_run(run), m_params(*params),
m_state(Thread_Paused) m_state(Thread_Paused)
{ {

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -29,13 +29,13 @@
* Version: $Id$ * Version: $Id$
*/ */
#include <sm_platform.h> #include <sm_platform.h>
#include "ThreadSupport.h" #include "threadsupport.h"
#include "common_logic.h" #include "common_logic.h"
#if defined PLATFORM_POSIX #if defined PLATFORM_POSIX
#include "thread/PosixThreads.h" #include "thread/posixthreads.h"
#elif defined PLATFORM_WINDOWS #elif defined PLATFORM_WINDOWS
#include "thread/WinThreads.h" #include "thread/winthreads.h"
#endif #endif
MainThreader g_MainThreader; MainThreader g_MainThreader;

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -34,11 +34,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <sm_platform.h> #include <sm_platform.h>
#include "Translator.h" #include "translator.h"
#include <IPlayerHelpers.h> #include <IPlayerHelpers.h>
#include <ISourceMod.h> #include <ISourceMod.h>
#include <ILibrarySys.h> #include <ILibrarySys.h>
#include "PhraseCollection.h" #include "phrasecollection.h"
#include "stringutil.h" #include "stringutil.h"
#include "sprintf.h" #include "sprintf.h"
#include <am-string.h> #include <am-string.h>
@ -158,7 +158,7 @@ void CPhraseFile::ReparseFile()
continue; continue;
} }
g_pSM->BuildPath(Path_SM, g_pSM->BuildPath(Path_SM,
path, path,
PLATFORM_MAX_PATH, PLATFORM_MAX_PATH,
"translations/%s/%s", "translations/%s/%s",
@ -179,8 +179,8 @@ void CPhraseFile::ReparseFile()
msg = m_ParseError.c_str(); msg = m_ParseError.c_str();
} }
logger->LogError("[SM] Fatal error encountered parsing translation file \"%s/%s\"", logger->LogError("[SM] Fatal error encountered parsing translation file \"%s/%s\"",
code, code,
m_File.c_str()); m_File.c_str());
logger->LogError("[SM] Error (line %d, column %d): %s", logger->LogError("[SM] Error (line %d, column %d): %s",
states.line, states.line,
@ -208,8 +208,8 @@ SMCResult CPhraseFile::ReadSMC_NewSection(const SMCStates *states, const char *n
m_ParseState = PPS_Phrases; m_ParseState = PPS_Phrases;
recognized = true; recognized = true;
} }
} }
else if (m_ParseState == PPS_Phrases) else if (m_ParseState == PPS_Phrases)
{ {
m_ParseState = PPS_InPhrase; m_ParseState = PPS_InPhrase;
recognized = true; recognized = true;
@ -241,8 +241,8 @@ SMCResult CPhraseFile::ReadSMC_NewSection(const SMCStates *states, const char *n
} }
m_LastPhraseString.assign(name); m_LastPhraseString.assign(name);
} }
else if (m_ParseState == PPS_InPhrase) else if (m_ParseState == PPS_InPhrase)
{ {
ParseError("Phrase sections may not have sub-sections"); ParseError("Phrase sections may not have sub-sections");
return SMCResult_HaltFail; return SMCResult_HaltFail;
@ -267,7 +267,7 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
phrase_t *pPhrase = (phrase_t *)m_pMemory->GetAddress(m_CurPhrase); phrase_t *pPhrase = (phrase_t *)m_pMemory->GetAddress(m_CurPhrase);
/* Duplicate format keys get silently ignored. */ /* Duplicate format keys get silently ignored. */
if (key[0] == '#' if (key[0] == '#'
&& strcmp(key, "#format") == 0 && strcmp(key, "#format") == 0
&& pPhrase->fmt_list == -1) && pPhrase->fmt_list == -1)
{ {
@ -297,12 +297,12 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
{ {
pPhrase->fmt_count++; pPhrase->fmt_count++;
state = Parse_Index; state = Parse_Index;
} }
else if (*value == ',') else if (*value == ',')
{ {
/* Do nothing */ /* Do nothing */
} }
else else
{ {
unsigned int bytes = textparsers->GetUTF8CharBytes(value); unsigned int bytes = textparsers->GetUTF8CharBytes(value);
if (bytes != 1 || !isalpha(*value)) if (bytes != 1 || !isalpha(*value))
@ -310,8 +310,8 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
ParseWarning("Invalid token '%c' in #format property on line %d.", *value, states->line); ParseWarning("Invalid token '%c' in #format property on line %d.", *value, states->line);
} }
} }
} }
else if (state == Parse_Index) else if (state == Parse_Index)
{ {
if (*value == ':') if (*value == ':')
{ {
@ -322,8 +322,8 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
m_CurPhrase = -1; m_CurPhrase = -1;
return SMCResult_Continue; return SMCResult_Continue;
} }
} }
else else
{ {
unsigned int bytes = textparsers->GetUTF8CharBytes(value); unsigned int bytes = textparsers->GetUTF8CharBytes(value);
if (bytes != 1 || !isdigit(*value)) if (bytes != 1 || !isdigit(*value))
@ -335,8 +335,8 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
return SMCResult_Continue; return SMCResult_Continue;
} }
} }
} }
else if (state == Parse_Format) else if (state == Parse_Format)
{ {
if (*value == '}') if (*value == '}')
{ {
@ -387,7 +387,7 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
idx_ptr = NULL; idx_ptr = NULL;
} }
} }
else if (state == Parse_Index) else if (state == Parse_Index)
{ {
if (*in_ptr == ':') if (*in_ptr == ':')
{ {
@ -405,7 +405,7 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
m_CurPhrase = -1; m_CurPhrase = -1;
return SMCResult_Continue; return SMCResult_Continue;
} }
else if (fmt_list[idx - 1] != -1) else if (fmt_list[idx - 1] != -1)
{ {
ParseWarning("Format property contains duplicated index '%d' on line %d, phrase will be ignored.", idx, states->line); ParseWarning("Format property contains duplicated index '%d' on line %d, phrase will be ignored.", idx, states->line);
m_CurPhrase = -1; m_CurPhrase = -1;
@ -415,12 +415,12 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
state = Parse_Format; state = Parse_Format;
out_ptr = NULL; out_ptr = NULL;
} }
else if (!idx_ptr) else if (!idx_ptr)
{ {
idx_ptr = in_ptr; idx_ptr = in_ptr;
} }
} }
else if (state == Parse_Format) else if (state == Parse_Format)
{ {
if (*in_ptr == '}') if (*in_ptr == '}')
{ {
@ -439,8 +439,8 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
pPhrase->fmt_bytes += strlen(fmt_buf); pPhrase->fmt_bytes += strlen(fmt_buf);
fmt_list = (int *)m_pMemory->GetAddress(pPhrase->fmt_list); fmt_list = (int *)m_pMemory->GetAddress(pPhrase->fmt_list);
fmt_list[cur_idx - 1] = tmp_idx; fmt_list[cur_idx - 1] = tmp_idx;
} }
else else
{ {
if (!out_ptr) if (!out_ptr)
{ {
@ -475,8 +475,8 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
return SMCResult_Continue; return SMCResult_Continue;
} }
} }
} }
else else
{ {
unsigned int lang; unsigned int lang;
if (!m_pTranslator->GetLanguageByCode(key, &lang)) if (!m_pTranslator->GetLanguageByCode(key, &lang))
@ -488,7 +488,7 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
} }
/* See how many bytes we need for this string, then allocate. /* See how many bytes we need for this string, then allocate.
* NOTE: THIS SHOULD GUARANTEE THAT WE DO NOT NEED TO NEED TO SIZE CHECK * NOTE: THIS SHOULD GUARANTEE THAT WE DO NOT NEED TO NEED TO SIZE CHECK
*/ */
size_t len = strlen(value) + pPhrase->fmt_bytes + 1; size_t len = strlen(value) + pPhrase->fmt_bytes + 1;
char *out_buf; char *out_buf;
@ -512,7 +512,7 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
if (fmt_list) if (fmt_list)
{ {
int tmp = m_pMemory->CreateMem(pPhrase->fmt_count * sizeof(int), (void **)&fmt_order); int tmp = m_pMemory->CreateMem(pPhrase->fmt_count * sizeof(int), (void **)&fmt_order);
/* Update pointers */ /* Update pointers */
pPhrase = (phrase_t *)m_pMemory->GetAddress(m_CurPhrase); pPhrase = (phrase_t *)m_pMemory->GetAddress(m_CurPhrase);
pTrans = (trans_t *)m_pMemory->GetAddress(pPhrase->trans_tbl); pTrans = (trans_t *)m_pMemory->GetAddress(pPhrase->trans_tbl);
@ -559,8 +559,8 @@ SMCResult CPhraseFile::ReadSMC_KeyValue(const SMCStates *states, const char *key
} }
/* Skip past the last byte read */ /* Skip past the last byte read */
in_ptr++; in_ptr++;
} }
else if (*in_ptr == '{' && fmt_list != NULL) else if (*in_ptr == '{' && fmt_list != NULL)
{ {
/* Search for parameters if this is a formatted string */ /* Search for parameters if this is a formatted string */
const char *scrap_in_point = in_ptr; const char *scrap_in_point = in_ptr;
@ -628,8 +628,8 @@ SMCResult CPhraseFile::ReadSMC_LeavingSection(const SMCStates *states)
m_CurPhrase = -1; m_CurPhrase = -1;
m_ParseState = PPS_Phrases; m_ParseState = PPS_Phrases;
m_LastPhraseString.assign(""); m_LastPhraseString.assign("");
} }
else if (m_ParseState == PPS_Phrases) else if (m_ParseState == PPS_Phrases)
{ {
m_ParseState = PPS_None; m_ParseState = PPS_None;
} }
@ -702,10 +702,10 @@ Translator::~Translator()
delete m_pStringTab; delete m_pStringTab;
} }
ConfigResult Translator::OnSourceModConfigChanged(const char *key, ConfigResult Translator::OnSourceModConfigChanged(const char *key,
const char *value, const char *value,
ConfigSource source, ConfigSource source,
char *error, char *error,
size_t maxlength) size_t maxlength)
{ {
if (strcasecmp(key, "ServerLang") == 0) if (strcasecmp(key, "ServerLang") == 0)
@ -807,7 +807,7 @@ unsigned int Translator::FindOrAddPhraseFile(const char *phrase_file)
CPhraseFile *pFile = new CPhraseFile(this, phrase_file); CPhraseFile *pFile = new CPhraseFile(this, phrase_file);
unsigned int idx = (unsigned int)m_Files.size(); unsigned int idx = (unsigned int)m_Files.size();
m_Files.push_back(pFile); m_Files.push_back(pFile);
pFile->ReparseFile(); pFile->ReparseFile();
@ -941,7 +941,7 @@ bool Translator::AddLanguage(const char *langcode, const char *description)
m_Languages.push_back(pLanguage); m_Languages.push_back(pLanguage);
} }
m_LAliases.insert(lower, idx); m_LAliases.insert(lower, idx);
return true; return true;
@ -1035,8 +1035,8 @@ bool CoreTranslate(char *buffer, size_t maxlength, const char *format, unsigned
va_end(ap); va_end(ap);
if (!g_pCorePhrases->FormatString(buffer, if (!g_pCorePhrases->FormatString(buffer,
maxlength, maxlength,
format, format,
params, params,
numparams, numparams,
pOutLength, pOutLength,

View File

@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -37,9 +37,9 @@
#include <sh_string.h> #include <sh_string.h>
#include <sh_vector.h> #include <sh_vector.h>
#include "sm_memtable.h" #include "sm_memtable.h"
#include "ITextParsers.h" #include <ITextParsers.h>
#include <ITranslator.h> #include <ITranslator.h>
#include "PhraseCollection.h" #include "phrasecollection.h"
/* :TODO: write a templatized version of tries? */ /* :TODO: write a templatized version of tries? */
@ -60,7 +60,7 @@ struct Language
int m_CanonicalName; int m_CanonicalName;
}; };
class CPhraseFile : class CPhraseFile :
public ITextListener_SMC, public ITextListener_SMC,
public IPhraseFile public IPhraseFile
{ {
@ -94,7 +94,7 @@ private:
bool m_FileLogged; bool m_FileLogged;
}; };
class Translator : class Translator :
public ITextListener_SMC, public ITextListener_SMC,
public SMGlobalClass, public SMGlobalClass,
public ITranslator public ITranslator
@ -103,10 +103,10 @@ public:
Translator(); Translator();
~Translator(); ~Translator();
public: // SMGlobalClass public: // SMGlobalClass
ConfigResult OnSourceModConfigChanged(const char *key, ConfigResult OnSourceModConfigChanged(const char *key,
const char *value, const char *value,
ConfigSource source, ConfigSource source,
char *error, char *error,
size_t maxlength); size_t maxlength);
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModLevelChange(const char *mapName); void OnSourceModLevelChange(const char *mapName);
@ -132,8 +132,8 @@ public: //ITranslator
int SetGlobalTarget(int index); int SetGlobalTarget(int index);
int GetGlobalTarget() const; int GetGlobalTarget() const;
size_t FormatString( size_t FormatString(
char *buffer, char *buffer,
size_t maxlength, size_t maxlength,
SourcePawn::IPluginContext *pContext, SourcePawn::IPluginContext *pContext,
const cell_t *params, const cell_t *params,
unsigned int param); unsigned int param);
@ -163,7 +163,7 @@ private:
}; };
/* Nice little wrapper to handle error logging and whatnot */ /* Nice little wrapper to handle error logging and whatnot */
bool CoreTranslate(char *buffer, bool CoreTranslate(char *buffer,
size_t maxlength, size_t maxlength,
const char *format, const char *format,
unsigned int numparams, unsigned int numparams,