From d48d7c94d91edcb3c045eff02e31ee3b633982d6 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 11 Dec 2021 22:10:09 +0800 Subject: [PATCH 01/13] =?UTF-8?q?chore.=E5=88=9D=E6=AD=A5=E5=AE=8C?= =?UTF-8?q?=E6=88=90cmake=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + CMakeLists.txt | 24 ++ src/MeoAssistance/AbstractConfiger.cpp | 2 +- src/MeoAssistance/Assistance.cpp | 2 +- src/MeoAssistance/AsstCaller.cpp | 430 ++++++++++++------------ src/MeoAssistance/AsstMsg.h | 2 +- src/MeoAssistance/GeneralConfiger.cpp | 4 +- src/MeoAssistance/InfrastConfiger.cpp | 4 +- src/MeoAssistance/ItemConfiger.cpp | 4 +- src/MeoAssistance/MeoAssistance.vcxproj | 4 +- src/MeoAssistance/PenguinPack.cpp | 4 +- src/MeoAssistance/PenguinUploader.cpp | 4 +- src/MeoAssistance/ProcessTask.cpp | 4 +- src/MeoAssistance/RecruitConfiger.cpp | 6 +- src/MeoAssistance/Resource.cpp | 4 +- src/MeoAssistance/TaskData.cpp | 362 ++++++++++---------- src/MeoAssistance/UserConfiger.cpp | 4 +- src/MeoAssistance/UserConfiger.h | 2 +- 18 files changed, 446 insertions(+), 421 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 95e687993b..b07366bc8f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.d # Compiled Object files +build *.slo *.lo *.o diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..2df6a84cc4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 2.8) +project(MeoAsst) + +include_directories(include 3rdparty/include) +aux_source_directory(src/MeoAssistance SRC) +add_definitions(-DMEO_DLL_EXPORTS) + +add_compile_options("$<$:/utf-8>") +add_compile_options("$<$:/utf-8>") +add_compile_options("$<$:/MP>") +add_compile_options("$<$:/MP>") + +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") +set(CMAKE_CXX_STANDARD 17) + +add_library(MeoAsst_LIB SHARED ${SRC}) + +find_library(Opencv_LIB NAMES opencv_world453 PATHS 3rdparty/lib) +find_library(OcrLite_LIB NAMES OcrLiteOnnx PATHS 3rdparty/lib) +find_library(Penguin_LIB NAMES penguin-stats-recognize PATHS 3rdparty/lib) +find_library(MeoJson_LIB NAMES libmeojson PATHS 3rdparty/lib) + +target_link_libraries(MeoAsst_LIB ${Opencv_LIB} ${OcrLite_LIB} ${Penguin_LIB} ${MeoJson_LIB}) diff --git a/src/MeoAssistance/AbstractConfiger.cpp b/src/MeoAssistance/AbstractConfiger.cpp index bad9bb4391..d375f6d319 100644 --- a/src/MeoAssistance/AbstractConfiger.cpp +++ b/src/MeoAssistance/AbstractConfiger.cpp @@ -1,6 +1,6 @@ #include "AbstractConfiger.h" -#include +#include #include "AsstUtils.hpp" diff --git a/src/MeoAssistance/Assistance.cpp b/src/MeoAssistance/Assistance.cpp index a6c2cdb6e5..fee548ff25 100644 --- a/src/MeoAssistance/Assistance.cpp +++ b/src/MeoAssistance/Assistance.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include "AsstUtils.hpp" diff --git a/src/MeoAssistance/AsstCaller.cpp b/src/MeoAssistance/AsstCaller.cpp index b89239ce28..bfc34a0d4c 100644 --- a/src/MeoAssistance/AsstCaller.cpp +++ b/src/MeoAssistance/AsstCaller.cpp @@ -1,252 +1,252 @@ -#include "AsstCaller.h" - -#include - -#include - -#include "Assistance.h" -#include "AsstDef.h" -#include "AsstUtils.hpp" +#include "AsstCaller.h" + +#include + +#include + +#include "Assistance.h" +#include "AsstDef.h" +#include "AsstUtils.hpp" #include "Version.h" -#if 0 -#if _MSC_VER -// Win32平台下Dll的入口 -BOOL APIENTRY DllMain(HINSTANCE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved -) -{ - UNREFERENCED_PARAMETER(hModule); - UNREFERENCED_PARAMETER(lpReserved); - switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} -#elif VA_GNUC - -#endif -#endif - -AsstCallback _callback = nullptr; - -void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg) -{ - _callback(static_cast(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg); -} - -void* AsstCreate(const char* dirname) -{ - try { - return new asst::Assistance(dirname); - } - catch (...) { - return nullptr; - } -} - -void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) -{ - try { - // 创建多实例回调会有问题,有空再慢慢整 - _callback = callback; - return new asst::Assistance(dirname, CallbackTrans, custom_arg); - } - catch (...) { - return nullptr; - } -} - -void AsstDestroy(void* p_asst) -{ - if (p_asst == nullptr) { - return; - } - - delete p_asst; - p_asst = nullptr; -} - -bool AsstCatchDefault(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_default(); -} - -bool AsstCatchEmulator(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_emulator(); -} - -bool AsstCatchCustom(void* p_asst, const char* address) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_custom(address); -} - -bool AsstCatchFake(void* p_asst) -{ -#ifdef LOG_TRACE - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_fake(); -#else - return false; -#endif // LOG_TRACE -} - -bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times) -{ - if (p_asst == nullptr) { - return false; +#if 0 +#if _MSC_VER +// Win32平台下Dll的入口 +BOOL APIENTRY DllMain(HINSTANCE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved +) +{ + UNREFERENCED_PARAMETER(hModule); + UNREFERENCED_PARAMETER(lpReserved); + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; } - asst::Assistance* ptr = (asst::Assistance*)p_asst; - - return ptr->append_fight(max_mecidine, max_stone, max_times); + return TRUE; +} +#elif VA_GNUC + +#endif +#endif + +AsstCallback _callback = nullptr; + +void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg) +{ + _callback(static_cast(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg); +} + +void* AsstCreate(const char* dirname) +{ + try { + return new asst::Assistance(dirname); + } + catch (...) { + return nullptr; + } +} + +void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) +{ + try { + // 创建多实例回调会有问题,有空再慢慢整 + _callback = callback; + return new asst::Assistance(dirname, CallbackTrans, custom_arg); + } + catch (...) { + return nullptr; + } +} + +void AsstDestroy(void* p_asst) +{ + if (p_asst == nullptr) { + return; + } + + delete p_asst; + p_asst = nullptr; +} + +bool AsstCatchDefault(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_default(); +} + +bool AsstCatchEmulator(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_emulator(); +} + +bool AsstCatchCustom(void* p_asst, const char* address) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_custom(address); +} + +bool AsstCatchFake(void* p_asst) +{ +#ifdef LOG_TRACE + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_fake(); +#else + return false; +#endif // LOG_TRACE +} + +bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times) +{ + if (p_asst == nullptr) { + return false; + } + asst::Assistance* ptr = (asst::Assistance*)p_asst; + + return ptr->append_fight(max_mecidine, max_stone, max_times); } bool AsstAppendAward(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - +{ + if (p_asst == nullptr) { + return false; + } + return ((asst::Assistance*)p_asst)->append_award(); -} - -bool AsstAppendVisit(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->append_visit(); +} + +bool AsstAppendVisit(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->append_visit(); } bool AsstAppendMall(void* p_asst, bool with_shopping) { - if (p_asst == nullptr) { - return false; - } - + if (p_asst == nullptr) { + return false; + } + return ((asst::Assistance*)p_asst)->append_mall(with_shopping); -} - -//bool AsstAppendProcessTask(void* p_asst, const char* task) -//{ -// if (p_asst == nullptr) { -// return false; -// } -// -// return ((asst::Assistance*)p_asst)->append_process_task(task); +} + +//bool AsstAppendProcessTask(void* p_asst, const char* task) +//{ +// if (p_asst == nullptr) { +// return false; +// } +// +// return ((asst::Assistance*)p_asst)->append_process_task(task); //} -bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time) -{ - if (p_asst == nullptr) { - return false; - } - std::vector level_vector; - level_vector.assign(select_level, select_level + required_len); - return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time); -} - -bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) -{ - if (p_asst == nullptr) { - return false; - } - std::vector order_vector; - order_vector.assign(order, order + order_size); - +bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time) +{ + if (p_asst == nullptr) { + return false; + } + std::vector level_vector; + level_vector.assign(select_level, select_level + required_len); + return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time); +} + +bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) +{ + if (p_asst == nullptr) { + return false; + } + std::vector order_vector; + order_vector.assign(order, order + order_size); + return ((asst::Assistance*)p_asst)-> append_infrast( static_cast(work_mode), order_vector, uses_of_drones, - dorm_threshold); + dorm_threshold); } bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh) -{ - if (p_asst == nullptr) { - return false; - } - std::vector required_vector; +{ + if (p_asst == nullptr) { + return false; + } + std::vector required_vector; required_vector.assign(select_level, select_level + select_len); - std::vector confirm_vector; + std::vector confirm_vector; confirm_vector.assign(confirm_level, confirm_level + confirm_len); - + return ((asst::Assistance*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh); -} - +} + bool AsstStart(void* p_asst) { - if (p_asst == nullptr) { - return false; - } - + if (p_asst == nullptr) { + return false; + } + return ((asst::Assistance*)p_asst)->start(); } -bool AsstStop(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->stop(); +bool AsstStop(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->stop(); } -bool MEOAPI AsstSetPenguinId(void* p_asst, const char* id) +bool AsstSetPenguinId(void* p_asst, const char* id) { - if (p_asst == nullptr) { - return false; - } + if (p_asst == nullptr) { + return false; + } auto ptr = (asst::Assistance*)p_asst; ptr->set_penguin_id(id); return true; -} - -//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value) -//{ -// if (p_asst == nullptr) { -// return false; -// } -// -// return ((asst::Assistance*)p_asst)->set_param(type, param, value); -//} - -const char* AsstGetVersion() -{ - return asst::Version; -} - -bool AsstAppendDebug(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } -#if LOG_TRACE - return ((asst::Assistance*)p_asst)->append_debug(); -#else - return false; -#endif // LOG_TRACE +} + +//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value) +//{ +// if (p_asst == nullptr) { +// return false; +// } +// +// return ((asst::Assistance*)p_asst)->set_param(type, param, value); +//} + +const char* AsstGetVersion() +{ + return asst::Version; +} + +bool AsstAppendDebug(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } +#if LOG_TRACE + return ((asst::Assistance*)p_asst)->append_debug(); +#else + return false; +#endif // LOG_TRACE } diff --git a/src/MeoAssistance/AsstMsg.h b/src/MeoAssistance/AsstMsg.h index ffcfbcd243..8e6dc1baa3 100644 --- a/src/MeoAssistance/AsstMsg.h +++ b/src/MeoAssistance/AsstMsg.h @@ -5,7 +5,7 @@ #include #include -#include +#include namespace asst { diff --git a/src/MeoAssistance/GeneralConfiger.cpp b/src/MeoAssistance/GeneralConfiger.cpp index a6e18843f2..22aff5f5cb 100644 --- a/src/MeoAssistance/GeneralConfiger.cpp +++ b/src/MeoAssistance/GeneralConfiger.cpp @@ -1,6 +1,6 @@ #include "GeneralConfiger.h" -#include +#include bool asst::GeneralConfiger::parse(const json::value& json) { @@ -52,4 +52,4 @@ bool asst::GeneralConfiger::parse(const json::value& json) } return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/InfrastConfiger.cpp b/src/MeoAssistance/InfrastConfiger.cpp index ae8246be5a..261a7f226e 100644 --- a/src/MeoAssistance/InfrastConfiger.cpp +++ b/src/MeoAssistance/InfrastConfiger.cpp @@ -1,6 +1,6 @@ #include "InfrastConfiger.h" -#include +#include bool asst::InfrastConfiger::parse(const json::value& json) { @@ -209,4 +209,4 @@ bool asst::InfrastConfiger::parse(const json::value& json) m_facilities_info.emplace(facility_name, std::move(fac_info)); } return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/ItemConfiger.cpp b/src/MeoAssistance/ItemConfiger.cpp index 2a05ceafec..c180ce6f85 100644 --- a/src/MeoAssistance/ItemConfiger.cpp +++ b/src/MeoAssistance/ItemConfiger.cpp @@ -1,6 +1,6 @@ #include "ItemConfiger.h" -#include +#include bool asst::ItemConfiger::parse(const json::value& json) { @@ -9,4 +9,4 @@ bool asst::ItemConfiger::parse(const json::value& json) m_item_name.emplace(id, std::move(name)); } return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/MeoAssistance.vcxproj b/src/MeoAssistance/MeoAssistance.vcxproj index 7189466dca..8f2790fad5 100644 --- a/src/MeoAssistance/MeoAssistance.vcxproj +++ b/src/MeoAssistance/MeoAssistance.vcxproj @@ -150,12 +150,12 @@ false - $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(SolutionDir)3rdparty\include\meojson;$(SolutionDir)\3rdparty\include\opencv;$(SolutionDir)\3rdparty\include\opencv2;$(SolutionDir)3drPart\include\OcrLiteNcnn;;$(IncludePath) + $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) true - $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(SolutionDir)3rdparty\include\meojson;$(SolutionDir)3rdparty\include\opencv;$(SolutionDir)3rdparty\include\opencv2;$(SolutionDir)3drPart\include\OcrLiteNcnn;$(IncludePath) + $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) diff --git a/src/MeoAssistance/PenguinPack.cpp b/src/MeoAssistance/PenguinPack.cpp index 59a7a0233c..395099af6a 100644 --- a/src/MeoAssistance/PenguinPack.cpp +++ b/src/MeoAssistance/PenguinPack.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include namespace penguin { @@ -92,4 +92,4 @@ bool asst::PenguinPack::load_templ(const std::string& item_id, const std::string penguin::load_templ(item_id.c_str(), buf.data(), buf.size()); return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/PenguinUploader.cpp b/src/MeoAssistance/PenguinUploader.cpp index ba9f05439c..8bc3ef9f73 100644 --- a/src/MeoAssistance/PenguinUploader.cpp +++ b/src/MeoAssistance/PenguinUploader.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include "AsstUtils.hpp" #include "Logger.hpp" @@ -96,4 +96,4 @@ bool asst::PenguinUploader::request_penguin(const std::string& body) ::CloseHandle(pipe_read); ::CloseHandle(pipe_child_write); return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/ProcessTask.cpp b/src/MeoAssistance/ProcessTask.cpp index 21bb85b74a..9304882410 100644 --- a/src/MeoAssistance/ProcessTask.cpp +++ b/src/MeoAssistance/ProcessTask.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include "AsstUtils.hpp" #include "Controller.h" @@ -208,4 +208,4 @@ void asst::ProcessTask::exec_swipe_task(ProcessTaskAction action) default: // 走不到这里,TODO 报个错 break; } -} +} \ No newline at end of file diff --git a/src/MeoAssistance/RecruitConfiger.cpp b/src/MeoAssistance/RecruitConfiger.cpp index 6a661c66a4..30fcae6167 100644 --- a/src/MeoAssistance/RecruitConfiger.cpp +++ b/src/MeoAssistance/RecruitConfiger.cpp @@ -2,7 +2,7 @@ #include -#include +#include bool asst::RecruitConfiger::parse(const json::value& json) { @@ -31,7 +31,7 @@ bool asst::RecruitConfiger::parse(const json::value& json) // 按干员等级排个序 std::sort(m_all_opers.begin(), m_all_opers.end(), [](const auto& lhs, const auto& rhs) -> bool { return lhs.level > rhs.level; - }); + }); return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/Resource.cpp b/src/MeoAssistance/Resource.cpp index 1aa2c91251..39c47fb31d 100644 --- a/src/MeoAssistance/Resource.cpp +++ b/src/MeoAssistance/Resource.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include "AsstDef.h" @@ -78,4 +78,4 @@ bool asst::Resource::load(const std::string& dir) } return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/TaskData.cpp b/src/MeoAssistance/TaskData.cpp index 81a1f45084..bea0e55e00 100644 --- a/src/MeoAssistance/TaskData.cpp +++ b/src/MeoAssistance/TaskData.cpp @@ -1,32 +1,32 @@ -#include "TaskData.h" - -#include - -#include - -#include "AsstDef.h" -#include "GeneralConfiger.h" -#include "TemplResource.h" - -const std::shared_ptr asst::TaskData::get(const std::string& name) const noexcept -{ - if (auto iter = m_all_tasks_info.find(name); - iter != m_all_tasks_info.cend()) { - return iter->second; - } - else { - return nullptr; - } -} - -const std::unordered_set& asst::TaskData::get_templ_required() const noexcept -{ - return m_templ_required; -} - -std::shared_ptr asst::TaskData::get(std::string name) -{ - return m_all_tasks_info[std::move(name)]; +#include "TaskData.h" + +#include + +#include + +#include "AsstDef.h" +#include "GeneralConfiger.h" +#include "TemplResource.h" + +const std::shared_ptr asst::TaskData::get(const std::string& name) const noexcept +{ + if (auto iter = m_all_tasks_info.find(name); + iter != m_all_tasks_info.cend()) { + return iter->second; + } + else { + return nullptr; + } +} + +const std::unordered_set& asst::TaskData::get_templ_required() const noexcept +{ + return m_templ_required; +} + +std::shared_ptr asst::TaskData::get(std::string name) +{ + return m_all_tasks_info[std::move(name)]; } void asst::TaskData::clear_cache() noexcept @@ -34,125 +34,125 @@ void asst::TaskData::clear_cache() noexcept for (auto&& [name, ptr] : m_all_tasks_info) { ptr->region_of_appeared = Rect(); } -} - -bool asst::TaskData::parse(const json::value& json) -{ - for (const auto& [name, task_json] : json.as_object()) { - std::string algorithm_str = task_json.get("algorithm", "matchtemplate"); - std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower); - AlgorithmType algorithm = AlgorithmType::Invaild; - if (algorithm_str == "matchtemplate") { - algorithm = AlgorithmType::MatchTemplate; - } - else if (algorithm_str == "justreturn") { - algorithm = AlgorithmType::JustReturn; - } - else if (algorithm_str == "ocrdetect") { - algorithm = AlgorithmType::OcrDetect; - } - // CompareHist是MatchTemplate的衍生算法,不应作为单独的配置参数出现 - // else if (algorithm_str == "comparehist") {} - else { - m_last_error = "algorithm error " + algorithm_str; - return false; - } - - std::shared_ptr task_info_ptr = nullptr; - switch (algorithm) { - case AlgorithmType::JustReturn: - task_info_ptr = std::make_shared(); - break; - case AlgorithmType::MatchTemplate: { - auto match_task_info_ptr = std::make_shared(); - match_task_info_ptr->templ_name = task_json.get("template", name + ".png"); - m_templ_required.emplace(match_task_info_ptr->templ_name); - - match_task_info_ptr->templ_threshold = task_json.get( - "templThreshold", TemplThresholdDefault); - match_task_info_ptr->special_threshold = task_json.get( - "specialThreshold", 0); - if (task_json.exist("maskRange")) { - match_task_info_ptr->mask_range = std::make_pair( - task_json.at("maskRange")[0].as_integer(), - task_json.at("maskRange")[1].as_integer()); - } - - task_info_ptr = match_task_info_ptr; - } break; - case AlgorithmType::OcrDetect: { - auto ocr_task_info_ptr = std::make_shared(); - for (const json::value& text : task_json.at("text").as_array()) { - ocr_task_info_ptr->text.emplace_back(text.as_string()); - } - ocr_task_info_ptr->need_full_match = task_json.get("need_match", false); - if (task_json.exist("ocrReplace")) { - for (const json::value& rep : task_json.at("ocrReplace").as_array()) { - ocr_task_info_ptr->replace_map.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string()); - } - } - task_info_ptr = ocr_task_info_ptr; - } break; - } - task_info_ptr->cache = task_json.get("cache", true); - task_info_ptr->algorithm = algorithm; - task_info_ptr->name = name; - std::string action = task_json.get("action", std::string()); - std::transform(action.begin(), action.end(), action.begin(), ::tolower); - if (action == "clickself") { - task_info_ptr->action = ProcessTaskAction::ClickSelf; - } - else if (action == "clickrand") { - task_info_ptr->action = ProcessTaskAction::ClickRand; - } - else if (action == "donothing" || action.empty()) { - task_info_ptr->action = ProcessTaskAction::DoNothing; - } - else if (action == "stop") { - task_info_ptr->action = ProcessTaskAction::Stop; - } - else if (action == "clickrect") { - task_info_ptr->action = ProcessTaskAction::ClickRect; - const json::value& rect_json = task_json.at("specificRect"); - task_info_ptr->specific_rect = Rect( - rect_json[0].as_integer(), - rect_json[1].as_integer(), - rect_json[2].as_integer(), - rect_json[3].as_integer()); - } - else if (action == "stagedrops") { - task_info_ptr->action = ProcessTaskAction::StageDrops; - } - else if (action == "swipetotheleft") { - task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft; - } - else if (action == "swipetotheright") { - task_info_ptr->action = ProcessTaskAction::SwipeToTheRight; - } - else { - m_last_error = "Task: " + name + " error: " + action; - return false; - } - - task_info_ptr->max_times = task_json.get("maxTimes", INT_MAX); - if (task_json.exist("exceededNext")) { - const json::array& excceed_next_arr = task_json.at("exceededNext").as_array(); - for (const json::value& excceed_next : excceed_next_arr) { - task_info_ptr->exceeded_next.emplace_back(excceed_next.as_string()); - } - } - else { - task_info_ptr->exceeded_next.emplace_back("Stop"); - } - task_info_ptr->pre_delay = task_json.get("preDelay", 0); - task_info_ptr->rear_delay = task_json.get("rearDelay", 0); - if (task_json.exist("reduceOtherTimes")) { - const json::array& reduce_arr = task_json.at("reduceOtherTimes").as_array(); - for (const json::value& reduce : reduce_arr) { - task_info_ptr->reduce_other_times.emplace_back(reduce.as_string()); - } - } - if (task_json.exist("roi")) { +} + +bool asst::TaskData::parse(const json::value& json) +{ + for (const auto& [name, task_json] : json.as_object()) { + std::string algorithm_str = task_json.get("algorithm", "matchtemplate"); + std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower); + AlgorithmType algorithm = AlgorithmType::Invaild; + if (algorithm_str == "matchtemplate") { + algorithm = AlgorithmType::MatchTemplate; + } + else if (algorithm_str == "justreturn") { + algorithm = AlgorithmType::JustReturn; + } + else if (algorithm_str == "ocrdetect") { + algorithm = AlgorithmType::OcrDetect; + } + // CompareHist是MatchTemplate的衍生算法,不应作为单独的配置参数出现 + // else if (algorithm_str == "comparehist") {} + else { + m_last_error = "algorithm error " + algorithm_str; + return false; + } + + std::shared_ptr task_info_ptr = nullptr; + switch (algorithm) { + case AlgorithmType::JustReturn: + task_info_ptr = std::make_shared(); + break; + case AlgorithmType::MatchTemplate: { + auto match_task_info_ptr = std::make_shared(); + match_task_info_ptr->templ_name = task_json.get("template", name + ".png"); + m_templ_required.emplace(match_task_info_ptr->templ_name); + + match_task_info_ptr->templ_threshold = task_json.get( + "templThreshold", TemplThresholdDefault); + match_task_info_ptr->special_threshold = task_json.get( + "specialThreshold", 0); + if (task_json.exist("maskRange")) { + match_task_info_ptr->mask_range = std::make_pair( + task_json.at("maskRange")[0].as_integer(), + task_json.at("maskRange")[1].as_integer()); + } + + task_info_ptr = match_task_info_ptr; + } break; + case AlgorithmType::OcrDetect: { + auto ocr_task_info_ptr = std::make_shared(); + for (const json::value& text : task_json.at("text").as_array()) { + ocr_task_info_ptr->text.emplace_back(text.as_string()); + } + ocr_task_info_ptr->need_full_match = task_json.get("need_match", false); + if (task_json.exist("ocrReplace")) { + for (const json::value& rep : task_json.at("ocrReplace").as_array()) { + ocr_task_info_ptr->replace_map.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string()); + } + } + task_info_ptr = ocr_task_info_ptr; + } break; + } + task_info_ptr->cache = task_json.get("cache", true); + task_info_ptr->algorithm = algorithm; + task_info_ptr->name = name; + std::string action = task_json.get("action", std::string()); + std::transform(action.begin(), action.end(), action.begin(), ::tolower); + if (action == "clickself") { + task_info_ptr->action = ProcessTaskAction::ClickSelf; + } + else if (action == "clickrand") { + task_info_ptr->action = ProcessTaskAction::ClickRand; + } + else if (action == "donothing" || action.empty()) { + task_info_ptr->action = ProcessTaskAction::DoNothing; + } + else if (action == "stop") { + task_info_ptr->action = ProcessTaskAction::Stop; + } + else if (action == "clickrect") { + task_info_ptr->action = ProcessTaskAction::ClickRect; + const json::value& rect_json = task_json.at("specificRect"); + task_info_ptr->specific_rect = Rect( + rect_json[0].as_integer(), + rect_json[1].as_integer(), + rect_json[2].as_integer(), + rect_json[3].as_integer()); + } + else if (action == "stagedrops") { + task_info_ptr->action = ProcessTaskAction::StageDrops; + } + else if (action == "swipetotheleft") { + task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft; + } + else if (action == "swipetotheright") { + task_info_ptr->action = ProcessTaskAction::SwipeToTheRight; + } + else { + m_last_error = "Task: " + name + " error: " + action; + return false; + } + + task_info_ptr->max_times = task_json.get("maxTimes", INT_MAX); + if (task_json.exist("exceededNext")) { + const json::array& excceed_next_arr = task_json.at("exceededNext").as_array(); + for (const json::value& excceed_next : excceed_next_arr) { + task_info_ptr->exceeded_next.emplace_back(excceed_next.as_string()); + } + } + else { + task_info_ptr->exceeded_next.emplace_back("Stop"); + } + task_info_ptr->pre_delay = task_json.get("preDelay", 0); + task_info_ptr->rear_delay = task_json.get("rearDelay", 0); + if (task_json.exist("reduceOtherTimes")) { + const json::array& reduce_arr = task_json.at("reduceOtherTimes").as_array(); + for (const json::value& reduce : reduce_arr) { + task_info_ptr->reduce_other_times.emplace_back(reduce.as_string()); + } + } + if (task_json.exist("roi")) { const json::array& area_arr = task_json.at("roi").as_array(); int x = area_arr[0].as_integer(); int y = area_arr[1].as_integer(); @@ -163,41 +163,41 @@ bool asst::TaskData::parse(const json::value& json) m_last_error = name + " roi is out of bounds"; return false; } -#endif - task_info_ptr->roi = Rect(x, y, width, height); - } - else { - task_info_ptr->roi = Rect(); - } - - if (task_json.exist("next")) { - for (const json::value& next : task_json.at("next").as_array()) { - task_info_ptr->next.emplace_back(next.as_string()); - } - } - if (task_json.exist("rectMove")) { - const json::array& move_arr = task_json.at("rectMove").as_array(); - task_info_ptr->rect_move = Rect( - move_arr[0].as_integer(), - move_arr[1].as_integer(), - move_arr[2].as_integer(), - move_arr[3].as_integer()); - } - else { - task_info_ptr->rect_move = Rect(); - } - - m_all_tasks_info.emplace(name, task_info_ptr); +#endif + task_info_ptr->roi = Rect(x, y, width, height); + } + else { + task_info_ptr->roi = Rect(); + } + + if (task_json.exist("next")) { + for (const json::value& next : task_json.at("next").as_array()) { + task_info_ptr->next.emplace_back(next.as_string()); + } + } + if (task_json.exist("rectMove")) { + const json::array& move_arr = task_json.at("rectMove").as_array(); + task_info_ptr->rect_move = Rect( + move_arr[0].as_integer(), + move_arr[1].as_integer(), + move_arr[2].as_integer(), + move_arr[3].as_integer()); + } + else { + task_info_ptr->rect_move = Rect(); + } + + m_all_tasks_info.emplace(name, task_info_ptr); } #ifdef LOG_TRACE for (const auto& [name, task] : m_all_tasks_info) { - for (const auto& next : task->next) { + for (const auto& next : task->next) { if (m_all_tasks_info.find(next) == m_all_tasks_info.cend()) { - m_last_error = name + "'s next " + next + " is null"; - return false; - } - } + m_last_error = name + "'s next " + next + " is null"; + return false; + } + } } -#endif - return true; -} +#endif + return true; +} \ No newline at end of file diff --git a/src/MeoAssistance/UserConfiger.cpp b/src/MeoAssistance/UserConfiger.cpp index 3235122e3e..a265e009cf 100644 --- a/src/MeoAssistance/UserConfiger.cpp +++ b/src/MeoAssistance/UserConfiger.cpp @@ -2,7 +2,7 @@ #include -#include +#include constexpr static const char* EmulatorPathKey = "emulatorPath"; @@ -45,4 +45,4 @@ bool asst::UserConfiger::save() ofs.close(); return true; -} +} \ No newline at end of file diff --git a/src/MeoAssistance/UserConfiger.h b/src/MeoAssistance/UserConfiger.h index cca11659b3..1bab48aac7 100644 --- a/src/MeoAssistance/UserConfiger.h +++ b/src/MeoAssistance/UserConfiger.h @@ -2,7 +2,7 @@ #include "AbstractConfiger.h" -#include +#include #include namespace asst From b5f2a6e41c72f44101354ffed428c1515cfd0eb1 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 12 Dec 2021 23:44:54 +0800 Subject: [PATCH 02/13] =?UTF-8?q?chore.=E5=88=87=E6=8D=A2OCR=E5=BA=93?= =?UTF-8?q?=E4=B8=BA=E9=A3=9E=E6=A1=A8OCR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 3rdparty/include/OcrLiteOnnx/AngleNet.h | 41 - 3rdparty/include/OcrLiteOnnx/CrnnNet.h | 43 - 3rdparty/include/OcrLiteOnnx/DbNet.h | 34 - 3rdparty/include/OcrLiteOnnx/OcrLite.h | 56 - 3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h | 39 - 3rdparty/include/OcrLiteOnnx/OcrLitePort.h | 45 - 3rdparty/include/OcrLiteOnnx/OcrResultUtils.h | 35 - 3rdparty/include/OcrLiteOnnx/OcrStruct.h | 55 - 3rdparty/include/OcrLiteOnnx/OcrUtils.h | 103 -- 3rdparty/include/OcrLiteOnnx/clipper.hpp | 406 ------ 3rdparty/include/OcrLiteOnnx/getopt.h | 44 - 3rdparty/include/OcrLiteOnnx/main.h | 54 - 3rdparty/include/OcrLiteOnnx/version.h | 6 - 3rdparty/include/PaddleOCR/exports.h | 37 + 3rdparty/include/PaddleOCR/paddle_ocr.h | 39 + 3rdparty/lib/OcrLiteOnnx.lib | Bin 7396 -> 0 bytes 3rdparty/lib/ppocr.lib | Bin 0 -> 2482 bytes .../det/ch_PP-OCRv2_det_slim_quant_infer | 0 .../keys.txt => PaddleOCR/ppocr_keys_v1.txt} | 1096 ++++++++++++++++- .../rec/ch_PP-OCRv2_rec_slim_quant_infer | 0 CMakeLists.txt | 4 +- README.md | 3 +- src/MeoAssistance/AsstDef.h | 3 +- src/MeoAssistance/MeoAssistance.vcxproj | 4 +- src/MeoAssistance/OcrPack.cpp | 98 +- src/MeoAssistance/OcrPack.h | 10 +- src/MeoAssistance/README.md | 3 +- src/MeoAssistance/Resource.cpp | 6 +- tools/TestCaller/main.cpp | 10 +- 30 files changed, 1250 insertions(+), 1025 deletions(-) delete mode 100644 3rdparty/include/OcrLiteOnnx/AngleNet.h delete mode 100644 3rdparty/include/OcrLiteOnnx/CrnnNet.h delete mode 100644 3rdparty/include/OcrLiteOnnx/DbNet.h delete mode 100644 3rdparty/include/OcrLiteOnnx/OcrLite.h delete mode 100644 3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h delete mode 100644 3rdparty/include/OcrLiteOnnx/OcrLitePort.h delete mode 100644 3rdparty/include/OcrLiteOnnx/OcrResultUtils.h delete mode 100644 3rdparty/include/OcrLiteOnnx/OcrStruct.h delete mode 100644 3rdparty/include/OcrLiteOnnx/OcrUtils.h delete mode 100644 3rdparty/include/OcrLiteOnnx/clipper.hpp delete mode 100644 3rdparty/include/OcrLiteOnnx/getopt.h delete mode 100644 3rdparty/include/OcrLiteOnnx/main.h delete mode 100644 3rdparty/include/OcrLiteOnnx/version.h create mode 100644 3rdparty/include/PaddleOCR/exports.h create mode 100644 3rdparty/include/PaddleOCR/paddle_ocr.h delete mode 100644 3rdparty/lib/OcrLiteOnnx.lib create mode 100644 3rdparty/lib/ppocr.lib create mode 100644 3rdparty/resource/PaddleOCR/det/ch_PP-OCRv2_det_slim_quant_infer rename 3rdparty/resource/{OcrLiteOnnx/models/keys.txt => PaddleOCR/ppocr_keys_v1.txt} (83%) create mode 100644 3rdparty/resource/PaddleOCR/rec/ch_PP-OCRv2_rec_slim_quant_infer diff --git a/.gitignore b/.gitignore index b07366bc8f..823d1c5bb8 100644 --- a/.gitignore +++ b/.gitignore @@ -406,6 +406,7 @@ MigrationBackup/ FodyWeavers.xsd # VS Code files for those working on multiple tools +**/.vscode/* .vscode/* !.vscode/settings.json !.vscode/tasks.json diff --git a/3rdparty/include/OcrLiteOnnx/AngleNet.h b/3rdparty/include/OcrLiteOnnx/AngleNet.h deleted file mode 100644 index 283b3fb213..0000000000 --- a/3rdparty/include/OcrLiteOnnx/AngleNet.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __OCR_ANGLENET_H__ -#define __OCR_ANGLENET_H__ - -#include "OcrStruct.h" -#include "onnxruntime_cxx_api.h" -#include - -class AngleNet { -public: - AngleNet(); - - ~AngleNet(); - - void setNumThread(int numOfThread); - - void initModel(const std::string &pathStr); - - std::vector getAngles(std::vector &partImgs, const char *path, - const char *imgName, bool doAngle, bool mostAngle); - -private: - bool isOutputAngleImg = false; - - Ort::Session *session; - Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "AngleNet"); - Ort::SessionOptions sessionOptions = Ort::SessionOptions(); - int numThread = 0; - - char *inputName; - char *outputName; - - const float meanValues[3] = {127.5, 127.5, 127.5}; - const float normValues[3] = {1.0 / 127.5, 1.0 / 127.5, 1.0 / 127.5}; - const int dstWidth = 192; - const int dstHeight = 32; - - Angle getAngle(cv::Mat &src); -}; - - -#endif //__OCR_ANGLENET_H__ diff --git a/3rdparty/include/OcrLiteOnnx/CrnnNet.h b/3rdparty/include/OcrLiteOnnx/CrnnNet.h deleted file mode 100644 index 288e8d58ec..0000000000 --- a/3rdparty/include/OcrLiteOnnx/CrnnNet.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __OCR_CRNNNET_H__ -#define __OCR_CRNNNET_H__ - -#include "OcrStruct.h" -#include "onnxruntime_cxx_api.h" -#include - -class CrnnNet { -public: - - CrnnNet(); - - ~CrnnNet(); - - void setNumThread(int numOfThread); - - void initModel(const std::string &pathStr, const std::string &keysPath); - - std::vector getTextLines(std::vector &partImg, const char *path, const char *imgName); - -private: - bool isOutputDebugImg = false; - Ort::Session *session; - Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "CrnnNet"); - Ort::SessionOptions sessionOptions = Ort::SessionOptions(); - int numThread = 0; - - char *inputName; - char *outputName; - - const float meanValues[3] = {127.5, 127.5, 127.5}; - const float normValues[3] = {1.0 / 127.5, 1.0 / 127.5, 1.0 / 127.5}; - const int dstHeight = 32; - - std::vector keys; - - TextLine scoreToTextLine(const std::vector &outputData, int h, int w); - - TextLine getTextLine(const cv::Mat &src); -}; - - -#endif //__OCR_CRNNNET_H__ diff --git a/3rdparty/include/OcrLiteOnnx/DbNet.h b/3rdparty/include/OcrLiteOnnx/DbNet.h deleted file mode 100644 index 4d070c30a6..0000000000 --- a/3rdparty/include/OcrLiteOnnx/DbNet.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __OCR_DBNET_H__ -#define __OCR_DBNET_H__ - -#include "OcrStruct.h" -#include "onnxruntime_cxx_api.h" -#include - -class DbNet { -public: - DbNet(); - - ~DbNet(); - - void setNumThread(int numOfThread); - - void initModel(const std::string &pathStr); - - std::vector getTextBoxes(cv::Mat &src, ScaleParam &s, float boxScoreThresh, - float boxThresh, float unClipRatio); - -private: - Ort::Session *session; - Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "DbNet"); - Ort::SessionOptions sessionOptions = Ort::SessionOptions(); - int numThread = 0; - char *inputName; - char *outputName; - - const float meanValues[3] = {0.485 * 255, 0.456 * 255, 0.406 * 255}; - const float normValues[3] = {1.0 / 0.229 / 255.0, 1.0 / 0.224 / 255.0, 1.0 / 0.225 / 255.0}; -}; - - -#endif //__OCR_DBNET_H__ diff --git a/3rdparty/include/OcrLiteOnnx/OcrLite.h b/3rdparty/include/OcrLiteOnnx/OcrLite.h deleted file mode 100644 index d650631f0c..0000000000 --- a/3rdparty/include/OcrLiteOnnx/OcrLite.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __OCR_LITE_H__ -#define __OCR_LITE_H__ - -#include "opencv2/core.hpp" -#include "onnxruntime_cxx_api.h" -#include "OcrStruct.h" -#include "DbNet.h" -#include "AngleNet.h" -#include "CrnnNet.h" - -class OcrLite { -public: - OcrLite(); - - ~OcrLite(); - - void setNumThread(int numOfThread); - - void initLogger(bool isConsole, bool isPartImg, bool isResultImg); - - void enableResultTxt(const char *path, const char *imgName); - - void initModels(const std::string &detPath, const std::string &clsPath, - const std::string &recPath, const std::string &keysPath); - - void Logger(const char *format, ...); - - OcrResult detect(const char *path, const char *imgName, - int padding, int maxSideLen, - float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); - - - OcrResult detect(const cv::Mat& mat, - int padding, int maxSideLen, - float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); - -private: - bool isOutputConsole = false; - bool isOutputPartImg = false; - bool isOutputResultTxt = false; - bool isOutputResultImg = false; - FILE *resultTxt; - DbNet dbNet; - AngleNet angleNet; - CrnnNet crnnNet; - - std::vector getPartImages(cv::Mat &src, std::vector &textBoxes, - const char *path, const char *imgName); - - OcrResult detect(const char *path, const char *imgName, - cv::Mat &src, cv::Rect &originRect, ScaleParam &scale, - float boxScoreThresh = 0.6f, float boxThresh = 0.3f, - float unClipRatio = 2.0f, bool doAngle = true, bool mostAngle = true); -}; - -#endif //__OCR_LITE_H__ diff --git a/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h b/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h deleted file mode 100644 index 8e8236d7bd..0000000000 --- a/3rdparty/include/OcrLiteOnnx/OcrLiteCaller.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -#include - -#include "OcrLitePort.h" -#include "OcrStruct.h" - -namespace cv -{ - class Mat; -} -class OcrLite; - -class OCRLITE_PORT OcrLiteCaller -{ -public: - OcrLiteCaller(); - ~OcrLiteCaller(); - OcrLiteCaller(const OcrLite&) = delete; - OcrLiteCaller(OcrLite&&) = delete; - - void setNumThread(int numOfThread); - bool initModels(const std::string& detPath, const std::string& clsPath, - const std::string& recPath, const std::string& keysPath); - - OcrResult detect(const cv::Mat& mat, - int padding, int maxSideLen, - float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); - - OcrResult detect(const std::string& dir, const std::string& file, - int padding, int maxSideLen, - float boxScoreThresh, float boxThresh, float unClipRatio, bool doAngle, bool mostAngle); - - OcrLiteCaller& operator=(const OcrLiteCaller&) = delete; - OcrLiteCaller& operator=(OcrLiteCaller&&) = delete; -private: - std::unique_ptr m_ocrlite_ptr; -}; \ No newline at end of file diff --git a/3rdparty/include/OcrLiteOnnx/OcrLitePort.h b/3rdparty/include/OcrLiteOnnx/OcrLitePort.h deleted file mode 100644 index e21b6999d4..0000000000 --- a/3rdparty/include/OcrLiteOnnx/OcrLitePort.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#if !defined(__JNI__) && !defined(__EXEC__) - -// The way how the function is called -#if !defined(OCRLITE_CALL) -#if defined(_WIN32) -#define OCRLITE_CALL __stdcall -#else -#define OCRLITE_CALL -#endif /* _WIN32 */ -#endif /* OCRLITE_CALL */ - -#if defined _WIN32 || defined __CYGWIN__ -#define OCRLITE_EXPORT __declspec(dllexport) -#define OCRLITE_IMPORT __declspec(dllimport) -#define OCRLITE_LOCAL -#else // ! defined _WIN32 || defined __CYGWIN__ -#if __GNUC__ >= 4 -#define OCRLITE_EXPORT __attribute__ ((visibility ("default"))) -#define OCRLITE_IMPORT __attribute__ ((visibility ("default"))) -#define OCRLITE_LOCAL __attribute__ ((visibility ("hidden"))) -#else // ! __GNUC__ >= 4 -#define OCRLITE_EXPORT -#define OCRLITE_IMPORT -#endif // End __GNUC__ >= 4 -#endif // End defined _WIN32 || defined __CYGWIN__ - -#ifdef __CLIB__ -#define OCRLITE_PORT OCRLITE_EXPORT -#else -#define OCRLITE_PORT OCRLITE_IMPORT -#endif // OCRLITE_PORT - -#define OCR_API OCRLITE_PORT OCRLITE_CALL - -#define OCR_LOCAL OCRLITE_LOCAL OCRLITE_CALL - -#else // __JNI__ || __EXEC__ - -#define OCRLITE_PORT -#define OCR_API -#define OCR_LOCAL - -#endif // __JNI__ || __EXEC__ diff --git a/3rdparty/include/OcrLiteOnnx/OcrResultUtils.h b/3rdparty/include/OcrLiteOnnx/OcrResultUtils.h deleted file mode 100644 index f60340fcdd..0000000000 --- a/3rdparty/include/OcrLiteOnnx/OcrResultUtils.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifdef __JNI__ -#ifndef __OCR_RESULT_UTILS_H__ -#define __OCR_RESULT_UTILS_H__ -#include -#include "OcrStruct.h" - -class OcrResultUtils { -public: - OcrResultUtils(JNIEnv *env, OcrResult &ocrResult); - - ~OcrResultUtils(); - - jobject getJObject(); - -private: - JNIEnv *jniEnv; - jobject jOcrResult; - - jclass newJListClass(); - - jmethodID getListConstructor(jclass clazz); - - jobject getTextBlock(TextBlock &textBlock); - - jobject getTextBlocks(std::vector &textBlocks); - - jobject newJPoint(cv::Point &point); - - jobject newJBoxPoint(std::vector &boxPoint); - - jfloatArray newJScoreArray(std::vector &scores); - -}; -#endif //__OCR_RESULT_UTILS_H__ -#endif diff --git a/3rdparty/include/OcrLiteOnnx/OcrStruct.h b/3rdparty/include/OcrLiteOnnx/OcrStruct.h deleted file mode 100644 index 961838aedb..0000000000 --- a/3rdparty/include/OcrLiteOnnx/OcrStruct.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __OCR_STRUCT_H__ -#define __OCR_STRUCT_H__ - -#include "opencv2/core.hpp" -#include - -#include "OcrLitePort.h" - -struct ScaleParam { - int srcWidth; - int srcHeight; - int dstWidth; - int dstHeight; - float ratioWidth; - float ratioHeight; -}; - -struct TextBox { - std::vector boxPoint; - float score; -}; - -struct Angle { - int index; - float score; - double time; -}; - -struct TextLine { - std::string text; - std::vector charScores; - double time; -}; - -struct OCRLITE_PORT TextBlock { - std::vector boxPoint; - float boxScore; - int angleIndex; - float angleScore; - double angleTime; - std::string text; - std::vector charScores; - double crnnTime; - double blockTime; -}; - -struct OCRLITE_PORT OcrResult { - double dbNetTime; - std::vector textBlocks; - cv::Mat boxImg; - double detectTime; - std::string strRes; -}; - -#endif //__OCR_STRUCT_H__ diff --git a/3rdparty/include/OcrLiteOnnx/OcrUtils.h b/3rdparty/include/OcrLiteOnnx/OcrUtils.h deleted file mode 100644 index 5f2488cc32..0000000000 --- a/3rdparty/include/OcrLiteOnnx/OcrUtils.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef __OCR_UTILS_H__ -#define __OCR_UTILS_H__ - -#include -#include "OcrStruct.h" -#include "onnxruntime_cxx_api.h" -#include -#include - -template -static std::unique_ptr makeUnique(Ts &&... params) { - return std::unique_ptr(new T(std::forward(params)...)); -} - -template -static double getMean(std::vector &input) { - auto sum = accumulate(input.begin(), input.end(), 0.0); - return sum / input.size(); -} - -template -static double getStdev(std::vector &input, double mean) { - if (input.size() <= 1) return 0; - double accum = 0.0; - for_each(input.begin(), input.end(), [&](const double d) { - accum += (d - mean) * (d - mean); - }); - double stdev = sqrt(accum / (input.size() - 1)); - return stdev; -} - -double getCurrentTime(); - -inline bool isFileExists(const std::string &name) { - struct stat buffer; - return (stat(name.c_str(), &buffer) == 0); -} - -#ifdef _WIN32 -#define my_strtol wcstol -#define my_strrchr wcsrchr -#define my_strcasecmp _wcsicmp -#define my_strdup _strdup -#else -#define my_strtol strtol -#define my_strrchr strrchr -#define my_strcasecmp strcasecmp -#define my_strdup strdup -#endif - -std::wstring strToWstr(std::string str); - -ScaleParam getScaleParam(cv::Mat &src, const float scale); - -ScaleParam getScaleParam(cv::Mat &src, const int targetSize); - -std::vector getBox(const cv::RotatedRect &rect); - -int getThickness(cv::Mat &boxImg); - -void drawTextBox(cv::Mat &boxImg, cv::RotatedRect &rect, int thickness); - -void drawTextBox(cv::Mat &boxImg, const std::vector &box, int thickness); - -void drawTextBoxes(cv::Mat &boxImg, std::vector &textBoxes, int thickness); - -cv::Mat matRotateClockWise180(cv::Mat src); - -cv::Mat matRotateClockWise90(cv::Mat src); - -cv::Mat getRotateCropImage(const cv::Mat &src, std::vector box); - -cv::Mat adjustTargetImg(cv::Mat &src, int dstWidth, int dstHeight); - -std::vector getMinBoxes(const std::vector &inVec, float &minSideLen, float &allEdgeSize); - -float boxScoreFast(const cv::Mat &inMat, const std::vector &inBox); - -std::vector unClip(const std::vector &inBox, float perimeter, float unClipRatio); - -std::vector substractMeanNormalize(cv::Mat &src, const float *meanVals, const float *normVals); - -std::vector getAngleIndexes(std::vector &angles); - -std::vector getInputNames(Ort::Session *session); - -std::vector getOutputNames(Ort::Session *session); - -void getInputName(Ort::Session *session, char *&inputName); - -void getOutputName(Ort::Session *session, char *&outputName); - -void saveImg(cv::Mat &img, const char *imgPath); - -std::string getSrcImgFilePath(const char *path, const char *imgName); - -std::string getResultTxtFilePath(const char *path, const char *imgName); - -std::string getResultImgFilePath(const char *path, const char *imgName); - -std::string getDebugImgFilePath(const char *path, const char *imgName, int i, const char *tag); - -#endif //__OCR_UTILS_H__ diff --git a/3rdparty/include/OcrLiteOnnx/clipper.hpp b/3rdparty/include/OcrLiteOnnx/clipper.hpp deleted file mode 100644 index cbe30db822..0000000000 --- a/3rdparty/include/OcrLiteOnnx/clipper.hpp +++ /dev/null @@ -1,406 +0,0 @@ -/******************************************************************************* -* * -* Author : Angus Johnson * -* Version : 6.4.2 * -* Date : 27 February 2017 * -* Website : http://www.angusj.com * -* Copyright : Angus Johnson 2010-2017 * -* * -* License: * -* Use, modification & distribution is subject to Boost Software License Ver 1. * -* http://www.boost.org/LICENSE_1_0.txt * -* * -* Attributions: * -* The code in this library is an extension of Bala Vatti's clipping algorithm: * -* "A generic solution to polygon clipping" * -* Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. * -* http://portal.acm.org/citation.cfm?id=129906 * -* * -* Computer graphics and geometric modeling: implementation and algorithms * -* By Max K. Agoston * -* Springer; 1 edition (January 4, 2005) * -* http://books.google.com/books?q=vatti+clipping+agoston * -* * -* See also: * -* "Polygon Offsetting by Computing Winding Numbers" * -* Paper no. DETC2005-85513 pp. 565-575 * -* ASME 2005 International Design Engineering Technical Conferences * -* and Computers and Information in Engineering Conference (IDETC/CIE2005) * -* September 24-28, 2005 , Long Beach, California, USA * -* http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf * -* * -*******************************************************************************/ - -#ifndef clipper_hpp -#define clipper_hpp - -#define CLIPPER_VERSION "6.4.2" - -//use_int32: When enabled 32bit ints are used instead of 64bit ints. This -//improve performance but coordinate values are limited to the range +/- 46340 -//#define use_int32 - -//use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance. -//#define use_xyz - -//use_lines: Enables line clipping. Adds a very minor cost to performance. -#define use_lines - -//use_deprecated: Enables temporary support for the obsolete functions -//#define use_deprecated - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ClipperLib { - - enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor }; - enum PolyType { ptSubject, ptClip }; -//By far the most widely used winding rules for polygon filling are -//EvenOdd & NonZero (GDI, GDI+, XLib, OpenGL, Cairo, AGG, Quartz, SVG, Gr32) -//Others rules include Positive, Negative and ABS_GTR_EQ_TWO (only in OpenGL) -//see http://glprogramming.com/red/chapter11.html - enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; - -#ifdef use_int32 - typedef int cInt; - static cInt const loRange = 0x7FFF; - static cInt const hiRange = 0x7FFF; -#else - typedef signed long long cInt; - static cInt const loRange = 0x3FFFFFFF; - static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; - typedef signed long long long64; //used by Int128 class - typedef unsigned long long ulong64; - -#endif - - struct IntPoint { - cInt X; - cInt Y; -#ifdef use_xyz - cInt Z; - IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {}; -#else - IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {}; -#endif - - friend inline bool operator== (const IntPoint& a, const IntPoint& b) - { - return a.X == b.X && a.Y == b.Y; - } - friend inline bool operator!= (const IntPoint& a, const IntPoint& b) - { - return a.X != b.X || a.Y != b.Y; - } - }; -//------------------------------------------------------------------------------ - - typedef std::vector< IntPoint > Path; - typedef std::vector< Path > Paths; - - inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;} - inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;} - - std::ostream& operator <<(std::ostream &s, const IntPoint &p); - std::ostream& operator <<(std::ostream &s, const Path &p); - std::ostream& operator <<(std::ostream &s, const Paths &p); - - struct DoublePoint - { - double X; - double Y; - DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {} - DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {} - }; -//------------------------------------------------------------------------------ - -#ifdef use_xyz - typedef void (*ZFillCallback)(IntPoint& e1bot, IntPoint& e1top, IntPoint& e2bot, IntPoint& e2top, IntPoint& pt); -#endif - - enum InitOptions {ioReverseSolution = 1, ioStrictlySimple = 2, ioPreserveCollinear = 4}; - enum JoinType {jtSquare, jtRound, jtMiter}; - enum EndType {etClosedPolygon, etClosedLine, etOpenButt, etOpenSquare, etOpenRound}; - - class PolyNode; - typedef std::vector< PolyNode* > PolyNodes; - - class PolyNode - { - public: - PolyNode(); - virtual ~PolyNode(){}; - Path Contour; - PolyNodes Childs; - PolyNode* Parent; - PolyNode* GetNext() const; - bool IsHole() const; - bool IsOpen() const; - int ChildCount() const; - private: - //PolyNode& operator =(PolyNode& other); - unsigned Index; //node index in Parent.Childs - bool m_IsOpen; - JoinType m_jointype; - EndType m_endtype; - PolyNode* GetNextSiblingUp() const; - void AddChild(PolyNode& child); - friend class Clipper; //to access Index - friend class ClipperOffset; - }; - - class PolyTree: public PolyNode - { - public: - ~PolyTree(){ Clear(); }; - PolyNode* GetFirst() const; - void Clear(); - int Total() const; - private: - //PolyTree& operator =(PolyTree& other); - PolyNodes AllNodes; - friend class Clipper; //to access AllNodes - }; - - bool Orientation(const Path &poly); - double Area(const Path &poly); - int PointInPolygon(const IntPoint &pt, const Path &path); - - void SimplifyPolygon(const Path &in_poly, Paths &out_polys, PolyFillType fillType = pftEvenOdd); - void SimplifyPolygons(const Paths &in_polys, Paths &out_polys, PolyFillType fillType = pftEvenOdd); - void SimplifyPolygons(Paths &polys, PolyFillType fillType = pftEvenOdd); - - void CleanPolygon(const Path& in_poly, Path& out_poly, double distance = 1.415); - void CleanPolygon(Path& poly, double distance = 1.415); - void CleanPolygons(const Paths& in_polys, Paths& out_polys, double distance = 1.415); - void CleanPolygons(Paths& polys, double distance = 1.415); - - void MinkowskiSum(const Path& pattern, const Path& path, Paths& solution, bool pathIsClosed); - void MinkowskiSum(const Path& pattern, const Paths& paths, Paths& solution, bool pathIsClosed); - void MinkowskiDiff(const Path& poly1, const Path& poly2, Paths& solution); - - void PolyTreeToPaths(const PolyTree& polytree, Paths& paths); - void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths); - void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths); - - void ReversePath(Path& p); - void ReversePaths(Paths& p); - - struct IntRect { cInt left; cInt top; cInt right; cInt bottom; }; - -//enums that are used internally ... - enum EdgeSide { esLeft = 1, esRight = 2}; - -//forward declarations (for stuff used internally) ... - struct TEdge; - struct IntersectNode; - struct LocalMinimum; - struct OutPt; - struct OutRec; - struct Join; - - typedef std::vector < OutRec* > PolyOutList; - typedef std::vector < TEdge* > EdgeList; - typedef std::vector < Join* > JoinList; - typedef std::vector < IntersectNode* > IntersectList; - -//------------------------------------------------------------------------------ - -//ClipperBase is the ancestor to the Clipper class. It should not be -//instantiated directly. This class simply abstracts the conversion of sets of -//polygon coordinates into edge objects that are stored in a LocalMinima list. - class ClipperBase - { - public: - ClipperBase(); - virtual ~ClipperBase(); - virtual bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed); - bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed); - virtual void Clear(); - IntRect GetBounds(); - bool PreserveCollinear() {return m_PreserveCollinear;}; - void PreserveCollinear(bool value) {m_PreserveCollinear = value;}; - protected: - void DisposeLocalMinimaList(); - TEdge* AddBoundsToLML(TEdge *e, bool IsClosed); - virtual void Reset(); - TEdge* ProcessBound(TEdge* E, bool IsClockwise); - void InsertScanbeam(const cInt Y); - bool PopScanbeam(cInt &Y); - bool LocalMinimaPending(); - bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin); - OutRec* CreateOutRec(); - void DisposeAllOutRecs(); - void DisposeOutRec(PolyOutList::size_type index); - void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2); - void DeleteFromAEL(TEdge *e); - void UpdateEdgeIntoAEL(TEdge *&e); - - typedef std::vector MinimaList; - MinimaList::iterator m_CurrentLM; - MinimaList m_MinimaList; - - bool m_UseFullRange; - EdgeList m_edges; - bool m_PreserveCollinear; - bool m_HasOpenPaths; - PolyOutList m_PolyOuts; - TEdge *m_ActiveEdges; - - typedef std::priority_queue ScanbeamList; - ScanbeamList m_Scanbeam; - }; -//------------------------------------------------------------------------------ - - class Clipper : public virtual ClipperBase - { - public: - Clipper(int initOptions = 0); - bool Execute(ClipType clipType, - Paths &solution, - PolyFillType fillType = pftEvenOdd); - bool Execute(ClipType clipType, - Paths &solution, - PolyFillType subjFillType, - PolyFillType clipFillType); - bool Execute(ClipType clipType, - PolyTree &polytree, - PolyFillType fillType = pftEvenOdd); - bool Execute(ClipType clipType, - PolyTree &polytree, - PolyFillType subjFillType, - PolyFillType clipFillType); - bool ReverseSolution() { return m_ReverseOutput; }; - void ReverseSolution(bool value) {m_ReverseOutput = value;}; - bool StrictlySimple() {return m_StrictSimple;}; - void StrictlySimple(bool value) {m_StrictSimple = value;}; - //set the callback function for z value filling on intersections (otherwise Z is 0) -#ifdef use_xyz - void ZFillFunction(ZFillCallback zFillFunc); -#endif - protected: - virtual bool ExecuteInternal(); - private: - JoinList m_Joins; - JoinList m_GhostJoins; - IntersectList m_IntersectList; - ClipType m_ClipType; - typedef std::list MaximaList; - MaximaList m_Maxima; - TEdge *m_SortedEdges; - bool m_ExecuteLocked; - PolyFillType m_ClipFillType; - PolyFillType m_SubjFillType; - bool m_ReverseOutput; - bool m_UsingPolyTree; - bool m_StrictSimple; -#ifdef use_xyz - ZFillCallback m_ZFill; //custom callback -#endif - void SetWindingCount(TEdge& edge); - bool IsEvenOddFillType(const TEdge& edge) const; - bool IsEvenOddAltFillType(const TEdge& edge) const; - void InsertLocalMinimaIntoAEL(const cInt botY); - void InsertEdgeIntoAEL(TEdge *edge, TEdge* startEdge); - void AddEdgeToSEL(TEdge *edge); - bool PopEdgeFromSEL(TEdge *&edge); - void CopyAELToSEL(); - void DeleteFromSEL(TEdge *e); - void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2); - bool IsContributing(const TEdge& edge) const; - bool IsTopHorz(const cInt XPos); - void DoMaxima(TEdge *e); - void ProcessHorizontals(); - void ProcessHorizontal(TEdge *horzEdge); - void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt); - OutPt* AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt); - OutRec* GetOutRec(int idx); - void AppendPolygon(TEdge *e1, TEdge *e2); - void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt); - OutPt* AddOutPt(TEdge *e, const IntPoint &pt); - OutPt* GetLastOutPt(TEdge *e); - bool ProcessIntersections(const cInt topY); - void BuildIntersectList(const cInt topY); - void ProcessIntersectList(); - void ProcessEdgesAtTopOfScanbeam(const cInt topY); - void BuildResult(Paths& polys); - void BuildResult2(PolyTree& polytree); - void SetHoleState(TEdge *e, OutRec *outrec); - void DisposeIntersectNodes(); - bool FixupIntersectionOrder(); - void FixupOutPolygon(OutRec &outrec); - void FixupOutPolyline(OutRec &outrec); - bool IsHole(TEdge *e); - bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl); - void FixHoleLinkage(OutRec &outrec); - void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt); - void ClearJoins(); - void ClearGhostJoins(); - void AddGhostJoin(OutPt *op, const IntPoint offPt); - bool JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2); - void JoinCommonEdges(); - void DoSimplePolygons(); - void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec); - void FixupFirstLefts2(OutRec* InnerOutRec, OutRec* OuterOutRec); - void FixupFirstLefts3(OutRec* OldOutRec, OutRec* NewOutRec); -#ifdef use_xyz - void SetZ(IntPoint& pt, TEdge& e1, TEdge& e2); -#endif - }; -//------------------------------------------------------------------------------ - - class ClipperOffset - { - public: - ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25); - ~ClipperOffset(); - void AddPath(const Path& path, JoinType joinType, EndType endType); - void AddPaths(const Paths& paths, JoinType joinType, EndType endType); - void Execute(Paths& solution, double delta); - void Execute(PolyTree& solution, double delta); - void Clear(); - double MiterLimit; - double ArcTolerance; - private: - Paths m_destPolys; - Path m_srcPoly; - Path m_destPoly; - std::vector m_normals; - double m_delta, m_sinA, m_sin, m_cos; - double m_miterLim, m_StepsPerRad; - IntPoint m_lowest; - PolyNode m_polyNodes; - - void FixOrientations(); - void DoOffset(double delta); - void OffsetPoint(int j, int& k, JoinType jointype); - void DoSquare(int j, int k); - void DoMiter(int j, int k, double r); - void DoRound(int j, int k); - }; -//------------------------------------------------------------------------------ - - class clipperException : public std::exception - { - public: - clipperException(const char* description): m_descr(description) {} - virtual ~clipperException() throw() {} - virtual const char* what() const throw() {return m_descr.c_str();} - private: - std::string m_descr; - }; -//------------------------------------------------------------------------------ - -} //ClipperLib namespace - -#endif //clipper_hpp - - diff --git a/3rdparty/include/OcrLiteOnnx/getopt.h b/3rdparty/include/OcrLiteOnnx/getopt.h deleted file mode 100644 index d606dfe90d..0000000000 --- a/3rdparty/include/OcrLiteOnnx/getopt.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * getopt - POSIX like getopt for Windows console Application - * - * win-c - Windows Console Library - * Copyright (c) 2015 Koji Takami - * Released under the MIT license - * https://github.com/takamin/win-c/blob/master/LICENSE - */ -#ifndef _GETOPT_H_ -#define _GETOPT_H_ - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -int getopt(int argc, char *const argv[], - const char *optstring); - -extern char *optarg; -extern int optind, opterr, optopt; - -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - -struct option { - const char *name; - int has_arg; - int *flag; - int val; -}; - -int getopt_long(int argc, char *const argv[], - const char *optstring, - const struct option *longopts, int *longindex); -/**************************************************************************** - int getopt_long_only(int argc, char* const argv[], - const char* optstring, - const struct option* longopts, int* longindex); -****************************************************************************/ -#ifdef __cplusplus -} -#endif // __cplusplus -#endif // _GETOPT_H_ diff --git a/3rdparty/include/OcrLiteOnnx/main.h b/3rdparty/include/OcrLiteOnnx/main.h deleted file mode 100644 index 4949e1e977..0000000000 --- a/3rdparty/include/OcrLiteOnnx/main.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef __MAIN_H__ -#define __MAIN_H__ - -#include "getopt.h" - -static const struct option long_options[] = { - {"models", required_argument, NULL, 'd'}, - {"det", required_argument, NULL, '1'}, - {"cls", required_argument, NULL, '2'}, - {"rec", required_argument, NULL, '3'}, - {"keys", required_argument, NULL, '4'}, - {"image", required_argument, NULL, 'i'}, - {"numThread", required_argument, NULL, 't'}, - {"padding", required_argument, NULL, 'p'}, - {"maxSideLen", required_argument, NULL, 's'}, - {"boxScoreThresh", required_argument, NULL, 'b'}, - {"boxThresh", required_argument, NULL, 'o'}, - {"unClipRatio", required_argument, NULL, 'u'}, - {"doAngle", required_argument, NULL, 'a'}, - {"mostAngle", required_argument, NULL, 'A'}, - {"version", no_argument, NULL, 'v'}, - {"help", no_argument, NULL, 'h'}, - {"loopCount", required_argument, NULL, 'l'}, - {NULL, no_argument, NULL, 0} -}; - -const char *usageMsg = "(-d --models) (-1 --det) (-2 --cls) (-3 --rec) (-4 --keys) (-i --image)\n"\ - "[-t --numThread] [-p --padding] [-s --maxSideLen]\n" \ - "[-b --boxScoreThresh] [-o --boxThresh] [-u --unClipRatio]\n" \ - "[-a --noAngle] [-A --mostAngle]\n\n"; - -const char *requiredMsg = "-d --models: models directory.\n" \ - "-1 --det: model file name of det.\n" \ - "-2 --cls: model file name of cls.\n" \ - "-3 --rec: model file name of rec.\n" \ - "-4 --keys: keys file name.\n" \ - "-i --image: path of target image.\n\n"; - -const char *optionalMsg = "-t --numThread: value of numThread(int), default: 4\n" \ - "-p --padding: value of padding(int), default: 50\n" \ - "-s --maxSideLen: Long side of picture for resize(int), default: 1024\n" \ - "-b --boxScoreThresh: value of boxScoreThresh(float), default: 0.6\n" \ - "-o --boxThresh: value of boxThresh(float), default: 0.3\n" \ - "-u --unClipRatio: value of unClipRatio(float), default: 2.0\n" \ - "-a --doAngle: Enable(1)/Disable(0) Angle Net, default: Enable\n" \ - "-A --mostAngle: Enable(1)/Disable(0) Most Possible AngleIndex, default: Enable\n\n"; - -const char *otherMsg = "-v --version: show version\n" \ - "-h --help: print this help\n\n"; - -const char *example1Msg = "Example1: %s --models models --det det.onnx --cls cls.onnx --rec rec.onnx --keys keys.txt --image 1.jpg\n"; -const char *example2Msg = "Example2: %s -d models -1 det.onnx -2 cls.onnx -3 rec.onnx -4 keys.txt -i 1.jpg -t 4 -p 50 -s 0 -b 0.6 -o 0.3 -u 2.0 -a 1 -A 1\n"; - -#endif //__MAIN_H__ diff --git a/3rdparty/include/OcrLiteOnnx/version.h b/3rdparty/include/OcrLiteOnnx/version.h deleted file mode 100644 index e09f1a4329..0000000000 --- a/3rdparty/include/OcrLiteOnnx/version.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __OCR_VERSION_H__ -#define __OCR_VERSION_H__ - -#define VERSION "1.5.1.20210128" - -#endif //__OCR_VERSION_H__ diff --git a/3rdparty/include/PaddleOCR/exports.h b/3rdparty/include/PaddleOCR/exports.h new file mode 100644 index 0000000000..3b0915b078 --- /dev/null +++ b/3rdparty/include/PaddleOCR/exports.h @@ -0,0 +1,37 @@ +#pragma once + +// The way how the function is called +#if !defined(OCR_CALL) +#if defined(_WIN32) +#define OCR_CALL __stdcall +#else +#define OCR_CALL +#endif /* _WIN32 */ +#endif /* OCR_CALL */ + +// The function exported symbols +#if defined _WIN32 || defined __CYGWIN__ +#define OCR_IMPORT __declspec(dllimport) +#define OCR_EXPORT __declspec(dllexport) +#define OCR_LOCAL +#else +#if __GNUC__ >= 4 +#define OCR_IMPORT __attribute__ ((visibility ("default"))) +#define OCR_EXPORT __attribute__ ((visibility ("default"))) +#define OCR_LOCAL __attribute__ ((visibility ("hidden"))) +#else +#define OCR_IMPORT +#define OCR_EXPORT +#define OCR_LOCAL +#endif +#endif + +#ifdef OCR_EXPORTS // defined if we are building the DLL (instead of using it) +#define OCRAPI_PORT OCR_EXPORT +#else +#define OCRAPI_PORT OCR_IMPORT +#endif // OCR_EXPORTS + +#define OCRAPI OCRAPI_PORT OCR_CALL + +#define OCRLOCAL OCR_LOCAL OCR_CALL \ No newline at end of file diff --git a/3rdparty/include/PaddleOCR/paddle_ocr.h b/3rdparty/include/PaddleOCR/paddle_ocr.h new file mode 100644 index 0000000000..69552d2927 --- /dev/null +++ b/3rdparty/include/PaddleOCR/paddle_ocr.h @@ -0,0 +1,39 @@ +#pragma once + +#include "exports.h" + +struct paddle_ocr_t; +typedef int OCR_ERROR; +typedef unsigned char uint8_t; + +#define OCR_SUCCESS 0 +#define OCR_FAILURE 1 + +#ifdef __cplusplus +extern "C" { +#endif + +OCRAPI_PORT paddle_ocr_t* OCR_CALL PaddleOcrCreate( + const char* det_model_dir, const char* rec_model_dir, + const char* char_list_file, const char* cls_model_dir); + +void OCRAPI PaddleOcrDestroy(paddle_ocr_t* ocr_ptr); + +OCR_ERROR OCRAPI PaddleOcrDet( + paddle_ocr_t* ocr_ptr, const uint8_t* encode_buf, size_t encode_buf_size, + int* out_boxes, size_t* out_boxes_size, + double* out_times, size_t* out_times_size); + +OCR_ERROR OCRAPI PaddleOcrRec( + paddle_ocr_t* ocr_ptr, const uint8_t* encode_buf, size_t encode_buf_size, + char** out_strs, float* out_scores, size_t* out_size, + double* out_times, size_t* out_times_size); + +OCR_ERROR OCRAPI PaddleOcrSystem( + paddle_ocr_t* ocr_ptr, const uint8_t* encode_buf, size_t encode_buf_size, bool with_cls, + int* out_boxes, char** out_strs, float* out_scores, size_t* out_size, + double* out_times, size_t* out_times_size); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/3rdparty/lib/OcrLiteOnnx.lib b/3rdparty/lib/OcrLiteOnnx.lib deleted file mode 100644 index e4381d20434fed86f6ec1d6912941d1cc1cb4695..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7396 zcmc&(O>7%Q6n?gorgih<#QEz_Bv-PU&_ZITiIWJ(uG>UPRND!ujjA5Hb#2oaoH*DU zlvBB&T*?7)s45OQB5@$Mq6!sSkZ3Cq5fuj%gi!gDP=%11LxngH-gtNH@p^Xc#dcWf zd3NT#neV+f^XAR0kG&Ah#1<#*L$2cIId5^D);#KqcWm6Jyk4>cKtDk1RRG5=fc71L z?s0{BHUJ29-BxK5OQb{CmZQU1B6U7csAmA>kvankIkx}^_1;ja6H6p#SfTDs#6dcG zQK2K(0SFy_s*(#!mn6*w=jRr}($w_1GYhlx;kgBAE|v)-<;2|b@)}4|C=v*i3c;I< zlp+(JiGDX(c_|mlBFP^`EVC+L9 zC>kK;B{;p^Zd9~Pe?~?SMl>4xbKUb0)Z8*+dgCxq#v?I;XcbP&LL$4Gk~x0o@X+s^ zRtm`DaWG0uF3}<{!RgKDPjO57GcxEejmCO@Hx|H%@BtY?#VQgsXQHW8BE$DR zkFWTj$D!b44tRVan~+1ROX0;#A{rMtLg!}+kx-GWkX%m6!E`*4%JRmOLO6>r3+~I& zY%(Tg6!I3dt#TAoT2$xb>U6Iew)w0%k+bM}_K z+Hot*760)pNK=(wD6ssZ!wECPx-$7G)|D_iTJjLI!BC2zm0%F`f`)3xJ2K^Y2IH1J zW6(kPf+aTa&=EFrG>cmAiG0 zdM4ES=Ouf5-3DLB-~HTa0nBR3GZ;@?UcKTzr&eJaU*4t_wG_c|dN3J}%2D?)WnpTC zhe*Gv4K^%A@Z449d}=f1O8^_{(BURpt&Z?0M_ySr>J z6vuQ=h?*_}?Hbd| zuAJe~5oYCB!T0Fe<4)|sD<`h7^1sZ=IYk@E%K3m+)RL^6x~+&x=C}_P(fz1l z+H(`E=WOtL&-fodA%HUBe9sxg+$ePxiCGeJ>?49mV{U}D6S-|#QA;9M7Y|qB-D9Xk zO?Nflu(~u|22A{LP81leRm5lE`Yxq3RuV ztDR}y`a0Qv{7Yi*{ycKgMWF`v@=!niHu42QJ)of0!OLU${|XBG*OR_?o{%JI&!O_q z^9D=Xbbj~IgCVn*^#1tPwik6cXrP1c0ynJz&kJ{+e|VpGp;^&D<9p?sZoR!Q_TH&q zh!a~~tu6bu=h3P*vsQ7g uZ&m9zQmWtfSIs}Kp?(gc-yU5ItF>c{b0TnlbnhOyo3s-I0Xa`f%Z-yoCP9V7DYP%lh$cvItGoErX9;K8Y27%6Y zAR7j@B0vWT*NF~@GBL9xXhS=~h#-mpf-WxP_$V@F`|O(p`_w@11sa&h9RvsA1zWmi>b}Bb5&W|nBv0yitK#<{Gf@VS*?Q9!R z%9WKW`MJFo2pk=`^+}Py#w5d40Mpe)DKP`HtO%Vn>(EEAb%q@Y%P;aI2LBxx6&x=? z#a|+znzrJ?gbIbLs0I2NR&H!+tg7 zP41X#y1&vxURzI|c6~Wdw)kap*)p6!&=NbZ!rwo#osioOzd8RBk583eT; diff --git a/src/MeoAssistance/MeoAssistance.vcxproj b/src/MeoAssistance/MeoAssistance.vcxproj index 8f2790fad5..1307c0d8a9 100644 --- a/src/MeoAssistance/MeoAssistance.vcxproj +++ b/src/MeoAssistance/MeoAssistance.vcxproj @@ -177,7 +177,7 @@ true true true - libmeojson.lib;OcrLiteOnnx.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) + libmeojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) RequireAdministrator @@ -222,7 +222,7 @@ xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource true true true - libmeojson.lib;OcrLiteOnnx.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) + libmeojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) RequireAdministrator diff --git a/src/MeoAssistance/OcrPack.cpp b/src/MeoAssistance/OcrPack.cpp index e5ed4beaac..77218c02c5 100644 --- a/src/MeoAssistance/OcrPack.cpp +++ b/src/MeoAssistance/OcrPack.cpp @@ -1,81 +1,95 @@ #include "OcrPack.h" -#include +#include #include #include "AsstUtils.hpp" #include "Logger.hpp" -asst::OcrPack::OcrPack() - : m_ocr_ptr(std::make_unique()) -{} - -asst::OcrPack::~OcrPack() = default; - -bool asst::OcrPack::load(const std::string & dir) +asst::OcrPack::~OcrPack() { - constexpr static const char* DetName = "\\models\\dbnet.onnx"; - constexpr static const char* ClsName = "\\models\\angle_net.onnx"; - constexpr static const char* RecName = "\\models\\crnn_lite_lstm.onnx"; - constexpr static const char* KeysName = "\\models\\keys.txt"; + PaddleOcrDestroy(m_ocr); +} + +bool asst::OcrPack::load(const std::string& dir) +{ + constexpr static const char* DetName = "\\det"; + //constexpr static const char* ClsName = "\\cls"; + constexpr static const char* RecName = "\\rec"; + constexpr static const char* KeysName = "\\ppocr_keys_v1.txt"; const std::string dst_filename = dir + DetName; - const std::string cls_filename = dir + ClsName; + //const std::string cls_filename = dir + ClsName; const std::string rec_filename = dir + RecName; const std::string keys_filename = dir + KeysName; - return m_ocr_ptr->initModels(dst_filename, cls_filename, rec_filename, keys_filename); + if (m_ocr != nullptr) { + PaddleOcrDestroy(m_ocr); + } + m_ocr = PaddleOcrCreate(dst_filename.c_str(), rec_filename.c_str(), keys_filename.c_str(), nullptr); + + return m_ocr != nullptr; } -void asst::OcrPack::set_param(int /*gpu_index*/, int thread_number) +std::vector asst::OcrPack::recognize(const cv::Mat& image, const asst::TextRectProc& pred) { - // gpu_index是ncnn的参数,onnx架构的没有,预留参数接口 - m_ocr_ptr->setNumThread(thread_number); -} + std::vector buf; + cv::imencode(".png", image, buf); -std::vector asst::OcrPack::recognize(const cv::Mat & image, const asst::TextRectProc & pred) -{ - constexpr int padding = 50; - constexpr int maxSideLen = 0; - constexpr float boxScoreThresh = 0.2f; - constexpr float boxThresh = 0.3f; - constexpr float unClipRatio = 2.0f; - constexpr bool doAngle = false; - constexpr bool mostAngle = false; + constexpr static size_t MaxBoxSize = 128; - OcrResult ocr_results = m_ocr_ptr->detect(image, - padding, maxSideLen, - boxScoreThresh, boxThresh, - unClipRatio, doAngle, mostAngle); + // each box has 8 value ( 4 points, x and y ) + int boxes[MaxBoxSize * 8] = { 0 }; + char* strs[MaxBoxSize] = { 0 }; + for (size_t i = 0; i != MaxBoxSize; ++i) { + constexpr static size_t MaxTextSize = 128; + *(strs + i) = new char[MaxTextSize]; + memset(*(strs + i), 0, MaxTextSize); + } + float scores[MaxBoxSize] = { 0 }; + size_t size; + + PaddleOcrSystem( + m_ocr, buf.data(), buf.size(), false, + boxes, strs, scores, &size, nullptr, nullptr); std::vector result; std::string log_str_raw; std::string log_str_proc; - for (TextBlock& text_block : ocr_results.textBlocks) { - if (text_block.boxPoint.size() != 4) { - continue; - } - // the rect like ↓ + for (size_t i = 0; i != size; ++i) { + // the box rect like ↓ // 0 - 1 // 3 - 2 - int x = text_block.boxPoint.at(0).x; - int y = text_block.boxPoint.at(0).y; - int width = text_block.boxPoint.at(1).x - x; - int height = text_block.boxPoint.at(3).y - y; + int* box = boxes + i * 8; + int x_collect[4] = { *(box + 0), *(box + 2), *(box + 4), *(box + 6) }; + int y_collect[4] = { *(box + 1), *(box + 3), *(box + 5), *(box + 7) }; + int left = int(*std::min_element(x_collect, x_collect + 4)); + int right = int(*std::max_element(x_collect, x_collect + 4)); + int top = int(*std::min_element(y_collect, y_collect + 4)); + int bottom = int(*std::max_element(y_collect, y_collect + 4)); + + Rect rect(left, top, right - left, bottom - top); + + std::string text(*(strs + i)); + float score = *(scores + i); + TextRect tr{ text, rect, score }; - TextRect tr{ std::move(text_block.text), Rect(x, y, width, height) }; log_str_raw += (std::string)tr + ", "; if (!pred || pred(tr)) { log_str_proc += tr.to_string() + ", "; result.emplace_back(std::move(tr)); } } + for (size_t i = 0; i != MaxBoxSize; ++i) { + delete[] * (strs + i); + } + Log.trace("OcrPack::recognize | raw : ", log_str_raw); Log.trace("OcrPack::recognize | proc : ", log_str_proc); return result; } -std::vector asst::OcrPack::recognize(const cv::Mat & image, const asst::Rect & roi, const asst::TextRectProc & pred) +std::vector asst::OcrPack::recognize(const cv::Mat& image, const asst::Rect& roi, const asst::TextRectProc& pred) { auto rect_cor = [&roi, &pred](TextRect& tr) -> bool { tr.rect.x += roi.x; diff --git a/src/MeoAssistance/OcrPack.h b/src/MeoAssistance/OcrPack.h index 994156b4fa..d241a99f61 100644 --- a/src/MeoAssistance/OcrPack.h +++ b/src/MeoAssistance/OcrPack.h @@ -2,31 +2,31 @@ #include "AbstractResource.h" #include -#include #include "AsstDef.h" -class OcrLiteCaller; namespace cv { class Mat; } +struct paddle_ocr_t; namespace asst { class OcrPack final : public AbstractResource { public: - OcrPack(); + using AbstractResource::AbstractResource; virtual ~OcrPack(); virtual bool load(const std::string& dir) override; - void set_param(int /*gpu_index*/, int thread_number); std::vector recognize(const cv::Mat& image, const TextRectProc& pred = nullptr); std::vector recognize(const cv::Mat& image, const Rect& roi, const TextRectProc& pred = nullptr); + std::vector only_rec(const cv::Mat& image, const TextRectProc& pred = nullptr); + std::vector only_rec(const cv::Mat& image, const Rect& roi, const TextRectProc& pred = nullptr); private: - std::unique_ptr m_ocr_ptr; + paddle_ocr_t* m_ocr = nullptr; }; } diff --git a/src/MeoAssistance/README.md b/src/MeoAssistance/README.md index 2683c03081..41611c31ef 100644 --- a/src/MeoAssistance/README.md +++ b/src/MeoAssistance/README.md @@ -10,7 +10,8 @@ ## 识别及解析 - 图像识别库:[opencv](https://github.com/opencv/opencv.git) -- 文字识别库:[chineseocr_lite](https://github.com/DayBreak-u/chineseocr_lite.git) +- ~~文字识别库:[chineseocr_lite](https://github.com/DayBreak-u/chineseocr_lite.git)~~ +- 文字识别库:[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) - 关卡掉落识别:[企鹅物流识别](https://github.com/KumoSiunaus/penguin-stats-recognize-v3) - C++ JSON库:[meojson](https://github.com/MistEO/meojson.git) diff --git a/src/MeoAssistance/Resource.cpp b/src/MeoAssistance/Resource.cpp index 39c47fb31d..e15bc2a6aa 100644 --- a/src/MeoAssistance/Resource.cpp +++ b/src/MeoAssistance/Resource.cpp @@ -17,7 +17,7 @@ bool asst::Resource::load(const std::string& dir) constexpr static const char* ItemCfgFilename = "item_index.json"; constexpr static const char* InfrastCfgFilename = "infrast.json"; constexpr static const char* UserCfgFilename = "..\\user.json"; - constexpr static const char* OcrResourceFilename = "OcrLiteOnnx"; + constexpr static const char* OcrResourceFilename = "PaddleOCR"; constexpr static const char* PenguinResourceFilename = "penguin-stats-recognize"; /* 加载各个Json配置文件 */ @@ -65,7 +65,7 @@ bool asst::Resource::load(const std::string& dir) } /* 加载OCR库所需要的资源 */ - m_ocr_pack_unique_ins.set_param(opt.ocr_gpu_index, opt.ocr_thread_number); + //m_ocr_pack_unique_ins.set_param(opt.ocr_gpu_index, opt.ocr_thread_number); if (!m_ocr_pack_unique_ins.load(dir + OcrResourceFilename)) { m_last_error = m_ocr_pack_unique_ins.get_last_error(); return false; @@ -78,4 +78,4 @@ bool asst::Resource::load(const std::string& dir) } return true; -} \ No newline at end of file +} diff --git a/tools/TestCaller/main.cpp b/tools/TestCaller/main.cpp index 62adee4caa..98f27a1743 100644 --- a/tools/TestCaller/main.cpp +++ b/tools/TestCaller/main.cpp @@ -31,11 +31,11 @@ int main(int argc, char** argv) while (ch != 'q') { //AsstAppendFight(ptr, 0, 0, 99999); //AsstAppendVisit(ptr, true); - //{ - // const int required[] = { 3, 4, 5, 6 }; - // AsstStartRecruitCalc(ptr, required, sizeof(required) / sizeof(int), true); - //} - AsstAppendDebug(ptr); + { + const int required[] = { 3, 4, 5, 6 }; + AsstStartRecruitCalc(ptr, required, sizeof(required) / sizeof(int), true); + } + //AsstAppendDebug(ptr); //{ // const char* order[] = { "Trade", "Mfg", "Dorm" }; // AsstAppendInfrast(ptr, 1, order, 3, 0, 0); From 8dfb34ef36847070dee3172d4d16a973bf6da74b Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 13 Dec 2021 00:11:53 +0800 Subject: [PATCH 03/13] =?UTF-8?q?perf.=E9=92=88=E5=AF=B9=E9=A3=9E=E6=A1=A8?= =?UTF-8?q?OCR=E8=BF=9B=E8=A1=8C=E9=83=A8=E5=88=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/config.json | 2 - resource/tasks.json | 47 ++----------------- src/MeoAssistance/Assistance.cpp | 2 +- src/MeoAssistance/GeneralConfiger.cpp | 6 +-- src/MeoAssistance/GeneralConfiger.h | 4 +- src/MeoAssistance/InfrastAbstractTask.cpp | 2 +- src/MeoAssistance/OcrImageAnalyzer.cpp | 2 +- src/MeoAssistance/OcrImageAnalyzer.h | 9 ++-- src/MeoAssistance/OcrPack.cpp | 25 ++++++---- src/MeoAssistance/OcrPack.h | 6 +-- .../ProcessTaskImageAnalyzer.cpp | 3 +- 11 files changed, 38 insertions(+), 70 deletions(-) diff --git a/resource/config.json b/resource/config.json index c2a0c91105..63ed461ae9 100644 --- a/resource/config.json +++ b/resource/config.json @@ -16,8 +16,6 @@ 0 ], "controlDelayRange_Doc": "点击随机延时:每次点击操作会进行随机延时,降低封号风险(好像也没听说过谁被封号的)。格式为 [ 最小延时, 最大延时 ],单位为毫秒。例如想设置3~5秒延时,即修改为[ 3000, 5000 ],默认0~0", - "ocrThreadNumber": 4, - "ocrThreadNumber_Doc": "文字识别库OcrLite的线程数量,理论上开的高点识别会快点,但是会更卡。默认4", "adbExtraSwipeDist": 50, "adbExtraSwipeDist_Doc": "额外的滑动距离:adb有bug,同样的参数,偶尔会划得非常远。额外做一个短程滑动,把之前的停下来", "adbExtraSwipeDuration": 1000, diff --git a/resource/tasks.json b/resource/tasks.json index cc31a9296e..cf61e94a96 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -1084,49 +1084,12 @@ "algorithm": "OcrDetect", "text": [], "roi": [ - 200, - 200, - 800, - 500 + 375, + 360, + 480, + 120 ], - "ocrReplace": [ - [ - "沮击", - "狙击" - ], - [ - "犯击", - "狙击" - ], - [ - "泪击", - "狙击" - ], - [ - "都出", - "输出" - ], - [ - "都乐", - "输出" - ], - [ - "抓出", - "输出" - ], - [ - "都任", - "输出" - ], - [ - "新于", - "新手" - ], - [ - "防拍", - "防护" - ] - ] + "ocrReplace": [] }, "RecruitRefresh": { "action": "clickSelf", diff --git a/src/MeoAssistance/Assistance.cpp b/src/MeoAssistance/Assistance.cpp index fee548ff25..52a1941df6 100644 --- a/src/MeoAssistance/Assistance.cpp +++ b/src/MeoAssistance/Assistance.cpp @@ -442,7 +442,7 @@ bool Assistance::stop(bool block) decltype(m_tasks_queue) empty; m_tasks_queue.swap(empty); - clear_cache(); + //clear_cache(); return true; } diff --git a/src/MeoAssistance/GeneralConfiger.cpp b/src/MeoAssistance/GeneralConfiger.cpp index 22aff5f5cb..5931ae1193 100644 --- a/src/MeoAssistance/GeneralConfiger.cpp +++ b/src/MeoAssistance/GeneralConfiger.cpp @@ -17,8 +17,8 @@ bool asst::GeneralConfiger::parse(const json::value& json) m_options.penguin_report_cmd_line = options_json.at("penguinReportCmdLine").as_string(); m_options.penguin_report_server = options_json.get("penguinReportServer", "CN"); - m_options.ocr_gpu_index = options_json.get("ocrGpuIndex", -1); - m_options.ocr_thread_number = options_json.at("ocrThreadNumber").as_integer(); + //m_options.ocr_gpu_index = options_json.get("ocrGpuIndex", -1); + //m_options.ocr_thread_number = options_json.at("ocrThreadNumber").as_integer(); m_options.adb_extra_swipe_dist = options_json.get("adbExtraSwipeDist", 100); m_options.adb_extra_swipe_duration = options_json.get("adbExtraSwipeDuration", -1); @@ -52,4 +52,4 @@ bool asst::GeneralConfiger::parse(const json::value& json) } return true; -} \ No newline at end of file +} diff --git a/src/MeoAssistance/GeneralConfiger.h b/src/MeoAssistance/GeneralConfiger.h index 1cca486cf4..d9b6a8ec8a 100644 --- a/src/MeoAssistance/GeneralConfiger.h +++ b/src/MeoAssistance/GeneralConfiger.h @@ -27,8 +27,8 @@ namespace asst std::string penguin_report_cmd_line; // 企鹅数据汇报的命令 std::string penguin_report_extra_param; // 企鹅数据汇报的命令 std::string penguin_report_server; // 企鹅数据汇报接口"server"字段,"CN", "US", "JP" and "KR". - int ocr_gpu_index = -1; // OcrLite使用GPU编号,-1(使用CPU)/0(使用GPU0)/1(使用GPU1)/... - int ocr_thread_number = 0; // OcrLite线程数量 + //int ocr_gpu_index = -1; // OcrLite使用GPU编号,-1(使用CPU)/0(使用GPU0)/1(使用GPU1)/... + //int ocr_thread_number = 0; // OcrLite线程数量 int adb_extra_swipe_dist = 0; // 额外的滑动距离:adb有bug,同样的参数,偶尔会划得非常远。额外做一个短程滑动,把之前的停下来 int adb_extra_swipe_duration = -1; // 额外的滑动持续时间:adb有bug,同样的参数,偶尔会划得非常远。额外做一个短程滑动,把之前的停下来。若小于0,则关闭额外滑动功能 }; diff --git a/src/MeoAssistance/InfrastAbstractTask.cpp b/src/MeoAssistance/InfrastAbstractTask.cpp index d4d92940ca..ca59ce86cb 100644 --- a/src/MeoAssistance/InfrastAbstractTask.cpp +++ b/src/MeoAssistance/InfrastAbstractTask.cpp @@ -95,7 +95,7 @@ bool asst::InfrastAbstractTask::enter_oper_list_page() auto image = Ctrler.get_image(); - // 识别右边的“进驻”按钮 + // 识别左边的“进驻”按钮 const auto enter_task_ptr = std::dynamic_pointer_cast( task.get("InfrastEnterOperList")); OcrImageAnalyzer enter_analyzer(image); diff --git a/src/MeoAssistance/OcrImageAnalyzer.cpp b/src/MeoAssistance/OcrImageAnalyzer.cpp index f54eaaec44..ba4c89c305 100644 --- a/src/MeoAssistance/OcrImageAnalyzer.cpp +++ b/src/MeoAssistance/OcrImageAnalyzer.cpp @@ -48,7 +48,7 @@ bool asst::OcrImageAnalyzer::analyze() } return true; }; - m_ocr_result = Resrc.ocr().recognize(m_image, m_roi, all_pred); + m_ocr_result = Resrc.ocr().recognize(m_image, m_roi, all_pred, m_without_det); //log.trace("ocr result", m_ocr_result); return !m_ocr_result.empty(); } diff --git a/src/MeoAssistance/OcrImageAnalyzer.h b/src/MeoAssistance/OcrImageAnalyzer.h index 3d4d5f78eb..38c7ea3532 100644 --- a/src/MeoAssistance/OcrImageAnalyzer.h +++ b/src/MeoAssistance/OcrImageAnalyzer.h @@ -36,9 +36,11 @@ namespace asst correct_roi(); auto& cache_roi = task_info.region_of_appeared; if (task_info.cache && !cache_roi.empty()) { - if (cache_roi.area() < m_roi.area()) { - m_roi = cache_roi; - } + m_roi = cache_roi; + m_without_det = true; + } + else { + m_without_det = false; } } @@ -57,5 +59,6 @@ namespace asst bool m_full_match = false; std::unordered_map m_replace; TextRectProc m_pred = nullptr; + bool m_without_det = false; }; } diff --git a/src/MeoAssistance/OcrPack.cpp b/src/MeoAssistance/OcrPack.cpp index 77218c02c5..89365da140 100644 --- a/src/MeoAssistance/OcrPack.cpp +++ b/src/MeoAssistance/OcrPack.cpp @@ -31,27 +31,33 @@ bool asst::OcrPack::load(const std::string& dir) return m_ocr != nullptr; } -std::vector asst::OcrPack::recognize(const cv::Mat& image, const asst::TextRectProc& pred) +std::vector asst::OcrPack::recognize(const cv::Mat& image, const asst::TextRectProc& pred, bool without_det) { + LogTraceFunction; + std::vector buf; cv::imencode(".png", image, buf); constexpr static size_t MaxBoxSize = 128; - // each box has 8 value ( 4 points, x and y ) int boxes[MaxBoxSize * 8] = { 0 }; char* strs[MaxBoxSize] = { 0 }; for (size_t i = 0; i != MaxBoxSize; ++i) { - constexpr static size_t MaxTextSize = 128; + constexpr static size_t MaxTextSize = 1024; *(strs + i) = new char[MaxTextSize]; memset(*(strs + i), 0, MaxTextSize); } float scores[MaxBoxSize] = { 0 }; size_t size; - PaddleOcrSystem( - m_ocr, buf.data(), buf.size(), false, - boxes, strs, scores, &size, nullptr, nullptr); + if (!without_det) { + PaddleOcrSystem(m_ocr, buf.data(), buf.size(), false, + boxes, strs, scores, &size, nullptr, nullptr); + } + else { + PaddleOcrRec(m_ocr, buf.data(), buf.size(), + strs, scores, &size, nullptr, nullptr); + } std::vector result; std::string log_str_raw; @@ -71,10 +77,11 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const Rect rect(left, top, right - left, bottom - top); std::string text(*(strs + i)); + std::cout << text.size() << std::endl; float score = *(scores + i); TextRect tr{ text, rect, score }; - log_str_raw += (std::string)tr + ", "; + log_str_raw += tr.to_string() + ", "; if (!pred || pred(tr)) { log_str_proc += tr.to_string() + ", "; result.emplace_back(std::move(tr)); @@ -89,7 +96,7 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const return result; } -std::vector asst::OcrPack::recognize(const cv::Mat& image, const asst::Rect& roi, const asst::TextRectProc& pred) +std::vector asst::OcrPack::recognize(const cv::Mat& image, const asst::Rect& roi, const asst::TextRectProc& pred, bool without_det) { auto rect_cor = [&roi, &pred](TextRect& tr) -> bool { tr.rect.x += roi.x; @@ -97,5 +104,5 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const return pred(tr); }; Log.trace("OcrPack::recognize | roi : ", roi.to_string()); - return recognize(image(utils::make_rect(roi)), rect_cor); + return recognize(image(utils::make_rect(roi)), rect_cor, without_det); } diff --git a/src/MeoAssistance/OcrPack.h b/src/MeoAssistance/OcrPack.h index d241a99f61..6e0f953771 100644 --- a/src/MeoAssistance/OcrPack.h +++ b/src/MeoAssistance/OcrPack.h @@ -21,11 +21,9 @@ namespace asst virtual bool load(const std::string& dir) override; - std::vector recognize(const cv::Mat& image, const TextRectProc& pred = nullptr); - std::vector recognize(const cv::Mat& image, const Rect& roi, const TextRectProc& pred = nullptr); + std::vector recognize(const cv::Mat& image, const TextRectProc& pred = nullptr, bool without_det = false); + std::vector recognize(const cv::Mat& image, const Rect& roi, const TextRectProc& pred = nullptr, bool without_det = false); - std::vector only_rec(const cv::Mat& image, const TextRectProc& pred = nullptr); - std::vector only_rec(const cv::Mat& image, const Rect& roi, const TextRectProc& pred = nullptr); private: paddle_ocr_t* m_ocr = nullptr; }; diff --git a/src/MeoAssistance/ProcessTaskImageAnalyzer.cpp b/src/MeoAssistance/ProcessTaskImageAnalyzer.cpp index f984495a1c..51d8e2ac0a 100644 --- a/src/MeoAssistance/ProcessTaskImageAnalyzer.cpp +++ b/src/MeoAssistance/ProcessTaskImageAnalyzer.cpp @@ -56,8 +56,7 @@ bool asst::ProcessTaskImageAnalyzer::ocr_analyze(std::shared_ptr task_ if (flag && ocr_task_ptr->roi.include(tr.rect)) { m_result = ocr_task_ptr; m_result_rect = tr.rect; - ocr_task_ptr->region_of_appeared - = m_result_rect.center_zoom(1.5, m_image.cols, m_image.rows); // OCR库不扩大一点容易识别不到 + ocr_task_ptr->region_of_appeared = m_result_rect; Log.trace("ProcessTaskImageAnalyzer::ocr_analyze | found in cache", tr.to_string()); return true; } From 278071624528e64b6712ea0753397f1c922d1e19 Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 13 Dec 2021 00:27:38 +0800 Subject: [PATCH 04/13] =?UTF-8?q?opt.=E4=BC=98=E5=8C=96=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=8B=E8=BD=BD=E5=87=BA=E9=94=99=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistance/Version.h | 2 +- src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/MeoAssistance/Version.h b/src/MeoAssistance/Version.h index 8e7f4bda86..8ed9c43a27 100644 --- a/src/MeoAssistance/Version.h +++ b/src/MeoAssistance/Version.h @@ -2,5 +2,5 @@ namespace asst { - constexpr static const char* Version = "v2.3.5"; + constexpr static const char* Version = "v2.4.0"; } diff --git a/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs b/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs index 72bf145b9c..a86bdd7ccd 100644 --- a/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs +++ b/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs @@ -186,12 +186,13 @@ namespace MeoAsstGui .AddButton(openUrlToastButton) .Show(); // 下载压缩包 - const int downloadRetryMaxTimes = 1; + const int downloadRetryMaxTimes = 2; string downloadTempFilename = UpdatePackageName + ".tmp"; bool downloaded = false; for (int i = 0; i != downloadRetryMaxTimes; ++i) { - if (DownloadFile(_downloadUrl, downloadTempFilename)) + if (DownloadFile(_downloadUrl.Replace("github.com", "hub.fastgit.org"), downloadTempFilename) + || DownloadFile(_downloadUrl, downloadTempFilename)) { downloaded = true; break; @@ -267,7 +268,7 @@ namespace MeoAsstGui string downUrl = asset["browser_download_url"].ToString(); if (downUrl.IndexOf("MeoAssistance") != -1) { - _downloadUrl = downUrl.Replace("github.com", "hub.fastgit.org"); + _downloadUrl = downUrl; _lastestJson = json; return true; } From 716d4e079a578187470f008e8a4c35dbcee9d305 Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 14 Dec 2021 21:29:35 +0800 Subject: [PATCH 05/13] =?UTF-8?q?style.=E9=A1=B9=E7=9B=AE=E3=80=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E7=BB=9F=E4=B8=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 +- ...ssistance.sln => MeoAssistantArknights.sln | 140 +- README.md | 10 +- appveyor.yml | 2 +- include/AsstCaller.h | 44 +- include/AsstPort.h | 38 +- .../.editorconfig | 0 .../AbstractConfiger.cpp | 0 .../AbstractConfiger.h | 0 .../AbstractImageAnalyzer.cpp | 0 .../AbstractImageAnalyzer.h | 0 .../AbstractResource.cpp | 0 .../AbstractResource.h | 0 .../AbstractTask.cpp | 0 .../AbstractTask.h | 2 +- .../Assistance.cpp | 1190 ++++++++--------- .../Assistance.h | 0 .../AsstCaller.cpp | 504 +++---- src/{MeoAssistance => MeoAssistant}/AsstDef.h | 0 .../AsstInfrastDef.h | 0 src/{MeoAssistance => MeoAssistant}/AsstMsg.h | 0 .../AsstUtils.hpp | 0 .../AutoRecruitTask.cpp | 136 +- .../AutoRecruitTask.h | 0 .../Controller.cpp | 0 .../Controller.h | 0 .../CreditShopImageAnalyzer.cpp | 0 .../CreditShopImageAnalyzer.h | 0 .../CreditShoppingTask.cpp | 0 .../CreditShoppingTask.h | 0 .../GeneralConfiger.cpp | 0 .../GeneralConfiger.h | 0 .../InfrastAbstractTask.cpp | 0 .../InfrastAbstractTask.h | 0 .../InfrastClueImageAnalyzer.cpp | 0 .../InfrastClueImageAnalyzer.h | 0 .../InfrastClueVacancyImageAnalyzer.cpp | 0 .../InfrastClueVacancyImageAnalyzer.h | 0 .../InfrastConfiger.cpp | 0 .../InfrastConfiger.h | 0 .../InfrastControlTask.cpp | 0 .../InfrastControlTask.h | 0 .../InfrastDormTask.cpp | 0 .../InfrastDormTask.h | 0 .../InfrastFacilityImageAnalyzer.cpp | 0 .../InfrastFacilityImageAnalyzer.h | 0 .../InfrastInfoTask.cpp | 0 .../InfrastInfoTask.h | 0 .../InfrastMfgTask.cpp | 0 .../InfrastMfgTask.h | 0 .../InfrastOfficeTask.cpp | 0 .../InfrastOfficeTask.h | 0 .../InfrastOperImageAnalyzer.cpp | 0 .../InfrastOperImageAnalyzer.h | 0 .../InfrastPowerTask.cpp | 0 .../InfrastPowerTask.h | 0 .../InfrastProductionTask.cpp | 28 +- .../InfrastProductionTask.h | 0 .../InfrastReceptionTask.cpp | 0 .../InfrastReceptionTask.h | 0 .../InfrastSmileyImageAnalyzer.cpp | 0 .../InfrastSmileyImageAnalyzer.h | 0 .../InfrastTradeTask.cpp | 0 .../InfrastTradeTask.h | 0 .../ItemConfiger.cpp | 0 .../ItemConfiger.h | 0 .../Logger.hpp | 2 +- .../MatchImageAnalyzer.cpp | 0 .../MatchImageAnalyzer.h | 0 .../MeoAssistant.vcxproj} | 506 +++---- .../MeoAssistant.vcxproj.filters} | 728 +++++----- .../MultiMatchImageAnalyzer.cpp | 0 .../MultiMatchImageAnalyzer.h | 0 .../OcrImageAnalyzer.cpp | 108 +- .../OcrImageAnalyzer.h | 128 +- .../OcrPack.cpp | 0 src/{MeoAssistance => MeoAssistant}/OcrPack.h | 0 .../PenguinPack.cpp | 0 .../PenguinPack.h | 0 .../PenguinUploader.cpp | 6 +- .../PenguinUploader.h | 0 .../ProcessTask.cpp | 0 .../ProcessTask.h | 0 .../ProcessTaskImageAnalyzer.cpp | 0 .../ProcessTaskImageAnalyzer.h | 0 src/{MeoAssistance => MeoAssistant}/README.md | 2 +- .../RecruitConfiger.cpp | 0 .../RecruitConfiger.h | 0 .../RecruitImageAnalyzer.cpp | 0 .../RecruitImageAnalyzer.h | 0 .../RecruitTask.cpp | 0 .../RecruitTask.h | 0 .../Resource.cpp | 0 .../Resource.h | 0 .../RuntimeStatus.cpp | 0 .../RuntimeStatus.h | 0 .../TaskData.cpp | 404 +++--- .../TaskData.h | 22 +- .../TemplResource.cpp | 2 +- .../TemplResource.h | 0 .../UserConfiger.cpp | 0 .../UserConfiger.h | 0 src/{MeoAssistance => MeoAssistant}/Version.h | 0 src/MeoAsstGui/.editorconfig | 2 +- src/MeoAsstGui/Helper/AsstProxy.cs | 32 +- src/MeoAsstGui/Helper/AutoScroll.cs | 2 +- src/MeoAsstGui/Helper/CombData.cs | 2 +- src/MeoAsstGui/Helper/DragItemViewModel.cs | 2 +- .../Helper/FlowDocumentPagePadding.cs | 2 +- src/MeoAsstGui/Helper/LogItemViewModel.cs | 2 +- src/MeoAsstGui/Helper/ScrollViewerBinding.cs | 2 +- src/MeoAsstGui/MeoAsstGui.csproj | 6 +- .../AutoRecruitSettingsUserControl.xaml.cs | 2 +- .../ConnectSettingsUserControl.xaml.cs | 2 +- .../InfrastSettingsUserControl.xaml.cs | 2 +- .../MallSettingsUserControl.xaml.cs | 2 +- .../PenguinReportSettingsUserControl.xaml.cs | 2 +- .../VersionUpdateSettingsUserControl.xaml.cs | 2 +- .../ViewModels/SettingsViewModel.cs | 6 +- .../ViewModels/VersionUpdateViewModel.cs | 258 ++-- src/Python/interface.py | 2 +- tools/TestCaller/TestCaller.vcxproj | 4 +- .../TransparentImageCvt.vcxproj | 61 - tools/TransparentImageCvt/main.cpp | 7 +- tools/build_release.bat | 2 +- tools/zip_release.sh | 2 +- tools/使用说明.url | 2 +- tools/问题反馈.url | 2 +- 128 files changed, 2182 insertions(+), 2240 deletions(-) rename MeoAssistance.sln => MeoAssistantArknights.sln (94%) rename src/{MeoAssistance => MeoAssistant}/.editorconfig (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractConfiger.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractConfiger.h (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractResource.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractResource.h (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/AbstractTask.h (99%) rename src/{MeoAssistance => MeoAssistant}/Assistance.cpp (96%) rename src/{MeoAssistance => MeoAssistant}/Assistance.h (100%) rename src/{MeoAssistance => MeoAssistant}/AsstCaller.cpp (95%) rename src/{MeoAssistance => MeoAssistant}/AsstDef.h (100%) rename src/{MeoAssistance => MeoAssistant}/AsstInfrastDef.h (100%) rename src/{MeoAssistance => MeoAssistant}/AsstMsg.h (100%) rename src/{MeoAssistance => MeoAssistant}/AsstUtils.hpp (100%) rename src/{MeoAssistance => MeoAssistant}/AutoRecruitTask.cpp (97%) rename src/{MeoAssistance => MeoAssistant}/AutoRecruitTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/Controller.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/Controller.h (100%) rename src/{MeoAssistance => MeoAssistant}/CreditShopImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/CreditShopImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/CreditShoppingTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/CreditShoppingTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/GeneralConfiger.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/GeneralConfiger.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastAbstractTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastAbstractTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastClueImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastClueImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastClueVacancyImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastClueVacancyImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastConfiger.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastConfiger.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastControlTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastControlTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastDormTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastDormTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastFacilityImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastFacilityImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastInfoTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastInfoTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastMfgTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastMfgTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastOfficeTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastOfficeTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastOperImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastOperImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastPowerTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastPowerTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastProductionTask.cpp (99%) rename src/{MeoAssistance => MeoAssistant}/InfrastProductionTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastReceptionTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastReceptionTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastSmileyImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastSmileyImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastTradeTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/InfrastTradeTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/ItemConfiger.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/ItemConfiger.h (100%) rename src/{MeoAssistance => MeoAssistant}/Logger.hpp (99%) rename src/{MeoAssistance => MeoAssistant}/MatchImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/MatchImageAnalyzer.h (100%) rename src/{MeoAssistance/MeoAssistance.vcxproj => MeoAssistant/MeoAssistant.vcxproj} (95%) rename src/{MeoAssistance/MeoAssistance.vcxproj.filters => MeoAssistant/MeoAssistant.vcxproj.filters} (97%) rename src/{MeoAssistance => MeoAssistant}/MultiMatchImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/MultiMatchImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/OcrImageAnalyzer.cpp (96%) rename src/{MeoAssistance => MeoAssistant}/OcrImageAnalyzer.h (96%) rename src/{MeoAssistance => MeoAssistant}/OcrPack.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/OcrPack.h (100%) rename src/{MeoAssistance => MeoAssistant}/PenguinPack.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/PenguinPack.h (100%) rename src/{MeoAssistance => MeoAssistant}/PenguinUploader.cpp (96%) rename src/{MeoAssistance => MeoAssistant}/PenguinUploader.h (100%) rename src/{MeoAssistance => MeoAssistant}/ProcessTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/ProcessTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/ProcessTaskImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/ProcessTaskImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/README.md (98%) rename src/{MeoAssistance => MeoAssistant}/RecruitConfiger.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/RecruitConfiger.h (100%) rename src/{MeoAssistance => MeoAssistant}/RecruitImageAnalyzer.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/RecruitImageAnalyzer.h (100%) rename src/{MeoAssistance => MeoAssistant}/RecruitTask.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/RecruitTask.h (100%) rename src/{MeoAssistance => MeoAssistant}/Resource.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/Resource.h (100%) rename src/{MeoAssistance => MeoAssistant}/RuntimeStatus.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/RuntimeStatus.h (100%) rename src/{MeoAssistance => MeoAssistant}/TaskData.cpp (97%) rename src/{MeoAssistance => MeoAssistant}/TaskData.h (98%) rename src/{MeoAssistance => MeoAssistant}/TemplResource.cpp (99%) rename src/{MeoAssistance => MeoAssistant}/TemplResource.h (100%) rename src/{MeoAssistance => MeoAssistant}/UserConfiger.cpp (100%) rename src/{MeoAssistance => MeoAssistant}/UserConfiger.h (100%) rename src/{MeoAssistance => MeoAssistant}/Version.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77175da5f6..5b2a530057 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 2.8) -project(MeoAsst) +project(MeoAssistantArknights) include_directories(include 3rdparty/include) -aux_source_directory(src/MeoAssistance SRC) -add_definitions(-DMEO_DLL_EXPORTS) +aux_source_directory(src/MeoAssistant SRC) +add_definitions(-DASST_DLL_EXPORTS) add_compile_options("$<$:/utf-8>") add_compile_options("$<$:/utf-8>") @@ -14,11 +14,11 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set(CMAKE_CXX_STANDARD 17) -add_library(MeoAsst_LIB SHARED ${SRC}) +add_library(MeoAssistant_LIB SHARED ${SRC}) find_library(Opencv_LIB NAMES opencv_world453 PATHS 3rdparty/lib) find_library(PaddleOCR_LIB NAMES ppocr PATHS 3rdparty/lib) find_library(Penguin_LIB NAMES penguin-stats-recognize PATHS 3rdparty/lib) find_library(MeoJson_LIB NAMES libmeojson PATHS 3rdparty/lib) -target_link_libraries(MeoAsst_LIB ${Opencv_LIB} ${PaddleOCR_LIB} ${Penguin_LIB} ${MeoJson_LIB}) +target_link_libraries(MeoAssistant_LIB ${Opencv_LIB} ${PaddleOCR_LIB} ${Penguin_LIB} ${MeoJson_LIB}) diff --git a/MeoAssistance.sln b/MeoAssistantArknights.sln similarity index 94% rename from MeoAssistance.sln rename to MeoAssistantArknights.sln index 5efd5a379b..2112154325 100644 --- a/MeoAssistance.sln +++ b/MeoAssistantArknights.sln @@ -1,69 +1,71 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31912.275 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MeoAssistance", "src\MeoAssistance\MeoAssistance.vcxproj", "{362D1E30-F5AE-4279-9985-65C27B3BA300}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{6C4B8D52-51D1-45F8-AAEC-808035443FD6}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCaller", "tools\TestCaller\TestCaller.vcxproj", "{63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}" - ProjectSection(ProjectDependencies) = postProject - {362D1E30-F5AE-4279-9985-65C27B3BA300} = {362D1E30-F5AE-4279-9985-65C27B3BA300} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MeoAsstGui", "src\MeoAsstGui\MeoAsstGui.csproj", "{FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}" - ProjectSection(ProjectDependencies) = postProject - {362D1E30-F5AE-4279-9985-65C27B3BA300} = {362D1E30-F5AE-4279-9985-65C27B3BA300} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TransparentImageCvt", "tools\TransparentImageCvt\TransparentImageCvt.vcxproj", "{093A3174-A27E-4D23-B64E-16F9448AD5AC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Release|x64 = Release|x64 - Release|x86 = Release|x86 - RelWithDebInfo|x64 = RelWithDebInfo|x64 - RelWithDebInfo|x86 = RelWithDebInfo|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x64.ActiveCfg = Release|x64 - {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x64.Build.0 = Release|x64 - {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x86.ActiveCfg = Release|x64 - {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.Release|x64.ActiveCfg = Release|x64 - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.Release|x64.Build.0 = Release|x64 - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.Release|x86.ActiveCfg = Release|x64 - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x64.ActiveCfg = Release|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x64.Build.0 = Release|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x86.ActiveCfg = Release|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x86.Build.0 = Release|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|Any CPU - {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|Any CPU - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x64.ActiveCfg = Release|x64 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x64.Build.0 = Release|x64 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x86.ActiveCfg = Release|Win32 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x86.Build.0 = Release|Win32 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x64.Build.0 = Release|x64 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 - {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64} = {6C4B8D52-51D1-45F8-AAEC-808035443FD6} - {093A3174-A27E-4D23-B64E-16F9448AD5AC} = {6C4B8D52-51D1-45F8-AAEC-808035443FD6} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4F2C0E4B-4FE9-47C6-A878-6BD2FAD8B9B2} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31912.275 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{6C4B8D52-51D1-45F8-AAEC-808035443FD6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestCaller", "tools\TestCaller\TestCaller.vcxproj", "{63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}" + ProjectSection(ProjectDependencies) = postProject + {362D1E30-F5AE-4279-9985-65C27B3BA300} = {362D1E30-F5AE-4279-9985-65C27B3BA300} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MeoAsstGui", "src\MeoAsstGui\MeoAsstGui.csproj", "{FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}" + ProjectSection(ProjectDependencies) = postProject + {362D1E30-F5AE-4279-9985-65C27B3BA300} = {362D1E30-F5AE-4279-9985-65C27B3BA300} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TransparentImageCvt", "tools\TransparentImageCvt\TransparentImageCvt.vcxproj", "{093A3174-A27E-4D23-B64E-16F9448AD5AC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MeoAssistant", "src\MeoAssistant\MeoAssistant.vcxproj", "{362D1E30-F5AE-4279-9985-65C27B3BA300}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release|x64 = Release|x64 + Release|x86 = Release|x86 + RelWithDebInfo|x64 = RelWithDebInfo|x64 + RelWithDebInfo|x86 = RelWithDebInfo|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.Release|x64.ActiveCfg = Release|x64 + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.Release|x64.Build.0 = Release|x64 + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.Release|x86.ActiveCfg = Release|x64 + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x64.ActiveCfg = Release|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x64.Build.0 = Release|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x86.ActiveCfg = Release|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.Release|x86.Build.0 = Release|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|Any CPU + {FFDC8F49-8EAF-45BE-B0A8-7EF0DB9875A2}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|Any CPU + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x64.ActiveCfg = Release|x64 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x64.Build.0 = Release|x64 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x86.ActiveCfg = Release|Win32 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.Release|x86.Build.0 = Release|Win32 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x64.Build.0 = Release|x64 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 + {093A3174-A27E-4D23-B64E-16F9448AD5AC}.RelWithDebInfo|x86.Build.0 = Release|Win32 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x64.ActiveCfg = Release|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x64.Build.0 = Release|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x86.ActiveCfg = Release|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.Release|x86.Build.0 = Release|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {362D1E30-F5AE-4279-9985-65C27B3BA300}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {63B4F1A2-291C-4C85-91E1-A1F6DAE30D64} = {6C4B8D52-51D1-45F8-AAEC-808035443FD6} + {093A3174-A27E-4D23-B64E-16F9448AD5AC} = {6C4B8D52-51D1-45F8-AAEC-808035443FD6} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4F2C0E4B-4FE9-47C6-A878-6BD2FAD8B9B2} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index a83160cb9d..353051bf90 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ platform
- license - commit - stars + license + commit + stars

@@ -38,8 +38,8 @@ A Game Assistant for Arknights ## 下载地址 -[稳定版](https://github.com/MistEO/MeoAssistance/releases/latest) -[测试版](https://github.com/MistEO/MeoAssistance/releases) +[稳定版](https://github.com/MistEO/MeoAssistantArknights/releases/latest) +[测试版](https://github.com/MistEO/MeoAssistantArknights/releases) ## 模拟器支持 diff --git a/appveyor.yml b/appveyor.yml index 5f620559fb..c3e4a5f2a2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,7 @@ clone_depth: 1 before_build: - ps: nuget restore build: - project: MeoAssistance.sln + project: MeoAssistantArknights.sln parallel: true verbosity: minimal notifications: diff --git a/include/AsstCaller.h b/include/AsstCaller.h index 6eae44818c..24bad509b6 100644 --- a/include/AsstCaller.h +++ b/include/AsstCaller.h @@ -5,34 +5,34 @@ #ifdef __cplusplus extern "C" { #endif - typedef void (MEO_CALL* AsstCallback)(int msg, const char* detail_json, void* custom_arg); + typedef void (ASST_CALL* AsstCallback)(int msg, const char* detail_json, void* custom_arg); - MEOAPI_PORT void* MEO_CALL AsstCreate(const char* dirname); - MEOAPI_PORT void* MEO_CALL AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg); - void MEOAPI AsstDestroy(void* p_asst); + ASSTAPI_PORT void* ASST_CALL AsstCreate(const char* dirname); + ASSTAPI_PORT void* ASST_CALL AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg); + void ASSTAPI AsstDestroy(void* p_asst); - bool MEOAPI AsstCatchDefault(void* p_asst); - bool MEOAPI AsstCatchEmulator(void* p_asst); - bool MEOAPI AsstCatchCustom(void* p_asst, const char* address); - bool MEOAPI AsstCatchFake(void* p_asst); + bool ASSTAPI AsstCatchDefault(void* p_asst); + bool ASSTAPI AsstCatchEmulator(void* p_asst); + bool ASSTAPI AsstCatchCustom(void* p_asst, const char* address); + bool ASSTAPI AsstCatchFake(void* p_asst); - bool MEOAPI AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times); - bool MEOAPI AsstAppendAward(void* p_asst); - bool MEOAPI AsstAppendVisit(void* p_asst); - bool MEOAPI AsstAppendMall(void* p_asst, bool with_shopping); - //bool MEOAPI AsstAppendProcessTask(void* p_asst, const char* task); - bool MEOAPI AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold); - bool MEOAPI AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh); - bool MEOAPI AsstAppendDebug(void* p_asst); + bool ASSTAPI AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times); + bool ASSTAPI AsstAppendAward(void* p_asst); + bool ASSTAPI AsstAppendVisit(void* p_asst); + bool ASSTAPI AsstAppendMall(void* p_asst, bool with_shopping); + //bool ASSTAPI AsstAppendProcessTask(void* p_asst, const char* task); + bool ASSTAPI AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold); + bool ASSTAPI AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh); + bool ASSTAPI AsstAppendDebug(void* p_asst); - bool MEOAPI AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time); - bool MEOAPI AsstStart(void* p_asst); - bool MEOAPI AsstStop(void* p_asst); + bool ASSTAPI AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time); + bool ASSTAPI AsstStart(void* p_asst); + bool ASSTAPI AsstStop(void* p_asst); - bool MEOAPI AsstSetPenguinId(void* p_asst, const char* id); - //bool MEOAPI AsstSetParam(void* p_asst, const char* type, const char* param, const char* value); + bool ASSTAPI AsstSetPenguinId(void* p_asst, const char* id); + //bool ASSTAPI AsstSetParam(void* p_asst, const char* type, const char* param, const char* value); - MEOAPI_PORT const char* MEO_CALL AsstGetVersion(); + ASSTAPI_PORT const char* ASST_CALL AsstGetVersion(); #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/include/AsstPort.h b/include/AsstPort.h index 390fddcca9..f426d7fef0 100644 --- a/include/AsstPort.h +++ b/include/AsstPort.h @@ -1,37 +1,37 @@ #pragma once // The way how the function is called -#if !defined(MEO_CALL) +#if !defined(ASST_CALL) #if defined(_WIN32) -#define MEO_CALL __stdcall +#define ASST_CALL __stdcall #else -#define MEO_CALL +#define ASST_CALL #endif /* _WIN32 */ -#endif /* MEO_CALL */ +#endif /* ASST_CALL */ // The function exported symbols #if defined _WIN32 || defined __CYGWIN__ -#define MEO_DLL_IMPORT __declspec(dllimport) -#define MEO_DLL_EXPORT __declspec(dllexport) -#define MEO_DLL_LOCAL +#define ASST_DLL_IMPORT __declspec(dllimport) +#define ASST_DLL_EXPORT __declspec(dllexport) +#define ASST_DLL_LOCAL #else #if __GNUC__ >= 4 -#define MEO_DLL_IMPORT __attribute__ ((visibility ("default"))) -#define MEO_DLL_EXPORT __attribute__ ((visibility ("default"))) -#define MEO_DLL_LOCAL __attribute__ ((visibility ("hidden"))) +#define ASST_DLL_IMPORT __attribute__ ((visibility ("default"))) +#define ASST_DLL_EXPORT __attribute__ ((visibility ("default"))) +#define ASST_DLL_LOCAL __attribute__ ((visibility ("hidden"))) #else -#define MEO_DLL_IMPORT -#define MEO_DLL_EXPORT -#define MEO_DLL_LOCAL +#define ASST_DLL_IMPORT +#define ASST_DLL_EXPORT +#define ASST_DLL_LOCAL #endif #endif -#ifdef MEO_DLL_EXPORTS // defined if we are building the DLL (instead of using it) -#define MEOAPI_PORT MEO_DLL_EXPORT +#ifdef ASST_DLL_EXPORTS // defined if we are building the DLL (instead of using it) +#define ASSTAPI_PORT ASST_DLL_EXPORT #else -#define MEOAPI_PORT MEO_DLL_IMPORT -#endif // MEO_DLL_EXPORTS +#define ASSTAPI_PORT ASST_DLL_IMPORT +#endif // ASST_DLL_EXPORTS -#define MEOAPI MEOAPI_PORT MEO_CALL +#define ASSTAPI ASSTAPI_PORT ASST_CALL -#define MEOLOCAL MEO_DLL_LOCAL MEO_CALL \ No newline at end of file +#define ASSTLOCAL ASST_DLL_LOCAL ASST_CALL \ No newline at end of file diff --git a/src/MeoAssistance/.editorconfig b/src/MeoAssistant/.editorconfig similarity index 100% rename from src/MeoAssistance/.editorconfig rename to src/MeoAssistant/.editorconfig diff --git a/src/MeoAssistance/AbstractConfiger.cpp b/src/MeoAssistant/AbstractConfiger.cpp similarity index 100% rename from src/MeoAssistance/AbstractConfiger.cpp rename to src/MeoAssistant/AbstractConfiger.cpp diff --git a/src/MeoAssistance/AbstractConfiger.h b/src/MeoAssistant/AbstractConfiger.h similarity index 100% rename from src/MeoAssistance/AbstractConfiger.h rename to src/MeoAssistant/AbstractConfiger.h diff --git a/src/MeoAssistance/AbstractImageAnalyzer.cpp b/src/MeoAssistant/AbstractImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/AbstractImageAnalyzer.cpp rename to src/MeoAssistant/AbstractImageAnalyzer.cpp diff --git a/src/MeoAssistance/AbstractImageAnalyzer.h b/src/MeoAssistant/AbstractImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/AbstractImageAnalyzer.h rename to src/MeoAssistant/AbstractImageAnalyzer.h diff --git a/src/MeoAssistance/AbstractResource.cpp b/src/MeoAssistant/AbstractResource.cpp similarity index 100% rename from src/MeoAssistance/AbstractResource.cpp rename to src/MeoAssistant/AbstractResource.cpp diff --git a/src/MeoAssistance/AbstractResource.h b/src/MeoAssistant/AbstractResource.h similarity index 100% rename from src/MeoAssistance/AbstractResource.h rename to src/MeoAssistant/AbstractResource.h diff --git a/src/MeoAssistance/AbstractTask.cpp b/src/MeoAssistant/AbstractTask.cpp similarity index 100% rename from src/MeoAssistance/AbstractTask.cpp rename to src/MeoAssistant/AbstractTask.cpp diff --git a/src/MeoAssistance/AbstractTask.h b/src/MeoAssistant/AbstractTask.h similarity index 99% rename from src/MeoAssistance/AbstractTask.h rename to src/MeoAssistant/AbstractTask.h index 5b77353d96..4fbf56d6ad 100644 --- a/src/MeoAssistance/AbstractTask.h +++ b/src/MeoAssistant/AbstractTask.h @@ -25,7 +25,7 @@ namespace asst void set_retry_times(int times) noexcept { m_retry_times = times; } void set_task_chain(std::string name) noexcept { m_task_chain = std::move(name); } const std::string& get_task_chain() const noexcept { return m_task_chain; } - + constexpr static int RetryTimesDefault = 20; protected: virtual bool _run() = 0; diff --git a/src/MeoAssistance/Assistance.cpp b/src/MeoAssistant/Assistance.cpp similarity index 96% rename from src/MeoAssistance/Assistance.cpp rename to src/MeoAssistant/Assistance.cpp index 52a1941df6..1b68dac998 100644 --- a/src/MeoAssistance/Assistance.cpp +++ b/src/MeoAssistant/Assistance.cpp @@ -1,595 +1,595 @@ -#include "Assistance.h" - -#include -#include - -#include -#include - -#include "AsstUtils.hpp" -#include "Controller.h" -#include "Logger.hpp" -#include "Resource.h" - -#include "CreditShoppingTask.h" -#include "InfrastDormTask.h" -#include "InfrastInfoTask.h" -#include "InfrastMfgTask.h" -#include "InfrastOfficeTask.h" -#include "InfrastPowerTask.h" -#include "InfrastReceptionTask.h" -#include "InfrastTradeTask.h" -#include "ProcessTask.h" -#include "RecruitTask.h" -#include "AutoRecruitTask.h" -#include "InfrastControlTask.h" -#include "RuntimeStatus.h" - -using namespace asst; - -Assistance::Assistance(std::string dirname, AsstCallback callback, void* callback_arg) - : m_dirname(std::move(dirname) + "\\"), - m_callback(callback), - m_callback_arg(callback_arg) -{ - Logger::set_dirname(m_dirname); - Controller::set_dirname(m_dirname); - - LogTraceFunction; - - bool resource_ret = Resrc.load(m_dirname + "Resource\\"); - if (!resource_ret) { - const std::string& error = Resrc.get_last_error(); - Log.error("resource broken", error); - if (m_callback == nullptr) { - throw error; - } - json::value callback_json; - callback_json["type"] = "resource broken"; - callback_json["what"] = error; - m_callback(AsstMsg::InitFaild, callback_json, m_callback_arg); - throw error; - } - - m_working_thread = std::thread(std::bind(&Assistance::working_proc, this)); - m_msg_thread = std::thread(std::bind(&Assistance::msg_proc, this)); -} - -Assistance::~Assistance() -{ - LogTraceFunction; - - m_thread_exit = true; - m_thread_idle = true; - m_condvar.notify_all(); - m_msg_condvar.notify_all(); - - if (m_working_thread.joinable()) { - m_working_thread.join(); - } - if (m_msg_thread.joinable()) { - m_msg_thread.join(); - } -} - -bool asst::Assistance::catch_default() -{ - LogTraceFunction; - - auto& opt = Resrc.cfg().get_options(); - switch (opt.connect_type) { - case ConnectType::Emulator: - return catch_emulator(); - case ConnectType::Custom: - return catch_custom(); - default: - return false; - } -} - -bool Assistance::catch_emulator(const std::string& emulator_name) -{ - LogTraceFunction; - - stop(); - - bool ret = false; - //std::string cor_name = emulator_name; - auto& cfg = Resrc.cfg(); - - std::unique_lock lock(m_mutex); - - // 自动匹配模拟器,逐个找 - if (emulator_name.empty()) { - for (const auto& [name, info] : cfg.get_emulators_info()) { - ret = Ctrler.try_capture(info); - if (ret) { - //cor_name = name; - break; - } - } - } - else { // 指定的模拟器 - auto& info = cfg.get_emulators_info().at(emulator_name); - ret = Ctrler.try_capture(info); - } - - m_inited = ret; - return ret; -} - -bool asst::Assistance::catch_custom(const std::string& address) -{ - LogTraceFunction; - - stop(); - - bool ret = false; - auto& cfg = Resrc.cfg(); - - std::unique_lock lock(m_mutex); - - EmulatorInfo remote_info = cfg.get_emulators_info().at("Custom"); - if (!address.empty()) { - remote_info.adb.addresses.push_back(address); - } - - ret = Ctrler.try_capture(remote_info, true); - - m_inited = ret; - return ret; -} - -bool asst::Assistance::catch_fake() -{ - LogTraceFunction; - - stop(); - - m_inited = true; - return true; -} - -bool asst::Assistance::append_fight(int mecidine, int stone, int times, bool only_append) -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - - std::unique_lock lock(m_mutex); - - auto task_ptr = std::make_shared(task_callback, (void*)this); - task_ptr->set_task_chain("Fight"); - task_ptr->set_tasks({ "SanityBegin" }); - task_ptr->set_times_limit("MedicineConfirm", mecidine); - task_ptr->set_times_limit("StoneConfirm", stone); - task_ptr->set_times_limit("StartButton1", times); - - m_tasks_queue.emplace(task_ptr); - - if (!only_append) { - return start(false); - } - - return true; -} - -bool asst::Assistance::append_award(bool only_append) -{ - return append_process_task("AwardBegin", "Award"); -} - -bool asst::Assistance::append_visit(bool only_append) -{ - return append_process_task("VisitBegin", "Visit"); -} - -bool asst::Assistance::append_mall(bool with_shopping, bool only_append) -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - - std::unique_lock lock(m_mutex); - - const std::string task_chain = "Mall"; - - append_process_task("MallBegin", task_chain); - - if (with_shopping) { - auto shopping_task_ptr = std::make_shared(task_callback, (void*)this); - shopping_task_ptr->set_task_chain(task_chain); - m_tasks_queue.emplace(shopping_task_ptr); - } - - if (!only_append) { - return start(false); - } - - return true; -} - -bool Assistance::append_process_task(const std::string& task, std::string task_chain, int retry_times) -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - - //std::unique_lock lock(m_mutex); - - if (task_chain.empty()) { - task_chain = task; - } - - auto task_ptr = std::make_shared(task_callback, (void*)this); - task_ptr->set_task_chain(task_chain); - task_ptr->set_tasks({ task }); - task_ptr->set_retry_times(retry_times); - - m_tasks_queue.emplace(task_ptr); - - //if (!only_append) { - // return start(false); - //} - - return true; -} - -bool asst::Assistance::append_recruit(unsigned max_times, const std::vector& select_level, const std::vector& confirm_level, bool need_refresh) -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - static const std::string TaskChain = "Recruit"; - - append_process_task("RecruitBegin", TaskChain); - - auto recruit_task_ptr = std::make_shared(task_callback, (void*)this); - recruit_task_ptr->set_max_times(max_times); - recruit_task_ptr->set_need_refresh(need_refresh); - recruit_task_ptr->set_select_level(select_level); - recruit_task_ptr->set_confirm_level(confirm_level); - recruit_task_ptr->set_task_chain(TaskChain); - recruit_task_ptr->set_retry_times(AutoRecruitTaskRetryTimesDefault); - - m_tasks_queue.emplace(recruit_task_ptr); - - return true; -} - -#ifdef LOG_TRACE -bool Assistance::append_debug() -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - - std::unique_lock lock(m_mutex); - - { - constexpr static const char* DebugTaskChain = "Debug"; - auto shift_task_ptr = std::make_shared(task_callback, (void*)this); - shift_task_ptr->set_work_mode(infrast::WorkMode::Aggressive); - shift_task_ptr->set_facility("Control"); - shift_task_ptr->set_product("MoodAddition"); - shift_task_ptr->set_task_chain(DebugTaskChain); - m_tasks_queue.emplace(shift_task_ptr); - } - - return true; -} -#endif - -bool Assistance::start_recruit_calc(const std::vector& select_level, bool set_time) -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - - std::unique_lock lock(m_mutex); - - auto task_ptr = std::make_shared(task_callback, (void*)this); - task_ptr->set_param(select_level, set_time); - task_ptr->set_retry_times(OpenRecruitTaskRetryTimesDefault); - task_ptr->set_task_chain("RecruitCalc"); - m_tasks_queue.emplace(task_ptr); - - return start(false); -} - -bool asst::Assistance::append_infrast(infrast::WorkMode work_mode, const std::vector& order, const std::string& uses_of_drones, double dorm_threshold, bool only_append) -{ - LogTraceFunction; - if (!m_inited) { - return false; - } - - // 保留接口,目前强制按激进模式进行换班 - work_mode = infrast::WorkMode::Aggressive; - - constexpr static const char* InfrastTaskCahin = "Infrast"; - - // 这个流程任务,结束的时候是处于基建主界面的。既可以用于进入基建,也可以用于从设施里返回基建主界面 - - auto append_infrast_begin = [&]() { - append_process_task("InfrastBegin", InfrastTaskCahin); - }; - - append_infrast_begin(); - - auto info_task_ptr = std::make_shared(task_callback, (void*)this); - info_task_ptr->set_work_mode(work_mode); - info_task_ptr->set_task_chain(InfrastTaskCahin); - info_task_ptr->set_mood_threshold(dorm_threshold); - - m_tasks_queue.emplace(info_task_ptr); - - // 因为后期要考虑多任务间的联动等,所以这些任务的声明暂时不放到for循环中 - auto mfg_task_ptr = std::make_shared(task_callback, (void*)this); - mfg_task_ptr->set_work_mode(work_mode); - mfg_task_ptr->set_task_chain(InfrastTaskCahin); - mfg_task_ptr->set_mood_threshold(dorm_threshold); - mfg_task_ptr->set_uses_of_drone(uses_of_drones); - auto trade_task_ptr = std::make_shared(task_callback, (void*)this); - trade_task_ptr->set_work_mode(work_mode); - trade_task_ptr->set_task_chain(InfrastTaskCahin); - trade_task_ptr->set_mood_threshold(dorm_threshold); - trade_task_ptr->set_uses_of_drone(uses_of_drones); - auto power_task_ptr = std::make_shared(task_callback, (void*)this); - power_task_ptr->set_work_mode(work_mode); - power_task_ptr->set_task_chain(InfrastTaskCahin); - power_task_ptr->set_mood_threshold(dorm_threshold); - auto office_task_ptr = std::make_shared(task_callback, (void*)this); - office_task_ptr->set_work_mode(work_mode); - office_task_ptr->set_task_chain(InfrastTaskCahin); - office_task_ptr->set_mood_threshold(dorm_threshold); - auto recpt_task_ptr = std::make_shared(task_callback, (void*)this); - recpt_task_ptr->set_work_mode(work_mode); - recpt_task_ptr->set_task_chain(InfrastTaskCahin); - recpt_task_ptr->set_mood_threshold(dorm_threshold); - auto control_task_ptr = std::make_shared(task_callback, (void*)this); - control_task_ptr->set_work_mode(work_mode); - control_task_ptr->set_task_chain(InfrastTaskCahin); - control_task_ptr->set_mood_threshold(dorm_threshold); - - auto dorm_task_ptr = std::make_shared(task_callback, (void*)this); - dorm_task_ptr->set_work_mode(work_mode); - dorm_task_ptr->set_task_chain(InfrastTaskCahin); - dorm_task_ptr->set_mood_threshold(dorm_threshold); - - for (const auto& facility : order) { - if (facility == "Dorm") { - m_tasks_queue.emplace(dorm_task_ptr); - } - else if (facility == "Mfg") { - m_tasks_queue.emplace(mfg_task_ptr); - } - else if (facility == "Trade") { - m_tasks_queue.emplace(trade_task_ptr); - } - else if (facility == "Power") { - m_tasks_queue.emplace(power_task_ptr); - } - else if (facility == "Office") { - m_tasks_queue.emplace(office_task_ptr); - } - else if (facility == "Reception") { - m_tasks_queue.emplace(recpt_task_ptr); - } - else if (facility == "Control") { - m_tasks_queue.emplace(control_task_ptr); - } - else { - Log.error("append_infrast | Unknown facility", facility); - } - append_infrast_begin(); - } - - if (!only_append) { - return start(false); - } - - return true; -} - -void asst::Assistance::set_penguin_id(const std::string& id) -{ - auto& opt = Resrc.cfg().get_options(); - if (id.empty()) { - opt.penguin_report_extra_param.clear(); - } - else { - opt.penguin_report_extra_param = "-H \"authorization: PenguinID " + id + "\""; - } -} - -bool asst::Assistance::start(bool block) -{ - LogTraceFunction; - Log.trace("Start |", block ? "block" : "non block"); - - if (!m_thread_idle || !m_inited) { - return false; - } - std::unique_lock lock; - if (block) { // 外部调用 - lock = std::unique_lock(m_mutex); - } - - m_thread_idle = false; - m_condvar.notify_one(); - - return true; -} - -bool Assistance::stop(bool block) -{ - LogTraceFunction; - Log.trace("Stop |", block ? "block" : "non block"); - - m_thread_idle = true; - - std::unique_lock lock; - if (block) { // 外部调用 - lock = std::unique_lock(m_mutex); - } - decltype(m_tasks_queue) empty; - m_tasks_queue.swap(empty); - - //clear_cache(); - - return true; -} - -void Assistance::working_proc() -{ - LogTraceFunction; - - std::string pre_taskchain; - while (!m_thread_exit) { - //LogTraceScope("Assistance::working_proc Loop"); - std::unique_lock lock(m_mutex); - - if (!m_thread_idle && !m_tasks_queue.empty()) { - auto start_time = std::chrono::system_clock::now(); - - auto task_ptr = m_tasks_queue.front(); - - std::string cur_taskchain = task_ptr->get_task_chain(); - json::value task_json = json::object{ - {"task_chain", cur_taskchain}, - }; - - if (cur_taskchain != pre_taskchain) { - task_callback(AsstMsg::TaskChainStart, task_json, this); - pre_taskchain = cur_taskchain; - } - - task_ptr->set_exit_flag(&m_thread_idle); - bool ret = task_ptr->run(); - m_tasks_queue.pop(); - - if (!ret) { - task_callback(AsstMsg::TaskError, task_json, this); - } - else if (m_tasks_queue.empty() || cur_taskchain != m_tasks_queue.front()->get_task_chain()) { - task_callback(AsstMsg::TaskChainCompleted, task_json, this); - } - if (m_tasks_queue.empty()) { - task_callback(AsstMsg::AllTasksCompleted, json::value(), this); - } - - //clear_cache(); - - auto& delay = Resrc.cfg().get_options().task_delay; - m_condvar.wait_until(lock, start_time + std::chrono::milliseconds(delay), - [&]() -> bool { return m_thread_idle; }); - } - else { - pre_taskchain.clear(); - m_thread_idle = true; - //controller.set_idle(true); - m_condvar.wait(lock); - } - } -} - -void Assistance::msg_proc() -{ - LogTraceFunction; - - while (!m_thread_exit) { - //LogTraceScope("Assistance::msg_proc Loop"); - std::unique_lock lock(m_msg_mutex); - if (!m_msg_queue.empty()) { - // 结构化绑定只能是引用,后续的pop会使引用失效,所以需要重新构造一份,这里采用了move的方式 - auto&& [temp_msg, temp_detail] = m_msg_queue.front(); - AsstMsg msg = std::move(temp_msg); - json::value detail = std::move(temp_detail); - m_msg_queue.pop(); - lock.unlock(); - - if (m_callback) { - m_callback(msg, detail, m_callback_arg); - } - } - else { - m_msg_condvar.wait(lock); - } - } -} - -void Assistance::task_callback(AsstMsg msg, const json::value& detail, void* custom_arg) -{ - Log.trace("Assistance::task_callback |", msg, detail.to_string()); - - Assistance* p_this = (Assistance*)custom_arg; - json::value more_detail = detail; - switch (msg) { - case AsstMsg::PtrIsNull: - case AsstMsg::ImageIsEmpty: - p_this->stop(false); - break; - case AsstMsg::StageDrops: - more_detail = p_this->organize_stage_drop(more_detail); - break; - default: - break; - } - - // Todo: 有些不需要回调给外部的消息,得在这里给拦截掉 - // 加入回调消息队列,由回调消息线程外抛给外部 - p_this->append_callback(msg, std::move(more_detail)); -} - -void asst::Assistance::append_callback(AsstMsg msg, json::value detail) -{ - std::unique_lock lock(m_msg_mutex); - m_msg_queue.emplace(msg, std::move(detail)); - m_msg_condvar.notify_one(); -} - -void Assistance::clear_cache() -{ - Resrc.item().clear_drop_count(); - task.clear_cache(); -} - -json::value asst::Assistance::organize_stage_drop(const json::value& rec) -{ - json::value dst = rec; - auto& item = Resrc.item(); - for (json::value& drop : dst["drops"].as_array()) { - std::string id = drop["itemId"].as_string(); - int quantity = drop["quantity"].as_integer(); - item.increase_drop_count(id, quantity); - const std::string& name = item.get_item_name(id); - drop["itemName"] = name.empty() ? "未知材料" : name; - } - std::vector statistics_vec; - for (auto&& [id, count] : item.get_drop_count()) { - json::value info; - info["itemId"] = id; - const std::string& name = item.get_item_name(id); - info["itemName"] = name.empty() ? "未知材料" : name; - info["count"] = count; - statistics_vec.emplace_back(std::move(info)); - } - // 排个序,数量多的放前面 - std::sort(statistics_vec.begin(), statistics_vec.end(), - [](const json::value& lhs, const json::value& rhs) -> bool { - return lhs.at("count").as_integer() > rhs.at("count").as_integer(); - }); - - dst["statistics"] = json::array(std::move(statistics_vec)); - - Log.trace("organize_stage_drop | ", dst.to_string()); - - return dst; -} +#include "Assistance.h" + +#include +#include + +#include +#include + +#include "AsstUtils.hpp" +#include "Controller.h" +#include "Logger.hpp" +#include "Resource.h" + +#include "CreditShoppingTask.h" +#include "InfrastDormTask.h" +#include "InfrastInfoTask.h" +#include "InfrastMfgTask.h" +#include "InfrastOfficeTask.h" +#include "InfrastPowerTask.h" +#include "InfrastReceptionTask.h" +#include "InfrastTradeTask.h" +#include "ProcessTask.h" +#include "RecruitTask.h" +#include "AutoRecruitTask.h" +#include "InfrastControlTask.h" +#include "RuntimeStatus.h" + +using namespace asst; + +Assistance::Assistance(std::string dirname, AsstCallback callback, void* callback_arg) + : m_dirname(std::move(dirname) + "\\"), + m_callback(callback), + m_callback_arg(callback_arg) +{ + Logger::set_dirname(m_dirname); + Controller::set_dirname(m_dirname); + + LogTraceFunction; + + bool resource_ret = Resrc.load(m_dirname + "Resource\\"); + if (!resource_ret) { + const std::string& error = Resrc.get_last_error(); + Log.error("resource broken", error); + if (m_callback == nullptr) { + throw error; + } + json::value callback_json; + callback_json["type"] = "resource broken"; + callback_json["what"] = error; + m_callback(AsstMsg::InitFaild, callback_json, m_callback_arg); + throw error; + } + + m_working_thread = std::thread(std::bind(&Assistance::working_proc, this)); + m_msg_thread = std::thread(std::bind(&Assistance::msg_proc, this)); +} + +Assistance::~Assistance() +{ + LogTraceFunction; + + m_thread_exit = true; + m_thread_idle = true; + m_condvar.notify_all(); + m_msg_condvar.notify_all(); + + if (m_working_thread.joinable()) { + m_working_thread.join(); + } + if (m_msg_thread.joinable()) { + m_msg_thread.join(); + } +} + +bool asst::Assistance::catch_default() +{ + LogTraceFunction; + + auto& opt = Resrc.cfg().get_options(); + switch (opt.connect_type) { + case ConnectType::Emulator: + return catch_emulator(); + case ConnectType::Custom: + return catch_custom(); + default: + return false; + } +} + +bool Assistance::catch_emulator(const std::string& emulator_name) +{ + LogTraceFunction; + + stop(); + + bool ret = false; + //std::string cor_name = emulator_name; + auto& cfg = Resrc.cfg(); + + std::unique_lock lock(m_mutex); + + // 自动匹配模拟器,逐个找 + if (emulator_name.empty()) { + for (const auto& [name, info] : cfg.get_emulators_info()) { + ret = Ctrler.try_capture(info); + if (ret) { + //cor_name = name; + break; + } + } + } + else { // 指定的模拟器 + auto& info = cfg.get_emulators_info().at(emulator_name); + ret = Ctrler.try_capture(info); + } + + m_inited = ret; + return ret; +} + +bool asst::Assistance::catch_custom(const std::string& address) +{ + LogTraceFunction; + + stop(); + + bool ret = false; + auto& cfg = Resrc.cfg(); + + std::unique_lock lock(m_mutex); + + EmulatorInfo remote_info = cfg.get_emulators_info().at("Custom"); + if (!address.empty()) { + remote_info.adb.addresses.push_back(address); + } + + ret = Ctrler.try_capture(remote_info, true); + + m_inited = ret; + return ret; +} + +bool asst::Assistance::catch_fake() +{ + LogTraceFunction; + + stop(); + + m_inited = true; + return true; +} + +bool asst::Assistance::append_fight(int mecidine, int stone, int times, bool only_append) +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + + std::unique_lock lock(m_mutex); + + auto task_ptr = std::make_shared(task_callback, (void*)this); + task_ptr->set_task_chain("Fight"); + task_ptr->set_tasks({ "SanityBegin" }); + task_ptr->set_times_limit("MedicineConfirm", mecidine); + task_ptr->set_times_limit("StoneConfirm", stone); + task_ptr->set_times_limit("StartButton1", times); + + m_tasks_queue.emplace(task_ptr); + + if (!only_append) { + return start(false); + } + + return true; +} + +bool asst::Assistance::append_award(bool only_append) +{ + return append_process_task("AwardBegin", "Award"); +} + +bool asst::Assistance::append_visit(bool only_append) +{ + return append_process_task("VisitBegin", "Visit"); +} + +bool asst::Assistance::append_mall(bool with_shopping, bool only_append) +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + + std::unique_lock lock(m_mutex); + + const std::string task_chain = "Mall"; + + append_process_task("MallBegin", task_chain); + + if (with_shopping) { + auto shopping_task_ptr = std::make_shared(task_callback, (void*)this); + shopping_task_ptr->set_task_chain(task_chain); + m_tasks_queue.emplace(shopping_task_ptr); + } + + if (!only_append) { + return start(false); + } + + return true; +} + +bool Assistance::append_process_task(const std::string& task, std::string task_chain, int retry_times) +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + + //std::unique_lock lock(m_mutex); + + if (task_chain.empty()) { + task_chain = task; + } + + auto task_ptr = std::make_shared(task_callback, (void*)this); + task_ptr->set_task_chain(task_chain); + task_ptr->set_tasks({ task }); + task_ptr->set_retry_times(retry_times); + + m_tasks_queue.emplace(task_ptr); + + //if (!only_append) { + // return start(false); + //} + + return true; +} + +bool asst::Assistance::append_recruit(unsigned max_times, const std::vector& select_level, const std::vector& confirm_level, bool need_refresh) +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + static const std::string TaskChain = "Recruit"; + + append_process_task("RecruitBegin", TaskChain); + + auto recruit_task_ptr = std::make_shared(task_callback, (void*)this); + recruit_task_ptr->set_max_times(max_times); + recruit_task_ptr->set_need_refresh(need_refresh); + recruit_task_ptr->set_select_level(select_level); + recruit_task_ptr->set_confirm_level(confirm_level); + recruit_task_ptr->set_task_chain(TaskChain); + recruit_task_ptr->set_retry_times(AutoRecruitTaskRetryTimesDefault); + + m_tasks_queue.emplace(recruit_task_ptr); + + return true; +} + +#ifdef LOG_TRACE +bool Assistance::append_debug() +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + + std::unique_lock lock(m_mutex); + + { + constexpr static const char* DebugTaskChain = "Debug"; + auto shift_task_ptr = std::make_shared(task_callback, (void*)this); + shift_task_ptr->set_work_mode(infrast::WorkMode::Aggressive); + shift_task_ptr->set_facility("Control"); + shift_task_ptr->set_product("MoodAddition"); + shift_task_ptr->set_task_chain(DebugTaskChain); + m_tasks_queue.emplace(shift_task_ptr); + } + + return true; +} +#endif + +bool Assistance::start_recruit_calc(const std::vector& select_level, bool set_time) +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + + std::unique_lock lock(m_mutex); + + auto task_ptr = std::make_shared(task_callback, (void*)this); + task_ptr->set_param(select_level, set_time); + task_ptr->set_retry_times(OpenRecruitTaskRetryTimesDefault); + task_ptr->set_task_chain("RecruitCalc"); + m_tasks_queue.emplace(task_ptr); + + return start(false); +} + +bool asst::Assistance::append_infrast(infrast::WorkMode work_mode, const std::vector& order, const std::string& uses_of_drones, double dorm_threshold, bool only_append) +{ + LogTraceFunction; + if (!m_inited) { + return false; + } + + // 保留接口,目前强制按激进模式进行换班 + work_mode = infrast::WorkMode::Aggressive; + + constexpr static const char* InfrastTaskCahin = "Infrast"; + + // 这个流程任务,结束的时候是处于基建主界面的。既可以用于进入基建,也可以用于从设施里返回基建主界面 + + auto append_infrast_begin = [&]() { + append_process_task("InfrastBegin", InfrastTaskCahin); + }; + + append_infrast_begin(); + + auto info_task_ptr = std::make_shared(task_callback, (void*)this); + info_task_ptr->set_work_mode(work_mode); + info_task_ptr->set_task_chain(InfrastTaskCahin); + info_task_ptr->set_mood_threshold(dorm_threshold); + + m_tasks_queue.emplace(info_task_ptr); + + // 因为后期要考虑多任务间的联动等,所以这些任务的声明暂时不放到for循环中 + auto mfg_task_ptr = std::make_shared(task_callback, (void*)this); + mfg_task_ptr->set_work_mode(work_mode); + mfg_task_ptr->set_task_chain(InfrastTaskCahin); + mfg_task_ptr->set_mood_threshold(dorm_threshold); + mfg_task_ptr->set_uses_of_drone(uses_of_drones); + auto trade_task_ptr = std::make_shared(task_callback, (void*)this); + trade_task_ptr->set_work_mode(work_mode); + trade_task_ptr->set_task_chain(InfrastTaskCahin); + trade_task_ptr->set_mood_threshold(dorm_threshold); + trade_task_ptr->set_uses_of_drone(uses_of_drones); + auto power_task_ptr = std::make_shared(task_callback, (void*)this); + power_task_ptr->set_work_mode(work_mode); + power_task_ptr->set_task_chain(InfrastTaskCahin); + power_task_ptr->set_mood_threshold(dorm_threshold); + auto office_task_ptr = std::make_shared(task_callback, (void*)this); + office_task_ptr->set_work_mode(work_mode); + office_task_ptr->set_task_chain(InfrastTaskCahin); + office_task_ptr->set_mood_threshold(dorm_threshold); + auto recpt_task_ptr = std::make_shared(task_callback, (void*)this); + recpt_task_ptr->set_work_mode(work_mode); + recpt_task_ptr->set_task_chain(InfrastTaskCahin); + recpt_task_ptr->set_mood_threshold(dorm_threshold); + auto control_task_ptr = std::make_shared(task_callback, (void*)this); + control_task_ptr->set_work_mode(work_mode); + control_task_ptr->set_task_chain(InfrastTaskCahin); + control_task_ptr->set_mood_threshold(dorm_threshold); + + auto dorm_task_ptr = std::make_shared(task_callback, (void*)this); + dorm_task_ptr->set_work_mode(work_mode); + dorm_task_ptr->set_task_chain(InfrastTaskCahin); + dorm_task_ptr->set_mood_threshold(dorm_threshold); + + for (const auto& facility : order) { + if (facility == "Dorm") { + m_tasks_queue.emplace(dorm_task_ptr); + } + else if (facility == "Mfg") { + m_tasks_queue.emplace(mfg_task_ptr); + } + else if (facility == "Trade") { + m_tasks_queue.emplace(trade_task_ptr); + } + else if (facility == "Power") { + m_tasks_queue.emplace(power_task_ptr); + } + else if (facility == "Office") { + m_tasks_queue.emplace(office_task_ptr); + } + else if (facility == "Reception") { + m_tasks_queue.emplace(recpt_task_ptr); + } + else if (facility == "Control") { + m_tasks_queue.emplace(control_task_ptr); + } + else { + Log.error("append_infrast | Unknown facility", facility); + } + append_infrast_begin(); + } + + if (!only_append) { + return start(false); + } + + return true; +} + +void asst::Assistance::set_penguin_id(const std::string& id) +{ + auto& opt = Resrc.cfg().get_options(); + if (id.empty()) { + opt.penguin_report_extra_param.clear(); + } + else { + opt.penguin_report_extra_param = "-H \"authorization: PenguinID " + id + "\""; + } +} + +bool asst::Assistance::start(bool block) +{ + LogTraceFunction; + Log.trace("Start |", block ? "block" : "non block"); + + if (!m_thread_idle || !m_inited) { + return false; + } + std::unique_lock lock; + if (block) { // 外部调用 + lock = std::unique_lock(m_mutex); + } + + m_thread_idle = false; + m_condvar.notify_one(); + + return true; +} + +bool Assistance::stop(bool block) +{ + LogTraceFunction; + Log.trace("Stop |", block ? "block" : "non block"); + + m_thread_idle = true; + + std::unique_lock lock; + if (block) { // 外部调用 + lock = std::unique_lock(m_mutex); + } + decltype(m_tasks_queue) empty; + m_tasks_queue.swap(empty); + + //clear_cache(); + + return true; +} + +void Assistance::working_proc() +{ + LogTraceFunction; + + std::string pre_taskchain; + while (!m_thread_exit) { + //LogTraceScope("Assistance::working_proc Loop"); + std::unique_lock lock(m_mutex); + + if (!m_thread_idle && !m_tasks_queue.empty()) { + auto start_time = std::chrono::system_clock::now(); + + auto task_ptr = m_tasks_queue.front(); + + std::string cur_taskchain = task_ptr->get_task_chain(); + json::value task_json = json::object{ + {"task_chain", cur_taskchain}, + }; + + if (cur_taskchain != pre_taskchain) { + task_callback(AsstMsg::TaskChainStart, task_json, this); + pre_taskchain = cur_taskchain; + } + + task_ptr->set_exit_flag(&m_thread_idle); + bool ret = task_ptr->run(); + m_tasks_queue.pop(); + + if (!ret) { + task_callback(AsstMsg::TaskError, task_json, this); + } + else if (m_tasks_queue.empty() || cur_taskchain != m_tasks_queue.front()->get_task_chain()) { + task_callback(AsstMsg::TaskChainCompleted, task_json, this); + } + if (m_tasks_queue.empty()) { + task_callback(AsstMsg::AllTasksCompleted, json::value(), this); + } + + //clear_cache(); + + auto& delay = Resrc.cfg().get_options().task_delay; + m_condvar.wait_until(lock, start_time + std::chrono::milliseconds(delay), + [&]() -> bool { return m_thread_idle; }); + } + else { + pre_taskchain.clear(); + m_thread_idle = true; + //controller.set_idle(true); + m_condvar.wait(lock); + } + } +} + +void Assistance::msg_proc() +{ + LogTraceFunction; + + while (!m_thread_exit) { + //LogTraceScope("Assistance::msg_proc Loop"); + std::unique_lock lock(m_msg_mutex); + if (!m_msg_queue.empty()) { + // 结构化绑定只能是引用,后续的pop会使引用失效,所以需要重新构造一份,这里采用了move的方式 + auto&& [temp_msg, temp_detail] = m_msg_queue.front(); + AsstMsg msg = std::move(temp_msg); + json::value detail = std::move(temp_detail); + m_msg_queue.pop(); + lock.unlock(); + + if (m_callback) { + m_callback(msg, detail, m_callback_arg); + } + } + else { + m_msg_condvar.wait(lock); + } + } +} + +void Assistance::task_callback(AsstMsg msg, const json::value& detail, void* custom_arg) +{ + Log.trace("Assistance::task_callback |", msg, detail.to_string()); + + Assistance* p_this = (Assistance*)custom_arg; + json::value more_detail = detail; + switch (msg) { + case AsstMsg::PtrIsNull: + case AsstMsg::ImageIsEmpty: + p_this->stop(false); + break; + case AsstMsg::StageDrops: + more_detail = p_this->organize_stage_drop(more_detail); + break; + default: + break; + } + + // Todo: 有些不需要回调给外部的消息,得在这里给拦截掉 + // 加入回调消息队列,由回调消息线程外抛给外部 + p_this->append_callback(msg, std::move(more_detail)); +} + +void asst::Assistance::append_callback(AsstMsg msg, json::value detail) +{ + std::unique_lock lock(m_msg_mutex); + m_msg_queue.emplace(msg, std::move(detail)); + m_msg_condvar.notify_one(); +} + +void Assistance::clear_cache() +{ + Resrc.item().clear_drop_count(); + task.clear_cache(); +} + +json::value asst::Assistance::organize_stage_drop(const json::value& rec) +{ + json::value dst = rec; + auto& item = Resrc.item(); + for (json::value& drop : dst["drops"].as_array()) { + std::string id = drop["itemId"].as_string(); + int quantity = drop["quantity"].as_integer(); + item.increase_drop_count(id, quantity); + const std::string& name = item.get_item_name(id); + drop["itemName"] = name.empty() ? "未知材料" : name; + } + std::vector statistics_vec; + for (auto&& [id, count] : item.get_drop_count()) { + json::value info; + info["itemId"] = id; + const std::string& name = item.get_item_name(id); + info["itemName"] = name.empty() ? "未知材料" : name; + info["count"] = count; + statistics_vec.emplace_back(std::move(info)); + } + // 排个序,数量多的放前面 + std::sort(statistics_vec.begin(), statistics_vec.end(), + [](const json::value& lhs, const json::value& rhs) -> bool { + return lhs.at("count").as_integer() > rhs.at("count").as_integer(); + }); + + dst["statistics"] = json::array(std::move(statistics_vec)); + + Log.trace("organize_stage_drop | ", dst.to_string()); + + return dst; +} diff --git a/src/MeoAssistance/Assistance.h b/src/MeoAssistant/Assistance.h similarity index 100% rename from src/MeoAssistance/Assistance.h rename to src/MeoAssistant/Assistance.h diff --git a/src/MeoAssistance/AsstCaller.cpp b/src/MeoAssistant/AsstCaller.cpp similarity index 95% rename from src/MeoAssistance/AsstCaller.cpp rename to src/MeoAssistant/AsstCaller.cpp index bfc34a0d4c..3199cf5109 100644 --- a/src/MeoAssistance/AsstCaller.cpp +++ b/src/MeoAssistant/AsstCaller.cpp @@ -1,252 +1,252 @@ -#include "AsstCaller.h" - -#include - -#include - -#include "Assistance.h" -#include "AsstDef.h" -#include "AsstUtils.hpp" -#include "Version.h" - -#if 0 -#if _MSC_VER -// Win32平台下Dll的入口 -BOOL APIENTRY DllMain(HINSTANCE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved -) -{ - UNREFERENCED_PARAMETER(hModule); - UNREFERENCED_PARAMETER(lpReserved); - switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} -#elif VA_GNUC - -#endif -#endif - -AsstCallback _callback = nullptr; - -void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg) -{ - _callback(static_cast(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg); -} - -void* AsstCreate(const char* dirname) -{ - try { - return new asst::Assistance(dirname); - } - catch (...) { - return nullptr; - } -} - -void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) -{ - try { - // 创建多实例回调会有问题,有空再慢慢整 - _callback = callback; - return new asst::Assistance(dirname, CallbackTrans, custom_arg); - } - catch (...) { - return nullptr; - } -} - -void AsstDestroy(void* p_asst) -{ - if (p_asst == nullptr) { - return; - } - - delete p_asst; - p_asst = nullptr; -} - -bool AsstCatchDefault(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_default(); -} - -bool AsstCatchEmulator(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_emulator(); -} - -bool AsstCatchCustom(void* p_asst, const char* address) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_custom(address); -} - -bool AsstCatchFake(void* p_asst) -{ -#ifdef LOG_TRACE - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->catch_fake(); -#else - return false; -#endif // LOG_TRACE -} - -bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times) -{ - if (p_asst == nullptr) { - return false; - } - asst::Assistance* ptr = (asst::Assistance*)p_asst; - - return ptr->append_fight(max_mecidine, max_stone, max_times); -} - -bool AsstAppendAward(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->append_award(); -} - -bool AsstAppendVisit(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->append_visit(); -} - -bool AsstAppendMall(void* p_asst, bool with_shopping) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->append_mall(with_shopping); -} - -//bool AsstAppendProcessTask(void* p_asst, const char* task) -//{ -// if (p_asst == nullptr) { -// return false; -// } -// -// return ((asst::Assistance*)p_asst)->append_process_task(task); -//} - -bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time) -{ - if (p_asst == nullptr) { - return false; - } - std::vector level_vector; - level_vector.assign(select_level, select_level + required_len); - return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time); -} - -bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) -{ - if (p_asst == nullptr) { - return false; - } - std::vector order_vector; - order_vector.assign(order, order + order_size); - - return ((asst::Assistance*)p_asst)-> - append_infrast( - static_cast(work_mode), - order_vector, - uses_of_drones, - dorm_threshold); -} - -bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh) -{ - if (p_asst == nullptr) { - return false; - } - std::vector required_vector; - required_vector.assign(select_level, select_level + select_len); - std::vector confirm_vector; - confirm_vector.assign(confirm_level, confirm_level + confirm_len); - - return ((asst::Assistance*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh); -} - -bool AsstStart(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->start(); -} - -bool AsstStop(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } - - return ((asst::Assistance*)p_asst)->stop(); -} - -bool AsstSetPenguinId(void* p_asst, const char* id) -{ - if (p_asst == nullptr) { - return false; - } - auto ptr = (asst::Assistance*)p_asst; - ptr->set_penguin_id(id); - return true; -} - -//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value) -//{ -// if (p_asst == nullptr) { -// return false; -// } -// -// return ((asst::Assistance*)p_asst)->set_param(type, param, value); -//} - -const char* AsstGetVersion() -{ - return asst::Version; -} - -bool AsstAppendDebug(void* p_asst) -{ - if (p_asst == nullptr) { - return false; - } -#if LOG_TRACE - return ((asst::Assistance*)p_asst)->append_debug(); -#else - return false; -#endif // LOG_TRACE -} +#include "AsstCaller.h" + +#include + +#include + +#include "Assistance.h" +#include "AsstDef.h" +#include "AsstUtils.hpp" +#include "Version.h" + +#if 0 +#if _MSC_VER +// Win32平台下Dll的入口 +BOOL APIENTRY DllMain(HINSTANCE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved +) +{ + UNREFERENCED_PARAMETER(hModule); + UNREFERENCED_PARAMETER(lpReserved); + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#elif VA_GNUC + +#endif +#endif + +AsstCallback _callback = nullptr; + +void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg) +{ + _callback(static_cast(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg); +} + +void* AsstCreate(const char* dirname) +{ + try { + return new asst::Assistance(dirname); + } + catch (...) { + return nullptr; + } +} + +void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) +{ + try { + // 创建多实例回调会有问题,有空再慢慢整 + _callback = callback; + return new asst::Assistance(dirname, CallbackTrans, custom_arg); + } + catch (...) { + return nullptr; + } +} + +void AsstDestroy(void* p_asst) +{ + if (p_asst == nullptr) { + return; + } + + delete p_asst; + p_asst = nullptr; +} + +bool AsstCatchDefault(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_default(); +} + +bool AsstCatchEmulator(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_emulator(); +} + +bool AsstCatchCustom(void* p_asst, const char* address) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_custom(address); +} + +bool AsstCatchFake(void* p_asst) +{ +#ifdef LOG_TRACE + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->catch_fake(); +#else + return false; +#endif // LOG_TRACE +} + +bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times) +{ + if (p_asst == nullptr) { + return false; + } + asst::Assistance* ptr = (asst::Assistance*)p_asst; + + return ptr->append_fight(max_mecidine, max_stone, max_times); +} + +bool AsstAppendAward(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->append_award(); +} + +bool AsstAppendVisit(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->append_visit(); +} + +bool AsstAppendMall(void* p_asst, bool with_shopping) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->append_mall(with_shopping); +} + +//bool AsstAppendProcessTask(void* p_asst, const char* task) +//{ +// if (p_asst == nullptr) { +// return false; +// } +// +// return ((asst::Assistance*)p_asst)->append_process_task(task); +//} + +bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time) +{ + if (p_asst == nullptr) { + return false; + } + std::vector level_vector; + level_vector.assign(select_level, select_level + required_len); + return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time); +} + +bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) +{ + if (p_asst == nullptr) { + return false; + } + std::vector order_vector; + order_vector.assign(order, order + order_size); + + return ((asst::Assistance*)p_asst)-> + append_infrast( + static_cast(work_mode), + order_vector, + uses_of_drones, + dorm_threshold); +} + +bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh) +{ + if (p_asst == nullptr) { + return false; + } + std::vector required_vector; + required_vector.assign(select_level, select_level + select_len); + std::vector confirm_vector; + confirm_vector.assign(confirm_level, confirm_level + confirm_len); + + return ((asst::Assistance*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh); +} + +bool AsstStart(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->start(); +} + +bool AsstStop(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } + + return ((asst::Assistance*)p_asst)->stop(); +} + +bool AsstSetPenguinId(void* p_asst, const char* id) +{ + if (p_asst == nullptr) { + return false; + } + auto ptr = (asst::Assistance*)p_asst; + ptr->set_penguin_id(id); + return true; +} + +//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value) +//{ +// if (p_asst == nullptr) { +// return false; +// } +// +// return ((asst::Assistance*)p_asst)->set_param(type, param, value); +//} + +const char* AsstGetVersion() +{ + return asst::Version; +} + +bool AsstAppendDebug(void* p_asst) +{ + if (p_asst == nullptr) { + return false; + } +#if LOG_TRACE + return ((asst::Assistance*)p_asst)->append_debug(); +#else + return false; +#endif // LOG_TRACE +} diff --git a/src/MeoAssistance/AsstDef.h b/src/MeoAssistant/AsstDef.h similarity index 100% rename from src/MeoAssistance/AsstDef.h rename to src/MeoAssistant/AsstDef.h diff --git a/src/MeoAssistance/AsstInfrastDef.h b/src/MeoAssistant/AsstInfrastDef.h similarity index 100% rename from src/MeoAssistance/AsstInfrastDef.h rename to src/MeoAssistant/AsstInfrastDef.h diff --git a/src/MeoAssistance/AsstMsg.h b/src/MeoAssistant/AsstMsg.h similarity index 100% rename from src/MeoAssistance/AsstMsg.h rename to src/MeoAssistant/AsstMsg.h diff --git a/src/MeoAssistance/AsstUtils.hpp b/src/MeoAssistant/AsstUtils.hpp similarity index 100% rename from src/MeoAssistance/AsstUtils.hpp rename to src/MeoAssistant/AsstUtils.hpp diff --git a/src/MeoAssistance/AutoRecruitTask.cpp b/src/MeoAssistant/AutoRecruitTask.cpp similarity index 97% rename from src/MeoAssistance/AutoRecruitTask.cpp rename to src/MeoAssistant/AutoRecruitTask.cpp index 5a8abd4a72..138befec15 100644 --- a/src/MeoAssistance/AutoRecruitTask.cpp +++ b/src/MeoAssistant/AutoRecruitTask.cpp @@ -2,33 +2,33 @@ #include "Resource.h" #include "OcrImageAnalyzer.h" -#include "Controller.h" -#include "RecruitImageAnalyzer.h" -#include "ProcessTask.h" +#include "Controller.h" +#include "RecruitImageAnalyzer.h" +#include "ProcessTask.h" #include "RecruitTask.h" -void asst::AutoRecruitTask::set_select_level(std::vector select_level) noexcept -{ - m_select_level = std::move(select_level); -} - -void asst::AutoRecruitTask::set_confirm_level(std::vector confirm_level) noexcept -{ - m_confirm_level = std::move(confirm_level); -} - -void asst::AutoRecruitTask::set_need_refresh(bool need_refresh) noexcept -{ - m_need_refresh = need_refresh; -} - +void asst::AutoRecruitTask::set_select_level(std::vector select_level) noexcept +{ + m_select_level = std::move(select_level); +} + +void asst::AutoRecruitTask::set_confirm_level(std::vector confirm_level) noexcept +{ + m_confirm_level = std::move(confirm_level); +} + +void asst::AutoRecruitTask::set_need_refresh(bool need_refresh) noexcept +{ + m_need_refresh = need_refresh; +} + void asst::AutoRecruitTask::set_max_times(int max_times) noexcept { m_max_times = max_times; -} - -bool asst::AutoRecruitTask::_run() -{ +} + +bool asst::AutoRecruitTask::_run() +{ json::value task_start_json = json::object{ { "task_type", "RecruitTask" }, { "task_chain", m_task_chain }, @@ -36,61 +36,61 @@ bool asst::AutoRecruitTask::_run() m_callback(AsstMsg::TaskStart, task_start_json, m_callback_arg); int delay = Resrc.cfg().get_options().task_delay; - + auto image = Ctrler.get_image(); OcrImageAnalyzer start_analyzer(image); const auto start_task_ptr = std::dynamic_pointer_cast(task.get("StartRecruit")); start_analyzer.set_task_info(*start_task_ptr); - if (!start_analyzer.analyze()) { - return false; + if (!start_analyzer.analyze()) { + return false; } const auto& start_res = start_analyzer.get_result(); for (; m_cur_times < start_res.size() && m_cur_times < m_max_times; ++m_cur_times) { if (need_exit()) { return false; - } - Rect start_rect = start_res.at(m_cur_times).rect; - Ctrler.click(start_rect); - sleep(delay); - - while (true) { - RecruitTask recurit_task(m_callback, m_callback_arg); - recurit_task.set_retry_times(10); - recurit_task.set_param(m_select_level, true); - recurit_task.set_task_chain(m_task_chain); - - // 识别错误,放弃这个公招位,直接返回 - if (!recurit_task.run()) { - m_callback(AsstMsg::RecruitError, json::value(), m_callback_arg); - click_return_button(); - break; - } - - int maybe_level = recurit_task.get_maybe_level(); - - // 尝试刷新 - if (m_need_refresh && maybe_level == 3 - && !recurit_task.get_has_special_tag() - && recurit_task.get_has_refresh()) { - ProcessTask refresh_task(*this, { "RecruitRefresh" }); - if (refresh_task.run()) { - continue; - } - } - if (std::find(m_confirm_level.cbegin(), m_confirm_level.cend(), maybe_level) != m_confirm_level.cend()) { - ProcessTask confirm_task(*this, { "RecruitConfirm" }); - if (!confirm_task.run()) { - return false; - } - break; - } - else { - click_return_button(); - break; - } - } - } + } + Rect start_rect = start_res.at(m_cur_times).rect; + Ctrler.click(start_rect); + sleep(delay); + + while (true) { + RecruitTask recurit_task(m_callback, m_callback_arg); + recurit_task.set_retry_times(10); + recurit_task.set_param(m_select_level, true); + recurit_task.set_task_chain(m_task_chain); + + // 识别错误,放弃这个公招位,直接返回 + if (!recurit_task.run()) { + m_callback(AsstMsg::RecruitError, json::value(), m_callback_arg); + click_return_button(); + break; + } + + int maybe_level = recurit_task.get_maybe_level(); + + // 尝试刷新 + if (m_need_refresh && maybe_level == 3 + && !recurit_task.get_has_special_tag() + && recurit_task.get_has_refresh()) { + ProcessTask refresh_task(*this, { "RecruitRefresh" }); + if (refresh_task.run()) { + continue; + } + } + if (std::find(m_confirm_level.cbegin(), m_confirm_level.cend(), maybe_level) != m_confirm_level.cend()) { + ProcessTask confirm_task(*this, { "RecruitConfirm" }); + if (!confirm_task.run()) { + return false; + } + break; + } + else { + click_return_button(); + break; + } + } + } return true; -} +} diff --git a/src/MeoAssistance/AutoRecruitTask.h b/src/MeoAssistant/AutoRecruitTask.h similarity index 100% rename from src/MeoAssistance/AutoRecruitTask.h rename to src/MeoAssistant/AutoRecruitTask.h diff --git a/src/MeoAssistance/Controller.cpp b/src/MeoAssistant/Controller.cpp similarity index 100% rename from src/MeoAssistance/Controller.cpp rename to src/MeoAssistant/Controller.cpp diff --git a/src/MeoAssistance/Controller.h b/src/MeoAssistant/Controller.h similarity index 100% rename from src/MeoAssistance/Controller.h rename to src/MeoAssistant/Controller.h diff --git a/src/MeoAssistance/CreditShopImageAnalyzer.cpp b/src/MeoAssistant/CreditShopImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/CreditShopImageAnalyzer.cpp rename to src/MeoAssistant/CreditShopImageAnalyzer.cpp diff --git a/src/MeoAssistance/CreditShopImageAnalyzer.h b/src/MeoAssistant/CreditShopImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/CreditShopImageAnalyzer.h rename to src/MeoAssistant/CreditShopImageAnalyzer.h diff --git a/src/MeoAssistance/CreditShoppingTask.cpp b/src/MeoAssistant/CreditShoppingTask.cpp similarity index 100% rename from src/MeoAssistance/CreditShoppingTask.cpp rename to src/MeoAssistant/CreditShoppingTask.cpp diff --git a/src/MeoAssistance/CreditShoppingTask.h b/src/MeoAssistant/CreditShoppingTask.h similarity index 100% rename from src/MeoAssistance/CreditShoppingTask.h rename to src/MeoAssistant/CreditShoppingTask.h diff --git a/src/MeoAssistance/GeneralConfiger.cpp b/src/MeoAssistant/GeneralConfiger.cpp similarity index 100% rename from src/MeoAssistance/GeneralConfiger.cpp rename to src/MeoAssistant/GeneralConfiger.cpp diff --git a/src/MeoAssistance/GeneralConfiger.h b/src/MeoAssistant/GeneralConfiger.h similarity index 100% rename from src/MeoAssistance/GeneralConfiger.h rename to src/MeoAssistant/GeneralConfiger.h diff --git a/src/MeoAssistance/InfrastAbstractTask.cpp b/src/MeoAssistant/InfrastAbstractTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastAbstractTask.cpp rename to src/MeoAssistant/InfrastAbstractTask.cpp diff --git a/src/MeoAssistance/InfrastAbstractTask.h b/src/MeoAssistant/InfrastAbstractTask.h similarity index 100% rename from src/MeoAssistance/InfrastAbstractTask.h rename to src/MeoAssistant/InfrastAbstractTask.h diff --git a/src/MeoAssistance/InfrastClueImageAnalyzer.cpp b/src/MeoAssistant/InfrastClueImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/InfrastClueImageAnalyzer.cpp rename to src/MeoAssistant/InfrastClueImageAnalyzer.cpp diff --git a/src/MeoAssistance/InfrastClueImageAnalyzer.h b/src/MeoAssistant/InfrastClueImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/InfrastClueImageAnalyzer.h rename to src/MeoAssistant/InfrastClueImageAnalyzer.h diff --git a/src/MeoAssistance/InfrastClueVacancyImageAnalyzer.cpp b/src/MeoAssistant/InfrastClueVacancyImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/InfrastClueVacancyImageAnalyzer.cpp rename to src/MeoAssistant/InfrastClueVacancyImageAnalyzer.cpp diff --git a/src/MeoAssistance/InfrastClueVacancyImageAnalyzer.h b/src/MeoAssistant/InfrastClueVacancyImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/InfrastClueVacancyImageAnalyzer.h rename to src/MeoAssistant/InfrastClueVacancyImageAnalyzer.h diff --git a/src/MeoAssistance/InfrastConfiger.cpp b/src/MeoAssistant/InfrastConfiger.cpp similarity index 100% rename from src/MeoAssistance/InfrastConfiger.cpp rename to src/MeoAssistant/InfrastConfiger.cpp diff --git a/src/MeoAssistance/InfrastConfiger.h b/src/MeoAssistant/InfrastConfiger.h similarity index 100% rename from src/MeoAssistance/InfrastConfiger.h rename to src/MeoAssistant/InfrastConfiger.h diff --git a/src/MeoAssistance/InfrastControlTask.cpp b/src/MeoAssistant/InfrastControlTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastControlTask.cpp rename to src/MeoAssistant/InfrastControlTask.cpp diff --git a/src/MeoAssistance/InfrastControlTask.h b/src/MeoAssistant/InfrastControlTask.h similarity index 100% rename from src/MeoAssistance/InfrastControlTask.h rename to src/MeoAssistant/InfrastControlTask.h diff --git a/src/MeoAssistance/InfrastDormTask.cpp b/src/MeoAssistant/InfrastDormTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastDormTask.cpp rename to src/MeoAssistant/InfrastDormTask.cpp diff --git a/src/MeoAssistance/InfrastDormTask.h b/src/MeoAssistant/InfrastDormTask.h similarity index 100% rename from src/MeoAssistance/InfrastDormTask.h rename to src/MeoAssistant/InfrastDormTask.h diff --git a/src/MeoAssistance/InfrastFacilityImageAnalyzer.cpp b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/InfrastFacilityImageAnalyzer.cpp rename to src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp diff --git a/src/MeoAssistance/InfrastFacilityImageAnalyzer.h b/src/MeoAssistant/InfrastFacilityImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/InfrastFacilityImageAnalyzer.h rename to src/MeoAssistant/InfrastFacilityImageAnalyzer.h diff --git a/src/MeoAssistance/InfrastInfoTask.cpp b/src/MeoAssistant/InfrastInfoTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastInfoTask.cpp rename to src/MeoAssistant/InfrastInfoTask.cpp diff --git a/src/MeoAssistance/InfrastInfoTask.h b/src/MeoAssistant/InfrastInfoTask.h similarity index 100% rename from src/MeoAssistance/InfrastInfoTask.h rename to src/MeoAssistant/InfrastInfoTask.h diff --git a/src/MeoAssistance/InfrastMfgTask.cpp b/src/MeoAssistant/InfrastMfgTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastMfgTask.cpp rename to src/MeoAssistant/InfrastMfgTask.cpp diff --git a/src/MeoAssistance/InfrastMfgTask.h b/src/MeoAssistant/InfrastMfgTask.h similarity index 100% rename from src/MeoAssistance/InfrastMfgTask.h rename to src/MeoAssistant/InfrastMfgTask.h diff --git a/src/MeoAssistance/InfrastOfficeTask.cpp b/src/MeoAssistant/InfrastOfficeTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastOfficeTask.cpp rename to src/MeoAssistant/InfrastOfficeTask.cpp diff --git a/src/MeoAssistance/InfrastOfficeTask.h b/src/MeoAssistant/InfrastOfficeTask.h similarity index 100% rename from src/MeoAssistance/InfrastOfficeTask.h rename to src/MeoAssistant/InfrastOfficeTask.h diff --git a/src/MeoAssistance/InfrastOperImageAnalyzer.cpp b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/InfrastOperImageAnalyzer.cpp rename to src/MeoAssistant/InfrastOperImageAnalyzer.cpp diff --git a/src/MeoAssistance/InfrastOperImageAnalyzer.h b/src/MeoAssistant/InfrastOperImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/InfrastOperImageAnalyzer.h rename to src/MeoAssistant/InfrastOperImageAnalyzer.h diff --git a/src/MeoAssistance/InfrastPowerTask.cpp b/src/MeoAssistant/InfrastPowerTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastPowerTask.cpp rename to src/MeoAssistant/InfrastPowerTask.cpp diff --git a/src/MeoAssistance/InfrastPowerTask.h b/src/MeoAssistant/InfrastPowerTask.h similarity index 100% rename from src/MeoAssistance/InfrastPowerTask.h rename to src/MeoAssistant/InfrastPowerTask.h diff --git a/src/MeoAssistance/InfrastProductionTask.cpp b/src/MeoAssistant/InfrastProductionTask.cpp similarity index 99% rename from src/MeoAssistance/InfrastProductionTask.cpp rename to src/MeoAssistant/InfrastProductionTask.cpp index 6262fa65c5..fa18219224 100644 --- a/src/MeoAssistance/InfrastProductionTask.cpp +++ b/src/MeoAssistant/InfrastProductionTask.cpp @@ -442,11 +442,11 @@ bool asst::InfrastProductionTask::optimal_calc() bool asst::InfrastProductionTask::opers_choose() { LogTraceFunction; - bool has_error = false; - - int count = 0; + bool has_error = false; + + int count = 0; auto& facility_info = Resrc.infrast().get_facility_info(m_facility); - int cur_max_num_of_opers = facility_info.max_num_of_opers - m_cur_num_of_lokced_opers; + int cur_max_num_of_opers = facility_info.max_num_of_opers - m_cur_num_of_lokced_opers; while (true) { if (need_exit()) { @@ -480,9 +480,9 @@ bool asst::InfrastProductionTask::opers_choose() auto remove_iter = std::remove_if(cur_all_opers.begin(), cur_all_opers.end(), [&](const infrast::Oper& rhs) -> bool { return rhs.mood_ratio < m_mood_threshold; - }); - cur_all_opers.erase(remove_iter, cur_all_opers.end()); - + }); + cur_all_opers.erase(remove_iter, cur_all_opers.end()); + for (auto opt_iter = m_optimal_combs.begin(); opt_iter != m_optimal_combs.end();) { auto find_iter = std::find_if( cur_all_opers.cbegin(), cur_all_opers.cend(), @@ -539,18 +539,18 @@ bool asst::InfrastProductionTask::opers_choose() else { Log.error("opers_choose | not found oper"); } - } + } ++count; cur_all_opers.erase(find_iter); opt_iter = m_optimal_combs.erase(opt_iter); } - if (m_optimal_combs.empty()) { + if (m_optimal_combs.empty()) { if (count >= cur_max_num_of_opers) { - break; + break; } - else { // 这种情况可能是萌新,可用干员人数不足以填满当前设施 - // TODO!!! - break; + else { // 这种情况可能是萌新,可用干员人数不足以填满当前设施 + // TODO!!! + break; } } @@ -619,4 +619,4 @@ bool asst::InfrastProductionTask::facility_list_detect() } return true; -} +} diff --git a/src/MeoAssistance/InfrastProductionTask.h b/src/MeoAssistant/InfrastProductionTask.h similarity index 100% rename from src/MeoAssistance/InfrastProductionTask.h rename to src/MeoAssistant/InfrastProductionTask.h diff --git a/src/MeoAssistance/InfrastReceptionTask.cpp b/src/MeoAssistant/InfrastReceptionTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastReceptionTask.cpp rename to src/MeoAssistant/InfrastReceptionTask.cpp diff --git a/src/MeoAssistance/InfrastReceptionTask.h b/src/MeoAssistant/InfrastReceptionTask.h similarity index 100% rename from src/MeoAssistance/InfrastReceptionTask.h rename to src/MeoAssistant/InfrastReceptionTask.h diff --git a/src/MeoAssistance/InfrastSmileyImageAnalyzer.cpp b/src/MeoAssistant/InfrastSmileyImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/InfrastSmileyImageAnalyzer.cpp rename to src/MeoAssistant/InfrastSmileyImageAnalyzer.cpp diff --git a/src/MeoAssistance/InfrastSmileyImageAnalyzer.h b/src/MeoAssistant/InfrastSmileyImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/InfrastSmileyImageAnalyzer.h rename to src/MeoAssistant/InfrastSmileyImageAnalyzer.h diff --git a/src/MeoAssistance/InfrastTradeTask.cpp b/src/MeoAssistant/InfrastTradeTask.cpp similarity index 100% rename from src/MeoAssistance/InfrastTradeTask.cpp rename to src/MeoAssistant/InfrastTradeTask.cpp diff --git a/src/MeoAssistance/InfrastTradeTask.h b/src/MeoAssistant/InfrastTradeTask.h similarity index 100% rename from src/MeoAssistance/InfrastTradeTask.h rename to src/MeoAssistant/InfrastTradeTask.h diff --git a/src/MeoAssistance/ItemConfiger.cpp b/src/MeoAssistant/ItemConfiger.cpp similarity index 100% rename from src/MeoAssistance/ItemConfiger.cpp rename to src/MeoAssistant/ItemConfiger.cpp diff --git a/src/MeoAssistance/ItemConfiger.h b/src/MeoAssistant/ItemConfiger.h similarity index 100% rename from src/MeoAssistance/ItemConfiger.h rename to src/MeoAssistant/ItemConfiger.h diff --git a/src/MeoAssistance/Logger.hpp b/src/MeoAssistant/Logger.hpp similarity index 99% rename from src/MeoAssistance/Logger.hpp rename to src/MeoAssistant/Logger.hpp index f76b407096..fad728f580 100644 --- a/src/MeoAssistance/Logger.hpp +++ b/src/MeoAssistant/Logger.hpp @@ -78,7 +78,7 @@ namespace asst void log_init_info() { trace("-----------------------------"); - trace("MeoAssistance Process Start"); + trace("MeoAssistant Process Start"); trace("Version", asst::Version); trace("Build DataTime", __DATE__, __TIME__); trace("Working Path", m_dirname); diff --git a/src/MeoAssistance/MatchImageAnalyzer.cpp b/src/MeoAssistant/MatchImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/MatchImageAnalyzer.cpp rename to src/MeoAssistant/MatchImageAnalyzer.cpp diff --git a/src/MeoAssistance/MatchImageAnalyzer.h b/src/MeoAssistant/MatchImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/MatchImageAnalyzer.h rename to src/MeoAssistant/MatchImageAnalyzer.h diff --git a/src/MeoAssistance/MeoAssistance.vcxproj b/src/MeoAssistant/MeoAssistant.vcxproj similarity index 95% rename from src/MeoAssistance/MeoAssistance.vcxproj rename to src/MeoAssistant/MeoAssistant.vcxproj index 1307c0d8a9..62df7f654e 100644 --- a/src/MeoAssistance/MeoAssistance.vcxproj +++ b/src/MeoAssistant/MeoAssistant.vcxproj @@ -1,256 +1,256 @@ - - - - - Release - x64 - - - RelWithDebInfo - x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 16.0 - Win32Proj - {362d1e30-f5ae-4279-9985-65c27b3ba300} - MeoAssistance - 10.0 - - - - DynamicLibrary - false - v142 - true - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - false - $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) - $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) - - - true - $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) - $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;MEO_DLL_EXPORTS;%(PreprocessorDefinitions) - true - stdcpp17 - stdc11 - MultiThreaded - MaxSpeed - /utf-8 /MP %(AdditionalOptions) - - - Console - true - true - true - libmeojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) - RequireAdministrator - - - - - - - - + + + + + Release + x64 + + + RelWithDebInfo + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + Win32Proj + {362d1e30-f5ae-4279-9985-65c27b3ba300} + MeoAssistant + 10.0 + + + + DynamicLibrary + false + v142 + true + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + false + $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) + $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) + + + true + $(SolutionDir)include;$(SolutionDir)3rdparty\include;$(IncludePath) + $(TargetDir);$(SolutionDir)\3rdparty\lib;$(LibraryPath) + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;ASST_DLL_EXPORTS;%(PreprocessorDefinitions) + true + stdcpp17 + stdc11 + MultiThreaded + MaxSpeed + /utf-8 /MP %(AdditionalOptions) + + + Console + true + true + true + libmeojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) + RequireAdministrator + + + + + + + + xcopy /e /y /i /c $(SolutionDir)resource $(TargetDir)resource -xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource - - - copy resource - - - xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) - - - copy 3rd party dll - - - - - Level3 - - - false - true - NDEBUG;_CONSOLE;MEO_DLL_EXPORTS;LOG_TRACE;DEBUG_API;%(PreprocessorDefinitions) - true - stdcpp17 - stdc11 - MultiThreaded - Disabled - false - EnableFastChecks - /utf-8 /MP %(AdditionalOptions) - - - Console - true - true - true - libmeojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) - RequireAdministrator - - - - - - - - +xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource + + + copy resource + + + xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) + + + copy 3rd party dll + + + + + Level3 + + + false + true + NDEBUG;_CONSOLE;ASST_DLL_EXPORTS;LOG_TRACE;DEBUG_API;%(PreprocessorDefinitions) + true + stdcpp17 + stdc11 + MultiThreaded + Disabled + false + EnableFastChecks + /utf-8 /MP %(AdditionalOptions) + + + Console + true + true + true + libmeojson.lib;ppocr.lib;opencv_world453.lib;penguin-stats-recognize.lib;%(AdditionalDependencies) + RequireAdministrator + + + + + + + + xcopy /e /y /i /c $(SolutionDir)resource $(TargetDir)resource -xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource - - - copy resource - - - xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) - - - copy 3rd party dll - - - - - - - - - - +xcopy /e /y /i /c $(SolutionDir)3rdparty\resource $(TargetDir)resource + + + copy resource + + + xcopy /e /y /i /c $(SolutionDir)3rdparty\bin $(TargetDir) + + + copy 3rd party dll + + + + + + + + + + \ No newline at end of file diff --git a/src/MeoAssistance/MeoAssistance.vcxproj.filters b/src/MeoAssistant/MeoAssistant.vcxproj.filters similarity index 97% rename from src/MeoAssistance/MeoAssistance.vcxproj.filters rename to src/MeoAssistant/MeoAssistant.vcxproj.filters index 494afc136a..098f1f536b 100644 --- a/src/MeoAssistance/MeoAssistance.vcxproj.filters +++ b/src/MeoAssistant/MeoAssistant.vcxproj.filters @@ -1,365 +1,365 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {81d86994-0d89-4cc2-aa6f-d726a0bd0490} - - - {3b93d9f2-728c-4a22-bc13-57ce7df5806c} - - - {1ef28df7-c174-4032-bbcf-9722ae53852d} - - - {557d6d96-11d9-46e1-b611-b2b8216abea6} - - - {1a8ffc31-8eb3-4af6-9065-634de2463a3e} - - - {c6a0898b-5dd7-4437-981c-00e53b30a60d} - - - {07a812fe-6b28-4be0-b6d4-33554824d3c5} - - - {74bd94e1-4973-412a-a17a-d8457de387af} - - - {87c9dee5-847b-41e6-818e-387a6385ea8b} - - - {a5c43813-70af-4b0e-94ac-9ddecc2e4a3c} - - - {a37e0b23-e8f8-499c-adf5-9990277e9ffe} - - - {51165426-1842-491a-b5d5-9d26c59facdd} - - - {c600668a-0d70-4694-b1e5-6a78cffd0b1a} - - - {d173e449-880b-4064-bbab-97007e3d090b} - - - {fc8aa302-89bb-4016-924d-10177dc8b334} - - - {9a6160e3-cd35-4dda-ba04-23ede1878740} - - - - - 头文件 - - - 头文件 - - - 头文件\Resource - - - 头文件\Resource - - - 头文件\Utils - - - 头文件\Utils - - - 头文件\Utils - - - 头文件\Utils - - - 头文件\Caller - - - 头文件\Caller - - - 头文件\Task - - - 头文件\Task - - - 头文件\Task - - - 头文件\Utils - - - 头文件\Resource - - - 头文件\Resource - - - 头文件\Task - - - 头文件\Utils - - - 头文件\Resource - - - 头文件\ImageAnalyzer - - - 头文件\Resource - - - 头文件\Resource - - - 头文件\Resource - - - 头文件\Resource - - - 头文件\ImageAnalyzer - - - 头文件 - - - 头文件\ImageAnalyzer - - - 头文件\ImageAnalyzer\General - - - 头文件\ImageAnalyzer\General - - - 头文件\ImageAnalyzer\General - - - 头文件\ImageAnalyzer\General - - - 头文件\ImageAnalyzer\Infrast - - - 头文件\Resource - - - 头文件\ImageAnalyzer\Infrast - - - 头文件 - - - 头文件\ImageAnalyzer\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\Task\Infrast - - - 头文件\ImageAnalyzer\Infrast - - - 头文件\Utils - - - 头文件\ImageAnalyzer\Infrast - - - 头文件 - - - 头文件\Task - - - 头文件\Task\Infrast - - - - - 源文件 - - - 源文件 - - - 源文件\Resource - - - 源文件\Resource - - - 源文件\Task - - - 源文件\Task - - - 源文件\Task - - - 源文件\Caller - - - 源文件\Resource - - - 源文件\Resource - - - 源文件\Task - - - 源文件\Utils - - - 源文件\Resource - - - 源文件\ImageAnalyzer - - - 源文件\Resource - - - 源文件\Resource - - - 源文件\Resource - - - 源文件\Resource - - - 源文件\ImageAnalyzer - - - 源文件 - - - 源文件\ImageAnalyzer - - - 源文件\ImageAnalyzer\Infrast - - - 源文件\ImageAnalyzer\General - - - 源文件\ImageAnalyzer\General - - - 源文件\ImageAnalyzer\General - - - 源文件\ImageAnalyzer\General - - - 源文件\Resource - - - 源文件\ImageAnalyzer\Infrast - - - 源文件 - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\Task\Infrast - - - 源文件\ImageAnalyzer\Infrast - - - 源文件\ImageAnalyzer\Infrast - - - 源文件\Task\Infrast - - - 源文件\ImageAnalyzer\Infrast - - - 源文件 - - - 源文件\Task - - - 源文件\Task\Infrast - - - - - 资源文件 - - - 资源文件 - - - 资源文件 - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {81d86994-0d89-4cc2-aa6f-d726a0bd0490} + + + {3b93d9f2-728c-4a22-bc13-57ce7df5806c} + + + {1ef28df7-c174-4032-bbcf-9722ae53852d} + + + {557d6d96-11d9-46e1-b611-b2b8216abea6} + + + {1a8ffc31-8eb3-4af6-9065-634de2463a3e} + + + {c6a0898b-5dd7-4437-981c-00e53b30a60d} + + + {07a812fe-6b28-4be0-b6d4-33554824d3c5} + + + {74bd94e1-4973-412a-a17a-d8457de387af} + + + {87c9dee5-847b-41e6-818e-387a6385ea8b} + + + {a5c43813-70af-4b0e-94ac-9ddecc2e4a3c} + + + {a37e0b23-e8f8-499c-adf5-9990277e9ffe} + + + {51165426-1842-491a-b5d5-9d26c59facdd} + + + {c600668a-0d70-4694-b1e5-6a78cffd0b1a} + + + {d173e449-880b-4064-bbab-97007e3d090b} + + + {fc8aa302-89bb-4016-924d-10177dc8b334} + + + {9a6160e3-cd35-4dda-ba04-23ede1878740} + + + + + 头文件 + + + 头文件 + + + 头文件\Resource + + + 头文件\Resource + + + 头文件\Utils + + + 头文件\Utils + + + 头文件\Utils + + + 头文件\Utils + + + 头文件\Caller + + + 头文件\Caller + + + 头文件\Task + + + 头文件\Task + + + 头文件\Task + + + 头文件\Utils + + + 头文件\Resource + + + 头文件\Resource + + + 头文件\Task + + + 头文件\Utils + + + 头文件\Resource + + + 头文件\ImageAnalyzer + + + 头文件\Resource + + + 头文件\Resource + + + 头文件\Resource + + + 头文件\Resource + + + 头文件\ImageAnalyzer + + + 头文件 + + + 头文件\ImageAnalyzer + + + 头文件\ImageAnalyzer\General + + + 头文件\ImageAnalyzer\General + + + 头文件\ImageAnalyzer\General + + + 头文件\ImageAnalyzer\General + + + 头文件\ImageAnalyzer\Infrast + + + 头文件\Resource + + + 头文件\ImageAnalyzer\Infrast + + + 头文件 + + + 头文件\ImageAnalyzer\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\Task\Infrast + + + 头文件\ImageAnalyzer\Infrast + + + 头文件\Utils + + + 头文件\ImageAnalyzer\Infrast + + + 头文件 + + + 头文件\Task + + + 头文件\Task\Infrast + + + + + 源文件 + + + 源文件 + + + 源文件\Resource + + + 源文件\Resource + + + 源文件\Task + + + 源文件\Task + + + 源文件\Task + + + 源文件\Caller + + + 源文件\Resource + + + 源文件\Resource + + + 源文件\Task + + + 源文件\Utils + + + 源文件\Resource + + + 源文件\ImageAnalyzer + + + 源文件\Resource + + + 源文件\Resource + + + 源文件\Resource + + + 源文件\Resource + + + 源文件\ImageAnalyzer + + + 源文件 + + + 源文件\ImageAnalyzer + + + 源文件\ImageAnalyzer\Infrast + + + 源文件\ImageAnalyzer\General + + + 源文件\ImageAnalyzer\General + + + 源文件\ImageAnalyzer\General + + + 源文件\ImageAnalyzer\General + + + 源文件\Resource + + + 源文件\ImageAnalyzer\Infrast + + + 源文件 + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\Task\Infrast + + + 源文件\ImageAnalyzer\Infrast + + + 源文件\ImageAnalyzer\Infrast + + + 源文件\Task\Infrast + + + 源文件\ImageAnalyzer\Infrast + + + 源文件 + + + 源文件\Task + + + 源文件\Task\Infrast + + + + + 资源文件 + + + 资源文件 + + + 资源文件 + + \ No newline at end of file diff --git a/src/MeoAssistance/MultiMatchImageAnalyzer.cpp b/src/MeoAssistant/MultiMatchImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/MultiMatchImageAnalyzer.cpp rename to src/MeoAssistant/MultiMatchImageAnalyzer.cpp diff --git a/src/MeoAssistance/MultiMatchImageAnalyzer.h b/src/MeoAssistant/MultiMatchImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/MultiMatchImageAnalyzer.h rename to src/MeoAssistant/MultiMatchImageAnalyzer.h diff --git a/src/MeoAssistance/OcrImageAnalyzer.cpp b/src/MeoAssistant/OcrImageAnalyzer.cpp similarity index 96% rename from src/MeoAssistance/OcrImageAnalyzer.cpp rename to src/MeoAssistant/OcrImageAnalyzer.cpp index ba4c89c305..d8489d0bfc 100644 --- a/src/MeoAssistance/OcrImageAnalyzer.cpp +++ b/src/MeoAssistant/OcrImageAnalyzer.cpp @@ -1,54 +1,54 @@ -#include "OcrImageAnalyzer.h" - -#include "AsstUtils.hpp" -#include "Logger.hpp" -#include "Resource.h" - -bool asst::OcrImageAnalyzer::analyze() -{ - m_ocr_result.clear(); - - std::vector preds_vec; - - if (!m_replace.empty()) { - TextRectProc text_replace = [&](TextRect& tr) -> bool { - for (const auto& [old_str, new_str] : m_replace) { - tr.text = utils::string_replace_all(tr.text, old_str, new_str); - } - return true; - }; - preds_vec.emplace_back(text_replace); - } - - if (!m_required.empty()) { - if (m_full_match) { - TextRectProc required_match = [&](TextRect& tr) -> bool { - return std::find(m_required.cbegin(), m_required.cend(), tr.text) != m_required.cend(); - }; - preds_vec.emplace_back(required_match); - } - else { - TextRectProc required_search = [&](TextRect& tr) -> bool { - auto is_sub = [&tr](const std::string& str) -> bool { - return tr.text.find(str) != std::string::npos; - }; - return std::find_if(m_required.cbegin(), m_required.cend(), is_sub) != m_required.cend(); - }; - preds_vec.emplace_back(required_search); - } - } - - preds_vec.emplace_back(m_pred); - - TextRectProc all_pred = [&](TextRect& tr) -> bool { - for (auto pred : preds_vec) { - if (pred && !pred(tr)) { - return false; - } - } - return true; - }; - m_ocr_result = Resrc.ocr().recognize(m_image, m_roi, all_pred, m_without_det); - //log.trace("ocr result", m_ocr_result); - return !m_ocr_result.empty(); -} +#include "OcrImageAnalyzer.h" + +#include "AsstUtils.hpp" +#include "Logger.hpp" +#include "Resource.h" + +bool asst::OcrImageAnalyzer::analyze() +{ + m_ocr_result.clear(); + + std::vector preds_vec; + + if (!m_replace.empty()) { + TextRectProc text_replace = [&](TextRect& tr) -> bool { + for (const auto& [old_str, new_str] : m_replace) { + tr.text = utils::string_replace_all(tr.text, old_str, new_str); + } + return true; + }; + preds_vec.emplace_back(text_replace); + } + + if (!m_required.empty()) { + if (m_full_match) { + TextRectProc required_match = [&](TextRect& tr) -> bool { + return std::find(m_required.cbegin(), m_required.cend(), tr.text) != m_required.cend(); + }; + preds_vec.emplace_back(required_match); + } + else { + TextRectProc required_search = [&](TextRect& tr) -> bool { + auto is_sub = [&tr](const std::string& str) -> bool { + return tr.text.find(str) != std::string::npos; + }; + return std::find_if(m_required.cbegin(), m_required.cend(), is_sub) != m_required.cend(); + }; + preds_vec.emplace_back(required_search); + } + } + + preds_vec.emplace_back(m_pred); + + TextRectProc all_pred = [&](TextRect& tr) -> bool { + for (auto pred : preds_vec) { + if (pred && !pred(tr)) { + return false; + } + } + return true; + }; + m_ocr_result = Resrc.ocr().recognize(m_image, m_roi, all_pred, m_without_det); + //log.trace("ocr result", m_ocr_result); + return !m_ocr_result.empty(); +} diff --git a/src/MeoAssistance/OcrImageAnalyzer.h b/src/MeoAssistant/OcrImageAnalyzer.h similarity index 96% rename from src/MeoAssistance/OcrImageAnalyzer.h rename to src/MeoAssistant/OcrImageAnalyzer.h index 38c7ea3532..9eb18a1346 100644 --- a/src/MeoAssistance/OcrImageAnalyzer.h +++ b/src/MeoAssistant/OcrImageAnalyzer.h @@ -1,64 +1,64 @@ -#pragma once -#include "AbstractImageAnalyzer.h" - -#include -#include -#include - -#include "AsstDef.h" - -namespace asst -{ - class OcrImageAnalyzer : public AbstractImageAnalyzer - { - public: - using AbstractImageAnalyzer::AbstractImageAnalyzer; - virtual ~OcrImageAnalyzer() = default; - - virtual bool analyze() override; - - void set_required(std::vector required, bool full_match = false) noexcept - { - m_required = std::move(required); - m_full_match = full_match; - } - void set_replace(std::unordered_map replace) noexcept - { - m_replace = std::move(replace); - } - void set_task_info(OcrTaskInfo task_info) noexcept - { - m_required = std::move(task_info.text); - m_full_match = task_info.need_full_match; - m_replace = std::move(task_info.replace_map); - - set_roi(task_info.roi); - correct_roi(); - auto& cache_roi = task_info.region_of_appeared; - if (task_info.cache && !cache_roi.empty()) { - m_roi = cache_roi; - m_without_det = true; - } - else { - m_without_det = false; - } - } - - void set_pred(const TextRectProc& pred) - { - m_pred = pred; - } - const std::vector& get_result() const noexcept - { - return m_ocr_result; - } - - protected: - std::vector m_ocr_result; - std::vector m_required; - bool m_full_match = false; - std::unordered_map m_replace; - TextRectProc m_pred = nullptr; - bool m_without_det = false; - }; -} +#pragma once +#include "AbstractImageAnalyzer.h" + +#include +#include +#include + +#include "AsstDef.h" + +namespace asst +{ + class OcrImageAnalyzer : public AbstractImageAnalyzer + { + public: + using AbstractImageAnalyzer::AbstractImageAnalyzer; + virtual ~OcrImageAnalyzer() = default; + + virtual bool analyze() override; + + void set_required(std::vector required, bool full_match = false) noexcept + { + m_required = std::move(required); + m_full_match = full_match; + } + void set_replace(std::unordered_map replace) noexcept + { + m_replace = std::move(replace); + } + void set_task_info(OcrTaskInfo task_info) noexcept + { + m_required = std::move(task_info.text); + m_full_match = task_info.need_full_match; + m_replace = std::move(task_info.replace_map); + + set_roi(task_info.roi); + correct_roi(); + auto& cache_roi = task_info.region_of_appeared; + if (task_info.cache && !cache_roi.empty()) { + m_roi = cache_roi; + m_without_det = true; + } + else { + m_without_det = false; + } + } + + void set_pred(const TextRectProc& pred) + { + m_pred = pred; + } + const std::vector& get_result() const noexcept + { + return m_ocr_result; + } + + protected: + std::vector m_ocr_result; + std::vector m_required; + bool m_full_match = false; + std::unordered_map m_replace; + TextRectProc m_pred = nullptr; + bool m_without_det = false; + }; +} diff --git a/src/MeoAssistance/OcrPack.cpp b/src/MeoAssistant/OcrPack.cpp similarity index 100% rename from src/MeoAssistance/OcrPack.cpp rename to src/MeoAssistant/OcrPack.cpp diff --git a/src/MeoAssistance/OcrPack.h b/src/MeoAssistant/OcrPack.h similarity index 100% rename from src/MeoAssistance/OcrPack.h rename to src/MeoAssistant/OcrPack.h diff --git a/src/MeoAssistance/PenguinPack.cpp b/src/MeoAssistant/PenguinPack.cpp similarity index 100% rename from src/MeoAssistance/PenguinPack.cpp rename to src/MeoAssistant/PenguinPack.cpp diff --git a/src/MeoAssistance/PenguinPack.h b/src/MeoAssistant/PenguinPack.h similarity index 100% rename from src/MeoAssistance/PenguinPack.h rename to src/MeoAssistant/PenguinPack.h diff --git a/src/MeoAssistance/PenguinUploader.cpp b/src/MeoAssistant/PenguinUploader.cpp similarity index 96% rename from src/MeoAssistance/PenguinUploader.cpp rename to src/MeoAssistant/PenguinUploader.cpp index 8bc3ef9f73..cd1c4692f9 100644 --- a/src/MeoAssistance/PenguinUploader.cpp +++ b/src/MeoAssistant/PenguinUploader.cpp @@ -28,14 +28,14 @@ std::string asst::PenguinUploader::cvt_json(const std::string& rec_res) auto& opt = Resrc.cfg().get_options(); body["server"] = opt.penguin_report_server; body["stageId"] = rec["stage"]["stageId"]; - // To fix: https://github.com/MistEO/MeoAssistance-Arknights/issues/40 + // To fix: https://github.com/MistEO/MeoAssistantArknights/issues/40 body["drops"] = json::array(); for (auto&& drop : rec["drops"].as_array()) { if (!drop["itemId"].as_string().empty()) { body["drops"].as_array().emplace_back(drop); } } - body["source"] = "MeoAssistance"; + body["source"] = "MeoAssistant"; body["version"] = Version; return body.to_string(); @@ -96,4 +96,4 @@ bool asst::PenguinUploader::request_penguin(const std::string& body) ::CloseHandle(pipe_read); ::CloseHandle(pipe_child_write); return true; -} \ No newline at end of file +} diff --git a/src/MeoAssistance/PenguinUploader.h b/src/MeoAssistant/PenguinUploader.h similarity index 100% rename from src/MeoAssistance/PenguinUploader.h rename to src/MeoAssistant/PenguinUploader.h diff --git a/src/MeoAssistance/ProcessTask.cpp b/src/MeoAssistant/ProcessTask.cpp similarity index 100% rename from src/MeoAssistance/ProcessTask.cpp rename to src/MeoAssistant/ProcessTask.cpp diff --git a/src/MeoAssistance/ProcessTask.h b/src/MeoAssistant/ProcessTask.h similarity index 100% rename from src/MeoAssistance/ProcessTask.h rename to src/MeoAssistant/ProcessTask.h diff --git a/src/MeoAssistance/ProcessTaskImageAnalyzer.cpp b/src/MeoAssistant/ProcessTaskImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/ProcessTaskImageAnalyzer.cpp rename to src/MeoAssistant/ProcessTaskImageAnalyzer.cpp diff --git a/src/MeoAssistance/ProcessTaskImageAnalyzer.h b/src/MeoAssistant/ProcessTaskImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/ProcessTaskImageAnalyzer.h rename to src/MeoAssistant/ProcessTaskImageAnalyzer.h diff --git a/src/MeoAssistance/README.md b/src/MeoAssistant/README.md similarity index 98% rename from src/MeoAssistance/README.md rename to src/MeoAssistant/README.md index 41611c31ef..bf33df259d 100644 --- a/src/MeoAssistance/README.md +++ b/src/MeoAssistant/README.md @@ -1,4 +1,4 @@ -# MeoAssistance +# MeoAssistant 辅助的底层C++模块 diff --git a/src/MeoAssistance/RecruitConfiger.cpp b/src/MeoAssistant/RecruitConfiger.cpp similarity index 100% rename from src/MeoAssistance/RecruitConfiger.cpp rename to src/MeoAssistant/RecruitConfiger.cpp diff --git a/src/MeoAssistance/RecruitConfiger.h b/src/MeoAssistant/RecruitConfiger.h similarity index 100% rename from src/MeoAssistance/RecruitConfiger.h rename to src/MeoAssistant/RecruitConfiger.h diff --git a/src/MeoAssistance/RecruitImageAnalyzer.cpp b/src/MeoAssistant/RecruitImageAnalyzer.cpp similarity index 100% rename from src/MeoAssistance/RecruitImageAnalyzer.cpp rename to src/MeoAssistant/RecruitImageAnalyzer.cpp diff --git a/src/MeoAssistance/RecruitImageAnalyzer.h b/src/MeoAssistant/RecruitImageAnalyzer.h similarity index 100% rename from src/MeoAssistance/RecruitImageAnalyzer.h rename to src/MeoAssistant/RecruitImageAnalyzer.h diff --git a/src/MeoAssistance/RecruitTask.cpp b/src/MeoAssistant/RecruitTask.cpp similarity index 100% rename from src/MeoAssistance/RecruitTask.cpp rename to src/MeoAssistant/RecruitTask.cpp diff --git a/src/MeoAssistance/RecruitTask.h b/src/MeoAssistant/RecruitTask.h similarity index 100% rename from src/MeoAssistance/RecruitTask.h rename to src/MeoAssistant/RecruitTask.h diff --git a/src/MeoAssistance/Resource.cpp b/src/MeoAssistant/Resource.cpp similarity index 100% rename from src/MeoAssistance/Resource.cpp rename to src/MeoAssistant/Resource.cpp diff --git a/src/MeoAssistance/Resource.h b/src/MeoAssistant/Resource.h similarity index 100% rename from src/MeoAssistance/Resource.h rename to src/MeoAssistant/Resource.h diff --git a/src/MeoAssistance/RuntimeStatus.cpp b/src/MeoAssistant/RuntimeStatus.cpp similarity index 100% rename from src/MeoAssistance/RuntimeStatus.cpp rename to src/MeoAssistant/RuntimeStatus.cpp diff --git a/src/MeoAssistance/RuntimeStatus.h b/src/MeoAssistant/RuntimeStatus.h similarity index 100% rename from src/MeoAssistance/RuntimeStatus.h rename to src/MeoAssistant/RuntimeStatus.h diff --git a/src/MeoAssistance/TaskData.cpp b/src/MeoAssistant/TaskData.cpp similarity index 97% rename from src/MeoAssistance/TaskData.cpp rename to src/MeoAssistant/TaskData.cpp index bea0e55e00..7ebd1c8934 100644 --- a/src/MeoAssistance/TaskData.cpp +++ b/src/MeoAssistant/TaskData.cpp @@ -1,203 +1,203 @@ -#include "TaskData.h" - -#include - -#include - -#include "AsstDef.h" -#include "GeneralConfiger.h" -#include "TemplResource.h" - -const std::shared_ptr asst::TaskData::get(const std::string& name) const noexcept -{ - if (auto iter = m_all_tasks_info.find(name); - iter != m_all_tasks_info.cend()) { - return iter->second; - } - else { - return nullptr; - } -} - -const std::unordered_set& asst::TaskData::get_templ_required() const noexcept -{ - return m_templ_required; -} - -std::shared_ptr asst::TaskData::get(std::string name) -{ - return m_all_tasks_info[std::move(name)]; -} - -void asst::TaskData::clear_cache() noexcept -{ - for (auto&& [name, ptr] : m_all_tasks_info) { - ptr->region_of_appeared = Rect(); - } -} - -bool asst::TaskData::parse(const json::value& json) -{ - for (const auto& [name, task_json] : json.as_object()) { - std::string algorithm_str = task_json.get("algorithm", "matchtemplate"); - std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower); - AlgorithmType algorithm = AlgorithmType::Invaild; - if (algorithm_str == "matchtemplate") { - algorithm = AlgorithmType::MatchTemplate; - } - else if (algorithm_str == "justreturn") { - algorithm = AlgorithmType::JustReturn; - } - else if (algorithm_str == "ocrdetect") { - algorithm = AlgorithmType::OcrDetect; - } - // CompareHist是MatchTemplate的衍生算法,不应作为单独的配置参数出现 - // else if (algorithm_str == "comparehist") {} - else { - m_last_error = "algorithm error " + algorithm_str; - return false; - } - - std::shared_ptr task_info_ptr = nullptr; - switch (algorithm) { - case AlgorithmType::JustReturn: - task_info_ptr = std::make_shared(); - break; - case AlgorithmType::MatchTemplate: { - auto match_task_info_ptr = std::make_shared(); - match_task_info_ptr->templ_name = task_json.get("template", name + ".png"); - m_templ_required.emplace(match_task_info_ptr->templ_name); - - match_task_info_ptr->templ_threshold = task_json.get( - "templThreshold", TemplThresholdDefault); - match_task_info_ptr->special_threshold = task_json.get( - "specialThreshold", 0); - if (task_json.exist("maskRange")) { - match_task_info_ptr->mask_range = std::make_pair( - task_json.at("maskRange")[0].as_integer(), - task_json.at("maskRange")[1].as_integer()); - } - - task_info_ptr = match_task_info_ptr; - } break; - case AlgorithmType::OcrDetect: { - auto ocr_task_info_ptr = std::make_shared(); - for (const json::value& text : task_json.at("text").as_array()) { - ocr_task_info_ptr->text.emplace_back(text.as_string()); - } - ocr_task_info_ptr->need_full_match = task_json.get("need_match", false); - if (task_json.exist("ocrReplace")) { - for (const json::value& rep : task_json.at("ocrReplace").as_array()) { - ocr_task_info_ptr->replace_map.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string()); - } - } - task_info_ptr = ocr_task_info_ptr; - } break; - } - task_info_ptr->cache = task_json.get("cache", true); - task_info_ptr->algorithm = algorithm; - task_info_ptr->name = name; - std::string action = task_json.get("action", std::string()); - std::transform(action.begin(), action.end(), action.begin(), ::tolower); - if (action == "clickself") { - task_info_ptr->action = ProcessTaskAction::ClickSelf; - } - else if (action == "clickrand") { - task_info_ptr->action = ProcessTaskAction::ClickRand; - } - else if (action == "donothing" || action.empty()) { - task_info_ptr->action = ProcessTaskAction::DoNothing; - } - else if (action == "stop") { - task_info_ptr->action = ProcessTaskAction::Stop; - } - else if (action == "clickrect") { - task_info_ptr->action = ProcessTaskAction::ClickRect; - const json::value& rect_json = task_json.at("specificRect"); - task_info_ptr->specific_rect = Rect( - rect_json[0].as_integer(), - rect_json[1].as_integer(), - rect_json[2].as_integer(), - rect_json[3].as_integer()); - } - else if (action == "stagedrops") { - task_info_ptr->action = ProcessTaskAction::StageDrops; - } - else if (action == "swipetotheleft") { - task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft; - } - else if (action == "swipetotheright") { - task_info_ptr->action = ProcessTaskAction::SwipeToTheRight; - } - else { - m_last_error = "Task: " + name + " error: " + action; - return false; - } - - task_info_ptr->max_times = task_json.get("maxTimes", INT_MAX); - if (task_json.exist("exceededNext")) { - const json::array& excceed_next_arr = task_json.at("exceededNext").as_array(); - for (const json::value& excceed_next : excceed_next_arr) { - task_info_ptr->exceeded_next.emplace_back(excceed_next.as_string()); - } - } - else { - task_info_ptr->exceeded_next.emplace_back("Stop"); - } - task_info_ptr->pre_delay = task_json.get("preDelay", 0); - task_info_ptr->rear_delay = task_json.get("rearDelay", 0); - if (task_json.exist("reduceOtherTimes")) { - const json::array& reduce_arr = task_json.at("reduceOtherTimes").as_array(); - for (const json::value& reduce : reduce_arr) { - task_info_ptr->reduce_other_times.emplace_back(reduce.as_string()); - } - } - if (task_json.exist("roi")) { - const json::array& area_arr = task_json.at("roi").as_array(); - int x = area_arr[0].as_integer(); - int y = area_arr[1].as_integer(); - int width = area_arr[2].as_integer(); - int height = area_arr[3].as_integer(); -#ifdef LOG_TRACE - if (x + width > WindowWidthDefault || y + height > WindowHeightDefault) { - m_last_error = name + " roi is out of bounds"; - return false; - } -#endif - task_info_ptr->roi = Rect(x, y, width, height); - } - else { - task_info_ptr->roi = Rect(); - } - - if (task_json.exist("next")) { - for (const json::value& next : task_json.at("next").as_array()) { - task_info_ptr->next.emplace_back(next.as_string()); - } - } - if (task_json.exist("rectMove")) { - const json::array& move_arr = task_json.at("rectMove").as_array(); - task_info_ptr->rect_move = Rect( - move_arr[0].as_integer(), - move_arr[1].as_integer(), - move_arr[2].as_integer(), - move_arr[3].as_integer()); - } - else { - task_info_ptr->rect_move = Rect(); - } - - m_all_tasks_info.emplace(name, task_info_ptr); - } -#ifdef LOG_TRACE - for (const auto& [name, task] : m_all_tasks_info) { - for (const auto& next : task->next) { - if (m_all_tasks_info.find(next) == m_all_tasks_info.cend()) { - m_last_error = name + "'s next " + next + " is null"; - return false; - } - } - } -#endif - return true; +#include "TaskData.h" + +#include + +#include + +#include "AsstDef.h" +#include "GeneralConfiger.h" +#include "TemplResource.h" + +const std::shared_ptr asst::TaskData::get(const std::string& name) const noexcept +{ + if (auto iter = m_all_tasks_info.find(name); + iter != m_all_tasks_info.cend()) { + return iter->second; + } + else { + return nullptr; + } +} + +const std::unordered_set& asst::TaskData::get_templ_required() const noexcept +{ + return m_templ_required; +} + +std::shared_ptr asst::TaskData::get(std::string name) +{ + return m_all_tasks_info[std::move(name)]; +} + +void asst::TaskData::clear_cache() noexcept +{ + for (auto&& [name, ptr] : m_all_tasks_info) { + ptr->region_of_appeared = Rect(); + } +} + +bool asst::TaskData::parse(const json::value& json) +{ + for (const auto& [name, task_json] : json.as_object()) { + std::string algorithm_str = task_json.get("algorithm", "matchtemplate"); + std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower); + AlgorithmType algorithm = AlgorithmType::Invaild; + if (algorithm_str == "matchtemplate") { + algorithm = AlgorithmType::MatchTemplate; + } + else if (algorithm_str == "justreturn") { + algorithm = AlgorithmType::JustReturn; + } + else if (algorithm_str == "ocrdetect") { + algorithm = AlgorithmType::OcrDetect; + } + // CompareHist是MatchTemplate的衍生算法,不应作为单独的配置参数出现 + // else if (algorithm_str == "comparehist") {} + else { + m_last_error = "algorithm error " + algorithm_str; + return false; + } + + std::shared_ptr task_info_ptr = nullptr; + switch (algorithm) { + case AlgorithmType::JustReturn: + task_info_ptr = std::make_shared(); + break; + case AlgorithmType::MatchTemplate: { + auto match_task_info_ptr = std::make_shared(); + match_task_info_ptr->templ_name = task_json.get("template", name + ".png"); + m_templ_required.emplace(match_task_info_ptr->templ_name); + + match_task_info_ptr->templ_threshold = task_json.get( + "templThreshold", TemplThresholdDefault); + match_task_info_ptr->special_threshold = task_json.get( + "specialThreshold", 0); + if (task_json.exist("maskRange")) { + match_task_info_ptr->mask_range = std::make_pair( + task_json.at("maskRange")[0].as_integer(), + task_json.at("maskRange")[1].as_integer()); + } + + task_info_ptr = match_task_info_ptr; + } break; + case AlgorithmType::OcrDetect: { + auto ocr_task_info_ptr = std::make_shared(); + for (const json::value& text : task_json.at("text").as_array()) { + ocr_task_info_ptr->text.emplace_back(text.as_string()); + } + ocr_task_info_ptr->need_full_match = task_json.get("need_match", false); + if (task_json.exist("ocrReplace")) { + for (const json::value& rep : task_json.at("ocrReplace").as_array()) { + ocr_task_info_ptr->replace_map.emplace(rep.as_array()[0].as_string(), rep.as_array()[1].as_string()); + } + } + task_info_ptr = ocr_task_info_ptr; + } break; + } + task_info_ptr->cache = task_json.get("cache", true); + task_info_ptr->algorithm = algorithm; + task_info_ptr->name = name; + std::string action = task_json.get("action", std::string()); + std::transform(action.begin(), action.end(), action.begin(), ::tolower); + if (action == "clickself") { + task_info_ptr->action = ProcessTaskAction::ClickSelf; + } + else if (action == "clickrand") { + task_info_ptr->action = ProcessTaskAction::ClickRand; + } + else if (action == "donothing" || action.empty()) { + task_info_ptr->action = ProcessTaskAction::DoNothing; + } + else if (action == "stop") { + task_info_ptr->action = ProcessTaskAction::Stop; + } + else if (action == "clickrect") { + task_info_ptr->action = ProcessTaskAction::ClickRect; + const json::value& rect_json = task_json.at("specificRect"); + task_info_ptr->specific_rect = Rect( + rect_json[0].as_integer(), + rect_json[1].as_integer(), + rect_json[2].as_integer(), + rect_json[3].as_integer()); + } + else if (action == "stagedrops") { + task_info_ptr->action = ProcessTaskAction::StageDrops; + } + else if (action == "swipetotheleft") { + task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft; + } + else if (action == "swipetotheright") { + task_info_ptr->action = ProcessTaskAction::SwipeToTheRight; + } + else { + m_last_error = "Task: " + name + " error: " + action; + return false; + } + + task_info_ptr->max_times = task_json.get("maxTimes", INT_MAX); + if (task_json.exist("exceededNext")) { + const json::array& excceed_next_arr = task_json.at("exceededNext").as_array(); + for (const json::value& excceed_next : excceed_next_arr) { + task_info_ptr->exceeded_next.emplace_back(excceed_next.as_string()); + } + } + else { + task_info_ptr->exceeded_next.emplace_back("Stop"); + } + task_info_ptr->pre_delay = task_json.get("preDelay", 0); + task_info_ptr->rear_delay = task_json.get("rearDelay", 0); + if (task_json.exist("reduceOtherTimes")) { + const json::array& reduce_arr = task_json.at("reduceOtherTimes").as_array(); + for (const json::value& reduce : reduce_arr) { + task_info_ptr->reduce_other_times.emplace_back(reduce.as_string()); + } + } + if (task_json.exist("roi")) { + const json::array& area_arr = task_json.at("roi").as_array(); + int x = area_arr[0].as_integer(); + int y = area_arr[1].as_integer(); + int width = area_arr[2].as_integer(); + int height = area_arr[3].as_integer(); +#ifdef LOG_TRACE + if (x + width > WindowWidthDefault || y + height > WindowHeightDefault) { + m_last_error = name + " roi is out of bounds"; + return false; + } +#endif + task_info_ptr->roi = Rect(x, y, width, height); + } + else { + task_info_ptr->roi = Rect(); + } + + if (task_json.exist("next")) { + for (const json::value& next : task_json.at("next").as_array()) { + task_info_ptr->next.emplace_back(next.as_string()); + } + } + if (task_json.exist("rectMove")) { + const json::array& move_arr = task_json.at("rectMove").as_array(); + task_info_ptr->rect_move = Rect( + move_arr[0].as_integer(), + move_arr[1].as_integer(), + move_arr[2].as_integer(), + move_arr[3].as_integer()); + } + else { + task_info_ptr->rect_move = Rect(); + } + + m_all_tasks_info.emplace(name, task_info_ptr); + } +#ifdef LOG_TRACE + for (const auto& [name, task] : m_all_tasks_info) { + for (const auto& next : task->next) { + if (m_all_tasks_info.find(next) == m_all_tasks_info.cend()) { + m_last_error = name + "'s next " + next + " is null"; + return false; + } + } + } +#endif + return true; } \ No newline at end of file diff --git a/src/MeoAssistance/TaskData.h b/src/MeoAssistant/TaskData.h similarity index 98% rename from src/MeoAssistance/TaskData.h rename to src/MeoAssistant/TaskData.h index 3b8869dbf5..c487cfeb59 100644 --- a/src/MeoAssistance/TaskData.h +++ b/src/MeoAssistant/TaskData.h @@ -12,31 +12,31 @@ namespace asst class TaskData : public AbstractConfiger { - public: - TaskData(const TaskData&) = delete; - TaskData(TaskData&&) = delete; + public: + TaskData(const TaskData&) = delete; + TaskData(TaskData&&) = delete; + + virtual ~TaskData() = default; - virtual ~TaskData() = default; - static TaskData& get_instance() { - static TaskData unique_instance; + static TaskData unique_instance; return unique_instance; } const std::shared_ptr get(const std::string& name) const noexcept; const std::unordered_set& get_templ_required() const noexcept; - std::shared_ptr get(std::string name); + std::shared_ptr get(std::string name); void clear_cache() noexcept; - protected: - TaskData() = default; + protected: + TaskData() = default; virtual bool parse(const json::value& json); std::unordered_map> m_all_tasks_info; std::unordered_set m_templ_required; - }; - + }; + static auto& task = TaskData::get_instance(); } diff --git a/src/MeoAssistance/TemplResource.cpp b/src/MeoAssistant/TemplResource.cpp similarity index 99% rename from src/MeoAssistance/TemplResource.cpp rename to src/MeoAssistant/TemplResource.cpp index 042a745212..482d5afa3b 100644 --- a/src/MeoAssistance/TemplResource.cpp +++ b/src/MeoAssistant/TemplResource.cpp @@ -48,4 +48,4 @@ const cv::Mat& asst::TemplResource::get_templ(const std::string& key) const noex void asst::TemplResource::emplace_templ(std::string key, cv::Mat templ) { m_templs.emplace(std::move(key), std::move(templ)); -} +} diff --git a/src/MeoAssistance/TemplResource.h b/src/MeoAssistant/TemplResource.h similarity index 100% rename from src/MeoAssistance/TemplResource.h rename to src/MeoAssistant/TemplResource.h diff --git a/src/MeoAssistance/UserConfiger.cpp b/src/MeoAssistant/UserConfiger.cpp similarity index 100% rename from src/MeoAssistance/UserConfiger.cpp rename to src/MeoAssistant/UserConfiger.cpp diff --git a/src/MeoAssistance/UserConfiger.h b/src/MeoAssistant/UserConfiger.h similarity index 100% rename from src/MeoAssistance/UserConfiger.h rename to src/MeoAssistant/UserConfiger.h diff --git a/src/MeoAssistance/Version.h b/src/MeoAssistant/Version.h similarity index 100% rename from src/MeoAssistance/Version.h rename to src/MeoAssistant/Version.h diff --git a/src/MeoAsstGui/.editorconfig b/src/MeoAsstGui/.editorconfig index 93a48124b8..34b1a3159e 100644 --- a/src/MeoAsstGui/.editorconfig +++ b/src/MeoAsstGui/.editorconfig @@ -150,7 +150,7 @@ dotnet_diagnostic.RS2008.severity = none # IDE0073: File header dotnet_diagnostic.IDE0073.severity = warning -file_header_template = MeoAssistanceGui - A part of the MeoAssistance-Arknight project\nCopyright (C) 2021 MistEO and Contributors\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\nany later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see . +file_header_template = MeoAsstGui - A part of the MeoAssistantArknights project\nCopyright (C) 2021 MistEO and Contributors\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\nany later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see . # IDE0035: Remove unreachable code dotnet_diagnostic.IDE0035.severity = warning diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index 4440af7100..aca15873fa 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -16,37 +16,37 @@ namespace MeoAsstGui private delegate void ProcCallbckMsg(AsstMsg msg, JObject detail); - [DllImport("MeoAssistance.dll")] private static extern IntPtr AsstCreate(string dirname); + [DllImport("MeoAssistant.dll")] private static extern IntPtr AsstCreate(string dirname); - [DllImport("MeoAssistance.dll")] private static extern IntPtr AsstCreateEx(string dirname, CallbackDelegate callback, IntPtr custom_arg); + [DllImport("MeoAssistant.dll")] private static extern IntPtr AsstCreateEx(string dirname, CallbackDelegate callback, IntPtr custom_arg); - [DllImport("MeoAssistance.dll")] private static extern void AsstDestroy(IntPtr ptr); + [DllImport("MeoAssistant.dll")] private static extern void AsstDestroy(IntPtr ptr); - [DllImport("MeoAssistance.dll")] private static extern bool AsstCatchDefault(IntPtr ptr); + [DllImport("MeoAssistant.dll")] private static extern bool AsstCatchDefault(IntPtr ptr); - [DllImport("MeoAssistance.dll")] private static extern bool AsstCatchCustom(IntPtr ptr, string address); + [DllImport("MeoAssistant.dll")] private static extern bool AsstCatchCustom(IntPtr ptr, string address); - [DllImport("MeoAssistance.dll")] private static extern bool AsstAppendFight(IntPtr ptr, int max_medicine, int max_stone, int max_times); + [DllImport("MeoAssistant.dll")] private static extern bool AsstAppendFight(IntPtr ptr, int max_medicine, int max_stone, int max_times); - [DllImport("MeoAssistance.dll")] private static extern bool AsstAppendAward(IntPtr ptr); + [DllImport("MeoAssistant.dll")] private static extern bool AsstAppendAward(IntPtr ptr); - [DllImport("MeoAssistance.dll")] private static extern bool AsstAppendVisit(IntPtr ptr); + [DllImport("MeoAssistant.dll")] private static extern bool AsstAppendVisit(IntPtr ptr); - [DllImport("MeoAssistance.dll")] private static extern bool AsstAppendMall(IntPtr ptr, bool with_shopping); + [DllImport("MeoAssistant.dll")] private static extern bool AsstAppendMall(IntPtr ptr, bool with_shopping); - [DllImport("MeoAssistance.dll")] private static extern bool AsstAppendInfrast(IntPtr ptr, int work_mode, string[] order, int order_len, string uses_of_drones, double dorm_threshold); + [DllImport("MeoAssistant.dll")] private static extern bool AsstAppendInfrast(IntPtr ptr, int work_mode, string[] order, int order_len, string uses_of_drones, double dorm_threshold); - [DllImport("MeoAssistance.dll")] private static extern bool AsstAppendRecruit(IntPtr ptr, int max_times, int[] select_level, int required_len, int[] confirm_level, int confirm_len, bool need_refresh); + [DllImport("MeoAssistant.dll")] private static extern bool AsstAppendRecruit(IntPtr ptr, int max_times, int[] select_level, int required_len, int[] confirm_level, int confirm_len, bool need_refresh); - [DllImport("MeoAssistance.dll")] private static extern bool AsstStartRecruitCalc(IntPtr ptr, int[] select_level, int required_len, bool set_time); + [DllImport("MeoAssistant.dll")] private static extern bool AsstStartRecruitCalc(IntPtr ptr, int[] select_level, int required_len, bool set_time); - [DllImport("MeoAssistance.dll")] private static extern bool AsstStart(IntPtr ptr); + [DllImport("MeoAssistant.dll")] private static extern bool AsstStart(IntPtr ptr); - [DllImport("MeoAssistance.dll")] private static extern bool AsstStop(IntPtr ptr); + [DllImport("MeoAssistant.dll")] private static extern bool AsstStop(IntPtr ptr); - [DllImport("MeoAssistance.dll")] private static extern bool AsstSetPenguinId(IntPtr p_asst, string id); + [DllImport("MeoAssistant.dll")] private static extern bool AsstSetPenguinId(IntPtr p_asst, string id); - //[DllImport("MeoAssistance.dll")] private static extern bool AsstSetParam(IntPtr p_asst, string type, string param, string value); + //[DllImport("MeoAssistant.dll")] private static extern bool AsstSetParam(IntPtr p_asst, string type, string param, string value); private CallbackDelegate _callback; diff --git a/src/MeoAsstGui/Helper/AutoScroll.cs b/src/MeoAsstGui/Helper/AutoScroll.cs index 41c7235489..626cf0e31d 100644 --- a/src/MeoAsstGui/Helper/AutoScroll.cs +++ b/src/MeoAsstGui/Helper/AutoScroll.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/Helper/CombData.cs b/src/MeoAsstGui/Helper/CombData.cs index ad11e740de..c4c744ecda 100644 --- a/src/MeoAsstGui/Helper/CombData.cs +++ b/src/MeoAsstGui/Helper/CombData.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/Helper/DragItemViewModel.cs b/src/MeoAsstGui/Helper/DragItemViewModel.cs index 1054eeb31c..223751ff21 100644 --- a/src/MeoAsstGui/Helper/DragItemViewModel.cs +++ b/src/MeoAsstGui/Helper/DragItemViewModel.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs b/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs index 31098a62c0..23d73e45c4 100644 --- a/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs +++ b/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/Helper/LogItemViewModel.cs b/src/MeoAsstGui/Helper/LogItemViewModel.cs index 5537839d57..fbea85de6d 100644 --- a/src/MeoAsstGui/Helper/LogItemViewModel.cs +++ b/src/MeoAsstGui/Helper/LogItemViewModel.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/Helper/ScrollViewerBinding.cs b/src/MeoAsstGui/Helper/ScrollViewerBinding.cs index 17b56b9ae2..57f661030c 100644 --- a/src/MeoAsstGui/Helper/ScrollViewerBinding.cs +++ b/src/MeoAsstGui/Helper/ScrollViewerBinding.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/MeoAsstGui.csproj b/src/MeoAsstGui/MeoAsstGui.csproj index d180809902..35c58ea3af 100644 --- a/src/MeoAsstGui/MeoAsstGui.csproj +++ b/src/MeoAsstGui/MeoAsstGui.csproj @@ -28,11 +28,11 @@ false false true - https://github.com/MistEO/MeoAssistance-Arknights - https://github.com/MistEO/MeoAssistance-Arknights/issues + https://github.com/MistEO/MeoAssistantArknights + https://github.com/MistEO/MeoAssistantArknights/issues Meo明日方舟辅助 MistEO - MeoAssistance + MeoAssistant 0 2.0.0.0 false diff --git a/src/MeoAsstGui/UserControl/AutoRecruitSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/AutoRecruitSettingsUserControl.xaml.cs index b74256231f..c60e0eb103 100644 --- a/src/MeoAsstGui/UserControl/AutoRecruitSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/AutoRecruitSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs index 57b7e0a89d..878e485c83 100644 --- a/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/UserControl/InfrastSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/InfrastSettingsUserControl.xaml.cs index b344dc6fed..a70e44eef1 100644 --- a/src/MeoAsstGui/UserControl/InfrastSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/InfrastSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml.cs index 68fb57a1bf..9d4b9b2834 100644 --- a/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/UserControl/PenguinReportSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/PenguinReportSettingsUserControl.xaml.cs index 2aa6829222..9ee038e331 100644 --- a/src/MeoAsstGui/UserControl/PenguinReportSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/PenguinReportSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/UserControl/VersionUpdateSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/VersionUpdateSettingsUserControl.xaml.cs index 88d55ea268..40332f1d77 100644 --- a/src/MeoAsstGui/UserControl/VersionUpdateSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/VersionUpdateSettingsUserControl.xaml.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify diff --git a/src/MeoAsstGui/ViewModels/SettingsViewModel.cs b/src/MeoAsstGui/ViewModels/SettingsViewModel.cs index a4619e2919..4c60e1420b 100644 --- a/src/MeoAsstGui/ViewModels/SettingsViewModel.cs +++ b/src/MeoAsstGui/ViewModels/SettingsViewModel.cs @@ -1,4 +1,4 @@ -// MeoAssistanceGui - A part of the MeoAssistance-Arknight project +// MeoAsstGui - A part of the MeoAssistantArknights project // Copyright (C) 2021 MistEO and Contributors // // This program is free software: you can redistribute it and/or modify @@ -24,7 +24,7 @@ namespace MeoAsstGui private IWindowManager _windowManager; private IContainer _container; - [DllImport("MeoAssistance.dll")] private static extern IntPtr AsstGetVersion(); + [DllImport("MeoAssistant.dll")] private static extern IntPtr AsstGetVersion(); private string _versionInfo = "版本号:" + Marshal.PtrToStringAnsi(AsstGetVersion()); @@ -418,4 +418,4 @@ namespace MeoAsstGui } } } -} +} \ No newline at end of file diff --git a/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs b/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs index a86bdd7ccd..9999164e82 100644 --- a/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs +++ b/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs @@ -1,103 +1,103 @@ -using System; +using System; using System.Collections.Generic; using StyletIoC; using System.Diagnostics; -using System.IO; -using System.Net; -using System.Runtime.InteropServices; -using System.Text; +using System.IO; +using System.Net; +using System.Runtime.InteropServices; +using System.Text; using System.Windows; using Microsoft.Toolkit.Uwp.Notifications; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Stylet; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Stylet; -namespace MeoAsstGui -{ - public class VersionUpdateViewModel : Screen - { - private IWindowManager _windowManager; +namespace MeoAsstGui +{ + public class VersionUpdateViewModel : Screen + { + private IWindowManager _windowManager; private IContainer _container; - - public VersionUpdateViewModel(IContainer container, IWindowManager windowManager) - { + + public VersionUpdateViewModel(IContainer container, IWindowManager windowManager) + { _container = container; - _windowManager = windowManager; - } - - [DllImport("MeoAssistance.dll")] private static extern IntPtr AsstGetVersion(); - - private string _curVersion = Marshal.PtrToStringAnsi(AsstGetVersion()); - private string _latestVersion; - + _windowManager = windowManager; + } + + [DllImport("MeoAssistant.dll")] private static extern IntPtr AsstGetVersion(); + + private string _curVersion = Marshal.PtrToStringAnsi(AsstGetVersion()); + private string _latestVersion; + private string _updateTag = ViewStatusStorage.Get("VersionUpdate.name", string.Empty); - - public string UpdateTag - { - get - { - return _updateTag; - } - set - { - SetAndNotify(ref _updateTag, value); - ViewStatusStorage.Set("VersionUpdate.name", value); - } - } - - private string _updateInfo = ViewStatusStorage.Get("VersionUpdate.body", string.Empty); - - public string UpdateInfo - { - get - { - return _updateInfo; - } - set - { - SetAndNotify(ref _updateInfo, value); - ViewStatusStorage.Set("VersionUpdate.body", value); - } + + public string UpdateTag + { + get + { + return _updateTag; + } + set + { + SetAndNotify(ref _updateTag, value); + ViewStatusStorage.Set("VersionUpdate.name", value); + } + } + + private string _updateInfo = ViewStatusStorage.Get("VersionUpdate.body", string.Empty); + + public string UpdateInfo + { + get + { + return _updateInfo; + } + set + { + SetAndNotify(ref _updateInfo, value); + ViewStatusStorage.Set("VersionUpdate.body", value); + } } private bool _isFirstBootAfterUpdate = Convert.ToBoolean(ViewStatusStorage.Get("VersionUpdate.firstboot", Boolean.FalseString)); - public bool IsFirstBootAfterUpdate - { - get - { - return _isFirstBootAfterUpdate; - } - set - { - SetAndNotify(ref _isFirstBootAfterUpdate, value); - ViewStatusStorage.Set("VersionUpdate.firstboot", value.ToString()); - } + public bool IsFirstBootAfterUpdate + { + get + { + return _isFirstBootAfterUpdate; + } + set + { + SetAndNotify(ref _isFirstBootAfterUpdate, value); + ViewStatusStorage.Set("VersionUpdate.firstboot", value.ToString()); + } } private string _updatePackageName = ViewStatusStorage.Get("VersionUpdate.package", string.Empty); - public string UpdatePackageName - { - get - { - return _updatePackageName; - } - set - { - SetAndNotify(ref _updatePackageName, value); - ViewStatusStorage.Set("VersionUpdate.package", value.ToString()); - } + public string UpdatePackageName + { + get + { + return _updatePackageName; + } + set + { + SetAndNotify(ref _updatePackageName, value); + ViewStatusStorage.Set("VersionUpdate.package", value.ToString()); + } } - private const string _requestUrl = "https://api.github.com/repos/MistEO/MeoAssistance-Arknights/releases/latest"; - private const string _requestBetaUrl = "https://api.github.com/repos/MistEO/MeoAssistance-Arknights/releases"; + private const string _requestUrl = "https://api.github.com/repos/MistEO/MeoAssistantArknights/releases/latest"; + private const string _requestBetaUrl = "https://api.github.com/repos/MistEO/MeoAssistantArknights/releases"; private string _viewUrl; - private JObject _lastestJson; + private JObject _lastestJson; private string _downloadUrl; - - // 检查是否有已下载的更新包,如果有立即更新并重启进程 + + // 检查是否有已下载的更新包,如果有立即更新并重启进程 public bool CheckAndUpdateNow() { if (UpdateTag == string.Empty @@ -110,9 +110,9 @@ namespace MeoAsstGui .AddText("检测到新版本包,正在解压,请稍等……") .AddText(UpdateTag) .Show(); - string extractDir = Directory.GetCurrentDirectory() + "\\NewVersionExtract"; - // 解压 - System.IO.Compression.ZipFile.ExtractToDirectory(UpdatePackageName, extractDir); + string extractDir = Directory.GetCurrentDirectory() + "\\NewVersionExtract"; + // 解压 + System.IO.Compression.ZipFile.ExtractToDirectory(UpdatePackageName, extractDir); var uncopiedList = new List(); // 复制新版本的所有文件到当前路径下 @@ -162,33 +162,33 @@ namespace MeoAsstGui return true; } - - // 检查更新,并下载更新包 - public bool CheckAndDownloadUpdate() - { - // 检查更新 + + // 检查更新,并下载更新包 + public bool CheckAndDownloadUpdate() + { + // 检查更新 if (!CheckUpdate()) { return false; - } - // 保存新版本的信息 + } + // 保存新版本的信息 UpdatePackageName = _downloadUrl.Substring(_downloadUrl.LastIndexOf('/') + 1); - UpdateTag = _lastestJson["name"].ToString(); + UpdateTag = _lastestJson["name"].ToString(); UpdateInfo = _lastestJson["body"].ToString(); - var openUrlToastButton = new ToastButton(); - openUrlToastButton.SetContent("前往页面查看"); - openUrlToastButton.SetProtocolActivation(new Uri(_viewUrl)); - new ToastContentBuilder() - .AddText("检测到新版本,正在后台下载……") - .AddText(UpdateTag) - .AddText(UpdateInfo) - .AddButton(openUrlToastButton) + var openUrlToastButton = new ToastButton(); + openUrlToastButton.SetContent("前往页面查看"); + openUrlToastButton.SetProtocolActivation(new Uri(_viewUrl)); + new ToastContentBuilder() + .AddText("检测到新版本,正在后台下载……") + .AddText(UpdateTag) + .AddText(UpdateInfo) + .AddButton(openUrlToastButton) .Show(); - // 下载压缩包 - const int downloadRetryMaxTimes = 2; - string downloadTempFilename = UpdatePackageName + ".tmp"; - bool downloaded = false; + // 下载压缩包 + const int downloadRetryMaxTimes = 2; + string downloadTempFilename = UpdatePackageName + ".tmp"; + bool downloaded = false; for (int i = 0; i != downloadRetryMaxTimes; ++i) { if (DownloadFile(_downloadUrl.Replace("github.com", "hub.fastgit.org"), downloadTempFilename) @@ -197,32 +197,32 @@ namespace MeoAsstGui downloaded = true; break; } - } + } if (!downloaded) { new ToastContentBuilder() - .AddText("新版本下载失败") - .AddText("请尝试手动下载后,将压缩包放到目录下_(:з」∠)_") + .AddText("新版本下载失败") + .AddText("请尝试手动下载后,将压缩包放到目录下_(:з」∠)_") .AddButton(openUrlToastButton) .Show(); return false; } - File.Copy(downloadTempFilename, UpdatePackageName, true); + File.Copy(downloadTempFilename, UpdatePackageName, true); File.Delete(downloadTempFilename); // 把相关信息存下来,更新完之后启动的时候显示 new ToastContentBuilder() - .AddText("新版本下载完成") - .AddText("软件将在下次启动时自动更新!") - .AddText("✿✿ヽ(°▽°)ノ✿") - .Show(); - return true; - } - - public bool CheckUpdate() + .AddText("新版本下载完成") + .AddText("软件将在下次启动时自动更新!") + .AddText("✿✿ヽ(°▽°)ノ✿") + .Show(); + return true; + } + + public bool CheckUpdate() { - var settings = _container.Get(); - string response = string.Empty; - const int requestRetryMaxTimes = 5; + var settings = _container.Get(); + string response = string.Empty; + const int requestRetryMaxTimes = 5; for (int i = 0; i != requestRetryMaxTimes; ++i) { if (settings.UpdateBeta) @@ -237,11 +237,11 @@ namespace MeoAsstGui { break; } - } - if (response.Length == 0) - { - return false; - } + } + if (response.Length == 0) + { + return false; + } try { @@ -266,7 +266,7 @@ namespace MeoAsstGui foreach (JObject asset in json["assets"]) { string downUrl = asset["browser_download_url"].ToString(); - if (downUrl.IndexOf("MeoAssistance") != -1) + if (downUrl.IndexOf("MeoAssistantArknights") != -1) { _downloadUrl = downUrl; _lastestJson = json; @@ -278,9 +278,9 @@ namespace MeoAsstGui { return false; } - return false; - } - + return false; + } + private string RequestApi(string url) { HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); @@ -348,8 +348,8 @@ namespace MeoAsstGui public bool ResourceOTA() { - const string req_base_url = "https://api.github.com/repos/MistEO/MeoAssistance-Arknights/commits?path="; - const string down_base_url = "https://cdn.jsdelivr.net/gh/MistEO/MeoAssistance-Arknights@"; + const string req_base_url = "https://api.github.com/repos/MistEO/MeoAssistantArknights/commits?path="; + const string down_base_url = "https://cdn.jsdelivr.net/gh/MistEO/MeoAssistantArknights@"; var update_dict = new Dictionary() { { "3rdparty/resource/penguin-stats-recognize/json/stages.json" , "resource/penguin-stats-recognize/json/stages.json"}, @@ -444,6 +444,6 @@ namespace MeoAsstGui IsFirstBootAfterUpdate = false; UpdateTag = ""; UpdateInfo = ""; - } - } + } + } } diff --git a/src/Python/interface.py b/src/Python/interface.py index 0e8b180e86..e1c8132cff 100644 --- a/src/Python/interface.py +++ b/src/Python/interface.py @@ -24,7 +24,7 @@ class Asst: ``callback``: 回调函数 ``arg``: 自定义参数 """ - self.__dllpath = pathlib.Path(dirname) / 'MeoAssistance.dll' + self.__dllpath = pathlib.Path(dirname) / 'MeoAssistant.dll' self.__dll = ctypes.WinDLL(str(self.__dllpath)) self.__dll.AsstCreateEx.restype = ctypes.c_void_p diff --git a/tools/TestCaller/TestCaller.vcxproj b/tools/TestCaller/TestCaller.vcxproj index 6464ec7e66..4268e9ebf1 100644 --- a/tools/TestCaller/TestCaller.vcxproj +++ b/tools/TestCaller/TestCaller.vcxproj @@ -75,7 +75,7 @@ true true true - MeoAssistance.lib;%(AdditionalDependencies) + MeoAssistant.lib;%(AdditionalDependencies) $(TargetDir);%(AdditionalLibraryDirectories)
@@ -97,7 +97,7 @@ true true true - MeoAssistance.lib;%(AdditionalDependencies) + MeoAssistant.lib;%(AdditionalDependencies) $(TargetDir);%(AdditionalLibraryDirectories) diff --git a/tools/TransparentImageCvt/TransparentImageCvt.vcxproj b/tools/TransparentImageCvt/TransparentImageCvt.vcxproj index d3883104df..d7ef4b1991 100644 --- a/tools/TransparentImageCvt/TransparentImageCvt.vcxproj +++ b/tools/TransparentImageCvt/TransparentImageCvt.vcxproj @@ -1,18 +1,10 @@ - - Debug - Win32 - Release Win32 - - Debug - x64 - Release x64 @@ -26,12 +18,6 @@ 10.0
- - Application - true - v142 - Unicode - Application false @@ -39,12 +25,6 @@ true Unicode - - Application - true - v142 - Unicode - Application false @@ -57,47 +37,21 @@ - - - - - - - - true - false - - true - $(SolutionDir)3rdparty\include;$(VC_IncludePath);$(WindowsSDK_IncludePath) - $(SolutionDir)3rdparty\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) - false $(SolutionDir)3rdparty\include;$(VC_IncludePath);$(WindowsSDK_IncludePath) $(SolutionDir)3rdparty\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64) - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - Level3 @@ -114,21 +68,6 @@ true - - - Level3 - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpp17 - MultiThreadedDLL - - - Console - true - opencv_world453.lib;%(AdditionalDependencies) - - Level3 diff --git a/tools/TransparentImageCvt/main.cpp b/tools/TransparentImageCvt/main.cpp index 2aaf75ed48..a59baea310 100644 --- a/tools/TransparentImageCvt/main.cpp +++ b/tools/TransparentImageCvt/main.cpp @@ -8,8 +8,9 @@ int main() { - std::string input_dir = R"(D:\Code\MeoAssistance\resource\infrast)"; - std::string output_dir = R"(D:\Code\MeoAssistance\resource\infrast\cvt\)"; + auto solution_dir = std::filesystem::current_path().parent_path().parent_path(); + auto input_dir = solution_dir / "resource" / "infrast"; + auto output_dir = solution_dir / "resource" / "infrast" / "cvt"; for (auto&& entry : std::filesystem::directory_iterator(input_dir)) { if (entry.path().extension() != ".png") { @@ -27,7 +28,7 @@ int main() } } } - std::string out_file = output_dir + entry.path().filename().u8string(); + std::string out_file = (output_dir / entry.path().filename()).u8string(); cv::imwrite(out_file, cvt); } diff --git a/tools/build_release.bat b/tools/build_release.bat index 4d2e240ffa..d00a174d11 100644 --- a/tools/build_release.bat +++ b/tools/build_release.bat @@ -1,2 +1,2 @@ -MSBuild.exe ..\MeoAssistance.sln /p:Configuration=Release /p:Platform=x64 /t:Rebuild +MSBuild.exe ..\MeoAssistantArknights.sln /p:Configuration=Release /p:Platform=x64 /t:Rebuild sh zip_release.sh \ No newline at end of file diff --git a/tools/zip_release.sh b/tools/zip_release.sh index f71ac6f915..7d78a3e60b 100644 --- a/tools/zip_release.sh +++ b/tools/zip_release.sh @@ -1,6 +1,6 @@ TargetDir="../x64/Release" LatestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) -Package="../x64/MeoAssistance_"$LatestTag".zip" +Package="../x64/MeoAssistantArknights_"$LatestTag".zip" cp ./*.url $TargetDir 7z.exe a $Package $TargetDir/resource $TargetDir/*.dll $TargetDir/aria2c.exe $TargetDir/MeoAsstGui.exe $TargetDir/*.url \ No newline at end of file diff --git a/tools/使用说明.url b/tools/使用说明.url index a467b530af..00bff04f26 100644 --- a/tools/使用说明.url +++ b/tools/使用说明.url @@ -1,2 +1,2 @@ [InternetShortcut] -URL=https://github.com/MistEO/MeoAssistance-Arknights/blob/master/README.md +URL=https://github.com/MistEO/MeoAssistantArknights/blob/master/README.md diff --git a/tools/问题反馈.url b/tools/问题反馈.url index 4cf932e0c1..40d2c43106 100644 --- a/tools/问题反馈.url +++ b/tools/问题反馈.url @@ -1,2 +1,2 @@ [InternetShortcut] -URL=https://github.com/MistEO/MeoAssistance-Arknights/issues +URL=https://github.com/MistEO/MeoAssistantArknights/issues From ceaaa4600b6bd3b4d3587907a436a7a8bbf57ae9 Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 14 Dec 2021 21:39:46 +0800 Subject: [PATCH 06/13] =?UTF-8?q?opt.=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/Logger.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/MeoAssistant/Logger.hpp b/src/MeoAssistant/Logger.hpp index fad728f580..02de9ac146 100644 --- a/src/MeoAssistant/Logger.hpp +++ b/src/MeoAssistant/Logger.hpp @@ -34,19 +34,19 @@ namespace asst template inline void trace(Args&&... args) { - constexpr static std::string_view level = "TRC"; + std::string_view level = "TRC"; log(level, std::forward(args)...); } template inline void info(Args&&... args) { - constexpr static std::string_view level = "INF"; + std::string_view level = "INF"; log(level, std::forward(args)...); } template inline void error(Args&&... args) { - constexpr static std::string_view level = "ERR"; + std::string_view level = "ERR"; log(level, std::forward(args)...); } @@ -86,7 +86,7 @@ namespace asst } template - void log(const std::string_view& level, Args&&... args) + void log(std::string_view level, Args&&... args) { std::unique_lock trace_lock(m_trace_mutex); @@ -96,7 +96,11 @@ namespace asst level.data(), _getpid(), ::GetCurrentThreadId()); std::ofstream ofs(m_log_filename, std::ios::out | std::ios::app); +#ifdef LOG_TRACE + stream_args(ofs, buff, args...); +#else stream_args(ofs, buff, std::forward(args)...); +#endif ofs.close(); #ifdef LOG_TRACE From 1e684c1d32622c4893738cbc9d218c3e5876e16e Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 14 Dec 2021 23:49:27 +0800 Subject: [PATCH 07/13] =?UTF-8?q?opt.=E4=BC=98=E5=8C=96=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/AbstractTask.cpp | 4 ++-- src/MeoAssistant/Assistance.cpp | 2 +- src/MeoAssistant/Controller.cpp | 4 ++-- src/MeoAssistant/Logger.hpp | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/MeoAssistant/AbstractTask.cpp b/src/MeoAssistant/AbstractTask.cpp index 51289c1d38..bfb4f42a0d 100644 --- a/src/MeoAssistant/AbstractTask.cpp +++ b/src/MeoAssistant/AbstractTask.cpp @@ -47,7 +47,7 @@ bool AbstractTask::sleep(unsigned millisecond) if (millisecond == 0) { return true; } - auto start = std::chrono::system_clock::now(); + auto start = std::chrono::steady_clock::now(); long long duration = 0; json::value callback_json; @@ -56,7 +56,7 @@ bool AbstractTask::sleep(unsigned millisecond) while (!need_exit() && duration < millisecond) { duration = std::chrono::duration_cast( - std::chrono::system_clock::now() - start) + std::chrono::steady_clock::now() - start) .count(); std::this_thread::yield(); } diff --git a/src/MeoAssistant/Assistance.cpp b/src/MeoAssistant/Assistance.cpp index 1b68dac998..a4a84dbd26 100644 --- a/src/MeoAssistant/Assistance.cpp +++ b/src/MeoAssistant/Assistance.cpp @@ -457,7 +457,7 @@ void Assistance::working_proc() std::unique_lock lock(m_mutex); if (!m_thread_idle && !m_tasks_queue.empty()) { - auto start_time = std::chrono::system_clock::now(); + auto start_time = std::chrono::steady_clock::now(); auto task_ptr = m_tasks_queue.front(); diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index 3949d4925b..ed932639e5 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -194,7 +194,7 @@ void asst::Controller::pipe_working_proc() } //else if (!m_thread_idle) { // 队列中没有任务,又不是闲置的时候,就去截图 // cmd_queue_lock.unlock(); - // auto start_time = std::chrono::system_clock::now(); + // auto start_time = std::chrono::steady_clock::now(); // screencap(); // cmd_queue_lock.lock(); // if (!m_cmd_queue.empty()) { @@ -447,7 +447,7 @@ void asst::Controller::random_delay() const if (opt.control_delay_upper != 0) { LogTraceFunction; static std::default_random_engine rand_engine( - std::chrono::system_clock::now().time_since_epoch().count()); + std::chrono::steady_clock::now().time_since_epoch().count()); static std::uniform_int_distribution rand_uni( opt.control_delay_lower, opt.control_delay_upper); diff --git a/src/MeoAssistant/Logger.hpp b/src/MeoAssistant/Logger.hpp index 02de9ac146..eb6eee3a35 100644 --- a/src/MeoAssistant/Logger.hpp +++ b/src/MeoAssistant/Logger.hpp @@ -146,20 +146,20 @@ namespace asst public: LoggerAux(const std::string& func_name) : m_func_name(func_name), - m_start_time(std::chrono::system_clock::now()) + m_start_time(std::chrono::steady_clock::now()) { Logger::get_instance().trace(m_func_name, " | enter"); } ~LoggerAux() { - auto duration = std::chrono::system_clock::now() - m_start_time; + auto duration = std::chrono::steady_clock::now() - m_start_time; Logger::get_instance().trace(m_func_name, " | leave,", std::chrono::duration_cast(duration).count(), "ms"); } private: std::string m_func_name; - std::chrono::time_point m_start_time; + std::chrono::time_point m_start_time; }; //static auto& log = Logger::get_instance(); From c0a3c99e4ed69dccda6587a3dba8d14c635dc60c Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 14 Dec 2021 23:58:22 +0800 Subject: [PATCH 08/13] =?UTF-8?q?perf.=E6=9B=B4=E6=96=B0=E9=A3=9E=E6=A1=A8?= =?UTF-8?q?=E4=B8=BA=E7=A7=BB=E5=8A=A8=E7=AB=AF=E8=B5=84=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/PaddleOCR/det/ch_PP-OCRv2_det_slim_quant_infer | 0 3rdparty/resource/PaddleOCR/det/version.txt | 1 + .../resource/PaddleOCR/rec/ch_PP-OCRv2_rec_slim_quant_infer | 0 3rdparty/resource/PaddleOCR/rec/version.txt | 1 + resource/tasks.json | 4 ++-- 5 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 3rdparty/resource/PaddleOCR/det/ch_PP-OCRv2_det_slim_quant_infer create mode 100644 3rdparty/resource/PaddleOCR/det/version.txt delete mode 100644 3rdparty/resource/PaddleOCR/rec/ch_PP-OCRv2_rec_slim_quant_infer create mode 100644 3rdparty/resource/PaddleOCR/rec/version.txt diff --git a/3rdparty/resource/PaddleOCR/det/ch_PP-OCRv2_det_slim_quant_infer b/3rdparty/resource/PaddleOCR/det/ch_PP-OCRv2_det_slim_quant_infer deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/3rdparty/resource/PaddleOCR/det/version.txt b/3rdparty/resource/PaddleOCR/det/version.txt new file mode 100644 index 0000000000..3e35e11c98 --- /dev/null +++ b/3rdparty/resource/PaddleOCR/det/version.txt @@ -0,0 +1 @@ +ch_ppocr_mobile_v2.0_det_prune_infer \ No newline at end of file diff --git a/3rdparty/resource/PaddleOCR/rec/ch_PP-OCRv2_rec_slim_quant_infer b/3rdparty/resource/PaddleOCR/rec/ch_PP-OCRv2_rec_slim_quant_infer deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/3rdparty/resource/PaddleOCR/rec/version.txt b/3rdparty/resource/PaddleOCR/rec/version.txt new file mode 100644 index 0000000000..8bf34ca81c --- /dev/null +++ b/3rdparty/resource/PaddleOCR/rec/version.txt @@ -0,0 +1 @@ +ch_ppocr_mobile_v2.0_rec_slim_infer \ No newline at end of file diff --git a/resource/tasks.json b/resource/tasks.json index cf61e94a96..b721d9cfb5 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -413,8 +413,8 @@ "LastBattle": { "algorithm": "OcrDetect", "text": [ - "上一次作战", - "前往上一次" + "前往上", + "次作战" ], "roi": [ 900, From 1acf77a8e91c3de71c08abf56e935b0f627a9d57 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 15 Dec 2021 00:18:29 +0800 Subject: [PATCH 09/13] =?UTF-8?q?feat.OcrReplace=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E6=9B=BF=E6=8D=A2=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=85=AC=E6=8B=9B=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/tasks.json | 7 ++++++- src/MeoAssistant/OcrImageAnalyzer.cpp | 7 ++++--- src/MeoAssistant/ProcessTaskImageAnalyzer.cpp | 6 ++++-- src/MeoAssistant/RecruitImageAnalyzer.cpp | 8 ++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/resource/tasks.json b/resource/tasks.json index b721d9cfb5..7700c1628c 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -1089,7 +1089,12 @@ 480, 120 ], - "ocrReplace": [] + "ocrReplace": [ + [ + ".+击干员", + "狙击干员" + ] + ] }, "RecruitRefresh": { "action": "clickSelf", diff --git a/src/MeoAssistant/OcrImageAnalyzer.cpp b/src/MeoAssistant/OcrImageAnalyzer.cpp index d8489d0bfc..dde277210a 100644 --- a/src/MeoAssistant/OcrImageAnalyzer.cpp +++ b/src/MeoAssistant/OcrImageAnalyzer.cpp @@ -1,6 +1,7 @@ #include "OcrImageAnalyzer.h" -#include "AsstUtils.hpp" +#include + #include "Logger.hpp" #include "Resource.h" @@ -12,8 +13,8 @@ bool asst::OcrImageAnalyzer::analyze() if (!m_replace.empty()) { TextRectProc text_replace = [&](TextRect& tr) -> bool { - for (const auto& [old_str, new_str] : m_replace) { - tr.text = utils::string_replace_all(tr.text, old_str, new_str); + for (const auto& [regex, new_str] : m_replace) { + tr.text = std::regex_replace(tr.text, std::regex(regex), new_str); } return true; }; diff --git a/src/MeoAssistant/ProcessTaskImageAnalyzer.cpp b/src/MeoAssistant/ProcessTaskImageAnalyzer.cpp index 51d8e2ac0a..312d40becc 100644 --- a/src/MeoAssistant/ProcessTaskImageAnalyzer.cpp +++ b/src/MeoAssistant/ProcessTaskImageAnalyzer.cpp @@ -1,5 +1,7 @@ #include "ProcessTaskImageAnalyzer.h" +#include + #include "AsstUtils.hpp" #include "Logger.hpp" #include "MatchImageAnalyzer.h" @@ -39,8 +41,8 @@ bool asst::ProcessTaskImageAnalyzer::ocr_analyze(std::shared_ptr task_ // 先尝试从缓存的结果里找 for (const TextRect& tr : m_ocr_cache) { TextRect temp = tr; - for (const auto& [old_str, new_str] : ocr_task_ptr->replace_map) { - temp.text = utils::string_replace_all(temp.text, old_str, new_str); + for (const auto& [regex, new_str] : ocr_task_ptr->replace_map) { + temp.text = std::regex_replace(temp.text, std::regex(regex), new_str); } for (const auto& text : ocr_task_ptr->text) { bool flag = false; diff --git a/src/MeoAssistant/RecruitImageAnalyzer.cpp b/src/MeoAssistant/RecruitImageAnalyzer.cpp index 4d862029d9..f7d5129505 100644 --- a/src/MeoAssistant/RecruitImageAnalyzer.cpp +++ b/src/MeoAssistant/RecruitImageAnalyzer.cpp @@ -9,10 +9,10 @@ bool asst::RecruitImageAnalyzer::analyze() m_tags_result.clear(); m_set_time_rect.clear(); - bool ret = time_analyze(); - ret |= tags_analyze(); - ret |= confirm_analyze(); - ret |= refresh_analyze(); + time_analyze(); + refresh_analyze(); + bool ret = tags_analyze(); + ret &= confirm_analyze(); return ret; } From 7abcb214ec8e998dbaf886c5cc6d28a43cd3f617 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 15 Dec 2021 00:22:56 +0800 Subject: [PATCH 10/13] =?UTF-8?q?style.=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAsstGui/App.xaml.cs | 13 ++++++++++++- src/MeoAsstGui/Bootstrapper.cs | 11 +++++++++++ src/MeoAsstGui/Helper/AsstProxy.cs | 15 ++++++++++++--- src/MeoAsstGui/Helper/AutoScroll.cs | 5 ----- src/MeoAsstGui/Helper/CombData.cs | 6 ------ src/MeoAsstGui/Helper/DragItemViewModel.cs | 4 ---- src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs | 7 +++---- src/MeoAsstGui/Helper/LogItemViewModel.cs | 4 ---- src/MeoAsstGui/Helper/ScrollViewerBinding.cs | 6 ------ src/MeoAsstGui/Helper/ViewStatusStorage.cs | 11 +++++++++++ src/MeoAsstGui/Properties/AssemblyInfo.cs | 13 ++++++++++++- .../ConnectSettingsUserControl.xaml.cs | 12 ------------ .../UserControl/FightSettingsUserControl.xaml.cs | 11 +++++++++++ src/MeoAsstGui/ViewModels/RecruitViewModel.cs | 11 +++++++++++ src/MeoAsstGui/ViewModels/RootViewModel.cs | 11 +++++++++++ src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs | 13 +++++++++++-- .../ViewModels/VersionUpdateViewModel.cs | 14 ++++++++++++-- 17 files changed, 117 insertions(+), 50 deletions(-) diff --git a/src/MeoAsstGui/App.xaml.cs b/src/MeoAsstGui/App.xaml.cs index 28be7624b6..b92f7993cc 100644 --- a/src/MeoAsstGui/App.xaml.cs +++ b/src/MeoAsstGui/App.xaml.cs @@ -1,4 +1,15 @@ -using System.Windows; +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + +using System.Windows; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/Bootstrapper.cs b/src/MeoAsstGui/Bootstrapper.cs index 515c6d9fab..e15906abc8 100644 --- a/src/MeoAsstGui/Bootstrapper.cs +++ b/src/MeoAsstGui/Bootstrapper.cs @@ -1,3 +1,14 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System.Windows; using System.Windows.Threading; using Stylet; diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index aca15873fa..c091e40b82 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -1,12 +1,21 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System; using System.Runtime.InteropServices; -using System.Threading.Tasks; -using System.Windows; +using Microsoft.Toolkit.Uwp.Notifications; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Stylet; using StyletIoC; -using Microsoft.Toolkit.Uwp.Notifications; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/Helper/AutoScroll.cs b/src/MeoAsstGui/Helper/AutoScroll.cs index 626cf0e31d..c6d45fccc8 100644 --- a/src/MeoAsstGui/Helper/AutoScroll.cs +++ b/src/MeoAsstGui/Helper/AutoScroll.cs @@ -9,11 +9,6 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; diff --git a/src/MeoAsstGui/Helper/CombData.cs b/src/MeoAsstGui/Helper/CombData.cs index c4c744ecda..21fe67b831 100644 --- a/src/MeoAsstGui/Helper/CombData.cs +++ b/src/MeoAsstGui/Helper/CombData.cs @@ -9,12 +9,6 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace MeoAsstGui { public class CombData diff --git a/src/MeoAsstGui/Helper/DragItemViewModel.cs b/src/MeoAsstGui/Helper/DragItemViewModel.cs index 223751ff21..8ddc89edbe 100644 --- a/src/MeoAsstGui/Helper/DragItemViewModel.cs +++ b/src/MeoAsstGui/Helper/DragItemViewModel.cs @@ -9,11 +9,7 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Threading.Tasks; using Stylet; -using StyletIoC; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs b/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs index 23d73e45c4..fef4993f92 100644 --- a/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs +++ b/src/MeoAsstGui/Helper/FlowDocumentPagePadding.cs @@ -10,11 +10,7 @@ // but WITHOUT ANY WARRANTY using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Documents; @@ -26,10 +22,12 @@ namespace MeoAsstGui { return (Thickness)obj.GetValue(PagePaddingProperty); } + public static void SetPagePadding(DependencyObject obj, Thickness value) { obj.SetValue(PagePaddingProperty, value); } + public static readonly DependencyProperty PagePaddingProperty = DependencyProperty.RegisterAttached("PagePadding", typeof(Thickness), typeof(FlowDocumentPagePadding), new UIPropertyMetadata(new Thickness(double.NegativeInfinity), (o, args) => { @@ -40,6 +38,7 @@ namespace MeoAsstGui fd.PagePadding = (Thickness)args.NewValue; dpd.AddValueChanged(fd, PaddingChanged); })); + public static void PaddingChanged(object s, EventArgs e) { ((FlowDocument)s).PagePadding = GetPagePadding((DependencyObject)s); diff --git a/src/MeoAsstGui/Helper/LogItemViewModel.cs b/src/MeoAsstGui/Helper/LogItemViewModel.cs index fbea85de6d..def55d1557 100644 --- a/src/MeoAsstGui/Helper/LogItemViewModel.cs +++ b/src/MeoAsstGui/Helper/LogItemViewModel.cs @@ -10,11 +10,7 @@ // but WITHOUT ANY WARRANTY using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Threading.Tasks; using Stylet; -using StyletIoC; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/Helper/ScrollViewerBinding.cs b/src/MeoAsstGui/Helper/ScrollViewerBinding.cs index 57f661030c..e39a6728a2 100644 --- a/src/MeoAsstGui/Helper/ScrollViewerBinding.cs +++ b/src/MeoAsstGui/Helper/ScrollViewerBinding.cs @@ -9,14 +9,8 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using Windows.UI.Xaml.Controls.Primitives; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/Helper/ViewStatusStorage.cs b/src/MeoAsstGui/Helper/ViewStatusStorage.cs index 720632dafc..9a4fa740ef 100644 --- a/src/MeoAsstGui/Helper/ViewStatusStorage.cs +++ b/src/MeoAsstGui/Helper/ViewStatusStorage.cs @@ -1,3 +1,14 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System; using System.IO; using Newtonsoft.Json; diff --git a/src/MeoAsstGui/Properties/AssemblyInfo.cs b/src/MeoAsstGui/Properties/AssemblyInfo.cs index 5425758d77..79222c16e0 100644 --- a/src/MeoAsstGui/Properties/AssemblyInfo.cs +++ b/src/MeoAsstGui/Properties/AssemblyInfo.cs @@ -1,4 +1,15 @@ -using System.Reflection; +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + +using System.Reflection; using System.Resources; using System.Runtime.InteropServices; using System.Windows; diff --git a/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs index 878e485c83..006e5303c0 100644 --- a/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/ConnectSettingsUserControl.xaml.cs @@ -9,19 +9,7 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml.cs b/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml.cs index 85a6894c18..85c97432f2 100644 --- a/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml.cs +++ b/src/MeoAsstGui/UserControl/FightSettingsUserControl.xaml.cs @@ -1,3 +1,14 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System.Windows.Controls; namespace MeoAsstGui diff --git a/src/MeoAsstGui/ViewModels/RecruitViewModel.cs b/src/MeoAsstGui/ViewModels/RecruitViewModel.cs index 62f7a5b71b..5f64c9f258 100644 --- a/src/MeoAsstGui/ViewModels/RecruitViewModel.cs +++ b/src/MeoAsstGui/ViewModels/RecruitViewModel.cs @@ -1,3 +1,14 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System.Collections.Generic; using System.Threading.Tasks; using Stylet; diff --git a/src/MeoAsstGui/ViewModels/RootViewModel.cs b/src/MeoAsstGui/ViewModels/RootViewModel.cs index 0fac4a11f1..36cbb55252 100644 --- a/src/MeoAsstGui/ViewModels/RootViewModel.cs +++ b/src/MeoAsstGui/ViewModels/RootViewModel.cs @@ -1,3 +1,14 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System.Threading.Tasks; using Stylet; using StyletIoC; diff --git a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs index a0bd4c11a5..d0e36ab65e 100644 --- a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs +++ b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs @@ -1,11 +1,20 @@ -using System; +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Windows; using Stylet; using StyletIoC; -using Windows.UI.Xaml.Documents; namespace MeoAsstGui { diff --git a/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs b/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs index 9999164e82..00b1f16809 100644 --- a/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs +++ b/src/MeoAsstGui/ViewModels/VersionUpdateViewModel.cs @@ -1,7 +1,16 @@ +// MeoAsstGui - A part of the MeoAssistantArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY + using System; using System.Collections.Generic; -using StyletIoC; - using System.Diagnostics; using System.IO; using System.Net; @@ -12,6 +21,7 @@ using Microsoft.Toolkit.Uwp.Notifications; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Stylet; +using StyletIoC; namespace MeoAsstGui { From 876dcb8e344c1bc7992e7941e99bee3639f11aa5 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 15 Dec 2021 01:07:10 +0800 Subject: [PATCH 11/13] =?UTF-8?q?chore.=E9=A1=B9=E7=9B=AE=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{Assistance.cpp => Assistant.cpp} | 62 +++++++++---------- .../{Assistance.h => Assistant.h} | 6 +- src/MeoAssistant/AsstCaller.cpp | 40 ++++++------ src/MeoAssistant/AsstMsg.h | 4 +- src/MeoAssistant/MeoAssistant.vcxproj | 4 +- src/MeoAssistant/MeoAssistant.vcxproj.filters | 4 +- src/MeoAsstGui/Helper/AsstProxy.cs | 4 +- 7 files changed, 62 insertions(+), 62 deletions(-) rename src/MeoAssistant/{Assistance.cpp => Assistant.cpp} (88%) rename src/MeoAssistant/{Assistance.h => Assistant.h} (96%) diff --git a/src/MeoAssistant/Assistance.cpp b/src/MeoAssistant/Assistant.cpp similarity index 88% rename from src/MeoAssistant/Assistance.cpp rename to src/MeoAssistant/Assistant.cpp index a4a84dbd26..5d53f734fd 100644 --- a/src/MeoAssistant/Assistance.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -1,4 +1,4 @@ -#include "Assistance.h" +#include "Assistant.h" #include #include @@ -27,7 +27,7 @@ using namespace asst; -Assistance::Assistance(std::string dirname, AsstCallback callback, void* callback_arg) +Assistant::Assistant(std::string dirname, AsstCallback callback, void* callback_arg) : m_dirname(std::move(dirname) + "\\"), m_callback(callback), m_callback_arg(callback_arg) @@ -51,11 +51,11 @@ Assistance::Assistance(std::string dirname, AsstCallback callback, void* callbac throw error; } - m_working_thread = std::thread(std::bind(&Assistance::working_proc, this)); - m_msg_thread = std::thread(std::bind(&Assistance::msg_proc, this)); + m_working_thread = std::thread(std::bind(&Assistant::working_proc, this)); + m_msg_thread = std::thread(std::bind(&Assistant::msg_proc, this)); } -Assistance::~Assistance() +Assistant::~Assistant() { LogTraceFunction; @@ -72,7 +72,7 @@ Assistance::~Assistance() } } -bool asst::Assistance::catch_default() +bool asst::Assistant::catch_default() { LogTraceFunction; @@ -87,7 +87,7 @@ bool asst::Assistance::catch_default() } } -bool Assistance::catch_emulator(const std::string& emulator_name) +bool Assistant::catch_emulator(const std::string& emulator_name) { LogTraceFunction; @@ -118,7 +118,7 @@ bool Assistance::catch_emulator(const std::string& emulator_name) return ret; } -bool asst::Assistance::catch_custom(const std::string& address) +bool asst::Assistant::catch_custom(const std::string& address) { LogTraceFunction; @@ -140,7 +140,7 @@ bool asst::Assistance::catch_custom(const std::string& address) return ret; } -bool asst::Assistance::catch_fake() +bool asst::Assistant::catch_fake() { LogTraceFunction; @@ -150,7 +150,7 @@ bool asst::Assistance::catch_fake() return true; } -bool asst::Assistance::append_fight(int mecidine, int stone, int times, bool only_append) +bool asst::Assistant::append_fight(int mecidine, int stone, int times, bool only_append) { LogTraceFunction; if (!m_inited) { @@ -175,17 +175,17 @@ bool asst::Assistance::append_fight(int mecidine, int stone, int times, bool onl return true; } -bool asst::Assistance::append_award(bool only_append) +bool asst::Assistant::append_award(bool only_append) { return append_process_task("AwardBegin", "Award"); } -bool asst::Assistance::append_visit(bool only_append) +bool asst::Assistant::append_visit(bool only_append) { return append_process_task("VisitBegin", "Visit"); } -bool asst::Assistance::append_mall(bool with_shopping, bool only_append) +bool asst::Assistant::append_mall(bool with_shopping, bool only_append) { LogTraceFunction; if (!m_inited) { @@ -211,7 +211,7 @@ bool asst::Assistance::append_mall(bool with_shopping, bool only_append) return true; } -bool Assistance::append_process_task(const std::string& task, std::string task_chain, int retry_times) +bool Assistant::append_process_task(const std::string& task, std::string task_chain, int retry_times) { LogTraceFunction; if (!m_inited) { @@ -238,7 +238,7 @@ bool Assistance::append_process_task(const std::string& task, std::string task_c return true; } -bool asst::Assistance::append_recruit(unsigned max_times, const std::vector& select_level, const std::vector& confirm_level, bool need_refresh) +bool asst::Assistant::append_recruit(unsigned max_times, const std::vector& select_level, const std::vector& confirm_level, bool need_refresh) { LogTraceFunction; if (!m_inited) { @@ -262,7 +262,7 @@ bool asst::Assistance::append_recruit(unsigned max_times, const std::vector } #ifdef LOG_TRACE -bool Assistance::append_debug() +bool Assistant::append_debug() { LogTraceFunction; if (!m_inited) { @@ -285,7 +285,7 @@ bool Assistance::append_debug() } #endif -bool Assistance::start_recruit_calc(const std::vector& select_level, bool set_time) +bool Assistant::start_recruit_calc(const std::vector& select_level, bool set_time) { LogTraceFunction; if (!m_inited) { @@ -303,7 +303,7 @@ bool Assistance::start_recruit_calc(const std::vector& select_level, bool s return start(false); } -bool asst::Assistance::append_infrast(infrast::WorkMode work_mode, const std::vector& order, const std::string& uses_of_drones, double dorm_threshold, bool only_append) +bool asst::Assistant::append_infrast(infrast::WorkMode work_mode, const std::vector& order, const std::string& uses_of_drones, double dorm_threshold, bool only_append) { LogTraceFunction; if (!m_inited) { @@ -398,7 +398,7 @@ bool asst::Assistance::append_infrast(infrast::WorkMode work_mode, const std::ve return true; } -void asst::Assistance::set_penguin_id(const std::string& id) +void asst::Assistant::set_penguin_id(const std::string& id) { auto& opt = Resrc.cfg().get_options(); if (id.empty()) { @@ -409,7 +409,7 @@ void asst::Assistance::set_penguin_id(const std::string& id) } } -bool asst::Assistance::start(bool block) +bool asst::Assistant::start(bool block) { LogTraceFunction; Log.trace("Start |", block ? "block" : "non block"); @@ -428,7 +428,7 @@ bool asst::Assistance::start(bool block) return true; } -bool Assistance::stop(bool block) +bool Assistant::stop(bool block) { LogTraceFunction; Log.trace("Stop |", block ? "block" : "non block"); @@ -447,13 +447,13 @@ bool Assistance::stop(bool block) return true; } -void Assistance::working_proc() +void Assistant::working_proc() { LogTraceFunction; std::string pre_taskchain; while (!m_thread_exit) { - //LogTraceScope("Assistance::working_proc Loop"); + //LogTraceScope("Assistant::working_proc Loop"); std::unique_lock lock(m_mutex); if (!m_thread_idle && !m_tasks_queue.empty()) { @@ -500,12 +500,12 @@ void Assistance::working_proc() } } -void Assistance::msg_proc() +void Assistant::msg_proc() { LogTraceFunction; while (!m_thread_exit) { - //LogTraceScope("Assistance::msg_proc Loop"); + //LogTraceScope("Assistant::msg_proc Loop"); std::unique_lock lock(m_msg_mutex); if (!m_msg_queue.empty()) { // 结构化绑定只能是引用,后续的pop会使引用失效,所以需要重新构造一份,这里采用了move的方式 @@ -525,11 +525,11 @@ void Assistance::msg_proc() } } -void Assistance::task_callback(AsstMsg msg, const json::value& detail, void* custom_arg) +void Assistant::task_callback(AsstMsg msg, const json::value& detail, void* custom_arg) { - Log.trace("Assistance::task_callback |", msg, detail.to_string()); + Log.trace("Assistant::task_callback |", msg, detail.to_string()); - Assistance* p_this = (Assistance*)custom_arg; + Assistant* p_this = (Assistant*)custom_arg; json::value more_detail = detail; switch (msg) { case AsstMsg::PtrIsNull: @@ -548,20 +548,20 @@ void Assistance::task_callback(AsstMsg msg, const json::value& detail, void* cus p_this->append_callback(msg, std::move(more_detail)); } -void asst::Assistance::append_callback(AsstMsg msg, json::value detail) +void asst::Assistant::append_callback(AsstMsg msg, json::value detail) { std::unique_lock lock(m_msg_mutex); m_msg_queue.emplace(msg, std::move(detail)); m_msg_condvar.notify_one(); } -void Assistance::clear_cache() +void Assistant::clear_cache() { Resrc.item().clear_drop_count(); task.clear_cache(); } -json::value asst::Assistance::organize_stage_drop(const json::value& rec) +json::value asst::Assistant::organize_stage_drop(const json::value& rec) { json::value dst = rec; auto& item = Resrc.item(); diff --git a/src/MeoAssistant/Assistance.h b/src/MeoAssistant/Assistant.h similarity index 96% rename from src/MeoAssistant/Assistance.h rename to src/MeoAssistant/Assistant.h index ddb2ca98a8..b171b3569c 100644 --- a/src/MeoAssistant/Assistance.h +++ b/src/MeoAssistant/Assistant.h @@ -23,11 +23,11 @@ namespace asst class Controller; class Identify; - class Assistance + class Assistant { public: - Assistance(std::string dirname, AsstCallback callback = nullptr, void* callback_arg = nullptr); - ~Assistance(); + Assistant(std::string dirname, AsstCallback callback = nullptr, void* callback_arg = nullptr); + ~Assistant(); // 根据配置文件,决定捕获模拟器、USB 还是远程设备 bool catch_default(); diff --git a/src/MeoAssistant/AsstCaller.cpp b/src/MeoAssistant/AsstCaller.cpp index 3199cf5109..77101cfcd2 100644 --- a/src/MeoAssistant/AsstCaller.cpp +++ b/src/MeoAssistant/AsstCaller.cpp @@ -4,7 +4,7 @@ #include -#include "Assistance.h" +#include "Assistant.h" #include "AsstDef.h" #include "AsstUtils.hpp" #include "Version.h" @@ -43,7 +43,7 @@ void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg) void* AsstCreate(const char* dirname) { try { - return new asst::Assistance(dirname); + return new asst::Assistant(dirname); } catch (...) { return nullptr; @@ -55,7 +55,7 @@ void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) try { // 创建多实例回调会有问题,有空再慢慢整 _callback = callback; - return new asst::Assistance(dirname, CallbackTrans, custom_arg); + return new asst::Assistant(dirname, CallbackTrans, custom_arg); } catch (...) { return nullptr; @@ -78,7 +78,7 @@ bool AsstCatchDefault(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->catch_default(); + return ((asst::Assistant*)p_asst)->catch_default(); } bool AsstCatchEmulator(void* p_asst) @@ -87,7 +87,7 @@ bool AsstCatchEmulator(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->catch_emulator(); + return ((asst::Assistant*)p_asst)->catch_emulator(); } bool AsstCatchCustom(void* p_asst, const char* address) @@ -96,7 +96,7 @@ bool AsstCatchCustom(void* p_asst, const char* address) return false; } - return ((asst::Assistance*)p_asst)->catch_custom(address); + return ((asst::Assistant*)p_asst)->catch_custom(address); } bool AsstCatchFake(void* p_asst) @@ -106,7 +106,7 @@ bool AsstCatchFake(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->catch_fake(); + return ((asst::Assistant*)p_asst)->catch_fake(); #else return false; #endif // LOG_TRACE @@ -117,7 +117,7 @@ bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_time if (p_asst == nullptr) { return false; } - asst::Assistance* ptr = (asst::Assistance*)p_asst; + asst::Assistant* ptr = (asst::Assistant*)p_asst; return ptr->append_fight(max_mecidine, max_stone, max_times); } @@ -128,7 +128,7 @@ bool AsstAppendAward(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->append_award(); + return ((asst::Assistant*)p_asst)->append_award(); } bool AsstAppendVisit(void* p_asst) @@ -137,7 +137,7 @@ bool AsstAppendVisit(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->append_visit(); + return ((asst::Assistant*)p_asst)->append_visit(); } bool AsstAppendMall(void* p_asst, bool with_shopping) @@ -146,7 +146,7 @@ bool AsstAppendMall(void* p_asst, bool with_shopping) return false; } - return ((asst::Assistance*)p_asst)->append_mall(with_shopping); + return ((asst::Assistant*)p_asst)->append_mall(with_shopping); } //bool AsstAppendProcessTask(void* p_asst, const char* task) @@ -155,7 +155,7 @@ bool AsstAppendMall(void* p_asst, bool with_shopping) // return false; // } // -// return ((asst::Assistance*)p_asst)->append_process_task(task); +// return ((asst::Assistant*)p_asst)->append_process_task(task); //} bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time) @@ -165,7 +165,7 @@ bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_l } std::vector level_vector; level_vector.assign(select_level, select_level + required_len); - return ((asst::Assistance*)p_asst)->start_recruit_calc(level_vector, set_time); + return ((asst::Assistant*)p_asst)->start_recruit_calc(level_vector, set_time); } bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) @@ -176,7 +176,7 @@ bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int orde std::vector order_vector; order_vector.assign(order, order + order_size); - return ((asst::Assistance*)p_asst)-> + return ((asst::Assistant*)p_asst)-> append_infrast( static_cast(work_mode), order_vector, @@ -194,7 +194,7 @@ bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], in std::vector confirm_vector; confirm_vector.assign(confirm_level, confirm_level + confirm_len); - return ((asst::Assistance*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh); + return ((asst::Assistant*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh); } bool AsstStart(void* p_asst) @@ -203,7 +203,7 @@ bool AsstStart(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->start(); + return ((asst::Assistant*)p_asst)->start(); } bool AsstStop(void* p_asst) @@ -212,7 +212,7 @@ bool AsstStop(void* p_asst) return false; } - return ((asst::Assistance*)p_asst)->stop(); + return ((asst::Assistant*)p_asst)->stop(); } bool AsstSetPenguinId(void* p_asst, const char* id) @@ -220,7 +220,7 @@ bool AsstSetPenguinId(void* p_asst, const char* id) if (p_asst == nullptr) { return false; } - auto ptr = (asst::Assistance*)p_asst; + auto ptr = (asst::Assistant*)p_asst; ptr->set_penguin_id(id); return true; } @@ -231,7 +231,7 @@ bool AsstSetPenguinId(void* p_asst, const char* id) // return false; // } // -// return ((asst::Assistance*)p_asst)->set_param(type, param, value); +// return ((asst::Assistant*)p_asst)->set_param(type, param, value); //} const char* AsstGetVersion() @@ -245,7 +245,7 @@ bool AsstAppendDebug(void* p_asst) return false; } #if LOG_TRACE - return ((asst::Assistance*)p_asst)->append_debug(); + return ((asst::Assistant*)p_asst)->append_debug(); #else return false; #endif // LOG_TRACE diff --git a/src/MeoAssistant/AsstMsg.h b/src/MeoAssistant/AsstMsg.h index 8e6dc1baa3..bb92ee2466 100644 --- a/src/MeoAssistant/AsstMsg.h +++ b/src/MeoAssistant/AsstMsg.h @@ -24,8 +24,8 @@ namespace asst ReachedLimit, // 单个原子任务达到次数上限 ReadyToSleep, // 准备开始睡眠 EndOfSleep, // 睡眠结束 - AppendProcessTask, // [已弃用] 新增流程任务,Assistance内部消息,外部不需要处理 - AppendTask, // [已弃用] 新增任务,Assistance内部消息,外部不需要处理 + AppendProcessTask, // [已弃用] 新增流程任务,Assistant内部消息,外部不需要处理 + AppendTask, // [已弃用] 新增任务,Assistant内部消息,外部不需要处理 TaskCompleted, // 单个原子任务完成 PrintWindow, // 截图消息 ProcessTaskStopAction, // 流程任务执行到了Stop的动作 diff --git a/src/MeoAssistant/MeoAssistant.vcxproj b/src/MeoAssistant/MeoAssistant.vcxproj index 62df7f654e..d278b1b0e9 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj +++ b/src/MeoAssistant/MeoAssistant.vcxproj @@ -17,7 +17,7 @@ - + @@ -93,7 +93,7 @@ - + diff --git a/src/MeoAssistant/MeoAssistant.vcxproj.filters b/src/MeoAssistant/MeoAssistant.vcxproj.filters index 098f1f536b..cd438ecc42 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj.filters +++ b/src/MeoAssistant/MeoAssistant.vcxproj.filters @@ -66,7 +66,7 @@ 头文件 - + 头文件 @@ -221,7 +221,7 @@ 源文件 - + 源文件 diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index c091e40b82..29a3c2bf9b 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -401,8 +401,8 @@ namespace MeoAsstGui ReachedLimit, // 单个原子任务达到次数上限 ReadyToSleep, // 准备开始睡眠 EndOfSleep, // 睡眠结束 - AppendProcessTask, // 新增流程任务,Assistance内部消息,外部不需要处理 - AppendTask, // 新增任务,Assistance内部消息,外部不需要处理 + AppendProcessTask, // 新增流程任务,Assistant内部消息,外部不需要处理 + AppendTask, // 新增任务,Assistant内部消息,外部不需要处理 TaskCompleted, // 单个原子任务完成 PrintWindow, // 截图消息 ProcessTaskStopAction, // 流程任务执行到了Stop的动作 From e1334f377511e6bafadad5961b9680da718e8ba5 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 15 Dec 2021 01:42:56 +0800 Subject: [PATCH 12/13] =?UTF-8?q?chore.=E4=BF=AE=E6=94=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/AsstCaller.h | 44 +++++++++-------- src/MeoAssistant/AsstCaller.cpp | 86 ++++++++++++++++----------------- tools/TestCaller/main.cpp | 2 +- 3 files changed, 67 insertions(+), 65 deletions(-) diff --git a/include/AsstCaller.h b/include/AsstCaller.h index 24bad509b6..9d86b0b3bc 100644 --- a/include/AsstCaller.h +++ b/include/AsstCaller.h @@ -2,35 +2,39 @@ #include "AsstPort.h" +namespace asst { + class Assistant; +} + #ifdef __cplusplus extern "C" { #endif typedef void (ASST_CALL* AsstCallback)(int msg, const char* detail_json, void* custom_arg); - ASSTAPI_PORT void* ASST_CALL AsstCreate(const char* dirname); - ASSTAPI_PORT void* ASST_CALL AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg); - void ASSTAPI AsstDestroy(void* p_asst); + ASSTAPI_PORT asst::Assistant* ASST_CALL AsstCreate(const char* dirname); + ASSTAPI_PORT asst::Assistant* ASST_CALL AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg); + void ASSTAPI AsstDestroy(asst::Assistant* p_asst); - bool ASSTAPI AsstCatchDefault(void* p_asst); - bool ASSTAPI AsstCatchEmulator(void* p_asst); - bool ASSTAPI AsstCatchCustom(void* p_asst, const char* address); - bool ASSTAPI AsstCatchFake(void* p_asst); + bool ASSTAPI AsstCatchDefault(asst::Assistant* p_asst); + bool ASSTAPI AsstCatchEmulator(asst::Assistant* p_asst); + bool ASSTAPI AsstCatchCustom(asst::Assistant* p_asst, const char* address); + bool ASSTAPI AsstCatchFake(asst::Assistant* p_asst); - bool ASSTAPI AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times); - bool ASSTAPI AsstAppendAward(void* p_asst); - bool ASSTAPI AsstAppendVisit(void* p_asst); - bool ASSTAPI AsstAppendMall(void* p_asst, bool with_shopping); - //bool ASSTAPI AsstAppendProcessTask(void* p_asst, const char* task); - bool ASSTAPI AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold); - bool ASSTAPI AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh); - bool ASSTAPI AsstAppendDebug(void* p_asst); + bool ASSTAPI AsstAppendFight(asst::Assistant* p_asst, int max_mecidine, int max_stone, int max_times); + bool ASSTAPI AsstAppendAward(asst::Assistant* p_asst); + bool ASSTAPI AsstAppendVisit(asst::Assistant* p_asst); + bool ASSTAPI AsstAppendMall(asst::Assistant* p_asst, bool with_shopping); + //bool ASSTAPI AsstAppendProcessTask(asst::Assistant* p_asst, const char* task); + bool ASSTAPI AsstAppendInfrast(asst::Assistant* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold); + bool ASSTAPI AsstAppendRecruit(asst::Assistant* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh); + bool ASSTAPI AsstAppendDebug(asst::Assistant* p_asst); - bool ASSTAPI AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time); - bool ASSTAPI AsstStart(void* p_asst); - bool ASSTAPI AsstStop(void* p_asst); + bool ASSTAPI AsstStartRecruitCalc(asst::Assistant* p_asst, const int select_level[], int required_len, bool set_time); + bool ASSTAPI AsstStart(asst::Assistant* p_asst); + bool ASSTAPI AsstStop(asst::Assistant* p_asst); - bool ASSTAPI AsstSetPenguinId(void* p_asst, const char* id); - //bool ASSTAPI AsstSetParam(void* p_asst, const char* type, const char* param, const char* value); + bool ASSTAPI AsstSetPenguinId(asst::Assistant* p_asst, const char* id); + //bool ASSTAPI AsstSetParam(asst::Assistant* p_asst, const char* type, const char* param, const char* value); ASSTAPI_PORT const char* ASST_CALL AsstGetVersion(); #ifdef __cplusplus diff --git a/src/MeoAssistant/AsstCaller.cpp b/src/MeoAssistant/AsstCaller.cpp index 77101cfcd2..649a5e3c7d 100644 --- a/src/MeoAssistant/AsstCaller.cpp +++ b/src/MeoAssistant/AsstCaller.cpp @@ -40,7 +40,7 @@ void CallbackTrans(asst::AsstMsg msg, const json::value& json, void* custom_arg) _callback(static_cast(msg), asst::utils::utf8_to_gbk(json.to_string()).c_str(), custom_arg); } -void* AsstCreate(const char* dirname) +asst::Assistant* AsstCreate(const char* dirname) { try { return new asst::Assistant(dirname); @@ -50,7 +50,7 @@ void* AsstCreate(const char* dirname) } } -void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) +asst::Assistant* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) { try { // 创建多实例回调会有问题,有空再慢慢整 @@ -62,7 +62,7 @@ void* AsstCreateEx(const char* dirname, AsstCallback callback, void* custom_arg) } } -void AsstDestroy(void* p_asst) +void AsstDestroy(asst::Assistant* p_asst) { if (p_asst == nullptr) { return; @@ -72,7 +72,7 @@ void AsstDestroy(void* p_asst) p_asst = nullptr; } -bool AsstCatchDefault(void* p_asst) +bool AsstCatchDefault(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; @@ -81,7 +81,7 @@ bool AsstCatchDefault(void* p_asst) return ((asst::Assistant*)p_asst)->catch_default(); } -bool AsstCatchEmulator(void* p_asst) +bool AsstCatchEmulator(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; @@ -90,7 +90,7 @@ bool AsstCatchEmulator(void* p_asst) return ((asst::Assistant*)p_asst)->catch_emulator(); } -bool AsstCatchCustom(void* p_asst, const char* address) +bool AsstCatchCustom(asst::Assistant* p_asst, const char* address) { if (p_asst == nullptr) { return false; @@ -99,76 +99,75 @@ bool AsstCatchCustom(void* p_asst, const char* address) return ((asst::Assistant*)p_asst)->catch_custom(address); } -bool AsstCatchFake(void* p_asst) +bool AsstCatchFake(asst::Assistant* p_asst) { #ifdef LOG_TRACE if (p_asst == nullptr) { return false; } - return ((asst::Assistant*)p_asst)->catch_fake(); + return p_asst->catch_fake(); #else return false; #endif // LOG_TRACE } -bool AsstAppendFight(void* p_asst, int max_mecidine, int max_stone, int max_times) -{ - if (p_asst == nullptr) { - return false; - } - asst::Assistant* ptr = (asst::Assistant*)p_asst; - - return ptr->append_fight(max_mecidine, max_stone, max_times); -} - -bool AsstAppendAward(void* p_asst) +bool AsstAppendFight(asst::Assistant* p_asst, int max_mecidine, int max_stone, int max_times) { if (p_asst == nullptr) { return false; } - return ((asst::Assistant*)p_asst)->append_award(); + return p_asst->append_fight(max_mecidine, max_stone, max_times); } -bool AsstAppendVisit(void* p_asst) +bool AsstAppendAward(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; } - return ((asst::Assistant*)p_asst)->append_visit(); + return p_asst->append_award(); } -bool AsstAppendMall(void* p_asst, bool with_shopping) +bool AsstAppendVisit(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; } - return ((asst::Assistant*)p_asst)->append_mall(with_shopping); + return p_asst->append_visit(); } -//bool AsstAppendProcessTask(void* p_asst, const char* task) +bool AsstAppendMall(asst::Assistant* p_asst, bool with_shopping) +{ + if (p_asst == nullptr) { + return false; + } + + return p_asst->append_mall(with_shopping); +} + +//bool AsstAppendProcessTask(asst::Assistant* p_asst, const char* task) //{ // if (p_asst == nullptr) { // return false; // } // -// return ((asst::Assistant*)p_asst)->append_process_task(task); +// return p_asst->append_process_task(task); //} -bool AsstStartRecruitCalc(void* p_asst, const int select_level[], int required_len, bool set_time) +bool AsstStartRecruitCalc(asst::Assistant* p_asst, const int select_level[], int required_len, bool set_time) { if (p_asst == nullptr) { return false; } std::vector level_vector; level_vector.assign(select_level, select_level + required_len); - return ((asst::Assistant*)p_asst)->start_recruit_calc(level_vector, set_time); + return p_asst->start_recruit_calc(level_vector, set_time); } -bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) +bool AsstAppendInfrast(asst::Assistant* p_asst, int work_mode, const char** order, int order_size, const char* uses_of_drones, double dorm_threshold) { if (p_asst == nullptr) { return false; @@ -176,15 +175,14 @@ bool AsstAppendInfrast(void* p_asst, int work_mode, const char** order, int orde std::vector order_vector; order_vector.assign(order, order + order_size); - return ((asst::Assistant*)p_asst)-> - append_infrast( + return p_asst->append_infrast( static_cast(work_mode), order_vector, uses_of_drones, dorm_threshold); } -bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh) +bool AsstAppendRecruit(asst::Assistant* p_asst, int max_times, const int select_level[], int select_len, const int confirm_level[], int confirm_len, bool need_refresh) { if (p_asst == nullptr) { return false; @@ -194,44 +192,44 @@ bool AsstAppendRecruit(void* p_asst, int max_times, const int select_level[], in std::vector confirm_vector; confirm_vector.assign(confirm_level, confirm_level + confirm_len); - return ((asst::Assistant*)p_asst)->append_recruit(max_times, required_vector, confirm_vector, need_refresh); + return p_asst->append_recruit(max_times, required_vector, confirm_vector, need_refresh); } -bool AsstStart(void* p_asst) +bool AsstStart(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; } - return ((asst::Assistant*)p_asst)->start(); + return p_asst->start(); } -bool AsstStop(void* p_asst) +bool AsstStop(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; } - return ((asst::Assistant*)p_asst)->stop(); + return p_asst->stop(); } -bool AsstSetPenguinId(void* p_asst, const char* id) +bool AsstSetPenguinId(asst::Assistant* p_asst, const char* id) { if (p_asst == nullptr) { return false; } - auto ptr = (asst::Assistant*)p_asst; - ptr->set_penguin_id(id); + + p_asst->set_penguin_id(id); return true; } -//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value) +//bool AsstSetParam(asst::Assistant* p_asst, const char* type, const char* param, const char* value) //{ // if (p_asst == nullptr) { // return false; // } // -// return ((asst::Assistant*)p_asst)->set_param(type, param, value); +// return p_asst->set_param(type, param, value); //} const char* AsstGetVersion() @@ -239,13 +237,13 @@ const char* AsstGetVersion() return asst::Version; } -bool AsstAppendDebug(void* p_asst) +bool AsstAppendDebug(asst::Assistant* p_asst) { if (p_asst == nullptr) { return false; } #if LOG_TRACE - return ((asst::Assistant*)p_asst)->append_debug(); + return p_asst->append_debug(); #else return false; #endif // LOG_TRACE diff --git a/tools/TestCaller/main.cpp b/tools/TestCaller/main.cpp index 98f27a1743..8055c53beb 100644 --- a/tools/TestCaller/main.cpp +++ b/tools/TestCaller/main.cpp @@ -16,7 +16,7 @@ const char* get_cur_dir() int main(int argc, char** argv) { - void* ptr = AsstCreate(get_cur_dir()); + auto ptr = AsstCreate(get_cur_dir()); auto ret = AsstCatchEmulator(ptr); if (!ret) { getchar(); From f473c1cb99fe73e0ded820250e3b3046d476945b Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 15 Dec 2021 11:32:15 +0800 Subject: [PATCH 13/13] =?UTF-8?q?chore.=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=EF=BC=8C=E4=BF=AE=E6=94=B9cmake=E4=BA=A7?= =?UTF-8?q?=E7=89=A9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++-- src/MeoAssistant/Version.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b2a530057..0d5c9f7c35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,11 +14,11 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set(CMAKE_CXX_STANDARD 17) -add_library(MeoAssistant_LIB SHARED ${SRC}) +add_library(MeoAssistant SHARED ${SRC}) find_library(Opencv_LIB NAMES opencv_world453 PATHS 3rdparty/lib) find_library(PaddleOCR_LIB NAMES ppocr PATHS 3rdparty/lib) find_library(Penguin_LIB NAMES penguin-stats-recognize PATHS 3rdparty/lib) find_library(MeoJson_LIB NAMES libmeojson PATHS 3rdparty/lib) -target_link_libraries(MeoAssistant_LIB ${Opencv_LIB} ${PaddleOCR_LIB} ${Penguin_LIB} ${MeoJson_LIB}) +target_link_libraries(MeoAssistant ${Opencv_LIB} ${PaddleOCR_LIB} ${Penguin_LIB} ${MeoJson_LIB}) diff --git a/src/MeoAssistant/Version.h b/src/MeoAssistant/Version.h index 8ed9c43a27..bbcc4bb552 100644 --- a/src/MeoAssistant/Version.h +++ b/src/MeoAssistant/Version.h @@ -2,5 +2,5 @@ namespace asst { - constexpr static const char* Version = "v2.4.0"; + constexpr static const char* Version = "v2.4.1"; }