This commit is contained in:
恍兮惚兮 2024-04-10 03:17:53 +08:00
parent d6633db3af
commit cb51b38533
12 changed files with 438 additions and 9 deletions

View File

@ -44,7 +44,14 @@ include_directories(.)
include(libs/libs.cmake)
include_directories(include)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
include(generate_product_version)
set(VERSION_MAJOR 2)
set(VERSION_MINOR 10)
set(VERSION_PATCH 0)
set(VERSION_REVISION 0)
add_subdirectory(include)
add_subdirectory(LunaHook)
add_subdirectory(LunaHost)

View File

@ -88,4 +88,6 @@
#define HS_HOOK_SEARCH_FILTER L"Results must match this regex"
#define HS_TEXT L"Text"
#define HS_CODEPAGE L"Codepage"
#define HS_SEARCH_FOR_TEXT L"Search for specific text"
#define HS_SEARCH_FOR_TEXT L"Search for specific text"
#define VersionLatest L"Latest version"
#define VersionCurrent L"Current version"

View File

@ -88,4 +88,6 @@
#define HS_HOOK_SEARCH_FILTER L"结果必须匹配的正则表达式"
#define HS_TEXT L"文本"
#define HS_CODEPAGE L"代码页"
#define HS_SEARCH_FOR_TEXT L"搜索指定文本"
#define HS_SEARCH_FOR_TEXT L"搜索指定文本"
#define VersionLatest L"最新版本"
#define VersionCurrent L"当前版本"

View File

@ -27,7 +27,19 @@ set(texthook_src
)
add_subdirectory(util)
add_subdirectory(engines)
add_library(LunaHook MODULE ${texthook_src} resource.rc)
generate_product_version(
versioninfohook
NAME "LunaHook"
COMPANY_COPYRIGHT "HIllya51 (C) 2024"
ICON ${PATH_TO_APPLICATION_ICON}
VERSION_MAJOR ${VERSION_MAJOR}
VERSION_MINOR ${VERSION_MINOR}
VERSION_PATCH ${VERSION_PATCH}
VERSION_REVISION ${VERSION_REVISION}
)
add_library(LunaHook MODULE ${texthook_src} resource.rc ${versioninfohook})
target_precompile_headers(LunaHook REUSE_FROM pch)

View File

@ -1,3 +1,15 @@
generate_product_version(
versioninfohost
NAME "LunaHost"
COMPANY_COPYRIGHT "HIllya51 (C) 2024"
ICON ${PATH_TO_APPLICATION_ICON}
VERSION_MAJOR ${VERSION_MAJOR}
VERSION_MINOR ${VERSION_MINOR}
VERSION_PATCH ${VERSION_PATCH}
VERSION_REVISION ${VERSION_REVISION}
)
add_library(host
host.cpp
textthread.cpp
@ -6,10 +18,10 @@ target_precompile_headers(host REUSE_FROM pch)
include_directories(.)
add_executable(LunaHostCLI LunaHostCLI.cpp)
add_executable(LunaHostCLI LunaHostCLI.cpp ${versioninfohost})
target_precompile_headers(LunaHostCLI REUSE_FROM pch)
add_library(LunaHostDll MODULE LunaHostDll.cpp)
add_library(LunaHostDll MODULE LunaHostDll.cpp ${versioninfohost})
target_precompile_headers(LunaHostDll REUSE_FROM pch)
set_target_properties(LunaHostCLI PROPERTIES OUTPUT_NAME "LunaHostCLI${bitappendix}")

View File

@ -1,5 +1,5 @@
add_executable(LunaHost WIN32 confighelper.cpp controls.cpp main.cpp processlistwindow.cpp LunaHost.cpp window.cpp luna.rc pluginmanager.cpp Plugin/pluginexample.cpp QtLoader_inline.cpp app.manifest)
add_executable(LunaHost WIN32 confighelper.cpp controls.cpp main.cpp processlistwindow.cpp LunaHost.cpp window.cpp luna.rc pluginmanager.cpp Plugin/pluginexample.cpp QtLoader_inline.cpp app.manifest ${versioninfohost})
target_precompile_headers(LunaHost REUSE_FROM pch)
set_target_properties(LunaHost PROPERTIES OUTPUT_NAME "LunaHost${bitappendix}")
target_link_libraries(LunaHost comctl32 pch host ${YY_Thunks_for_WinXP})
target_link_libraries(LunaHost comctl32 winhttp version pch host ${YY_Thunks_for_WinXP})
add_subdirectory(Plugin)

View File

@ -9,6 +9,7 @@
#include"textthread.h"
#include"LunaHost.h"
#include"Lang/Lang.h"
#include"http.hpp"
auto gmf=[&](DWORD processId)->std::optional<std::wstring>{
//见鬼了GetModuleFileName找不到标识符
std::vector<wchar_t> buffer(MAX_PATH);
@ -101,7 +102,72 @@ void LunaHost::on_proc_connect(DWORD pid)
autoattachexes.insert(WideStringToString(pexe.value()));
}
}
bool queryversion(WORD *_1, WORD *_2, WORD *_3, WORD *_4)
{
wchar_t fileName[MAX_PATH];
GetModuleFileNameW(NULL, fileName, MAX_PATH);
DWORD dwHandle;
DWORD dwSize = GetFileVersionInfoSizeW(fileName, &dwHandle);
if (dwSize == 0)
{
return false;
}
std::vector<char> versionInfoBuffer(dwSize);
if (!GetFileVersionInfoW(fileName, dwHandle, dwSize, versionInfoBuffer.data()))
{
return false;
}
VS_FIXEDFILEINFO *pFileInfo;
UINT fileInfoSize;
if (!VerQueryValueW(versionInfoBuffer.data(), L"\\", reinterpret_cast<LPVOID *>(&pFileInfo), &fileInfoSize))
{
return false;
}
DWORD ms = pFileInfo->dwFileVersionMS;
DWORD ls = pFileInfo->dwFileVersionLS;
WORD majorVersion = HIWORD(ms);
WORD minorVersion = LOWORD(ms);
WORD buildNumber = HIWORD(ls);
WORD revisionNumber = LOWORD(ls);
*_1 = majorVersion;
*_2 = minorVersion;
*_3 = buildNumber;
*_4 = revisionNumber;
return true;
}
LunaHost::LunaHost(){
std::wstring title=WndLunaHostGui;
WORD _1,_2,_3,_4;
WCHAR vs[32];
if(queryversion(&_1,&_2,&_3,&_4)){
wsprintf(vs,L" | %s v%d.%d.%d",VersionCurrent,_1,_2,_3);
title+=vs;
std::thread([&](){
if (HttpRequest httpRequest{
L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
L"api.github.com",
L"GET",
L"/repos/HIllya51/LunaHook/releases/latest"
}){
try{
auto resp=nlohmann::json::parse(WideStringToString(httpRequest.response));
std::string ver=resp["tag_name"];
ver=ver.substr(1);
settext(text()+L" | "+VersionLatest+L" "+ StringToWideString(ver));
}
catch(std::exception&e){}
}
}).detach();
}
settext(title.c_str());
configs=new confighelper;
loadsettings();
@ -114,7 +180,6 @@ LunaHost::LunaHost(){
}).detach();
setfont(25);
settext(WndLunaHostGui);
btnshowsettionwindow=new button(this, BtnShowSettingWindow);
g_selectprocessbutton =new button(this,BtnSelectProcess) ;

74
LunaHost/GUI/http.hpp Normal file
View File

@ -0,0 +1,74 @@
#include <winhttp.h>
using InternetHandle = AutoHandle<Functor<WinHttpCloseHandle>>;
struct HttpRequest
{
HttpRequest(
const wchar_t* agentName,
const wchar_t* serverName,
const wchar_t* action,
const wchar_t* objectName,
std::string body = "",
const wchar_t* headers = NULL,
DWORD port = INTERNET_DEFAULT_PORT,
const wchar_t* referrer = NULL,
DWORD requestFlags = WINHTTP_FLAG_SECURE | WINHTTP_FLAG_ESCAPE_DISABLE,
const wchar_t* httpVersion = NULL,
const wchar_t** acceptTypes = NULL
);
operator bool() { return errorCode == ERROR_SUCCESS; }
std::wstring response;
std::wstring headers;
InternetHandle connection = NULL;
InternetHandle request = NULL;
DWORD errorCode = ERROR_SUCCESS;
};
HttpRequest::HttpRequest(
const wchar_t* agentName,
const wchar_t* serverName,
const wchar_t* action,
const wchar_t* objectName,
std::string body,
const wchar_t* headers,
DWORD port,
const wchar_t* referrer,
DWORD requestFlags,
const wchar_t* httpVersion,
const wchar_t** acceptTypes
)
{
static std::atomic<HINTERNET> internet = NULL;
if (!internet) internet = WinHttpOpen(agentName, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, NULL, NULL, 0);
if (internet)
if (InternetHandle connection = WinHttpConnect(internet, serverName, port, 0))
if (InternetHandle request = WinHttpOpenRequest(connection, action, objectName, httpVersion, referrer, acceptTypes, requestFlags))
if (WinHttpSendRequest(request, headers, -1UL, body.empty() ? NULL : body.data(), body.size(), body.size(), NULL))
{
WinHttpReceiveResponse(request, NULL);
//DWORD size = 0;
//WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX, NULL, &size, WINHTTP_NO_HEADER_INDEX);
//this->headers.resize(size);
//WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX, this->headers.data(), &size, WINHTTP_NO_HEADER_INDEX);
std::string data;
DWORD availableSize, downloadedSize;
do
{
availableSize = 0;
WinHttpQueryDataAvailable(request, &availableSize);
if (!availableSize) break;
std::vector<char> buffer(availableSize);
WinHttpReadData(request, buffer.data(), availableSize, &downloadedSize);
data.append(buffer.data(), downloadedSize);
} while (availableSize > 0);
response = StringToWideString(data);
this->connection = std::move(connection);
this->request = std::move(request);
}
else errorCode = GetLastError();
else errorCode = GetLastError();
else errorCode = GetLastError();
else errorCode = GetLastError();
}

82
version/VersionInfo.in Normal file
View File

@ -0,0 +1,82 @@
#pragma once
#ifndef PRODUCT_VERSION_MAJOR
#define PRODUCT_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@
#endif
#ifndef PRODUCT_VERSION_MINOR
#define PRODUCT_VERSION_MINOR @PRODUCT_VERSION_MINOR@
#endif
#ifndef PRODUCT_VERSION_PATCH
#define PRODUCT_VERSION_PATCH @PRODUCT_VERSION_PATCH@
#endif
#ifndef PRODUCT_VERSION_BUILD
#define PRODUCT_VERSION_BUILD @PRODUCT_VERSION_REVISION@
#endif
#ifndef FILE_VERSION_MAJOR
#define FILE_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@
#endif
#ifndef FILE_VERSION_MINOR
#define FILE_VERSION_MINOR @PRODUCT_VERSION_MINOR@
#endif
#ifndef FILE_VERSION_PATCH
#define FILE_VERSION_PATCH @PRODUCT_VERSION_PATCH@
#endif
#ifndef FILE_VERSION_BUILD
#define FILE_VERSION_BUILD @PRODUCT_VERSION_REVISION@
#endif
#ifndef __TO_STRING
#define __TO_STRING_IMPL(x) #x
#define __TO_STRING(x) __TO_STRING_IMPL(x)
#endif
#define PRODUCT_VERSION_MAJOR_MINOR_STR __TO_STRING(PRODUCT_VERSION_MAJOR) "." __TO_STRING(PRODUCT_VERSION_MINOR)
#define PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR PRODUCT_VERSION_MAJOR_MINOR_STR "." __TO_STRING(PRODUCT_VERSION_PATCH)
#define PRODUCT_VERSION_FULL_STR PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(PRODUCT_VERSION_BUILD)
#define PRODUCT_VERSION_RESOURCE PRODUCT_VERSION_MAJOR,PRODUCT_VERSION_MINOR,PRODUCT_VERSION_PATCH,PRODUCT_VERSION_BUILD
#define PRODUCT_VERSION_RESOURCE_STR PRODUCT_VERSION_FULL_STR "\0"
#define FILE_VERSION_MAJOR_MINOR_STR __TO_STRING(FILE_VERSION_MAJOR) "." __TO_STRING(FILE_VERSION_MINOR)
#define FILE_VERSION_MAJOR_MINOR_PATCH_STR FILE_VERSION_MAJOR_MINOR_STR "." __TO_STRING(FILE_VERSION_PATCH)
#define FILE_VERSION_FULL_STR FILE_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(FILE_VERSION_BUILD)
#define FILE_VERSION_RESOURCE FILE_VERSION_MAJOR,FILE_VERSION_MINOR,FILE_VERSION_PATCH,FILE_VERSION_BUILD
#define FILE_VERSION_RESOURCE_STR FILE_VERSION_FULL_STR "\0"
#ifndef PRODUCT_ICON
#define PRODUCT_ICON "@PRODUCT_ICON@"
#endif
#ifndef PRODUCT_COMMENTS
#define PRODUCT_COMMENTS "@PRODUCT_COMMENTS@\0"
#endif
#ifndef PRODUCT_COMPANY_NAME
#define PRODUCT_COMPANY_NAME "@PRODUCT_COMPANY_NAME@\0"
#endif
#ifndef PRODUCT_COMPANY_COPYRIGHT
#define PRODUCT_COMPANY_COPYRIGHT "@PRODUCT_COMPANY_COPYRIGHT@\0"
#endif
#ifndef PRODUCT_FILE_DESCRIPTION
#define PRODUCT_FILE_DESCRIPTION "@PRODUCT_FILE_DESCRIPTION@\0"
#endif
#ifndef PRODUCT_INTERNAL_NAME
#define PRODUCT_INTERNAL_NAME "@PRODUCT_NAME@\0"
#endif
#ifndef PRODUCT_ORIGINAL_FILENAME
#define PRODUCT_ORIGINAL_FILENAME "@PRODUCT_ORIGINAL_FILENAME@\0"
#endif
#ifndef PRODUCT_BUNDLE
#define PRODUCT_BUNDLE "@PRODUCT_BUNDLE@\0"
#endif

View File

@ -0,0 +1,52 @@
#include "VersionInfo.h"
#if defined(__MINGW64__) || defined(__MINGW32__)
// MinGW-w64, MinGW
#if defined(__has_include) && __has_include(<winres.h>)
#include <winres.h>
#else
#include <afxres.h>
#include <winresrc.h>
#endif
#else
// MSVC, Windows SDK
#include <winres.h>
#endif
//IDI_ICON1 ICON PRODUCT_ICON
//LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILE_VERSION_RESOURCE
PRODUCTVERSION PRODUCT_VERSION_RESOURCE
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000904b0"
BEGIN
VALUE "Comments", PRODUCT_COMMENTS
VALUE "CompanyName", PRODUCT_COMPANY_NAME
VALUE "FileDescription", PRODUCT_FILE_DESCRIPTION
VALUE "FileVersion", FILE_VERSION_RESOURCE_STR
VALUE "InternalName", PRODUCT_INTERNAL_NAME
VALUE "LegalCopyright", PRODUCT_COMPANY_COPYRIGHT
VALUE "OriginalFilename", PRODUCT_ORIGINAL_FILENAME
VALUE "ProductName", PRODUCT_BUNDLE
VALUE "ProductVersion", PRODUCT_VERSION_RESOURCE_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x9, 1200
END
END

View File

@ -0,0 +1,107 @@
include (CMakeParseArguments)
set (GenerateProductVersionCurrentDir ${CMAKE_CURRENT_LIST_DIR})
# generate_product_version() function
#
# This function uses VersionInfo.in template file and VersionResource.rc file
# to generate WIN32 resource with version information and general resource strings.
#
# Usage:
# generate_product_version(
# SomeOutputResourceVariable
# NAME MyGreatProject
# ICON ${PATH_TO_APP_ICON}
# VERSION_MAJOR 2
# VERSION_MINOR 3
# VERSION_PATCH ${BUILD_COUNTER}
# VERSION_REVISION ${BUILD_REVISION}
# )
# where BUILD_COUNTER and BUILD_REVISION could be values from your CI server.
#
# You can use generated resource for your executable targets:
# add_executable(target-name ${target-files} ${SomeOutputResourceVariable})
#
# You can specify resource strings in arguments:
# NAME - name of executable (no defaults, ex: Microsoft Word)
# BUNDLE - bundle (${NAME} is default, ex: Microsoft Office)
# ICON - path to application icon (${CMAKE_SOURCE_DIR}/product.ico by default)
# VERSION_MAJOR - 1 is default
# VERSION_MINOR - 0 is default
# VERSION_PATCH - 0 is default
# VERSION_REVISION - 0 is default
# COMPANY_NAME - your company name (no defaults)
# COMPANY_COPYRIGHT - ${COMPANY_NAME} (C) Copyright ${CURRENT_YEAR} is default
# COMMENTS - ${NAME} v${VERSION_MAJOR}.${VERSION_MINOR} is default
# ORIGINAL_FILENAME - ${NAME} is default
# INTERNAL_NAME - ${NAME} is default
# FILE_DESCRIPTION - ${NAME} is default
function(generate_product_version outfiles)
set (options)
set (oneValueArgs
NAME
BUNDLE
ICON
VERSION_MAJOR
VERSION_MINOR
VERSION_PATCH
VERSION_REVISION
COMPANY_NAME
COMPANY_COPYRIGHT
COMMENTS
ORIGINAL_FILENAME
INTERNAL_NAME
FILE_DESCRIPTION)
set (multiValueArgs)
cmake_parse_arguments(PRODUCT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT PRODUCT_BUNDLE OR "${PRODUCT_BUNDLE}" STREQUAL "")
set(PRODUCT_BUNDLE "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_ICON OR "${PRODUCT_ICON}" STREQUAL "")
set(PRODUCT_ICON "${CMAKE_SOURCE_DIR}/product.ico")
endif()
if (NOT PRODUCT_VERSION_MAJOR EQUAL 0 AND (NOT PRODUCT_VERSION_MAJOR OR "${PRODUCT_VERSION_MAJOR}" STREQUAL ""))
set(PRODUCT_VERSION_MAJOR 1)
endif()
if (NOT PRODUCT_VERSION_MINOR EQUAL 0 AND (NOT PRODUCT_VERSION_MINOR OR "${PRODUCT_VERSION_MINOR}" STREQUAL ""))
set(PRODUCT_VERSION_MINOR 0)
endif()
if (NOT PRODUCT_VERSION_PATCH EQUAL 0 AND (NOT PRODUCT_VERSION_PATCH OR "${PRODUCT_VERSION_PATCH}" STREQUAL ""))
set(PRODUCT_VERSION_PATCH 0)
endif()
if (NOT PRODUCT_VERSION_REVISION EQUAL 0 AND (NOT PRODUCT_VERSION_REVISION OR "${PRODUCT_VERSION_REVISION}" STREQUAL ""))
set(PRODUCT_VERSION_REVISION 0)
endif()
if (NOT PRODUCT_COMPANY_COPYRIGHT OR "${PRODUCT_COMPANY_COPYRIGHT}" STREQUAL "")
string(TIMESTAMP PRODUCT_CURRENT_YEAR "%Y")
set(PRODUCT_COMPANY_COPYRIGHT "${PRODUCT_COMPANY_NAME} (C) Copyright ${PRODUCT_CURRENT_YEAR}")
endif()
if (NOT PRODUCT_COMMENTS OR "${PRODUCT_COMMENTS}" STREQUAL "")
set(PRODUCT_COMMENTS "${PRODUCT_NAME} v${PRODUCT_VERSION_MAJOR}.${PRODUCT_VERSION_MINOR}")
endif()
if (NOT PRODUCT_ORIGINAL_FILENAME OR "${PRODUCT_ORIGINAL_FILENAME}" STREQUAL "")
set(PRODUCT_ORIGINAL_FILENAME "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_INTERNAL_NAME OR "${PRODUCT_INTERNAL_NAME}" STREQUAL "")
set(PRODUCT_INTERNAL_NAME "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_FILE_DESCRIPTION OR "${PRODUCT_FILE_DESCRIPTION}" STREQUAL "")
set(PRODUCT_FILE_DESCRIPTION "${PRODUCT_NAME}")
endif()
set (_VersionInfoFile ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h)
set (_VersionResourceFile ${CMAKE_CURRENT_BINARY_DIR}/VersionResource.rc)
configure_file(
${GenerateProductVersionCurrentDir}/VersionInfo.in
${_VersionInfoFile}
@ONLY)
configure_file(
${GenerateProductVersionCurrentDir}/VersionResource.rc
${_VersionResourceFile}
COPYONLY)
list(APPEND ${outfiles} ${_VersionInfoFile} ${_VersionResourceFile})
set (${outfiles} ${${outfiles}} PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,14 @@
# Package Information for pkg-config
prefix=@PJSIP_ROOT_DIR_FOR_PKGCONFIG@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/pjlib/include;${prefix}/pjlib-util/include;${prefix}/pjmedia/include;${prefix}/pjnath/include;${prefix}/pjsip/include
Name: LunaHook
Description: Visual Novel Text Hook Engine
URL: https://github.com/HIllya51/LunaHook
Version: @PJSIP_VERSION@
Libs: -L${libdir} -llibpjproject-$$(Platform)-$$(PlatformToolset)-$$(Configuration)-@PJSIP_CRT_LINKAGE@.lib
Libs.private: -lWs2_32.lib
Cflags: -I${includedir}