Advertisement
clark

RAC Roit Anti Cheat

Dec 29th, 2011
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  1. if SERVER and not CLIENT then return end
  2. require "usermessage"
  3.  
  4. local GetConVar = GetConVar
  5. local GetConVarNumber = GetConVarNumber
  6. local GetConVarString = GetConVarNumber
  7. local setmetatable = setmetatable
  8. local getmetatable = getmetatable
  9. local RunConsoleCommand = RunConsoleCommand
  10. local AddConsoleCommand = AddConsoleCommand
  11. local engineConsoleCommand = engineConsoleCommand
  12. local rawget = rawget
  13. local rawset = rawset
  14. local type = type
  15. local string = string
  16. local math = math
  17. local timer = require "timer"
  18. local _hook = require "hook"
  19. local _debug = debug
  20. local _util = util
  21. local pcall = pcall
  22. local UAC = {}
  23.  
  24. local bResponse = false
  25. local bInform = false
  26. local bDebugValid = false
  27. local bMetaValid = false
  28. local protected_struct = {
  29.     "hook",
  30.     "debug"
  31. }
  32. local debug_struct = {
  33.     "getupvalue",
  34.     "sethook",
  35.     "getlocal",
  36.     "setlocal",
  37.     "gethook",
  38.     "getmetatable",
  39.     "setmetatable",
  40.     "traceback",
  41.     "setfenv",
  42.     "getinfo",
  43.     "setupvalue",
  44.     "getregistry",
  45.     "getfenv",
  46. }
  47. local detour_check_struct = {
  48.     ["file"] = {
  49.         "Read",
  50.         "Write",
  51.         "Exists",
  52.         "Find"
  53.     },
  54.     ["debug"] = {
  55.         "getupvalue",
  56.         "sethook",
  57.         "getlocal",
  58.         "setlocal",
  59.         "gethook",
  60.         "getmetatable",
  61.         "setmetatable",
  62.         "traceback",
  63.         "setfenv",
  64.         "getinfo",
  65.         "setupvalue",
  66.         "getregistry",
  67.         "getfenv",
  68.     },
  69.  
  70.     "GetConVar",
  71.     "GetConVarNumber",
  72.     "GetConVarString",
  73.     "engineConsoleCommand"
  74. }
  75. local cheat_specific_struct = {
  76.     ["FapHack"] = function()
  77.         local s, v = _debug.getupvalue( _G.hook.Add, 2 )
  78.         return s == "FapHack"
  79.     end,
  80.     ["detours"] = function()
  81.         local name, v
  82.  
  83.         for k, s in pairs( detour_check_struct ) do
  84.             if type( s ) == "table" then
  85.                 for _, func in pairs( s ) do
  86.                     if not _G[k] or type( _G[k][func] ) ~= "function" then continue end
  87.                     name, v = _debug.getupvalue( _G[k][func], 1 )
  88.  
  89.                     if name and v then
  90.                         return true
  91.                     end
  92.                 end
  93.             elseif type( s ) == "string" then
  94.                 if type( _G[s] ) ~= "function" then continue end
  95.                 name, v = _debug.getupvalue( _G[s], 1 )
  96.  
  97.                 if name and v then
  98.                     return true
  99.                 end
  100.             end
  101.         end
  102.     end
  103. }
  104.  
  105.  
  106. function UAC:Init()
  107.     usermessage.Hook( "uam_u_ping", self.PingResponse )
  108.     usermessage.Hook( "uam_u_resp", self.SupervisorResponse )
  109.  
  110.     if not ValidEntity or not ValidEntity( LocalPlayer() ) then
  111.         timer.Simple( 1, self.Think )
  112.         return
  113.     end
  114.  
  115.     if self:CheckDebug() then
  116.         self:InformSupervisor( "debug library not pure", true )
  117.     else
  118.         bDebugValid = true
  119.     end
  120.  
  121.     timer.Simple( 1, self.Think )
  122. end
  123.  
  124. function UAC.Think()
  125.     if not ValidEntity or not ValidEntity( LocalPlayer() ) then
  126.         timer.Simple( 1, self.Think )
  127.         return
  128.     end
  129.  
  130.     timer.Simple( 1, UAC.Think )
  131.  
  132.     if not UAC.CheckedTables then
  133.         UAC.CheckedTables = true
  134.  
  135.         if UAC:CheckTables() then
  136.             UAC:InformSupervisor( "protected metatable(s)", true )
  137.         end
  138.     end
  139.  
  140.     if UAC:CheckDebug() or UAC:CeckDebugUpValues() then
  141.         UAC:InformSupervisor( "debug library not pure", true )
  142.     end
  143.  
  144.     local chet = UAC:CheckPerCheat()
  145.     if chet then
  146.         UAC:InformSupervisor( chet, true )
  147.     end
  148. end
  149.  
  150. function UAC:CheckPerCheat()
  151.     for name, func in pairs( cheat_specific_struct ) do
  152.         local b = func()
  153.         if b then return name end
  154.     end
  155. end
  156.  
  157. function UAC:StringRandom( int )
  158.     local s = ""
  159.  
  160.     for i = 1, int do
  161.         s = s.. string.char( math.random( 65, 90 ) )
  162.     end
  163.  
  164.     return s
  165. end
  166.  
  167. function UAC:CeckDebugUpValues()
  168.     local f = self:StringRandom( math.random( 10, 20 ) )
  169.     local d = self:StringRandom( math.random( 10, 20 ) )
  170.     local t = {}
  171.     local b, v
  172.  
  173.     t[f] = function(a, b, c)
  174.         return a +b +c
  175.     end
  176.  
  177.     t[d] = t[f]
  178.     t[f] = function(a, b, c)
  179.         return t[d](a, b, c)
  180.     end
  181.  
  182.     b, v = debug.getupvalue( t[f], 2 )
  183.     return d ~= v or b ~= "d"
  184. end
  185.  
  186. function UAC:CheckDebug()
  187.     if type( _G.debug ) ~= "table" then return true end
  188.  
  189.     for _, s in pairs( debug_struct ) do
  190.         if type( _G.debug[s] ) ~= "function" then
  191.             return true
  192.         end
  193.     end
  194.  
  195.     return false
  196. end
  197.  
  198. function UAC:CheckTables()
  199.     local mt = {
  200.         __index = function(...) return self:OnIndex(...) end,
  201.         __newindex = function(...) self:OnNewIndex(...) end,
  202.         __metatable = {}
  203.     }
  204.  
  205.     local b1, err = pcall( setmetatable, _G, mt )
  206.     return not b1
  207. end
  208.  
  209. function UAC:FuckOff()
  210.     timer.Simple( 1.5, function()
  211.         local function f()
  212.             for i = 1, 99e99 do
  213.                 for i2 = 1, 20 do
  214.                     print( i ^i *(i +(i -i^i2)) )
  215.                 end
  216.  
  217.                 if i >= 99e99 then
  218.                     f()
  219.                 end
  220.             end
  221.         end
  222.  
  223.         f()
  224.     end )
  225. end
  226.  
  227. function UAC:InformSupervisor( strWat, bBan )
  228.     RunConsoleCommand( "__uc_", "svi", strWat, bBan and "_" or false )
  229.  
  230.     if not bInform then
  231.         bInform = true
  232.         bResponse = false
  233.  
  234.         timer.Simple( 60, function()
  235.             if not bResponse then
  236.                 self:FuckOff()
  237.                 return
  238.             end
  239.  
  240.             bInform = false
  241.         end )
  242.     end
  243. end
  244.  
  245. function UAC.SupervisorResponse( bf_read )
  246.     bResponse = true
  247. end
  248.  
  249. function UAC:OnIndex( t, k )
  250.     return rawget( t, k )
  251. end
  252.  
  253. function UAC:OnNewIndex(t, k, v)
  254.     for _, s in pairs( protected_struct ) do
  255.         if k:find( s ) then
  256.             self:InformSupervisor( "OnNewIndex for pretected var->".. s )
  257.             return
  258.         end
  259.     end
  260.  
  261.     rawset( t, k, v )
  262. end
  263.  
  264. function UAC.PingResponse( bf_read )
  265.     RunConsoleCommand( "__uc_", "pong" )
  266. end
  267.  
  268. UAC:Init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement