Skip to content

Commit 65eb9ca

Browse files
authored
Merge pull request #77 from acidlabsdev/main
fix(misc): several bug fixes & improvements
2 parents 53384af + 162379a commit 65eb9ca

32 files changed

Lines changed: 1048 additions & 493 deletions

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: 32 additions & 6 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>
@@ -72,6 +74,7 @@ local SubHandlingCtorMap <const> = {
7274
---@field public m_deform_mult pointer<float>
7375
---@field public m_wheel_scale pointer<float>
7476
---@field public m_wheel_scale_rear pointer<float>
77+
---@field public m_throttle pointer<float> // 0x8D8
7578
---@field public m_wheels atArray<CWheel> -- 0xC30
7679
---@field public m_num_wheels number -- 0xC38
7780
---@field public m_ride_height pointer<float>
@@ -106,11 +109,13 @@ function CVehicle:init(vehicle)
106109
instance.m_deform_god = ptr:add(0x096C)
107110
instance.m_is_targetable = ptr:add(0x0AEE)
108111
instance.m_door_lock_status = ptr:add(0x13D0)
109-
instance.m_water_damage = ptr:add(0xD8)
112+
instance.m_water_damage = ptr:add(0x00D8)
110113
instance.m_next_gear = ptr:add(0x0880)
111114
instance.m_current_gear = ptr:add(0x0882)
112115
instance.m_top_gear = ptr:add(0x0886)
113116
instance.m_engine_health = ptr:add(0x0910)
117+
instance.m_steering_input = ptr:add(0x09D4)
118+
instance.m_current_steering = ptr:add(0x09DC)
114119
instance.m_model_info_flags = instance.m_model_info:add(0x057C)
115120
instance.m_mass = instance.m_handling_data:add(0x000C)
116121
instance.m_initial_drag_coeff = instance.m_handling_data:add(0x0010)
@@ -133,9 +138,10 @@ function CVehicle:init(vehicle)
133138
instance.m_damage_flags = instance.m_handling_data:add(0x012C)
134139
instance.m_wheel_scale = instance.m_model_info:add(0x048C)
135140
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)
141+
instance.m_throttle = instance.m_model_info:add(0x08D8)
142+
instance.m_wheels = atArray(ptr:add(0x0C30), CWheel)
143+
instance.m_num_wheels = ptr:add(0x0C38):get_int()
144+
instance.m_ride_height = ptr:add(0x0C30):deref():add(0x07C)
139145

140146
return instance
141147
end
@@ -429,8 +435,28 @@ function CVehicle:IsWheelBrokenOff(wheelIndex)
429435
return false
430436
end
431437

432-
-- Thanks tupoy-ya
433-
return (self.m_ptr:add(0xA98):get_dword() >> (wheelIndex & 0x1F) & 1) ~= 0
438+
-- -- Thanks tupoy-ya
439+
-- return (self.m_ptr:add(0xA98):get_dword() >> (wheelIndex & 0x1F) & 1) ~= 0
440+
441+
local cwheel = self:GetWheel(wheelIndex)
442+
if (not cwheel) then
443+
return false
444+
end
445+
446+
return cwheel:GetDynamicFlag(Enums.eWheelDynamicFlags.BROKEN_OFF)
447+
end
448+
449+
---@return CWheel?
450+
function CVehicle:GetWheel(index)
451+
if (not self:IsValid()) then
452+
return
453+
end
454+
455+
if (index > self.m_wheels:Size()) then
456+
return
457+
end
458+
459+
return CWheel(self.m_wheels:Get(index))
434460
end
435461

436462
---@param refresh? boolean

SSV2/includes/classes/CWheel.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@diagnostic disable: param-type-mismatch
22

3-
---@enum eWheelFlags
4-
Enums.eWheelFlags = {
3+
---@enum eWheelDynamicFlags
4+
Enums.eWheelDynamicFlags = {
55
HIT = 0,
66
HIT_PREV = 1,
77
ON_GAS = 2,
@@ -89,30 +89,30 @@ Enums.eWheelConfigFlags = {
8989
---@field m_suspension_length pointer<float> //0x110
9090
---@field m_max_suspension_travel pointer<float> //0x114
9191
---@field m_suspension_forward_offset pointer<float> //0x13C // prefer this to raise/lower individual wheels
92-
---@field m_suspension_compression pointer<float> // 0x164 `radians`
93-
---@field m_suspension_compression_2 pointer<float> // 0x168 `radians`
92+
---@field m_suspension_compression pointer<float> // 0x164
93+
---@field m_suspension_compression_2 pointer<float> // 0x168
9494
---@field m_wheel_compression pointer<float> // 0x16C
9595
---@field m_rotation_speed pointer // 0x170
9696
---@field m_unk0190 pointer // ?? 0x190
9797
---@field m_unk0194 pointer // ?? 0x194
9898
---@field m_tire_drag_coeff pointer<float> // 0x198
9999
---@field m_top_speed_mult pointer<float> // 0x19C
100-
---@field m_steering_angle pointer<float> // 0x1CC `radians`
100+
---@field m_steering_angle pointer<float> // 0x1CC
101101
---@field m_brake_force pointer<float> // 0x1D0
102102
---@field m_drive_force pointer<float> // 0x1D4
103103
---@field m_suspension_health pointer<float> // 0x1E8 // 100.0f: car gets slammed (old method of shooting your suspension to stance your car) // 0.0f: wheel should fall off but doesn't. Something else must be set to trigger wheel detachment
104104
---@field m_tyre_health pointer<float> // 0x1EC // <= 500.0f: flat tyre // 0.0f: no tyre
105105
---@field m_tyre_wear_mult pointer<float> // 0x1F0 // 0.0f: tyres won't burst from long burnout
106106
---@field m_tyre_wear_unk pointer<float> // 0x1F8 // similar?
107-
---@field m_wheel_flags pointer<eWheelFlags> // 0x200
107+
---@field m_wheel_flags pointer<eWheelDynamicFlags> // 0x200
108108
---@field m_wheel_config_flags pointer<eWheelConfigFlags> // 0x204
109109
---@field m_unk_u16 pointer<uint16_t> // 0x208
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, {
@@ -233,9 +233,9 @@ function CWheel:GetTiltAngle()
233233
return math.deg(math.acos(dot / mag))
234234
end
235235

236-
---@param flag eWheelFlags
236+
---@param flag eWheelDynamicFlags
237237
---@return boolean
238-
function CWheel:GetWheelFlag(flag)
238+
function CWheel:GetDynamicFlag(flag)
239239
if (not self:IsValid()) then
240240
return false
241241
end
@@ -253,9 +253,9 @@ function CWheel:GetConfigFlag(flag)
253253
return Bit.is_set(self.m_wheel_config_flags:get_dword(), flag)
254254
end
255255

256-
---@param flag eWheelFlags
256+
---@param flag eWheelDynamicFlags
257257
---@param toggle boolean
258-
function CWheel:SetWheelFlag(flag, toggle)
258+
function CWheel:SetDynamicFlag(flag, toggle)
259259
if (not self:IsValid()) then
260260
return
261261
end

SSV2/includes/data/pointers.lua

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
PatternScanner = require("includes.services.PatternScanner"):init()
22

3-
--- A place to store callable naems returned from `memory.dynamic_call`
4-
---@class DynamicFuncNames
5-
---@field dfn_IsVehicleWheelBrokenOff? string
3+
--- A place to store functions returned from `memory.dynamic_call`
4+
---@class DynamicFuncs
5+
---@field BreakOffVehicleWheel? fun(pVehicleDamage: pointer<CVehicleDamage>, wheelIdx: integer, ptfxChance: float, deleteChance: float, burstChance: float, setOnFire: bool, isNetwork: bool)
66

77
-- ### A place to store pointers globally.
88
--
@@ -19,20 +19,18 @@ PatternScanner = require("includes.services.PatternScanner"):init()
1919
---@field GameTime pointer<uint32_t>
2020
---@field GameVersion { _build: string, _online: string }
2121
---@field ScreenResolution vec2
22-
---@field IsVehicleWheelBrokenOff pointer<function>
23-
---@field DynamicFuncNames DynamicFuncNames
22+
---@field DynamicFuncs DynamicFuncs
2423
local GPointers = {
25-
Init = function() PatternScanner:Scan() end,
26-
Retry = function() PatternScanner:RetryScan() end,
27-
ScriptGlobals = nullptr,
28-
GameState = nullptr,
29-
GameTime = nullptr,
30-
IsVehicleWheelBrokenOff = nullptr,
31-
GameVersion = { _build = "nil", _online = "nil" },
32-
ScreenResolution = vec2:zero(),
24+
Init = function() PatternScanner:Scan() end,
25+
Retry = function() PatternScanner:RetryScan() end,
26+
ScriptGlobals = nullptr,
27+
GameState = nullptr,
28+
GameTime = nullptr,
29+
GameVersion = { _build = "nil", _online = "nil" },
30+
ScreenResolution = vec2:zero(),
3331
}
3432

35-
GPointers.DynamicFuncNames = {}
33+
GPointers.DynamicFuncs = {}
3634

3735

3836
---@class MemoryBatch
@@ -98,18 +96,21 @@ local mem_batches <const> = {
9896
ptr:add(0x4):rip():get_word()
9997
)
10098
end),
101-
-- MemoryBatch.new("IsVehicleWheelBrokenOff", "E8 ? ? ? ? 48 8B CD 41 88 84 1F", function(ptr)
99+
100+
-- fuck my life man fuck it
101+
-- MemoryBatch.new("BreakOffVehicleWheel", "F3 44 0F 11 4C 24 ? E8 ? ? ? ? EB 7A", function(ptr)
102102
-- if ptr:is_null() then
103103
-- return
104104
-- end
105105

106-
-- local func_ptr = ptr:add(0x1):rip()
107-
-- GPointers.IsVehicleWheelBrokenOff = func_ptr -- not needed for this but we'll just go ahead and store it
108-
-- GPointers.DynamicFuncNames.dfn_IsVehicleWheelBrokenOff = memory.dynamic_call(
109-
-- "bool",
110-
-- { "void*", "int" },
106+
-- local func_ptr = ptr:add(0x7)
107+
-- local func_name = memory.dynamic_call(
108+
-- "void",
109+
-- { "void*", "uint32_t", "float", "float", "float", "bool", "bool" },
111110
-- func_ptr
112111
-- )
112+
113+
-- GPointers.DynamicFuncs.BreakOffVehicleWheel = _G[func_name]
113114
-- end),
114115
},
115116
[Enums.eAPIVersion.V2] = {
@@ -148,9 +149,7 @@ local mem_batches <const> = {
148149
)
149150
end),
150151
},
151-
[Enums.eAPIVersion.L54] = {
152-
-- dummy
153-
},
152+
[Enums.eAPIVersion.L54] = { --[[dummy]] },
154153
}
155154

156155
local API_VERSON <const> = Backend:GetAPIVersion()

SSV2/includes/features/Speedometer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function Speedometer:DrawImpl(ImDrawList, center, radius, current_speed, max_spe
298298
local textWidth = ImGui.CalcTextSize(self._state.Manufacturer)
299299
ImGui.ImDrawListAddText(
300300
ImDrawList,
301-
21,
301+
19.5,
302302
center.x - 5 - (textWidth / 2),
303303
center.y - 15 - (radius / 2),
304304
GVars.features.speedometer.colors.text - (math.pi * 10),

SSV2/includes/features/vehicle/drift_mode.lua

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---@diagnostic disable: param-type-mismatch, return-type-mismatch, assign-type-mismatch
22

33
local FeatureBase = require("includes.modules.FeatureBase")
4+
local CWheel = require("includes.classes.CWheel")
45

56
---@class DriftMode : FeatureBase
67
---@field private m_entity PlayerVehicle -- Reference to PlayerVehicle
78
---@field private m_smoke_fx array<handle>|nil
89
---@field private m_is_active boolean
910
---@overload fun(pv: PlayerVehicle): DriftMode
10-
local DriftMode = setmetatable({}, FeatureBase)
11+
local DriftMode = setmetatable({}, FeatureBase)
1112
DriftMode.__index = DriftMode
1213
DriftMode.fxBones = { "suspension_lr", "suspension_rr" }
1314

@@ -107,7 +108,90 @@ function DriftMode:UpdateFX()
107108
end
108109
end
109110

110-
function DriftMode:Update()
111+
-- local debug_txt_scale = vec2:new(0.3, 0.3)
112+
-- local debug_white = Color(225, 225, 225, 255)
113+
-- function DriftMode:DrawDebugHUD()
114+
-- local PV = self.m_entity
115+
-- if (not PV:IsValid()) then
116+
-- return
117+
-- end
118+
119+
-- local speed_vec = PV:GetSpeedVector()
120+
-- local lateral_vel = speed_vec.x
121+
-- local forward_vel = speed_vec.y
122+
-- local absolute_x = math.abs(lateral_vel)
123+
-- local absolute_y = math.abs(speed_vec.y)
124+
-- local delta_x = 0 + absolute_x
125+
-- local delta_y = 0 + absolute_y
126+
-- local angle_rad = math.atan(delta_y, delta_x)
127+
-- local angle_deg = math.deg(angle_rad)
128+
-- local wheels = PV:Resolve().m_wheels
129+
130+
-- Game.DrawText(
131+
-- vec2:new(0.8, 0.35),
132+
-- _F("Raw Lateral Velocity: %.3f", lateral_vel),
133+
-- debug_white,
134+
-- debug_txt_scale,
135+
-- 4
136+
-- )
137+
-- Game.DrawText(
138+
-- vec2:new(0.8, 0.37),
139+
-- _F("Angle: %.0f°", angle_deg),
140+
-- debug_white,
141+
-- debug_txt_scale,
142+
-- 4
143+
-- )
144+
145+
-- Game.DrawText(
146+
-- vec2:new(0.8, 0.39),
147+
-- _F("Forward Velocity: %.3f", forward_vel),
148+
-- debug_white,
149+
-- debug_txt_scale,
150+
-- 4
151+
-- )
152+
153+
-- for i, wheel in wheels:Iter() do
154+
-- local cwheel = CWheel(wheel)
155+
-- if (not cwheel) then
156+
-- goto continue
157+
-- end
158+
159+
-- local wheel_pwr = cwheel.m_drive_force:get_float()
160+
-- local brk_pwr = cwheel.m_brake_force:get_float()
161+
-- local drag_co = cwheel.m_tire_drag_coeff:get_float()
162+
-- local rot_spd = cwheel.m_rotation_speed:get_float()
163+
-- local top_spd_mult = cwheel.m_top_speed_mult:get_float()
164+
-- local is_full_thottle = cwheel:GetWheelFlag(Enums.eWheelFlags.FULL_THROTTLE)
165+
-- local is_cheat_tc = cwheel:GetWheelFlag(Enums.eWheelFlags.CHEAT_TC)
166+
-- local is_cheat_sc = cwheel:GetWheelFlag(Enums.eWheelFlags.CHEAT_SC)
167+
-- local is_driven = cwheel:GetConfigFlag(Enums.eWheelConfigFlags.POWERED)
168+
-- local wheel_txt = _F(
169+
-- "- %d: Power: %.3f | Brake: %.3f | Drag: %.3f | Rotation: %.3f | Speed Mult: %.3f",
170+
-- i,
171+
-- wheel_pwr,
172+
-- brk_pwr,
173+
-- drag_co,
174+
-- rot_spd,
175+
-- top_spd_mult
176+
-- )
177+
178+
-- Game.DrawText(
179+
-- vec2:new(0.7, 0.4 + (i * 0.02)),
180+
-- wheel_txt,
181+
-- debug_white,
182+
-- debug_txt_scale,
183+
-- 4
184+
-- )
185+
186+
-- ::continue::
187+
-- end
188+
189+
-- if (angle_deg <= 88 and PAD.IS_CONTROL_PRESSED(0, 71)) then
190+
-- VEHICLE.SET_VEHICLE_CHEAT_POWER_INCREASE(PV:GetHandle(), 10.0)
191+
-- end
192+
-- end
193+
194+
function DriftMode:UpdateArcadeStyle()
111195
local PV = self.m_entity
112196
local handle = PV:GetHandle()
113197

@@ -135,8 +219,18 @@ function DriftMode:Update()
135219
VEHICLE.SET_VEHICLE_CHEAT_POWER_INCREASE(handle, 1.0)
136220
self.m_is_active = false
137221
end
222+
end
223+
224+
function DriftMode:Update()
225+
if (GVars.features.vehicle.drift.mode < 3) then
226+
self:UpdateArcadeStyle()
227+
end
138228

139229
self:UpdateFX()
230+
231+
-- if (Backend.debug_mode) then
232+
-- self:DrawDebugHUD()
233+
-- end
140234
end
141235

142236
return DriftMode

0 commit comments

Comments
 (0)