Skip to content

Commit

Permalink
ChaosMod: Replace hardcoded values with GET_WEAPONTYPE_GROUP call in …
Browse files Browse the repository at this point in the history
…IsWeaponShotgun (#3653)
  • Loading branch information
holysnipz authored Feb 17, 2024
1 parent 2a1a3a8 commit 4bc9ab0
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions ChaosMod/Util/Weapon.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
#pragma once

#include <unordered_map>

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<Hash, bool> 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;
}
}

0 comments on commit 4bc9ab0

Please sign in to comment.