SHARE
TWEET

map_download

it300 Apr 17th, 2019 (edited) 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Map Downloader by Devieth
  2. -- For SAPP
  3.  
  4. -- Required files:
  5. -- wget.exe
  6. -- 7z.exe
  7. -- 7z.dll
  8.  
  9. hac2_repo = "http://maps.halonet.net/" -- HAC2 Repo
  10. hac2_legacy_repo = "http://maps.haloanticheat.com/" -- Legacy HAC2 Repo
  11.  
  12. api_version = "1.10.0.0"
  13.  
  14. function OnScriptLoad()
  15.     register_callback(cb['EVENT_COMMAND'], "OnEventCommand")
  16.     -- Assign the repo to use.
  17.     map_repo = hac2_repo
  18.     -- Get the EXE Path
  19.     exe_path = read_string(read_dword(sig_scan("0000BE??????005657C605") + 0x3))
  20.     -- Split the string
  21.     local t = tokenizestring(exe_path, "\\")
  22.     -- Create the maps_folder_path
  23.     maps_folder_path = string.sub(exe_path, 0, string.len(exe_path) - string.len(t[#t])).."\\maps\\"
  24. end
  25.  
  26. function OnScriptUnload() end
  27.  
  28. function OnEventCommand(PlayerIndex, Command, Enviroment, Password)
  29.     local t = tokenizestring(string.lower(string.gsub(Command, '"', "")), " ")
  30.     if get_var(PlayerIndex, "$lvl") ~= "-1" or tonumber(Enviroment) == 0 then
  31.  
  32.         -- Hi-Jack SAPP's command.
  33.         if t[1] == "map_download" then
  34.  
  35.             -- Make sure they actually used a name
  36.             if t[2] then
  37.                 local downloaded, map_name = false, tostring(t[2])
  38.  
  39.                 -- Download the map.
  40.                 local map = assert(io.popen('wget -O "'..map_name..'" -c '..map_repo.."map_download.php?map="..map_name))
  41.                 map:close()
  42.  
  43.                 -- Check if the download was successful.
  44.                 local file = io.open(map_name)
  45.                 if file then
  46.                     downloaded = true
  47.                     file:close()
  48.                 end
  49.  
  50.                 if downloaded then
  51.                     -- Unzip the map.
  52.                     local sevenz = assert(io.popen('7z.exe e "'..map_name..'" -o'..maps_folder_path))
  53.                     sevenz:close()
  54.  
  55.                     -- Load the map.
  56.                     execute_command("map_load "..map_name)
  57.                     rcon_return(tonumber(Enviroment), PlayerIndex, "Download of "..map_name.. " complete!")
  58.  
  59.                     -- Delete the .zip file.
  60.                     os.remove(map_name)
  61.                 else
  62.  
  63.                     -- Alert the usere that the download failed.
  64.                     rcon_return(tonumber(Enviroment), PlayerIndex, "Failed to download "..map_name)
  65.                     rcon_return(tonumber(Enviroment), PlayerIndex, "Check the spelling of the map.")
  66.                     rcon_return(tonumber(Enviroment), PlayerIndex, "Check the repo for the map @ http://maps.halonet.net/maplist.php")
  67.                 end
  68.             else
  69.                 -- Let them know how to use the hi-jacked command.
  70.                 rcon_return(tonumber(Enviroment), PlayerIndex, "map_download <map name>")
  71.             end
  72.             return false
  73.         elseif t[1] == "map_download.map" then
  74.             if t[2] then
  75.                 if t[3] then
  76.                     local downloaded, URL, map_name = false, tostring(t[2]), tostring(t[3])
  77.  
  78.                     -- Download the map.
  79.                     local map = assert(io.popen('wget -c '..URL..' -O '..maps_folder_path..map_name))
  80.                     map:close()
  81.  
  82.                     --Load the map
  83.                     execute_command("map_load "..map_name)
  84.                 else
  85.                     rcon_return(tonumber(Enviroment), PlayerIndex, "Please include the full map and file name. EX: cmt_snow_grove.map")
  86.                 end
  87.             else
  88.                 rcon_return(tonumber(Enviroment), PlayerIndex, "map_download.map <URL> <map_name.map>")
  89.             end
  90.             return false
  91.         elseif t[1] == "map_download.zip" then
  92.             if t[2] then
  93.                 if t[3] then
  94.                     local downloaded, URL, map_name = false, tostring(t[2]), tostring(t[3])
  95.  
  96.                     -- Download the map.
  97.                     local map = assert(io.popen('wget -O "'..map_name..'" -c '..URL))
  98.                     map:close()
  99.  
  100.                     -- Check if the download was successful.
  101.                     local file = io.open(map_name)
  102.                     if file then
  103.                         downloaded = true
  104.                         file:close()
  105.                     end
  106.  
  107.                     if downloaded then
  108.                         -- Unzip the map.
  109.                         local sevenz = assert(io.popen('7z.exe e "'..map_name..'" -o'..maps_folder_path))
  110.                         sevenz:close()
  111.                         -- Load the map.
  112.                         execute_command("map_load "..map_name)
  113.                         rcon_return(tonumber(Enviroment), PlayerIndex, "Download of "..map_name.." complete!")
  114.                         -- Delete the .zip file.
  115.                         os.remove(map_name)
  116.                     else
  117.                         -- Alert the usere that the download failed.
  118.                         rcon_return(tonumber(Enviroment), PlayerIndex, "Download failed.")
  119.                     end
  120.                 else
  121.                     rcon_return(tonumber(Enviroment), PlayerIndex, "Map name required! Ex: garden_ce")
  122.                 end
  123.             else
  124.                 rcon_return(tonumber(Enviroment), PlayerIndex, "map_download.zip <URL> <map_name>")
  125.             end
  126.             return false
  127.         elseif t[1] == "repo" then
  128.             if t[2] then
  129.                 if t[2] == "legacy" then
  130.                     map_repo = hac2_legacy_repo
  131.                 else
  132.                     map_repo = tostring(t[2])
  133.                 end
  134.                 rcon_return(tonumber(Enviroment), PlayerIndex, "Map Repo set to: "..repo)
  135.             else
  136.                 rcon_return(tonumber(Enviroment), PlayerIndex, "Current Map Repo: "..repo)
  137.             end
  138.             return false
  139.         end
  140.     end
  141. end
  142.  
  143. function rcon_return(Enviroment, PlayerIndex, Message)
  144.     local Compatable_Message = string.gsub(tostring(Message), "|t", "   ")
  145.     if Enviroment == 0 then
  146.         cprint(Compatable_Message,14)
  147.     elseif Enviroment == 1 then
  148.         rprint(PlayerIndex, Message)
  149.     elseif Enviroment == 2 then
  150.         say(PlayerIndex, Compatable_Message)
  151.     end
  152. end
  153.  
  154. function tokenizestring(inputstr, sep)
  155.     if sep == nil then
  156.         sep = "%s"
  157.     end
  158.     local t={} ; i=1
  159.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  160.         t[i] = str
  161.         i = i + 1
  162.     end
  163.     return t
  164. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top