1.1 --- a/core/sourcemod.cpp Mon Jul 07 06:24:54 2008 +0000
1.2 +++ b/core/sourcemod.cpp Mon Jul 07 06:25:15 2008 +0000
1.3 @@ -33,7 +33,6 @@
1.4 #include "sourcemod.h"
1.5 #include "sourcemm_api.h"
1.6 #include "systems/LibrarySys.h"
1.7 -#include "vm/sp_vm_engine.h"
1.8 #include <sh_string.h>
1.9 #include "PluginSys.h"
1.10 #include "ShareSys.h"
1.11 @@ -47,27 +46,26 @@
1.12 #include "ForwardSys.h"
1.13 #include "TimerSys.h"
1.14 #include "GameConfigs.h"
1.15 +#include "DebugReporter.h"
1.16 +#include "Profiler.h"
1.17
1.18 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
1.19 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
1.20 SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, false, bool);
1.21 SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char *);
1.22
1.23 -SourcePawnEngine g_SourcePawn;
1.24 SourceModBase g_SourceMod;
1.25
1.26 ILibrary *g_pJIT = NULL;
1.27 SourceHook::String g_BaseDir;
1.28 -ISourcePawnEngine *g_pSourcePawn = &g_SourcePawn;
1.29 -IVirtualMachine *g_pVM;
1.30 +ISourcePawnEngine *g_pSourcePawn = NULL;
1.31 +ISourcePawnEngine2 *g_pSourcePawn2 = NULL;
1.32 IdentityToken_t *g_pCoreIdent = NULL;
1.33 IForward *g_pOnMapEnd = NULL;
1.34 bool g_Loaded = false;
1.35
1.36 -typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
1.37 -typedef int (*GIVEENGINEPOINTER2)(ISourcePawnEngine *, unsigned int api_version);
1.38 -typedef unsigned int (*GETEXPORTCOUNT)();
1.39 -typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
1.40 +typedef ISourcePawnEngine *(*GET_SP_V1)();
1.41 +typedef ISourcePawnEngine2 *(*GET_SP_V2)();
1.42 typedef void (*NOTIFYSHUTDOWN)();
1.43
1.44 void ShutdownJIT()
1.45 @@ -165,104 +163,33 @@
1.46 return false;
1.47 }
1.48
1.49 - int err;
1.50 -
1.51 - GIVEENGINEPOINTER2 jit_init2 = (GIVEENGINEPOINTER2)g_pJIT->GetSymbolAddress("GiveEnginePointer2");
1.52 - if (!jit_init2)
1.53 - {
1.54 - GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
1.55 - if (!jit_init)
1.56 - {
1.57 - ShutdownJIT();
1.58 - if (error && maxlength)
1.59 - {
1.60 - snprintf(error, maxlength, "Failed to find GiveEnginePointer in JIT!");
1.61 - }
1.62 - return false;
1.63 - }
1.64 + GET_SP_V1 getv1 = (GET_SP_V1)g_pJIT->GetSymbolAddress("GetSourcePawn1");
1.65 + GET_SP_V2 getv2 = (GET_SP_V2)g_pJIT->GetSymbolAddress("GetSourcePawn2");
1.66
1.67 - if ((err=jit_init(g_pSourcePawn)) != 0)
1.68 - {
1.69 - ShutdownJIT();
1.70 - if (error && maxlength)
1.71 - {
1.72 - snprintf(error, maxlength, "GiveEnginePointer returned %d in the JIT", err);
1.73 - }
1.74 - return false;
1.75 - }
1.76 - }
1.77 - else
1.78 + if (getv1 == NULL)
1.79 {
1.80 - /* On version bumps, we should check for older versions as well, if the new version fails.
1.81 - * We can then check the exports to see if any VM versions will be sufficient.
1.82 - */
1.83 - if ((err=jit_init2(g_pSourcePawn, SOURCEPAWN_ENGINE_API_VERSION)) != SP_ERROR_NONE)
1.84 - {
1.85 - ShutdownJIT();
1.86 - if (error && maxlength)
1.87 - {
1.88 - snprintf(error, maxlength, "JIT incompatible with SourceMod version");
1.89 - }
1.90 - return false;
1.91 - }
1.92 - }
1.93 -
1.94 - GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount");
1.95 - GETEXPORT jit_get = (GETEXPORT)g_pJIT->GetSymbolAddress("GetExport");
1.96 - if (!jit_get)
1.97 - {
1.98 - ShutdownJIT();
1.99 if (error && maxlength)
1.100 {
1.101 - snprintf(error, maxlength, "JIT is missing a necessary export!");
1.102 + snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
1.103 }
1.104 + ShutdownJIT();
1.105 + return false;
1.106 + }
1.107 + else if (getv2 == NULL)
1.108 + {
1.109 + if (error && maxlength)
1.110 + {
1.111 + snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
1.112 + }
1.113 + ShutdownJIT();
1.114 return false;
1.115 }
1.116
1.117 - unsigned int num = jit_getnum();
1.118 - if (!num)
1.119 - {
1.120 - ShutdownJIT();
1.121 - if (error && maxlength)
1.122 - {
1.123 - snprintf(error, maxlength, "JIT did not export any virtual machines!");
1.124 - }
1.125 - return false;
1.126 - }
1.127 + g_pSourcePawn = getv1();
1.128 + g_pSourcePawn2 = getv2();
1.129
1.130 - unsigned int api_version;
1.131 - for (unsigned int i=0; i<num; i++)
1.132 - {
1.133 - if ((g_pVM=jit_get(i)) == NULL)
1.134 - {
1.135 - if (error && maxlength)
1.136 - {
1.137 - snprintf(error, maxlength, "JIT did not export any virtual machines!");
1.138 - }
1.139 - continue;
1.140 - }
1.141 - /* Refuse any API that we might not be able to deal with.
1.142 - * <s>Also refuse anything < 3 because we need fake natives.</s>
1.143 - * Also refuse anything < 7 because we need the new sp_native definition.
1.144 - */
1.145 - api_version = g_pVM->GetAPIVersion();
1.146 - if (api_version < 7 || api_version > SOURCEPAWN_VM_API_VERSION)
1.147 - {
1.148 - if (error && maxlength)
1.149 - {
1.150 - snprintf(error, maxlength, "JIT is not a compatible version");
1.151 - }
1.152 - g_pVM = NULL;
1.153 - continue;
1.154 - }
1.155 - break;
1.156 - }
1.157 -
1.158 - if (!g_pVM)
1.159 - {
1.160 - ShutdownJIT();
1.161 - return false;
1.162 - }
1.163 + g_pSourcePawn2->SetDebugListener(&g_DbgReporter);
1.164 + g_pSourcePawn2->SetProfiler(&g_Profiler);
1.165
1.166 /* Hook this now so we can detect startup without calling StartSourceMod() */
1.167 SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);