-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLuaUnlocker.cpp
165 lines (137 loc) · 3.66 KB
/
LuaUnlocker.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
//Stolen entirely from https://github.com/Source2ZE/MovementUnlocker
//Edited for unlocking Lua
//With lots of help from Vauff & tilgep
#include <stdio.h>
#include "LuaUnlocker.h"
#include <sh_memory.h>
#ifdef _WIN32
#include <Windows.h>
#elif __linux__
#include <dlfcn.h>
#endif
LuaUnlocker g_LuaUnlocker;
#ifdef _WIN32
const unsigned char *pPatchSignature = (unsigned char *)"\xBE\x01\x2A\x2A\x2A\x2B\xD6\x74\x2A\x3B\xD6";
const char *pPatchPattern = "xx???xxx?xx";
int offset = 1;
#elif __linux__
const unsigned char * pPatchSignature = (unsigned char *)"\x83\xFE\x01\x0F\x84\x2A\x2A\x2A\x2A\x83";
const char* pPatchPattern = "xxxxx????x";
int offset = 2;
#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(LuaUnlocker, g_LuaUnlocker);
bool LuaUnlocker::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(), "/bin/win64/vscript.dll");
auto *pBin = LoadLibrary(pBinPath);
#elif __linux__
V_snprintf(pBinPath, MAX_PATH, "%s%s", Plat_GetGameDirectory(), "/bin/linuxsteamrt64/libvscript.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 VScript patch signature!");
return false;
}
//Patch
SourceHook::SetMemAccess((void*)(pPatchAddress + offset), 1, SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC);
*(unsigned char*)(pPatchAddress + offset) = ((unsigned char*)"\x02")[0];
SourceHook::SetMemAccess((void*)(pPatchAddress + offset), 1, SH_MEM_READ | SH_MEM_EXEC);
META_CONPRINTF( "[Lua Unlocker] Successfully patched Lua Unlocker!\n" );
return true;
}
bool LuaUnlocker::Unload(char *error, size_t maxlen)
{
return true;
}
void LuaUnlocker::AllPluginsLoaded()
{
}
bool LuaUnlocker::Pause(char *error, size_t maxlen)
{
return true;
}
bool LuaUnlocker::Unpause(char *error, size_t maxlen)
{
return true;
}
const char * LuaUnlocker::GetLicense()
{
return "GNU General Public License v3.0";
}
const char * LuaUnlocker::GetVersion()
{
return "1.0";
}
const char * LuaUnlocker::GetDate()
{
return __DATE__;
}
const char * LuaUnlocker::GetLogTag()
{
return "LUAUNLOCKER";
}
const char * LuaUnlocker::GetAuthor()
{
return "Hichatu";
}
const char * LuaUnlocker::GetDescription()
{
return "Enables the use of the Lua VScripting language in CS2";
}
const char * LuaUnlocker::GetName()
{
return "Lua Unlocker";
}
const char * LuaUnlocker::GetURL()
{
return "https://github.com/Source2ZE/LuaUnlocker";
}