Skip to content

Commit 9e41741

Browse files
committed
feat(vehicle): improve "keep wheels turned"
- Keep wheels turned no longer teleports you outside the vehicle.
1 parent dfcc933 commit 9e41741

16 files changed

Lines changed: 71 additions & 33 deletions

File tree

SSV2/includes/classes/CEntity.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function CEntity:IsValid()
6363
return self.m_ptr and self.m_ptr:is_valid()
6464
end
6565

66+
---@return uint64_t
67+
function CEntity:GetAddress()
68+
return self.m_ptr:get_address()
69+
end
70+
6671
---@return eModelType
6772
function CEntity:GetModelType()
6873
if not self:IsValid() then

SSV2/includes/classes/CVehicle.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ local SubHandlingCtorMap <const> = {
4848
---@field public m_current_gear pointer<int16_t>
4949
---@field public m_top_gear pointer<int8_t>
5050
---@field public m_engine_health pointer<float>
51+
---@field public m_steering_input pointer<float> // 0xD4 name might not correctly reflect what this actually is but this seems to store controller input (value is between 0.99 (left) .. -0.99 (right))
52+
---@field public m_current_steering pointer<float> 0xDC // actual wheel steer. Wr'll use it to rewrite last known wheel steer after exiting a vehicle in IV-Style Exit so we'll no longer need to teleport outside or patch CTaskVehicleExit
5153
---@field public m_is_targetable pointer<byte> `bool`
5254
---@field public m_door_lock_status pointer<uint32_t>
5355
---@field public m_model_info_flags pointer<uint32_t>
@@ -106,11 +108,13 @@ function CVehicle:init(vehicle)
106108
instance.m_deform_god = ptr:add(0x096C)
107109
instance.m_is_targetable = ptr:add(0x0AEE)
108110
instance.m_door_lock_status = ptr:add(0x13D0)
109-
instance.m_water_damage = ptr:add(0xD8)
111+
instance.m_water_damage = ptr:add(0x00D8)
110112
instance.m_next_gear = ptr:add(0x0880)
111113
instance.m_current_gear = ptr:add(0x0882)
112114
instance.m_top_gear = ptr:add(0x0886)
113115
instance.m_engine_health = ptr:add(0x0910)
116+
instance.m_steering_input = ptr:add(0x09D4)
117+
instance.m_current_steering = ptr:add(0x09DC)
114118
instance.m_model_info_flags = instance.m_model_info:add(0x057C)
115119
instance.m_mass = instance.m_handling_data:add(0x000C)
116120
instance.m_initial_drag_coeff = instance.m_handling_data:add(0x0010)
@@ -133,9 +137,9 @@ function CVehicle:init(vehicle)
133137
instance.m_damage_flags = instance.m_handling_data:add(0x012C)
134138
instance.m_wheel_scale = instance.m_model_info:add(0x048C)
135139
instance.m_wheel_scale_rear = instance.m_model_info:add(0x0490)
136-
instance.m_wheels = atArray(ptr:add(0xC30), CWheel)
137-
instance.m_num_wheels = ptr:add(0xC38):get_int()
138-
instance.m_ride_height = ptr:add(0xC30):deref():add(0x07C)
140+
instance.m_wheels = atArray(ptr:add(0x0C30), CWheel)
141+
instance.m_num_wheels = ptr:add(0x0C38):get_int()
142+
instance.m_ride_height = ptr:add(0x0C30):deref():add(0x07C)
139143

140144
return instance
141145
end

SSV2/includes/classes/CWheel.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ Enums.eWheelConfigFlags = {
110110
---@field m_unk_u8 pointer<uint8_t> // 0x20A
111111
---@field m_tyre_is_burst pointer<bool> // 0x20B
112112
---@field m_unk_byte pointer<byte> // 0x20C
113-
---@field m_has_hydraulics pointer<bool> // 0x20D // true for cars with DUNK mod
113+
---@field m_has_hydraulics pointer<bool> // 0x20D // true for cars with DONK mod
114114
---@overload fun(addr: pointer): CWheel|nil
115-
local CWheel = { m_size = 0x1FC }
115+
local CWheel = { m_size = 0x20E }
116116
CWheel.__index = CWheel
117117
CWheel.__type = "CWheel"
118118
setmetatable(CWheel, {

SSV2/includes/features/vehicle/iv_style_exit.lua

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ local FeatureBase = require("includes.modules.FeatureBase")
66
---@field private m_entity PlayerVehicle
77
---@field private m_triggered boolean
88
---@field private m_timer Time.Timer
9+
---@field private m_steering_timer Time.Timer
10+
---@field private m_pending_steering boolean
11+
---@field private m_last_steer_angle float
912
local IVStyleExit = setmetatable({}, FeatureBase)
1013
IVStyleExit.__index = IVStyleExit
1114

@@ -17,9 +20,13 @@ function IVStyleExit.new(pv)
1720
end
1821

1922
function IVStyleExit:Init()
20-
self.m_triggered = false
21-
self.m_timer = Timer.new(1000)
23+
self.m_triggered = false
24+
self.m_pending_steering = false
25+
self.m_last_steer_angle = 0.0
26+
self.m_steering_timer = Timer.new(200)
27+
self.m_timer = Timer.new(1000)
2228
self.m_timer:pause()
29+
self.m_steering_timer:pause()
2330
end
2431

2532
function IVStyleExit:ShouldRun()
@@ -39,39 +46,51 @@ function IVStyleExit:Cleanup()
3946
self.m_timer:pause()
4047
end
4148

49+
function IVStyleExit:ShouldReapplySteering()
50+
local fVal = math.abs(self.m_last_steer_angle)
51+
return fVal ~= 0 and fVal < 1 and fVal > 0.001
52+
end
53+
4254
---@param keepEngineOn boolean
4355
function IVStyleExit:LeaveVehicle(keepEngineOn)
4456
local vehHandle = self.m_entity:GetHandle()
45-
local leftPressed = PAD.IS_CONTROL_PRESSED(0, 34)
46-
local rightPressed = PAD.IS_CONTROL_PRESSED(0, 35)
47-
local enabled = GVars.features.vehicle.no_wheel_recenter and self.m_entity:IsCar() and (leftPressed or rightPressed)
57+
local enabled = GVars.features.vehicle.no_wheel_recenter and self.m_entity:IsCar()
4858
Self:SetConfigFlag(Enums.ePedConfigFlags.LeaveEngineOnWhenExitingVehicles, keepEngineOn)
4959

50-
if (enabled and not keepEngineOn) then
51-
VEHICLE.SET_VEHICLE_ENGINE_ON(self.m_entity:GetHandle(), false, true, false)
60+
if (enabled) then
61+
self.m_last_steer_angle = self.m_entity:Resolve().m_current_steering:get_float()
62+
if (not keepEngineOn) then
63+
VEHICLE.SET_VEHICLE_ENGINE_ON(self.m_entity:GetHandle(), false, true, false)
64+
end
65+
end
66+
67+
TASK.TASK_LEAVE_VEHICLE(Self:GetHandle(), vehHandle, 0)
68+
69+
if (self:ShouldReapplySteering()) then
70+
self.m_pending_steering = true
71+
self.m_steering_timer:reset()
72+
self.m_steering_timer:resume()
5273
end
53-
TASK.TASK_LEAVE_VEHICLE(Self:GetHandle(), vehHandle, enabled and 16 or 0) -- 16=tp outside. goofy because I don't feel like patching memory 🤷‍♂️
74+
5475
self:Cleanup()
5576
end
5677

5778
function IVStyleExit:Update()
5879
PAD.DISABLE_CONTROL_ACTION(0, 75, true)
5980

60-
local exitPressed = PAD.IS_DISABLED_CONTROL_PRESSED(0, 75)
61-
if (exitPressed) then
81+
if (PAD.IS_DISABLED_CONTROL_PRESSED(0, 75)) then
6282
if (self.m_entity:GetSpeed() > 15) then
6383
TASK.TASK_LEAVE_VEHICLE(Self:GetHandle(), self.m_entity:GetHandle(), 4160)
6484
self:Cleanup()
6585
return
6686
end
6787

68-
if (not GVars.features.vehicle.iv_exit) then
88+
if (not GVars.features.vehicle.iv_exit and not self.m_triggered) then
6989
self:LeaveVehicle(false)
70-
return
7190
end
7291

73-
self.m_timer:resume()
7492
self.m_triggered = true
93+
self.m_timer:resume()
7594
end
7695

7796
if (self.m_triggered) then
@@ -80,8 +99,19 @@ function IVStyleExit:Update()
8099
elseif (PAD.IS_DISABLED_CONTROL_PRESSED(0, 75) and self.m_timer:is_done()) then
81100
self:LeaveVehicle(false)
82101
end
102+
end
103+
104+
if (self.m_pending_steering) then
105+
local veh = self.m_entity
106+
if (veh and veh:IsValid()) then
107+
local pSteering = veh:Resolve().m_current_steering
108+
pSteering:set_float(self.m_last_steer_angle)
109+
end
83110

84-
return
111+
if (self.m_steering_timer:is_done()) then
112+
self.m_pending_steering = false
113+
self.m_last_steer_angle = 0.0
114+
end
85115
end
86116

87117
if (self.m_triggered and not Self:IsDriving()) then

SSV2/includes/lib/translations/de-DE.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ return {
425425
["VEH_RALLY_TYRES"] = "Rallye-Reifen",
426426
["VEH_OFFROAD_ABILITIES_TT"] = "Erhöht die Offroad-Fähigkeiten Ihres Fahrzeugs.",
427427
["VEH_RALLY_TYRES_TT"] = "Rüstet Ihr Fahrzeug mit Rallye-Reifen aus, die das Handling im Gelände weiter verbessern.",
428-
["SELF_LASER_SIGHTS_TT"] = "Ermöglicht Laservisiere für Ihre Schusswaffen. Sie können die Visiere ein- und ausschalten, indem Sie [%s] drücken.",
428+
["SELF_LASER_SIGHTS_TT"] = "Ermöglicht Laservisiere für Ihre Schusswaffen.",
429429
["VEH_FORCE_NO_TC_TT"] = "Nur Fahrräder: Zwingt Ihr Fahrzeug dazu, keine Traktionskontrolle zu haben, sodass Sie mit Fahrrädern driften und ins Schleudern geraten können.",
430430
["VEH_LOW_SPEED_WHEELIE_TT"] = "Nur Fahrräder: Ermöglicht Ihnen, Wheelies bei sehr niedrigen Geschwindigkeiten zu machen, ähnlich wie beim „Manchez“.",
431431
["VEH_LOW_SPEED_WHEELIE"] = "Low-Speed-Wheelie",

SSV2/includes/lib/translations/en-US.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ return {
312312
"This feature does not auto-aim or auto-fire. It simply remembers the last ped you aimed at and redirects your shot to that ped when you fire, even if you shoot elsewhere. The target resets when you stop aiming.",
313313
["SELF_LASER_SIGHTS"] = "Laser Sights",
314314
["SELF_LASER_SIGHTS_LENGTH"] = "Laser Ray Length",
315-
["SELF_LASER_SIGHTS_TT"] =
316-
"Enables laser sights on your firearms. You can toggle the sights on and off by pressing [%s]", -- hopefully the keybind's name gets formatted across locales
315+
["SELF_LASER_SIGHTS_TT"] = "Enables laser sights on your firearms.",
317316
["SELF_LASER_SIGHTS_COL"] = "Laser Color",
318317
["SELF_KATANA"] = "Katana",
319318
["SELF_KATANA_TT"] = "Replaces one of four melee weapon models of your choosing with a Katana.",

SSV2/includes/lib/translations/es-ES.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ return {
414414
["GENERIC_CLEAR"] = "Claro",
415415
["SUBTAB_HANDLING_EDITOR"] = "Editor de manejo",
416416
["SELF_LASER_SIGHTS"] = "Miras láser",
417-
["SELF_LASER_SIGHTS_TT"] = "Habilita miras láser en sus armas de fuego. Puedes activar y desactivar las miras presionando [%s]",
417+
["SELF_LASER_SIGHTS_TT"] = "Habilita miras láser en sus armas de fuego.",
418418
["SELF_LASER_SIGHTS_LENGTH"] = "Longitud del rayo láser",
419419
["SELF_LASER_SIGHTS_COL"] = "Color láser",
420420
["VEH_NO_ENGINE_BRAKE_TT"] = "Te permite deslizarte cuando no pisas el acelerador sin perder tanta velocidad.",

SSV2/includes/lib/translations/fr-FR.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ return {
422422
["VEH_OFFROAD_ABILITIES"] = "Capacités tout-terrain",
423423
["VEH_OFFROAD_ABILITIES_TT"] = "Augmente les capacités tout-terrain de votre véhicule.",
424424
["VEH_KERS_BOOST_TT"] = "Équipe votre véhicule du boost KERS (Kinetic Energy Recovery System), similaire aux voitures de F1.",
425-
["SELF_LASER_SIGHTS_TT"] = "Permet des vues laser sur vos armes à feu. Vous pouvez activer et désactiver les viseurs en appuyant sur [%s]",
425+
["SELF_LASER_SIGHTS_TT"] = "Permet des vues laser sur vos armes à feu.",
426426
["SUBTAB_HANDLING_EDITOR"] = "Éditeur de manipulation",
427427
["SELF_LASER_SIGHTS_COL"] = "Couleur laser",
428428
["VEH_FORCE_NO_TC_TT"] = "Vélos uniquement : oblige votre véhicule à ne pas avoir de contrôle de traction, ce qui vous permet de faire des dérives et des dérapages avec des vélos.",

SSV2/includes/lib/translations/it-IT.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ return {
427427
["SELF_LASER_SIGHTS_LENGTH"] = "Lunghezza del raggio laser",
428428
["VEH_LOW_SPEED_WHEELIE"] = "Impennata a bassa velocità",
429429
["VEH_RALLY_TYRES"] = "Pneumatici Rally",
430-
["SELF_LASER_SIGHTS_TT"] = "Abilita i mirini laser sulle tue armi da fuoco. Puoi attivare e disattivare la vista premendo [%s]",
430+
["SELF_LASER_SIGHTS_TT"] = "Abilita i mirini laser sulle tue armi da fuoco.",
431431
["VEH_OFFROAD_ABILITIES_TT"] = "Aumenta le capacità fuoristrada del tuo veicolo.",
432432
["VEH_ROCKET_BOOST"] = "Spinta del razzo",
433433
["VEH_ROCKET_BOOST_TT"] = "Dota il tuo veicolo di un razzo potenziato, simile al \"Vigilante\".",

SSV2/includes/lib/translations/ja-JP.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ return {
423423
["VEH_RALLY_TYRES"] = "ラリータイヤ",
424424
["VEH_OFFROAD_ABILITIES"] = "オフロード能力",
425425
["VEH_FORCE_NO_TC_TT"] = "バイクのみ: 車両にトラクション コントロールを強制的に無効にし、バイクでドリフトやスキッドを行うことができます。",
426-
["SELF_LASER_SIGHTS_TT"] = "銃器のレーザー照準器を有効にします。 [%s] を押すと照準器のオンとオフを切り替えることができます。",
426+
["SELF_LASER_SIGHTS_TT"] = "銃器のレーザー照準器を有効にします。",
427427
["VEH_RALLY_TYRES_TT"] = "車両にラリータイヤを装備すると、オフロードでのハンドリングがさらに向上します。",
428428
["VEH_NO_ENGINE_BRAKE"] = "エンジンブレーキを無効にする",
429429
["VEH_KERS_BOOST"] = "KERSブースト",

0 commit comments

Comments
 (0)