c0deine

Simple Function Detour Example

Feb 16th, 2015
1,505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. --[[
  2. Probably a very popular method of detouring, very simple, and effective if run before localization or no localization is used.
  3. ]]--
  4.  
  5. local Detours = {} -- Our Detours table, we are going to store our detoured functions here.
  6. local ProtectedFiles = {
  7.     "aimbot.lua",
  8.     "esp.lua"
  9. }
  10. local function DetourFunction(originalFunction, newFunction) -- Function that handles the detouring for us
  11.     Detours[newFunction] = originalFunction -- Save the old function
  12.     return newFunction -- We want to return our new, detoured function
  13. end
  14.  
  15. file.Read = DetourFunction(file.Read, function(fileName, path) -- For this example, we are going to be detouring file.Read, this function has the arguments of string filename and string path
  16.     for k,v in next, ProtectedFiles do
  17.         if (string.find(filename, v) then -- We want to protect our files
  18.             return "haha not today bitchboy" -- Return an intimidating string so they know you're not messing around
  19.         end
  20.     end
  21.    
  22.     return Detours[file.Read](fileName, path) -- Return the original function of file.Read so files that you dont care about can still be read by addons that use things like configs, etc.
  23. end)
Advertisement
Add Comment
Please, Sign In to add comment