add basic extension support

This commit is contained in:
Akash Mozumdar 2018-05-25 04:34:40 -04:00
parent 0b79811cc3
commit 9715612b83
6 changed files with 68 additions and 32 deletions

View File

@ -0,0 +1,38 @@
#include <Windows.h>
#include <map>
typedef void(*ExtensionFunction)(LPCWSTR, DWORD64);
std::map<DWORD, ExtensionFunction> extensionFunctions;
void LoadExtensions()
{
wchar_t path[MAX_PATH];
wchar_t* end = path + GetModuleFileNameW(nullptr, path, MAX_PATH);
while (*(--end) != L'\\');
*(end + 1) = L'*';
*(end + 2) = L'\0';
WIN32_FIND_DATAW fileData;
HANDLE file = FindFirstFileW(path, &fileData);
do
{
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
}
else
{
if (wcsstr(fileData.cFileName, L"_nextvnr_extension.dll"))
{
extensionFunctions[wcstoul(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(LoadLibraryW(fileData.cFileName), "OnSentence");
}
}
} while (FindNextFileW(file, &fileData) != 0);
}
void DispatchSentenceToExtensions(LPCWSTR sentence, DWORD64 info)
{
for (auto extension : extensionFunctions)
{
extension.second(sentence, info);
}
}

View File

@ -0,0 +1,5 @@
#include <Windows.h>
typedef void(*ExtensionFunction)(LPCWSTR, DWORD64);
void LoadExtensions();
void DispatchSentenceToExtensions(LPCWSTR sentence, DWORD64 info);

View File

@ -25,6 +25,8 @@ set(vnrhost_src
# ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.cc
# ${PROJECT_SOURCE_DIR}/wintimer/wintimerbase.h
${PROJECT_SOURCE_DIR}/sakurakit/skdebug.h
${PROJECT_SOURCE_DIR}/extensions/Extensions.cpp
${PROJECT_SOURCE_DIR}/extensions/Extensions.h
)
add_library(vnrhost SHARED ${vnrhost_src})

View File

@ -18,6 +18,7 @@
#include "ithsys/ithsys.h"
#include "ccutil/ccmacro.h"
#include <commctrl.h>
#include "extensions/Extensions.h"
#define DEBUG "vnrhost/host.cc"
#include "sakurakit/skdebug.h"
@ -106,6 +107,7 @@ IHFSERVICE bool IHFAPI OpenHost()
}
else
{
LoadExtensions();
::running = true;
::settings = new Settings;
::man = new HookManager;

View File

@ -13,6 +13,7 @@
#include "vnrhook/include/const.h"
#include "ithsys/ithsys.h"
#include <stdio.h>
#include "extensions/Extensions.h"
MK_BASIC_TYPE(BYTE)
MK_BASIC_TYPE(ThreadParameter)
@ -36,10 +37,9 @@ void CALLBACK NewLineBuff(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
KillTimer(hwnd,idEvent);
TextThread *id=(TextThread*)idEvent;
if (id->Status()&CURRENT_SELECT)
//texts->SetLine();
id->CopyLastToClipboard();
id->DispatchLastSentence();
//id->SendLastToExtension();
id->SetNewLineFlag();
}
@ -649,43 +649,32 @@ DWORD TextThread::GetEntryString(LPSTR str, DWORD max)
// }
//}
static char clipboard_buffer[0x400];
// jichi 8/25/2013: clipboard removed
void CopyToClipboard(void* str,bool unicode, int len)
void DispatchSentence(void* str,DWORD status, int len)
{
if (settings->clipboardFlag && str && len > 0)
char sentenceBuffer[0x400];
if (str && len > 0)
{
int size=(len*2|0xF)+1;
if (len>=1022) return;
memcpy(clipboard_buffer,str,len);
*(WORD*)(clipboard_buffer+len)=0;
memcpy(sentenceBuffer,str,len);
*(WORD*)(sentenceBuffer+len)=0;
HGLOBAL hCopy;
LPWSTR copy;
if (OpenClipboard(0))
{
if (hCopy=GlobalAlloc(GMEM_MOVEABLE,size))
{
if (copy=(LPWSTR)GlobalLock(hCopy))
{
if (unicode)
{
memcpy(copy,clipboard_buffer,len+2);
}
else
copy[MB_WC(clipboard_buffer,copy)]=0;
GlobalUnlock(hCopy);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT,hCopy);
}
}
CloseClipboard();
}
wchar_t copy[0x200];
if (status&USING_UNICODE)
{
memcpy(copy, sentenceBuffer, len + 2);
}
else
copy[MB_WC(sentenceBuffer, copy)] = 0;
DispatchSentenceToExtensions(copy, status);
}
}
void TextThread::CopyLastToClipboard()
void TextThread::DispatchLastSentence()
{
// jichi 8/25/2013: clipboard removed
CopyToClipboard(storage+last_sentence,(status&USING_UNICODE)>0,used-last_sentence);
DispatchSentence(storage+last_sentence,status,used-last_sentence);
}
//void TextThread::ResetEditText()

View File

@ -62,7 +62,7 @@ public:
//void ResetEditText();
void ComboSelectCurrent();
void UnLinkAll();
void CopyLastToClipboard();
void DispatchLastSentence();
//void AdjustPrevRepeat(DWORD len);
//void PrevRepeatLength(DWORD &len);