forked from ac-custom-shaders-patch/acc-lua-internal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
3,170 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1 @@ | ||
# Compiled Lua sources | ||
luac.out | ||
|
||
# luarocks build files | ||
*.src.rock | ||
*.zip | ||
*.tar.gz | ||
|
||
# Object files | ||
*.o | ||
*.os | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
*.def | ||
*.exp | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# acc-lua-internal | ||
Some Lua internals for reference | ||
# CSP Lua Internals | ||
|
||
Some Lua internals for reference. | ||
|
||
- `lua-module`: code used by Small Tweaks module adding all sorts of small things, too small to be kept in C++ code (feel free to use those modules as examples); | ||
- `lua-shared`: shared libraries available by any Lua script running with CSP. To include, use “shared/” prefix, like `require('shared/socket')`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--[[ | ||
Small Tweaks loads and runs this script with apps library. Script itself loads modules | ||
from `src` folder and defines a new `register()` function allowing for those modules | ||
to subscribe for different events. | ||
]] | ||
|
||
---@diagnostic disable-next-line: undefined-field | ||
Config = ac.INIConfig(ac.INIFormat.Extended, _G.__config__ or {}) -- Small Tweaks config is as `__config__` in a compatible form. | ||
|
||
ConfigGUI = ac.INIConfig.cspModule(ac.CSPModuleID.GUI) | ||
ConfigVRTweaks = ac.INIConfig.cspModule(ac.CSPModuleID.VRTweaks) | ||
|
||
local fns = { | ||
core = {}, | ||
gameplay = {}, | ||
simUpdate = {}, | ||
draw3D = {}, | ||
drawUI = {}, | ||
} | ||
|
||
---@param mode 'core'|'gameplay'|'simUpdate'|'draw3D'|'drawUI' | ||
---@param callback fun(dt: number) | ||
function Register(mode, callback) | ||
table.insert(fns[mode], callback) | ||
return function() | ||
table.removeItem(fns[mode], callback) | ||
end | ||
end | ||
|
||
-- Only for this Small Tweaks script: callbacks are optional to avoid a tiny overhead on calling them if | ||
-- there is nothing to draw. | ||
local draw3DCallbackCounter = 0 | ||
local drawUICallbackCounter = 0 | ||
|
||
Toggle = { | ||
Draw3D = function () | ||
local state = false | ||
---@param active boolean | ||
return function (active) | ||
if not active ~= state then return end | ||
state = not state | ||
local newCounter = draw3DCallbackCounter + (state and 1 or -1) | ||
if (newCounter > 0) ~= (draw3DCallbackCounter > 0) then | ||
__setDraw3DActive__(newCounter > 0) ---@diagnostic disable-line: undefined-global | ||
end | ||
draw3DCallbackCounter = newCounter | ||
end | ||
end, | ||
---@type fun(): fun(active: boolean) | ||
DrawUI = function () | ||
local state = false | ||
---@param active boolean | ||
return function (active) | ||
if not active ~= state then return end | ||
state = not state | ||
local newCounter = drawUICallbackCounter + (state and 1 or -1) | ||
if (newCounter > 0) ~= (drawUICallbackCounter > 0) then | ||
__setDrawUIActive__(newCounter > 0) ---@diagnostic disable-line: undefined-global | ||
end | ||
drawUICallbackCounter = newCounter | ||
end | ||
end | ||
} | ||
|
||
io.scanDir(__dirname..'/src', '*.lua', function (fileName) | ||
require('src/'..fileName:sub(1, #fileName - 4)) | ||
end) | ||
|
||
local sim = ac.getSim() | ||
|
||
function script.update(dt) | ||
if not sim.isPaused and not sim.isInMainMenu then | ||
for i = 1, #fns.gameplay do fns.gameplay[i](dt) end | ||
end | ||
for i = 1, #fns.core do fns.core[i](dt) end | ||
end | ||
|
||
if #fns.simUpdate > 0 then | ||
function script.simUpdate(dt) | ||
for i = 1, #fns.simUpdate do fns.simUpdate[i](dt) end | ||
end | ||
end | ||
|
||
if #fns.draw3D > 0 then | ||
function script.draw3D(dt) | ||
for i = 1, #fns.draw3D do fns.draw3D[i](dt) end | ||
end | ||
end | ||
|
||
if #fns.drawUI > 0 then | ||
function script.drawUI(dt) | ||
for i = 1, #fns.drawUI do fns.drawUI[i](dt) end | ||
end | ||
end | ||
|
||
--[[ | ||
local handbrake = ac.AudioEvent('event:/extension_common/turn_signal_ext') | ||
handbrake.cameraInteriorMultiplier = 1 | ||
handbrake.volume = 10 | ||
function UpdateAudio() | ||
local car = ac.getCar(0) | ||
if car.handbrake > 0 and not handbrake:isPlaying() then | ||
handbrake:start() | ||
end | ||
handbrake:setPosition(car.position, car.up, car.look, car.velocity) | ||
handbrake:setParam('state', car.handbrake) | ||
end | ||
]] | ||
|
||
-- local cs = ac.getCar(0).currentSector | ||
-- local cs = ac.getCar(0).currentSplits[0] | ||
-- local cs = ac.getCar(0).lastSplits[0] | ||
-- local cs = ac.getCar(0).bestSplits[0] | ||
-- local cs = ac.getCar(0).bestLapSplits[0] | ||
-- local cs = ac.getSim().lapSplits | ||
|
||
-- ac.getSession(0). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--[[ | ||
A small script running during loading before most of AC is ready, with limited API. | ||
Used for patching some Python apps, adding missing data and such. | ||
]] | ||
|
||
local function proTyresSync(carIndex, proTyresPath) | ||
if io.dirExists(proTyresPath) then | ||
ac.debug('found dir', proTyresPath) | ||
|
||
local tyresIni = ac.INIConfig.carData(carIndex, 'tyres.ini') | ||
if #tyresIni:get('FRONT', 'NAME', '') ~= 0 then | ||
local srcCarDir = ac.getFolder(ac.FolderID.ContentCars)..'/'..ac.getCarID(carIndex)..'/data' | ||
local dstCarDir = proTyresPath..'/'..ac.getCarID(carIndex) | ||
io.createDir(dstCarDir) | ||
|
||
local filesToCopy = {} | ||
for i = 0, 100 do | ||
local wf = tyresIni:get(i == 0 and 'FRONT' or 'FRONT_'..tostring(i), 'WEAR_CURVE', '') | ||
local wr = tyresIni:get(i == 0 and 'REAR' or 'REAR_'..tostring(i), 'WEAR_CURVE', '') | ||
local sf = tyresIni:get(i == 0 and 'THERMAL_FRONT' or 'THERMAL_FRONT_'..tostring(i), 'PERFORMANCE_CURVE', '') | ||
local sr = tyresIni:get(i == 0 and 'THERMAL_REAR' or 'THERMAL_REAR_'..tostring(i), 'PERFORMANCE_CURVE', '') | ||
if #sf == 0 and #sr == 0 and #wf == 0 and #wr == 0 then break end | ||
table.insert(filesToCopy, wf) | ||
table.insert(filesToCopy, wr) | ||
table.insert(filesToCopy, sf) | ||
table.insert(filesToCopy, sr) | ||
end | ||
|
||
ac.debug('filesToCopy', stringify(filesToCopy)) | ||
if #filesToCopy > 0 then | ||
for _, name in ipairs(table.distinct(filesToCopy)) do | ||
if #name > 0 then | ||
local data = ac.readDataFile(srcCarDir..'/'..name) | ||
if #data > 0 then io.save(dstCarDir..'/'..name, data) end | ||
end | ||
end | ||
tyresIni:save(dstCarDir..'/tyres.ini') | ||
end | ||
end | ||
end | ||
end | ||
|
||
proTyresSync(0, ac.getFolder(ac.FolderID.Root)..'/apps/python/proTyres/cars') | ||
proTyresSync(0, ac.getFolder(ac.FolderID.Root)..'/apps/python/proTyres/cars_extra') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--[[ | ||
Adds hotkeys to quickly alter audio level. Might be helpful for something like quickly lowering volume for a bit with voice chat. | ||
]] | ||
|
||
local btn0 = ac.ControlButton('__EXT_AUDIO_BTN_0', nil, nil, 0.2) | ||
local btn1 = ac.ControlButton('__EXT_AUDIO_BTN_1', nil, nil, 0.2) | ||
if not btn0:configured() and not btn1:configured() then | ||
return | ||
end | ||
|
||
local cfg = Config:mapSection('AUDIO_VOLUME_BUTTONS', { | ||
MODE = 'SET_RESTORE', | ||
LEVEL_0 = 0, | ||
LEVEL_1 = 0, | ||
STEP = 0.05, | ||
TRANSITION_LAG = 0.9, | ||
SHOW_MESSAGE = true, | ||
}) | ||
|
||
local audioTarget = 1 | ||
local audioSmooth = 1 | ||
local flag0 = false | ||
local flag1 = false | ||
|
||
local modes = { | ||
function () -- SET_RESTORE, default mode | ||
if btn0:down() then audioTarget = cfg.LEVEL_0 end | ||
if btn1:down() then audioTarget = 1 end | ||
end, | ||
HOLD_TO_ALTER = function () | ||
audioTarget = 1 | ||
if btn0:down() then audioTarget = cfg.LEVEL_0 end | ||
if btn1:down() then audioTarget = cfg.LEVEL_1 end | ||
end, | ||
PRESS_TO_ALTER = function () | ||
if btn0:pressed() then | ||
flag1 = false | ||
flag0 = not flag0 | ||
end | ||
if btn1:pressed() then | ||
flag0 = false | ||
flag1 = not flag1 | ||
end | ||
audioTarget = flag0 and cfg.LEVEL_0 or flag1 and cfg.LEVEL_1 or 1 | ||
end, | ||
UP_DOWN = function () | ||
if btn0:pressed() then | ||
audioTarget = audioTarget + cfg.STEP | ||
end | ||
if btn1:pressed() then | ||
audioTarget = audioTarget - cfg.STEP | ||
end | ||
end | ||
} | ||
|
||
local modeFn = modes[cfg.MODE] or modes[1] | ||
|
||
local function audioCallback() | ||
local previousTarget = audioTarget | ||
modeFn() | ||
audioTarget = math.saturateN(audioTarget) | ||
if previousTarget ~= audioTarget and cfg.SHOW_MESSAGE then | ||
ac.setSystemMessage('Volume Level', string.format('Volume changed to %.0f%%', audioTarget * 100)) | ||
end | ||
|
||
audioSmooth = math.applyLag(audioSmooth, audioTarget, cfg.TRANSITION_LAG, ac.getDeltaT()) | ||
return audioSmooth | ||
end | ||
|
||
ac.onAudioVolumeCalculation(audioCallback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--[[ | ||
Hides standing spectators. | ||
]]-- | ||
|
||
if Config:get('MISCELLANEOUS', 'HIDE_STANDING_SPECTATORS', false) then | ||
ac.findAny('texture:people_stand.dds'):setAttribute('SmallTweaks.HiddenSpectators', true):setVisible(false) | ||
else | ||
ac.findAny('hasAttribute:SmallTweaks.HiddenSpectators'):setVisible(true) | ||
end |
Oops, something went wrong.