Page MenuHomeFeedback Tracker

GetMaxMagazineTypeName CTDs if some magazine types do not exist
Assigned, NormalPublic

Description

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).

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.

  1. Load game with (only) the weapon mod in question, not any additional mods providing further mags.
  2. Spawn weapon (e.g. FOX_AK74M)
  3. Call OnDebugSpawn on spawned weapon.
  4. 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;
	}
}

Event Timeline

lava76 created this task.Feb 12 2023, 1:41 PM
lava76 edited Additional Information. (Show Details)Feb 12 2023, 1:44 PM
lava76 edited Additional Information. (Show Details)
lava76 changed Category from Scripting to Modding.Feb 12 2023, 2:30 PM
Geez changed the task status from New to Assigned.Feb 13 2023, 9:44 AM