示例#1
0
bool l4dtoolz::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{

	PLUGIN_SAVEVARS();

	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
	GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);


#if defined METAMOD_PLAPI_VERSION
	if ((vsp_callbacks = ismm->GetVSPInfo(NULL)) == NULL)
#endif
	{
		ismm->AddListener(this, this);
		ismm->EnableVSPListener();
	}


#if !defined METAMOD_PLAPI_VERSION
	m_EngineCC = SH_GET_CALLCLASS(engine);
#endif

#if SOURCE_ENGINE >= SE_ORANGEBOX
	g_pCVar = icvar;
	ConVar_Register(0, &s_BaseAccessor);
#else
	ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor);
#endif

	struct base_addr_t base_addr;
	base_addr.addr = NULL;
	base_addr.len = 0;

	find_base_from_list(matchmaking_dll, &base_addr);

	if(!lobby_match_ptr) {
		lobby_match_ptr = find_signature(lobby_match, &base_addr, 1);
		get_original_signature(lobby_match_ptr, lobby_match_new, lobby_match_org);
	}

	find_base_from_list(engine_dll, &base_addr);
#ifdef L4D1
	if(!max_players_friend_lobby) {
		max_players_friend_lobby = find_signature(friends_lobby, &base_addr, 0);
		get_original_signature(max_players_friend_lobby, friends_lobby_new, friends_lobby_org);
	}
#endif
	if(!max_players_connect) {
		max_players_connect = find_signature(max_players, &base_addr, 0);
		get_original_signature(max_players_connect, max_players_new, max_players_org);
	}
	if(!lobby_sux_ptr) {

#ifdef WIN32
		lobby_sux_ptr = max_players_connect;
#else
		lobby_sux_ptr = find_signature(lobby_sux, &base_addr, 0);
#endif
		get_original_signature(lobby_sux_ptr, lobby_sux_new, lobby_sux_org);
	}
#ifdef L4D1
#ifdef WIN32
	if(!max_players_server_browser) {
		max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
		get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
	}
#endif
#endif
	if(!tmp_player) {
		tmp_player = find_signature(players, &base_addr, 0);
		if(tmp_player) {
			tmp_player2 = find_signature(players2, &base_addr, 0);
			if(tmp_player2) {
				get_original_signature(tmp_player, players_new, players_org);
				write_signature(tmp_player, players_new);
				get_original_signature(tmp_player2, players_new2, players_org2);
				write_signature(tmp_player2, players_new2);
				engine->ServerCommand("maxplayers 32\n");
				engine->ServerCommand("L4DToolZ [email protected]\n");
			}
		}
	}
	if(!unreserved_ptr) {
		unreserved_ptr = find_signature(unreserved, &base_addr, 0);
		get_original_signature(unreserved_ptr, unreserved_new, unreserved_org);
	}

	find_base_from_list(server_dll, &base_addr);
#ifdef L4D1
	if(!chuman_limit) {
		chuman_limit = find_signature(human_limit, &base_addr, 0);
		get_original_signature(chuman_limit, human_limit_new, human_limit_org);
	}
#ifndef WIN32
	if(!max_players_server_browser) {
		max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
		get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
	}
#endif
#else
	if(!max_players_server_browser) {
		max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
		get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
	}
#endif

	return true;
}
示例#2
0
void SourceModBase::StartSourceMod(bool late)
{
    SH_ADD_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SourceModBase::LevelShutdown), false);
    SH_ADD_HOOK(IServerGameDLL, GameFrame, gamedll, SH_MEMBER(&g_Timers, &TimerSystem::GameFrame), false);

    enginePatch = SH_GET_CALLCLASS(engine);
    gamedllPatch = SH_GET_CALLCLASS(gamedll);

    InitLogicBridge();

    /* Notify! */
    SMGlobalClass *pBase = SMGlobalClass::head;
    while (pBase)
    {
        pBase->OnSourceModStartup(false);
        pBase = pBase->m_pGlobalClassNext;
    }
    g_pGameConf = logicore.GetCoreGameConfig();

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

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

    /* Add us now... */
    sharesys->AddInterface(NULL, this);

    /* We're loaded! */
    g_Loaded = true;

    /* Initialize VSP stuff */
    if (vsp_interface != NULL)
    {
        g_SourceMod_Core.OnVSPListening(vsp_interface);
    }

    if (late)
    {
        /* We missed doing anythin gin this if we late-loaded. Sneak it in now. */
        AllPluginsLoaded();
    }

    /* If we want to autoload, do that now */
    const char *disabled = GetCoreConfigValue("DisableAutoUpdate");
    if (disabled == NULL || strcasecmp(disabled, "yes") != 0)
    {
        extsys->LoadAutoExtension("updater.ext." PLATFORM_LIB_EXT);
    }

    const char *timeout = GetCoreConfigValue("SlowScriptTimeout");
    if (timeout == NULL)
    {
        timeout = "8";
    }
    if (atoi(timeout) != 0)
    {
        g_pSourcePawn2->InstallWatchdogTimer(atoi(timeout) * 1000);
    }
}
示例#3
0
void ValveMenuStyle::OnSourceModAllInitialized()
{
    g_Players.AddClientListener(this);
    SH_ADD_HOOK_MEMFUNC(IServerPluginHelpers, CreateMessage, serverpluginhelpers, this, &ValveMenuStyle::HookCreateMessage, false);
    g_pSPHCC = SH_GET_CALLCLASS(serverpluginhelpers);
}
示例#4
0
bool TestThisPtrOffs(std::string &error)
{
	GET_SHPTR(g_SHPtr);
	g_PLID = 1337;

	Derived *pD = MyInstanceFactory();
	Base1 *pB1 = pD;
	Base2 *pB2 = pD;

	CAutoPtrDestruction<Derived> apd(pD);


	// It should be:
	// pB1 = pD
	// pB2 > pB1

	// 1)
	//  Get a callclass for pD
	//  Verify whether the this pointers are correct
	//  Also call them normally to make sure that we aren't messing it up ;)
	SourceHook::CallClass<Derived> *pD_CC = SH_GET_CALLCLASS(pD);

	SH_CALL(pD_CC, &Derived::Func1)();
	SH_CALL(pD_CC, &Derived::Func2)();
	SH_CALL(pD_CC, &Derived::Func3)();
	pD->Func1();
	pD->Func2();
	pD->Func3();

	CHECK_STATES((&g_States,
		new State_Func1_Called(pB1),
		new State_Func2_Called(pB2),
		new State_Func3_Called(pD),
		new State_Func1_Called(pB1),
		new State_Func2_Called(pB2),
		new State_Func3_Called(pD),
		NULL), "Part 1");

	SH_CALL(pD_CC, &Base1::Func1)();
	SH_CALL(pD_CC, &Base2::Func2)();

	CHECK_STATES((&g_States,
		new State_Func1_Called(pB1),
		new State_Func2_Called(pB2),
		NULL), "Part 1.1");

	// 2)
	//   Get callclasses for the other ones and verify it as well

	SourceHook::CallClass<Base1> *pB1_CC = SH_GET_CALLCLASS(pB1);
	SourceHook::CallClass<Base2> *pB2_CC = SH_GET_CALLCLASS(pB2);

	SH_CALL(pB1_CC, &Base1::Func1)();
	SH_CALL(pB2_CC, &Base2::Func2)();

	CHECK_STATES((&g_States,
		new State_Func1_Called(pB1),
		new State_Func2_Called(pB2),
		NULL), "Part 2");


	// 3) Add hooks on them (referring to them through pD1 / Derived)
	//   Check whether the hooks are called with the correct this pointer

	SH_ADD_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false);
	SH_ADD_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false);
	SH_ADD_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false);

	pD->Func1();
	pD->Func2();
	pD->Func3();
	pB1->Func1();
	pB2->Func2();

	// The handlers should always be called with the pointer to Derived
	CHECK_STATES((&g_States,
		new State_Func1H_Called(pD),
		new State_Func1_Called(pB1),
		new State_Func2H_Called(pD),
		new State_Func2_Called(pB2),
		new State_Func3H_Called(pD),
		new State_Func3_Called(pD),
		new State_Func1H_Called(pD),
		new State_Func1_Called(pB1),
		new State_Func2H_Called(pD),
		new State_Func2_Called(pB2),
		NULL), "Part 3");

	SH_REMOVE_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false);
	SH_REMOVE_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false);
	SH_REMOVE_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false);

	// 4)
	//   Now add the hooks on Base1 and Base2 and check again

	// Note that the new implicit_cast should convert the pD to Base1*/Base2* :)
	SH_ADD_HOOK(Base1, Func1, pD, SH_STATIC(Handler_Func1), false);
	SH_ADD_HOOK(Base2, Func2, pD, SH_STATIC(Handler_Func2), false);
	SH_ADD_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false);

	pD->Func1();
	pD->Func2();
	pD->Func3();
	pB1->Func1();
	pB2->Func2();

	// This time, the handlers for Func1 should be called with pB1 and the handlers
	// for Func2 should be called with pB2
	CHECK_STATES((&g_States,
		new State_Func1H_Called(pB1),
		new State_Func1_Called(pB1),
		new State_Func2H_Called(pB2),
		new State_Func2_Called(pB2),
		new State_Func3H_Called(pD),
		new State_Func3_Called(pD),
		new State_Func1H_Called(pB1),
		new State_Func1_Called(pB1),
		new State_Func2H_Called(pB2),
		new State_Func2_Called(pB2),
		NULL), "Part 4");

	SH_REMOVE_HOOK(Base1, Func1, pD, SH_STATIC(Handler_Func1), false);
	SH_REMOVE_HOOK(Base2, Func2, pD, SH_STATIC(Handler_Func2), false);
	SH_REMOVE_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false);


	// 5)
	//   Add some hooks, and use callclasses

	// 5.1) First off, add all of them on pD
	SH_ADD_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false);
	SH_ADD_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false);
	SH_ADD_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false);

	pD->Func1();
	pD->Func2();
	pD->Func3();

	CHECK_STATES((&g_States,
		new State_Func1H_Called(pD),
		new State_Func1_Called(pB1),
		new State_Func2H_Called(pD),
		new State_Func2_Called(pB2),
		new State_Func3H_Called(pD),
		new State_Func3_Called(pD),
		NULL), "Part 5.1");

	SH_CALL(pD_CC, &Derived::Func1)();
	SH_CALL(pD_CC, &Derived::Func2)();
	SH_CALL(pD_CC, &Derived::Func3)();
	SH_CALL(pB1_CC, &Base1::Func1)();
	SH_CALL(pB2_CC, &Base2::Func2)();

	CHECK_STATES((&g_States,
		new State_Func1_Called(pB1),
		new State_Func2_Called(pB2),
		new State_Func3_Called(pD),
		new State_Func1_Called(pB1),
		new State_Func2_Called(pB2),
		NULL), "Part 5.2");

	SH_REMOVE_HOOK(Derived, Func1, pD, SH_STATIC(Handler_Func1), false);
	SH_REMOVE_HOOK(Derived, Func2, pD, SH_STATIC(Handler_Func2), false);
	SH_REMOVE_HOOK(Derived, Func3, pD, SH_STATIC(Handler_Func3), false);

	SH_RELEASE_CALLCLASS(pB1_CC);
	SH_RELEASE_CALLCLASS(pB2_CC);
	SH_RELEASE_CALLCLASS(pD_CC);

	return true;
}
bool CSourceMMMAP::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
	PLUGIN_SAVEVARS();

	//char iface_buffer[255];
	//int num = 0;
#ifdef GAME_ORANGE
	GET_V_IFACE(GetServerFactory, playerinfomanager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
	GET_V_IFACE(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
	GET_V_IFACE(GetEngineFactory, gameeventmanager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
	GET_V_IFACE(GetEngineFactory, filesystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
	GET_V_IFACE(GetEngineFactory, helpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
	GET_V_IFACE(GetEngineFactory, networkstringtable, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER);
	GET_V_IFACE(GetEngineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER);
	GET_V_IFACE(GetEngineFactory, randomStr, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
	GET_V_IFACE(GetServerFactory, serverents, IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
	GET_V_IFACE(GetServerFactory, effects, IEffects, IEFFECTS_INTERFACE_VERSION);
	GET_V_IFACE(GetEngineFactory, esounds, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
	GET_V_IFACE(GetServerFactory, serverdll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
	GET_V_IFACE(GetEngineFactory, voiceserver, IVoiceServer, INTERFACEVERSION_VOICESERVER);
	GET_V_IFACE(GetServerFactory, serverclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
	g_pCVar = GetICVar();
#else
	GET_V_IFACE(serverFactory, playerinfomanager, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
	GET_V_IFACE(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
	GET_V_IFACE(engineFactory, gameeventmanager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
	GET_V_IFACE(engineFactory, filesystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
	GET_V_IFACE(engineFactory, helpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
	GET_V_IFACE(engineFactory, networkstringtable, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER);
	GET_V_IFACE(engineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER);
	GET_V_IFACE(engineFactory, randomStr, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
	GET_V_IFACE(serverFactory, serverents, IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
	GET_V_IFACE(serverFactory, effects, IEffects, IEFFECTS_INTERFACE_VERSION);
	GET_V_IFACE(engineFactory, esounds, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
	GET_V_IFACE(engineFactory, g_pCVar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
	GET_V_IFACE(serverFactory, serverdll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
	GET_V_IFACE(engineFactory, voiceserver, IVoiceServer, INTERFACEVERSION_VOICESERVER);
	GET_V_IFACE(serverFactory, serverclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
#endif
	ConVar *testload = g_pCVar->FindVar("mani_admin_plugin_version");
	if ( testload ) {
		MMsg( "Error:  Version %s of Mani Admin Plugin is already loaded.\n", testload->GetString() );
		return false;
	}

	META_LOG(g_PLAPI, "Starting plugin.\n");

	ismm->AddListener(this, &g_Listener);

	//Init our cvars/concmds
#if defined GAME_ORANGE
	ConVar_Register(0, this);
#else
	ConCommandBaseMgr::OneTimeInit(this);
#endif
	//We're hooking the following things as POST, in order to seem like Server Plugins.
	//However, I don't actually know if Valve has done server plugins as POST or not.
	//Change the last parameter to 'false' in order to change this to PRE.
	//SH_ADD_HOOK_MEMFUNC means "SourceHook, Add Hook, Member Function".

	//Hook LevelInit to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, serverdll, &g_ManiCallback, &CSourceMMMAP::LevelInit, false);
	//Hook ServerActivate to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, serverdll, &g_ManiCallback, &CSourceMMMAP::ServerActivate, true);
	//Hook GameFrame to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, serverdll, &g_ManiCallback, &CSourceMMMAP::GameFrame, true);
	//Hook LevelShutdown to our function -- this makes more sense as pre I guess
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, serverdll, &g_ManiCallback, &CSourceMMMAP::LevelShutdown, false);
	//Hook ClientActivate to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientActive, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientActive, false);
	//Hook ClientDisconnect to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientDisconnect, false);
	//Hook ClientPutInServer to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientPutInServer, true);
	//Hook SetCommandClient to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverclients, &g_ManiCallback, &CSourceMMMAP::SetCommandClient, true);
	//Hook ClientSettingsChanged to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientSettingsChanged, true);

	//The following functions are pre handled, because that's how they are in IServerPluginCallbacks
	//Hook ClientConnect to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientConnect, false);
	//Hook ClientCommand to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, serverclients, &g_ManiCallback, &CSourceMMMAP::ClientCommand, false);

	//This hook is a static hook, no member function
	//SH_ADD_HOOK_STATICFUNC(IGameEventManager2, FireEvent, gameeventmanager, FireEvent_Handler, false); 
#if !defined GAME_ORANGE && defined SOURCEMM
	//Get the call class for IVServerEngine so we can safely call functions without
	// invoking their hooks (when needed).
	engine_cc = SH_GET_CALLCLASS(engine);
	voiceserver_cc = SH_GET_CALLCLASS(voiceserver);
	serverdll_cc = SH_GET_CALLCLASS(serverdll);
#endif


#ifdef GAME_ORANGE 
	gamedll = g_SMAPI->GetServerFactory(false);
#else
	gamedll = g_SMAPI->serverFactory(false);
#endif

	g_SMAPI->AddListener(g_PLAPI, this);

#ifdef GAME_ORANGE 
	gpGlobals = g_SMAPI->GetCGlobals();
#else
	gpGlobals = g_SMAPI->pGlobals();
#endif

	FindConPrintf();

	MMsg("********************************************************\n");
	MMsg(" Loading ");
	MMsg("%s\n", mani_version);
	MMsg("\n");

	if (!UTIL_InterfaceMsg(playerinfomanager,"IPlayerInfoManager", INTERFACEVERSION_PLAYERINFOMANAGER)) return false;
	if (!UTIL_InterfaceMsg(engine,"IVEngineServer", INTERFACEVERSION_VENGINESERVER)) return false;
	if (!UTIL_InterfaceMsg(gameeventmanager,"IGameEventManager2", INTERFACEVERSION_GAMEEVENTSMANAGER2)) return false;
	if (!UTIL_InterfaceMsg(filesystem,"IFileSystem", FILESYSTEM_INTERFACE_VERSION)) return false;
	if (!UTIL_InterfaceMsg(helpers,"IServerPluginHelpers", INTERFACEVERSION_ISERVERPLUGINHELPERS)) return false;
	if (!UTIL_InterfaceMsg(networkstringtable,"INetworkStringTableContainer", INTERFACENAME_NETWORKSTRINGTABLESERVER)) return false;
	if (!UTIL_InterfaceMsg(enginetrace,"IEngineTrace", INTERFACEVERSION_ENGINETRACE_SERVER)) return false;
	if (!UTIL_InterfaceMsg(randomStr,"IUniformRandomStream", VENGINE_SERVER_RANDOM_INTERFACE_VERSION)) return false;
	if (!UTIL_InterfaceMsg(serverents,"IServerGameEnts", INTERFACEVERSION_SERVERGAMEENTS)) return false;
	if (!UTIL_InterfaceMsg(effects,"IEffects", IEFFECTS_INTERFACE_VERSION)) return false;
	if (!UTIL_InterfaceMsg(esounds,"IEngineSound", IENGINESOUND_SERVER_INTERFACE_VERSION)) return false;

#ifdef GAME_ORANGE 
	if (!UTIL_InterfaceMsg(g_pCVar,"ICvar", CVAR_INTERFACE_VERSION)) return false;
#else
	if (!UTIL_InterfaceMsg(g_pCVar,"ICvar", VENGINE_CVAR_INTERFACE_VERSION)) return false;
#endif

	if (!UTIL_InterfaceMsg(serverdll,"IServerGameDLL", "ServerGameDLL003")) return false;
	if (!UTIL_InterfaceMsg(voiceserver,"IVoiceServer", INTERFACEVERSION_VOICESERVER)) return false;
	//if (!UTIL_InterfaceMsg(partition,"ISpatialPartition", INTERFACEVERSION_SPATIALPARTITION)) return false;

	MMsg("********************************************************\n");

	// max players = 0 on first load, > 0 on late load
	max_players = gpGlobals->maxClients;
	if (late)
	{
		HookConCommands();
	}

	gpManiAdminPlugin->Load();

	return true;
}