-
Notifications
You must be signed in to change notification settings - Fork 191
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
Feat/lhg #149
Changes from 37 commits
13b4b06
4831a67
1b06d17
5d4da97
f66c04e
13402c6
c90bc06
b49630c
029117d
6739b1e
32175a1
e68217d
861ca10
3dc489e
987f985
775d119
d239317
0b9a80a
abef59e
9496247
db78e78
e2fcece
745a01f
93e5875
17a0980
34d33fa
6da7bde
57dafb0
04367af
c951c41
b08b0f3
470f3f9
2ccae7d
47f360a
c2643f1
38c7762
7fa3635
8b55ab8
602b3dc
0d009fb
1f09b7d
8e9f09c
6f7dde2
fda816a
de881e8
a7a281f
6941d8b
ded01b7
415ac75
e48da5d
19aab68
139c2e4
e78ac31
2f17075
3eac056
a13c856
a0ffa0f
9980a60
ae5423e
905553d
f3a08d0
53ffa0d
f3add40
6943167
5faa871
9ea8bc8
226b660
842b5bc
b7e3792
db92ca4
0106ebd
8c16775
35fb21e
3a36b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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}) |
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 |
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" | ||
} | ||
} |
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); | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fake 是 else 的实现,不是这个宏的意义(改个名字.jpg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这还真就是Fake吧, 就, 扫描时假装是import, 编译时变成空的, 可不就是fake import吗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
是干嘛用的_(:з」∠)_ |
||
#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); |
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些咋删掉了,要不要再还原回来?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
主要是之前开了pr之后一更新就被跑两次, 太蠢了, 最后把这个文件revert了就行