Exemple #1
0
bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
{
	g_Players.MaxPlayersChanged();

	/* If we're not loaded... */
	if (!g_Loaded)
	{
		/* Do all global initialization now */
		StartSourceMod(true);
	}

	m_IsMapLoading = true;
	m_ExecPluginReload = true;

	/* Notify! */
	SMGlobalClass *pBase = SMGlobalClass::head;
	while (pBase)
	{
		pBase->OnSourceModLevelChange(pMapName);
		pBase = pBase->m_pGlobalClassNext;
	}

	DoGlobalPluginLoads();

	m_IsMapLoading = false;

	/* Notify! */
	pBase = SMGlobalClass::head;
	while (pBase)
	{
		pBase->OnSourceModPluginsLoaded();
		pBase = pBase->m_pGlobalClassNext;
	}

	if (!g_pOnMapEnd)
	{
		g_pOnMapEnd = forwardsys->CreateForward("OnMapEnd", ET_Ignore, 0, NULL);
	}

	g_LevelEndBarrier = true;

	RETURN_META_VALUE(MRES_IGNORED, true);
}
Exemple #2
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;
}
Exemple #3
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;
}