Skip to content

Commit 236731e

Browse files
committed
Lua module update
1 parent f6133a1 commit 236731e

19 files changed

+688
-75
lines changed

lua-module/.build/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let code = $.readText('module.lua');
22
code = code.replace(/--@includes:start[\s\S]+--@includes:end/, () => $.glob('src/*.lua')
3-
.map(x => `-- ${x}\n;(function ()\n${$.readText(x)}\nend)()`).join('\n\n'));
3+
.map(x => `-- ${x}\nac.log('Module ${x}')\n;(function ()\n${$.readText(x)}\nend)()`).join('\n\n'));
44
fs.writeFileSync('module.lua.compiled', code);
55

66
const luaJit = $[process.env['LUA_JIT']];

lua-module/module.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ AIRace = not Sim.isOnlineRace and not Sim.isReplayOnlyMode and Sim.carsCount > 1
1111
---@diagnostic disable-next-line: undefined-field
1212
Config = ac.INIConfig(ac.INIFormat.Extended, _G.__config__ or {}) -- Small Tweaks config is as `__config__` in a compatible form.
1313

14-
ConfigGamepadFX = ac.INIConfig.cspModule(ac.CSPModuleID.GamepadFX)
15-
ConfigGUI = ac.INIConfig.cspModule(ac.CSPModuleID.GUI)
16-
ConfigVRTweaks = ac.INIConfig.cspModule(ac.CSPModuleID.VRTweaks)
14+
ConfigGamepadFX = ac.INIConfig.cspModule(ac.CSPModuleID.GamepadFX) ---@type ac.INIConfig?
15+
ConfigGUI = ac.INIConfig.cspModule(ac.CSPModuleID.GUI) ---@type ac.INIConfig?
16+
ConfigVRTweaks = ac.INIConfig.cspModule(ac.CSPModuleID.VRTweaks) ---@type ac.INIConfig?
1717

1818
ac.onCSPConfigChanged(ac.CSPModuleID.GamepadFX, __reloadScript__)
1919
ac.onCSPConfigChanged(ac.CSPModuleID.GUI, __reloadScript__)
2020
ac.onCSPConfigChanged(ac.CSPModuleID.VRTweaks, __reloadScript__)
2121

22+
if not ConfigGamepadFX:get('BASIC', 'ENABLED', true) then ConfigGamepadFX = nil end
23+
if not ConfigGUI:get('BASIC', 'ENABLED', true) then ConfigGUI = nil end
24+
if not ConfigVRTweaks:get('BASIC', 'ENABLED', true) then ConfigVRTweaks = nil end
25+
2226
if AIRace then
2327
ac.onCSPConfigChanged(ac.CSPModuleID.NewBehaviour, __reloadScript__)
24-
ConfigNewBehaviour = ac.INIConfig.cspModule(ac.CSPModuleID.NewBehaviour)
28+
ConfigNewBehaviour = ac.INIConfig.cspModule(ac.CSPModuleID.NewBehaviour) ---@type ac.INIConfig?
29+
if not ConfigNewBehaviour:get('BASIC', 'ENABLED', true) then ConfigNewBehaviour = nil end
2530
end
2631

2732
local fns = {

lua-module/res/controller-battery.png

-2.67 KB
Loading

lua-module/src/ai_tweaks.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
if not AIRace then
1+
if not AIRace or not ConfigNewBehaviour then
22
return
33
end
44

5+
if Sim.customAISplinesAllowed then
6+
local aiFolder = '%s/ai' % ac.getFolder(ac.FolderID.CurrentTrackLayout)
7+
local altSplines = io.scanDir(aiFolder, 'ext_alt_fast_lane_*.ai')
8+
if #altSplines > 0 then
9+
math.randomseed(math.randomKey())
10+
for i = 0, Sim.carsCount - 1 do
11+
local s = math.random(#altSplines + 1)
12+
if s <= #altSplines then
13+
physics.setAISpline(i, '%s/%s' % {aiFolder, altSplines[s]})
14+
ac.log('AI #%s' % i, '%s/%s' % {aiFolder, altSplines[s]})
15+
end
16+
end
17+
end
18+
end
19+
520
local fixRedlining = ConfigNewBehaviour:get('AI_TWEAKS', 'START_REDUCE_REDLINING', false)
621
local fixTrajectory = ConfigNewBehaviour:get('AI_TWEAKS', 'START_STRAIGHTEN_TRAJECTORY', false)
722
if not fixRedlining and not fixTrajectory then
@@ -10,7 +25,7 @@ end
1025

1126
local carOffsets = {}
1227
local carOffsetsApplied = 0
13-
local throttleLimited = false
28+
local throttleLimited = false
1429

1530
local function randomNoise(seed)
1631
local time = os.preciseClock() + seed * 0.1

lua-module/src/audio_spatial_fix.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
of stereo effect in VR.
44
]]
55

6-
local cfgMode = ConfigVRTweaks:get('EXTRA_TWEAKS', 'AUDIO_STEREO_FIX', 0)
6+
local cfgMode = ConfigVRTweaks and ConfigVRTweaks:get('EXTRA_TWEAKS', 'AUDIO_STEREO_FIX', 0) or 0
77
if cfgMode == 0 or cfgMode == 1 and not Sim.isVRConnected then
88
return
99
end

lua-module/src/background_pause.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pauses AC in background.
33
]]
44

5-
if not Config:get('MISCELLANEOUS', 'PAUSE_IN_BACKGROUND', false) then
5+
if not Config:get('MISCELLANEOUS', 'PAUSE_IN_BACKGROUND', false) or Sim.isShowroomMode then
66
return
77
end
88

lua-module/src/cef.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ local connect = ac.connect{
55
cefState = ac.StructItem.byte(), -- 0: ready, 1: installing, ≥10: errors
66
cefLoop = ac.StructItem.boolean(),
77
noProxyServer = ac.StructItem.boolean(),
8+
useTimer = ac.StructItem.boolean(),
9+
setGPUDevicePriority = ac.StructItem.int8(),
10+
setGPUProcessPriority = ac.StructItem.int8(),
811
targetFPS = ac.StructItem.int32(),
912
}
1013
connect.tabsCount = 0
@@ -25,13 +28,16 @@ local reinstalledOnce = false
2528
local function runWebHostProcess(filename, key, closeCallback)
2629
ac.store('.SmallTweaks.CEFLaunchedOnce', 1)
2730
ac.log('CEF loop: '..tostring(connect.cefLoop and 1 or 0))
31+
32+
if __util.dev then
33+
local devFilename = 'C:/Development/temp-alt/cef-mixer-master/bin/Debug/cefmixer.exe'
34+
if io.fileExists(devFilename) then
35+
filename = devFilename
36+
ac.warn('Using debug cefmixer build')
37+
end
38+
end
2839

29-
-- local devFilename = 'C:/Development/temp-alt/cef-mixer-master/bin/Debug/cefmixer.exe'
30-
-- if io.fileExists(devFilename) then
31-
-- filename = devFilename
32-
-- ac.warn('Using debug cefmixer build')
33-
-- end
34-
40+
local setPriority = Config:get('MISCELLANEOUS', 'SET_CEF_PRIORITY', true)
3541
local startTime = os.time()
3642
local errData = {}
3743
connect.cefState = 0
@@ -54,7 +60,9 @@ local function runWebHostProcess(filename, key, closeCallback)
5460
ACCSPWB_AUTOPLAY = 1,
5561
ACCSPWB_NO_PROXY_SERVER = connect.noProxyServer and 1 or nil,
5662
ACCSPWB_CEF_THREADING = connect.cefLoop and 1 or nil,
57-
ACCSPWB_USE_TIMER = false,
63+
ACCSPWB_USE_TIMER = connect.useTimer and 1 or nil,
64+
ACCSPWB_GPU_PROCESS_PRIORITY = connect.setGPUProcessPriority ~= 0 and connect.setGPUProcessPriority or setPriority and 3 or nil,
65+
ACCSPWB_GPU_PRIORITY = connect.setGPUDevicePriority ~= 0 and connect.setGPUDevicePriority or setPriority and 5 or nil,
5866
ACCSPWB_TARGET_FPS = connect.targetFPS < 1 and 60 or connect.targetFPS,
5967
ACCSPWB_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 AssettoCorsa/1.16.3',
6068
ACCSPWB_DATA_DIRECTORY = ac.getFolder(ac.FolderID.AppDataLocal)..'/ac-cef-layer',
@@ -218,9 +226,11 @@ local function rebuildWebHost()
218226
else
219227
-- 33554432 is a special value for when the actual list is being updated
220228
webHost.mapped.count = 33554432
229+
ac.memoryBarrier()
221230
for i = 1, #webHost.tabs do
222231
webHost.mapped.tabs[i - 1] = webHost.tabs[i].key
223232
end
233+
ac.memoryBarrier()
224234
webHost.mapped.count = #webHost.tabs
225235
end
226236
end
@@ -236,7 +246,10 @@ local function startWebHost()
236246
awaitingWebHostStart = true
237247
connect.cefState = 1
238248
connect.cefLoop = ac.load('.SmallTweaks.CEF.useCEFLoop') == 1
249+
connect.useTimer = ac.load('.SmallTweaks.CEF.useTimer') == 1
239250
connect.noProxyServer = ac.load('.SmallTweaks.CEF.skipProxyServer') == 1
251+
connect.setGPUDevicePriority = ac.load('.SmallTweaks.CEF.setGPUDevicePriority') or 0
252+
connect.setGPUProcessPriority = ac.load('.SmallTweaks.CEF.setGPUProcessPriority') or 0
240253
connect.targetFPS = ac.load('.SmallTweaks.CEF.targetFPS') or 60
241254
if connect.targetFPS < 1 then connect.targetFPS = 60 end
242255

lua-module/src/dualsense_lights.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
so that other apps could override the state.
44
]]
55

6+
if not ConfigGamepadFX then
7+
return
8+
end
9+
610
local function implementation()
711
local settings = ConfigGamepadFX:mapSection('ADVANCED_GAMEPADS', {
812
ENABLED = true,
@@ -265,7 +269,7 @@ local function implementation()
265269
if settings.LOW_BATTERY_WARNING then
266270
Register('drawGameUI', function (dt)
267271
if minBatteryLevel < 0.2 then
268-
ui.drawCarIcon('res/controller-battery.png', minBatteryLevel < 0.05 and rgbm.colors.red
272+
ui.drawCarIcon('?internal\\lua-module\\res\\controller-battery.png', minBatteryLevel < 0.05 and rgbm.colors.red
269273
or minBatteryLevel < 0.1 and rgbm.colors.orange or rgbm.colors.yellow)
270274
end
271275
end)

lua-module/src/extra_buttons.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ __CM_DISCORD_REQUEST_ACCEPT
1010
__CM_DISCORD_REQUEST_DENY
1111
]]
1212

13+
if Config:get('MISCELLANEOUS', 'DISABLE_CM_HOTKEYS', false) then
14+
return
15+
end
16+
1317
local buttons = {} ---@type {button: ac.ControlButton, action: fun(), delayed: {label: string, icon: string, condition: nil|fun(): boolean}?}[]
1418
local buttonsCount = 0
1519
local delayActive = false
@@ -26,6 +30,20 @@ local function addButton(button, action, delayed)
2630
end
2731
end
2832

33+
local msgs = {}
34+
local function log(str)
35+
if #msgs > 50 then
36+
table.remove(msgs, 1)
37+
end
38+
msgs[#msgs + 1] = str
39+
end
40+
41+
if Config:get('MISCELLANEOUS', 'DEBUG_SYSTEM_KEYBINDINGS', false) then
42+
ui.onExclusiveHUD(function (mode)
43+
ui.text(table.concat(msgs, '\n'))
44+
end)
45+
end
46+
2947
for k, v in pairs{
3048
HIDE_APPS = 'Hide Show Apps',
3149
HIDE_DAMAGE = 'Hide Damage',
@@ -51,7 +69,12 @@ for k, v in pairs{
5169
__CM_ENGINE_BRAKE = 'Engine Brake',
5270
__CM_NEXT_APPS_DESKTOP = 'Cycle Virtual Desktop',
5371
} do
54-
ac.ControlButton(k, nil, {remap = true}):onPressed(ac.trySimKeyPressCommand:bind(v))
72+
local btn = ac.ControlButton(k, nil, {remap = true})
73+
log(string.format('System binding: %s, configured: %s, bound to: %s', k, btn:configured(), btn:boundTo()))
74+
btn:onPressed((function (id)
75+
local s = ac.trySimKeyPressCommand(id)
76+
log('System binding pressed: %s, %s' % {id, s})
77+
end):bind(v))
5578
end
5679

5780
ac.ControlButton('__CM_RESET_CAMERA_VR', nil, {remap = true}):onPressed(ac.recenterVR)

lua-module/src/extra_misc_buttons.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ac.ControlButton('__EXT_MUSIC_PLAYPAUSE'):onPressed(function ()
2+
ac.mediaPlayPause()
3+
end)
4+
5+
ac.ControlButton('__EXT_MUSIC_NEXT'):onPressed(function ()
6+
ac.mediaNextTrack()
7+
end)
8+
9+
ac.ControlButton('__EXT_MUSIC_PREVIOUS'):onPressed(function ()
10+
ac.mediaPreviousTrack()
11+
end)
12+

0 commit comments

Comments
 (0)