small bugfixes

This commit is contained in:
Akash Mozumdar 2018-09-23 01:08:33 -04:00
parent 524a0f362d
commit 3df68a6c2c
4 changed files with 11 additions and 17 deletions

View File

@ -115,7 +115,7 @@ namespace
case HOST_NOTIFICATION_TEXT: case HOST_NOTIFICATION_TEXT:
{ {
auto info = *(ConsoleOutputNotif*)buffer; auto info = *(ConsoleOutputNotif*)buffer;
Host::AddConsoleOutput(ToWString(info.message, CP_UTF8)); Host::AddConsoleOutput(StringToWideString(info.message, CP_UTF8));
} }
break; break;
default: default:
@ -256,7 +256,7 @@ namespace Host
ReadProcessMemory(pr.processHandle, hooks[i].hook_name, buffer.data(), hooks[i].name_length, nullptr); ReadProcessMemory(pr.processHandle, hooks[i].hook_name, buffer.data(), hooks[i].name_length, nullptr);
} }
ReleaseMutex(pr.sectionMutex); ReleaseMutex(pr.sectionMutex);
return ToWString(buffer.c_str(), CP_UTF8); return StringToWideString(buffer.c_str(), CP_UTF8);
} }
TextThread* GetThread(ThreadParam tp) TextThread* GetThread(ThreadParam tp)

View File

@ -29,10 +29,10 @@ namespace Host
void AddConsoleOutput(std::wstring text); void AddConsoleOutput(std::wstring text);
} }
inline std::wstring ToWString(const char* text, UINT encoding) inline std::wstring StringToWideString(const std::string& text, UINT encoding)
{ {
std::wstring ret(strlen(text), 0); std::wstring ret(text.size(), 0);
ret.resize(MultiByteToWideChar(encoding, 0, text, -1, ret.data(), ret.capacity())); ret.resize(MultiByteToWideChar(encoding, 0, text.c_str(), -1, ret.data(), ret.capacity()));
return ret; return ret;
} }

View File

@ -27,16 +27,10 @@ void TextThread::Flush()
std::wstring sentence; std::wstring sentence;
{ {
LOCK(ttMutex); LOCK(ttMutex);
if (buffer.size() < 400 && (GetTickCount() - timestamp < FlushDelay || buffer.size() == 0)) return; if (buffer.size() < 400 && (GetTickCount() - timestamp < FlushDelay || buffer.size() < 2)) return;
if (status & USING_UNICODE) sentence = status & USING_UNICODE
{ ? std::wstring((wchar_t*)buffer.data(), buffer.size() / 2)
sentence = std::wstring((wchar_t*)buffer.data(), buffer.size() / 2); : StringToWideString(std::string(buffer.data(), buffer.size()), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS);
}
else
{
buffer.push_back(0); // Null terminate
sentence = ToWString(buffer.data(), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS);
}
buffer.clear(); buffer.clear();
} }
AddSentence(sentence); AddSentence(sentence);

View File

@ -16,7 +16,7 @@ MainWindow::MainWindow(QWidget *parent) :
QSettings settings("NextHooker.ini", QSettings::IniFormat); QSettings settings("NextHooker.ini", QSettings::IniFormat);
if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect()); if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect());
// TODO: add GUI for changing this // TODO: add GUI for changing this
if (settings.contains("Flush_Delay")) TextThread::FlushDelay = settings.value("Flush Delay").toUInt(); if (settings.contains("Flush_Delay")) TextThread::FlushDelay = settings.value("Flush_Delay").toUInt();
processCombo = findChild<QComboBox*>("processCombo"); processCombo = findChild<QComboBox*>("processCombo");
ttCombo = findChild<QComboBox*>("ttCombo"); ttCombo = findChild<QComboBox*>("ttCombo");
@ -36,7 +36,7 @@ MainWindow::MainWindow(QWidget *parent) :
); );
ReloadExtensions(); ReloadExtensions();
Host::AddConsoleOutput(L"NextHooker beta v3.2.0 by Artikash\r\nSource code and more information available under GPLv3 at https://github.com/Artikash/NextHooker"); Host::AddConsoleOutput(L"NextHooker beta v3.2.1 by Artikash\r\nSource code and more information available under GPLv3 at https://github.com/Artikash/NextHooker");
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()