Dany Alex Posted February 28, 2016 Posted February 28, 2016 cMods.lua: -- Don't store txd and dff files in the XML - Prevent hackers from changing file names Mods = { }; Mods.FromXML = { }; -- Mods Constructor function Mods:Mods ( ) Mods:PhraseXML ( ); if ( isTimer ( checkServerTimer ) ) then killTimer ( checkServerTimer ); end setTimer ( function ( ) -- Did the server have time to load the list?? Downloader:RequestList ( ); -- Get list from server end, 500, 1 ); end function Mods:PhraseXML ( ) -- Create the user cmods.xml for saving of enabled/disabled -- Create if it doesn't exist if ( not File.exists ( "@cmods.xml" ) ) then local t = File.new ( "@cmods.xml" ); t:write ( "" ); t:close ( ); end -- Attempt to load XML file local xml = XML.load ( "@cmods.xml" ); -- if XML failed to load, delete it and try again if ( not xml ) then File.delete ( "@cmods.xml" ); Mods:Mods ( ); return end -- If it exists, loop the children and collect info for index, child in pairs ( xml.children ) do -- Is it a mod child? if ( child.name == "mod" ) then local name = child:getAttribute ( "name" ); local enabled = child:getAttribute ( "enabled" ); -- Do all of our attributes exist? if ( name and enabled ) then -- Was this already loaded? if ( not Mods.FromXML [ name ] ) then Mods.FromXML [ name ] = ( tostring ( enabled ):lower ( ) == "true" ); else child:destroy ( ); end else child:destroy ( ); end end end -- Save and unload xml file xmlSaveFile ( xml ); xmlUnloadFile ( xml ); end function Mods.SaveXML ( ) if ( File.exists ( "@cmods.xml" ) ) then File.delete ( "@cmods.xml" ); end local str= "\n \n %s \n"; local _str = ""; for i, v in pairs ( Downloader.Mods ) do _str = _str .. "\n" .. string.format ( '', i, tostring ( v.enabled ) ); end local f = File.new ( "@cmods.xml" ); f:write ( str:format ( _str ) ); f:close ( ); end setTimer ( Mods.SaveXML, 5000000, 0 ); addEventHandler ( "onClientResourceStop", resourceRoot, Mods.SaveXML ); -- Mods:PhraseList -> Used to check mods list for enabled mods function Mods:PhraseList ( ) --Downloader.Mods = { } -- Loop through the list and find completed downloaded files for name, mod in pairs ( Downloader.Mods ) do local txd = mod.txd; local dff = mod.dff; local replace = mod.replace; Downloader.Mods [ name ].enabled = false; -- Check if the txd file is downloaded local bothExist = false; if ( File.exists ( tostring ( txd ) ) ) then -- if so, load it local temp = File( txd, true ); -- is it out-dated? doDelete = ( tostring ( md5 ( temp:read ( temp.size ) ) ):lower ( ) ~= tostring ( mod.txd_hash ):lower( ) ); temp:close ( ); -- if outdated, then delete if ( doDelete ) then File.delete ( txd ); outputDebugString ( txd.." was deleted - hash doesn't match with server" ); bothExist = false; else outputDebugString ( txd.." has been successfully listed" ); bothExist = true; end else outputDebugString ( tostring ( txd ).. " not present - beginning download" ); Downloader:AddDownload ( tostring ( txd ) ); end -- Check if the dff file is downloaded if ( File.exists ( tostring ( dff ) ) ) then -- if so, load it local temp = File( dff, true ); -- is it out-dated? doDelete = ( md5 ( temp:read ( temp.size ) ):lower() ~= mod.dff_hash:lower() ); temp:close ( ); -- if outdated, then delete if ( doDelete ) then File.delete ( dff ); outputDebugString ( dff.." was deleted - hash doesn't match with server" ); bothExist = false; else outputDebugString ( dff.." has been successfully listed" ); if ( bothExist ) then bothExist = true; end end else outputDebugString ( tostring ( dff ).. " not present - beginning download" ); Downloader:AddDownload ( tostring ( dff ) ); end if ( bothExist ) then --outputDebugString ( name.." - both files loaded. Enabled: "..tostring ( Mods.FromXML [ name ] ) ); if ( Mods.FromXML [ name ] ) then Mods.SetModEnabled ( name, true ); end end end end function Mods.SetModEnabled ( mod, enabled ) if ( not Downloader.Mods [ mod ] ) then return outputDebugString ( string.format ( "Attempted to enable mod '%s' - doesn't exist in Downloader.Mods", mod ), 255, 0, 0 ); end if ( ( enabled and Downloader.Mods [ mod ].enabled ) or ( not enabled and not Downloader.Mods [ mod ].enabled ) ) then -- check current state return false; -- cancel if is already current state end Downloader.Mods [ mod ].enabled = enabled; if ( enabled ) then if ( File.exists ( Downloader.Mods [ mod ].dff ) and File.exists ( Downloader.Mods [ mod ].txd ) ) then local txd = engineLoadTXD ( Downloader.Mods [ mod ].txd ) engineImportTXD ( txd, Downloader.Mods [ mod ].replace ) local dff = engineLoadDFF ( Downloader.Mods [ mod ].dff, 0 ) engineReplaceModel ( dff, Downloader.Mods [ mod ].replace ) end else engineRestoreModel ( Downloader.Mods [ mod ].replace ); end end --addEventHandler ( "onClientResourceStart", resourceRoot, Mods.Mods ); addEvent ( "ModLoader:OnServerReadyAccepts", true ); addEventHandler ( "ModLoader:OnServerReadyAccepts", root, Mods.Mods ); checkServerTimer = setTimer ( function ( ) outputDebugString ( "Sending server request" ); triggerServerEvent ( "ModDownloader:TestServerReadyForClient", localPlayer ); end, 2000, 0 )
Dany Alex Posted February 29, 2016 Author Posted February 29, 2016 Smods.lua "Infernus Drift" txd="infernus.txd" dff="infernus.dff" replace="411" /> "Mercedes Benz" txd="merit.txd" dff="merit.dff" replace="551" /> "BMW 730iX" txd="euros.txd" dff="euros.dff" replace="587" /> "Ford Shelby" txd="buffalo.txd" dff="buffalo.dff" replace="402" /> "Porsche 911" txd="feltzer.txd" dff="feltzer.dff" replace="533" /> "Dacia Logan" txd="intruder.txd" dff="intruder.dff" replace="546" /> "VW Scirocco" txd="blistac.txd" dff="blistac.dff" replace="496" /> "VW Golf 4" txd="club.txd" dff="club.dff" replace="589" /> "Mitsubishi Evo 2008" txd="sultan.txd" dff="sultan.dff" replace="560" /> "BMW e36" txd="cheetah.txd" dff="cheetah.dff" replace="415" /> "Chevrolet Camaro" txd="phoenix.txd" dff="phoenix.dff" replace="603" /> "NRG-500 ER" txd="nrg500.txd" dff="nrg500.dff" replace="522" /> "BMX X6" txd="huntley.txd" dff="huntley.dff" replace="579" /> "Ferrari 458 Italia" txd="supergt.txd" dff="supergt.dff" replace="506" /> "Hydra" txd="hydra.txd" dff="hydra.dff" replace="520" /> "Audi RS 5" txd="uranus.txd" dff="uranus.dff" replace="558" /> "BMW M3 GTR" txd="esperant.txd" dff="esperant.dff" replace="419" /> "BMX MOD" txd="bmx.txd" dff="bmx.dff" replace="481" /> "VW Vento Police" txd="copcarla.txd" dff="copcarla.dff" replace="596" /> "Dodge Challenger RT 426" txd="clover.txd" dff="clover.dff" replace="542" /> "Audi A6" txd="elegant.txd" dff="elegant.dff" replace="507" /> "Old Fat Lady" txd="bfost.txd" dff="bfost.dff" replace="10" /> "Floral Shirt" txd="bmori.txd" dff="bmori.dff" replace="14" /> "Plaid Baldy" txd="bmost.txd" dff="bmost.dff" replace="15" /> "Earmuff Worker" txd="bmyap.txd" dff="bmyap.dff" replace="16" /> "Black suit" txd="bmybu.txd" dff="bmybu.dff" replace="17" /> "Striped Gangsta" txd="bmycr.txd" dff="bmycr.dff" replace="21" /> "Orange Sportsman" txd="bmydrug.txd" dff="bmydrug.dff" replace="22" /> "Skater Kid" txd="bmyst.txd" dff="bmyst.dff" replace="23" /> "LS Coach" txd="dwfolc.txd" dff="dwfolc.dff" replace="24" /> "Varsity jacket" txd="dwmolc1.txd" dff="dwmolc1.dff" replace="25" /> "Hiker" txd="dwmolc2.txd" dff="dwmolc2.dff" replace="26" /> "Construction 1" txd="hfori.txd" dff="hfori.dff" replace="27" /> "Black Dealer" txd="hfost.txd" dff="hfost.dff" replace="28" /> "White Dealer" txd="hfyri.txd" dff="hfyri.dff" replace="29" /> "Fat Cowgirl" txd="hmogar.txd" dff="hmogar.dff" replace="31" /> "Bounty Hunter" txd="wbdyg2.txd" dff="wbdyg2.dff" replace="33" /> "Marlboro Man" txd="wmybmx.txd" dff="wmybmx.dff" replace="34" /> "Fisherman" txd="wmybp.txd" dff="wmybp.dff" replace="35" /> "Baseball Dad" txd="wmycon.txd" dff="wmycon.dff" replace="37" /> "Old Golf Lady" txd="wmydrug.txd" dff="wmydrug.dff" replace="38" /> "Old Maid" txd="wmygol1.txd" dff="wmygol1.dff" replace="39" /> "Classy Dark Hooker" txd="wmygol2.txd" dff="wmygol2.dff" replace="40" /> "ak47" txd="ak47.txd" dff="ak47.dff" replace="355" /> "m4" txd="m4.txd" dff="m4.dff" replace="356" /> "colt45" txd="colt45.txd" dff="colt45.dff" replace="346" /> "mp5lng" txd="mp5lng.txd" dff="mp5lng.dff" replace="353" /> "sawnoff" txd="sawnoff.txd" dff="sawnoff.dff" replace="350" /> "sniper" txd="sniper.txd" dff="sniper.dff" replace="358" /> "silenced" txd="silenced.txd" dff="silenced.dff" replace="347" /> "micro_uzi" txd="micro_uzi.txd" dff="micro_uzi.dff" replace="352" /> "knife" txd="knifecur.txd" dff="knifecur.dff" replace="335" /> "Parachute" txd="gun_para.txd" dff="gun_para.dff" replace="371" /> "desert_eagle" txd="desert_eagle.txd" dff="desert_eagle.dff" replace="348" /> "chromegun" txd="chromegun.txd" dff="chromegun.dff" replace="349" /> Meta.xml "xXMADEXx" type="script" version="1.2.1" name="Mod Downloader" /> true
BluntZ Posted February 29, 2016 Posted February 29, 2016 Everything looks fine in code ... Mods are loading or not ?
Dany Alex Posted February 29, 2016 Author Posted February 29, 2016 Yea, error on the join in server and 5 sec lag
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now