Skip to content

Commit

Permalink
feat: impl some spec
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Mar 12, 2024
1 parent de881e8 commit a7a281f
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 248 deletions.
8 changes: 2 additions & 6 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @brief The type definitions.
*
* @copyright Copyright (c) 2024
*
*
*/

#pragma once
Expand Down Expand Up @@ -106,7 +106,7 @@ typedef MaaOption MaaCtrlOption;

/**
* @brief Option keys for controller instance options. See MaaControllerSetOption().
*
*
*/
enum MaaCtrlOptionEnum
{
Expand Down Expand Up @@ -239,11 +239,7 @@ enum MaaWin32ControllerTypeEnum
// MaaWin32ControllerType_Screencap_DXGI_BackBuffer = 3 << 16,
MaaWin32ControllerType_Screencap_DXGI_FramePool = 4 << 16,
};
#if defined(LHG_PROCESS) || defined(LHG_BUILD)
typedef size_t MaaWin32Hwnd;
#else
typedef void* MaaWin32Hwnd;
#endif

typedef void* MaaTransparentArg;
typedef MaaTransparentArg MaaCallbackTransparentArg;
Expand Down
2 changes: 0 additions & 2 deletions source/MaaHttp/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
"MaaWin32ControllerCreate",
"MaaCustomControllerCreate",
"MaaSetImageRawData",
"MaaRegisterCustomRecognizer",
"MaaRegisterCustomAction",
"/MaaSyncContext.+",
"/Maa.+Rect.*",
"/Maa.+String.+",
Expand Down
42 changes: 0 additions & 42 deletions source/MaaHttp/extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,45 +35,3 @@ MaaBool MaaSetGlobalOptionBoolean(MaaCtrlOption key, bool value)
MaaBool v = !!value;
return MaaSetGlobalOption(key, &v, 1);
}

struct CustomRecoInfo {
MaaCustomRecognizerAPI api;
MaaTransparentArg analyze;
};

MaaBool FAKE_IMPORT MaaRegisterCustomRecognizerImpl(MaaInstanceHandle inst, MaaStringView name, decltype(MaaCustomRecognizerAPI{}.analyze) analyze, MaaTransparentArg analyze_arg) {
static MaaCustomRecognizerAPI api = {
[](auto sycctx, auto img, auto task, auto param, auto ctx, auto out_box, auto out_detail) {
auto info = reinterpret_cast<CustomRecoInfo *>(ctx);
return info->api.analyze(sycctx, img, task, param, info->analyze, out_box, out_detail);
}
};
auto info = new CustomRecoInfo { {analyze}, analyze_arg };
return MaaRegisterCustomRecognizer(inst, name, &api, info);
}

struct CustomActionInfo
{
MaaCustomActionAPI api;
MaaTransparentArg run;
MaaTransparentArg stop;
};

MaaBool FAKE_IMPORT MaaRegisterCustomActionImpl(MaaInstanceHandle inst, MaaStringView name,
decltype(MaaCustomActionAPI {}.run) run, MaaTransparentArg run_arg,
decltype(MaaCustomActionAPI {}.stop) stop, MaaTransparentArg stop_arg)
{
static MaaCustomActionAPI api = {
[](auto sycctx, auto task, auto param, auto box, auto detail, auto ctx) {
auto info = reinterpret_cast<CustomActionInfo *>(ctx);
return info->api.run(sycctx, task, param, box, detail, info->run);
},
[](auto ctx) {
auto info = reinterpret_cast<CustomActionInfo *>(ctx);
info->api.stop(info->stop);
}
};
auto info = new CustomActionInfo { { run, stop }, run_arg, stop_arg };

return MaaRegisterCustomAction(inst, name, &api, info);
}
7 changes: 0 additions & 7 deletions source/MaaHttp/extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,3 @@ MaaBool FAKE_IMPORT MaaControllerSetOptionBoolean(MaaControllerHandle ctrl, MaaC
MaaBool FAKE_IMPORT MaaSetGlobalOptionString(MaaCtrlOption key, MaaStringView value);
MaaBool FAKE_IMPORT MaaSetGlobalOptionInteger(MaaCtrlOption key, int value);
MaaBool FAKE_IMPORT MaaSetGlobalOptionBoolean(MaaCtrlOption key, bool value);

MaaBool FAKE_IMPORT MaaRegisterCustomRecognizerImpl(MaaInstanceHandle inst, MaaStringView name,
decltype(MaaCustomRecognizerAPI {}.analyze) analyze,
MaaTransparentArg analyze_arg);
MaaBool FAKE_IMPORT MaaRegisterCustomActionImpl(MaaInstanceHandle inst, MaaStringView name,
decltype(MaaCustomActionAPI {}.run) run, MaaTransparentArg run_arg,
decltype(MaaCustomActionAPI {}.stop) stop, MaaTransparentArg stop_arg);
227 changes: 109 additions & 118 deletions source/MaaHttp/info.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// clang-format off
#pragma once

#include "function/interface.hpp"
Expand Down Expand Up @@ -1077,6 +1078,56 @@ struct is_output<maa::func_type_MaaInited::ret, false> {

namespace lhg::maa {

struct func_type_MaaRegisterCustomRecognizer {
struct _0_inst {
constexpr static size_t index = 0;
constexpr static const char* name = "inst";
using type = MaaInstanceAPI *;
};
struct _1_name {
constexpr static size_t index = 1;
constexpr static const char* name = "name";
using type = const char *;
};
struct _2_recognizer {
constexpr static size_t index = 2;
constexpr static const char* name = "recognizer";
using type = MaaCustomRecognizerAPI *;
};
struct _3_recognizer_arg {
constexpr static size_t index = 3;
constexpr static const char* name = "recognizer_arg";
using type = void *;
};
struct ret {
constexpr static size_t index = 4;
constexpr static const char* name = "return";
using type = unsigned char;
};
using args = std::tuple<_0_inst, _1_name, _2_recognizer, _3_recognizer_arg, ret>;
};
struct function_MaaRegisterCustomRecognizer {
constexpr static auto func = MaaRegisterCustomRecognizer;
constexpr static const char* name = "MaaRegisterCustomRecognizer";
using type = func_type_MaaRegisterCustomRecognizer;
};

}
namespace lhg::call {

template<>
struct is_input<maa::func_type_MaaRegisterCustomRecognizer::ret, false> {
constexpr static bool value = false;
};
template<>
struct is_output<maa::func_type_MaaRegisterCustomRecognizer::ret, false> {
constexpr static bool value = true;
};

}

namespace lhg::maa {

struct func_type_MaaUnregisterCustomRecognizer {
struct _0_inst {
constexpr static size_t index = 0;
Expand Down Expand Up @@ -1152,6 +1203,56 @@ struct is_output<maa::func_type_MaaClearCustomRecognizer::ret, false> {

namespace lhg::maa {

struct func_type_MaaRegisterCustomAction {
struct _0_inst {
constexpr static size_t index = 0;
constexpr static const char* name = "inst";
using type = MaaInstanceAPI *;
};
struct _1_name {
constexpr static size_t index = 1;
constexpr static const char* name = "name";
using type = const char *;
};
struct _2_action {
constexpr static size_t index = 2;
constexpr static const char* name = "action";
using type = MaaCustomActionAPI *;
};
struct _3_action_arg {
constexpr static size_t index = 3;
constexpr static const char* name = "action_arg";
using type = void *;
};
struct ret {
constexpr static size_t index = 4;
constexpr static const char* name = "return";
using type = unsigned char;
};
using args = std::tuple<_0_inst, _1_name, _2_action, _3_action_arg, ret>;
};
struct function_MaaRegisterCustomAction {
constexpr static auto func = MaaRegisterCustomAction;
constexpr static const char* name = "MaaRegisterCustomAction";
using type = func_type_MaaRegisterCustomAction;
};

}
namespace lhg::call {

template<>
struct is_input<maa::func_type_MaaRegisterCustomAction::ret, false> {
constexpr static bool value = false;
};
template<>
struct is_output<maa::func_type_MaaRegisterCustomAction::ret, false> {
constexpr static bool value = true;
};

}

namespace lhg::maa {

struct func_type_MaaUnregisterCustomAction {
struct _0_inst {
constexpr static size_t index = 0;
Expand Down Expand Up @@ -2956,7 +3057,7 @@ struct func_type_MaaToolkitGetWindow {
struct ret {
constexpr static size_t index = 1;
constexpr static const char* name = "return";
using type = unsigned long long;
using type = void *;
};
using args = std::tuple<_0_index, ret>;
};
Expand Down Expand Up @@ -2986,7 +3087,7 @@ struct func_type_MaaToolkitGetCursorWindow {
struct ret {
constexpr static size_t index = 0;
constexpr static const char* name = "return";
using type = unsigned long long;
using type = void *;
};
using args = std::tuple<ret>;
};
Expand Down Expand Up @@ -3016,7 +3117,7 @@ struct func_type_MaaToolkitGetDesktopWindow {
struct ret {
constexpr static size_t index = 0;
constexpr static const char* name = "return";
using type = unsigned long long;
using type = void *;
};
using args = std::tuple<ret>;
};
Expand Down Expand Up @@ -3046,7 +3147,7 @@ struct func_type_MaaToolkitGetForegroundWindow {
struct ret {
constexpr static size_t index = 0;
constexpr static const char* name = "return";
using type = unsigned long long;
using type = void *;
};
using args = std::tuple<ret>;
};
Expand Down Expand Up @@ -3327,116 +3428,6 @@ struct is_output<maa::func_type_MaaSetGlobalOptionBoolean::ret, false> {

namespace lhg::maa {

struct func_type_MaaRegisterCustomRecognizerImpl {
struct _0_inst {
constexpr static size_t index = 0;
constexpr static const char* name = "inst";
using type = MaaInstanceAPI *;
};
struct _1_name {
constexpr static size_t index = 1;
constexpr static const char* name = "name";
using type = const char *;
};
struct _2_analyze {
constexpr static size_t index = 2;
constexpr static const char* name = "analyze";
using type = unsigned char (*)(MaaSyncContextAPI *, MaaImageBuffer *, const char *, const char *, void *, MaaRect *, MaaStringBuffer *);
};
struct _3_analyze_arg {
constexpr static size_t index = 3;
constexpr static const char* name = "analyze_arg";
using type = void *;
};
struct ret {
constexpr static size_t index = 4;
constexpr static const char* name = "return";
using type = unsigned char;
};
using args = std::tuple<_0_inst, _1_name, _2_analyze, _3_analyze_arg, ret>;
};
struct function_MaaRegisterCustomRecognizerImpl {
constexpr static auto func = MaaRegisterCustomRecognizerImpl;
constexpr static const char* name = "MaaRegisterCustomRecognizerImpl";
using type = func_type_MaaRegisterCustomRecognizerImpl;
};

}
namespace lhg::call {

template<>
struct is_input<maa::func_type_MaaRegisterCustomRecognizerImpl::ret, false> {
constexpr static bool value = false;
};
template<>
struct is_output<maa::func_type_MaaRegisterCustomRecognizerImpl::ret, false> {
constexpr static bool value = true;
};

}

namespace lhg::maa {

struct func_type_MaaRegisterCustomActionImpl {
struct _0_inst {
constexpr static size_t index = 0;
constexpr static const char* name = "inst";
using type = MaaInstanceAPI *;
};
struct _1_name {
constexpr static size_t index = 1;
constexpr static const char* name = "name";
using type = const char *;
};
struct _2_run {
constexpr static size_t index = 2;
constexpr static const char* name = "run";
using type = unsigned char (*)(MaaSyncContextAPI *, const char *, const char *, MaaRect *, const char *, void *);
};
struct _3_run_arg {
constexpr static size_t index = 3;
constexpr static const char* name = "run_arg";
using type = void *;
};
struct _4_stop {
constexpr static size_t index = 4;
constexpr static const char* name = "stop";
using type = void (*)(void *);
};
struct _5_stop_arg {
constexpr static size_t index = 5;
constexpr static const char* name = "stop_arg";
using type = void *;
};
struct ret {
constexpr static size_t index = 6;
constexpr static const char* name = "return";
using type = unsigned char;
};
using args = std::tuple<_0_inst, _1_name, _2_run, _3_run_arg, _4_stop, _5_stop_arg, ret>;
};
struct function_MaaRegisterCustomActionImpl {
constexpr static auto func = MaaRegisterCustomActionImpl;
constexpr static const char* name = "MaaRegisterCustomActionImpl";
using type = func_type_MaaRegisterCustomActionImpl;
};

}
namespace lhg::call {

template<>
struct is_input<maa::func_type_MaaRegisterCustomActionImpl::ret, false> {
constexpr static bool value = false;
};
template<>
struct is_output<maa::func_type_MaaRegisterCustomActionImpl::ret, false> {
constexpr static bool value = true;
};

}

namespace lhg::maa {

using __function_list = std::tuple<
function_MaaAdbControllerCreate,
function_MaaAdbControllerCreateV2,
Expand All @@ -3462,8 +3453,10 @@ using __function_list = std::tuple<
function_MaaBindResource,
function_MaaBindController,
function_MaaInited,
function_MaaRegisterCustomRecognizer,
function_MaaUnregisterCustomRecognizer,
function_MaaClearCustomRecognizer,
function_MaaRegisterCustomAction,
function_MaaUnregisterCustomAction,
function_MaaClearCustomAction,
function_MaaPostTask,
Expand Down Expand Up @@ -3522,9 +3515,7 @@ using __function_list = std::tuple<
function_MaaControllerSetOptionBoolean,
function_MaaSetGlobalOptionString,
function_MaaSetGlobalOptionInteger,
function_MaaSetGlobalOptionBoolean,
function_MaaRegisterCustomRecognizerImpl,
function_MaaRegisterCustomActionImpl
function_MaaSetGlobalOptionBoolean
>;

}
Expand Down Expand Up @@ -3771,4 +3762,4 @@ struct type_is_handle<MaaSyncContextAPI *, false> {
constexpr static bool value = true;
};

}
}
Loading

0 comments on commit a7a281f

Please sign in to comment.