-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (78 loc) · 2.97 KB
/
main.cpp
File metadata and controls
103 lines (78 loc) · 2.97 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
#include "GarrysMod/Lua/Interface.h"
#include "vmthook.h"
#include "util.h"
#include "windows.h"
#define CREATELUAINTERFACE 4
#define CLOSELUAINTERFACE 5
#define RUNSTRINGEX 111
typedef unsigned char uchar;
VMTHook* luaSharedVMTHook;
VMTHook* luaClientVMTHook;
using namespace GarrysMod;
Lua::ILuaBase *MENU;
lua_State *clientState;
typedef void *(__thiscall *RunStringExHookFn)(void *thisptr, const char *fileName, const char *path, const char *stringToRun, bool run, bool showErrors, bool, bool);
void * __fastcall RunStringExHook(void *thisptr, int edx, const char *fileName, const char *path, const char *stringToRun, bool run, bool showErrors, bool a, bool b)
{
MENU->PushSpecial(Lua::SPECIAL_GLOB);
MENU->GetField(-1, "hook");
MENU->GetField(-1, "Call");
MENU->PushString("RunOnClient");
MENU->PushNil();
MENU->PushString(fileName);
MENU->PushString(stringToRun);
MENU->Call(4, 1);
if (!MENU->IsType(-1, Lua::Type::NIL))
stringToRun = MENU->CheckString();
MENU->Pop(3);
return luaClientVMTHook->GetOriginalFunction<RunStringExHookFn>(RUNSTRINGEX)(thisptr, fileName, path, stringToRun, run, showErrors, a, b);
}
typedef lua_State *(__thiscall *CreateLuaInterfaceHookFn)(void *thisptr, unsigned char stateType, bool renew);
lua_State * __fastcall CreateLuaInterfaceHook(void *thisptr, int edx, unsigned char stateType, bool renew)
{
lua_State *state = luaSharedVMTHook->GetOriginalFunction<CreateLuaInterfaceHookFn>(CREATELUAINTERFACE)(thisptr, stateType, renew);
MENU->PushSpecial(Lua::SPECIAL_GLOB);
MENU->GetField(-1, "hook");
MENU->GetField(-1, "Call");
MENU->PushString("ClientStateCreated");
MENU->PushNil();
MENU->Call(2, 0);
MENU->Pop(2);
if (stateType != 0)
return state;
clientState = state;
luaClientVMTHook = new VMTHook(state);
luaClientVMTHook->HookFunction(&RunStringExHook, RUNSTRINGEX);
return clientState;
}
typedef void *(__thiscall *CloseLuaInterfaceHookFn)(void *thisptr, void *state);
void * __fastcall CloseLuaInterfaceHook(void *thisptr, int edx, lua_State *state)
{
if (state == clientState)
clientState = NULL;
return luaSharedVMTHook->GetOriginalFunction<CloseLuaInterfaceHookFn>(CLOSELUAINTERFACE)(thisptr, state);
}
int RunOnClient(lua_State *state)
{
LUA->CheckType(1, GarrysMod::Lua::Type::STRING);
if (!clientState)
LUA->ThrowError("Not in game");
luaClientVMTHook->GetOriginalFunction<RunStringExHookFn>(RUNSTRINGEX)(clientState, "", "", LUA->CheckString(1), true, true, true, true);
return 0;
}
GMOD_MODULE_OPEN()
{
MENU = LUA;
auto luaShared = util::GetInterfaceSingle<void *>("lua_shared.dll", "LUASHARED003");
if (!luaShared)
MessageBoxA(NULL, "gay", "gay", NULL);
luaSharedVMTHook = new VMTHook(luaShared);
luaSharedVMTHook->HookFunction(&CreateLuaInterfaceHook, CREATELUAINTERFACE);
luaSharedVMTHook->HookFunction(&CloseLuaInterfaceHook, CLOSELUAINTERFACE);
LUA->PushSpecial(Lua::SPECIAL_GLOB);
LUA->PushString("RunOnClient");
LUA->PushCFunction(RunOnClient);
LUA->SetTable(-3);
LUA->Pop();
return 0;
}