diff --git a/include/itemtypes.hpp b/include/itemtypes.hpp index 306abd5f..f20b57dd 100644 --- a/include/itemtypes.hpp +++ b/include/itemtypes.hpp @@ -7,7 +7,7 @@ #pragma once -#include +#include #include #include @@ -139,8 +139,8 @@ public: void RegisterItem(std::string modelpath, k_EItemType type); k_EItemType GetItemType(CachedEntity *entity); - std::unordered_map models; - std::unordered_map map; + std::map models; + std::map map; }; class ItemManager @@ -151,10 +151,10 @@ public: void RegisterSpecialMapping(ItemCheckerFn fn, k_EItemType type); k_EItemType GetItemType(CachedEntity *ent); - std::unordered_map special_map; + std::map special_map; std::vector specials; ItemModelMapper mapper_special; ItemModelMapper mapper; }; -extern ItemManager g_ItemManager; +extern ItemManager g_ItemManager; \ No newline at end of file diff --git a/src/itemtypes.cpp b/src/itemtypes.cpp index d1517b73..6f3d0370 100644 --- a/src/itemtypes.cpp +++ b/src/itemtypes.cpp @@ -167,32 +167,54 @@ void ItemManager::RegisterModelMapping(std::string path, k_EItemType type) void ItemManager::RegisterSpecialMapping(ItemCheckerFn fn, k_EItemType type) { - special_map[fn] = type; + special_map.emplace(fn, type); } k_EItemType ItemManager::GetItemType(CachedEntity *ent) { + for (const auto &it : specials) + { + const auto type = it(ent); + if (type != ITEM_NONE) + return type; + } + for (const auto &it : special_map) + { + if (it.first(ent)) + return it.second; + } return mapper.GetItemType(ent); } void ItemModelMapper::RegisterItem(std::string modelpath, k_EItemType type) { - models[modelpath] = type; + models.emplace(modelpath, type); } k_EItemType ItemModelMapper::GetItemType(CachedEntity *entity) { - const uintptr_t model = (uint64_t) RAW_ENT(entity)->GetModel(); - auto find = map.find(model); - if (find != map.end()) - return find->second; + const uintptr_t model = (uintptr_t) RAW_ENT(entity)->GetModel(); + for (const auto &it : map) + { + if (it.first == model) + return it.second; + } std::string path(g_IModelInfo->GetModelName((const model_t *) model)); - bool set = false; - auto find2 = models.find(path); - if (find2 != models.end()) - set = true; + bool set = false; + for (const auto &it : models) + { + // logging::Info("comparing [%s] to [%s]", path.c_str(), + // it.first.c_str()); + if (it.first == path) + { + // logging::Info("Found %s!", path.c_str()); + map.emplace(model, it.second); + set = true; + break; + } + } if (!set) - map[model] = k_EItemType::ITEM_NONE; + map.emplace(model, k_EItemType::ITEM_NONE); return k_EItemType::ITEM_NONE; }