-
Notifications
You must be signed in to change notification settings - Fork 2
/
mod.lua
288 lines (250 loc) · 8.59 KB
/
mod.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
if not StreamHeist then
StreamHeist = {
mod_path = ModPath,
save_path = SavePath .. "streamlined_heisting.json",
mod_instance = ModInstance,
logging = io.file_is_readable("mods/developer.txt"),
required = {},
settings = {
auto_faction_tweaks = true,
faction_tweaks = {
swat = true,
fbi = true,
gensec = true,
zeal = true,
murkywater = true,
federales = true,
russia = true
},
radio_filtered_heavies = true,
allow_flashlights = true
}
}
function StreamHeist:require(file)
local path = self.mod_path .. "req/" .. file .. ".lua"
return io.file_is_readable(path) and blt.vm.dofile(path)
end
function StreamHeist:mission_script_patches()
if self._mission_script_patches == nil then
local level_id = Global.game_settings and Global.game_settings.level_id
if level_id then
self._mission_script_patches = self:require("mission_script/" .. level_id:gsub("_night$", ""):gsub("_day$", "")) or false
end
end
return self._mission_script_patches
end
function StreamHeist:log(str, ...)
if self.logging then
log("[StreamlinedHeisting] " .. str:format(...))
end
end
function StreamHeist:warn(str, ...)
log("[StreamlinedHeisting][Warning] " .. str:format(...))
end
function StreamHeist:error(str, ...)
log("[StreamlinedHeisting][Error] " .. str:format(...))
end
-- Redirect unit localization for units that can't be auto-detected
Hooks:Add("LocalizationManagerPostInit", "LocalizationManagerPostInitStreamlinedHeisting", function (loc)
loc:add_localized_strings({
ene_zeal_medic = loc:exists("ene_medic") and loc:text("ene_medic"),
ene_zeal_sniper = loc:exists("ene_sniper") and loc:text("ene_sniper")
})
if HopLib then
HopLib:load_localization(StreamHeist.mod_path .. "loc/", loc)
else
loc:load_localization_file(StreamHeist.mod_path .. "loc/english.txt")
end
end)
-- Check for common mod conflicts
Hooks:Add("MenuManagerOnOpenMenu", "MenuManagerOnOpenMenuStreamlinedHeisting", function()
if Global.sh_mod_conflicts then
return
end
Global.sh_mod_conflicts = {}
local conflicting_mods = StreamHeist:require("mod_conflicts") or {}
for _, mod in pairs(BLT.Mods:Mods()) do
if mod:IsEnabled() and conflicting_mods[mod:GetName()] then
table.insert(Global.sh_mod_conflicts, mod:GetName())
end
end
if #Global.sh_mod_conflicts == 0 then
return
end
local message = managers.localization:text("sh_menu_conflicts") .. "\n\n" .. table.concat(Global.sh_mod_conflicts, "\n")
local buttons = {
{
text = managers.localization:text("sh_menu_conflicts_disable"),
callback = function ()
for _, mod_name in pairs(Global.sh_mod_conflicts) do
BLT.Mods:GetModByName(mod_name):SetEnabled(false, true)
end
MenuCallbackHandler:perform_blt_save()
end
},
{
text = managers.localization:text("sh_menu_conflicts_ignore")
},
}
QuickMenu:new(managers.localization:text("sh_menu_warning"), message, buttons, true)
end)
-- Create settings menu
Hooks:Add("MenuManagerBuildCustomMenus", "MenuManagerBuildCustomMenusStreamlinedHeisting", function(_, nodes)
local menu_id = "sh_menu"
local menu_id_faction_tweaks = "sh_menu_faction_tweaks"
MenuHelper:NewMenu(menu_id)
MenuHelper:NewMenu(menu_id_faction_tweaks)
local faction_menu_elements = {}
function MenuCallbackHandler:sh_auto_faction_tweaks_toggle(item)
local enabled = (item:value() == "on")
StreamHeist.settings.auto_faction_tweaks = enabled
for _, element in pairs(faction_menu_elements) do
element:set_enabled(not enabled)
end
end
function MenuCallbackHandler:sh_faction_toggle(item)
StreamHeist.settings.faction_tweaks[item:name()] = (item:value() == "on")
end
function MenuCallbackHandler:sh_toggle(item)
StreamHeist.settings[item:name()] = (item:value() == "on")
end
function MenuCallbackHandler:sh_save()
io.save_as_json(StreamHeist.settings, StreamHeist.save_path)
end
MenuHelper:AddButton({
id = "faction_tweaks",
title = "sh_menu_faction_tweaks",
desc = "sh_menu_faction_tweaks_desc",
next_node = menu_id_faction_tweaks,
menu_id = menu_id,
priority = 100
})
MenuHelper:AddDivider({
menu_id = menu_id,
size = 16,
priority = 99
})
MenuHelper:AddToggle({
id = "radio_filtered_heavies",
title = "sh_menu_radio_filtered_heavies",
desc = "sh_menu_radio_filtered_heavies_desc",
callback = "sh_toggle",
value = StreamHeist.settings.radio_filtered_heavies,
menu_id = menu_id,
priority = 98
})
MenuHelper:AddToggle({
id = "allow_flashlights",
title = "sh_menu_allow_flashlights",
desc = "sh_menu_allow_flashlights_desc",
callback = "sh_toggle",
value = StreamHeist.settings.allow_flashlights,
menu_id = menu_id,
priority = 97
})
MenuHelper:AddToggle({
id = "auto_faction_tweaks",
title = "sh_menu_auto_faction_tweaks",
desc = "sh_menu_auto_faction_tweaks_desc",
callback = "sh_auto_faction_tweaks_toggle",
value = StreamHeist.settings.auto_faction_tweaks,
menu_id = menu_id_faction_tweaks,
priority = 100
})
local auto_faction_tweaks = StreamHeist.settings.auto_faction_tweaks
local faction_conflicts = Global.sh_faction_conflicts or {}
for i, faction in ipairs({ "swat", "fbi", "gensec", "zeal", "russia", "federales", "murkywater" }) do
local conflict = faction_conflicts[faction]
local menu_element = MenuHelper:AddToggle({
id = faction,
localized = false,
title = managers.localization:text("sh_menu_" .. faction),
desc = managers.localization:text(conflict and "sh_menu_faction_tweak_conflict_desc" or "sh_menu_faction_tweak_desc", { MOD = conflict }),
callback = "sh_faction_toggle",
value = StreamHeist.settings.faction_tweaks[faction],
disabled = auto_faction_tweaks,
disabled_color = conflict and tweak_data.screen_colors.important_2,
menu_id = menu_id_faction_tweaks,
priority = 100 - i
})
table.insert(faction_menu_elements, menu_element)
end
nodes[menu_id_faction_tweaks] = MenuHelper:BuildMenu(menu_id_faction_tweaks, { back_callback = "sh_save" })
nodes[menu_id] = MenuHelper:BuildMenu(menu_id, { back_callback = "sh_save" })
MenuHelper:AddMenuItem(nodes["blt_options"], menu_id, "sh_menu_main")
end)
-- Load settings
if io.file_is_readable(StreamHeist.save_path) then
local data = io.load_as_json(StreamHeist.save_path)
if data then
local function merge(tbl1, tbl2)
for k, v in pairs(tbl2) do
if type(tbl1[k]) == type(v) then
if type(v) == "table" then
merge(tbl1[k], v)
else
tbl1[k] = v
end
end
end
end
merge(StreamHeist.settings, data)
end
end
-- Disable some of "The Fixes"
TheFixesPreventer = TheFixesPreventer or {}
TheFixesPreventer.crash_aim_allow_fire_coplogicattack = true
TheFixesPreventer.crash_no_unit_type_aistatebesiege = true
TheFixesPreventer.crash_upd_aim_coplogicattack = true
TheFixesPreventer.fix_ai_set_attention = true
TheFixesPreventer.fix_gensec_shotgunner_in_murkywater = true
TheFixesPreventer.fix_hostages_not_moving = true
TheFixesPreventer.tank_remove_recoil_anim = true
TheFixesPreventer.tank_walk_near_players = true
-- Check faction tweaks
if not Global.sh_faction_tweaks_check then
Global.sh_faction_tweaks_check = true
Global.sh_faction_conflicts = {}
local auto_detect = StreamHeist.settings.auto_faction_tweaks
local asset_loader = StreamHeist.mod_instance.supermod:GetAssetLoader()
local mod_overrides = {}
if auto_detect then
for modname, data in pairs(DB:mods()) do
for _, file in pairs(data.files) do
local name, ext = file:match("^(.-)%.(.-)$")
if ext == "model" then
mod_overrides[name] = modname
end
end
end
end
for faction, enabled in pairs(StreamHeist.settings.faction_tweaks) do
if auto_detect then
enabled = true
local assets = asset_loader.script_loadable_packages[faction].assets
for _, spec in pairs(assets) do
if mod_overrides[spec.dbpath] then
StreamHeist:log("Disabling faction tweak for faction %s due to mod_override %s", faction, mod_overrides[spec.dbpath])
Global.sh_faction_conflicts[faction] = mod_overrides[spec.dbpath]
enabled = false
break
end
end
StreamHeist.settings.faction_tweaks[faction] = enabled
end
if enabled then
asset_loader:LoadAssetGroup(faction)
end
end
if auto_detect then
io.save_as_json(StreamHeist.settings, StreamHeist.save_path)
end
end
end
if RequiredScript and not StreamHeist.required[RequiredScript] then
local fname = StreamHeist.mod_path .. RequiredScript:gsub(".+/(.+)", "lua/%1.lua")
if io.file_is_readable(fname) then
dofile(fname)
end
StreamHeist.required[RequiredScript] = true
end