diff --git a/assets/resource/pipeline/combat/combat.json b/assets/resource/pipeline/combat/combat.json new file mode 100644 index 0000000..8cd4f6c --- /dev/null +++ b/assets/resource/pipeline/combat/combat.json @@ -0,0 +1,4 @@ +{ + "$schema": "../../pipeline.schema.json", + "Combating": {} +} \ No newline at end of file diff --git a/assets/resource/pipeline/combat/universal_mirage_combat_generic.json b/assets/resource/pipeline/combat/universal_mirage_combat_generic.json index de9e435..6dfac94 100644 --- a/assets/resource/pipeline/combat/universal_mirage_combat_generic.json +++ b/assets/resource/pipeline/combat/universal_mirage_combat_generic.json @@ -29,14 +29,8 @@ ] }, "UniversalMirageCombatGenericPreheat": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 500, @@ -47,14 +41,8 @@ ] }, "UniversalMirageCombatGeneric_001": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Backward", "pre_delay": 0, @@ -65,14 +53,8 @@ ] }, "UniversalMirageCombatGeneric_002": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Forward", "pre_delay": 0, @@ -83,14 +65,8 @@ ] }, "UniversalMirageCombatGeneric_003": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Left", "pre_delay": 0, @@ -101,14 +77,8 @@ ] }, "UniversalMirageCombatGeneric_004": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Right", "pre_delay": 0, @@ -119,14 +89,8 @@ ] }, "UniversalMirageCombatGeneric_005": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Evade", "pre_delay": 0, @@ -137,14 +101,8 @@ ] }, "UniversalMirageCombatGeneric_006": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -155,14 +113,8 @@ ] }, "UniversalMirageCombatGeneric_007": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -173,14 +125,8 @@ ] }, "UniversalMirageCombatGeneric_008": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -191,14 +137,8 @@ ] }, "UniversalMirageCombatGeneric_009": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -209,14 +149,8 @@ ] }, "UniversalMirageCombatGeneric_010": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -227,14 +161,8 @@ ] }, "UniversalMirageCombatGeneric_011": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATKCharge", "pre_delay": 0, @@ -245,14 +173,8 @@ ] }, "UniversalMirageCombatGeneric_012": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Evade", "pre_delay": 0, @@ -263,14 +185,8 @@ ] }, "UniversalMirageCombatGeneric_013": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -281,14 +197,8 @@ ] }, "UniversalMirageCombatGeneric_014": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "WeaponSkill", "pre_delay": 0, @@ -299,14 +209,8 @@ ] }, "UniversalMirageCombatGeneric_015": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -317,14 +221,8 @@ ] }, "UniversalMirageCombatGeneric_016": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -335,14 +233,8 @@ ] }, "UniversalMirageCombatGeneric_017": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -353,14 +245,8 @@ ] }, "UniversalMirageCombatGeneric_018": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -371,14 +257,8 @@ ] }, "UniversalMirageCombatGeneric_019": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -389,14 +269,8 @@ ] }, "UniversalMirageCombatGeneric_020": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATKCharge", "pre_delay": 0, @@ -407,14 +281,8 @@ ] }, "UniversalMirageCombatGeneric_021": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -425,14 +293,8 @@ ] }, "UniversalMirageCombatGeneric_022": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Ultimate", "pre_delay": 0, @@ -443,14 +305,8 @@ ] }, "UniversalMirageCombatGeneric_023": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -461,14 +317,8 @@ ] }, "UniversalMirageCombatGeneric_024": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "ExtraSkill", "pre_delay": 0, @@ -479,14 +329,8 @@ ] }, "UniversalMirageCombatGeneric_025": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -497,14 +341,8 @@ ] }, "UniversalMirageCombatGeneric_026": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Evade", "pre_delay": 0, @@ -515,14 +353,8 @@ ] }, "UniversalMirageCombatGeneric_027": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -533,14 +365,8 @@ ] }, "UniversalMirageCombatGeneric_028": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "ELFSkill", "pre_delay": 0, @@ -551,14 +377,8 @@ ] }, "UniversalMirageCombatGeneric_029": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -569,14 +389,8 @@ ] }, "UniversalMirageCombatGeneric_030": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "UltimateCharge", "pre_delay": 0, @@ -587,14 +401,8 @@ ] }, "UniversalMirageCombatGeneric_031": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -605,14 +413,8 @@ ] }, "UniversalMirageCombatGeneric_032": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -623,14 +425,8 @@ ] }, "UniversalMirageCombatGeneric_033": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -641,14 +437,8 @@ ] }, "UniversalMirageCombatGeneric_034": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -659,14 +449,8 @@ ] }, "UniversalMirageCombatGeneric_035": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, @@ -677,14 +461,8 @@ ] }, "UniversalMirageCombatGeneric_036": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATKCharge", "pre_delay": 0, @@ -695,14 +473,8 @@ ] }, "UniversalMirageCombatGeneric_037": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "Evade", "pre_delay": 0, @@ -713,14 +485,8 @@ ] }, "UniversalMirageCombatGeneric_038": { - "recognition": "TemplateMatch", - "template": "Combat/StopCombat.png", - "roi": [ - 0, - 0, - 136, - 140 - ], + "recognition": "Custom", + "custom_recognizer": "Combating", "action": "Custom", "custom_action": "BasicATK", "pre_delay": 0, diff --git a/source/cli/CMakeLists.txt b/source/cli/CMakeLists.txt index 4e2c4e0..1e5e088 100644 --- a/source/cli/CMakeLists.txt +++ b/source/cli/CMakeLists.txt @@ -20,6 +20,13 @@ add_executable(MAABH3_CLI CustomAction/CustomActionRegistry.h CustomAction/RandomPointGenerator.h CustomAction/RandomPointGenerator.cpp + CustomRecognizer/CustomRecognizer.cpp + CustomRecognizer/CustomRecognizer.h + CustomRecognizer/CustomRecognizerRegistrar.cpp + CustomRecognizer/CustomRecognizerRegistrar.h + CustomRecognizer/CustomRecognizerRegistry.h + CustomRecognizer/CombatRecognizer.h + CustomRecognizer/CombatRecognizer.cpp ) target_link_libraries(MAABH3_CLI PRIVATE MaaFramework MaaToolKit) diff --git a/source/cli/CustomRecognizer/CombatRecognizer.cpp b/source/cli/CustomRecognizer/CombatRecognizer.cpp new file mode 100644 index 0000000..e8f14f8 --- /dev/null +++ b/source/cli/CustomRecognizer/CombatRecognizer.cpp @@ -0,0 +1,19 @@ +#include "CombatRecognizer.h" + +MaaBool combat_combating(MaaSyncContextHandle sync_context, const MaaImageBufferHandle image, + [[maybe_unused]] MaaStringView task_name, + [[maybe_unused]] MaaStringView custom_recognition_param, + [[maybe_unused]] MaaTransparentArg recognizer_arg, MaaRectHandle out_box, + MaaStringBufferHandle detail_buff) +{ + json::object combating { { "recognition", "TemplateMatch" }, + { "template", "Combat/StopCombat.png" }, + { "roi", json::array { 0, 0, 136, 140 } } }; + json::value diff_task { { "Combating", combating } }; + json::value task_param { { "diff_task", diff_task } }; + std::string task_param_str = task_param.to_string(); + + MaaBool result = + MaaSyncContextRunRecognizer(sync_context, image, "Combating", task_param_str.c_str(), out_box, detail_buff); + return result; +} \ No newline at end of file diff --git a/source/cli/CustomRecognizer/CombatRecognizer.h b/source/cli/CustomRecognizer/CombatRecognizer.h new file mode 100644 index 0000000..0835646 --- /dev/null +++ b/source/cli/CustomRecognizer/CombatRecognizer.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#include "MaaFramework/Task/MaaSyncContext.h" +#include "MaaFramework/Utility/MaaBuffer.h" +#include "../meojson/json.hpp" + +MaaBool combat_combating(MaaSyncContextHandle sync_context, const MaaImageBufferHandle image, MaaStringView task_name, + MaaStringView custom_recognition_param, MaaTransparentArg recognizer_arg, MaaRectHandle out_box, + MaaStringBufferHandle detail_buff); \ No newline at end of file diff --git a/source/cli/CustomRecognizer/CustomRecognizer.cpp b/source/cli/CustomRecognizer/CustomRecognizer.cpp new file mode 100644 index 0000000..a2e5756 --- /dev/null +++ b/source/cli/CustomRecognizer/CustomRecognizer.cpp @@ -0,0 +1,22 @@ +#include "CustomRecognizer.h" + +CustomRecognizer::CustomRecognizer( + const std::string& recognizer_name, + MaaBool (*recognizer_analyze)(MaaSyncContextHandle sync_context, const MaaImageBufferHandle image, + MaaStringView task_name, MaaStringView custom_recognition_param, + MaaTransparentArg recognizer_arg, MaaRectHandle out_box, + MaaStringBufferHandle detail_buff)) + : name_(recognizer_name) +{ + custom_recognizer_.analyze = recognizer_analyze; +} + +std::string CustomRecognizer::get_name() const +{ + return name_; +} + +MaaCustomRecognizerAPI CustomRecognizer::get_custom_recognizer() const +{ + return custom_recognizer_; +} \ No newline at end of file diff --git a/source/cli/CustomRecognizer/CustomRecognizer.h b/source/cli/CustomRecognizer/CustomRecognizer.h new file mode 100644 index 0000000..5c56939 --- /dev/null +++ b/source/cli/CustomRecognizer/CustomRecognizer.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "MaaFramework/Task/MaaCustomRecognizer.h" + +class CustomRecognizer +{ +public: + CustomRecognizer(const std::string& recognizer_name, + MaaBool (*recognizer_analyze)(MaaSyncContextHandle sync_context, const MaaImageBufferHandle image, + MaaStringView task_name, MaaStringView custom_recognition_param, + MaaTransparentArg recognizer_arg, MaaRectHandle out_box, + MaaStringBufferHandle detail_buff)); + ~CustomRecognizer() = default; + +public: + std::string get_name() const; + MaaCustomRecognizerAPI get_custom_recognizer() const; + +private: + std::string name_; + MaaCustomRecognizerAPI custom_recognizer_; +}; \ No newline at end of file diff --git a/source/cli/CustomRecognizer/CustomRecognizerRegistrar.cpp b/source/cli/CustomRecognizer/CustomRecognizerRegistrar.cpp new file mode 100644 index 0000000..c1d2099 --- /dev/null +++ b/source/cli/CustomRecognizer/CustomRecognizerRegistrar.cpp @@ -0,0 +1,21 @@ +#include "CustomRecognizerRegistrar.h" + +void CustomRecognizerRegistrar::add_recognizer( + const std::string& name, + MaaBool (*recognizer_analyze)(MaaSyncContextHandle sync_context, const MaaImageBufferHandle image, + MaaStringView task_name, MaaStringView custom_recognition_param, + MaaTransparentArg recognizer_arg, MaaRectHandle out_box, + MaaStringBufferHandle detail_buff)) +{ + recognizers_.emplace_back(name, recognizer_analyze); +} + +void CustomRecognizerRegistrar::register_recognizers(MaaInstanceHandle maa_handle) +{ + for (const auto& recognizer : recognizers_) { + std::shared_ptr custom_recognizer = + std::make_shared(recognizer.get_custom_recognizer()); + custom_recognizers_.push_back(custom_recognizer); + MaaRegisterCustomRecognizer(maa_handle, recognizer.get_name().c_str(), custom_recognizer.get(), nullptr); + } +} \ No newline at end of file diff --git a/source/cli/CustomRecognizer/CustomRecognizerRegistrar.h b/source/cli/CustomRecognizer/CustomRecognizerRegistrar.h new file mode 100644 index 0000000..d06a99c --- /dev/null +++ b/source/cli/CustomRecognizer/CustomRecognizerRegistrar.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +#include "CustomRecognizer.h" +#include "MaaFramework/Instance/MaaInstance.h" +#include "MaaFramework/Task/MaaCustomRecognizer.h" + +class CustomRecognizerRegistrar +{ +public: + CustomRecognizerRegistrar() = default; + ~CustomRecognizerRegistrar() = default; + +public: + void add_recognizer(const std::string& name, + MaaBool (*recognizer_analyze)(MaaSyncContextHandle sync_context, + const MaaImageBufferHandle image, MaaStringView task_name, + MaaStringView custom_recognition_param, + MaaTransparentArg recognizer_arg, MaaRectHandle out_box, + MaaStringBufferHandle detail_buff)); + void register_recognizers(MaaInstanceHandle maa_handle); + +private: + std::vector recognizers_; + std::vector> custom_recognizers_; +}; \ No newline at end of file diff --git a/source/cli/CustomRecognizer/CustomRecognizerRegistry.h b/source/cli/CustomRecognizer/CustomRecognizerRegistry.h new file mode 100644 index 0000000..fd8c1b8 --- /dev/null +++ b/source/cli/CustomRecognizer/CustomRecognizerRegistry.h @@ -0,0 +1,16 @@ +#pragma once + +#include "CustomRecognizerRegistrar.h" + +#include "CombatRecognizer.h" + +void custom_recognizer_init(CustomRecognizerRegistrar& registrar) +{ + registrar.add_recognizer("Combating", combat_combating); +} + +void register_custom_recognizer(MaaInstanceHandle maa_handle, CustomRecognizerRegistrar& registerar) +{ + custom_recognizer_init(registerar); + registerar.register_recognizers(maa_handle); +} \ No newline at end of file diff --git a/source/cli/main.cpp b/source/cli/main.cpp index 2efd6be..1727f6b 100644 --- a/source/cli/main.cpp +++ b/source/cli/main.cpp @@ -93,8 +93,10 @@ int main(int argc, char** argv) return -1; } - CustomActionRegistrar registerar; - register_custom_action(maa_handle, registerar); + CustomActionRegistrar action_registerar; + CustomRecognizerRegistrar recognizer_registerar; + register_custom_action(maa_handle, action_registerar); + register_custom_recognizer(maa_handle, recognizer_registerar); MaaTaskId task_id = 0; for (const auto& task : tasks) { diff --git a/source/cli/main.h b/source/cli/main.h index 2586236..35f0c18 100644 --- a/source/cli/main.h +++ b/source/cli/main.h @@ -9,6 +9,7 @@ #include "MaaToolKit/MaaToolKitAPI.h" #include "meojson/json.hpp" +#include "CustomRecognizer/CustomRecognizerRegistry.h" #include "CustomAction/CustomActionRegistry.h" struct Task