-
Notifications
You must be signed in to change notification settings - Fork 15
/
MovementUnlocker.cpp
185 lines (156 loc) · 4.67 KB
/
MovementUnlocker.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* =============================================================================
* Movement Unlocker
* Copyright (C) 2024 Source2ZE
* =============================================================================
*
* 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/>.
*/
#include <stdio.h>
#include "MovementUnlocker.h"
#include <sh_memory.h>
#ifdef _WIN32
#include <Windows.h>
#elif __linux__
#include <dlfcn.h>
#endif
MovementUnlocker g_MovementUnlocker;
#ifdef _WIN32
const unsigned char *pPatchSignature = (unsigned char *)"\x76\x2A\xF2\x0F\x10\x4F\x2A\x41\x0F\x28\xC1\x0F\x28\xD1\xF3\x0F\x59\xC0";
const char *pPatchPattern = "x?xxxx?xxxxxxxxxxx";
int PatchLen = 1;
#elif __linux__
const unsigned char * pPatchSignature = (unsigned char *)"\x0F\x87\x2A\x2A\x2A\x2A\x49\x8B\x7C\x24\x2A\xE8\x2A\x2A\x2A\x2A\x66\x0F\xEF\xED\x66\x0F\xD6\x85";
const char* pPatchPattern = "xx????xxxx?x????xxxxxxxx";
int PatchLen = 6;
#endif
// From https://git.botox.bz/CSSZombieEscape/sm-ext-PhysHooks
uintptr_t FindPattern(uintptr_t BaseAddr, const unsigned char* pData, const char* pPattern, size_t MaxSize, bool Reverse)
{
unsigned char* pMemory;
uintptr_t PatternLen = strlen(pPattern);
pMemory = reinterpret_cast<unsigned char*>(BaseAddr);
if (!Reverse)
{
for (uintptr_t i = 0; i < MaxSize; i++)
{
uintptr_t Matches = 0;
while (*(pMemory + i + Matches) == pData[Matches] || pPattern[Matches] != 'x')
{
Matches++;
if (Matches == PatternLen)
return (uintptr_t)(pMemory + i);
}
}
}
else
{
for (uintptr_t i = 0; i < MaxSize; i++)
{
uintptr_t Matches = 0;
while (*(pMemory - i + Matches) == pData[Matches] || pPattern[Matches] != 'x')
{
Matches++;
if (Matches == PatternLen)
return (uintptr_t)(pMemory - i);
}
}
}
return 0x00;
}
PLUGIN_EXPOSE(MovementUnlocker, g_MovementUnlocker);
bool MovementUnlocker::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
char pBinPath[MAX_PATH];
#ifdef _WIN32
V_snprintf(pBinPath, MAX_PATH, "%s%s", Plat_GetGameDirectory(), "/csgo/bin/win64/server.dll");
auto *pBin = LoadLibrary(pBinPath);
#elif __linux__
V_snprintf(pBinPath, MAX_PATH, "%s%s", Plat_GetGameDirectory(), "/csgo/bin/linuxsteamrt64/libserver.so");
auto *pBin = dlopen(pBinPath, RTLD_NOW);
#endif
if (!pBin)
{
snprintf(error, maxlen, "Could not open %s", pBinPath);
return false;
}
#ifdef _WIN32
uintptr_t pPatchAddress = (uintptr_t)GetProcAddress(pBin, "CreateInterface");
#elif __linux__
uintptr_t pPatchAddress = (uintptr_t)dlsym(pBin, "CreateInterface");
#endif
pPatchAddress = FindPattern(pPatchAddress, pPatchSignature, pPatchPattern, ULLONG_MAX, true);
if (!pPatchAddress)
{
snprintf(error, maxlen, "Could not find WalkMove patch signature!");
return false;
}
SourceHook::SetMemAccess((void*)pPatchAddress, PatchLen, SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC);
#ifdef _WIN32
*(unsigned char*)(pPatchAddress) = ((unsigned char*)"\xEB")[0];
#elif __linux__
for (int i = 0; i < PatchLen; i++)
*(unsigned char*)(pPatchAddress + i) = ((unsigned char*)"\x90")[0];
#endif
SourceHook::SetMemAccess((void*)pPatchAddress, PatchLen, SH_MEM_READ | SH_MEM_EXEC);
META_CONPRINTF( "[Movement Unlocker] Successfully patched Movement Unlocker!\n" );
return true;
}
bool MovementUnlocker::Unload(char *error, size_t maxlen)
{
return true;
}
void MovementUnlocker::AllPluginsLoaded()
{
}
bool MovementUnlocker::Pause(char *error, size_t maxlen)
{
return true;
}
bool MovementUnlocker::Unpause(char *error, size_t maxlen)
{
return true;
}
const char *MovementUnlocker::GetLicense()
{
return "GNU General Public License v3.0";
}
const char *MovementUnlocker::GetVersion()
{
return "1.4";
}
const char *MovementUnlocker::GetDate()
{
return __DATE__;
}
const char *MovementUnlocker::GetLogTag()
{
return "MOVEMENTUNLOCKER";
}
const char *MovementUnlocker::GetAuthor()
{
return "Vauff";
}
const char *MovementUnlocker::GetDescription()
{
return "Removes max speed limitation from players on the ground, feels like CS:S";
}
const char *MovementUnlocker::GetName()
{
return "Movement Unlocker";
}
const char *MovementUnlocker::GetURL()
{
return "https://github.com/Source2ZE/MovementUnlocker";
}