3 #include "sourcemm_api.h"
4 #include "systems/LibrarySys.h"
5 #include "vm/sp_vm_engine.h"
9 SourcePawnEngine g_SourcePawn;
10 SourceModBase g_SourceMod;
12 ILibrary *g_pJIT = NULL;
13 SourceHook::String g_BaseDir;
14 ISourcePawnEngine *g_pSourcePawn = &g_SourcePawn;
15 IVirtualMachine *g_pVM;
17 typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
18 typedef unsigned int (*GETEXPORTCOUNT)();
19 typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
20 typedef void (*NOTIFYSHUTDOWN)();
24 NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
30 g_pJIT->CloseLibrary();
33 bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
35 //:TODO: we need a localinfo system!
36 g_BaseDir.assign(g_SMAPI->GetBaseDir());
38 /* Attempt to load the JIT! */
39 char file[PLATFORM_MAX_PATH];
41 g_SMAPI->PathFormat(file, sizeof(file), "%s/addons/sourcemod/bin/sourcepawn.jit.x86.%s",
46 g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
51 snprintf(error, err_max, "%s (failed to load bin/sourcepawn.jit.x86.%s)",
59 GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
65 snprintf(error, err_max, "Failed to find GiveEnginePointer in JIT!");
70 if ((err=jit_init(g_pSourcePawn)) != 0)
75 snprintf(error, err_max, "GiveEnginePointer returned %d in the JIT", err);
80 GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount");
81 GETEXPORT jit_get = (GETEXPORT)g_pJIT->GetSymbolAddress("GetExport");
87 snprintf(error, err_max, "JIT is missing a necessary export!");
92 unsigned int num = jit_getnum();
93 if (!num || ((g_pVM=jit_get(0)) == NULL))
98 snprintf(error, err_max, "JIT did not export any virtual machines!");
103 unsigned int api = g_pVM->GetAPIVersion();
104 if (api != SOURCEPAWN_VM_API_VERSION)
107 if (error && err_max)
109 snprintf(error, err_max, "JIT is not a compatible version");
115 g_SMAPI->PathFormat(file, sizeof(file), "%s/addons/sourcemod/plugins/test.smx", g_BaseDir.c_str());
116 IPlugin *pPlugin = g_PluginMngr.LoadPlugin(file, false, PluginType_Global, error, err_max);
117 IPluginFunction *func = pPlugin->GetFunctionByName("Test");
121 func->PushCellByRef(&val, SMFUNC_COPYBACK_ONCE);
122 func->Execute(&result, NULL);
123 g_PluginMngr.UnloadPlugin(pPlugin);