3 #include "sourcemm_api.h"
4 #include "systems/LibrarySys.h"
5 #include "vm/sp_vm_engine.h"
8 SourcePawnEngine g_SourcePawn;
9 SourceModBase g_SourceMod;
11 ILibrary *g_pJIT = NULL;
12 SourceHook::String g_BaseDir;
13 ISourcePawnEngine *g_pSourcePawn = &g_SourcePawn;
14 IVirtualMachine *g_pVM;
16 typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
17 typedef unsigned int (*GETEXPORTCOUNT)();
18 typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
19 typedef void (*NOTIFYSHUTDOWN)();
23 NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
29 g_pJIT->CloseLibrary();
32 bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
34 //:TODO: we need a localinfo system!
35 g_BaseDir.assign(g_SMAPI->GetBaseDir());
37 /* Attempt to load the JIT! */
38 char file[PLATFORM_MAX_PATH];
40 g_SMAPI->PathFormat(file, sizeof(file), "%s/addons/sourcemod/bin/sourcepawn.jit.x86.%s",
45 g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
50 snprintf(error, err_max, "%s (failed to load bin/sourcepawn.jit.x86.%s)",
58 GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
64 snprintf(error, err_max, "Failed to find GiveEnginePointer in JIT!");
69 if ((err=jit_init(g_pSourcePawn)) != 0)
74 snprintf(error, err_max, "GiveEnginePointer returned %d in the JIT", err);
79 GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount");
80 GETEXPORT jit_get = (GETEXPORT)g_pJIT->GetSymbolAddress("GetExport");
86 snprintf(error, err_max, "JIT is missing a necessary export!");
91 unsigned int num = jit_getnum();
92 if (!num || ((g_pVM=jit_get(0)) == NULL))
97 snprintf(error, err_max, "JIT did not export any virtual machines!");