From 0fa88b0260bc6691208d6d8f48cda822a9674f8e Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 1 Feb 2024 19:07:51 +0100 Subject: [PATCH] Small SVF refactor --- SilentPatch/SVF.cpp | 7 +++++-- SilentPatch/SVF.h | 2 +- SilentPatchSA/VehicleSA.cpp | 7 ++++--- SilentPatchVC/SilentPatchVC.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/SilentPatch/SVF.cpp b/SilentPatch/SVF.cpp index 7cfa802..a9e7849 100644 --- a/SilentPatch/SVF.cpp +++ b/SilentPatch/SVF.cpp @@ -127,12 +127,15 @@ namespace SVF } ) != results.second; } - std::function ForAllModelFeatures( int32_t modelID, std::function pred ) + std::function ForAllModelFeatures( int32_t modelID, std::function pred ) { auto results = specialVehFeatures.equal_range( modelID ); for ( auto it = results.first; it != results.second; ++it ) { - pred(std::get(it->second)); + if (!pred(std::get(it->second))) + { + break; + } } return std::move(pred); } diff --git a/SilentPatch/SVF.h b/SilentPatch/SVF.h index 138849f..83691ac 100644 --- a/SilentPatch/SVF.h +++ b/SilentPatch/SVF.h @@ -47,5 +47,5 @@ namespace SVF void DeleteFeature( int32_t cookie ); void DisableStockVehiclesForFeature( Feature feature ); bool ModelHasFeature( int32_t modelID, Feature feature ); - std::function ForAllModelFeatures( int32_t modelID, std::function pred ); + std::function ForAllModelFeatures( int32_t modelID, std::function pred ); }; \ No newline at end of file diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 4261e2b..4637ff1 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -66,18 +66,19 @@ bool __stdcall CheckDoubleRWheelsList( void* modelInfo, uint8_t* handlingData ) bool foundFeature = false; bool featureStatus = false; SVF::ForAllModelFeatures( modelID, [&]( SVF::Feature f ) { - if ( foundFeature ) return; - if ( f == SVF::Feature::_INTERNAL_FORCE_DOUBLE_RWHEELS_OFF ) { foundFeature = true; featureStatus = false; + return false; } - else if ( f == SVF::Feature::_INTERNAL_FORCE_DOUBLE_RWHEELS_ON ) + if ( f == SVF::Feature::_INTERNAL_FORCE_DOUBLE_RWHEELS_ON ) { foundFeature = true; featureStatus = true; + return false; } + return true; } ); if ( !foundFeature ) { diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index aba1689..79a1b45 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -399,15 +399,17 @@ namespace FBISirenCoronaFix if ( f >= SVF::Feature::FBI_RANCHER_SIREN && f <= SVF::Feature::VICE_CHEETAH_SIREN ) { foundFeature = f; + return false; } + return true; } ); if ( foundFeature != SVF::Feature::NO_FEATURE ) { if ( foundFeature != SVF::Feature::VICE_CHEETAH_SIREN ) { - const CVector FBICAR_SIREN_POS = CVector(0.4f, 0.8f, 0.25f); - const CVector FBIRANCH_SIREN_POS = CVector(0.5f, 1.12f, 0.5f); + constexpr CVector FBICAR_SIREN_POS(0.4f, 0.8f, 0.25f); + constexpr CVector FBIRANCH_SIREN_POS(0.5f, 1.12f, 0.5f); overridePosition = true; vecOverridePosition = foundFeature == SVF::Feature::FBI_WASHINGTON_SIREN ? FBICAR_SIREN_POS : FBIRANCH_SIREN_POS;