From 3df68a6c2c9a80f060d733fa87f18d461c43ca8d Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 23 Sep 2018 01:08:33 -0400 Subject: [PATCH] small bugfixes --- GUI/host/host.cc | 4 ++-- GUI/host/host.h | 6 +++--- GUI/host/textthread.cc | 14 ++++---------- GUI/mainwindow.cpp | 4 ++-- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/GUI/host/host.cc b/GUI/host/host.cc index c91a99d..9a98dd0 100644 --- a/GUI/host/host.cc +++ b/GUI/host/host.cc @@ -115,7 +115,7 @@ namespace case HOST_NOTIFICATION_TEXT: { auto info = *(ConsoleOutputNotif*)buffer; - Host::AddConsoleOutput(ToWString(info.message, CP_UTF8)); + Host::AddConsoleOutput(StringToWideString(info.message, CP_UTF8)); } break; default: @@ -256,7 +256,7 @@ namespace Host ReadProcessMemory(pr.processHandle, hooks[i].hook_name, buffer.data(), hooks[i].name_length, nullptr); } ReleaseMutex(pr.sectionMutex); - return ToWString(buffer.c_str(), CP_UTF8); + return StringToWideString(buffer.c_str(), CP_UTF8); } TextThread* GetThread(ThreadParam tp) diff --git a/GUI/host/host.h b/GUI/host/host.h index 2aebd7e..0941749 100644 --- a/GUI/host/host.h +++ b/GUI/host/host.h @@ -29,10 +29,10 @@ namespace Host 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); - ret.resize(MultiByteToWideChar(encoding, 0, text, -1, ret.data(), ret.capacity())); + std::wstring ret(text.size(), 0); + ret.resize(MultiByteToWideChar(encoding, 0, text.c_str(), -1, ret.data(), ret.capacity())); return ret; } diff --git a/GUI/host/textthread.cc b/GUI/host/textthread.cc index bd129f3..b52cdc1 100644 --- a/GUI/host/textthread.cc +++ b/GUI/host/textthread.cc @@ -27,16 +27,10 @@ void TextThread::Flush() std::wstring sentence; { LOCK(ttMutex); - if (buffer.size() < 400 && (GetTickCount() - timestamp < FlushDelay || buffer.size() == 0)) return; - if (status & USING_UNICODE) - { - sentence = std::wstring((wchar_t*)buffer.data(), buffer.size() / 2); - } - else - { - buffer.push_back(0); // Null terminate - sentence = ToWString(buffer.data(), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS); - } + if (buffer.size() < 400 && (GetTickCount() - timestamp < FlushDelay || buffer.size() < 2)) return; + sentence = status & USING_UNICODE + ? std::wstring((wchar_t*)buffer.data(), buffer.size() / 2) + : StringToWideString(std::string(buffer.data(), buffer.size()), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS); buffer.clear(); } AddSentence(sentence); diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 8a86338..3433c85 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -16,7 +16,7 @@ MainWindow::MainWindow(QWidget *parent) : QSettings settings("NextHooker.ini", QSettings::IniFormat); if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect()); // 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("processCombo"); ttCombo = findChild("ttCombo"); @@ -36,7 +36,7 @@ MainWindow::MainWindow(QWidget *parent) : ); 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()