It is relatively common for mods to list magazine types of other mods in their weapon configs magazines[] array for compatibility. Spawning such a weapon and using OnDebugSpawn() on it to auto-attach a compatible mag with max capacity leads to CTD if any of the listed mags doesn't exist (when the mod providing the mag isn't loaded).
Description
Description
Details
Details
- Severity
- None
- Resolution
- Open
- Reproducibility
- Always
- Operating System
- Windows 10
- Category
- Modding
Steps To Reproduce
Can be replicated with any mod that lists compatible mags of other mods in their weapon configs. Using AK74M from "FOX WEAPONS 2.0" as an example.
- Load game with (only) the weapon mod in question, not any additional mods providing further mags.
- Spawn weapon (e.g. FOX_AK74M)
- Call OnDebugSpawn on spawned weapon.
- Game CTD.
Additional Information
It seems that GetMaxMagazineTypeName never checks if the type of a magazine exists. Since this is a native function, the only workarounds are to not use OnDebugSpawn on affected weapons or override SpawnAttachedMagazine so you can use a custom function to get magazine type with max ammo count (example below).
modded class Weapon_Base { TStringArray GetMagazineTypesValidated() { auto magazines = new TStringArray; ConfigGetTextArray("magazines", magazines); auto magazinesValidated = new TStringArray; foreach (string magazine: magazines) { if (GetGame().ConfigIsExisting("CfgMagazines " + magazine)) magazinesValidated.Insert(magazine); } return magazinesValidated; } string CustomGetMaxMagazineTypeName(int muzzleIndex) { auto magazines = GetMagazineTypesValidated(); int max; string magazineType; foreach (string magazine: magazines) { int count = GetGame().ConfigGetInt("CfgMagazines " + magazine + " count"); if (count > max) magazineType = magazine; } return magazineType; } }