-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.cpp
134 lines (97 loc) · 2.35 KB
/
source.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
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "SDK/plugincommon.h"
#include "SDK/amx/amx.h"
typedef void(*logprintf_t)(const char* format, ...);
logprintf_t logprintf;
void ** ppPluginData;
extern void * pAMXFunctions;
// [terminal]
cell AMX_NATIVE_CALL TerminalCommand(AMX* amx, cell* params)
{
int len = NULL, ret = NULL;
cell *addr = NULL;
amx_GetAddr(amx, params[1], &addr);
amx_StrLen(addr, &len);
if (len)
{
len++;
char* text = new char[len];
amx_GetString(text, addr, 0, len);
char buff[100];
snprintf(buff, sizeof(buff), "%s", text);
delete[] text;
return system(buff);
}
return 0;
}
cell AMX_NATIVE_CALL print_t(AMX* amx, cell* params)
{
int len = NULL, ret = NULL;
cell *addr = NULL;
amx_GetAddr(amx, params[1], &addr);
amx_StrLen(addr, &len);
if (len)
{
len++;
char* text = new char[len];
amx_GetString(text, addr, 0, len);
char buff[100];
snprintf(buff, sizeof(buff), "%s", text);
delete[] text;
return printf("%s", text);
}
return 0;
}
cell AMX_NATIVE_CALL TerminalTitle(AMX* amx, cell* params)
{
int len = NULL, ret = NULL;
cell *addr = NULL;
amx_GetAddr(amx, params[1], &addr);
amx_StrLen(addr, &len);
if (len)
{
len++;
char* text = new char[len];
amx_GetString(text, addr, 0, len);
HANDLE csl = GetStdHandle(STD_OUTPUT_HANDLE);;
char buff[100];
snprintf(buff, sizeof(buff), "%s", text);
delete[] text;
return SetConsoleTitleA(text);
}
return 0;
}
// hook
// ------------------------------------------------
PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
{
pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];
logprintf(" * terminal load.");
return true;
}
PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
logprintf(" * terminal plugin unload.");
}
AMX_NATIVE_INFO PluginNatives[] =
{
{ "TerminalCommand", TerminalCommand },
{ "TerminalTitle", TerminalTitle },
{ "print_t", print_t },
{ 0, 0 }
};
PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
{
return amx_Register(amx, PluginNatives, -1);
}
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
{
return AMX_ERR_NONE;
}