2 * vim: set ts=4 sw=4 tw=99 noet:
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
33 #include <sm_platform.h>
36 #include "common_logic.h"
37 #include "TextParsers.h"
40 #include "MemoryUtils.h"
41 #include "stringutil.h"
42 #include "ThreadSupport.h"
43 #include "Translator.h"
44 #include "GameConfigs.h"
45 #include "DebugReporter.h"
46 #include "PluginSys.h"
48 #include "NativeOwner.h"
49 #include "HandleSys.h"
50 #include "ExtensionSys.h"
53 IHandleSys *handlesys = &g_HandleSys;
54 IdentityToken_t *g_pCoreIdent;
55 SMGlobalClass *SMGlobalClass::head = NULL;
58 ITextParsers *textparser = &g_TextParser;
59 IVEngineServer *engine;
60 IShareSys *sharesys = &g_ShareSys;
61 IRootConsole *rootmenu;
62 IPluginManager *pluginsys = g_PluginSys.GetOldAPI();
63 IForwardManager *forwardsys;
64 ITimerSystem *timersys;
65 ServerGlobals serverGlobals;
66 IPlayerManager *playerhelpers;
67 IAdminSystem *adminsys;
68 IGameHelpers *gamehelpers;
69 ISourcePawnEngine *g_pSourcePawn;
70 ISourcePawnEngine2 *g_pSourcePawn2;
71 CNativeOwner g_CoreNatives;
72 IScriptManager *scripts = &g_PluginSys;
74 static void AddCorePhraseFile(const char *filename)
76 g_pCorePhrases->AddPhraseFile(filename);
79 static IGameConfig *GetCoreGameConfig()
84 // Defined in smn_filesystem.cpp.
85 extern bool OnLogPrint(const char *msg);
87 static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...)
91 g_DbgReporter.GenerateErrorVA(ctx, idx, err, msg, ap);
95 static void AddNatives(sp_nativeinfo_t *natives)
97 g_CoreNatives.AddNatives(natives);
100 static void DumpHandles(void (*dumpfn)(const char *fmt, ...))
102 g_HandleSys.Dump(dumpfn);
105 static sm_logic_t logic =
116 UTIL_DecodeHexString,
131 static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
133 logic.head = SMGlobalClass::head;
135 memcpy(&smcore, core, sizeof(sm_core_t));
136 memcpy(_logic, &logic, sizeof(sm_logic_t));
137 memcpy(&serverGlobals, core->serverGlobals, sizeof(ServerGlobals));
139 libsys = core->libsys;
140 engine = core->engine;
142 rootmenu = core->rootmenu;
143 forwardsys = core->forwardsys;
144 timersys = core->timersys;
145 playerhelpers = core->playerhelpers;
146 adminsys = core->adminsys;
147 gamehelpers = core->gamehelpers;
148 g_pSourcePawn = *core->spe1;
149 g_pSourcePawn2 = *core->spe2;
150 SMGlobalClass::head = core->listeners;
152 g_ShareSys.Initialize();
153 g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
155 _logic->core_ident = g_pCoreIdent;
158 PLATFORM_EXTERN_C ITextParsers *get_textparsers()
160 return &g_TextParser;
163 PLATFORM_EXTERN_C LogicInitFunction logic_load(uint32_t magic)
165 if (magic != SM_LOGIC_MAGIC)
173 void CoreNativesToAdd::OnSourceModAllInitialized()
175 g_CoreNatives.AddNatives(m_NativeList);
178 /* Overload a few things to prevent libstdc++ linking */
179 #if defined __linux__ || defined __APPLE__
180 extern "C" void __cxa_pure_virtual(void)
184 void *operator new(size_t size)
189 void *operator new[](size_t size)
194 void operator delete(void *ptr)
199 void operator delete[](void * ptr)