Skip to content

Commit

Permalink
v1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
adam10603 authored Feb 23, 2024
2 parents 4b2f270 + a970568 commit dbb3ca1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local uiData = ac.connect{
graphSelection = ac.StructItem.int32(), -- 1 = none, 2 = static, 3 = live
keyboardMode = ac.StructItem.int32(), -- 0 = disabled, 1 = enabled, 2 = enabled + brake assist, 3 = enabled + throttle and brake assist
autoClutch = ac.StructItem.boolean(),
autoShifting = ac.StructItem.boolean(),
autoShiftingMode = ac.StructItem.int32(), -- 0 = default, 1 = manual, 2 = automatic
autoShiftingCruise = ac.StructItem.boolean(),
autoShiftingDownBias = ac.StructItem.double(),
triggerFeedbackL = ac.StructItem.double(),
Expand Down Expand Up @@ -57,12 +57,12 @@ local tooltips = {
presets = "This is where you can save or load presets!",
calibration = "Performs a quick steering calibration, just in case the assist isn't working correctly.\nYou must stop the car before doing this!",
graphs = "Shows graphs to visualize what the steering assist is doing.\nThey can either be static or updated with live values.",
assistEnabled = "Enables or disables the assist.\nIf unchecked, AC's built-in input processing is used without alterations.",
assistEnabled = "Enables or disables the entire assist.\nIf unchecked, AC's built-in input processing is used without alterations.",
useFilter = "Provides a single slider that will adjust most settings automatically for you.",
autoClutch = "Automatically controls the clutch if the engine would otherwise stall, or when setting off from a standstill.",
autoShifting = "Automatically shifts gears using a more intelligent algorithm than the default one.\nOnly works if 'Automatic shifting' is DISABLED in the game's assist settings!",
autoShiftingMode = "Default = AC's own gear shifting, no change.\n\nManual = custom rev-matching and clutch logic, but manual shifting only.\n\nAutomatic = custom rev-matching and clutch logic, but with automatic gear shifts. You can still shift manually to temporary override a gear though.\n\nIMPORTANT: Options other than 'Default' only work properly if 'Automatic shifting' is DISABLED in AC's assist settings!",
autoShiftingCruise = "Allows the automatic shifting to go between cruise mode and performance mode depending on your throttle input.\nUseful if you want to do both performance driving and casual cruising, but you can disable it for racing (especially for rolling starts).",
autoShiftingDownBias = "Higher = more aggressive downshifting.\nFor example at 90% the car will downshift almost right away when you brake for a turn, however, this might leave you very close to the top of a gear when going back on the throttle again.",
autoShiftingDownBias = "Higher = more aggressive downshifting when using automatic mode.\nFor example at 90% the car will downshift almost immediately when you brake for a turn, however, this might leave you very close to the top of a gear when going back on the throttle again.",
triggerFeedbackL = "Vibration feedback on the left trigger when braking.\nOnly works with compatible Xbox controllers!",
triggerFeedbackR = "Vibration feedback on the right trigger when accelerating.\nOnly works with compatible Xbox controllers!",
triggerFeedbackAlwaysOn = "Allows trigger vibrations even when TCS or ABS are enabled.",
Expand All @@ -71,11 +71,11 @@ local tooltips = {
steeringRate = "How fast the steering is in general.",
rateIncreaseWithSpeed = "How much slower or faster the steering gets as you speed up.",
selfSteerResponse = "How aggressive the self-steer force will fight to keep the car straight.\nLow = looser feel and easier to oversteer, high = more assistance to prevent oversteer and keep the car stable.",
dampingStrength = "Counteracts the car's angular momentum which prevents the self-steer force from overcorrecting.\nHigher = more stability.\nHigher 'Response' and 'Max angle' settings require more damping to stop the car from wobbling.\nThe damping force is not limited by the 'Max angle' setting.",
dampingStrength = "This is an advanced setting, and in most cases it's best to leave it at a similar value to 'Response'.\n\nDamping adds some additional self-steer that counteracts the car's yaw rotation which results in more stability.\nHigher 'Response' and 'Max angle' settings require more damping to stop the car from wobbling, especially at high speed.\nThe damping force is not limited by the 'Max angle' setting.",
maxSelfSteerAngle = "Caps the self-steer force to a certain steering angle.\nBasically this limits how big of a slide the self-steer can help to recover from.",
targetSlip = "Changes the slip angle that the front wheels will target.\nHigher = more steering, lower = less steering.\nMost cars feel best around 90-95%, but you can set it higher if you want to force the car to go over the limit, or to generate more heat in the front tires.\nBeware that the slip angle achieved in reality might be slightly different from the intended amount on some cars.",
countersteerResponse = "High = more effective manual countersteering, but also easier to overcorrect a slide.",
maxDynamicLimitReduction = "How much the steering angle is allowed to reduce when the car oversteers while you turn inward, in order to maintain front grip.\nLow = more raw and more prone to front wheel slippage.\nHigh = more assistance to keep front grip in a turn.\nFor the best grip it should be at least as high as the travel angle in a typical turn, but high values can feel restricting.\nIf you like to throw the car into a turn more aggressively with less assistance, set it lower.\nYou might want to use a higher setting for loose-handling cars."
maxDynamicLimitReduction = "How much the steering angle is allowed to reduce when the car oversteers while you turn inward, in order to maintain front grip.\nLow = more raw and more prone to front wheel slippage.\nHigh = more assistance to keep front grip in a turn.\nFor the best grip it should be at least as high as the travel angle when cornering, but high values can feel restricting.\nIf you like to throw the car into a turn more aggressively with less assistance, set it lower.\nYou might want to use a higher setting for loose-handling cars."
}

local sectionPadding = 10
Expand Down Expand Up @@ -430,7 +430,7 @@ local function factoryReset()
-- // TODO use the event instead of setting these by hand here
uiData.assistEnabled = true
uiData.autoClutch = false
uiData.autoShifting = false
uiData.autoShiftingMode = 0
uiData.autoShiftingCruise = true
uiData.autoShiftingDownBias = 0.7
uiData.triggerFeedbackL = 0.0
Expand Down Expand Up @@ -541,8 +541,11 @@ end

function script.windowMain(dt)
if not uiData._appCanRun then

if not lib.clampEased then
if ac.getPatchVersionCode() < 2651 then
ui.pushStyleColor(ui.StyleColor.Text, rgbm(1.0, 0.0, 0.0, 1.0))
ui.textWrapped("Update CSP to 0.2.0 or newer!\nOlder versions are not supported anymore.")
ui.popStyleColor(1)
elseif not lib.clampEased then
ui.textWrapped("Advanced Gamepad Assist is not installed!")
else
ui.textWrapped("Advanced Gamepad Assist is currently not enabled!")
Expand Down Expand Up @@ -626,9 +629,9 @@ function script.windowSettings(dt)

showDummyLine(0.25)

showCheckbox("autoShifting", "Automatic shifting", false, false, 0)
showCheckbox("autoShiftingCruise", "Auto-switch into cruise mode", false, not uiData.autoShifting, 20)
showConfigSlider("autoShiftingDownBias", "Downshift bias", "%.f%%", 0.0, 90.0, 100.0, false, 200.0, 20, not uiData.autoShifting)
uiData.autoShiftingMode = showCompactDropdown("Shifting mode", "autoShiftingMode", {"Default", "Manual", "Automatic"}, uiData.autoShiftingMode + 1, 0) - 1;
showCheckbox("autoShiftingCruise", "Auto-switch into cruise mode", false, uiData.autoShiftingMode < 2, 20)
showConfigSlider("autoShiftingDownBias", "Downshift bias", "%.f%%", 0.0, 90.0, 100.0, false, 200.0, 20, uiData.autoShiftingMode < 2)

showDummyLine(0.25)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[ABOUT]
NAME = Advanced Gamepad Assist Config
AUTHOR = adam10603
VERSION = 1.4.1
VERSION = 1.4.2
DESCRIPTION = Settings for the Advanced Gamepad Assist mod.

[CORE]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function M:new(vehicle)
end

idleRPM = engineINI:get("ENGINE_DATA", "MINIMUM", 900)
maxRPM = math.min(engineINI:get("ENGINE_DATA", "LIMITER", 99999), engineINI:get("DAMAGE", "RPM_THRESHOLD", 99999))
maxRPM = math.min(((vehicle.rpmLimiter and vehicle.rpmLimiter ~= 0) and vehicle.rpmLimiter or engineINI:get("ENGINE_DATA", "LIMITER", 99999)), engineINI:get("DAMAGE", "RPM_THRESHOLD", 99999))

if maxRPM == 99999 then
maxRPM = ((vehicle.rpmLimiter > 0) and vehicle.rpmLimiter or 7000)
Expand Down Expand Up @@ -195,7 +195,7 @@ function M:calcShiftingTable(minNormRPM, maxNormRPM)

if self.vehicle.mgukDeliveryCount == 0 then
local bestArea = 0
local areaSkew = math.lerp(0.9, 1.4, (gear - 1) / (self.vehicle.gearCount - 2))
local areaSkew = math.lerp(0.95, 1.15, (gear - 1) / (self.vehicle.gearCount - 2)) -- shifts the bias of the power integral higher as the gear number increases
local nextOverCurrentRatio = self:getGearRatio(gear + 1) / self:getGearRatio(gear)
for i = 0, 300, 1 do
local upshiftRPM = self:getAbsoluteRPM(i / 300.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
if ac.getPatchVersionCode() < 2651 then
ac.onCarJumped(car.index, function ()
ac.setMessage("Advanced Gamepad Assist", "Error - Only CSP 0.2.0 and higher are supported!")
end)
return
end

if car.isAIControlled then return end

local lib = require "AGALib"
Expand All @@ -16,10 +23,10 @@ local uiData = ac.connect{
_rearNdSlip = ac.StructItem.double(),
_limitReduction = ac.StructItem.double(),
assistEnabled = ac.StructItem.boolean(),
graphSelection = ac.StructItem.int32(),
graphSelection = ac.StructItem.int32(), -- 1 = none, 2 = static, 3 = live
keyboardMode = ac.StructItem.int32(), -- 0 = disabled, 1 = enabled, 2 = enabled + brake assist, 3 = enabled + throttle and brake assist
autoClutch = ac.StructItem.boolean(),
autoShifting = ac.StructItem.boolean(),
autoShiftingMode = ac.StructItem.int32(), -- 0 = default, 1 = manual, 2 = automatic
autoShiftingCruise = ac.StructItem.boolean(),
autoShiftingDownBias = ac.StructItem.double(),
triggerFeedbackL = ac.StructItem.double(),
Expand All @@ -43,7 +50,7 @@ local savedCfg = ac.storage({
graphSelection = 1,
keyboardMode = 0,
autoClutch = false,
autoShifting = false,
autoShiftingMode = 0,
autoShiftingCruise = true,
autoShiftingDownBias = 0.7,
triggerFeedbackL = 0.0,
Expand All @@ -68,7 +75,7 @@ uiData.keyboardMode = savedCfg.keyboardMode
uiData.graphSelection = savedCfg.graphSelection
uiData.useFilter = savedCfg.useFilter
uiData.autoClutch = savedCfg.autoClutch
uiData.autoShifting = savedCfg.autoShifting
uiData.autoShiftingMode = savedCfg.autoShiftingMode
uiData.autoShiftingCruise = savedCfg.autoShiftingCruise
uiData.autoShiftingDownBias = savedCfg.autoShiftingDownBias
uiData.triggerFeedbackL = savedCfg.triggerFeedbackL
Expand Down Expand Up @@ -136,7 +143,7 @@ local steeringCurveSamples = {}
local steeringExponent = 0.95

-- Updates the config values based on the settings in the UI app
local function updateConfig(inputData)
local function updateConfig()
if uiData.useFilter then
uiData.rateIncreaseWithSpeed = (1.0 - uiData.filterSetting) * 0.2
uiData.selfSteerResponse = uiData.filterSetting * 0.5 + 0.12
Expand All @@ -152,7 +159,7 @@ local function updateConfig(inputData)
savedCfg.graphSelection = uiData.graphSelection
savedCfg.useFilter = uiData.useFilter
savedCfg.autoClutch = uiData.autoClutch
savedCfg.autoShifting = uiData.autoShifting
savedCfg.autoShiftingMode = uiData.autoShiftingMode
savedCfg.autoShiftingCruise = uiData.autoShiftingCruise
savedCfg.autoShiftingDownBias = uiData.autoShiftingDownBias
savedCfg.triggerFeedbackL = uiData.triggerFeedbackL
Expand Down Expand Up @@ -418,14 +425,14 @@ local function calcSteeringRateMult(fwdVelClamped, steeringLockDeg)
end

-- Returns the corrected sterering angle with the steering limit and self-steer force applied, normalized to the car's steering lock
local function calcCorrectedSteering(vData, targetFrontSlipDeg, initialSteering, absInitialSteering, steeringRateMult, dt)
local function calcCorrectedSteering(vData, targetFrontSlipDeg, initialSteering, absInitialSteering, dt)
-- Calculating baseline data

local fAxleHVelAngle = lib.numberGuard(math.deg(math.atan2(vData.fAxleLocalVel.x, math.abs(vData.fAxleLocalVel.z)))) -- Angle of the weighted average front wheel velocity on the local horizontal plane, corrected for reverse (deg)
local rAxleHVelAngle = lib.numberGuard(math.deg(math.atan2(vData.rAxleLocalVel.x, math.abs(vData.rAxleLocalVel.z)))) -- Angle of the rear axle velocity on the local horizontal plane, corrected for reverse (deg)
local localVelHAngle = lib.numberGuard(math.deg(math.atan2(vData.localVel.x, math.abs(vData.localVel.z)))) -- Angle of the car's velocity on the local horizontal plane, corrected for reverse (deg)
local inputSign = math.sign(initialSteering) -- Sign of the initial steering input by the player (after smoothing)
local lowSpeedFade = lib.clamp01(math.max(0.0, vData.localHVelLen - 0.5) / (30.0 / 3.6)) -- Used for fading some effects at low speed
local lowSpeedFade = lib.clamp01(math.max(0.0, vData.localHVelLen - 0.5) / (35.0 / 3.6)) -- Used for fading some effects at low speed
local midSpeedFade = lib.clamp01(math.max(0.0, vData.localHVelLen - 0.5) / (60.0 / 3.6)) -- Used for fading some effects at medium speed

-- Self-steer force
Expand All @@ -434,9 +441,10 @@ local function calcCorrectedSteering(vData, targetFrontSlipDeg, initialSteering,
local correctionBase = lib.signedPow(math.clamp(-rAxleHVelAngle / 72.0, -1, 1), correctionExponent) * 72.0 / vData.steeringLockDeg -- Base self-steer force
local selfSteerCap = lib.clamp01(uiData.maxSelfSteerAngle / vData.steeringLockDeg) -- Max self-steer amount
local selfSteerStrength = lowSpeedFade * vData.frontGrounded -- Multiplier that can fade the self-steer force in and out
local dampingForce = vData.localAngularVel.y * uiData.dampingStrength * 0.1275 -- * 0.2125 * 0.6
local dampingForce = vData.localAngularVel.y * uiData.dampingStrength * 0.15 * (30.0 / vData.steeringLockDeg) -- 0.2125 * 0.6 = 0.1275 -- 0.159375
local selfSteerCapT = math.min(1.0, 4.0 / (2.0 * selfSteerCap)) -- Easing window
local selfSteerForce = math.clamp(selfSteerSmoother:get(lib.clampEased(correctionBase, -selfSteerCap, selfSteerCap, selfSteerCapT) + dampingForce, dt), -2.0, 2.0) * selfSteerStrength
local rawSelfSteer = lib.clampEased(correctionBase, -selfSteerCap, selfSteerCap, selfSteerCapT) + dampingForce
local selfSteerForce = math.clamp(selfSteerSmoother:get(rawSelfSteer, dt), -2.0, 2.0) * selfSteerStrength
uiData._selfSteerStrength = selfSteerStrength * (1.0 - absInitialSteering)

-- Steering limit
Expand Down Expand Up @@ -582,17 +590,9 @@ end

local logTimer = 0.0

local compatibilityErrorShowed = false

function script.update(dt)
if car.isAIControlled or not car.physicsAvailable then return end

if not compatibilityErrorShowed and ac.getPatchVersionCode() < 2651 then
ac.setMessage("Advanced Gamepad Assist", "Error - Only CSP 0.2.0 and higher are supported!")
compatibilityErrorShowed = true
return
end

uiData._appCanRun = true

local vData = getVehicleData(dt, not uiData.assistEnabled) -- Vehicle data such as velocities, slip angles etc.
Expand All @@ -609,7 +609,7 @@ function script.update(dt)
calibrationTries = 0
end

updateConfig(vData.inputData) -- Updates the config values based on the settings in the UI app
updateConfig() -- Updates the config values based on the settings in the UI app

local desiredSteering = 0 -- The desired steering angle normalized to the car's steering lock
local assistFadeIn = 0 -- Controls how the steering processing is faded in and out at low speeds
Expand All @@ -621,7 +621,7 @@ function script.update(dt)
vData.perfData:updateTargetFrontSlipAngle(vData, initialSteering, dt)

assistFadeIn = math.lerpInvSat(vData.fAxleHVelLen, 2.0, 6.0)
local processedSteering = calcCorrectedSteering(vData, vData.perfData:getTargetFrontSlipAngle(), initialSteering, absInitialSteering, steeringRateMult, dt)
local processedSteering = calcCorrectedSteering(vData, vData.perfData:getTargetFrontSlipAngle(), initialSteering, absInitialSteering, dt)

desiredSteering = math.lerp(initialSteering, processedSteering, assistFadeIn)
vData.inputData.steer = sanitizeSteeringInput(normalizedSteeringToInput(desiredSteering, vData.steeringCurveExponent)) -- Final steering input sent to the car
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ M.update = function(vData, uiData, absInitialSteering, dt)
end
end

if not uiData.autoClutch and not uiData.autoShifting then return end -- Quit here if none of these are enabled
if not uiData.autoClutch and uiData.autoShiftingMode == 0 then return end -- Quit here if none of these are enabled

-- ================================ Values used by both the auto clutch and auto shifting

Expand Down Expand Up @@ -375,28 +375,28 @@ M.update = function(vData, uiData, absInitialSteering, dt)

-- ================================ Auto shifting

if vData.vehicle.gearCount < 2 or not uiData.autoShifting then
if uiData.autoShiftingMode == 0 or vData.vehicle.gearCount < 2 then
requestedGear = vData.vehicle.gear
return
end

if not vData.perfData.baseTorqueCurve then
if not errorShown1 then
ac.setMessage("Advanced Gamepad Assist", "Error reading engine data. Automatic shifting will be disabled.")
ac.setMessage("Advanced Gamepad Assist", "Error reading engine data. Custom shifting modes will be disabled.")
errorShown1 = true
end
return
end

if vData.vehicle.autoShift then
if not errorShown3 then
ac.setMessage("Advanced Gamepad Assist", "Disable AC's automatic shifting for the custom auto-shifting to work!")
ac.setMessage("Advanced Gamepad Assist", "Disable AC's automatic shifting for the custom shifting modes to work!")
errorShown3 = true
end
return
end

if vData.vehicle.mgukDeliveryCount > 0 then
if vData.vehicle.mgukDeliveryCount > 0 and uiData.autoShiftingMode == 2 then
if not errorShown4 then
ac.setMessage("Advanced Gamepad Assist", "Automatic shifting will have reduced accuracy with this car.")
errorShown4 = true
Expand Down Expand Up @@ -449,7 +449,7 @@ M.update = function(vData, uiData, absInitialSteering, dt)
tSinceHighGearBurnoutStopped = 0.0
end

if not gearOverride then
if uiData.autoShiftingMode == 2 and not gearOverride then

local canShiftUp = false
if vData.vehicle.gear > 0 and vData.vehicle.gear < vData.vehicle.gearCount then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[ABOUT]
NAME = Advanced Gamepad Assist
AUTHOR = adam10603
VERSION = 1.4.1
VERSION = 1.4.2
DESCRIPTION = Provides steering input assistance for gamepad and keyboard, highly customizable through a UI app.
Loading

0 comments on commit dbb3ca1

Please sign in to comment.