Skip to content

Commit 63811da

Browse files
committed
chore(classes): add CTransmission
- Add CTransmission class to CVehicle. - Add more stuff to `ManualGearbox`.
1 parent e958ae0 commit 63811da

28 files changed

Lines changed: 991 additions & 513 deletions

SSV2/includes/classes/Set.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function Set:Clear()
7373
self.m_data = {}
7474
end
7575

76-
---@param element T
76+
---@param element any
7777
---@return boolean
7878
function Set:Contains(element)
7979
return self.m_data[element] == true
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
-- Copyright (C) 2026 SAMURAI (xesdoog) & Contributors.
2+
-- This file is part of Samurai's Scripts.
3+
--
4+
-- Permission is hereby granted to copy, modify, and redistribute
5+
-- this code as long as you respect these conditions:
6+
-- * Credit the owner and contributors.
7+
-- * Provide a copy of or a link to the original license (GPL-3.0 or later); see LICENSE.md or <https://www.gnu.org/licenses/>.
8+
9+
10+
local CStructView = require("includes.classes.gta.CStructView")
11+
12+
13+
--------------------------------------
14+
-- Class: CTransmission
15+
--------------------------------------
16+
---@class CTransmission
17+
---@field public m_current_gear pointer<uint8_t>
18+
---@field public m_previous_gear pointer<uint8_t>
19+
---@field public m_top_gear pointer<uint8_t>
20+
---@field public m_gear_ratios array<pointer<float>>
21+
---@field public m_drive_force pointer<float>
22+
---@field public m_drive_max_flat_velocity pointer<float>
23+
---@field public m_drive_max_velocity pointer<float>
24+
---@field public m_throttle_unk pointer<float> -- not sure what this does but I managed to force revs using only this offset. it worked once then stopped doing anything
25+
---@field public m_rpm pointer<float>
26+
---@field public m_rpm_2 pointer<float>
27+
---@field public m_clutch pointer<float> cvehicle + 0x08D4
28+
---@field public m_throttle pointer<float> these two might be flipped
29+
---@field public m_throttle_input pointer<float> //
30+
---@field public m_boost_pressure pointer<float> m_throttle_input + 16 ? TODO: fix this it's wrong. this keeps incrementing when throttle is held and resets to 0 when released. pressure does not infinitely accumulate but this does
31+
---@overload fun(ptr: pointer): CTransmission
32+
local CTransmission = CStructView("CTransmission")
33+
34+
---@param ptr pointer
35+
---@return CTransmission
36+
function CTransmission.new(ptr)
37+
---@diagnostic disable-next-line
38+
local instance = setmetatable({ m_ptr = ptr, }, CTransmission)
39+
instance.m_current_gear = ptr:add(0x0000)
40+
instance.m_previous_gear = ptr:add(0x0002)
41+
instance.m_top_gear = ptr:add(0x0006)
42+
instance.m_drive_force = ptr:add(0x0038)
43+
instance.m_drive_max_flat_velocity = ptr:add(0x003C)
44+
instance.m_drive_max_velocity = ptr:add(0x0040)
45+
instance.m_throttle_unk = ptr:add(0x0044)
46+
instance.m_rpm = ptr:add(0x0048)
47+
instance.m_rpm_2 = ptr:add(0x004C)
48+
instance.m_clutch = ptr:add(0x0054)
49+
instance.m_throttle = ptr:add(0x0058)
50+
instance.m_throttle_input = ptr:add(0x0060)
51+
instance.m_boost_pressure = ptr:add(0x0070)
52+
53+
54+
local gearRatios = {} ---@type array<pointer<float>>
55+
local pArrayStart = ptr:add(0x000C)
56+
for i = 0, 10 do -- reverse + 10 fwd gears
57+
gearRatios[i + 1] = pArrayStart:add(i * 0x4)
58+
end
59+
instance.m_gear_ratios = gearRatios
60+
61+
return instance
62+
end
63+
64+
---@param gear uint8_t
65+
---@return float
66+
function CTransmission:GetRatioForGear(gear)
67+
local ptr = self.m_gear_ratios[gear + 1]
68+
if (not ptr or ptr:is_null()) then
69+
return 0.0
70+
end
71+
72+
return ptr:get_float()
73+
end
74+
75+
---@param gear uint8_t
76+
---@param ratio float
77+
function CTransmission:SetRatioForGear(gear, ratio)
78+
local ptr = self.m_gear_ratios[gear + 1]
79+
if (not ptr or ptr:is_null()) then return end
80+
ptr:set_float(ratio)
81+
end
82+
83+
---@param gear uint8_t
84+
---@return float
85+
function CTransmission:GetMaxSpeedForGear(gear)
86+
local max_drive_vel = self.m_drive_max_velocity:get_float()
87+
local gear_ratio = math.abs(self:GetRatioForGear(gear))
88+
if (gear_ratio == 0) then
89+
return 0.0
90+
end
91+
return max_drive_vel / gear_ratio
92+
end
93+
94+
return CTransmission

SSV2/includes/classes/gta/CVehicle.lua

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ local CHandlingData = require("includes.classes.gta.CHandlingData")
1414
local CEntity = require("includes.classes.gta.CEntity")
1515
local CVehicleDrawData = require("includes.classes.gta.CVehicleDrawData")
1616
local CVehicleModelInfo = require("includes.classes.gta.CVehicleModelInfo")
17+
local CTransmission = require("includes.classes.gta.CTransmission")
1718
local CWheel = require("includes.classes.gta.CWheel")
1819
local fMatrix44 = require("includes.classes.gta.fMatrix44")
1920
local phFragInst = require("includes.classes.gta.phFragInst")
20-
local CCarHandlingData = require("includes.classes.gta.CCarHandlingData")
2121

2222

2323
---@class CAdvancedData
@@ -30,26 +30,22 @@ local CCarHandlingData = require("includes.classes.gta.CCarHandlingData")
3030
---@ignore
3131
---@class CVehicle : CEntity
3232
---@field protected m_ptr pointer
33-
---@field public m_physics_fragments phFragInst //0x0030 `struct rage::phFragInst`
3433
---@field public m_draw_data CVehicleDrawData
3534
---@field public m_handling_data CHandlingData
3635
---@field public m_model_info CVehicleModelInfo
3736
---@field public m_vehicle_damage pointer<CVehicleDamage>
3837
---@field public m_can_boost_jump pointer<byte> `bool`
3938
---@field public m_velocity pointer<vec3>
39+
---@field public m_transmission CTransmission
4040
---@field public m_deform_god pointer<uint8_t>
41+
---@field public m_frag_inst phFragInst //0x09C0 `fragInstGTA`
42+
---@field public m_turbo pointer<float>
4143
---@field public m_water_damage pointer<uint32_t>
42-
---@field public m_next_gear pointer<uint8_t>
43-
---@field public m_current_gear pointer<uint8_t>
44-
---@field public m_top_gear pointer<uint8_t>
45-
---@field public m_rpm pointer<float>
46-
---@field public m_rpm_2 pointer<float>
47-
---@field public m_clutch pointer<float> // 0x08D4
48-
---@field public m_throttle pointer<float> -- these two might be flipped
49-
---@field public m_throttle_input pointer<float> //
5044
---@field public m_engine_health pointer<float>
51-
---@field public m_steering_input pointer<float> // 0x00D4 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> 0x00DC // 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
45+
---@field public m_steering_input pointer<float> // 0x00D4 name might not correctly reflect what this actually is but this seems to store controller input (value is between 1.0 (left) .. -1.0 (right))
46+
---@field public m_steering_angle pointer<float> 0x00DC // steering angle?. We'll use it to rewrite last known steering value after exiting a vehicle in IV-Style Exit so we'll no longer have to teleport outside or patch CTaskVehicleExit
47+
---@field public m_throttle_power pointer<float> m_steering_angle + 0x8
48+
---@field public m_brake_power pointer<float>
5349
---@field public m_is_targetable pointer<byte> `bool`
5450
---@field public m_door_lock_status pointer<uint32_t>
5551
---@field public m_wheels atArray<CWheel> -- 0x0C30
@@ -71,35 +67,32 @@ function CVehicle:init(vehicle)
7167
local instance = setmetatable({}, CVehicle)
7268
instance:super().init(instance, vehicle)
7369

74-
local ptr = memory.handle_to_ptr(vehicle)
75-
instance.m_ptr = ptr
76-
instance.m_model_info = CVehicleModelInfo(ptr:add(0x0020):deref())
77-
instance.m_water_damage = ptr:add(0x00D8)
78-
instance.m_physics_fragments = phFragInst(ptr:add(0x0030):deref())
79-
instance.m_draw_data = CVehicleDrawData(ptr:add(0x0048):deref())
80-
instance.m_can_boost_jump = ptr:add(0x03A4)
81-
instance.m_vehicle_damage = ptr:add(0x0420)
82-
instance.m_velocity = ptr:add(0x07D0)
83-
instance.m_is_targetable = ptr:add(0x0AEE)
84-
instance.m_next_gear = ptr:add(0x0880)
85-
instance.m_current_gear = ptr:add(0x0882)
86-
instance.m_top_gear = ptr:add(0x0886)
87-
instance.m_rpm = ptr:add(0x08C8)
88-
instance.m_rpm_2 = ptr:add(0x08CC)
89-
instance.m_clutch = ptr:add(0x08D4)
90-
instance.m_throttle = ptr:add(0x08D8)
91-
instance.m_throttle_input = ptr:add(0x08E0)
92-
instance.m_engine_health = ptr:add(0x0910)
93-
instance.m_handling_data = CHandlingData(ptr:add(0x0960):deref(), instance.m_model_info:GetVehicleType())
94-
instance.m_deform_god = ptr:add(0x096C)
95-
instance.m_steering_input = ptr:add(0x09D4)
96-
instance.m_current_steering = ptr:add(0x09DC)
97-
instance.m_door_lock_status = ptr:add(0x13D0)
98-
99-
local array_ptr = ptr:add(0x0C30)
100-
instance.m_wheels = atArray(array_ptr, CWheel)
101-
instance.m_num_wheels = array_ptr:add(0x8):get_int()
102-
instance.m_ride_height = array_ptr:deref():add(0x007C)
70+
local ptr = memory.handle_to_ptr(vehicle)
71+
instance.m_ptr = ptr
72+
instance.m_model_info = CVehicleModelInfo(ptr:add(0x0020):deref())
73+
instance.m_draw_data = CVehicleDrawData(ptr:add(0x0048):deref())
74+
instance.m_turbo = ptr:add(0x007C)
75+
instance.m_water_damage = ptr:add(0x00D8)
76+
instance.m_can_boost_jump = ptr:add(0x03A4)
77+
instance.m_vehicle_damage = ptr:add(0x0420)
78+
instance.m_velocity = ptr:add(0x07D0)
79+
instance.m_transmission = CTransmission(ptr:add(0x0880))
80+
instance.m_engine_health = ptr:add(0x0910)
81+
instance.m_handling_data = CHandlingData(ptr:add(0x0960):deref(), instance.m_model_info:GetVehicleType())
82+
instance.m_deform_god = ptr:add(0x096C)
83+
instance.m_frag_inst = phFragInst(ptr:add(0x09C0):deref())
84+
instance.m_steering_input = ptr:add(0x09D4)
85+
instance.m_steering_angle = ptr:add(0x09DC)
86+
instance.m_throttle_power = ptr:add(0x09E4)
87+
instance.m_brake_power = ptr:add(0x09E8)
88+
instance.m_is_targetable = ptr:add(0x0AEE)
89+
90+
local array_ptr = ptr:add(0x0C30)
91+
instance.m_wheels = atArray(array_ptr, CWheel)
92+
instance.m_num_wheels = array_ptr:add(0x8):get_int()
93+
instance.m_ride_height = array_ptr:deref():add(0x007C)
94+
95+
instance.m_door_lock_status = ptr:add(0x13D0)
10396

10497
return instance
10598
end
@@ -125,14 +118,6 @@ function CVehicle:GetDeformMultiplier()
125118
end)
126119
end
127120

128-
-- ---@param handlingType eHandlingType
129-
-- ---@return CCarHandlingData|CBikeHandlingData|CFlyingHandlingData|any
130-
-- function CVehicle:GetSubHandlingData(handlingType)
131-
-- return self:__safecall(nil, function()
132-
-- return self.m_handling_data:GetSubHandlingData(handlingType)
133-
-- end)
134-
-- end
135-
136121
---@return pointer<(CCarHandlingData|CBikeHandlingData|CFlyingHandlingData)?>
137122
function CVehicle:GetSubHandlingData()
138123
return self.m_handling_data:GetSubHandlingData()
@@ -332,7 +317,7 @@ end
332317
---@param boneIndex integer
333318
---@return fMatrix44
334319
function CVehicle:GetBoneMatrix(boneIndex)
335-
local ph_frag_inst = self.m_physics_fragments
320+
local ph_frag_inst = self.m_frag_inst
336321
if not ph_frag_inst then
337322
return fMatrix44:zero()
338323
end
@@ -348,7 +333,7 @@ end
348333
---@param boneIndex integer
349334
---@param matrix fMatrix44
350335
function CVehicle:SetBoneMatrix(boneIndex, matrix)
351-
local ph_frag_inst = self.m_physics_fragments
336+
local ph_frag_inst = self.m_frag_inst
352337
if not ph_frag_inst then
353338
return
354339
end

SSV2/includes/data/config.lua

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,76 +42,81 @@ local Config <const> = {
4242
auto_close = false,
4343
},
4444
keyboard_keybinds = {
45-
gui_toggle = "F5",
46-
kill_all_enemies = "F7",
47-
enemies_flee = "F8",
45+
gui_toggle = "F5",
46+
kill_all_enemies = "F7",
47+
enemies_flee = "F8",
4848
-- missile_defence = "F9",
49-
cobra_maneuver = "X",
50-
flatbed = "X",
51-
laser_sights = "L",
52-
nos = "MOUSE5",
53-
rolling_launch = "N",
54-
panik = "F12",
55-
nos_purge = "X",
56-
rod = "X",
57-
drift_mode = "SHIFT",
49+
cobra_maneuver = "X",
50+
flatbed = "X",
51+
laser_sights = "L",
52+
nos = "MOUSE5",
53+
rolling_launch = "N",
54+
panik = "F12",
55+
nos_purge = "X",
56+
rod = "X",
57+
drift_mode = "SHIFT",
5858
-- trigger_bot = "SHIFT",
59-
veh_mine = "NUMPAD0",
60-
stop_anim = "G",
61-
shift_up = "NUMPAD9",
62-
shift_down = "NUMPAD3",
63-
clutch = "NUMPAD5",
59+
veh_mine = "NUMPAD0",
60+
stop_anim = "G",
61+
shift_up = "NUMPAD9",
62+
shift_down = "NUMPAD3",
63+
clutch = "NUMPAD5",
64+
engine_start_stop = "NUMPAD1",
6465
},
6566
gamepad_keybinds = {
66-
flatbed = {
67+
flatbed = {
6768
code = 288,
6869
name = "A"
6970
},
70-
laser_sights = {
71+
laser_sights = {
7172
code = 303,
7273
name = "DPAD UP"
7374
},
74-
nos = {
75+
nos = {
7576
code = 289,
7677
name = "X"
7778
},
78-
nos_purge = {
79+
nos_purge = {
7980
code = 288,
8081
name = "A"
8182
},
82-
rod = {
83+
rod = {
8384
code = 288,
8485
name = "A"
8586
},
86-
drift_mode = {
87+
drift_mode = {
8788
code = 288,
8889
name = "A"
8990
},
9091
-- trigger_bot = {
9192
-- code = 0,
9293
-- name = "Unbound"
9394
-- },
94-
veh_mine = {
95+
veh_mine = {
9596
code = 0,
9697
name = "Unbound"
9798
},
98-
stop_anim = {
99+
stop_anim = {
99100
code = 0,
100101
name = "Unbound"
101102
},
102-
rolling_launch = {
103+
rolling_launch = {
103104
code = 0,
104105
name = "Unbound"
105106
},
106-
shift_up = {
107+
shift_up = {
107108
code = 0,
108109
name = "Unbound"
109110
},
110-
shift_down = {
111+
shift_down = {
111112
code = 0,
112113
name = "Unbound"
113114
},
114-
clutch = {
115+
clutch = {
116+
code = 0,
117+
name = "Unbound"
118+
},
119+
engine_start_stop = {
115120
code = 0,
116121
name = "Unbound"
117122
},
@@ -167,7 +172,8 @@ local Config <const> = {
167172
},
168173
manual_gearbox = {
169174
enabled = false,
170-
mode = 0,
175+
disable_stalling = false,
176+
mode = 0, ---@type eManualGearboxType
171177
},
172178
bangs_rpm_max = 9000.0,
173179
bangs_rpm_min = 4000.0,

SSV2/includes/data/custom_paints.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ return {
8282
{ name = "Rosso Corsa", hex = "#D40000", p = 28, m = false, manufacturer = "Ferrari", shade = "Red" },
8383
{ name = "Millennium Jade", hex = "#3B3F31", p = 102, m = false, manufacturer = "Nissan", shade = "Green" },
8484
{ name = "Copper Gold", hex = "#5A4441", p = 136, m = false, manufacturer = "None", shade = "Gold" },
85-
{ name = "Taipei Gold", hex = "#49231F", p = 99, m = false, manufacturer = "Koeniggsegg", shade = "Gold" },
85+
{ name = "Taipei Gold", hex = "#49231F", p = 99, m = false, manufacturer = "Koenigsegg", shade = "Gold" },
8686
{ name = "Olympic Gold", hex = "#706546", p = 104, m = false, manufacturer = "None", shade = "Gold" },
8787
{ name = "Sandy Gold", hex = "#504942", p = 105, m = false, manufacturer = "None", shade = "Gold" },
8888
{ name = "Mulberry", hex = "#240719", p = 137, m = false, manufacturer = "None", shade = "Purple" },
8989
{ name = "Onyx", hex = "#353839", p = 103, m = false, manufacturer = "None", shade = "Grey" },
9090
{ name = "Amethyst", hex = "#27253C", p = 65, m = false, manufacturer = "Porsche", shade = "Grey" },
91-
{ name = "AAden Purple", hex = "#0C080C", p = 96, m = false, manufacturer = "Koeniggsegg", shade = "Purple" },
92-
{ name = "Zjin Purple", hex = "#120119", p = 145, m = false, manufacturer = "Koeniggsegg", shade = "Purple" },
91+
{ name = "AAden Purple", hex = "#0C080C", p = 96, m = false, manufacturer = "Koenigsegg", shade = "Purple" },
92+
{ name = "Zjin Purple", hex = "#120119", p = 145, m = false, manufacturer = "Koenigsegg", shade = "Purple" },
9393
{ name = "Viola Ophelia", hex = "#1A000F", p = 7, m = false, manufacturer = "Lamborghini", shade = "Purple" },
9494
{ name = "Nismo Grey", hex = "#191919", p = 4, m = false, manufacturer = "Nissan", shade = "Grey" },
9595
{ name = "Pagani Brown", hex = "#201913", p = 94, m = false, manufacturer = "Pagani", shade = "Brown" },
@@ -232,7 +232,7 @@ return {
232232
{ name = "Sunset Gold", hex = "#262425", p = 99, m = false, manufacturer = "Land Rover", shade = "Gold" },
233233
{ name = "Rio Gold", hex = "#666162", p = 4, m = false, manufacturer = "Land Rover", shade = "Gold" },
234234
{ name = "Rose Gold I", hex = "#B76E6E", p = 66, m = false, manufacturer = "None", shade = "Gold" },
235-
{ name = "Rose Gold II", hex = "#322121", p = 66, m = false, manufacturer = "Koeniggsegg", shade = "Gold" },
235+
{ name = "Rose Gold II", hex = "#322121", p = 66, m = false, manufacturer = "Koenigsegg", shade = "Gold" },
236236
{ name = "Metallic Gold", hex = "#5C4C36", p = 37, m = false, manufacturer = "None", shade = "Gold" },
237237
{ name = "Champagne Gold I", hex = "#4B443D", p = 97, m = false, manufacturer = "Ford", shade = "Gold" },
238238
{ name = "Champagne Gold II", hex = "#644606", p = 37, m = false, manufacturer = "Lotus", shade = "Gold" },

0 commit comments

Comments
 (0)