From 4bc9ab05375ee898fd6c9ef3f244bb319d2f2a15 Mon Sep 17 00:00:00 2001 From: holysnipz <9103583+holysnipz@users.noreply.github.com> Date: Sun, 18 Feb 2024 04:04:31 +0700 Subject: [PATCH] ChaosMod: Replace hardcoded values with GET_WEAPONTYPE_GROUP call in IsWeaponShotgun (#3653) --- ChaosMod/Util/Weapon.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ChaosMod/Util/Weapon.h b/ChaosMod/Util/Weapon.h index aa1bdc7c0..779950224 100644 --- a/ChaosMod/Util/Weapon.h +++ b/ChaosMod/Util/Weapon.h @@ -1,25 +1,21 @@ #pragma once +#include + using Hash = unsigned long; namespace Util { - // TODO: Maybe CWeaponInfo has some field which can be checked (instead of hardcoding the weapon hashes) inline bool IsWeaponShotgun(Hash weaponHash) { - switch ((long)weaponHash) + static std::unordered_map cachedResults; + static const Hash shotgunGroup = "GROUP_SHOTGUN"_hash; + + if (const auto result = cachedResults.find(weaponHash); result != cachedResults.end()) { - case 487013001: - case 2017895192: - case -1654528753: - case -494615257: - case -1466123874: - case 984333226: - case -275439685: - case 317205821: - return true; + return result->second; } - return false; + return cachedResults.emplace(weaponHash, (GET_WEAPONTYPE_GROUP(weaponHash) == shotgunGroup)).first->second; } } \ No newline at end of file