-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperSlot.cpp
137 lines (113 loc) · 3.96 KB
/
SuperSlot.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
#include "SDK/amx/amx.h"
#include "SDK/plugincommon.h"
#if defined __LINUX__
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <ctype.h>
#else
#include <Windows.h>
#endif
#if defined __LINUX__
#define CConsolePool 0x81CA4B8
#define CConsole_SetIntVar 0x80A0040
#define RakServerOffset 0x40
#define RakServerInterface_SetAllowedPlayers 0x38
#else
#define CConsolePool 0x4F5FBC
#define CConsole_SetIntVar 0x48B5D0
#define RakServerOffset 0x40
#define RakServerInterface_SetAllowedPlayers 0x34
#endif
typedef void (*logprintf_t)(char* format, ...);
logprintf_t logprintf;
void **ppPluginData;
extern void *pAMXFunctions;
void **ppPlayers;
#if defined __LINUX__
unsigned char bServer;
#endif
#if defined __LINUX__
typedef void (*SetIntVar_t)(void *PoolPtr, char *varname, int data);
typedef void (*SetAllowedPlayers_t)(void *PoolPtr, unsigned short usPlayersNumber);
#else
typedef void(__thiscall* SetIntVar_t)(void *PoolPtr, char *varname, int data);
typedef void(__thiscall* SetAllowedPlayers_t)(void *PoolPtr, unsigned short usPlayersNumber);
#endif
void SetSampLevelMaxPlayers(int iCount)
{
void **pConsolePool = (void **)(*(unsigned int *)CConsolePool);
if (pConsolePool == 0) logprintf("Error. Console Pool is null");
#if defined __LINUX__
((SetIntVar_t)(CConsole_SetIntVar))(pConsolePool, "maxplayers", iCount);
#else
((SetIntVar_t)(CConsole_SetIntVar))(pConsolePool, "maxplayers", iCount);
#endif
}
void SetLowNetworkpLevelMaxPlayers(unsigned short usCount)
{
void *pRakServer = (void*)*(unsigned long*)((unsigned char*)*(unsigned long*)ppPlayers + RakServerOffset);
((SetAllowedPlayers_t)(*(unsigned long*)((unsigned char*)*(unsigned long*)pRakServer + RakServerInterface_SetAllowedPlayers)))(pRakServer, usCount);
}
static cell AMX_NATIVE_CALL n_SetServerMaxPlayers(AMX* amx, cell* params)
{
if (
(unsigned long*)ppPlayers && *(unsigned long*)ppPlayers &&
*(unsigned long*)((unsigned char*)*(unsigned long*)ppPlayers + RakServerOffset) &&
*(unsigned long*)*(unsigned long*)((unsigned char*)*(unsigned long*)ppPlayers + RakServerOffset)
)
{
unsigned short iMaxPlayerID = params[1];
if (iMaxPlayerID < 1 || iMaxPlayerID > 1000) return 0;
SetSampLevelMaxPlayers((int)iMaxPlayerID);
SetLowNetworkpLevelMaxPlayers(iMaxPlayerID);
return 1;
}
return -1;
}
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];
#if defined __LINUX__
ppPlayers = (void**)*(unsigned long*)((unsigned char*)ppData[PLUGIN_DATA_CALLPUBLIC_FS] + 10);
#else
ppPlayers = (void**)*(unsigned long*)((unsigned char*)ppData[PLUGIN_DATA_CALLPUBLIC_FS] + 1);
#endif
logprintf(" SuperSlot plugin for SA:MP Server 0.3.7 R2-1 loaded! (http://vk.com/povargek)");
return true;
}
PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
logprintf(" SuperSlot plugin for SA:MP Server 0.3.7 R2-1 unloaded! (http://vk.com/povargek)");
}
AMX_NATIVE_INFO pluginNatives[] =
{
{ "SetServerMaxPlayers", n_SetServerMaxPlayers },
{ 0, 0 }
};
#define USENAMETABLE(hdr) \
((hdr)->defsize==sizeof(AMX_FUNCSTUBNT))
#define NUMENTRIES(hdr,field,nextfield) \
(unsigned)(((hdr)->nextfield - (hdr)->field) / (hdr)->defsize)
#define GETENTRY(hdr,table,index) \
(AMX_FUNCSTUB *)((unsigned char*)(hdr) + (unsigned)(hdr)->table + (unsigned)index*(hdr)->defsize)
#define GETENTRYNAME(hdr,entry) \
( USENAMETABLE(hdr) \
? (char *)((unsigned char*)(hdr) + (unsigned)((AMX_FUNCSTUBNT*)(entry))->nameofs) \
: ((AMX_FUNCSTUB*)(entry))->name )
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;
}
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick()
{
}