update build stuff and add the starter extensions
This commit is contained in:
parent
9733cca628
commit
8711332f77
@ -29,5 +29,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Build)
|
||||
set(CMAKE_CONFIGURATION_TYPES Debug Release)
|
||||
|
||||
add_subdirectory(host)
|
||||
add_subdirectory(vnrhook)
|
||||
add_subdirectory(GUI)
|
||||
add_subdirectory(vnrhook)
|
||||
add_subdirectory(extensions)
|
||||
|
@ -30,7 +30,7 @@
|
||||
"inheritEnvironments": [ "msvc_x64" ],
|
||||
"buildRoot": "${workspaceRoot}\\Builds\\${name}",
|
||||
"installRoot": "${workspaceRoot}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "-Dx64=1",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
},
|
||||
@ -41,7 +41,7 @@
|
||||
"inheritEnvironments": [ "msvc_x64" ],
|
||||
"buildRoot": "${workspaceRoot}\\Builds\\${name}",
|
||||
"installRoot": "${workspaceRoot}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "-Dx64=1",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
}
|
||||
|
5
extensions/CMakeLists.txt
Normal file
5
extensions/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
cmake_policy(SET CMP0037 OLD)
|
||||
add_library(1_Remove\ Repetition_nexthooker_extension SHARED removerepeat.cpp)
|
||||
add_library(2_Copy\ to\ Clipboard_nexthooker_extension SHARED copyclipboard.cpp)
|
||||
#add_library("3_Google\ Translate_nexthooker_extension" SHARED googletranslate.cpp)
|
||||
add_library(4_Extra\ Newlines_nexthooker_extension SHARED extranewlines.cpp)
|
28
extensions/copyclipboard.cpp
Normal file
28
extensions/copyclipboard.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "extensions.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
/**
|
||||
* Param sentence: pointer to sentence received by NextHooker (UTF-16).
|
||||
* You should not modify this sentence. If you want NextHooker to receive a modified sentence, copy it into your own buffer and return that.
|
||||
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
|
||||
* Return value: pointer to sentence NextHooker takes for future processing and display.
|
||||
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
|
||||
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it.
|
||||
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
|
||||
*/
|
||||
__declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
|
||||
{
|
||||
if (GetProperty("current select", miscInfo) && GetProperty("text number", miscInfo) > 0)
|
||||
{
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (wcslen(sentence) + 1) * sizeof(wchar_t));
|
||||
memcpy(GlobalLock(hMem), sentence, (wcslen(sentence) + 1) * sizeof(wchar_t));
|
||||
GlobalUnlock(hMem);
|
||||
OpenClipboard(0);
|
||||
EmptyClipboard();
|
||||
SetClipboardData(CF_UNICODETEXT, hMem);
|
||||
CloseClipboard();
|
||||
}
|
||||
return sentence;
|
||||
}
|
||||
}
|
21
extensions/extensions.h
Normal file
21
extensions/extensions.h
Normal file
@ -0,0 +1,21 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
|
||||
struct InfoForExtension
|
||||
{
|
||||
const char* propertyName;
|
||||
int propertyValue;
|
||||
InfoForExtension* nextProperty;
|
||||
};
|
||||
|
||||
// Traverses linked list to find info.
|
||||
int GetProperty(const char* propertyName, const InfoForExtension* miscInfo)
|
||||
{
|
||||
const InfoForExtension* miscInfoTraverser = miscInfo;
|
||||
while (miscInfoTraverser != nullptr)
|
||||
if (strcmp(propertyName, miscInfoTraverser->propertyName) == 0) return miscInfoTraverser->propertyValue;
|
||||
else miscInfoTraverser = miscInfoTraverser->nextProperty;
|
||||
|
||||
return 0;
|
||||
}
|
21
extensions/extranewlines.cpp
Normal file
21
extensions/extranewlines.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "extensions.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
/**
|
||||
* Param sentence: pointer to sentence received by NextHooker (UTF-16).
|
||||
* You should not modify this sentence. If you want NextHooker to receive a modified sentence, copy it into your own buffer and return that.
|
||||
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
|
||||
* Return value: pointer to sentence NextHooker takes for future processing and display.
|
||||
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
|
||||
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it.
|
||||
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
|
||||
*/
|
||||
__declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
|
||||
{
|
||||
if (GetProperty("text number", miscInfo) == 0) return sentence;
|
||||
wchar_t* newSentence = (wchar_t*)malloc((wcslen(sentence) + 6) * sizeof(wchar_t));
|
||||
swprintf(newSentence, wcslen(sentence) + 6, L"%s\r\n", sentence);
|
||||
return newSentence;
|
||||
}
|
||||
}
|
17
extensions/googletranslate.cpp
Normal file
17
extensions/googletranslate.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "extensions.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
/**
|
||||
* Param sentence: pointer to sentence received by NextHooker (UTF-16).
|
||||
* You should not modify this sentence. If you want NextHooker to receive a modified sentence, copy it into your own buffer and return that.
|
||||
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
|
||||
* Return value: pointer to sentence NextHooker takes for future processing and display.
|
||||
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
|
||||
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it.
|
||||
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
|
||||
*/
|
||||
__declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
|
||||
{
|
||||
}
|
||||
}
|
46
extensions/removerepeat.cpp
Normal file
46
extensions/removerepeat.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "extensions.h"
|
||||
#include <algorithm>
|
||||
#include <cwctype>
|
||||
|
||||
std::wstring remove_side_spaces(const std::wstring& str)
|
||||
{
|
||||
auto begin = std::find_if_not(str.begin(), str.end(), std::iswspace);
|
||||
if (begin == str.end()) return L"";
|
||||
auto end = std::find_if_not(str.rbegin(), str.rend(), std::iswspace);
|
||||
return std::wstring(begin, end.base());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
/**
|
||||
* Param sentence: pointer to sentence received by NextHooker (UTF-16).
|
||||
* You should not modify this sentence. If you want NextHooker to receive a modified sentence, copy it into your own buffer and return that.
|
||||
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
|
||||
* Return value: pointer to sentence NextHooker takes for future processing and display.
|
||||
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
|
||||
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it.
|
||||
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
|
||||
*/
|
||||
__declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
|
||||
{
|
||||
std::wstring sentenceStr = remove_side_spaces(std::wstring(sentence));
|
||||
unsigned long repeatNumber = 0;
|
||||
wchar_t prevChar = sentenceStr[0];
|
||||
for (auto i : sentenceStr)
|
||||
if (i == prevChar) repeatNumber++;
|
||||
else break;
|
||||
|
||||
for (int i = 0; i < sentenceStr.size(); i += repeatNumber)
|
||||
for (int j = i; j < sentenceStr.size(); ++j)
|
||||
if (sentenceStr[j] != sentenceStr[i])
|
||||
if ((j - i) % repeatNumber != 0) return sentence;
|
||||
else break;
|
||||
|
||||
if (repeatNumber == 1) return sentence;
|
||||
sentenceStr.erase(std::remove_if(sentenceStr.begin(), sentenceStr.end(), [&](const wchar_t& c) {return (&c - &*sentenceStr.begin()) % repeatNumber != 0; }), sentenceStr.end());
|
||||
|
||||
wchar_t* newSentence = (wchar_t*)malloc((sentenceStr.size() + 2) * sizeof(wchar_t));
|
||||
wcscpy(newSentence, sentenceStr.c_str());
|
||||
return newSentence;
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
project(host)
|
||||
|
||||
set(vnrhost_src
|
||||
host.h
|
||||
pipe.h
|
||||
|
@ -1,8 +1,6 @@
|
||||
project(vnrhook)
|
||||
include_directories(.)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if (${x64})
|
||||
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
|
||||
set(vnrhook_src
|
||||
include/const.h
|
||||
include/defs.h
|
||||
@ -13,7 +11,7 @@ set(vnrhook_src
|
||||
src/util/ithsys/ithsys.cc
|
||||
src/hijack/texthook.cc
|
||||
)
|
||||
else(${x64})
|
||||
else()
|
||||
set(vnrhook_src
|
||||
include/const.h
|
||||
include/defs.h
|
||||
@ -45,7 +43,7 @@ set(vnrhook_src
|
||||
src/util/mono/monoobject.h
|
||||
src/util/mono/monotype.h
|
||||
)
|
||||
endif(${x64})
|
||||
endif()
|
||||
|
||||
include_directories(src/util)
|
||||
|
||||
|
@ -87,8 +87,8 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID unused)
|
||||
VirtualQuery((void*)::processStopAddress, &info, sizeof(info));
|
||||
::processStopAddress = (DWORD)info.BaseAddress + info.RegionSize;
|
||||
} while (info.Protect > PAGE_NOACCESS);
|
||||
#endif
|
||||
processStopAddress -= info.RegionSize;
|
||||
#endif
|
||||
|
||||
{
|
||||
wchar_t hm_mutex[0x100];
|
||||
|
Loading…
Reference in New Issue
Block a user