From c0064dcc848b8005d3da345db05d8098b284d737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Mon, 1 Jul 2024 22:14:01 +0800 Subject: [PATCH] faster --- .gitmodules | 3 +++ plugins/libs/libs.cmake | 1 + plugins/libs/rapidfuzz-cpp | 1 + plugins/pch.h | 3 +++ plugins/shareddllproxy/ntleas.cpp | 2 +- plugins/winrtutils/winrtocr.cpp | 8 ++++---- plugins/winsharedutils/levenshtein.cpp | 8 +++++--- 7 files changed, 18 insertions(+), 8 deletions(-) create mode 160000 plugins/libs/rapidfuzz-cpp diff --git a/.gitmodules b/.gitmodules index 54120b54..8491442d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "plugins/libs/miniaudio"] path = plugins/libs/miniaudio url = https://github.com/HIllya51/miniaudio +[submodule "plugins/libs/rapidfuzz-cpp"] + path = plugins/libs/rapidfuzz-cpp + url = https://github.com/rapidfuzz/rapidfuzz-cpp diff --git a/plugins/libs/libs.cmake b/plugins/libs/libs.cmake index 70f18d6d..659e47a1 100644 --- a/plugins/libs/libs.cmake +++ b/plugins/libs/libs.cmake @@ -10,6 +10,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/Detours-4.0.1/include) include_directories(${CMAKE_CURRENT_LIST_DIR}/wil/include) include_directories(${CMAKE_CURRENT_LIST_DIR}/miniaudio) include_directories(${CMAKE_CURRENT_LIST_DIR}/tinymp3) +include_directories(${CMAKE_CURRENT_LIST_DIR}/rapidfuzz-cpp) include_directories(${CMAKE_CURRENT_LIST_DIR}/webview2/Microsoft.Web.WebView2.1.0.2535.41/build/native/include) diff --git a/plugins/libs/rapidfuzz-cpp b/plugins/libs/rapidfuzz-cpp new file mode 160000 index 00000000..10426d24 --- /dev/null +++ b/plugins/libs/rapidfuzz-cpp @@ -0,0 +1 @@ +Subproject commit 10426d24cd7479df0fe8c78b17877e756e1c3cd5 diff --git a/plugins/pch.h b/plugins/pch.h index 7fbd3f8a..7346a0f8 100644 --- a/plugins/pch.h +++ b/plugins/pch.h @@ -1,5 +1,7 @@ #pragma once #define _CRT_SECURE_NO_WARNINGS +#define NOMINMAX + #include #include #include @@ -14,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/plugins/shareddllproxy/ntleas.cpp b/plugins/shareddllproxy/ntleas.cpp index 1ae3cf3a..6219aae7 100644 --- a/plugins/shareddllproxy/ntleas.cpp +++ b/plugins/shareddllproxy/ntleas.cpp @@ -554,7 +554,7 @@ int CreateProcessEndExt(NtleaProcess *process, PROCESS_INFORMATION const *proinf OUTPUT_DEBUG_STRING_INFO *dbginfo = (OUTPUT_DEBUG_STRING_INFO *)&dbgevent.u.DebugString; unsigned char *msg = (unsigned char *)dbgstrbuf; // read debug string from debugee process : - ReadProcessMemory(proinfo->hProcess, dbginfo->lpDebugStringData, msg, min(1024, dbginfo->nDebugStringLength), NULL); + ReadProcessMemory(proinfo->hProcess, dbginfo->lpDebugStringData, msg, std::min(1024, (int)dbginfo->nDebugStringLength), NULL); fprintf(stderr, dbginfo->fUnicode ? "%S\n" : "%s\n", msg); ContinueDebugEvent(dbgevent.dwProcessId, dbgevent.dwThreadId, DBG_CONTINUE); } diff --git a/plugins/winrtutils/winrtocr.cpp b/plugins/winrtutils/winrtocr.cpp index 88a0d6e9..5010b3c9 100644 --- a/plugins/winrtutils/winrtocr.cpp +++ b/plugins/winrtutils/winrtocr.cpp @@ -89,10 +89,10 @@ ocrres OCR(void *ptr, size_t size, wchar_t *lang, wchar_t *space, int *num) start = false; xx += word.Text(); auto &rect = word.BoundingRect(); - x1 = min(rect.X, x1); - x2 = max(x2, rect.X + rect.Width); - y1 = min(rect.Y, y1); - y2 = max(y2, rect.Y + rect.Height); + x1 = std::min((unsigned int)rect.X, x1); + x2 = std::max(x2, (unsigned int)(rect.X + rect.Width)); + y1 = std::min((unsigned int)rect.Y, y1); + y2 = std::max(y2, (unsigned int)(rect.Y + rect.Height)); } ys.push_back(y1); xs.push_back(x1); diff --git a/plugins/winsharedutils/levenshtein.cpp b/plugins/winsharedutils/levenshtein.cpp index f1a24f84..f59ee405 100644 --- a/plugins/winsharedutils/levenshtein.cpp +++ b/plugins/winsharedutils/levenshtein.cpp @@ -157,16 +157,18 @@ size_t lev_u_edit_distance(size_t len1, const wchar_t *string1, free(row); return i; } - +#include size_t levenshtein_distance(size_t len1, const wchar_t *string1, size_t len2, const wchar_t *string2) { - return lev_u_edit_distance(len1, string1, len2, string2, 0); + return rapidfuzz::levenshtein_distance(std::wstring_view(string1, len1), std::wstring_view(string2, len2)); + // return lev_u_edit_distance(len1, string1, len2, string2, 0); } double levenshtein_ratio(size_t len1, const wchar_t *string1, size_t len2, const wchar_t *string2) { - auto ldist = lev_u_edit_distance(len1, string1, len2, string2, 1); + // auto ldist = lev_u_edit_distance(len1, string1, len2, string2, 1); + auto ldist = levenshtein_distance(len1, string1, len2, string2); auto lensum = len1 + len2; if (lensum == 0) return 0;