Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Decompiled using luadec 2.1 UNICODE by sztupy (http://winmo.sztupy.hu) and viruscamp
- -- Command line was: D:\MTA San Andreas 1.3.2\mods\deathmatch\resources\load\loadscript_c.lua
- local event = {}
- local timers = {}
- local boundKeys = {}
- local commands = {}
- local musicz = {}
- local soundFile = {}
- local loaded = {}
- local replaceTimer = nil
- _addCommandHandler = addCommandHandler
- _bindKey = bindKey
- _setTimer = setTimer
- _addEventHandler = addEventHandler
- _playSound = playSound
- _playSound3D = playSound3D
- _xmlLoadFile = xmlLoadFile
- _dxCreateTexture = dxCreateTexture
- _dxCreateShader = dxCreateShader
- _dxDrawImage = dxDrawImage
- _setElementModel = setElementModel
- _engineLoadTXD = engineLoadTXD
- local loadedTXD = {}
- _engineImportTXD = engineImportTXD
- _engineLoadDFF = engineLoadDFF
- local loadedDFF = {}
- _engineReplaceModel = engineReplaceModel
- _engineLoadCOL = engineLoadCOL
- local loadedCOL = {}
- _engineReplaceCOL = engineReplaceCOL
- local texture = {}
- local shader = {}
- local importedTXD = {}
- local replacedModel = {}
- local replacedCOL = {}
- setElementModel = function(element, model)
- _setElementModel(element, model)
- if isElement(element) and getElementType(element) == "vehicle" then
- local vehicle = getElementData(localPlayer, "race.vehicle")
- end
- if element == vehicle then
- triggerServerEvent("serverSetElementModel", localPlayer, model)
- end
- end
- dxDrawImage = function(posX, posY, width, height, dir, rot, rotOffX, rotOffY, color, postGUI)
- local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
- _dxDrawImage(posX, posY, width, height, downloadLoc, rot, rotOffX, rotOffY, color, postGUI)
- end
- dxCreateTexture = function(dir)
- -- upvalues: texture
- local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
- local index = #texture + 1
- texture[index] = _dxCreateTexture(downloadLoc)
- return texture[index]
- end
- dxCreateShader = function(dir)
- -- upvalues: shader
- local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
- local index = #shader + 1
- shader[index] = _dxCreateShader(downloadLoc)
- return shader[index]
- end
- xmlLoadFile = function(dir)
- local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. dir
- return _xmlLoadFile(downloadLoc)
- end
- engineLoadTXD = function(txd_file, filter)
- return true
- end
- engineImportTXD = function(texture, model_id)
- return true
- end
- engineLoadDFF = function(dff_file, model_id)
- return true
- end
- engineReplaceModel = function(dff_file, model_id)
- return true
- end
- engineLoadCOL = function(col_file)
- return true
- end
- engineReplaceCOL = function(col_file, model_id)
- return true
- end
- addEvent("load.DUMMY", true)
- addCommandHandler = function(commandName, handlerFunction)
- -- upvalues: commands
- local index = #commands + 1
- commands[index] = {}
- commands[index].commandName = commandName
- commands[index].handlerFunction = handlerFunction
- _addCommandHandler(commandName, handlerFunction)
- return true
- end
- bindKey = function(key, keyState, handlerFunction, ...)
- -- upvalues: boundKeys
- local index = #boundKeys + 1
- boundKeys[index] = {}
- boundKeys[index].key = key
- boundKeys[index].keyState = keyState
- boundKeys[index].handlerFunction = handlerFunction
- _bindKey(key, keyState, handlerFunction)
- return true
- end
- setTimer = function(theFunction, interval, timesToExecute, ...)
- -- upvalues: timers
- local index = #timers + 1
- timers[index] = _setTimer(theFunction, interval, timesToExecute, ...)
- return timers[index]
- end
- createProjectile = function(creator)
- if isElement(creator) and (getElementType(creator) == "player" or getElementType(creator) == "vehicle") then
- return
- end
- end
- addEventHandler = function(eventName, attachedTo, handlerFunction, prop)
- -- upvalues: event
- if not handlerFunction then
- return
- end
- if not attachedTo then
- attachedTo = root
- end
- if not prop then
- prop = true
- end
- eventName = toClientEvent(eventName)
- local daRoot, _eve = getStartEventArguments(eventName)
- if daRoot then
- setTimer(function()
- -- upvalues: attachedTo , handlerFunction , prop , daRoot , _eve
- _addEventHandler("load.DUMMY", attachedTo, handlerFunction, prop)
- triggerEvent("load.DUMMY", daRoot, unpack(_eve))
- removeEventHandler("load.DUMMY", attachedTo, handlerFunction)
- end, 300, 1)
- end
- local index = #event + 1
- event[index] = {}
- event[index].name = eventName
- event[index].attached = attachedTo
- event[index].hFunction = handlerFunction
- removeEventHandler(eventName, attachedTo, handlerFunction, prop)
- return _addEventHandler(eventName, attachedTo, handlerFunction, prop)
- end
- playSound = function(location, loop)
- -- upvalues: soundFile
- if getElementData(localPlayer, "race_music") == 0 then
- return
- end
- local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. location
- if soundFile[downloadLoc] then
- return
- end
- outputDebugString("starting to play sound: " .. downloadLoc)
- soundFile[downloadLoc] = _playSound(downloadLoc, loop)
- return soundFile[downloadLoc]
- end
- playSound3D = function(location, x, y, z, loop)
- if getElementData(localPlayer, "race_music") == 0 then
- return
- end
- local downloadLoc = getElementData(localPlayer, "race.resource") .. "/" .. location
- return _playSound3D(downloadLoc, x, y, z, loop)
- end
- toClientEvent = function(eventName)
- eventName = eventName:gsub("onResourceStart", "onClientResourceStart")
- eventName = eventName:gsub("onMarkerHit", "onClientMarkerHit")
- eventName = eventName:gsub("onElementColShapeHit", "onClientElementColShapeHit")
- return eventName
- end
- getStartEventArguments = function(eventName)
- local eventList = {}
- eventList[1] = "onClientResourceStart"
- eventList[2] = "onClientVehicleEnter"
- eventList[3] = "onClientPlayerSpawn"
- eventList[4] = "onClientVehicleStartEnter"
- if eventName == eventList[1] then
- return root, {getThisResource()}
- end
- if eventName == eventList[2] then
- return getElementData(localPlayer, "race.vehicle"), {localPlayer, 0}
- end
- if eventName == eventList[3] then
- return localPlayer, {getPlayerTeam(localPlayer)}
- end
- if eventName == eventList[4] then
- return getElementData(localPlayer, "race.vehicle"), {localPlayer, 0, 0}
- end
- return false
- end
- unload = function(dontStopMusic)
- -- upvalues: timers , boundKeys , commands , event , soundFile , loadedTXD , loadedDFF , loadedCOL , importedTXD , replacedModel , replacedCOL , texture , shader
- for i = 1, #timers do
- if isTimer(timers[i]) then
- killTimer(timers[i])
- end
- end
- for i = 1, #boundKeys do
- unbindKey(boundKeys[i].key, boundKeys[i].keyState, boundKeys[i].handlerFunction)
- end
- for i = 1, #commands do
- removeCommandHandler(commands[i].commandName, commands[i].handlerFunction)
- end
- for k,_event in ipairs(event) do
- removeEventHandler(_event.name, _event.attached, _event.hFunction)
- end
- for k,element in ipairs(getElementChildren(resourceRoot)) do
- for k,childElement in ipairs(getElementChildren(element)) do
- local type = getElementType(childElement)
- if type == "sound" and not dontStopMusic then
- destroyElement(childElement)
- end
- for k,childElement in (for generator) do
- destroyElement(childElement)
- end
- end
- if not dontStopMusic then
- soundFile = {}
- end
- outputDebugString("Models unloaded")
- loadedTXD = {}
- loadedDFF = {}
- loadedCOL = {}
- importedTXD = {}
- replacedModel = {}
- replacedCOL = {}
- texture = {}
- shader = {}
- event = {}
- timers = {}
- boundKeys = {}
- commands = {}
- -- WARNING: missing end command somewhere! Added here
- end
- end
- local scriptLoaded = {}
- loadscript = function(location, str)
- -- upvalues: scriptLoaded
- scriptLoaded[location] = loadstring(str)
- do
- local loaded = pcall(scriptLoaded[location])
- end
- if loaded then
- -- WARNING: missing end command somewhere! Added here
- end
- end
- unloadscript = function(location)
- -- upvalues: scriptLoaded
- scriptLoaded[location] = nil
- end
- local file = {}
- local originalFiles = {}
- local fileFinished = {}
- addEvent("serverSendFileData", true)
- _addEventHandler("serverSendFileData", root, function(location, data, start, sendNext)
- -- upvalues: file
- local slashPos = string.find(location, "/")
- local fileSrc = string.sub(location, slashPos + 1)
- local isScript = isScriptFile(fileSrc)
- if isScript then
- if not file[location] then
- file[location] = ""
- end
- file[location] = file[location] .. data
- if sendNext then
- triggerServerEvent("serverSendFileDataToPlayer", localPlayer, location, localPlayer, start)
- else
- triggerEvent("fileSendingFinished", localPlayer, location)
- end
- else
- local nloc = location
- local theFile = nil
- if fileExists(nloc) then
- theFile = fileOpen(nloc)
- else
- theFile = fileCreate(nloc)
- if theFile then
- outputDebugString("Created " .. nloc .. " from: " .. location)
- end
- else
- outputDebugString("Failed to create file: " .. nloc)
- end
- fileSetPos(theFile, fileGetSize(theFile))
- fileWrite(theFile, data)
- local saved = fileFlush(theFile)
- local size = fileGetSize(theFile)
- fileClose(theFile)
- if sendNext then
- triggerServerEvent("serverSendFileDataToPlayer", localPlayer, location, localPlayer, start)
- end
- else
- triggerEvent("fileSendingFinished", localPlayer, location)
- end
- end
- )
- getResourceNameFromLocation = function(location)
- local pos = string.find(location, "/", 1)
- location = string.sub(location, 1, pos - 1)
- return location
- end
- isMusicFile = function(file)
- file = getFileType(file)
- if not file then
- return
- end
- local compList = {}
- compList[#compList + 1] = ".mp3"
- compList[#compList + 1] = ".wav"
- compList[#compList + 1] = ".ogg"
- compList[#compList + 1] = ".riff"
- compList[#compList + 1] = ".mod"
- compList[#compList + 1] = ".xm"
- compList[#compList + 1] = ".it"
- compList[#compList + 1] = ".s3m"
- for i = 1, #compList do
- if string.find(file, compList[i], 1, true) then
- return true
- end
- end
- return false
- end
- isScriptFile = function(file)
- file = getFileType(file)
- if not file then
- return
- end
- if string.find(file, ".lua", 1, true) then
- return true
- end
- return false
- end
- getFileType = function(file)
- file = file:lower()
- local dotPos = nil
- for i = 1, file:len() do
- if file:sub(i, i) == "." then
- dotPos = i
- else
- end
- end
- if not dotPos then
- return false
- end
- return file:sub(dotPos)
- end
- getFileName = function(file)
- file = file:lower()
- local dotPos = nil
- for i = 1, file:len() do
- if file:sub(i, i) == "." then
- dotPos = i
- end
- end
- if not dotPos then
- return false
- end
- return file:sub(1, dotPos - 1)
- end
- addEvent("fileSendingFinished", true)
- _addEventHandler("fileSendingFinished", getRootElement(), function(location)
- -- upvalues: fileFinished , originalFiles , file , scriptLoaded
- local room = getElementParent(localPlayer)
- if getElementType(room) ~= "race.room" then
- return
- end
- local mapDownloadFinished = getElementData(localPlayer, "mapDownloadFinished")
- local scriptsLoaded = getElementData(localPlayer, "scriptsLoaded")
- if location then
- local slashPos = string.find(location, "/")
- local fileSrc = string.sub(location, slashPos + 1)
- do
- local isScript = isScriptFile(fileSrc)
- fileFinished[location] = true
- end
- end
- if not isScript then
- local allDoneExceptMusic = true
- end
- for k,origFile in ipairs(originalFiles) do
- local slashPos = string.find(origFile.location, "/")
- local fileSrc = string.sub(origFile.location, slashPos + 1)
- if (isScriptFile(fileSrc) or fileSrc:find("xml", 1, true)) and not fileFinished[origFile.location] then
- allDoneExceptMusic = false
- end
- end
- if mapDownloadFinished then
- mapDownloadFinished = false
- setElementData(localPlayer, "mapDownloadFinished", mapDownloadFinished, false)
- end
- if getElementData(room, "gamemode") ~= "training" then
- triggerServerEvent("onClientFinishedCreatingMap", localPlayer, getElementData(localPlayer, "doSpec"))
- end
- if allDoneExceptMusic and not scriptsLoaded then
- scriptsLoaded = true
- setElementData(localPlayer, "scriptsLoaded", scriptsLoaded, false)
- for loc,data in pairs(file) do
- local slashPos = string.find(loc, "/")
- local fileSrc = string.sub(loc, slashPos + 1)
- if isScriptFile(fileSrc) and not scriptLoaded[loc] and fileFinished[loc] then
- loadscript(loc, data)
- end
- end
- end
- end
- )
- getCharPos = function(str, char)
- local pos = 0
- for i = 1, str:len() do
- if str:sub(i, i) == char then
- pos = i
- end
- end
- return pos
- end
- addEvent("unloadScriptFromMemory", true)
- _addEventHandler("unloadScriptFromMemory", getRootElement(), function(files, spec, wait, sendMap)
- -- upvalues: scriptLoaded , loaded , file , fileFinished , originalFiles
- unload()
- for i,s in pairs(scriptLoaded) do
- unloadscript(i)
- end
- for k,_files in ipairs(files) do
- local fileName = _files.location
- local slashPos = string.find(fileName, "/")
- fileName = string.sub(fileName, slashPos + 1)
- if fileExists(fileName) and fileGetMD5(fileName) ~= _files.md5 then
- _setTimer(function(fileName)
- fileDelete(fileName)
- outputDebugString("corrupted file deleted: " .. fileName)
- end, 250, 1, fileName)
- end
- end
- loaded = {}
- scriptLoaded = {}
- file = {}
- fileFinished = {}
- originalFiles = {}
- originalFiles = files
- setElementData(localPlayer, "doSpec", spec, false)
- setElementData(localPlayer, "scriptsLoaded", nil, false)
- triggerServerEvent("onServerScriptUnloaded", localPlayer, files, sendMap)
- end
- )
- addEvent("clientRestartScripts", true)
- _addEventHandler("clientRestartScripts", root, function()
- -- upvalues: file
- unload(true)
- for i,s in pairs(file) do
- loadscript(i, s)
- end
- end
- )
- fileGetMD5 = function(location)
- local theFile = fileOpen(location)
- local MD5String = ""
- if theFile then
- local buffer = ""
- buffer = buffer .. fileRead(theFile, fileGetSize(theFile))
- fileClose(theFile)
- return md5(buffer)
- end
- return MD5String
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement