Beispiel #1
0
bool
LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *c, char const *d, bool e, bool f)
{
    g_mapname.assign(pMapName);
    const char *ents = stripper_core.parse_map(g_mapname.c_str(), pMapEntities);
    RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, true, &IServerGameDLL::LevelInit, (pMapName, ents, c, d, e, f));
}
Beispiel #2
0
ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, 
									  const char *value, 
									  ConfigSource source, 
									  char *error, 
									  size_t maxlength)
{
	if (strcasecmp(key, "BasePath") == 0)
	{
		if (source == ConfigSource_Console)
		{
			UTIL_Format(error, maxlength, "Cannot be set at runtime");
			return ConfigResult_Reject;
		}

		if (!m_GotBasePath)
		{
			g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value);
			g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), value);

			m_GotBasePath = true;
		}

		return ConfigResult_Accept;
	}
	else if (strcasecmp(key, "DebugSpew") == 0)
	{
		sm_show_debug_spew = (strcasecmp(value, "yes") == 0) ? true : false;

		return ConfigResult_Accept;
	}
	else if (strcasecmp(key, "DisableJIT") == 0)
	{
		sm_disable_jit = (strcasecmp(value, "yes") == 0) ? true : false;
		if (g_pSourcePawn2)
			g_pSourcePawn2->SetJitEnabled(!sm_disable_jit);

		return ConfigResult_Accept;
	}

	return ConfigResult_Ignore;
}
Beispiel #3
0
const char *SourceModBase::GetGamePath() const
{
	return g_BaseDir.c_str();
}
Beispiel #4
0
bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late)
{
	const char *gamepath = g_SMAPI->GetBaseDir();

	/* Store full path to game */
	g_BaseDir.assign(gamepath);

	/* Store name of game directory by itself */
	size_t len = strlen(gamepath);
	for (size_t i = len - 1; i < len; i--)
	{
		if (gamepath[i] == PLATFORM_SEP_CHAR)
		{
			strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir));
			break;
		}
	}

	const char *basepath = icvar->GetCommandLineValue("sm_basepath");
	/* Set a custom base path if there is one. */
	if (basepath != NULL && basepath[0] != '\0')
	{
		m_GotBasePath = true;
	}
	/* Otherwise, use a default and keep the m_GotBasePath unlocked. */
	else
	{
		basepath = sm_basepath.GetDefault();
	}

	g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath);
	g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath);

	if (!StartLogicBridge(error, maxlength))
	{
		return false;
	}

	/* There will always be a path by this point, since it was force-set above. */
	m_GotBasePath = true;

	/* Attempt to load the JIT! */
	char file[PLATFORM_MAX_PATH];
	char myerror[255];
	g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s",
		GetSourceModPath(),
		PLATFORM_LIB_EXT
		);

	g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
	if (!g_pJIT)
	{
		if (error && maxlength)
		{
			UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", 
				myerror,
				PLATFORM_LIB_EXT);
		}
		return false;
	}

	GetSourcePawnFactoryFn factoryFn =
		(GetSourcePawnFactoryFn)g_pJIT->GetSymbolAddress("GetSourcePawnFactory");

	if (!factoryFn) {
		if (error && maxlength)
			snprintf(error, maxlength, "SourcePawn library is out of date");
		ShutdownJIT();
		return false;
	}

	ISourcePawnFactory *factory = factoryFn(SOURCEPAWN_API_VERSION);
	if (!factory) {
		if (error && maxlength)
			snprintf(error, maxlength, "SourcePawn library is out of date");
		ShutdownJIT();
		return false;
	}

	g_pPawnEnv = factory->NewEnvironment();
	if (!g_pPawnEnv) {
		if (error && maxlength)
			snprintf(error, maxlength, "Could not create a SourcePawn environment!");
		ShutdownJIT();
		return false;
	}

	g_pSourcePawn = g_pPawnEnv->APIv1();
	g_pSourcePawn2 = g_pPawnEnv->APIv2();

	g_pSourcePawn2->SetDebugListener(logicore.debugger);

	if (sm_disable_jit)
		g_pSourcePawn2->SetJitEnabled(!sm_disable_jit);

	sSourceModInitialized = true;

	/* Hook this now so we can detect startup without calling StartSourceMod() */
	SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false);

	/* Only load if we're not late */
	if (!late)
	{
		StartSourceMod(false);
	}

	return true;
}
Beispiel #5
0
bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late)
{
    const char *gamepath = g_SMAPI->GetBaseDir();

    /* Store full path to game */
    g_BaseDir.assign(gamepath);

    /* Store name of game directory by itself */
    size_t len = strlen(gamepath);
    for (size_t i = len - 1; i < len; i--)
    {
        if (gamepath[i] == PLATFORM_SEP_CHAR)
        {
            strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir));
            break;
        }
    }

    const char *basepath = icvar->GetCommandLineValue("sm_basepath");
    /* Set a custom base path if there is one. */
    if (basepath != NULL && basepath[0] != '\0')
    {
        m_GotBasePath = true;
    }
    /* Otherwise, use a default and keep the m_GotBasePath unlocked. */
    else
    {
        basepath = sm_basepath.GetDefault();
    }

    g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath);
    g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath);

    if (!StartLogicBridge(error, maxlength))
    {
        return false;
    }

    /* Initialize CoreConfig to get the SourceMod base path properly - this parses core.cfg */
    g_CoreConfig.Initialize();

    /* There will always be a path by this point, since it was force-set above. */
    m_GotBasePath = true;

    /* Attempt to load the JIT! */
    char file[PLATFORM_MAX_PATH];
    char myerror[255];
    g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s",
                        GetSourceModPath(),
                        PLATFORM_LIB_EXT
                       );

    g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
    if (!g_pJIT)
    {
        if (error && maxlength)
        {
            UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)",
                        myerror,
                        PLATFORM_LIB_EXT);
        }
        return false;
    }

    GET_SP_V1 getv1 = (GET_SP_V1)g_pJIT->GetSymbolAddress("GetSourcePawnEngine1");
    GET_SP_V2 getv2 = (GET_SP_V2)g_pJIT->GetSymbolAddress("GetSourcePawnEngine2");

    if (getv1 == NULL)
    {
        if (error && maxlength)
        {
            snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
        }
        ShutdownJIT();
        return false;
    }
    else if (getv2 == NULL)
    {
        if (error && maxlength)
        {
            snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
        }
        ShutdownJIT();
        return false;
    }

    g_pSourcePawn = getv1();
    g_pSourcePawn2 = getv2();

    if (g_pSourcePawn2->GetAPIVersion() < 3)
    {
        g_pSourcePawn2 = NULL;
        if (error && maxlength)
        {
            snprintf(error, maxlength, "JIT version is out of date");
        }
        return false;
    }

    if (!g_pSourcePawn2->Initialize())
    {
        g_pSourcePawn2 = NULL;
        if (error && maxlength)
        {
            snprintf(error, maxlength, "JIT could not be initialized");
        }
        return false;
    }

    g_pSourcePawn2->SetDebugListener(logicore.debugger);

    if (sm_disable_jit)
        g_pSourcePawn2->SetJitEnabled(!sm_disable_jit);

    sSourceModInitialized = true;

    /* Hook this now so we can detect startup without calling StartSourceMod() */
    SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false);

    /* Only load if we're not late */
    if (!late)
    {
        StartSourceMod(false);
    }

    return true;
}
Beispiel #6
0
	virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength)
	{
		if (!g_Metamod.IsLoadedAsGameDLL())
		{
			vsp_desc.append(" ");
			vsp_desc.append(METAMOD_VERSION);

			CGlobalVars *pGlobals;
			IPlayerInfoManager *playerInfoManager;

			playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL);
			if (playerInfoManager == NULL)
			{
				UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game");
				return false;
			}

			pGlobals = playerInfoManager->GetGlobalVars();

			char gamedll_iface[24];
			for (unsigned int i = 3; i <= 50; i++)
			{
				UTIL_Format(gamedll_iface, sizeof(gamedll_iface), "ServerGameDLL%03d", i);
				if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL)
				{
					g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false);
					break;
				}
			}

			if (server == NULL)
			{
				UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible).");
				return false;
			}

			char gameclients_iface[] = "ServerGameClients000";
			for (unsigned int i = 3; i <= 4; i++)
			{
				gameclients_iface[19] = '0' + i;
				if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL)
					break;
			}

			mm_InitializeGlobals((CreateInterfaceFn) info->engineFactory,
				(CreateInterfaceFn) info->engineFactory,
				(CreateInterfaceFn) info->engineFactory,
				pGlobals);

			if (!mm_DetectGameInformation())
			{
				UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load.");
				return false;
			}

			mm_InitializeForLoad();			
			g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
			mm_StartupMetamod(true);
		}
		else
		{
			vsp_desc.append(" Interface ");
			vsp_desc.append(METAMOD_VERSION);

			g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version);
		}

#if SOURCE_ENGINE >= SE_ORANGEBOX
		g_plugin_unload = icvar->FindCommand("plugin_unload");
#else
		const ConCommandBase *pBase = icvar->GetCommands();
		while (pBase != NULL)
		{
			if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0)
			{
				g_plugin_unload = (ConCommand *)pBase;
				break;
			}
			pBase = pBase->GetNext();
		}
#endif

		if (g_plugin_unload != NULL)
		{
			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false);
			SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true);
		}

		return true;
	}
Beispiel #7
0
	virtual const char *GetDescription()
	{
		return vsp_desc.c_str();
	}