Advertisement
Guest User

init_faf_dev.lua

a guest
Sep 11th, 2016
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.88 KB | None | 0 0
  1. -- this imports a path file that is written by Forged Alliance Forever right before it starts the game.
  2. dofile(InitFileDir .. '\\..\\fa_path.lua')
  3. path = {}
  4. blacklist = {
  5.     "00_BigMap.scd",
  6.     "00_BigMapLEM.scd",
  7.     "fa-ladder.scd",
  8.     "fa_ladder.scd",
  9.     "faladder.scd",
  10.     "powerlobby.scd",
  11.     "02_sorian_ai_pack.scd",
  12.     "03_lobbyenhancement.scd",
  13.     "randmap.scd",
  14.     "_Eject.scd",
  15.     "Eject.scd",
  16.     "gaz_ui",
  17.     "lobby.nxt",
  18.     "faforever.nxt"    
  19. }
  20. whitelist =
  21. {
  22.     "effects.nx2",
  23.     "env.nx2",
  24.     "etc.nx2",
  25.     "loc.nx2",
  26.     "lua.nx2",
  27.     "meshes.nx2",
  28.     "mods.nx2",
  29.     "modules.nx2",
  30.     "projectiles.nx2",
  31.     "schook.nx2",
  32.     "textures.nx2",
  33.     "units.nx2",    
  34.     "murderparty.nxt",
  35.     "labwars.nxt",
  36.     "units.scd",
  37.     "textures.scd",
  38.     "skins.scd",
  39.     "schook.scd",
  40.     "props.scd",
  41.     "projectiles.scd",
  42.     "objects.scd",
  43.     "moholua.scd",
  44.     "mohodata.scd",
  45.     "mods.scd",
  46.     "meshes.scd",
  47.     "lua.scd",
  48.     "loc_us.scd",
  49.     "loc_es.scd",
  50.     "loc_fr.scd",
  51.     "loc_it.scd",
  52.     "loc_de.scd",
  53.     "loc_ru.scd",
  54.     "env.scd",
  55.     "effects.scd",
  56.     "editor.scd",
  57.     "ambience.scd",
  58.     "advanced strategic icons.nxt",
  59.     "lobbymanager_v105.scd",
  60.     "texturepack.nxt",
  61.     "sc_music.scd"
  62. }
  63.  
  64. local function mount_dir(dir, mountpoint)
  65.     table.insert(path, { dir = dir, mountpoint = mountpoint } )
  66. end
  67. local function mount_contents(dir, mountpoint)
  68.     LOG('checking ' .. dir)
  69.     for _,entry in io.dir(dir .. '\\*') do
  70.         if entry != '.' and entry != '..' then
  71.             local mp = string.lower(entry)
  72.             local safe = true
  73.             for i, black in blacklist do
  74.                 safe = safe and (string.find(mp, black, 1) == nil)
  75.             end
  76.             if safe then
  77.                 mp = string.gsub(mp, '[.]scd$', '')
  78.                 mp = string.gsub(mp, '[.]zip$', '')
  79.                 mount_dir(dir .. '\\' .. entry, mountpoint .. '/' .. mp)
  80.             else
  81.                 LOG('not safe ' .. entry)
  82.             end
  83.         end
  84.     end
  85. end
  86.  
  87. local function mount_dir_with_whitelist(dir, glob, mountpoint)
  88.     sorted = {}
  89.     LOG('checking ' .. dir .. glob)
  90.     for _,entry in io.dir(dir .. glob) do
  91.         if entry != '.' and entry != '..' then
  92.             local mp = string.lower(entry)
  93.             local notsafe = true
  94.             for i, white in whitelist do
  95.                     notsafe = notsafe and (string.find(mp, white, 1) == nil)
  96.             end
  97.             if notsafe then
  98.                     LOG('not safe ' .. dir .. entry)                                
  99.             else
  100.                     table.insert(sorted, dir .. entry)
  101.             end
  102.         end
  103.     end
  104.     table.sort(sorted)
  105.     table.foreach(sorted, function(k,v) mount_dir(v,'/') end)
  106. end
  107. local function mount_dir_with_blacklist(dir, glob, mountpoint)
  108.     sorted = {}
  109.     LOG('checking ' .. dir .. glob)
  110.     for _,entry in io.dir(dir .. glob) do
  111.         if entry != '.' and entry != '..' then
  112.             local mp = string.lower(entry)
  113.             local safe = true
  114.             for i, black in blacklist do
  115.                     safe = safe and (string.find(mp, black, 1) == nil)
  116.             end
  117.             if safe then
  118.                     table.insert(sorted, dir .. entry)
  119.             else
  120.                     LOG('not safe ' .. dir .. entry)
  121.             end
  122.         end
  123.     end
  124.     table.sort(sorted)
  125.     table.foreach(sorted, function(k,v) mount_dir(v,'/') end)
  126. end
  127. -- Begin map mounting section
  128. -- This section mounts movies and sounds from maps, essential for custom missions and scripted maps
  129. local function mount_map_dir(dir, glob, mountpoint)
  130.     LOG('mounting maps from: '..dir)
  131.     mount_contents(dir, mountpoint)
  132.     for _, map in io.dir(dir..glob) do
  133.         for _, folder in io.dir(dir..'\\'..map..'\\**') do
  134.             if folder == 'movies' then
  135.                 LOG('Found map movies in: '..map)
  136.                 mount_dir(dir..map..'\\movies', '/movies')
  137.             elseif folder == 'sounds' then
  138.                 LOG('Found map sounds in: '..map)
  139.                 mount_dir(dir..map..'\\sounds', '/sounds')
  140.             end
  141.         end
  142.     end
  143. end
  144. mount_map_dir(SHGetFolderPath('PERSONAL') .. 'My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\maps\\', '**', '/maps')
  145. mount_map_dir(InitFileDir .. '\\..\\user\\My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\maps\\', '**', '/maps')
  146. -- Begin mod mounting section
  147. -- This section mounts sounds from the mods directory to allow mods to add custom sounds to the game
  148. function mount_mod_sounds(MODFOLDER)
  149.     -- searching for mods inside the modfolder
  150.     for _,mod in io.dir( MODFOLDER..'\\*.*') do
  151.         -- do we have a true directory ?
  152.         if mod != '.' and mod != '..' then
  153.             -- searching for sounds inside mod folder
  154.             for _,folder in io.dir(MODFOLDER..'\\'..mod..'\\*.*') do
  155.                 -- if we found a folder named sounds then mount it
  156.                 if folder == 'sounds' then
  157.                     LOG('Found mod sounds in: '..mod)
  158.                     mount_dir(MODFOLDER..'\\'..mod..'\\sounds', '/sounds')
  159.                     break
  160.                 end
  161.             end
  162.         end
  163.     end
  164. end
  165. mount_mod_sounds(SHGetFolderPath('PERSONAL') .. 'My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\mods')
  166. mount_mod_sounds(InitFileDir .. '\\..\\user\\My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\mods')
  167. -- End mod mounting section
  168. -- these are the classic supcom directories. They don't work with accents or other foreign characters in usernames
  169. mount_contents(SHGetFolderPath('PERSONAL') .. 'My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\mods', '/mods')
  170. mount_contents(SHGetFolderPath('PERSONAL') .. 'My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\maps', '/maps')
  171.  
  172. -- these are the local FAF directories. The My Games ones are only there for people with usernames that don't work in the uppder ones.
  173. mount_contents(InitFileDir .. '\\..\\user\\My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\mods', '/mods')
  174. mount_contents(InitFileDir .. '\\..\\user\\My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\maps', '/maps')
  175.  
  176. -- Change this path to fit your fa repository, this one is Documents\GitHub\fa
  177. dev_path = SHGetFolderPath('PERSONAL') .. 'GitHub\\fa'
  178. mount_dir(dev_path, '/')
  179.  
  180. mount_dir_with_whitelist(InitFileDir .. '\\..\\gamedata\\', '*.nxt', '/')
  181. mount_dir_with_whitelist(InitFileDir .. '\\..\\gamedata\\', '*.nx2', '/')
  182.  
  183. -- these are using the newly generated path from the dofile() statement at the beginning of this script
  184. mount_dir_with_whitelist(fa_path .. '\\gamedata\\', '*.scd', '/')
  185. mount_dir(fa_path, '/')
  186.  
  187.  
  188. hook = {
  189.     '/schook'
  190. }
  191.  
  192. protocols = {
  193.     'http',
  194.     'https',
  195.     'mailto',
  196.     'ventrilo',
  197.     'teamspeak',
  198.     'daap',
  199.     'im',
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement