cssdm_main.cpp
author Ruben Gonzalez <drifter01620@gmail.com>
Wed Oct 01 11:50:24 2014 -0400 (2014-10-01)
changeset 193 277c856152b0
parent 59 41feee1fac07
permissions -rw-r--r--
Update linix CS:GO gamedata
[email protected]
     1
/**
[email protected]
     2
 * vim: set ts=4 :
[email protected]
     3
 * ===============================================================
[email protected]
     4
 * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC. 
[email protected]
     5
 * By David "BAILOPAN" Anderson
[email protected]
     6
 * All rights reserved.
[email protected]
     7
 * ===============================================================
[email protected]
     8
 *
[email protected]
     9
 * This program is free software; you can redistribute it and/or modify
[email protected]
    10
 * it under the terms of the GNU General Public License as published by
[email protected]
    11
 * the Free Software Foundation; either version 2 of the License, or (at
[email protected]
    12
 * your option) any later version.
[email protected]
    13
 * 
[email protected]
    14
 * This program is distributed in the hope that it will be useful, but
[email protected]
    15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
[email protected]
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
[email protected]
    17
 * General Public License for more details.
[email protected]
    18
 * 
[email protected]
    19
 * You should have received a copy of the GNU General Public License
[email protected]
    20
 * along with this program; see the file COPYING; if not, write to the
[email protected]
    21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
[email protected]
    22
 * MA 02110-1301 USA
[email protected]
    23
 * 
[email protected]
    24
 * Version: $Id$
[email protected]
    25
 */
[email protected]
    26
[email protected]
    27
[email protected]
    28
#include "cssdm_main.h"
[email protected]
    29
#include "cssdm_headers.h"
[email protected]
    30
#include "cssdm_utils.h"
[email protected]
    31
#include "cssdm_events.h"
[email protected]
    32
#include "cssdm_players.h"
[email protected]
    33
#include "cssdm_ctrl.h"
[email protected]
    34
#include "cssdm_config.h"
[email protected]
    35
#include "cssdm_ffa.h"
[email protected]
    36
#include "cssdm_callbacks.h"
[email protected]
    37
#include "cssdm_weapons.h"
[email protected]
    38
#include "cssdm_detours.h"
[email protected]
    39
#include "cssdm_version.h"
[email protected]
    40
[email protected]
    41
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
[email protected]
    42
SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0)
[email protected]
    43
SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, false);
[email protected]
    44
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, false, edict_t *, const CCommand &);
[email protected]
    45
[email protected]
    46
Deathmatch g_DM;
[email protected]
    47
IGameEventManager2 *gameevents = NULL;
[email protected]
    48
IBaseFileSystem *basefilesystem = NULL;
[email protected]
    49
IBinTools *bintools = NULL;
[email protected]
    50
IGameConfig *g_pDmConf = NULL;
[email protected]
    51
CGlobalVars *gpGlobals = NULL;
[email protected]
    52
IPlayerInfoManager *playerinfomngr = NULL;
[email protected]
    53
IServerGameEnts *gameents = NULL;
[email protected]
    54
IServerGameClients *gameclients = NULL;
[email protected]
    55
ISourcePawnEngine *spengine = NULL;
[email protected]
    56
IBotManager *botmanager = NULL;
[email protected]
    57
char g_GlobError[255] = {0};
[email protected]
    58
bool g_IsLoadedOkay = false;
[email protected]
    59
bool g_Startup = false;
[email protected]
    60
bool g_IsInGlobalShutdown = false;
[email protected]
    61
[email protected]
    62
SMEXT_LINK(&g_DM);
[email protected]
    63
[email protected]
    64
#define VERIFY_SIGNATURE(name) \
[email protected]
    65
	if (!g_pDmConf->GetMemSig(name, &addr) || !addr) { \
[email protected]
    66
		snprintf(error, maxlength, "Could not find signature \"%s\"", name); \
[email protected]
    67
		return false; \
[email protected]
    68
	}
[email protected]
    69
[email protected]
    70
#define VERIFY_OFFSET(name) \
[email protected]
    71
	if (!g_pDmConf->GetOffset(name, &offset) || !offset) { \
[email protected]
    72
		snprintf(error, maxlength, "Could not find offset \"%s\"", name); \
[email protected]
    73
		return false; \
[email protected]
    74
	}
[email protected]
    75
[email protected]
    76
#define HOOK_EVENT2(name) \
[email protected]
    77
	if (!gameevents->AddListener(&g_cls_event_##name, #name, true)) { \
[email protected]
    78
		snprintf(error, maxlength, "Could not hook event \"%s\"", #name); \
[email protected]
    79
		return false; \
[email protected]
    80
	}
[email protected]
    81
[email protected]
    82
#define UNHOOK_EVENT2(name) gameevents->RemoveListener(&g_cls_event_##name);
[email protected]
    83
[email protected]
    84
bool Deathmatch::SDK_OnLoad(char *error, size_t maxlength, bool late)
[email protected]
    85
{
[email protected]
    86
	sharesys->AddDependency(myself, "bintools.ext", true, true);
[email protected]
    87
	sharesys->AddNatives(myself, g_BaseNatives);
[email protected]
    88
	if (!gameconfs->LoadGameConfigFile("cssdm.games", &g_pDmConf, error, maxlength))
[email protected]
    89
	{
[email protected]
    90
		return false;
[email protected]
    91
	}
[email protected]
    92
[email protected]
    93
	void *addr;
[email protected]
    94
	int offset;
[email protected]
    95
	VERIFY_OFFSET("CSWeaponDropPatch");
[email protected]
    96
	VERIFY_SIGNATURE("RoundRespawn");
[email protected]
    97
	VERIFY_SIGNATURE("CSWeaponDrop");
[email protected]
    98
	VERIFY_SIGNATURE("DropWeapons");
[email protected]
    99
	VERIFY_OFFSET("Weapon_GetSlot");
[email protected]
   100
	VERIFY_OFFSET("RemoveAllItems");
[email protected]
   101
	VERIFY_OFFSET("DropWeaponsPatch");
[email protected]
   102
	VERIFY_OFFSET("GiveAmmo");
[email protected]
   103
[email protected]
   104
	if (!DM_ParseWeapons(error, maxlength))
[email protected]
   105
	{
[email protected]
   106
		return false;
[email protected]
   107
	}
[email protected]
   108
[email protected]
   109
	gpGlobals = g_SMAPI->GetCGlobals();
[email protected]
   110
[email protected]
   111
	SM_InitConCommandBase();
[email protected]
   112
[email protected]
   113
	spengine = g_pSM->GetScriptingEngine();
[email protected]
   114
[email protected]
   115
	return true;
[email protected]
   116
}
[email protected]
   117
[email protected]
   118
bool Deathmatch::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
[email protected]
   119
{
[email protected]
   120
	GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
[email protected]
   121
	GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
[email protected]
   122
	GET_V_IFACE_ANY(GetServerFactory, playerinfomngr, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
[email protected]
   123
	GET_V_IFACE_ANY(GetServerFactory, gameents,IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
[email protected]
   124
	GET_V_IFACE_ANY(GetServerFactory, botmanager, IBotManager, INTERFACEVERSION_PLAYERBOTMANAGER);
[email protected]
   125
	GET_V_IFACE_ANY(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
[email protected]
   126
	GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
[email protected]
   127
[email protected]
   128
	return true;
[email protected]
   129
}
[email protected]
   130
[email protected]
   131
void OnDLLShutdown()
[email protected]
   132
{
[email protected]
   133
	g_IsInGlobalShutdown = true;
[email protected]
   134
	RETURN_META(MRES_IGNORED);
[email protected]
   135
}
[email protected]
   136
[email protected]
   137
void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
[email protected]
   138
{
[email protected]
   139
	OnLevelInitialized();
[email protected]
   140
	RETURN_META(MRES_IGNORED);
[email protected]
   141
}
[email protected]
   142
[email protected]
   143
void LevelShutdown()
[email protected]
   144
{
[email protected]
   145
	OnLevelEnd();
[email protected]
   146
	RETURN_META(MRES_IGNORED);
[email protected]
   147
}
[email protected]
   148
[email protected]
   149
bool Startup(char *error, size_t maxlength)
[email protected]
   150
{
[email protected]
   151
	playerhelpers->AddClientListener(&g_ClientListener);
[email protected]
   152
[email protected]
   153
	HOOK_EVENT2(player_death);
[email protected]
   154
	HOOK_EVENT2(player_spawn);
[email protected]
   155
	HOOK_EVENT2(player_team);
[email protected]
   156
	HOOK_EVENT2(round_start);
[email protected]
   157
	HOOK_EVENT2(round_end);
[email protected]
   158
	HOOK_EVENT2(server_shutdown);
[email protected]
   159
	HOOK_EVENT2(item_pickup);
[email protected]
   160
[email protected]
   161
	g_Startup = true;
[email protected]
   162
[email protected]
   163
	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, gamedll, ServerActivate, true);
[email protected]
   164
	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, gamedll, LevelShutdown, false);
[email protected]
   165
	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, gamedll, OnDLLShutdown, false);
[email protected]
   166
	SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, OnClientCommand_Post, true);
[email protected]
   167
[email protected]
   168
	DM_InitCallbacks();
[email protected]
   169
[email protected]
   170
	char ffa_error[255];
[email protected]
   171
	if (!DM_Prepare_FFA(ffa_error, sizeof(ffa_error)))
[email protected]
   172
	{
[email protected]
   173
		g_pSM->LogError(myself, "FFA will not work: %s", ffa_error);
[email protected]
   174
	}
[email protected]
   175
[email protected]
   176
	DM_InitDetours();
[email protected]
   177
[email protected]
   178
	return InitializeUtils(error, maxlength);
[email protected]
   179
}
[email protected]
   180
[email protected]
   181
void Shutdown()
[email protected]
   182
{
[email protected]
   183
	/* Remove hooks that could have happened whether we got started up or not */
[email protected]
   184
	playerhelpers->RemoveClientListener(&g_ClientListener);
[email protected]
   185
[email protected]
   186
	UNHOOK_EVENT2(player_death);
[email protected]
   187
	UNHOOK_EVENT2(player_spawn);
[email protected]
   188
	UNHOOK_EVENT2(player_team);
[email protected]
   189
	UNHOOK_EVENT2(round_start);
[email protected]
   190
	UNHOOK_EVENT2(round_end);
[email protected]
   191
	UNHOOK_EVENT2(server_shutdown);
[email protected]
   192
	UNHOOK_EVENT2(item_pickup);
[email protected]
   193
[email protected]
   194
	/* If we were never started up, the rest of this is invalid */
[email protected]
   195
	if (!g_Startup)
[email protected]
   196
	{
[email protected]
   197
		return;
[email protected]
   198
	}
[email protected]
   199
[email protected]
   200
	/* Make sure stuff like FFA is cleaned up */
[email protected]
   201
	DM_Disable();
[email protected]
   202
[email protected]
   203
	/* Destroy various internal things */
[email protected]
   204
	DM_ShutdownDetours();
[email protected]
   205
	DM_ShutdownCallbacks();
[email protected]
   206
	DM_FreeWeapons();
[email protected]
   207
	ShutdownUtils();
[email protected]
   208
[email protected]
   209
	/* Unhook everything from SourceHook */
[email protected]
   210
	SH_REMOVE_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, OnClientCommand_Post, true);
[email protected]
   211
	SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, gamedll, OnDLLShutdown, false);
[email protected]
   212
	SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, gamedll, LevelShutdown, false);
[email protected]
   213
	SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, gamedll, ServerActivate, true);
[email protected]
   214
}
[email protected]
   215
[email protected]
   216
void Deathmatch::SDK_OnAllLoaded()
[email protected]
   217
{
[email protected]
   218
	SM_GET_LATE_IFACE(BINTOOLS, bintools);
[email protected]
   219
[email protected]
   220
	g_IsLoadedOkay = Startup(g_GlobError, sizeof(g_GlobError));
[email protected]
   221
[email protected]
   222
	if (!QueryRunning(NULL, 0))
[email protected]
   223
	{
[email protected]
   224
		return;
[email protected]
   225
	}
[email protected]
   226
}
[email protected]
   227
[email protected]
   228
void Deathmatch::SDK_OnUnload()
[email protected]
   229
{
[email protected]
   230
	DM_FreeWeapons();
[email protected]
   231
	Shutdown();
[email protected]
   232
	gameconfs->CloseGameConfigFile(g_pDmConf);
[email protected]
   233
}
[email protected]
   234
[email protected]
   235
bool Deathmatch::QueryRunning(char *error, size_t maxlength)
[email protected]
   236
{
[email protected]
   237
	SM_CHECK_IFACE(BINTOOLS, bintools);
[email protected]
   238
[email protected]
   239
	if (!g_IsLoadedOkay && g_GlobError[0] != '\0')
[email protected]
   240
	{
[email protected]
   241
		snprintf(error, maxlength, "%s", g_GlobError);
[email protected]
   242
		return false;
[email protected]
   243
	}
[email protected]
   244
[email protected]
   245
	return true;
[email protected]
   246
}
[email protected]
   247
[email protected]
   248
bool Deathmatch::QueryInterfaceDrop(SMInterface *pInterface)
[email protected]
   249
{
[email protected]
   250
	if (pInterface == bintools)
[email protected]
   251
	{
[email protected]
   252
		return false;
[email protected]
   253
	}
[email protected]
   254
[email protected]
   255
	return true;
[email protected]
   256
}
[email protected]
   257
[email protected]
   258
void Deathmatch::NotifyInterfaceDrop(SMInterface *pInterface)
[email protected]
   259
{
[email protected]
   260
	/* We have to take care of bintools early then... */
[email protected]
   261
	if (pInterface == bintools)
[email protected]
   262
	{
[email protected]
   263
		ShutdownUtils();
[email protected]
   264
		bintools = NULL;
[email protected]
   265
	}
[email protected]
   266
}
[email protected]
   267
[email protected]
   268
const char *Deathmatch::GetExtensionVerString()
[email protected]
   269
{
[email protected]
   270
	return CSSDM_FULL_VERSION;
[email protected]
   271
}
[email protected]
   272