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