diff --git a/include/MaaFramework/MaaDef.h b/include/MaaFramework/MaaDef.h index e18dcabc0..50ba52c30 100644 --- a/include/MaaFramework/MaaDef.h +++ b/include/MaaFramework/MaaDef.h @@ -94,6 +94,11 @@ enum MaaGlobalOptionEnum /// /// value: bool, eg: true; val_size: sizeof(bool) MaaGlobalOption_ShowHitDraw = 5, + + /// Whether to callback debug message + /// + /// value: bool, eg: true; val_size: sizeof(bool) + MaaGlobalOption_DebugMessage = 6, }; typedef MaaOption MaaResOption; diff --git a/include/MaaFramework/MaaMsg.h b/include/MaaFramework/MaaMsg.h index 164d378c2..213cc89be 100644 --- a/include/MaaFramework/MaaMsg.h +++ b/include/MaaFramework/MaaMsg.h @@ -154,4 +154,26 @@ #define MaaMsg_Task_Focus_Runout ("Task.Focus.Runout") #define MaaMsg_Task_Focus_Completed ("Task.Focus.Completed") /// @} + +/** + * @{ + * @brief Message for debug. + * + * payload: { + * id: number, + * entry: string, + * name: string, + * uuid: string, + * hash: string, + * recognition: object, + * run_times: number, + * last_time: string, + * status: string + * } + */ +#define MaaMsg_Task_Debug_Hit ("Task.Debug.Hit") +#define MaaMsg_Task_Debug_Runout ("Task.Debug.Runout") +#define MaaMsg_Task_Debug_Completed ("Task.Debug.Completed") +/// @} + /** @} */ diff --git a/source/MaaFramework/Option/GlobalOptionMgr.cpp b/source/MaaFramework/Option/GlobalOptionMgr.cpp index 83418470b..83cbf9b20 100644 --- a/source/MaaFramework/Option/GlobalOptionMgr.cpp +++ b/source/MaaFramework/Option/GlobalOptionMgr.cpp @@ -23,6 +23,8 @@ bool GlobalOptionMgr::set_option( return set_stdout_level(value, val_size); case MaaGlobalOption_ShowHitDraw: return set_show_hit_draw(value, val_size); + case MaaGlobalOption_DebugMessage: + return set_debug_message(value, val_size); default: LogError << "Unknown key" << VAR(key) << VAR(value); return false; @@ -109,4 +111,20 @@ bool GlobalOptionMgr::set_stdout_level(MaaOptionValue value, MaaOptionValueSize return true; } -MAA_NS_END \ No newline at end of file +bool GlobalOptionMgr::set_debug_message(MaaOptionValue value, MaaOptionValueSize val_size) +{ + LogFunc; + + if (val_size != sizeof(bool)) { + LogError << "Invalid value size" << VAR(val_size); + return false; + } + + debug_message_ = *reinterpret_cast(value); + + LogInfo << "Set debug message" << VAR(debug_message_); + + return true; +} + +MAA_NS_END diff --git a/source/MaaFramework/Option/GlobalOptionMgr.h b/source/MaaFramework/Option/GlobalOptionMgr.h index 512aed8fb..7143eb804 100644 --- a/source/MaaFramework/Option/GlobalOptionMgr.h +++ b/source/MaaFramework/Option/GlobalOptionMgr.h @@ -23,6 +23,7 @@ class GlobalOptionMgr : public SingletonHolder bool save_draw() const { return save_draw_; } bool show_hit_draw() const { return show_hit_draw_; } bool recording() const { return recording_; } + bool debug_message() const { return debug_message_; } private: GlobalOptionMgr() = default; @@ -33,12 +34,14 @@ class GlobalOptionMgr : public SingletonHolder bool set_show_hit_draw(MaaOptionValue value, MaaOptionValueSize val_size); bool set_recording(MaaOptionValue value, MaaOptionValueSize val_size); bool set_stdout_level(MaaOptionValue value, MaaOptionValueSize val_size); + bool set_debug_message(MaaOptionValue value, MaaOptionValueSize val_size); private: std::filesystem::path log_dir_; bool save_draw_ = false; bool show_hit_draw_ = false; bool recording_ = false; + bool debug_message_ = false; }; MAA_NS_END diff --git a/source/MaaFramework/Resource/PipelineResMgr.h b/source/MaaFramework/Resource/PipelineResMgr.h index 394c4f77c..fd44191ed 100644 --- a/source/MaaFramework/Resource/PipelineResMgr.h +++ b/source/MaaFramework/Resource/PipelineResMgr.h @@ -46,9 +46,10 @@ class PipelineResMgr : public NonCopyable Recognition::Param& out_param, const Recognition::Type& default_type, const Recognition::Param& default_param); - // static bool parse_direct_hit_param(const json::value& input, MAA_VISION_NS::DirectHitParam& - // output, - // const MAA_VISION_NS::DirectHitParam& default_value); + // static bool parse_direct_hit_param( + // const json::value& input, + // MAA_VISION_NS::DirectHitParam& output, + // const MAA_VISION_NS::DirectHitParam& default_value); static bool parse_template_matcher_param( const json::value& input, MAA_VISION_NS::TemplateMatcherParam& output, diff --git a/source/MaaFramework/Task/PipelineTask.cpp b/source/MaaFramework/Task/PipelineTask.cpp index d8832bd43..c169455cd 100644 --- a/source/MaaFramework/Task/PipelineTask.cpp +++ b/source/MaaFramework/Task/PipelineTask.cpp @@ -5,6 +5,7 @@ #include "Controller/ControllerAgent.h" #include "Instance/InstanceStatus.h" #include "MaaFramework/MaaMsg.h" +#include "Option/GlobalOptionMgr.h" #include "Resource/ResourceMgr.h" #include "Task/CustomAction.h" #include "Utils/ImageIo.h" @@ -181,6 +182,9 @@ PipelineTask::RunningResult PipelineTask::run_task(const HitResult& hits) if (hits.task_data.focus) { notify(MaaMsg_Task_Focus_Hit, detail); } + if (debug_mode()) { + notify(MaaMsg_Task_Debug_Hit, detail); + } if (hits.task_data.times_limit <= run_times) { LogInfo << "Task runout:" << name; @@ -190,6 +194,9 @@ PipelineTask::RunningResult PipelineTask::run_task(const HitResult& hits) if (hits.task_data.focus) { notify(MaaMsg_Task_Focus_Runout, detail); } + if (debug_mode()) { + notify(MaaMsg_Task_Debug_Runout, detail); + } return RunningResult::Runout; } @@ -204,8 +211,16 @@ PipelineTask::RunningResult PipelineTask::run_task(const HitResult& hits) if (hits.task_data.focus) { notify(MaaMsg_Task_Focus_Completed, detail); } + if (debug_mode()) { + notify(MaaMsg_Task_Debug_Completed, detail); + } return ret ? RunningResult::Success : RunningResult::InternalError; } -MAA_TASK_NS_END \ No newline at end of file +bool PipelineTask::debug_mode() const +{ + return GlobalOptionMgr::get_instance().debug_message(); +} + +MAA_TASK_NS_END diff --git a/source/MaaFramework/Task/PipelineTask.h b/source/MaaFramework/Task/PipelineTask.h index 72e554b9d..b240b5e2b 100644 --- a/source/MaaFramework/Task/PipelineTask.h +++ b/source/MaaFramework/Task/PipelineTask.h @@ -74,6 +74,7 @@ class PipelineTask : public MaaInstanceSink } bool need_to_stop() const { return need_to_stop_; } + bool debug_mode() const; private: bool need_to_stop_ = false;