From 92eccce8e911465a21eacb6c7b7f63576d2e297e Mon Sep 17 00:00:00 2001 From: march <106459595+marchc1@users.noreply.github.com> Date: Wed, 6 Mar 2024 00:48:54 -0800 Subject: [PATCH 1/4] Add seat model validation check --- lua/acf/contraption/seats_sv.lua | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua index 4ffe0303b..cb60d5b5a 100644 --- a/lua/acf/contraption/seats_sv.lua +++ b/lua/acf/contraption/seats_sv.lua @@ -1,5 +1,36 @@ -- Optional functionality for legality checking on all vehicles +-- A whitelist of allowed seats, prevents setting your seat to something with a microscopic physics object +local ValidSeatModels = { + -- Default HL2 seats + ["models/nova/airboat_seat.mdl"] = true, + ["models/nova/chair_office02.mdl"] = true, + ["models/props_phx/carseat2.mdl"] = true, + ["models/props_phx/carseat2.mdl"] = true, + ["models/props_phx/carseat3.mdl"] = true, + ["models/props_phx/carseat2.mdl"] = true, + ["models/nova/chair_plastic01.mdl"] = true, + ["models/nova/jeep_seat.mdl"] = true, + ["models/nova/chair_office01.mdl"] = true, + ["models/nova/chair_wood01.mdl"] = true, + ["models/vehicles/prisoner_pod_inner.mdl"] = true, + + -- ACF default seats + ["models/vehicles/driver_pod.mdl"] = true, + ["models/vehicles/pilot_seat.mdl"] = true, + + ["models/chairs_playerstart/airboatpose.mdl"] = true, + ["models/chairs_playerstart/jeeppose.mdl"] = true, + ["models/chairs_playerstart/podpose.mdl"] = true, + ["models/chairs_playerstart/sitposealt.mdl"] = true, + ["models/chairs_playerstart/pronepose.mdl"] = true, + ["models/chairs_playerstart/sitpose.mdl"] = true, + ["models/chairs_playerstart/standingpose.mdl"] = true, + + ["models/lubprops/seat/raceseat.mdl"] = true, + ["models/lubprops/seat/raceseat2.mdl"] = true, +} + hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) timer.Simple(0, function() if not IsValid(Entity) then return end @@ -34,6 +65,12 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) end) end) +hook.Add("ACF_IsLegal", "ACF_CheckLegal_SeatLegality", function(Entity) + if ACF.VehicleLegalChecks and Entity:IsVehicle() and not ValidSeatModels[Entity:GetModel()] then + return false, "Bad Seat Model", "This seat model is not on the whitelist." + end +end) + hook.Add("CanPlayerEnterVehicle", "ACF_SeatLegality", function(Player, Entity) if not Entity.ACF then return end From 90239ac4a2d2c526ddd17a1b2a7495560d46dc49 Mon Sep 17 00:00:00 2001 From: march <106459595+marchc1@users.noreply.github.com> Date: Wed, 6 Mar 2024 00:49:24 -0800 Subject: [PATCH 2/4] forgot to comment these --- lua/acf/contraption/seats_sv.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua index cb60d5b5a..16bf1d82b 100644 --- a/lua/acf/contraption/seats_sv.lua +++ b/lua/acf/contraption/seats_sv.lua @@ -19,6 +19,7 @@ local ValidSeatModels = { ["models/vehicles/driver_pod.mdl"] = true, ["models/vehicles/pilot_seat.mdl"] = true, + -- Playerstart seats ["models/chairs_playerstart/airboatpose.mdl"] = true, ["models/chairs_playerstart/jeeppose.mdl"] = true, ["models/chairs_playerstart/podpose.mdl"] = true, @@ -27,6 +28,7 @@ local ValidSeatModels = { ["models/chairs_playerstart/sitpose.mdl"] = true, ["models/chairs_playerstart/standingpose.mdl"] = true, + -- Racing seats ["models/lubprops/seat/raceseat.mdl"] = true, ["models/lubprops/seat/raceseat2.mdl"] = true, } From 5ee9263cda32288623fcccd184dbb678d09f33a0 Mon Sep 17 00:00:00 2001 From: march <106459595+marchc1@users.noreply.github.com> Date: Wed, 6 Mar 2024 01:07:19 -0800 Subject: [PATCH 3/4] Fix linter complaining & tests breaking --- lua/acf/contraption/seats_sv.lua | 52 ++++++++++--------- lua/tests/acf/core/validation_sv/is_legal.lua | 4 ++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua index 16bf1d82b..9486d1479 100644 --- a/lua/acf/contraption/seats_sv.lua +++ b/lua/acf/contraption/seats_sv.lua @@ -3,36 +3,38 @@ -- A whitelist of allowed seats, prevents setting your seat to something with a microscopic physics object local ValidSeatModels = { -- Default HL2 seats - ["models/nova/airboat_seat.mdl"] = true, - ["models/nova/chair_office02.mdl"] = true, - ["models/props_phx/carseat2.mdl"] = true, - ["models/props_phx/carseat2.mdl"] = true, - ["models/props_phx/carseat3.mdl"] = true, - ["models/props_phx/carseat2.mdl"] = true, - ["models/nova/chair_plastic01.mdl"] = true, - ["models/nova/jeep_seat.mdl"] = true, - ["models/nova/chair_office01.mdl"] = true, - ["models/nova/chair_wood01.mdl"] = true, - ["models/vehicles/prisoner_pod_inner.mdl"] = true, + ["models/nova/airboat_seat.mdl"] = true, + ["models/nova/chair_office02.mdl"] = true, + ["models/props_phx/carseat2.mdl"] = true, + ["models/props_phx/carseat2.mdl"] = true, + ["models/props_phx/carseat3.mdl"] = true, + ["models/props_phx/carseat2.mdl"] = true, + ["models/nova/chair_plastic01.mdl"] = true, + ["models/nova/jeep_seat.mdl"] = true, + ["models/nova/chair_office01.mdl"] = true, + ["models/nova/chair_wood01.mdl"] = true, + ["models/vehicles/prisoner_pod_inner.mdl"] = true, -- ACF default seats - ["models/vehicles/driver_pod.mdl"] = true, - ["models/vehicles/pilot_seat.mdl"] = true, + ["models/vehicles/driver_pod.mdl"] = true, + ["models/vehicles/pilot_seat.mdl"] = true, -- Playerstart seats - ["models/chairs_playerstart/airboatpose.mdl"] = true, - ["models/chairs_playerstart/jeeppose.mdl"] = true, - ["models/chairs_playerstart/podpose.mdl"] = true, - ["models/chairs_playerstart/sitposealt.mdl"] = true, - ["models/chairs_playerstart/pronepose.mdl"] = true, - ["models/chairs_playerstart/sitpose.mdl"] = true, - ["models/chairs_playerstart/standingpose.mdl"] = true, - + ["models/chairs_playerstart/airboatpose.mdl"] = true, + ["models/chairs_playerstart/jeeppose.mdl"] = true, + ["models/chairs_playerstart/podpose.mdl"] = true, + ["models/chairs_playerstart/sitposealt.mdl"] = true, + ["models/chairs_playerstart/pronepose.mdl"] = true, + ["models/chairs_playerstart/sitpose.mdl"] = true, + ["models/chairs_playerstart/standingpose.mdl"] = true, + -- Racing seats - ["models/lubprops/seat/raceseat.mdl"] = true, - ["models/lubprops/seat/raceseat2.mdl"] = true, + ["models/lubprops/seat/raceseat.mdl"] = true, + ["models/lubprops/seat/raceseat2.mdl"] = true, } +ACF.ValidSeatModels = ValidSeatModels + hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) timer.Simple(0, function() if not IsValid(Entity) then return end @@ -68,8 +70,8 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) end) hook.Add("ACF_IsLegal", "ACF_CheckLegal_SeatLegality", function(Entity) - if ACF.VehicleLegalChecks and Entity:IsVehicle() and not ValidSeatModels[Entity:GetModel()] then - return false, "Bad Seat Model", "This seat model is not on the whitelist." + if ACF.VehicleLegalChecks and Entity:IsVehicle() and not ValidSeatModels[Entity:GetModel()] then + return false, "Bad Seat Model", "This seat model is not on the whitelist." end end) diff --git a/lua/tests/acf/core/validation_sv/is_legal.lua b/lua/tests/acf/core/validation_sv/is_legal.lua index fc6baec54..8a88ed6b4 100644 --- a/lua/tests/acf/core/validation_sv/is_legal.lua +++ b/lua/tests/acf/core/validation_sv/is_legal.lua @@ -19,6 +19,10 @@ return { return true end, + IsVehicle = function() + return false + end, + GetCollisionGroup = function() return COLLISION_GROUP_NONE end From eb7e38d027107be286090ee2afaafc4b8608a665 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:26:14 -0400 Subject: [PATCH 4/4] Add VehicleTable model check This will only allow the seat to fail its model legal check if its model does not match the one it has listed in its VehicleTable, which should avoid any potential incompatibility with other addons by ensuring that you can only fail if something intentionally changes the seat model. --- lua/acf/contraption/seats_sv.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/acf/contraption/seats_sv.lua b/lua/acf/contraption/seats_sv.lua index 9486d1479..f96fb8f38 100644 --- a/lua/acf/contraption/seats_sv.lua +++ b/lua/acf/contraption/seats_sv.lua @@ -47,7 +47,7 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) Entity.ACF = {} Entity.ACF.PhysObj = PhysObj Entity.ACF.LegalMass = PhysObj:GetMass() - Entity.ACF.Model = Entity:GetModel() + Entity.ACF.Model = Entity.VehicleTable.Model or Entity:GetModel() Entity.ACF.LegalSeat = true Entity.WireDebugName = Entity.WireDebugName or Entity.VehicleTable.Name or "ACF Legal Vehicle" @@ -70,7 +70,12 @@ hook.Add("OnEntityCreated", "ACF_SeatLegality", function(Entity) end) hook.Add("ACF_IsLegal", "ACF_CheckLegal_SeatLegality", function(Entity) - if ACF.VehicleLegalChecks and Entity:IsVehicle() and not ValidSeatModels[Entity:GetModel()] then + if not ACF.VehicleLegalChecks then return end + if not Entity:IsVehicle() then return end + + local ModelPath = Entity:GetModel() + + if not ValidSeatModels[ModelPath] and ModelPath ~= Entity.VehicleTable.Model then return false, "Bad Seat Model", "This seat model is not on the whitelist." end end) @@ -82,4 +87,4 @@ hook.Add("CanPlayerEnterVehicle", "ACF_SeatLegality", function(Player, Entity) ACF.SendNotify(Player, false, "[ACF] Seat is not legal and is currently disabled.") return false end -end) \ No newline at end of file +end)