Ejemplo n.º 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));
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}