Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.06 KB | None | 0 0
  1. /*
  2. * SA-MP Clientside Anticheat (SAMPCAC)
  3. * Version: v0.10.0
  4. * Author: 0xCAC
  5. * Compatible with: SA-MP 0.3.7 Server
  6. * Site: https://SAMPCAC.xyz
  7. * Documentation: https://SAMPCAC.xyz/docs
  8. *
  9. *
  10. * Usage: Configure cheat detection by editing "scriptfiles/sampcac_base.ini"
  11. */
  12.  
  13. #define FILTERSCRIPT
  14.  
  15. #include <a_samp>
  16. #include <sampcac>
  17.  
  18. enum
  19. {
  20. CAC_ACTION__WARNING,
  21. CAC_ACTION__KICK,
  22. CAC_ACTION__BAN
  23. };
  24. new const g_szCheatSections[][] = {"aimbot_1", "aimbot_2", "triggerbot_1", "triggerbot_2", "nametag_wh_1", "esp_wh_1", "macro_1", "fake_ping_1", "weaponinfo_1", "norecoil_1", "norecoil_2", "aimbot_3", "aimbot_4", "cleo", "aimbot_5", "aimbot_6", "norecoil_3", "untrusted_1", "untrusted_2", "untrusted_3", "untrusted_4"};
  25. new const g_szCheatNames [][] = {"Aimbot (1)", "Aimbot (2)", "Triggerbot (1)", "Triggerbot (2)", "Nametag wallhack (1)", "ESP (1)", "Macro keybind (1)", "Fake ping (1)", "Weapon info (1)", "No recoil (1)", "No recoil (2)", "Aimbot (3)", "Aimbot (4)", "CLEO", "Aimbot (5)", "Aimbot (6)", "No recoil (3)", "Untrusted (1)", "Untrusted (2)", "Untrusted (3)", "Untrusted (4)"};
  26. new g_iCheatStatus[CAC_CHEAT__ALL];
  27. new g_iCheatActions[CAC_CHEAT__ALL];
  28. new const g_szVKNames[256][] = {
  29. "NULL", "VK_LBUTTON", "VK_RBUTTON", "VK_CANCEL", "VK_MBUTTON", "VK_XBUTTON1", "VK_XBUTTON2", "NULL", "VK_BACK", "VK_TAB", "NULL", "NULL", "VK_CLEAR", "VK_RETURN", "NULL", "NULL", "VK_SHIFT", "VK_CONTROL", "VK_MENU", "VK_PAUSE", "VK_CAPITAL", "VK_KANA", "NULL", "VK_JUNJA", "VK_FINAL", "VK_KANJI", "NULL", "VK_ESCAPE", "VK_CONVERT", "VK_NONCONVERT", "VK_ACCEPT", "VK_MODECHANGE", "VK_SPACE", "VK_PRIOR", "VK_NEXT", "VK_END", "VK_HOME", "VK_LEFT", "VK_UP", "VK_RIGHT", "VK_DOWN", "VK_SELECT", "VK_PRINT",
  30. "VK_EXECUTE", "VK_SNAPSHOT", "VK_INSERT", "VK_DELETE", "VK_HELP", "VK_0", "VK_1", "VK_2", "VK_3", "VK_4", "VK_5", "VK_6", "VK_7", "VK_8", "VK_9", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "VK_A", "VK_B", "VK_C", "VK_D", "VK_E", "VK_F", "VK_G", "VK_H", "VK_I", "VK_J", "VK_K", "VK_L", "VK_M", "VK_N", "VK_O", "VK_P", "VK_Q", "VK_R", "VK_S", "VK_T", "VK_U", "VK_V", "VK_W", "VK_X", "VK_Y", "VK_Z", "VK_LWIN", "VK_RWIN", "VK_APPS", "NULL", "VK_SLEEP", "VK_NUMPAD0", "VK_NUMPAD1", "VK_NUMPAD2",
  31. "VK_NUMPAD3", "VK_NUMPAD4", "VK_NUMPAD5", "VK_NUMPAD6", "VK_NUMPAD7", "VK_NUMPAD8", "VK_NUMPAD9", "VK_MULTIPLY", "VK_ADD", "VK_SEPARATOR", "VK_SUBTRACT", "VK_DECIMAL", "VK_DIVIDE", "VK_F1", "VK_F2", "VK_F3", "VK_F4", "VK_F5", "VK_F6", "VK_F7", "VK_F8", "VK_F9", "VK_F10", "VK_F11", "VK_F12", "VK_F13", "VK_F14", "VK_F15", "VK_F16", "VK_F17", "VK_F18", "VK_F19", "VK_F20", "VK_F21", "VK_F22", "VK_F23", "VK_F24", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "VK_NUMLOCK", "VK_SCROLL",
  32. "VK_OEM_FJ_JISHO", "VK_OEM_FJ_MASSHOU", "VK_OEM_FJ_TOUROKU", "VK_OEM_FJ_LOYA", "VK_OEM_FJ_ROYA", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "VK_LSHIFT", "VK_RSHIFT", "VK_LCONTROL", "VK_RCONTROL", "VK_LMENU", "VK_RMENU", "VK_BROWSER_BACK", "VK_BROWSER_FORWARD", "VK_BROWSER_REFRESH", "VK_BROWSER_STOP", "VK_BROWSER_SEARCH", "VK_BROWSER_FAVORITES", "VK_BROWSER_HOME", "VK_VOLUME_MUTE", "VK_VOLUME_DOWN", "VK_VOLUME_UP", "VK_MEDIA_NEXT_TRACK", "VK_MEDIA_PREV_TRACK",
  33. "VK_MEDIA_STOP", "VK_MEDIA_PLAY_PAUSE", "VK_LAUNCH_MAIL", "VK_LAUNCH_MEDIA_SELECT", "VK_LAUNCH_APP1", "VK_LAUNCH_APP2", "NULL", "NULL", "VK_OEM_1", "VK_OEM_PLUS", "VK_OEM_COMMA", "VK_OEM_MINUS", "VK_OEM_PERIOD", "VK_OEM_2", "VK_OEM_3", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "VK_OEM_4", "VK_OEM_5", "VK_OEM_6", "VK_OEM_7", "VK_OEM_8",
  34. "NULL", "VK_OEM_AX", "VK_OEM_102", "VK_ICO_HELP", "VK_ICO_00", "VK_PROCESSKEY", "VK_ICO_CLEAR", "VK_PACKET", "NULL", "VK_OEM_RESET", "VK_OEM_JUMP", "VK_OEM_PA1", "VK_OEM_PA2", "VK_OEM_PA3", "VK_OEM_WSCTRL", "VK_OEM_CUSEL", "VK_OEM_ATTN", "VK_OEM_FINISH", "VK_OEM_COPY", "VK_OEM_AUTO", "VK_OEM_ENLW", "VK_OEM_BACKTAB", "VK_ATTN", "VK_CRSEL", "VK_EXSEL", "VK_EREOF", "VK_PLAY", "VK_ZOOM", "VK_NONAME", "VK_PA1", "VK_OEM_CLEAR", "NULL"
  35. };
  36. new g_iVKStatus[256];
  37.  
  38. #if sizeof(g_szCheatSections) != CAC_CHEAT__ALL
  39. #error Your version of sampcac.inc is not compatible with this filterscript. Redownload the server package from www.SAMPCAC.xyz
  40. #endif
  41.  
  42. #if sizeof(g_szCheatSections) != sizeof(g_szCheatNames)
  43. #error Fix cheat names
  44. #endif
  45.  
  46. new g_iScreenshotStatus;
  47. new g_iScreenshotMax;
  48. new g_iScreenshotResetTime;
  49. new g_iScreenshotAction;
  50.  
  51. enum e_ScreenshotDetect
  52. {
  53. FirstTick,
  54. Count
  55. }
  56. new g_ScreenshotDetect[MAX_PLAYERS][e_ScreenshotDetect];
  57.  
  58. public OnFilterScriptInit()
  59. {
  60. new result[16], status, action, max_screenshots, reset_time;
  61. for(new i = 0; i != CAC_CHEAT__ALL; ++i)
  62. {
  63. if(getINIString("sampcac_base.ini", g_szCheatSections[i], "status", result))
  64. {
  65. if(!strcmp(result, "on", true, 2))
  66. status = 1;
  67. else
  68. status = 0;
  69. }
  70. else
  71. {
  72. status = 1;
  73. printf(" SAMPCAC: Couldn't read \"status\" key inside \"%s\" section from \"scriptfiles/sampcac_base.ini\"", g_szCheatSections[i]);
  74. printf(" SAMPCAC: \"status\" for this cheat is set as enabled by default.");
  75. }
  76.  
  77. if(getINIString("sampcac_base.ini", g_szCheatSections[i], "action", result))
  78. {
  79. if(!strcmp(result, "warning", true, 7))
  80. action = CAC_ACTION__WARNING;
  81. else if(!strcmp(result, "ban", true, 3))
  82. action = CAC_ACTION__BAN;
  83. else
  84. action = CAC_ACTION__KICK;
  85. }
  86. else
  87. {
  88. action = CAC_ACTION__KICK;
  89. printf(" SAMPCAC: Couldn't read \"action\" key inside \"%s\" section from \"scriptfiles/sampcac_base.ini\"", g_szCheatSections[i]);
  90. printf(" SAMPCAC: \"action\" for this cheat is set as \"kick\" by default.");
  91. }
  92.  
  93.  
  94. g_iCheatStatus[i] = status;
  95. g_iCheatActions[i] = action;
  96. }
  97.  
  98. if(getINIString("sampcac_base.ini", "screenshot", "status", result))
  99. {
  100. if(!strcmp(result, "on", true, 2))
  101. status = 1;
  102. else
  103. status = 0;
  104. }
  105. else
  106. {
  107. status = 1;
  108. printf(" SAMPCAC: Couldn't read \"status\" key inside \"screenshot\" section from \"scriptfiles/sampcac_base.ini\"");
  109. printf(" SAMPCAC: \"status\" is set as enabled by default.");
  110. }
  111. if(getINIString("sampcac_base.ini", "screenshot", "max_screenshots", result))
  112. {
  113. max_screenshots = strval(result);
  114. }
  115. else
  116. {
  117. max_screenshots = 1;
  118. printf(" SAMPCAC: Couldn't read \"max_screenshots\" key inside \"screenshot\" section from \"scriptfiles/sampcac_base.ini\"");
  119. printf(" SAMPCAC: \"max_screenshots\" is set to 1.");
  120. }
  121. if(getINIString("sampcac_base.ini", "screenshot", "reset_time", result))
  122. {
  123. reset_time = strval(result);
  124. }
  125. else
  126. {
  127. reset_time = 1000;
  128. printf(" SAMPCAC: Couldn't read \"reset_time\" key inside \"screenshot\" section from \"scriptfiles/sampcac_base.ini\"");
  129. printf(" SAMPCAC: \"reset_time\" is set to 1000 ms.");
  130. }
  131. if(getINIString("sampcac_base.ini", "screenshot", "action", result))
  132. {
  133. if(!strcmp(result, "warning", true, 7))
  134. action = CAC_ACTION__WARNING;
  135. else if(!strcmp(result, "ban", true, 3))
  136. action = CAC_ACTION__BAN;
  137. else
  138. action = CAC_ACTION__KICK;
  139. }
  140. else
  141. {
  142. action = CAC_ACTION__KICK;
  143. printf(" SAMPCAC: Couldn't read \"action\" key inside \"screenshot\" section from \"scriptfiles/sampcac_base.ini\"");
  144. printf(" SAMPCAC: \"action\" for screenshots is set as \"kick\" by default.");
  145. }
  146. g_iScreenshotStatus = status;
  147. g_iScreenshotMax = max_screenshots;
  148. g_iScreenshotResetTime = reset_time;
  149. g_iScreenshotAction = action;
  150.  
  151. for(new i = 0; i != 256; ++i)
  152. {
  153. if(strcmp(g_szVKNames[i], "NULL") != 0)
  154. {
  155. if(getINIString("sampcac_base.ini", "macro_key_detection", g_szVKNames[i], result))
  156. {
  157. if(!strcmp(result, "on", true, 2))
  158. status = 1;
  159. else
  160. status = 0;
  161. }
  162. else
  163. {
  164. status = 1;
  165. printf(" SAMPCAC: Couldn't read \"%s\" key inside \"macro_key_detection\" section from \"scriptfiles/sampcac_base.ini\"", g_szVKNames[i]);
  166. printf(" SAMPCAC: \"Detection status\" for this key is set as enabled by default.");
  167. }
  168. g_iVKStatus[i] = status;
  169. }
  170. }
  171. printf(" SAMPCAC anticheat base filterscript loaded.");
  172. return 1;
  173. }
  174.  
  175. public OnPlayerConnect(playerid)
  176. {
  177. g_ScreenshotDetect[playerid][FirstTick] = 0;
  178. g_ScreenshotDetect[playerid][Count] = 0;
  179. return 1;
  180. }
  181.  
  182. public CAC_OnCheatDetect(player_id, cheat_id, opt1, opt2)
  183. {
  184. if(IsValidCheatID(cheat_id) && !g_iCheatStatus[cheat_id]) // skip if detection is disabled for this cheat type
  185. return 1;
  186.  
  187. if(cheat_id == CAC_CHEAT__MACRO_1 && g_iVKStatus[opt1] == 0) // if macro key is pressed, but we disabled this key detection in "sampcac_base.ini", then ignore this call
  188. return 1;
  189.  
  190. new string[144+1], playerName[MAX_PLAYER_NAME] = "[not connected yet]", cheatName[64];
  191. if(IsPlayerConnected(player_id))
  192. GetPlayerName(player_id, playerName, sizeof(playerName));
  193.  
  194. if(IsValidCheatID(cheat_id))
  195. strcat(cheatName, g_szCheatNames[cheat_id]);
  196. else
  197. format(cheatName, sizeof(cheatName), "[invalid] [ID: %i]", cheat_id);
  198.  
  199. format(string, sizeof(string), "SAMPCAC: {FFFFFF}Cheat detected: Player: %s [ID: %i] | Cheat: %s", playerName, player_id, cheatName);
  200. if(cheat_id == CAC_CHEAT__MACRO_1)
  201. format(string, sizeof(string), "%s [Key: %s (0x%02x)]", string, g_szVKNames[opt1], opt1);
  202. SendClientMessageToAll(0xEE5555FF, string);
  203.  
  204. if(IsValidCheatID(cheat_id))
  205. {
  206. switch(g_iCheatActions[cheat_id])
  207. {
  208. case CAC_ACTION__KICK:
  209. {
  210. format(string, sizeof(string), "SAMPCAC: {FFFFFF}%s has been kicked. Reason: Cheats detected.", playerName);
  211. SendClientMessageToAll(0xEE5555FF, string);
  212. SetTimerEx("CAC_KickFix", 1000, false, "i", player_id);
  213. }
  214. case CAC_ACTION__BAN:
  215. {
  216. format(string, sizeof(string), "SAMPCAC: {FFFFFF}%s has been banned. Reason: Cheats detected.", playerName);
  217. SendClientMessageToAll(0xEE5555FF, string);
  218. SetTimerEx("CAC_BanFix", 1000, false, "i", player_id);
  219. }
  220. }
  221. }
  222. return 1;
  223. }
  224.  
  225. public CAC_OnScreenshotTaken(player_id)
  226. {
  227. if(!g_iScreenshotStatus) // skip if detection is disabled
  228. return 1;
  229.  
  230. new curTick = GetTickCount();
  231. new diffTick = curTick - g_ScreenshotDetect[player_id][FirstTick];
  232. if (diffTick >= g_iScreenshotResetTime)
  233. {
  234. g_ScreenshotDetect[player_id][Count] = 0;
  235. g_ScreenshotDetect[player_id][FirstTick] = curTick;
  236. }
  237.  
  238. if (++g_ScreenshotDetect[player_id][Count] > g_iScreenshotMax)
  239. {
  240. new string[144+1], playerName[MAX_PLAYER_NAME] = "[not connected yet]";
  241. if(IsPlayerConnected(player_id))
  242. GetPlayerName(player_id, playerName, sizeof(playerName));
  243.  
  244. format(string, sizeof(string), "SAMPCAC: {FFFFFF}Screenshot: Player: %s [ID: %i] took %i screenshot(s) in %i ms.", playerName, player_id, g_ScreenshotDetect[player_id][Count], diffTick);
  245. SendClientMessageToAll(0xEE5555FF, string);
  246.  
  247. switch(g_iScreenshotAction)
  248. {
  249. case CAC_ACTION__KICK:
  250. {
  251. format(string, sizeof(string), "SAMPCAC: {FFFFFF}%s has been kicked. Reason: Too many screenshots.", playerName);
  252. SendClientMessageToAll(0xEE5555FF, string);
  253. SetTimerEx("CAC_KickFix", 1000, false, "i", player_id);
  254. }
  255. case CAC_ACTION__BAN:
  256. {
  257. format(string, sizeof(string), "SAMPCAC: {FFFFFF}%s has been banned. Reason: Too many screenshots.", playerName);
  258. SendClientMessageToAll(0xEE5555FF, string);
  259. SetTimerEx("CAC_BanFix", 1000, false, "i", player_id);
  260. }
  261. }
  262. }
  263. return 1;
  264. }
  265.  
  266. forward CAC_KickFix(player_id);
  267. public CAC_KickFix(player_id) { Kick(player_id); }
  268.  
  269. forward CAC_BanFix(player_id);
  270. public CAC_BanFix(player_id) { Ban(player_id); }
  271.  
  272. // Slightly modified code from: http://wiki.sa-mp.com/wiki/How_to_read_from_INI_files
  273. getINIString(const filename[], const section[], const item[], result[], max_size = sizeof(result)) {
  274. new File: inifile;
  275. new line[512];
  276. new sectionstr[64], itemstr[64];
  277. new sectionfound = 0;
  278.  
  279. inifile = fopen(filename, io_read);
  280. if (!inifile) {
  281. return 0;
  282. }
  283.  
  284. format(sectionstr, sizeof(sectionstr), "[%s]", section);
  285. format(itemstr, sizeof(itemstr), "%s=", item);
  286.  
  287. while (fread(inifile, line)) {
  288. StripNewLine(line);
  289.  
  290. if (line[0] == 0) {
  291. continue;
  292. }
  293.  
  294. /* If !sectionfound is true, we're looking for the proper section. */
  295. if (!sectionfound) {
  296. /* Check if wanted section is being opened. */
  297. if (!strcmp(line, sectionstr, true, strlen(sectionstr))) {
  298. sectionfound = 1;
  299. }
  300. } else { /* Itemmode from here. */
  301. /* We're leaving the wanted section and didn't find the value yet.
  302. * So we'll never reach it. */
  303. if (line[0] == '[') {
  304. fclose(inifile);
  305. return 0;
  306. }
  307.  
  308. /* Have we reached our wanted INI item? */
  309. if (!strcmp(line, itemstr, true, strlen(itemstr))) {
  310. format(result, max_size, "%s", line[strlen(itemstr)]);
  311. fclose(inifile);
  312. return 1;
  313. }
  314. }
  315. }
  316.  
  317. fclose(inifile);
  318. return 0;
  319. }
  320.  
  321. // http://forum.sa-mp.com/showpost.php?p=2908420&postcount=2
  322. StripNewLine(string[])
  323. {
  324. new len = strlen(string);
  325. if (len >= 1 && ((string[len - 1] == '\n') || (string[len - 1] == '\r'))) {
  326. string[len - 1] = 0;
  327. if (len >= 2 && ((string[len - 2] == '\n') || (string[len - 2] == '\r'))) string[len - 2] = 0;
  328. }
  329. }
  330.  
  331. IsValidCheatID(cheat_id)
  332. {
  333. return (0 <= cheat_id < CAC_CHEAT__ALL);
  334. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement