ScriptManScriptThing

Anti Exploit Framework

Sep 2nd, 2020 (edited)
1,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.01 KB | None | 0 0
  1. --//AntiExploitModule [Main]
  2.  
  3.  
  4. --[[
  5.  █████╗ ███╗   ██╗████████╗██╗      ███████╗██╗  ██╗██████╗ ██╗      ██████╗ ██╗████████╗
  6. ██╔══██╗████╗  ██║╚══██╔══╝██║      ██╔════╝╚██╗██╔╝██╔══██╗██║     ██╔═══██╗██║╚══██╔══╝
  7. ███████║██╔██╗ ██║   ██║   ██║█████╗█████╗   ╚███╔╝ ██████╔╝██║     ██║   ██║██║   ██║  
  8. ██╔══██║██║╚██╗██║   ██║   ██║╚════╝██╔══╝   ██╔██╗ ██╔═══╝ ██║     ██║   ██║██║   ██║  
  9. ██║  ██║██║ ╚████║   ██║   ██║      ███████╗██╔╝ ██╗██║     ███████╗╚██████╔╝██║   ██║  
  10. ╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝   ╚═╝      ╚══════╝╚═╝  ╚═╝╚═╝     ╚══════╝ ╚═════╝ ╚═╝   ╚═╝  
  11. \\ version: 1/31/2021 //
  12.  
  13. For more Information Please Look At My DevForum Post About It:
  14. https://devforum.roblox.com/t/anti-exploit-framework-unknownparabellum/721362/32
  15.  
  16. //How To Get Started\\
  17. 1.Create a new Script
  18.  
  19. 2.Move the Script to ServerScriptStorage
  20.  
  21. 3.Copy and paste this into the script:
  22.  
  23. local AntiExploit = require(script.AntiExploitModule)
  24. AntiExploit:Start()
  25.  
  26. 4. And after that you are set!
  27.                                                                                  
  28. ]]
  29.  
  30. local RunService = game:GetService("RunService")
  31. local Players = game:GetService("Players")
  32.  
  33. local PlayerClass = require(script.PlayerClass)
  34. local Utils = require(script.Utils)
  35.  
  36. local ThreadUtil = Utils.ThreadUtil
  37. local Maid = Utils.Maid
  38.  
  39. local AntiExploit = {}
  40.  
  41. AntiExploit.PlayersMonitoring = {}
  42. AntiExploit.FlaggedPlayers = {}
  43. AntiExploit.Config = {
  44.     ["Increment"] = 0.05,
  45. }
  46. AntiExploit._maid = Maid.new()
  47.  
  48. AntiExploit.Started = false
  49.  
  50. function AntiExploit:AddPlayer(plr) --Adds a player to PlayersMonitoring, queueing them up to be monitored
  51.     --Here is where you should add any exceptions for Admins.
  52.     local obj = PlayerClass.new(plr)
  53.     self.PlayersMonitoring[plr.Name] = obj
  54.     self._maid[plr.UserId] = obj
  55. end
  56.  
  57. function AntiExploit:RemovePlayer(plr)
  58.     self._maid[plr.UserId] = nil
  59.     self.PlayersMonitoring[plr.Name] = nil
  60.     self.FlaggedPlayers[plr.Name] = nil
  61. end
  62.  
  63. function AntiExploit:Start()
  64.     if self.Started then
  65.         warn("Anti-Exploit Already Started")
  66.         return
  67.     end
  68.     self.Started = true
  69.     print("Started Anti Exploit")
  70.    
  71.     for _,plr in pairs(Players:GetPlayers())do
  72.         self:AddPlayer(plr)
  73.     end
  74.    
  75.     self._maid["PlayerAdded"] = Players.PlayerAdded:Connect(function(plr)
  76.         self:AddPlayer(plr)
  77.     end)
  78.     self._maid["PlayerRemoved"] = Players.PlayerRemoving:Connect(function(plr)
  79.         self:RemovePlayer(plr)
  80.     end)   
  81.     self._maid["RepeatingChecks"] = ThreadUtil.DelayRepeat(self.Config.Increment,
  82.         function()
  83.             for name,player in pairs(AntiExploit.PlayersMonitoring)do
  84.                 player:Update()
  85.                 if player.Flags.NumberOfFlags > 5 then
  86.                     if not AntiExploit.FlaggedPlayers[player.Info.Name] then
  87.                         warn(player.Info.Name.." has exeeded 5 flags...")
  88.                         AntiExploit.FlaggedPlayers[player.Info.Name] = player
  89.                     end
  90.                 end
  91.             end
  92.         end
  93.     )
  94. end
  95.  
  96.  
  97.  
  98. function AntiExploit:Stop()
  99.     if not self.Started then
  100.         warn("Anti-Exploit Already Stopped")
  101.         return
  102.     end
  103.     self.Started = false
  104.     warn("Anti-Exploit Stopped")
  105.     self._maid:DoCleaning()
  106.     self.PlayersMonitoring = {}
  107.     self.FlaggedPlayers = {}
  108. end
  109.  
  110. return AntiExploit
  111. ----------//PlayerClass\\----------------
  112. local FlagClass = require(script.Parent.FlagClass)
  113. local ExploitChecks = require(script.ExploitChecks)
  114.  
  115. local Utils = require(script.Parent.Utils)
  116. local ThreadUtil = Utils.ThreadUtil
  117. local Maid = Utils.Maid
  118.  
  119. local PlayerClass = {}
  120. PlayerClass.__index = PlayerClass
  121.  
  122. local function dist(Pos1,Pos2)
  123.     return (Pos1-Pos2).Magnitude
  124. end
  125.  
  126. function PlayerClass:AddFlag(Reason)
  127.     local flag = FlagClass.new(Reason)
  128.     self.Flags[flag.Id] = flag
  129.     self.Flags.NumberOfFlags += 1
  130. end
  131.  
  132. function PlayerClass:RemoveFlag(id)
  133.     self.Flags[id] = nil
  134.     self.Flags.NumberOfFlags -= 1
  135. end
  136.  
  137. function PlayerClass:ResetStats(resetMessage,shouldWarn)
  138.     resetMessage = resetMessage or "No Message Given"
  139.     local info = self.Info
  140.     if info.LastReset and info.LastChecked then
  141.         if (info.LastReset>info.LastChecked) then
  142.             return
  143.         end
  144.     end
  145.     local whiteList = {
  146.         ["Name"] = true,
  147.         ["Player"] = true,
  148.     }
  149.     for name,val in pairs(info)do
  150.         local valType = typeof(val)
  151.         if not whiteList[name] then
  152.             if valType == "table" then
  153.                 info[name] = {}
  154.             else
  155.                 info[name] = nil
  156.             end
  157.         end
  158.     end
  159.     info.LastReset = tick()
  160.     if not shouldWarn then
  161.         warn(info.Name.."'s Data Wiped Because: "..resetMessage)
  162.     end
  163. end
  164.  
  165. function PlayerClass:UpdateStats()
  166.     local clientInfo = self.Info
  167.  
  168.     local Character = clientInfo.Player.Character
  169.    
  170.     if self.CanUpdate and Character then
  171.         local rootPart = Character:FindFirstChild("HumanoidRootPart")
  172.         local head =  Character:FindFirstChild("Head")
  173.         clientInfo.LastChecked = tick()
  174.         clientInfo.RootPart = rootPart
  175.         clientInfo.Head = head
  176.         clientInfo.LastPosition = rootPart.Position
  177.     end
  178. end
  179.  
  180. function StopPlayer(Character)
  181.     ThreadUtil.Spawn(function()
  182.         for _, Part in pairs(Character:GetDescendants()) do
  183.             if Part:IsA("BasePart")then
  184.                 if Part:CanSetNetworkOwnership() then
  185.                     Part:SetNetworkOwner(nil)
  186.                 end
  187.                 Part.Anchored = true   
  188.             end
  189.         end
  190.     end)
  191.     ThreadUtil.Delay(5,function()
  192.         for _, Part in pairs(Character:GetDescendants()) do
  193.             if Part:IsA("BasePart")then
  194.                 Part.Anchored = false
  195.                 if Part:CanSetNetworkOwnership() then
  196.                     Part:SetNetworkOwner(game.Players:GetPlayerFromCharacter(Character))
  197.                 end
  198.             end
  199.         end
  200.     end)
  201. end
  202.  
  203.  
  204. function PlayerClass:Update()
  205.     local clientInfo = self.Info
  206.     local client = clientInfo.Player
  207.     local character = client.Character
  208.     if character and self.CanUpdate then
  209.         local rootPart = character:FindFirstChild("HumanoidRootPart")
  210.         local playerHead =  character:FindFirstChild("Head")
  211.         if rootPart and playerHead then
  212.            
  213.             if clientInfo.LastPosition then
  214.                 if dist(clientInfo.LastPosition,rootPart.Position) < 0.3 then
  215.                     return
  216.                 end
  217.             else
  218.                 self:UpdateStats()
  219.             end
  220.             clientInfo.RootPart = rootPart --Setting new value
  221.             clientInfo.Head = playerHead
  222.             for _,exploit in pairs(ExploitChecks)do --Checking for any exploits
  223.                 local Passed,ReturnMessage = exploit:Check(self)
  224.                 if not Passed then
  225.                     exploit:Punish(self)
  226.                     self:AddFlag(ReturnMessage)
  227.                     StopPlayer(character)
  228.                     warn(ReturnMessage)
  229.                     break
  230.                 end
  231.             end
  232.             self:UpdateStats()
  233.         elseif not rootPart or not playerHead then
  234.             self.Info.Player:LoadCharacter()
  235.             warn(self.Info.Player.Name.." doesn't have an important body part")
  236.         end
  237.     end
  238. end
  239.  
  240. function PlayerClass.new(Player)
  241.     local self =  setmetatable({       
  242.         ["Flags"] = {["NumberOfFlags"] = 0,},              
  243.         ["TimeStarted"] = tick(),
  244.         ["CanUpdate"] = true,
  245.         ["Info"] = {
  246.             ["Name"] = Player.Name,
  247.             ["Player"] = Player,
  248.                        
  249.             ["Humanoid"] = nil, --This is so we know what you can usually index
  250.             ["Head"] = nil,
  251.             ["RootPart"] = nil,
  252.             ["LastPosition"] = nil,
  253.             ["LastChecked"] = nil,
  254.             ["LastUpdated"] = nil,
  255.         },
  256.         ["_maid"] = Maid.new(),    
  257.         ["_state"] = true, 
  258.        
  259.     },PlayerClass)
  260.     self._maid["CharacterChanged"] = Player.CharacterAdded:Connect(function(Char)
  261.         local Root = Char:WaitForChild("HumanoidRootPart")
  262.         if self._maid["CFrameChanged"] then
  263.             self._maid["CFrameChanged"] = nil
  264.         end
  265.         self._maid["CFrameChanged"] = Root:GetPropertyChangedSignal("CFrame"):Connect(function()
  266.             self.CanUpdate = false
  267.             self:ResetStats(Player.Name.." CFrame changed because of the Server",true)
  268.             ThreadUtil.Delay(3,
  269.                 function()
  270.                     self.CanUpdate = true
  271.                 end
  272.             )
  273.         end)
  274.         if Root then
  275.             self.CanUpdate = true
  276.             self:UpdateStats()                 
  277.         end    
  278.     end)
  279.     self._maid["CharacterRemoved"] = Player.CharacterRemoving:Connect(function(Char)
  280.         self.CanUpdate = false
  281.     end)       
  282.     return self
  283.  
  284. end
  285.  
  286. function PlayerClass:Destroy()
  287.     self._maid:DoCleaning()
  288. end
  289.  
  290. return PlayerClass
  291.  
  292. ----------//FlagClass\\----------------
  293. local HttpService = game:GetService("HttpService")
  294.  
  295. local Flag = {}
  296. Flag.__index = Flag
  297.  
  298. function Flag.new(Reason)
  299.     return setmetatable({
  300.         ["TimeOfFlag"] = tick(),
  301.         ["Reason"] = Reason,       
  302.         ["Id"] = HttpService:GenerateGUID(false)
  303.     },Flag)
  304. end
  305.  
  306. return Flag
  307. ---//Utils\\---
  308. --// Assorted Util modules
  309.  
  310. local utils = {}
  311. setmetatable(utils,{ --Lazy loads Utils
  312.     __index = function(tbl,index)
  313.         local util = require(script[index])
  314.         tbl[index] = util
  315.         return util
  316.     end,
  317. })
  318. return utils
  319.  
Add Comment
Please, Sign In to add comment