-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ChaosMod: Replace hardcoded values with GET_WEAPONTYPE_GROUP call in …
…IsWeaponShotgun (#3653)
- Loading branch information
Showing
1 changed file
with
8 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |