2012-12-15 06:38:27 +08:00
|
|
|
#include "l4dtoolz_mm.h"
|
2013-01-21 21:39:57 +08:00
|
|
|
#include "signature.h"
|
|
|
|
#include "game_signature.h"
|
2012-12-15 06:38:27 +08:00
|
|
|
|
|
|
|
l4dtoolz g_l4dtoolz;
|
|
|
|
IVEngineServer* engine = NULL;
|
|
|
|
IServerPluginCallbacks* vsp_callbacks = NULL;
|
|
|
|
ICvar* icvar = NULL;
|
|
|
|
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
void* l4dtoolz::max_players_friend_lobby = NULL;
|
2013-07-09 17:57:40 +08:00
|
|
|
void* l4dtoolz::chuman_limit = NULL;
|
|
|
|
#endif
|
|
|
|
|
2013-01-21 21:39:57 +08:00
|
|
|
void* l4dtoolz::max_players_connect = NULL;
|
|
|
|
void* l4dtoolz::max_players_server_browser = NULL;
|
|
|
|
void* l4dtoolz::lobby_sux_ptr = NULL;
|
|
|
|
void* l4dtoolz::tmp_player = NULL;
|
|
|
|
void* l4dtoolz::tmp_player2 = NULL;
|
|
|
|
void* l4dtoolz::unreserved_ptr = NULL;
|
|
|
|
void* l4dtoolz::lobby_match_ptr = NULL;
|
2012-12-15 06:38:27 +08:00
|
|
|
|
2013-01-21 17:50:58 +08:00
|
|
|
ConVar sv_maxplayers("sv_maxplayers", "-1", 0, "Max Human Players", true, -1, true, 32, l4dtoolz::OnChangeMaxplayers);
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2012-12-15 06:38:27 +08:00
|
|
|
ConVar sv_removehumanlimit("sv_removehumanlimit", "0", 0, "Remove Human limit reached kick", true, 0, true, 1, l4dtoolz::OnChangeRemovehumanlimit);
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2012-12-15 06:38:27 +08:00
|
|
|
ConVar L4DToolZ("L4DToolZ", "",0,"L4DToolZ Author",l4dtoolz::OnChangeIvailosp);
|
|
|
|
ConVar sv_force_unreserved("sv_force_unreserved", "0", 0, "Disallow lobby reservation cookie", true, 0, true, 1, l4dtoolz::OnChangeUnreserved);
|
|
|
|
|
|
|
|
void l4dtoolz::OnChangeMaxplayers ( IConVar *var, const char *pOldValue, float flOldValue )
|
|
|
|
{
|
2013-01-21 21:39:57 +08:00
|
|
|
int new_value = ((ConVar*)var)->GetInt();
|
|
|
|
int old_value = atoi(pOldValue);
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
if (max_players_friend_lobby == NULL || max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
|
2013-07-09 17:57:40 +08:00
|
|
|
#else
|
|
|
|
if (max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
|
|
|
|
#endif
|
|
|
|
Msg("sv_maxplayers init error\n");
|
2012-12-15 06:38:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
if(new_value != old_value) {
|
2013-01-22 04:27:24 +08:00
|
|
|
if(new_value >= 0) {
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
max_players_new[4] = friends_lobby_new[3] = server_bplayers_new[3] = new_value;
|
2013-07-09 17:57:40 +08:00
|
|
|
#else
|
2015-11-02 22:16:30 +08:00
|
|
|
max_players_new[4] = server_bplayers_new[3] = (unsigned char)new_value;
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2013-01-22 04:27:24 +08:00
|
|
|
if(lobby_match_ptr) {
|
2015-11-02 22:16:30 +08:00
|
|
|
lobby_match_new[2] = (unsigned char)new_value;
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(lobby_match_ptr, lobby_match_new);
|
|
|
|
} else {
|
|
|
|
Msg("sv_maxplayers MS init error\n");
|
|
|
|
}
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(max_players_friend_lobby, friends_lobby_new);
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(max_players_connect, max_players_new);
|
|
|
|
write_signature(lobby_sux_ptr, lobby_sux_new);
|
|
|
|
write_signature(max_players_server_browser, server_bplayers_new);
|
|
|
|
} else {
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(max_players_friend_lobby, friends_lobby_org);
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(max_players_connect, max_players_org);
|
|
|
|
write_signature(lobby_sux_ptr, lobby_sux_org);
|
|
|
|
write_signature(max_players_server_browser, server_bplayers_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
|
2013-01-22 04:27:24 +08:00
|
|
|
if(lobby_match_ptr)
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(lobby_match_ptr, lobby_match_org);
|
|
|
|
}
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2012-12-15 06:38:27 +08:00
|
|
|
void l4dtoolz::OnChangeRemovehumanlimit ( IConVar *var, const char *pOldValue, float flOldValue )
|
|
|
|
{
|
2013-01-21 21:39:57 +08:00
|
|
|
int new_value = ((ConVar*)var)->GetInt();
|
|
|
|
int old_value = atoi(pOldValue);
|
|
|
|
if(chuman_limit == NULL) {
|
2012-12-15 06:38:27 +08:00
|
|
|
Msg( "sv_removehumanlimit init error\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
if(new_value != old_value) {
|
|
|
|
if(new_value == 1) {
|
|
|
|
write_signature(chuman_limit, human_limit_new);
|
|
|
|
}else{
|
|
|
|
write_signature(chuman_limit, human_limit_org);
|
|
|
|
}
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2012-12-15 06:38:27 +08:00
|
|
|
|
|
|
|
void l4dtoolz::OnChangeIvailosp ( IConVar *var, const char *pOldValue, float flOldValue )
|
|
|
|
{
|
2013-01-21 21:39:57 +08:00
|
|
|
if(tmp_player == NULL || tmp_player2 == NULL) {
|
2013-01-21 17:50:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(tmp_player, players_org);
|
2013-01-22 04:27:24 +08:00
|
|
|
free(players_org);
|
|
|
|
players_org = NULL;
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(tmp_player2, players_org2);
|
2013-01-22 04:27:24 +08:00
|
|
|
free(players_org2);
|
|
|
|
players_org2 = NULL;
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
|
2012-12-15 06:38:27 +08:00
|
|
|
void l4dtoolz::OnChangeUnreserved ( IConVar *var, const char *pOldValue, float flOldValue )
|
|
|
|
{
|
2013-01-21 21:39:57 +08:00
|
|
|
int new_value = ((ConVar*)var)->GetInt();
|
|
|
|
int old_value = atoi(pOldValue);
|
|
|
|
if(unreserved_ptr == NULL ) {
|
2012-12-15 06:38:27 +08:00
|
|
|
Msg("unreserved_ptr init error\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
if(new_value != old_value) {
|
|
|
|
if(new_value == 1) {
|
|
|
|
write_signature(unreserved_ptr, unreserved_new);
|
|
|
|
engine->ServerCommand("sv_allow_lobby_connect_only 0\n");
|
|
|
|
} else {
|
|
|
|
write_signature(unreserved_ptr, unreserved_org);
|
|
|
|
}
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BaseAccessor : public IConCommandBaseAccessor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool RegisterConCommandBase(ConCommandBase *pCommandBase)
|
|
|
|
{
|
|
|
|
return META_REGCVAR(pCommandBase);
|
|
|
|
}
|
|
|
|
} s_BaseAccessor;
|
|
|
|
|
|
|
|
PLUGIN_EXPOSE(l4dtoolz, g_l4dtoolz);
|
|
|
|
|
|
|
|
bool l4dtoolz::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
|
|
|
{
|
2013-01-21 21:39:57 +08:00
|
|
|
|
2012-12-15 06:38:27 +08:00
|
|
|
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
|
|
|
|
|
2013-01-21 21:39:57 +08:00
|
|
|
struct base_addr_t base_addr;
|
|
|
|
base_addr.addr = NULL;
|
|
|
|
base_addr.len = 0;
|
2012-12-15 06:38:27 +08:00
|
|
|
|
2013-07-06 07:52:53 +08:00
|
|
|
find_base_from_list(matchmaking_dll, &base_addr);
|
2013-01-22 05:49:12 +08:00
|
|
|
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!lobby_match_ptr) {
|
|
|
|
lobby_match_ptr = find_signature(lobby_match, &base_addr, 1);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(lobby_match_ptr, lobby_match_new, lobby_match_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
|
2013-07-06 07:52:53 +08:00
|
|
|
find_base_from_list(engine_dll, &base_addr);
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!max_players_friend_lobby) {
|
|
|
|
max_players_friend_lobby = find_signature(friends_lobby, &base_addr, 0);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(max_players_friend_lobby, friends_lobby_new, friends_lobby_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!max_players_connect) {
|
|
|
|
max_players_connect = find_signature(max_players, &base_addr, 0);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(max_players_connect, max_players_new, max_players_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!lobby_sux_ptr) {
|
2012-12-15 06:38:27 +08:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
lobby_sux_ptr = max_players_connect;
|
|
|
|
#else
|
2013-01-21 21:39:57 +08:00
|
|
|
lobby_sux_ptr = find_signature(lobby_sux, &base_addr, 0);
|
2012-12-15 06:38:27 +08:00
|
|
|
#endif
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(lobby_sux_ptr, lobby_sux_new, lobby_sux_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2012-12-15 06:38:27 +08:00
|
|
|
#ifdef WIN32
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!max_players_server_browser) {
|
2013-01-22 04:27:24 +08:00
|
|
|
max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
|
|
|
|
get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
2013-07-09 17:57:40 +08:00
|
|
|
#endif
|
2012-12-15 06:38:27 +08:00
|
|
|
#endif
|
2013-01-21 21:39:57 +08:00
|
|
|
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) {
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(tmp_player, players_new, players_org);
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(tmp_player, players_new);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(tmp_player2, players_new2, players_org2);
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(tmp_player2, players_new2);
|
2013-01-21 17:50:58 +08:00
|
|
|
engine->ServerCommand("maxplayers 32\n");
|
|
|
|
engine->ServerCommand("L4DToolZ ivailosp@abv.bg\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!unreserved_ptr) {
|
|
|
|
unreserved_ptr = find_signature(unreserved, &base_addr, 0);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(unreserved_ptr, unreserved_new, unreserved_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
|
2013-07-06 07:52:53 +08:00
|
|
|
find_base_from_list(server_dll, &base_addr);
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!chuman_limit) {
|
|
|
|
chuman_limit = find_signature(human_limit, &base_addr, 0);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(chuman_limit, human_limit_new, human_limit_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
#ifndef WIN32
|
2013-01-21 21:39:57 +08:00
|
|
|
if(!max_players_server_browser) {
|
|
|
|
max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
|
2013-01-22 04:27:24 +08:00
|
|
|
get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
#endif
|
2013-07-09 17:57:40 +08:00
|
|
|
#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
|
2012-12-15 06:38:27 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool l4dtoolz::Unload(char *error, size_t maxlen)
|
|
|
|
{
|
|
|
|
|
|
|
|
#if !defined METAMOD_PLAPI_VERSION
|
|
|
|
SH_RELEASE_CALLCLASS(m_EngineCC);
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 17:57:40 +08:00
|
|
|
#ifdef L4D1
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(max_players_friend_lobby, friends_lobby_org);
|
2013-07-09 17:57:40 +08:00
|
|
|
write_signature(chuman_limit, human_limit_org);
|
|
|
|
free(friends_lobby_org);
|
|
|
|
free(human_limit_org);
|
|
|
|
#endif
|
|
|
|
|
2013-01-21 21:39:57 +08:00
|
|
|
write_signature(max_players_connect, max_players_org);
|
|
|
|
write_signature(lobby_sux_ptr, lobby_sux_org);
|
|
|
|
write_signature(max_players_server_browser, server_bplayers_org);
|
|
|
|
write_signature(unreserved_ptr, unreserved_org);
|
|
|
|
write_signature(lobby_match_ptr, lobby_match_org);
|
|
|
|
|
|
|
|
free(max_players_org);
|
|
|
|
free(lobby_sux_org);
|
|
|
|
free(server_bplayers_org);
|
|
|
|
free(unreserved_org);
|
2013-01-22 04:27:24 +08:00
|
|
|
free(lobby_match_org);
|
|
|
|
|
2012-12-15 06:38:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void l4dtoolz::OnVSPListening(IServerPluginCallbacks *iface)
|
|
|
|
{
|
|
|
|
vsp_callbacks = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool l4dtoolz::Pause(char *error, size_t maxlen)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool l4dtoolz::Unpause(char *error, size_t maxlen)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetLicense()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetVersion()
|
|
|
|
{
|
2013-01-21 21:54:05 +08:00
|
|
|
#ifdef __GIT_VERSION
|
|
|
|
return __GIT_VERSION;
|
|
|
|
#else
|
2015-11-01 23:49:58 +08:00
|
|
|
return "1.0.0.9r1";
|
2013-01-21 21:54:05 +08:00
|
|
|
#endif
|
2012-12-15 06:38:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetDate()
|
|
|
|
{
|
|
|
|
return __DATE__;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetLogTag()
|
|
|
|
{
|
|
|
|
return "L4DToolZ";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetAuthor()
|
|
|
|
{
|
|
|
|
return "Ivailosp";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetDescription()
|
|
|
|
{
|
|
|
|
return "Ivailosp plugin";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetName()
|
|
|
|
{
|
|
|
|
return "L4DToolZ";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *l4dtoolz::GetURL()
|
|
|
|
{
|
|
|
|
return "n/a";
|
|
|
|
}
|