From: bones_was_here Date: Wed, 23 Sep 2020 14:05:51 +0000 (+1000) Subject: q3compat: Fix null function crash when a weapon has no ammo_type X-Git-Tag: xonotic-v0.8.5~352^2~27 X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=1dba0805c66aa6505f1cc3ebbfdb23b6aff6781f;p=xonotic%2Fxonotic-data.pk3dir.git q3compat: Fix null function crash when a weapon has no ammo_type --- diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 5c6ec494a..26f89cad5 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -65,7 +65,7 @@ const int ITS_GLOW = BIT(6); .float invincible_finished; // ditto #define spawnfunc_body(item) \ - if (!Item_IsDefinitionAllowed(item)) \ + if (!(item) || !Item_IsDefinitionAllowed(item)) \ { \ startitem_failed = true; \ delete(this); \ diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 606090db3..5de760d48 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -254,14 +254,15 @@ entity GetAmmoItem(int ammotype) #ifdef SVQC int GetAmmoConsumptionPrimary(string netname) // Returns ammo consumed per shot by the primary/default fire mode +// Returns 0 if the netname has no ammo cvar { switch (netname) { - case "arc": return cvar("g_balance_arc_beam_ammo"); - case "devastator": return cvar("g_balance_devastator_ammo"); - case "machinegun": return cvar("g_balance_machinegun_sustained_ammo"); - case "minelayer": return cvar("g_balance_minelayer_ammo"); - case "seeker": return cvar("g_balance_seeker_tag_ammo"); + case "arc": return autocvar_g_balance_arc_beam_ammo; + case "devastator": return autocvar_g_balance_devastator_ammo; + case "machinegun": return autocvar_g_balance_machinegun_sustained_ammo; + case "minelayer": return autocvar_g_balance_minelayer_ammo; + case "seeker": return autocvar_g_balance_seeker_tag_ammo; default: return cvar(strcat("g_balance_", netname, "_primary_ammo")); } } diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index 85219b1c8..f850b84b6 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -78,6 +78,7 @@ SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX) // BFG -> Crylink || Fireball SPAWNFUNC_Q3_COND(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL) + // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by spawnfunc_body // grappling hook -> hook SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK)