2009-05-14 03:55:50 +02:00
|
|
|
/**
|
2013-08-22 23:05:44 +02:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet:
|
2009-05-14 03:55:50 +02:00
|
|
|
* =============================================================================
|
|
|
|
* SourceMod
|
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* "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
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
#include <new>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sm_platform.h>
|
|
|
|
#include <string.h>
|
2013-02-17 02:01:53 +01:00
|
|
|
#include <stdarg.h>
|
2009-05-14 03:55:50 +02:00
|
|
|
#include "common_logic.h"
|
|
|
|
#include "TextParsers.h"
|
2010-01-18 12:08:52 +01:00
|
|
|
#include "sm_crc32.h"
|
2010-05-15 01:14:59 +02:00
|
|
|
#include "MemoryUtils.h"
|
2010-05-15 04:28:10 +02:00
|
|
|
#include "stringutil.h"
|
2011-06-15 23:02:05 +02:00
|
|
|
#include "ThreadSupport.h"
|
2010-05-15 04:43:53 +02:00
|
|
|
#include "Translator.h"
|
2010-05-15 08:35:42 +02:00
|
|
|
#include "GameConfigs.h"
|
2013-02-17 00:57:00 +01:00
|
|
|
#include "DebugReporter.h"
|
2013-03-29 19:37:29 +01:00
|
|
|
#include "PluginSys.h"
|
|
|
|
#include "ShareSys.h"
|
|
|
|
#include "NativeOwner.h"
|
|
|
|
#include "HandleSys.h"
|
|
|
|
#include "ExtensionSys.h"
|
2013-10-09 14:43:08 +02:00
|
|
|
#include "ForwardSys.h"
|
2014-05-29 19:31:12 +02:00
|
|
|
#include "AdminCache.h"
|
2014-06-24 10:04:13 +02:00
|
|
|
#include "ProfileTools.h"
|
2014-08-13 23:24:35 +02:00
|
|
|
#include "Logger.h"
|
2015-08-17 04:10:50 +02:00
|
|
|
#include "frame_tasks.h"
|
2015-08-26 08:28:50 +02:00
|
|
|
#include "sprintf.h"
|
2015-08-27 23:09:59 +02:00
|
|
|
#include "LibrarySys.h"
|
2015-08-28 20:08:25 +02:00
|
|
|
#include "RootConsoleMenu.h"
|
2015-09-06 06:10:32 +02:00
|
|
|
#include "CDataPack.h"
|
2015-08-31 06:27:32 +02:00
|
|
|
#include <bridge/include/BridgeAPI.h>
|
|
|
|
#include <bridge/include/IProviderCallbacks.h>
|
2009-05-14 03:55:50 +02:00
|
|
|
|
|
|
|
SMGlobalClass *SMGlobalClass::head = NULL;
|
2015-08-30 01:23:50 +02:00
|
|
|
|
|
|
|
CoreProvider *bridge = nullptr;
|
|
|
|
ISourceMod *g_pSM = nullptr;
|
2015-08-31 04:26:33 +02:00
|
|
|
IVEngineServerBridge *engine = nullptr;
|
2015-08-30 01:23:50 +02:00
|
|
|
IdentityToken_t *g_pCoreIdent = nullptr;
|
|
|
|
ITimerSystem *timersys = nullptr;
|
|
|
|
IGameHelpers *gamehelpers = nullptr;
|
|
|
|
IMenuManager *menus = nullptr;
|
|
|
|
IPlayerManager *playerhelpers = nullptr;
|
|
|
|
|
|
|
|
IHandleSys *handlesys = &g_HandleSys;
|
2015-08-27 23:09:59 +02:00
|
|
|
ILibrarySys *libsys = &g_LibSys;
|
2009-05-14 03:55:50 +02:00
|
|
|
ITextParsers *textparser = &g_TextParser;
|
2013-03-29 19:37:29 +01:00
|
|
|
IShareSys *sharesys = &g_ShareSys;
|
2015-08-28 20:08:25 +02:00
|
|
|
IRootConsole *rootmenu = &g_RootMenu;
|
2013-03-29 19:37:29 +01:00
|
|
|
IPluginManager *pluginsys = g_PluginSys.GetOldAPI();
|
2013-10-09 14:43:08 +02:00
|
|
|
IForwardManager *forwardsys = &g_Forwards;
|
2010-05-13 10:47:12 +02:00
|
|
|
ServerGlobals serverGlobals;
|
2014-05-29 19:31:12 +02:00
|
|
|
IAdminSystem *adminsys = &g_Admins;
|
2013-02-17 00:57:00 +01:00
|
|
|
ISourcePawnEngine *g_pSourcePawn;
|
|
|
|
ISourcePawnEngine2 *g_pSourcePawn2;
|
2013-03-29 19:37:29 +01:00
|
|
|
IScriptManager *scripts = &g_PluginSys;
|
2014-08-17 17:11:55 +02:00
|
|
|
IExtensionSys *extsys = &g_Extensions;
|
2014-08-13 23:24:35 +02:00
|
|
|
ILogger *logger = &g_Logger;
|
2015-08-30 01:23:50 +02:00
|
|
|
CNativeOwner g_CoreNatives;
|
2009-05-14 03:55:50 +02:00
|
|
|
|
2010-05-15 04:43:53 +02:00
|
|
|
static void AddCorePhraseFile(const char *filename)
|
|
|
|
{
|
2012-05-24 16:59:53 +02:00
|
|
|
g_pCorePhrases->AddPhraseFile(filename);
|
2010-05-15 04:43:53 +02:00
|
|
|
}
|
|
|
|
|
2010-05-15 08:35:42 +02:00
|
|
|
static IGameConfig *GetCoreGameConfig()
|
|
|
|
{
|
|
|
|
return g_pGameConf;
|
|
|
|
}
|
|
|
|
|
2013-02-17 00:57:00 +01:00
|
|
|
static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, msg);
|
|
|
|
g_DbgReporter.GenerateErrorVA(ctx, idx, err, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2013-03-29 19:37:29 +01:00
|
|
|
static void AddNatives(sp_nativeinfo_t *natives)
|
|
|
|
{
|
|
|
|
g_CoreNatives.AddNatives(natives);
|
|
|
|
}
|
|
|
|
|
2014-06-24 10:04:13 +02:00
|
|
|
static void RegisterProfiler(IProfilingTool *tool)
|
|
|
|
{
|
|
|
|
g_ProfileToolManager.RegisterTool(tool);
|
|
|
|
}
|
|
|
|
|
2015-08-28 20:08:25 +02:00
|
|
|
static void OnRootCommand(const ICommandArgs *args)
|
|
|
|
{
|
|
|
|
g_RootMenu.GotRootCmd(args);
|
|
|
|
}
|
|
|
|
|
2015-08-30 04:10:59 +02:00
|
|
|
// Defined in smn_filesystem.cpp.
|
|
|
|
extern bool OnLogPrint(const char *msg);
|
|
|
|
|
|
|
|
class ProviderCallbackListener : public IProviderCallbacks
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool OnLogPrint(const char *msg) override {
|
|
|
|
return ::OnLogPrint(msg);
|
|
|
|
}
|
2015-08-17 04:10:50 +02:00
|
|
|
void OnThink(bool simulating) override {
|
|
|
|
RunScheduledFrameTasks(simulating);
|
|
|
|
}
|
2015-08-30 04:10:59 +02:00
|
|
|
} sProviderCallbackListener;
|
|
|
|
|
2009-05-14 03:55:50 +02:00
|
|
|
static sm_logic_t logic =
|
|
|
|
{
|
|
|
|
NULL,
|
2009-12-15 08:08:15 +01:00
|
|
|
g_pThreader,
|
2010-05-15 04:43:53 +02:00
|
|
|
&g_Translator,
|
|
|
|
stristr,
|
2015-08-26 08:28:50 +02:00
|
|
|
atcprintf,
|
2010-05-15 04:43:53 +02:00
|
|
|
CoreTranslate,
|
2010-05-15 05:04:30 +02:00
|
|
|
AddCorePhraseFile,
|
|
|
|
UTIL_ReplaceAll,
|
2010-05-15 08:35:42 +02:00
|
|
|
UTIL_ReplaceEx,
|
|
|
|
UTIL_DecodeHexString,
|
2013-02-17 00:52:11 +01:00
|
|
|
GetCoreGameConfig,
|
2013-02-17 00:57:00 +01:00
|
|
|
&g_DbgReporter,
|
2013-03-29 19:37:29 +01:00
|
|
|
GenerateError,
|
|
|
|
AddNatives,
|
2014-06-24 10:04:13 +02:00
|
|
|
RegisterProfiler,
|
2015-08-28 20:08:25 +02:00
|
|
|
OnRootCommand,
|
2015-09-06 06:10:32 +02:00
|
|
|
CDataPack::New,
|
|
|
|
CDataPack::Free,
|
2013-03-29 19:37:29 +01:00
|
|
|
&g_PluginSys,
|
|
|
|
&g_ShareSys,
|
|
|
|
&g_Extensions,
|
|
|
|
&g_HandleSys,
|
2013-10-09 14:43:08 +02:00
|
|
|
&g_Forwards,
|
2014-05-29 19:31:12 +02:00
|
|
|
&g_Admins,
|
2013-03-29 19:37:29 +01:00
|
|
|
NULL,
|
2014-08-13 23:24:35 +02:00
|
|
|
&g_Logger,
|
2015-08-28 20:08:25 +02:00
|
|
|
&g_RootMenu,
|
2015-08-30 04:10:59 +02:00
|
|
|
&sProviderCallbackListener,
|
2013-03-29 19:37:29 +01:00
|
|
|
-1.0f
|
2009-05-14 03:55:50 +02:00
|
|
|
};
|
|
|
|
|
2015-08-30 01:23:50 +02:00
|
|
|
static void logic_init(CoreProvider* core, sm_logic_t* _logic)
|
2009-05-14 03:55:50 +02:00
|
|
|
{
|
|
|
|
logic.head = SMGlobalClass::head;
|
|
|
|
|
2015-08-30 01:23:50 +02:00
|
|
|
bridge = core;
|
2009-05-14 03:55:50 +02:00
|
|
|
memcpy(_logic, &logic, sizeof(sm_logic_t));
|
2010-05-13 10:47:12 +02:00
|
|
|
memcpy(&serverGlobals, core->serverGlobals, sizeof(ServerGlobals));
|
2009-05-14 03:55:50 +02:00
|
|
|
|
|
|
|
engine = core->engine;
|
|
|
|
g_pSM = core->sm;
|
2010-05-13 10:47:12 +02:00
|
|
|
timersys = core->timersys;
|
2010-05-13 21:28:51 +02:00
|
|
|
playerhelpers = core->playerhelpers;
|
2010-05-15 08:35:42 +02:00
|
|
|
gamehelpers = core->gamehelpers;
|
2014-09-05 03:01:12 +02:00
|
|
|
menus = core->menus;
|
2013-02-19 02:13:08 +01:00
|
|
|
g_pSourcePawn = *core->spe1;
|
|
|
|
g_pSourcePawn2 = *core->spe2;
|
2013-08-22 23:05:44 +02:00
|
|
|
SMGlobalClass::head = core->listeners;
|
2013-03-29 19:37:29 +01:00
|
|
|
|
|
|
|
g_ShareSys.Initialize();
|
|
|
|
g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
|
|
|
|
|
|
|
|
_logic->core_ident = g_pCoreIdent;
|
2009-05-14 03:55:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PLATFORM_EXTERN_C ITextParsers *get_textparsers()
|
|
|
|
{
|
|
|
|
return &g_TextParser;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLATFORM_EXTERN_C LogicInitFunction logic_load(uint32_t magic)
|
|
|
|
{
|
|
|
|
if (magic != SM_LOGIC_MAGIC)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return logic_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoreNativesToAdd::OnSourceModAllInitialized()
|
|
|
|
{
|
2013-03-29 19:37:29 +01:00
|
|
|
g_CoreNatives.AddNatives(m_NativeList);
|
2009-05-14 03:55:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Overload a few things to prevent libstdc++ linking */
|
|
|
|
#if defined __linux__ || defined __APPLE__
|
|
|
|
extern "C" void __cxa_pure_virtual(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void *operator new(size_t size)
|
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *operator new[](size_t size)
|
|
|
|
{
|
|
|
|
return malloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete(void *ptr)
|
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete[](void * ptr)
|
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|