Skip to content

Commit

Permalink
Rangecard - fix CTD on weapons with invalid configs (#10710)
Browse files Browse the repository at this point in the history
* Rangecard - fix CTD on weapons with invalid configs

* handle in ext

* diagnose / xm157

* fmt

* Update fnc_ballistics_getData.sqf
  • Loading branch information
PabstMirror authored Feb 6, 2025
1 parent c9110b3 commit 41c5c21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions addons/advanced_ballistics/functions/fnc_diagnoseWeapons.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ for "_i" from 0 to (count _cfgWeapons)-1 do {
_WeaponCacheEntry params ["_barrelTwist", "_twistDirection", "_barrelLength"];

private _barrelVelocityShift = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, _vanillaInitialSpeed] call FUNC(calculateBarrelLengthVelocityShift);
if (_barrelLength > 0) then {
private _shiftedMV = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call FUNC(calculateBarrelLengthVelocityShift);
if (_shiftedMV == 0) then { ERROR_2("%1:%2 has length set but invalid mags",_weapon,_magazine)};
};
private _abInitialSpeed = _vanillaInitialSpeed + _barrelVelocityShift;
// --------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion addons/rangecard/functions/fnc_updateRangeCard.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private _useAmmoTemperatureInfluence = (

if (_barrelLength > 0 && _useBarrelLengthInfluence) then {
_muzzleVelocity = [_barrelLength, _ammoConfig select 10, _ammoConfig select 11, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift);
} else {
};
if (_muzzleVelocity == 0) then {
private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "initSpeed");
private _initSpeedCoef = getNumber (configFile >> "CfgWeapons" >> _weaponClass >> "initSpeed");
if (_initSpeedCoef < 0) then {
Expand Down
10 changes: 6 additions & 4 deletions addons/xm157/functions/fnc_ballistics_getData.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ if ((_weaponInfo isEqualTo []) && {_magazineClass != ""}) then {
);

// Get Muzzle Velocity
private _muzzleVelocity = if (_barrelLength > 0 && _useAB) then {
[_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift)
} else {
private _muzzleVelocity = 0;
if (_barrelLength > 0 && _useAB) then {
_muzzleVelocity = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift)
};
if (_muzzleVelocity == 0) then {
private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "initSpeed");
private _initSpeedCoef = getNumber (configFile >> "CfgWeapons" >> _weaponClass >> "initSpeed");
if (_initSpeedCoef < 0) then {
Expand All @@ -52,7 +54,7 @@ if ((_weaponInfo isEqualTo []) && {_magazineClass != ""}) then {
if (_initSpeedCoef > 0) then {
_initSpeed = _initSpeedCoef;
};
_initSpeed
_muzzleVelocity = _initSpeed
};

// Scope Base Angle
Expand Down
3 changes: 3 additions & 0 deletions extension/src/ballistics/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub fn calculate(
bore_height: f64,
ballistic_model: BallisticModel,
) -> f64 {
if *muzzle_velocity <= 0.0 {
return 0.0;
}
let mut zero_angle = 0.0f64;
let delta_time = 1.0 / 100.0f64.max(zero_range);

Expand Down

0 comments on commit 41c5c21

Please sign in to comment.