diff --git a/src/game/bondgun.c b/src/game/bondgun.c index ac599ade4..e2920d53f 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -6320,9 +6320,15 @@ void bgunDisarm(struct prop *attackerprop) for (i = 0; i < 2; i++) { struct weaponfunc *func = gsetGetWeaponFunction(&player->hands[i].gset); +#ifdef AVOID_UB + if (func && (func->type & 0xff) == INVENTORYFUNCTYPE_THROW + && player->hands[i].state == HANDSTATE_ATTACK + && player->hands[i].stateminor == HANDSTATEMINOR_ATTACK_THROW_0) { +#else if ((func->type & 0xff) == INVENTORYFUNCTYPE_THROW && player->hands[i].state == HANDSTATE_ATTACK && player->hands[i].stateminor == HANDSTATEMINOR_ATTACK_THROW_0) { +#endif drop = false; bgunCreateThrownProjectile(i + 2, &player->hands[i].gset); } diff --git a/src/game/game_0b0fd0.c b/src/game/game_0b0fd0.c index 8e56c4aef..8c7953ccf 100644 --- a/src/game/game_0b0fd0.c +++ b/src/game/game_0b0fd0.c @@ -56,6 +56,12 @@ struct weaponfunc *gsetGetWeaponFunction(struct gset *gset) struct weapon *weapon = g_Weapons[gset->weaponnum]; if (weapon) { +#ifdef AVOID_UB + // SuperDragon grenades have FUNC_2, so this can happen + if (gset->weaponfunc > FUNC_SECONDARY) { + return NULL; + } +#endif return weapon->functions[gset->weaponfunc]; } diff --git a/src/game/prop.c b/src/game/prop.c index 1daed88a7..786a64db1 100644 --- a/src/game/prop.c +++ b/src/game/prop.c @@ -1191,7 +1191,11 @@ void handInflictMeleeDamage(s32 handnum, struct gset *gset, bool arg2) struct model *model; struct weaponfunc *func = gsetGetWeaponFunction(gset); +#ifdef AVOID_UB + if (func && (func->type & 0xff) == INVENTORYFUNCTYPE_MELEE) { +#else if ((func->type & 0xff) == INVENTORYFUNCTYPE_MELEE) { +#endif struct weaponfunc_melee *meleefunc = (struct weaponfunc_melee *)func; rangelimit = meleefunc->range; }