Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
553 lines (469 loc) · 15.4 KB
/
Copy pathinit.lua
File metadata and controls
553 lines (469 loc) · 15.4 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
Cron = require("Modules/Cron")
local GameSession = require("Modules/GameSession")
Vars = require("Modules/Vars")
GraphicsQuality = require("Modules/GraphicsQuality")
Config = require("Modules/Config")
local GameUI = require("Modules/GameUI")
Helpers = require("Modules/Helpers")
Tweaks = require("Modules/Tweaks")
local Window = require("Modules/Window")
App = { ["version"] = "1.5.1" }
local isLoaded = false
App.inited = false
App.isOverlayOpen = false
App.isEnabled = true
App.currentPreset = ""
App.shouldCloseOverlay = false
App.menuState = nil
Errors = {
SETTINGS_APPLY = false,
}
App.States = {
isCombat = false,
isVehicle = false
}
local API = {}
function API.Enable()
App.isEnabled = true
end
function API.Disable()
App.isEnabled = false
end
function API.DisableAndSetToNormal()
App.isEnabled = false
GraphicsQuality.RequestPreset(Config.inner.presets.normal, "normal")
end
function API.IsEnabled()
return App.isEnabled
end
function IsCombat()
return App.States.isCombat
end
function IsVehicle()
return App.States.isVehicle
end
function IsPhotomode()
return GameUI.IsPhoto()
end
function IsMenu()
return GameUI.GetMenu() == "NewGame" or GameUI.GetMenu() == "Hub"
end
function IsScene()
return GameUI.IsScene()
end
local function initTweaks()
for _,tweakOption in pairs(Tweaks.list) do
local curValue = GameOptions.Get(tweakOption.var, tweakOption.key)
local savedValue = Config.inner.tweaks[tweakOption.var..tweakOption.key]
if savedValue and savedValue.value ~= nil then
if tweakOption.kind == "bool" then
GameOptions.SetBool(tweakOption.var, tweakOption.key, savedValue.value)
elseif tweakOption.kind == "float" then
GameOptions.SetFloat(tweakOption.var, tweakOption.key, savedValue.value)
elseif tweakOption.kind == "int" then
GameOptions.SetInt(tweakOption.var, tweakOption.key, savedValue.value)
end
else
-- Config.inner.tweaks[tweakOption.var..tweakOption.key] = { value = nil, _ = 0 }
end
--
end
end
local function assertDefaultPresetsExist()
local defaultPreset = GraphicsQuality.GetCurrentPreset()
local changed = false
for presetName, value in pairs(Config.inner.presets) do
if value == 0 then
changed = true
-- clone the list
Config.inner.presets[presetName] = json.decode(json.encode(defaultPreset))
-- Default photomode's DOF option to true in order to not break it.
if presetName == "photo" then
for _, presetSettings in pairs(Config.inner.presets[presetName]) do
if presetSettings.var == "/graphics/basic/DepthOfField" then
presetSettings.value = true
break
end
end
end
end
end
if changed then
Config.SaveConfig()
end
end
function IsCurrentPreset(preset)
local currentPreset = GraphicsQuality.GetCurrentPreset()
for _,currentPresetSettings in pairs(currentPreset) do
for _,presetSettings in pairs(preset) do
if not presetSettings.ignore then
if presetSettings.var == currentPresetSettings.var and (presetSettings.value ~= currentPresetSettings.value) then
return false
end
end
end
end
return true
end
function HasMountedVehicle()
return not not Game['GetMountedVehicle;GameObject'](Game.GetPlayer())
end
function IsEnteringVehicle()
return IsInVehicle() and Game.GetWorkspotSystem():GetExtendedInfo(Game.GetPlayer()).entering
end
function IsExitingVehicle()
return IsInVehicle() and Game.GetWorkspotSystem():GetExtendedInfo(Game.GetPlayer()).exiting
end
function IsInVehicle()
local ws = Game.GetWorkspotSystem()
local player = Game.GetPlayer()
if ws and player then
local info = ws:GetExtendedInfo(player)
if info then
return ws:IsActorInWorkspot(player)
and info.isActive
and HasMountedVehicle()
end
end
end
function SetPresetIfNeeded()
if not App.isEnabled then
if Config.inner.switchToNormalWhenDisabled then
GraphicsQuality.RequestPreset(Config.inner.presets.normal, "normal")
end
return
end
local delay = 0.1
if IsPhotomode() and Config.inner.enabled.photo then
delay = 0.8
GraphicsQuality.RequestPreset(Config.inner.presets.photo, "photo", delay)
elseif IsMenu() and Config.inner.enabled.menu then
GraphicsQuality.RequestPreset(Config.inner.presets.menu, "menu", delay)
elseif IsCombat() and Config.inner.enabled.combat then
delay = 0
GraphicsQuality.RequestPreset(Config.inner.presets.combat, "combat", delay)
elseif IsVehicle() and Config.inner.enabled.vehicle then
GraphicsQuality.RequestPreset(Config.inner.presets.vehicle, "vehicle", delay)
elseif IsScene() and Config.inner.enabled.scene then
GraphicsQuality.RequestPreset(Config.inner.presets.scene, "scene", delay)
else
if App.currentPreset == "combat" then
delay = 0.8
end
GraphicsQuality.RequestPreset(Config.inner.presets.normal, "normal", delay)
end
end
function App.new()
-- registerForEvent('onTweak', function()
-- print(123)
-- TweakDB:SetFlat('PreventionSystem.setup.totalEntitiesLimit', 20)
-- local lookAtPreset = TweakDB:GetFlat('PhotoModePoses.idle__katana.lookAtPreset')
-- TweakDB:SetFlat('PhotoModePoses.idle_squat.lookAtPreset', lookAtPreset)
-- print(TweakDB:GetFlat("PhotoModePoses.idle_squat.disableLookAtForGarmentTags")[1])
-- end)
local deltaAccum = 0
registerForEvent("onDraw", function(delta)
if not App.inited or not App.isOverlayOpen then
return
end
Window.Draw(Config.isReady)
end)
local checkEvery = Vars.CHECK_COMBAR_EVERY_MS / 1000
-- Cron.Every(0.2, GraphicsQuality.EnsurePreset, {})
local hadWeapon = false
registerForEvent("onUpdate", function(delta)
if not App.inited or not Config.isReady then
return
end
Cron.Update(delta)
if not GameUI.IsMainMenu() and (GameUI.IsMenu() or GameUI.IsLoading()) then
return
end
GraphicsQuality.EnsurePreset()
if not isLoaded then
return
end
deltaAccum = deltaAccum + delta
-- do stuff every N seconds
if deltaAccum > checkEvery then
-- print(Helpers.highestHostileDetection())
deltaAccum = 0
CheckCombat()
CheckVehicle()
end
end)
local lastIsInCombat = false
local lastInVehiceState = false
local lastUnholstered = false
local ignoreForThisLocomotion = false
local lastLocomotion = 0
local upperBodyState = 0
function CheckCombat()
local combatState = Helpers.CombatState()
local securityZone = Helpers.SecurityZone()
local unholstered = Config.inner.combatUnholstered and (Helpers.HasWeapon())
local isInCombat =
combatState == "InCombat" or
(unholstered and (not IsInVehicle() or Config.inner.combatUnholsteredVehicle)) or
(Config.inner.isDangerousAreaACombat and securityZone == "DangerousZone") or
(Config.inner.isRestrictedAreaACombat and securityZone == "RestrictedZone")
-- print(isInCombat)
local hasCombatStateChanged = lastIsInCombat ~= isInCombat
local unholsteredChanged = lastUnholstered ~= unholstered
local locomotionState = Helpers.LocomotionState()
-- print(Game.GetWorkspotSystem():IsActorInWorkspot(Game.GetPlayer()))
-- if one of the potentially temporary locomotions
-- 8 - Climb
-- 10-13 - Ladder
local isTempLocomotion = Config.inner.combatUnholstered
and (locomotionState == 8
or (locomotionState >= 10 and locomotionState <= 13)
or locomotionState == 14
or locomotionState == 17
or locomotionState == 23
or locomotionState == 24
or locomotionState == 25
or locomotionState == 26
or locomotionState == 27
or locomotionState == 28
or locomotionState == 29
or locomotionState == 31
or upperBodyState == 4
or (Helpers.IsInWorkspot() and not IsInVehicle() and not GameUI.IsVehicle())
or Helpers.GrappleState() > 0
)
if not isTempLocomotion and ignoreForThisLocomotion then
ignoreForThisLocomotion = false
end
if Config.inner.combatUnholstered then
ignoreForThisLocomotion = false
end
if hasCombatStateChanged then
if isInCombat then
OnCombatEnter()
else
-- if holstered a gun
if unholsteredChanged and not unholstered and Config.inner.combatUnholstered then
-- if one of the temporary locomotions, then ignore the combat state change
if isTempLocomotion then
ignoreForThisLocomotion = true
end
end
if not ignoreForThisLocomotion then
OnCombatExit()
end
end
end
lastUnholstered = unholstered
lastLocomotion = locomotionState
lastIsInCombat = isInCombat
end
function CheckVehicle()
local isInVehicle = IsInVehicle()
local hasInVehicleChanged = lastInVehiceState ~= isInVehicle
if hasInVehicleChanged then
if isInVehicle then
OnVehicleEnter()
else
OnVehicleExit()
end
end
lastInVehiceState = isInVehicle
end
function OnPhotomodeEnter()
isLoaded = true
if Config.inner.enabled.photo then
SetPresetIfNeeded()
end
end
function OnPhotomodeExit()
isLoaded = true
if Config.inner.enabled.photo then
SetPresetIfNeeded()
end
end
function OnVehicleEnter()
isLoaded = true
App.States.isVehicle = true
if Config.inner.enabled.vehicle then
SetPresetIfNeeded()
end
end
function OnVehicleExit()
App.States.isVehicle = false
if Config.inner.enabled.vehicle then
SetPresetIfNeeded()
end
end
function OnCombatEnter()
isLoaded = true
App.States.isCombat = true
if Config.inner.enabled.combat then
SetPresetIfNeeded()
end
end
function OnCombatExit()
App.States.isCombat = false
if Config.inner.enabled.combat then
SetPresetIfNeeded()
end
end
function OnMenuEnter()
if Config.inner.enabled.menu then
SetPresetIfNeeded()
end
end
function OnMenuExit()
if Config.inner.enabled.menu then
SetPresetIfNeeded()
end
end
function OnSceneEnter()
if Config.inner.enabled.scene then
SetPresetIfNeeded()
end
end
function OnSceneExit()
if Config.inner.enabled.scene then
SetPresetIfNeeded()
end
end
registerForEvent("onShutdown", function()
GraphicsQuality.RequestPreset(Config.inner.presets.normal, "normal")
end)
registerForEvent("onOverlayOpen", function ()
App.isOverlayOpen = true
end)
registerForEvent("onOverlayClose", function ()
App.isOverlayOpen = false
end)
registerForEvent("onInit", function ()
Config.InitConfig()
App.isEnabled = Config.inner.enabledOnStart
if App.isEnabled then
App.currentPreset = "normal"
end
assertDefaultPresetsExist()
-- temp sorting fix
Config.InitConfig()
initTweaks()
GameSession.OnStart(function()
Helpers.PrintDebugMsg("Game session has been started")
isLoaded = true
end)
GameSession.OnEnd(function()
Helpers.PrintDebugMsg("Game session has been ended")
isLoaded = false
end)
GameSession.OnResume(function()
Helpers.PrintDebugMsg("Game has been unpaused")
isLoaded = true
end)
GameSession.OnPause(function()
Helpers.PrintDebugMsg("Game has been paused")
isLoaded = false
end)
GameUI.Observe(GameUI.Event.MenuNav, SetPresetIfNeeded)
GameUI.OnPhotoModeOpen(OnPhotomodeEnter)
GameUI.OnPhotoModeClose(OnPhotomodeExit)
GameUI.OnMenuOpen(OnMenuEnter)
GameUI.OnMenuClose(OnMenuExit)
GameUI.OnVehicleEnter(OnVehicleEnter)
GameUI.OnVehicleExit(OnVehicleExit)
GameUI.OnSceneEnter(OnSceneEnter)
GameUI.OnSceneExit(OnSceneExit)
-- Observe('RadialWheelController', 'RegisterBlackboards', function(_, loaded)
-- isLoaded = loaded
-- end)
Observe('WeaponRosterGameController', 'OnWeaponDataChanged', function (_, state)
if Config.inner.combatUnholstered then
if ItemID.IsValid(FromVariant(state).weapon.weaponID) then
OnCombatEnter()
else
CheckCombat()
end
end
end)
Observe('PlayerPuppet', 'OnGameAttached', function(self, b)
self:RegisterInputListener(self, "OpenInventoryMenu")
end)
-- Observe('PlayerPuppet', 'OnCombatGadgetStateChanged', function(self, newState)
-- print("combatStateChanged", newState)
-- CheckCombat()
-- end)
Observe('PlayerPuppet', 'OnUpperBodyStateChange', function(self, newState)
upperBodyState = newState
end)
Observe("PlayerPuppet", "OnAction", function(_, action)
local ListenerAction = GetSingleton('gameinputScriptListenerAction')
local actionName = Game.NameToString(ListenerAction:GetName(action))
-- if you open inventory without going into HUB menu first, settings are not applied for some reason.
if actionName == "OpenInventoryMenu" then
if Config.inner.enabled.menu then
GraphicsQuality.RequestPreset(Config.inner.presets.menu, "menu")
end
end
end)
-- Observe("PlayerPuppet", "OnEnterUndefinedZone", function() end)
-- Observe("PlayerPuppet", "OnEnterPublicZone", function() end)
-- Observe("PlayerPuppet", "OnExitPublicZone", function() end)
-- Observe("PlayerPuppet", "OnEnterSafeZone", function() end)
-- Observe("PlayerPuppet", "OnExitSafeZone", function() end)
-- Observe("PlayerPuppet", "OnEnterRestrictedZone", function() end)
-- Observe("PlayerPuppet", "OnEnterDangerousZone", function() end)
App.inited = true
end)
registerHotkey("agq_toggle_enabled", "Toggle enabled", function()
App.isEnabled = not App.isEnabled
end)
registerHotkey("agq_toggle_force_normal", 'Force "Normal" preset', function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets.normal, "normal")
end)
registerHotkey("agq_toggle_force_photomode", 'Force "Photomode" preset', function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets.photo, "photo", 0)
end)
registerHotkey("agq_toggle_force_menu", 'Force "Menu" preset', function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets.menu, "menu")
end)
registerHotkey("agq_toggle_force_combat", 'Force "Combat" preset', function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets.combat, "combat")
end)
registerHotkey("agq_toggle_force_vehicle", 'Force "Vehicle" preset', function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets.vehicle, "vehicle")
end)
registerHotkey("agq_toggle_force_scene", 'Force "Scene" preset', function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets.scene, "scene")
end)
for var=1,10 do
registerHotkey("agq_force_custom_" .. var, "Force custom preset #" .. tostring(var), function()
if Config.inner.disableAutoswitchOnHotkey then
App.isEnabled = false
end
GraphicsQuality.RequestPreset(Config.inner.presets[tostring(var)], tostring(var))
end)
end
return {
version = App.version,
api = API,
GameSettings = GameSettings,
}
end
return App.new()