forked from Public-Mirror/Textractor
refactor
This commit is contained in:
parent
7a059cc2e0
commit
4dc7b236c9
@ -6,7 +6,6 @@
|
||||
#include "const.h"
|
||||
#include "defs.h"
|
||||
#include "../vnrhook/hijack/texthook.h"
|
||||
#include <atlbase.h> // A2W
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -116,8 +115,7 @@ namespace
|
||||
case HOST_NOTIFICATION_TEXT:
|
||||
{
|
||||
auto info = *(ConsoleOutputNotif*)buffer;
|
||||
USES_CONVERSION;
|
||||
Host::AddConsoleOutput(A2W(info.message));
|
||||
Host::AddConsoleOutput(ToWString(info.message, CP_UTF8));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -255,11 +253,10 @@ namespace Host
|
||||
if (hooks[i].hp.address == addr)
|
||||
{
|
||||
buffer.resize(hooks[i].name_length);
|
||||
ReadProcessMemory(pr.processHandle, hooks[i].hook_name, &buffer[0], hooks[i].name_length, nullptr);
|
||||
ReadProcessMemory(pr.processHandle, hooks[i].hook_name, buffer.data(), hooks[i].name_length, nullptr);
|
||||
}
|
||||
ReleaseMutex(pr.sectionMutex);
|
||||
USES_CONVERSION;
|
||||
return std::wstring(A2W(buffer.c_str()));
|
||||
return ToWString(buffer.c_str(), CP_UTF8);
|
||||
}
|
||||
|
||||
TextThread* GetThread(ThreadParam tp)
|
||||
|
@ -28,4 +28,12 @@ namespace Host
|
||||
TextThread* GetThread(ThreadParam tp);
|
||||
void AddConsoleOutput(std::wstring text);
|
||||
}
|
||||
|
||||
inline std::wstring ToWString(const char* text, UINT encoding)
|
||||
{
|
||||
std::wstring ret(strlen(text), 0);
|
||||
ret.resize(MultiByteToWideChar(encoding, 0, text, -1, ret.data(), ret.size()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -27,17 +27,9 @@ void TextThread::Flush()
|
||||
std::wstring sentence;
|
||||
{
|
||||
LOCK(ttMutex);
|
||||
if (buffer.size() < 400 && (GetTickCount() - timestamp < 250 || buffer.size() == 0)) return; // TODO: let user change delay before sentence is flushed
|
||||
if (status & USING_UNICODE)
|
||||
{
|
||||
sentence = std::wstring((wchar_t*)buffer.data(), buffer.size() / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t* converted = new wchar_t[buffer.size()];
|
||||
sentence = std::wstring(converted, MultiByteToWideChar(status & USING_UTF8 ? CP_UTF8 : 932, 0, buffer.data(), buffer.size(), converted, buffer.size()));
|
||||
delete[] converted;
|
||||
}
|
||||
if (buffer.size() < 400 && (GetTickCount() - timestamp < flushDelay || buffer.size() == 0)) return; // TODO: let user change delay before sentence is flushed
|
||||
if (status & USING_UNICODE) sentence = std::wstring((wchar_t*)buffer.data(), buffer.size() / 2);
|
||||
else sentence = ToWString(buffer.data(), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS);
|
||||
buffer.clear();
|
||||
}
|
||||
AddSentence(sentence);
|
||||
|
@ -24,6 +24,8 @@ public:
|
||||
const std::wstring name;
|
||||
const ThreadParam tp;
|
||||
|
||||
inline static unsigned flushDelay = 250; // flush every 250ms by default
|
||||
|
||||
private:
|
||||
void Flush();
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
// 8/23/2013 jichi
|
||||
// Branch: ITH/common.h, rev 128
|
||||
|
||||
enum { MESSAGE_SIZE = 500, PIPE_BUFFER_SIZE = 0x1000 };
|
||||
enum { MESSAGE_SIZE = 500, PIPE_BUFFER_SIZE = 0x1000, SHIFT_JIS = 932 };
|
||||
|
||||
// jichi 375/2014: Add offset of pusha/pushad
|
||||
// http://faydoc.tripod.com/cpu/pushad.htm
|
||||
|
Loading…
x
Reference in New Issue
Block a user