diff --git a/src/MaaCore/Config/Miscellaneous/AvatarCacheManager.cpp b/src/MaaCore/Config/Miscellaneous/AvatarCacheManager.cpp index 6b543c92a6..c6f2736d84 100644 --- a/src/MaaCore/Config/Miscellaneous/AvatarCacheManager.cpp +++ b/src/MaaCore/Config/Miscellaneous/AvatarCacheManager.cpp @@ -3,6 +3,7 @@ #include "BattleDataConfig.h" #include "Utils/ImageIo.hpp" #include "Utils/Logger.hpp" +#include "../TaskData.h" bool asst::AvatarCacheManager::load(const std::filesystem::path& path) { @@ -15,6 +16,8 @@ bool asst::AvatarCacheManager::load(const std::filesystem::path& path) return true; } + const auto& [_, _, w, h] = Task.get("BattleOperAvatar")->rect_move; + for (const auto& entry : std::filesystem::directory_iterator(path)) { if (!entry.is_regular_file()) { continue; @@ -27,12 +30,19 @@ bool asst::AvatarCacheManager::load(const std::filesystem::path& path) Log.warn("unknown oper", name); continue; } + Log.trace(filepath); cv::Mat avatar = asst::imread(filepath); + if (avatar.empty()) { Log.warn("failed to read", filepath); continue; } + if (avatar.cols > w || avatar.rows > h) { + Log.warn("avatar size too large", filepath); + continue; + } + m_avatars[role].emplace(name, std::move(avatar)); }