From 99c345e80d480203800a1785c8588a3d9b340f77 Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 16 Jan 2023 17:56:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8D=E8=AF=BB=E5=8F=96=E6=97=A7?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84=E5=A4=B4=E5=83=8F=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/Miscellaneous/AvatarCacheManager.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)); }