Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/lhg #149

Merged
merged 74 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
13b4b06
feat: intro LHG
neko-para Jan 3, 2024
4831a67
feat: add install
neko-para Jan 3, 2024
1b06d17
fix: build error
neko-para Jan 3, 2024
5d4da97
fix: build error
neko-para Jan 3, 2024
f66c04e
fix: gcc error
neko-para Jan 3, 2024
13402c6
fix: use before init
neko-para Jan 3, 2024
c90bc06
refactor: split helper
neko-para Jan 4, 2024
b49630c
chore: stop building twice
neko-para Jan 4, 2024
029117d
feat: update help message
neko-para Jan 4, 2024
6739b1e
chore: update LHG
neko-para Jan 4, 2024
32175a1
refactor: split main
neko-para Jan 4, 2024
e68217d
refactor: some split
neko-para Jan 4, 2024
861ca10
refactor: add meta tags
neko-para Jan 5, 2024
3dc489e
refactor: explicit split SetOption
neko-para Jan 5, 2024
987f985
fix: build error
neko-para Jan 5, 2024
775d119
refactor: move most logic into c++
neko-para Jan 5, 2024
d239317
chore: change tag name
neko-para Jan 5, 2024
0b9a80a
feat: update lhg
neko-para Jan 8, 2024
abef59e
feat: update schema
neko-para Jan 12, 2024
9496247
fix: link warning
neko-para Jan 12, 2024
db78e78
refactor: callback
neko-para Jan 13, 2024
e2fcece
chore: update LHG
neko-para Jan 13, 2024
745a01f
Merge branch 'main' into lhg
neko-para Jan 13, 2024
93e5875
feat: update wrapper
neko-para Jan 13, 2024
17a0980
feat: update
neko-para Jan 14, 2024
34d33fa
fix: some fix
neko-para Jan 15, 2024
6da7bde
chore: update submodule
neko-para Jan 17, 2024
57dafb0
Merge branch 'main' into lhg
neko-para Jan 17, 2024
04367af
Merge branch 'main' into lhg
neko-para Jan 18, 2024
c951c41
fix: build error
neko-para Jan 18, 2024
b08b0f3
fix: build error again
neko-para Jan 18, 2024
470f3f9
fix: build error
neko-para Jan 18, 2024
2ccae7d
fix: use base64 in binary string
neko-para Jan 19, 2024
47f360a
chore: update LHG
neko-para Feb 21, 2024
c2643f1
Merge branch 'main' into lhg
neko-para Feb 21, 2024
38c7762
chore: use std::format
neko-para Feb 21, 2024
7fa3635
Merge branch 'main' into feat/lhg
neko-para Feb 21, 2024
8b55ab8
feat: custom action & reco
neko-para Feb 23, 2024
602b3dc
fix: update mac avd
neko-para Feb 23, 2024
0d009fb
Merge branch 'main' into feat/lhg
neko-para Feb 28, 2024
1f09b7d
WIP: new impl
neko-para Mar 10, 2024
8e9f09c
refactor: refactor
neko-para Mar 11, 2024
6f7dde2
feat: update
neko-para Mar 11, 2024
fda816a
feat: update
neko-para Mar 11, 2024
de881e8
feat: update
neko-para Mar 12, 2024
a7a281f
feat: impl some spec
neko-para Mar 12, 2024
6941d8b
feat: finish spec
neko-para Mar 12, 2024
ded01b7
feat: keep type
neko-para Mar 12, 2024
415ac75
feat: finish callback
neko-para Mar 12, 2024
e48da5d
chore: clean
neko-para Mar 12, 2024
19aab68
Merge branch 'main' into feat/lhg
neko-para Mar 12, 2024
139c2e4
chore: format
neko-para Mar 12, 2024
e78ac31
fix: force crlf
neko-para Mar 12, 2024
2f17075
fix: force lf
neko-para Mar 12, 2024
3eac056
feat: schema
neko-para Mar 13, 2024
a13c856
fix: build error
neko-para Mar 14, 2024
a0ffa0f
feat: convert into header only library
neko-para Mar 14, 2024
9980a60
feat: reimpl base64
neko-para Mar 14, 2024
ae5423e
feat: cmake generate
neko-para Mar 14, 2024
905553d
ci: install nodejs
neko-para Mar 14, 2024
f3a08d0
feat: finish schema
neko-para Mar 14, 2024
53ffa0d
chore: revert ci
neko-para Mar 14, 2024
f3add40
chore: not updated
neko-para Mar 14, 2024
6943167
chore: revert ci
neko-para Mar 14, 2024
5faa871
chore: revert
neko-para Mar 14, 2024
9ea8bc8
fix: oper id
neko-para Mar 14, 2024
226b660
Merge branch 'main' into feat/lhg
neko-para Mar 14, 2024
842b5bc
chore: update
neko-para Mar 14, 2024
b7e3792
fix: test ci
neko-para Mar 14, 2024
db92ca4
feat: add handle dump
neko-para Mar 14, 2024
0106ebd
fix: custom action crash
neko-para Mar 14, 2024
8c16775
chore: some fix
neko-para Mar 15, 2024
35fb21e
refactor: move sources
neko-para Mar 15, 2024
3a36b13
fix: build error
neko-para Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ on:
- "include/**"
- "source/**"
- "CMakeLists.txt"

pull_request:
branches:
- "**"
paths:
- ".github/workflows/build.yml"
- "3rdparty/**"
- "cmake/**"
- "include/**"
- "source/**"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些咋删掉了,要不要再还原回来?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主要是之前开了pr之后一更新就被跑两次, 太蠢了, 最后把这个文件revert了就行

- "CMakeLists.txt"
workflow_dispatch:

jobs:
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ on:
- "source/**"
- "CMakeLists.txt"
- "test/**"

pull_request:
branches:
- "**"
paths:
- ".github/workflows/test.yml"
- "3rdparty/**"
- "cmake/**"
- "include/**"
- "source/**"
- "CMakeLists.txt"
- "test/**"
workflow_dispatch:

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "test/TestingDataSet"]
path = test/TestingDataSet
url = https://github.com/MaaAssistantArknights/MaaFrameworkTesting.git
[submodule "source/MaaHttp/LHG"]
path = source/MaaHttp/LHG
url = https://github.com/neko-para/LibHttpGen
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ option(WITH_GRPC "build with protobuf and grpc" OFF)

option(BUILD_GRPC_CLI "build grpc CLI exec" OFF)

option(WITH_HTTP "build with http" ON)

option(BUILD_SAMPLE "build a demo" OFF)

option(BUILD_PIPELINE_TESTING "build pipeline testing" OFF)
Expand Down
4 changes: 4 additions & 0 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ enum MaaWin32ControllerTypeEnum
// MaaWin32ControllerType_Screencap_DXGI_BackBuffer = 3 << 16,
MaaWin32ControllerType_Screencap_DXGI_FramePool = 4 << 16,
};
#ifdef LHG_PROCESS
MistEO marked this conversation as resolved.
Show resolved Hide resolved
typedef size_t MaaWin32Hwnd;
#else
typedef void* MaaWin32Hwnd;
#endif

typedef void* MaaTransparentArg;
typedef MaaTransparentArg MaaCallbackTransparentArg;
Expand Down
3 changes: 3 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ add_subdirectory(MaaProjectInterfaceCli)
if(WITH_GRPC)
add_subdirectory(MaaRpc)
endif()
if(WITH_HTTP)
add_subdirectory(MaaHttp)
endif()

add_subdirectory(binding)
21 changes: 21 additions & 0 deletions source/MaaHttp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(LHG_EMBEDDED ON CACHE BOOL "make lhg work in embedded mode")
add_subdirectory(LHG)

file(GLOB_RECURSE maa_http_src wrapper.cpp extra.cpp extra.h include.h LHG/projects/target/*.cpp LHG/projects/target/*.hpp LHG/projects/target/*.h)
MistEO marked this conversation as resolved.
Show resolved Hide resolved

add_executable(MaaHttp ${maa_http_src})
target_include_directories(MaaHttp PRIVATE ./../include LHG/projects/target)
target_link_libraries(MaaHttp LHGHeaderonly Boost::system MaaFramework MaaToolkit)

if(WIN32)
target_compile_definitions(MaaHttp PRIVATE _WIN32_WINNT=0x0A00)
MistEO marked this conversation as resolved.
Show resolved Hide resolved
endif()

install(
TARGETS MaaHttp
EXPORT MaaFrameworkTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_http_src})
1 change: 1 addition & 0 deletions source/MaaHttp/LHG
Submodule LHG added at 1945dd
105 changes: 105 additions & 0 deletions source/MaaHttp/base64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#ifndef BASE_64_HPP
#define BASE_64_HPP
neko-para marked this conversation as resolved.
Show resolved Hide resolved

#include <algorithm>
#include <stdexcept>
#include <string>
#include <string_view>

namespace base64
{

inline constexpr std::string_view base64_chars { "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/" };

template <class OutputBuffer, class InputIterator>
inline OutputBuffer encode_into(InputIterator begin, InputIterator end)
{
static_assert(std::is_same_v<std::decay_t<decltype(*begin)>, char> ||
std::is_same_v<std::decay_t<decltype(*begin)>, unsigned char> ||
std::is_same_v<std::decay_t<decltype(*begin)>, std::byte>);

size_t counter = 0;
uint32_t bit_stream = 0;
size_t offset = 0;
OutputBuffer encoded;
encoded.reserve(static_cast<size_t>(1.5 * static_cast<double>(std::distance(begin, end))));
while (begin != end) {
auto const num_val = static_cast<unsigned char>(*begin);
offset = 16 - counter % 3 * 8;
bit_stream += num_val << offset;
if (offset == 16) {
encoded.push_back(base64_chars[bit_stream >> 18 & 0x3f]);
}
if (offset == 8) {
encoded.push_back(base64_chars[bit_stream >> 12 & 0x3f]);
}
if (offset == 0 && counter != 3) {
encoded.push_back(base64_chars[bit_stream >> 6 & 0x3f]);
encoded.push_back(base64_chars[bit_stream & 0x3f]);
bit_stream = 0;
}
++counter;
++begin;
}
if (offset == 16) {
encoded.push_back(base64_chars[bit_stream >> 12 & 0x3f]);
encoded.push_back('=');
encoded.push_back('=');
}
if (offset == 8) {
encoded.push_back(base64_chars[bit_stream >> 6 & 0x3f]);
encoded.push_back('=');
}
return encoded;
}

inline std::string to_base64(std::string_view data)
{
return encode_into<std::string>(std::begin(data), std::end(data));
}

template <class OutputBuffer>
inline OutputBuffer decode_into(std::string_view data)
{
using value_type = typename OutputBuffer::value_type;
static_assert(std::is_same_v<value_type, char> || std::is_same_v<value_type, unsigned char> ||
std::is_same_v<value_type, std::byte>);

size_t counter = 0;
uint32_t bit_stream = 0;
OutputBuffer decoded;
decoded.reserve(std::size(data));
for (unsigned char c : data) {
auto const num_val = base64_chars.find(c);
if (num_val != std::string::npos) {
auto const offset = 18 - counter % 4 * 6;
bit_stream += static_cast<uint32_t>(num_val) << offset;
if (offset == 12) {
decoded.push_back(static_cast<value_type>(bit_stream >> 16 & 0xff));
}
if (offset == 6) {
decoded.push_back(static_cast<value_type>(bit_stream >> 8 & 0xff));
}
if (offset == 0 && counter != 4) {
decoded.push_back(static_cast<value_type>(bit_stream & 0xff));
bit_stream = 0;
}
}
else if (c != '=') {
throw std::runtime_error { "Invalid base64 encoded data" };
}
counter++;
}
return decoded;
}

inline std::string from_base64(std::string_view data)
{
return decode_into<std::string>(data);
}

} // namespace base64

#endif // BASE_64_HPP
51 changes: 51 additions & 0 deletions source/MaaHttp/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"callback": {
"void (*)(const char *, const char *, void *)": {
"name": "MaaAPICallback",
"pass": 1,
"self": 2,
"all": 3,
"arg_name": ["msg", "details_json", ""]
}
},
"opaque": {
"MaaControllerAPI": {
"non-alloc": ["MaaGetController"],
"free": ["MaaControllerDestroy"]
},
"MaaResourceAPI": {
"non-alloc": ["MaaGetResource"],
"free": ["MaaResourceDestroy"]
},
"MaaInstanceAPI": {
"free": ["MaaDestroy"]
},
"MaaImageBuffer": {
"free": ["MaaDestroyImageBuffer"]
}
},
"output": ["MaaStringBuffer"],
"remove": [
"MaaCustomControllerCreate",
"MaaSetImageRawData",
"MaaRegisterCustomRecognizer",
"MaaRegisterCustomAction",
"MaaUnregisterCustomRecognizer",
"MaaUnregisterCustomAction",
"/MaaSyncContext.+",
"/Maa.+Rect.*",
"/Maa.+String.+",
"MaaClearString",
"MaaGetString",
"MaaSetString",
"MaaGetImageEncodedSize",
"MaaGetImageRawData",
"MaaControllerSetOption",
"MaaResourceSetOption",
"MaaSetOption",
"MaaSetGlobalOption"
],
"check": {
"const char *": "string"
}
}
35 changes: 35 additions & 0 deletions source/MaaHttp/extra.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <cstring>

#include "extra.h"

MaaBool MaaControllerSetOptionString(MaaControllerHandle ctrl, MaaCtrlOption key, MaaStringView value)
{
return MaaControllerSetOption(ctrl, key, const_cast<char*>(value), strlen(value));
}

MaaBool MaaControllerSetOptionInteger(MaaControllerHandle ctrl, MaaCtrlOption key, int value)
{
return MaaControllerSetOption(ctrl, key, &value, 4);
}

MaaBool MaaControllerSetOptionBoolean(MaaControllerHandle ctrl, MaaCtrlOption key, bool value)
{
MaaBool v = !!value;
return MaaControllerSetOption(ctrl, key, &v, 1);
}

MaaBool MaaSetGlobalOptionString(MaaCtrlOption key, MaaStringView value)
{
return MaaSetGlobalOption(key, const_cast<char*>(value), strlen(value));
}

MaaBool MaaSetGlobalOptionInteger(MaaCtrlOption key, int value)
{
return MaaSetGlobalOption(key, &value, 4);
}

MaaBool MaaSetGlobalOptionBoolean(MaaCtrlOption key, bool value)
{
MaaBool v = !!value;
return MaaSetGlobalOption(key, &v, 1);
}
17 changes: 17 additions & 0 deletions source/MaaHttp/extra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "MaaFramework/MaaAPI.h"

#if defined(LHG_PROCESS) && !defined(LHG_BUILD)
#define FAKE_IMPORT MAA_FRAMEWORK_API
#else
#define FAKE_IMPORT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fake 是 else 的实现,不是这个宏的意义(改个名字.jpg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这还真就是Fake吧, 就, 扫描时假装是import, 编译时变成空的, 可不就是fake import吗

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

扫描时假装是import

是干嘛用的_(:з」∠)_

#endif

MaaBool FAKE_IMPORT MaaControllerSetOptionString(MaaControllerHandle ctrl, MaaCtrlOption key, MaaStringView value);
MaaBool FAKE_IMPORT MaaControllerSetOptionInteger(MaaControllerHandle ctrl, MaaCtrlOption key, int value);
MaaBool FAKE_IMPORT MaaControllerSetOptionBoolean(MaaControllerHandle ctrl, MaaCtrlOption key, bool value);

MaaBool FAKE_IMPORT MaaSetGlobalOptionString(MaaCtrlOption key, MaaStringView value);
MaaBool FAKE_IMPORT MaaSetGlobalOptionInteger(MaaCtrlOption key, int value);
MaaBool FAKE_IMPORT MaaSetGlobalOptionBoolean(MaaCtrlOption key, bool value);
9 changes: 9 additions & 0 deletions source/MaaHttp/include.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _SIZE_T
#define _SIZE_T
// 统一win&other
typedef unsigned long long size_t;
MistEO marked this conversation as resolved.
Show resolved Hide resolved
#endif

#include "MaaFramework/MaaAPI.h"
#include "MaaToolkit/MaaToolkitAPI.h"
#include "extra.h"
Loading
Loading