Advertisement
Noneatme

Untitled

Jul 4th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.38 KB | None | 0 0
  1. -- Decompiled using luadec 2.1 UNICODE by sztupy (http://winmo.sztupy.hu) and viruscamp
  2. -- Command line was: D:\MTA San Andreas 1.3.2\mods\deathmatch\resources\load\loadscript_c.lua
  3.  
  4. local event = {}
  5. local timers = {}
  6. local boundKeys = {}
  7. local commands = {}
  8. local musicz = {}
  9. local soundFile = {}
  10. local loaded = {}
  11. local replaceTimer = nil
  12. _addCommandHandler = addCommandHandler
  13. _bindKey = bindKey
  14. _setTimer = setTimer
  15. _addEventHandler = addEventHandler
  16. _playSound = playSound
  17. _playSound3D = playSound3D
  18. _xmlLoadFile = xmlLoadFile
  19. _dxCreateTexture = dxCreateTexture
  20. _dxCreateShader = dxCreateShader
  21. _dxDrawImage = dxDrawImage
  22. _setElementModel = setElementModel
  23. _engineLoadTXD = engineLoadTXD
  24. local loadedTXD = {}
  25. _engineImportTXD = engineImportTXD
  26. _engineLoadDFF = engineLoadDFF
  27. local loadedDFF = {}
  28. _engineReplaceModel = engineReplaceModel
  29. _engineLoadCOL = engineLoadCOL
  30. local loadedCOL = {}
  31. _engineReplaceCOL = engineReplaceCOL
  32. local texture = {}
  33. local shader = {}
  34. local importedTXD = {}
  35. local replacedModel = {}
  36. local replacedCOL = {}
  37. setElementModel = function(element, model)
  38.   _setElementModel(element, model)
  39.   if isElement(element) and getElementType(element) == "vehicle" then
  40.     local vehicle = getElementData(localPlayer, "race.vehicle")
  41.   end
  42.   if element == vehicle then
  43.     triggerServerEvent("serverSetElementModel", localPlayer, model)
  44.   end
  45. end
  46.  
  47. dxDrawImage = function(posX, posY, width, height, dir, rot, rotOffX, rotOffY, color, postGUI)
  48.   local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
  49.   _dxDrawImage(posX, posY, width, height, downloadLoc, rot, rotOffX, rotOffY, color, postGUI)
  50. end
  51.  
  52. dxCreateTexture = function(dir)
  53.   -- upvalues: texture
  54.   local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
  55.   local index = #texture + 1
  56.   texture[index] = _dxCreateTexture(downloadLoc)
  57.   return texture[index]
  58. end
  59.  
  60. dxCreateShader = function(dir)
  61.   -- upvalues: shader
  62.   local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
  63.   local index = #shader + 1
  64.   shader[index] = _dxCreateShader(downloadLoc)
  65.   return shader[index]
  66. end
  67.  
  68. xmlLoadFile = function(dir)
  69.   local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
  70.   return _xmlLoadFile(downloadLoc)
  71. end
  72.  
  73. engineLoadTXD = function(txd_file, filter)
  74.   return true
  75. end
  76.  
  77. engineImportTXD = function(texture, model_id)
  78.   return true
  79. end
  80.  
  81. engineLoadDFF = function(dff_file, model_id)
  82.   return true
  83. end
  84.  
  85. engineReplaceModel = function(dff_file, model_id)
  86.   return true
  87. end
  88.  
  89. engineLoadCOL = function(col_file)
  90.   return true
  91. end
  92.  
  93. engineReplaceCOL = function(col_file, model_id)
  94.   return true
  95. end
  96.  
  97. addEvent("load.DUMMY", true)
  98. addCommandHandler = function(commandName, handlerFunction)
  99.   -- upvalues: commands
  100.   local index = #commands + 1
  101.   commands[index] = {}
  102.   commands[index].commandName = commandName
  103.   commands[index].handlerFunction = handlerFunction
  104.   _addCommandHandler(commandName, handlerFunction)
  105.   return true
  106. end
  107.  
  108. bindKey = function(key, keyState, handlerFunction, ...)
  109.   -- upvalues: boundKeys
  110.   local index = #boundKeys + 1
  111.   boundKeys[index] = {}
  112.   boundKeys[index].key = key
  113.   boundKeys[index].keyState = keyState
  114.   boundKeys[index].handlerFunction = handlerFunction
  115.   _bindKey(key, keyState, handlerFunction)
  116.   return true
  117. end
  118.  
  119. setTimer = function(theFunction, interval, timesToExecute, ...)
  120.   -- upvalues: timers
  121.   local index = #timers + 1
  122.   timers[index] = _setTimer(theFunction, interval, timesToExecute, ...)
  123.   return timers[index]
  124. end
  125.  
  126. createProjectile = function(creator)
  127.   if isElement(creator) and (getElementType(creator) == "player" or getElementType(creator) == "vehicle") then
  128.     return
  129.   end
  130. end
  131.  
  132. addEventHandler = function(eventName, attachedTo, handlerFunction, prop)
  133.   -- upvalues: event
  134.   if not handlerFunction then
  135.     return
  136.   end
  137.   if not attachedTo then
  138.     attachedTo = root
  139.   end
  140.   if not prop then
  141.     prop = true
  142.   end
  143.   eventName = toClientEvent(eventName)
  144.   local daRoot, _eve = getStartEventArguments(eventName)
  145.   if daRoot then
  146.     setTimer(function()
  147.     -- upvalues: attachedTo , handlerFunction , prop , daRoot , _eve
  148.     _addEventHandler("load.DUMMY", attachedTo, handlerFunction, prop)
  149.     triggerEvent("load.DUMMY", daRoot, unpack(_eve))
  150.     removeEventHandler("load.DUMMY", attachedTo, handlerFunction)
  151.   end, 300, 1)
  152.   end
  153.   local index = #event + 1
  154.   event[index] = {}
  155.   event[index].name = eventName
  156.   event[index].attached = attachedTo
  157.   event[index].hFunction = handlerFunction
  158.   removeEventHandler(eventName, attachedTo, handlerFunction, prop)
  159.   return _addEventHandler(eventName, attachedTo, handlerFunction, prop)
  160. end
  161.  
  162. playSound = function(location, loop)
  163.   -- upvalues: soundFile
  164.   if getElementData(localPlayer, "race_music") == 0 then
  165.     return
  166.   end
  167.   local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. location
  168.   if soundFile[downloadLoc] then
  169.     return
  170.   end
  171.   outputDebugString("starting to play sound: " .. downloadLoc)
  172.   soundFile[downloadLoc] = _playSound(downloadLoc, loop)
  173.   return soundFile[downloadLoc]
  174. end
  175.  
  176. playSound3D = function(location, x, y, z, loop)
  177.   if getElementData(localPlayer, "race_music") == 0 then
  178.     return
  179.   end
  180.   local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. location
  181.   return _playSound3D(downloadLoc, x, y, z, loop)
  182. end
  183.  
  184. toClientEvent = function(eventName)
  185.   eventName = eventName:gsub("onResourceStart", "onClientResourceStart")
  186.   eventName = eventName:gsub("onMarkerHit", "onClientMarkerHit")
  187.   eventName = eventName:gsub("onElementColShapeHit", "onClientElementColShapeHit")
  188.   return eventName
  189. end
  190.  
  191. getStartEventArguments = function(eventName)
  192.   local eventList = {}
  193.   eventList[1] = "onClientResourceStart"
  194.   eventList[2] = "onClientVehicleEnter"
  195.   eventList[3] = "onClientPlayerSpawn"
  196.   eventList[4] = "onClientVehicleStartEnter"
  197.   if eventName == eventList[1] then
  198.     return root, {getThisResource()}
  199.   end
  200.   if eventName == eventList[2] then
  201.     return getElementData(localPlayer, "race.vehicle"), {localPlayer, 0}
  202.   end
  203.   if eventName == eventList[3] then
  204.     return localPlayer, {getPlayerTeam(localPlayer)}
  205.   end
  206.   if eventName == eventList[4] then
  207.     return getElementData(localPlayer, "race.vehicle"), {localPlayer, 0, 0}
  208.   end
  209.   return false
  210. end
  211.  
  212. unload = function(dontStopMusic)
  213.   -- upvalues: timers , boundKeys , commands , event , soundFile , loadedTXD , loadedDFF , loadedCOL , importedTXD , replacedModel , replacedCOL , texture , shader
  214.   for i = 1, #timers do
  215.     if isTimer(timers[i]) then
  216.       killTimer(timers[i])
  217.     end
  218.   end
  219.   for i = 1, #boundKeys do
  220.     unbindKey(boundKeys[i].key, boundKeys[i].keyState, boundKeys[i].handlerFunction)
  221.   end
  222.   for i = 1, #commands do
  223.     removeCommandHandler(commands[i].commandName, commands[i].handlerFunction)
  224.   end
  225.   for k,_event in ipairs(event) do
  226.     removeEventHandler(_event.name, _event.attached, _event.hFunction)
  227.   end
  228.   for k,element in ipairs(getElementChildren(resourceRoot)) do
  229.     for k,childElement in ipairs(getElementChildren(element)) do
  230.       local type = getElementType(childElement)
  231.       if type == "sound" and not dontStopMusic then
  232.         destroyElement(childElement)
  233.       end
  234.       for k,childElement in (for generator) do
  235.         destroyElement(childElement)
  236.       end
  237.     end
  238.     if not dontStopMusic then
  239.       soundFile = {}
  240.     end
  241.     outputDebugString("Models unloaded")
  242.     loadedTXD = {}
  243.     loadedDFF = {}
  244.     loadedCOL = {}
  245.     importedTXD = {}
  246.     replacedModel = {}
  247.     replacedCOL = {}
  248.     texture = {}
  249.     shader = {}
  250.     event = {}
  251.     timers = {}
  252.     boundKeys = {}
  253.     commands = {}
  254.      -- WARNING: missing end command somewhere! Added here
  255.   end
  256. end
  257.  
  258. local scriptLoaded = {}
  259. loadscript = function(location, str)
  260.   -- upvalues: scriptLoaded
  261.   scriptLoaded[location] = loadstring(str)
  262.   do
  263.     local loaded = pcall(scriptLoaded[location])
  264.   end
  265.   if loaded then
  266.      -- WARNING: missing end command somewhere! Added here
  267.   end
  268. end
  269.  
  270. unloadscript = function(location)
  271.   -- upvalues: scriptLoaded
  272.   scriptLoaded[location] = nil
  273. end
  274.  
  275. local file = {}
  276. local originalFiles = {}
  277. local fileFinished = {}
  278. addEvent("serverSendFileData", true)
  279. _addEventHandler("serverSendFileData", root, function(location, data, start, sendNext)
  280.   -- upvalues: file
  281.   local slashPos = string.find(location, "/")
  282.   local fileSrc = string.sub(location, slashPos + 1)
  283.   local isScript = isScriptFile(fileSrc)
  284.   if isScript then
  285.     if not file[location] then
  286.       file[location] = ""
  287.     end
  288.     file[location] = file[location] .. data
  289.     if sendNext then
  290.       triggerServerEvent("serverSendFileDataToPlayer", localPlayer, location, localPlayer, start)
  291.     else
  292.       triggerEvent("fileSendingFinished", localPlayer, location)
  293.     end
  294.   else
  295.     local nloc = location
  296.     local theFile = nil
  297.     if fileExists(nloc) then
  298.       theFile = fileOpen(nloc)
  299.     else
  300.       theFile = fileCreate(nloc)
  301.       if theFile then
  302.         outputDebugString("Created " .. nloc .. " from: " .. location)
  303.       end
  304.     else
  305.       outputDebugString("Failed to create file: " .. nloc)
  306.     end
  307.     fileSetPos(theFile, fileGetSize(theFile))
  308.     fileWrite(theFile, data)
  309.     local saved = fileFlush(theFile)
  310.     local size = fileGetSize(theFile)
  311.     fileClose(theFile)
  312.     if sendNext then
  313.       triggerServerEvent("serverSendFileDataToPlayer", localPlayer, location, localPlayer, start)
  314.     end
  315.   else
  316.     triggerEvent("fileSendingFinished", localPlayer, location)
  317.   end
  318. end
  319. )
  320. getResourceNameFromLocation = function(location)
  321.   local pos = string.find(location, "/", 1)
  322.   location = string.sub(location, 1, pos - 1)
  323.   return location
  324. end
  325.  
  326. isMusicFile = function(file)
  327.   file = getFileType(file)
  328.   if not file then
  329.     return
  330.   end
  331.   local compList = {}
  332.   compList[#compList + 1] = ".mp3"
  333.   compList[#compList + 1] = ".wav"
  334.   compList[#compList + 1] = ".ogg"
  335.   compList[#compList + 1] = ".riff"
  336.   compList[#compList + 1] = ".mod"
  337.   compList[#compList + 1] = ".xm"
  338.   compList[#compList + 1] = ".it"
  339.   compList[#compList + 1] = ".s3m"
  340.   for i = 1, #compList do
  341.     if string.find(file, compList[i], 1, true) then
  342.       return true
  343.     end
  344.   end
  345.   return false
  346. end
  347.  
  348. isScriptFile = function(file)
  349.   file = getFileType(file)
  350.   if not file then
  351.     return
  352.   end
  353.   if string.find(file, ".lua", 1, true) then
  354.     return true
  355.   end
  356.   return false
  357. end
  358.  
  359. getFileType = function(file)
  360.   file = file:lower()
  361.   local dotPos = nil
  362.   for i = 1, file:len() do
  363.     if file:sub(i, i) == "." then
  364.       dotPos = i
  365.   else
  366.     end
  367.   end
  368.   if not dotPos then
  369.     return false
  370.   end
  371.   return file:sub(dotPos)
  372. end
  373.  
  374. getFileName = function(file)
  375.   file = file:lower()
  376.   local dotPos = nil
  377.   for i = 1, file:len() do
  378.     if file:sub(i, i) == "." then
  379.       dotPos = i
  380.     end
  381.   end
  382.   if not dotPos then
  383.     return false
  384.   end
  385.   return file:sub(1, dotPos - 1)
  386. end
  387.  
  388. addEvent("fileSendingFinished", true)
  389. _addEventHandler("fileSendingFinished", getRootElement(), function(location)
  390.   -- upvalues: fileFinished , originalFiles , file , scriptLoaded
  391.   local room = getElementParent(localPlayer)
  392.   if getElementType(room) ~= "race.room" then
  393.     return
  394.   end
  395.   local mapDownloadFinished = getElementData(localPlayer, "mapDownloadFinished")
  396.   local scriptsLoaded = getElementData(localPlayer, "scriptsLoaded")
  397.   if location then
  398.     local slashPos = string.find(location, "/")
  399.     local fileSrc = string.sub(location, slashPos + 1)
  400.     do
  401.       local isScript = isScriptFile(fileSrc)
  402.       fileFinished[location] = true
  403.     end
  404.   end
  405.   if not isScript then
  406.     local allDoneExceptMusic = true
  407.   end
  408.   for k,origFile in ipairs(originalFiles) do
  409.     local slashPos = string.find(origFile.location, "/")
  410.     local fileSrc = string.sub(origFile.location, slashPos + 1)
  411.     if (isScriptFile(fileSrc) or fileSrc:find("xml", 1, true)) and not fileFinished[origFile.location] then
  412.       allDoneExceptMusic = false
  413.     end
  414.   end
  415.   if mapDownloadFinished then
  416.     mapDownloadFinished = false
  417.     setElementData(localPlayer, "mapDownloadFinished", mapDownloadFinished, false)
  418.   end
  419.   if getElementData(room, "gamemode") ~= "training" then
  420.     triggerServerEvent("onClientFinishedCreatingMap", localPlayer, getElementData(localPlayer, "doSpec"))
  421.   end
  422.   if allDoneExceptMusic and not scriptsLoaded then
  423.     scriptsLoaded = true
  424.     setElementData(localPlayer, "scriptsLoaded", scriptsLoaded, false)
  425.     for loc,data in pairs(file) do
  426.       local slashPos = string.find(loc, "/")
  427.       local fileSrc = string.sub(loc, slashPos + 1)
  428.       if isScriptFile(fileSrc) and not scriptLoaded[loc] and fileFinished[loc] then
  429.         loadscript(loc, data)
  430.       end
  431.     end
  432.   end
  433. end
  434. )
  435. getCharPos = function(str, char)
  436.   local pos = 0
  437.   for i = 1, str:len() do
  438.     if str:sub(i, i) == char then
  439.       pos = i
  440.     end
  441.   end
  442.   return pos
  443. end
  444.  
  445. addEvent("unloadScriptFromMemory", true)
  446. _addEventHandler("unloadScriptFromMemory", getRootElement(), function(files, spec, wait, sendMap)
  447.   -- upvalues: scriptLoaded , loaded , file , fileFinished , originalFiles
  448.   unload()
  449.   for i,s in pairs(scriptLoaded) do
  450.     unloadscript(i)
  451.   end
  452.   for k,_files in ipairs(files) do
  453.     local fileName = _files.location
  454.     local slashPos = string.find(fileName, "/")
  455.     fileName = string.sub(fileName, slashPos + 1)
  456.     if fileExists(fileName) and fileGetMD5(fileName) ~= _files.md5 then
  457.       _setTimer(function(fileName)
  458.       fileDelete(fileName)
  459.       outputDebugString("corrupted file deleted: " .. fileName)
  460.     end, 250, 1, fileName)
  461.     end
  462.   end
  463.   loaded = {}
  464.   scriptLoaded = {}
  465.   file = {}
  466.   fileFinished = {}
  467.   originalFiles = {}
  468.   originalFiles = files
  469.   setElementData(localPlayer, "doSpec", spec, false)
  470.   setElementData(localPlayer, "scriptsLoaded", nil, false)
  471.   triggerServerEvent("onServerScriptUnloaded", localPlayer, files, sendMap)
  472. end
  473. )
  474. addEvent("clientRestartScripts", true)
  475. _addEventHandler("clientRestartScripts", root, function()
  476.   -- upvalues: file
  477.   unload(true)
  478.   for i,s in pairs(file) do
  479.     loadscript(i, s)
  480.   end
  481. end
  482. )
  483. fileGetMD5 = function(location)
  484.   local theFile = fileOpen(location)
  485.   local MD5String = ""
  486.   if theFile then
  487.     local buffer = ""
  488.     buffer = buffer .. fileRead(theFile, fileGetSize(theFile))
  489.     fileClose(theFile)
  490.     return md5(buffer)
  491.   end
  492.   return MD5String
  493. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement