Repository navigation
Expand file tree
/
Copy pathaddons_disabler.cpp
More file actions
130 lines (111 loc) · 4.6 KB
/
Copy pathaddons_disabler.cpp
File metadata and controls
130 lines (111 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* vim: set ts=4 :
* =============================================================================
* Left 4 Downtown SourceMod Extension
* Copyright (C) 2009-2011 Downtown1, ProdigySim; 2012-2015 Visor
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include "extension.h"
#include "addons_disabler.h"
#include "CDetour/detourhelpers.h"
static void *vanillaModeSig = NULL;
static patch_t vanillaModeSigRestore;
extern ConVar g_AddonsEclipse;
int AddonsDisabler::AddonsEclipse;
void AddonsDisabler::Patch()
{
L4D_DEBUG_LOG("AddonsDisabler - Patching ...");
bool firstTime = (vanillaModeSig == NULL);
if (firstTime)
{
if (!g_pGameConf->GetMemSig("VanillaModeOffset", &vanillaModeSig) || !vanillaModeSig)
{
g_pSM->LogError(myself, "AddonsDisabler -- Could not find 'VanillaModeOffset' signature");
return;
}
}
patch_t vanillaModePatch;
vanillaModePatch.bytes = 3;
// mov esi+19h -> NOP
vanillaModePatch.patch[0] = 0x0f;
vanillaModePatch.patch[1] = 0x1f;
vanillaModePatch.patch[2] = 0x00;
#ifdef PLATFORM_WINDOWS
ApplyPatch(vanillaModeSig, /*offset*/0, &vanillaModePatch, /*restore*/firstTime ? &vanillaModeSigRestore : NULL);
#else
ApplyPatch(vanillaModeSig, /*offset*/4, &vanillaModePatch, /*restore*/firstTime ? &vanillaModeSigRestore : NULL);
#endif
L4D_DEBUG_LOG("AddonsDisabler -- 'VanillaModeOffset' patched to NOP");
}
void AddonsDisabler::Unpatch()
{
L4D_DEBUG_LOG("AddonsDisabler - Unpatching ...");
if (vanillaModeSig)
{
#ifdef PLATFORM_WINDOWS
ApplyPatch(vanillaModeSig, /*offset*/0, &vanillaModeSigRestore, /*restore*/NULL);
#else
ApplyPatch(vanillaModeSig, /*offset*/4, &vanillaModeSigRestore, /*restore*/NULL);
#endif
L4D_DEBUG_LOG("AddonsDisabler -- 'VanillaModeOffset' restored");
}
}
void OnAddonsEclipseChanged( IConVar *var, const char *pOldValue, float flOldValue )
{
if (AddonsDisabler::AddonsEclipse == g_AddonsEclipse.GetInt())
return;
AddonsDisabler::AddonsEclipse = g_AddonsEclipse.GetInt();
L4D_DEBUG_LOG("CVAR l4d2_addons_eclipse changed to %i...", AddonsDisabler::AddonsEclipse);
if (AddonsDisabler::AddonsEclipse > -1)
{
L4D_DEBUG_LOG("Enabling AddonsDisabler patch");
AddonsDisabler::Patch();
}
else
{
L4D_DEBUG_LOG("Disabling AddonsDisabler patch");
AddonsDisabler::Unpatch();
}
}
namespace Detours
{
void CBaseServer::OnFillServerInfo(int SVC_ServerInfo)
{
cell_t result = Pl_Continue;
if (g_pFwdAddonsDisabler && AddonsDisabler::AddonsEclipse > 0 && vanillaModeSig)
{
int m_nPlayerSlot = *(int *)((unsigned char *)SVC_ServerInfo + 48);
IClient *pClient = g_pServer->GetClient(m_nPlayerSlot);
L4D_DEBUG_LOG("ADDONS DISABLER: Eligible client '%s' connected[%s]", pClient->GetClientName(), pClient->GetNetworkIDString());
g_pFwdAddonsDisabler->PushString(pClient->GetNetworkIDString());
g_pFwdAddonsDisabler->Execute(&result);
/* uint8_t != unsigned char in terms of type */
uint8_t disableAddons = result == Pl_Handled ? 0 : 1;
memset((unsigned char *)SVC_ServerInfo + 25, disableAddons, sizeof(uint8_t));
}
(this->*(GetTrampoline()))(SVC_ServerInfo);
}
};