diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index b143edb..7d61e9f 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -13,6 +13,8 @@ extern const char* CONFIRM_EXTENSION_OVERWRITE; extern const char* EXTENSION_WRITE_ERROR; extern const char* EXTEN_WINDOW_INSTRUCTIONS; +constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repeated Characters>Remove Repeated Phrases>Regex Filter>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines"; + namespace { struct Extension diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 40be2d1..8cb7b71 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -31,7 +31,7 @@ void TextThread::Stop() timer = NULL; } -void TextThread::AddSentence(std::wstring&& sentence) +void TextThread::AddSentence(std::wstring sentence) { queuedSentences->emplace_back(std::move(sentence)); } diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 18c7a61..0456278 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -17,7 +17,7 @@ public: void Start(); void Stop(); - void AddSentence(std::wstring&& sentence); + void AddSentence(std::wstring sentence); void Push(BYTE* data, int length); Synchronized storage; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index a60cc24..b0bd1df 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -18,7 +18,8 @@ extern const char* SETTINGS; extern const char* EXTENSIONS; extern const char* SELECT_PROCESS; extern const char* ATTACH_INFO; -extern const char* SEARCH_GAME; +extern const char* SELECT_PROCESS_INFO; +extern const char* FROM_COMPUTER; extern const char* PROCESSES; extern const char* CODE_INFODUMP; extern const char* HOOK_SEARCH_UNSTABLE_WARNING; @@ -53,7 +54,7 @@ MainWindow::MainWindow(QWidget *parent) : extenWindow(new ExtenWindow(this)) { ui->setupUi(this); - for (auto [text, slot] : Array>{ + for (auto [text, slot] : Array>{ { ATTACH, &MainWindow::AttachProcess }, { LAUNCH, &MainWindow::LaunchProcess }, { DETACH, &MainWindow::DetachProcess }, @@ -66,9 +67,8 @@ MainWindow::MainWindow(QWidget *parent) : { EXTENSIONS, &MainWindow::Extensions } }) { - auto button = new QPushButton(ui->processFrame); + auto button = new QPushButton(text, ui->processFrame); connect(button, &QPushButton::clicked, this, slot); - button->setText(text); ui->processLayout->addWidget(button); } ui->processLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); @@ -154,7 +154,6 @@ void MainWindow::ProcessConnected(DWORD processId) QTextFile(GAME_SAVE_FILE, QIODevice::WriteOnly | QIODevice::Append).write((process + "\n").toUtf8()); QStringList allProcesses = QString(QTextFile(HOOK_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); - // Can't use QFileInfo::absoluteFilePath since hook save file has '\\' as path separator auto hookList = std::find_if(allProcesses.rbegin(), allProcesses.rend(), [&](QString hookList) { return hookList.contains(process); }); if (hookList != allProcesses.rend()) for (auto hookInfo : hookList->split(" , ")) @@ -173,7 +172,7 @@ void MainWindow::ProcessDisconnected(DWORD processId) void MainWindow::ThreadAdded(TextThread& thread) { std::wstring threadCode = Util::GenerateCode(thread.hp, thread.tp.processId); - QString ttString = TextThreadString(thread) + S(thread.name) + " (" + S(threadCode) + ")"; + QString ttString = TextThreadString(thread) + S(FormatString(L"(%s)", threadCode)); bool savedMatch = savedThreadCtx == thread.tp.ctx && savedThreadCtx2 == thread.tp.ctx2 && savedThreadCode == threadCode; if (savedMatch) savedThreadCtx = savedThreadCtx2 = savedThreadCode[0] = 0; QMetaObject::invokeMethod(this, [this, ttString, savedMatch] @@ -209,13 +208,13 @@ bool MainWindow::SentenceReceived(TextThread& thread, std::wstring& sentence) QString MainWindow::TextThreadString(TextThread& thread) { - return QString("%1:%2:%3:%4:%5: ").arg( + return QString("%1:%2:%3:%4:%5: %6 ").arg( QString::number(thread.handle, 16), QString::number(thread.tp.processId, 16), QString::number(thread.tp.addr, 16), QString::number(thread.tp.ctx, 16), QString::number(thread.tp.ctx2, 16) - ).toUpper(); + ).toUpper().arg(S(thread.name)); } ThreadParam MainWindow::ParseTextThreadString(QString ttString) @@ -233,9 +232,8 @@ std::array MainWindow::GetMiscInfo(TextThread& thread) { void(*AddSentence)(MainWindow*, int64_t, const wchar_t*) = [](MainWindow* This, int64_t number, const wchar_t* sentence) { - std::wstring copy = sentence; // pointer from Host::GetThread may not stay valid unless on main thread - QMetaObject::invokeMethod(This, [=]() mutable { if (TextThread* thread = Host::GetThread(number)) thread->AddSentence(std::move(copy)); }); + QMetaObject::invokeMethod(This, [number, sentence = std::wstring(sentence)] { if (TextThread* thread = Host::GetThread(number)) thread->AddSentence(sentence); }); }; return @@ -252,6 +250,18 @@ std::array MainWindow::GetMiscInfo(TextThread& thread) } }; } +std::optional MainWindow::UserSelectedProcess() +{ + QStringList savedProcesses = QString::fromUtf8(QTextFile(GAME_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); + std::reverse(savedProcesses.begin(), savedProcesses.end()); + savedProcesses.removeDuplicates(); + savedProcesses.insert(1, FROM_COMPUTER); + QString process = QInputDialog::getItem(this, SELECT_PROCESS, SELECT_PROCESS_INFO, savedProcesses, 0, true, &ok, Qt::WindowCloseButtonHint); + if (process == FROM_COMPUTER) process = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, SELECT_PROCESS, "C:\\", PROCESSES)); + if (ok && process.contains('\\')) return S(process); + return {}; +} + void MainWindow::AttachProcess() { QMultiHash allProcesses; @@ -267,14 +277,9 @@ void MainWindow::AttachProcess() void MainWindow::LaunchProcess() { - QStringList savedProcesses = QString::fromUtf8(QTextFile(GAME_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); - std::reverse(savedProcesses.begin(), savedProcesses.end()); - savedProcesses.removeDuplicates(); - savedProcesses.push_back(SEARCH_GAME); - std::wstring process = S(QInputDialog::getItem(this, SELECT_PROCESS, "", savedProcesses, 0, true, &ok, Qt::WindowCloseButtonHint)); - if (!ok) return; - if (S(process) == SEARCH_GAME) process = S(QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, SELECT_PROCESS, "C:\\", PROCESSES))); - if (process.find(L'\\') == std::wstring::npos) return; + std::wstring process; + if (auto selected = UserSelectedProcess()) process = selected.value(); + else return; std::wstring path = std::wstring(process).erase(process.rfind(L'\\')); PROCESS_INFORMATION info = {}; @@ -317,16 +322,16 @@ void MainWindow::DetachProcess() void MainWindow::ForgetProcess() { - if (auto processName = Util::GetModuleFilename(GetSelectedProcessId())) - { - for (auto file : { GAME_SAVE_FILE, HOOK_SAVE_FILE }) - { - QStringList lines = QString::fromUtf8(QTextFile(file, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); - lines.erase(std::remove_if(lines.begin(), lines.end(), [&](auto line) { return line.contains(S(processName.value())); }), lines.end()); - QTextFile(file, QIODevice::WriteOnly | QIODevice::Truncate).write(lines.join("\n").toUtf8()); - } - } + std::optional processName = Util::GetModuleFilename(GetSelectedProcessId()); + if (!processName) processName = UserSelectedProcess(); DetachProcess(); + if (!processName) return; + for (auto file : { GAME_SAVE_FILE, HOOK_SAVE_FILE }) + { + QStringList lines = QString::fromUtf8(QTextFile(file, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); + lines.erase(std::remove_if(lines.begin(), lines.end(), [&](auto line) { return line.contains(S(processName.value())); }), lines.end()); + QTextFile(file, QIODevice::WriteOnly | QIODevice::Truncate).write(lines.join("\n").append("\n").toUtf8()); + } } void MainWindow::AddHook() @@ -432,11 +437,7 @@ void MainWindow::FindHooks() { auto input = new QLineEdit(QString::number(value, 16), &dialog); layout.addRow(label, input); - connect(input, &QLineEdit::textEdited, [&value](QString input) - { - bool ok; - if (uintptr_t newValue = input.toULongLong(&ok, 16); ok) value = newValue; - }); + connect(input, &QLineEdit::textEdited, [&value](QString text) { if (uintptr_t newValue = text.toULongLong(&ok, 16); ok) value = newValue; }); } QLineEdit filterInput(".", &dialog); layout.addRow(HOOK_SEARCH_FILTER, &filterInput); diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 58664f5..d72fbcd 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -31,6 +31,7 @@ private: ThreadParam ParseTextThreadString(QString ttString); DWORD GetSelectedProcessId(); std::array GetMiscInfo(TextThread& thread); + std::optional UserSelectedProcess(); void AttachProcess(); void LaunchProcess(); void DetachProcess(); diff --git a/extensions/lua.cpp b/extensions/lua.cpp index c9925d1..5d6b677 100644 --- a/extensions/lua.cpp +++ b/extensions/lua.cpp @@ -80,7 +80,7 @@ private: QWidget centralWidget{ this }; QHBoxLayout layout{ ¢ralWidget }; - QPlainTextEdit scriptEditor{ std::string(std::istreambuf_iterator(std::ifstream(LUA_SAVE_FILE, std::ios::in)), {}).c_str(), ¢ralWidget }; + QPlainTextEdit scriptEditor{ S(std::string(std::istreambuf_iterator(std::ifstream(LUA_SAVE_FILE, std::ios::in)), {})), ¢ralWidget }; QPushButton loadButton{ LOAD_LUA_SCRIPT, ¢ralWidget }; } window; diff --git a/include/defs.h b/include/defs.h index 5ffb349..28e9b48 100644 --- a/include/defs.h +++ b/include/defs.h @@ -28,7 +28,6 @@ constexpr auto CONFIG_FILE = u8"Textractor.ini"; // Misc -constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repeated Characters>Remove Repeated Phrases>Regex Filter>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines"; constexpr auto WINDOW = u8"Window"; // EOF diff --git a/include/qtcommon.h b/include/qtcommon.h index ad3fe7e..03a28a3 100644 --- a/include/qtcommon.h +++ b/include/qtcommon.h @@ -22,4 +22,5 @@ struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } }; inline std::wstring S(const QString& S) { return { S.toStdWString() }; } +inline QString S(const std::string& S) { return QString::fromStdString(S); } inline QString S(const std::wstring& S) { return QString::fromStdWString(S); } diff --git a/text.cpp b/text.cpp index 3245d13..6cf8d05 100644 --- a/text.cpp +++ b/text.cpp @@ -19,7 +19,8 @@ const char* EXTENSIONS = u8"Extensions"; const char* SELECT_PROCESS = u8"Select process"; const char* ATTACH_INFO = u8R"(If you don't see the process you want to attach, try running with admin rights You can also type in the process id)"; -const char* SEARCH_GAME = u8"Select from computer"; +const char* SELECT_PROCESS_INFO = u8"If you manually type in the process file name, please use the absolute path"; +const char* FROM_COMPUTER = u8"Select from computer"; const char* PROCESSES = u8"Processes (*.exe)"; const char* CODE_INFODUMP = u8R"(Search for text S[codepage#]text @@ -207,7 +208,7 @@ Kaynak kodu GKLv3 koruması altında proje ana sayfasında mevcut SELECT_PROCESS = u8"Seleccionar procreso"; ATTACH_INFO = u8R"(Si no ves el proceso que quieras adjuntar, ejecuta este programa como administrador También puedes escribir la ID del proceso)"; - SEARCH_GAME = u8"Seleccionar desde computadora"; + FROM_COMPUTER = u8"Seleccionar desde computadora"; PROCESSES = u8"Procesos (*.exe)"; SAVE_SETTINGS = u8"Guardar opciones"; EXTEN_WINDOW_INSTRUCTIONS = u8R"(Arrrastra y suelta la extension (.dll) aquí desde tu computadora para añadirlos @@ -271,7 +272,7 @@ Clic y arrastra los bordes de la ventana para moverla, o en la esquina inferior SELECT_PROCESS = u8"选择进程"; ATTACH_INFO = u8R"(如果没看见想要附加的进程,尝试使用管理员权限运行 也可以手动输入进程ID)"; - SEARCH_GAME = u8"从计算机中选择"; + FROM_COMPUTER = u8"从计算机中选择"; PROCESSES = u8"进程 (*.exe)"; SAVE_SETTINGS = u8"保存设置"; EXTEN_WINDOW_INSTRUCTIONS = u8R"(从计算机拖拽扩展 (.dll) 文件到这里来添加 @@ -337,7 +338,7 @@ Clic y arrastra los bordes de la ventana para moverla, o en la esquina inferior SELECT_PROCESS = u8"Выберете процесс"; ATTACH_INFO = u8R"(Если вы не видите процесс, к которому хотите присоединить, попробуйте запуск с правами администратора Вы также можете ввести id процесса)"; - SEARCH_GAME = u8"Найти в проводнике"; + FROM_COMPUTER = u8"Найти в проводнике"; PROCESSES = u8"Процессы (*.exe)"; SAVE_SETTINGS = u8"Сохранить настройки"; EXTEN_WINDOW_INSTRUCTIONS = u8R"(Перетащите сюда (.dll) файлы расширений из проводника для их добавления @@ -442,7 +443,7 @@ end)"; SELECT_PROCESS = u8"Pilih Proses"; ATTACH_INFO = u8R"(Jika kamu tidak dapat melihat proses yang akan ditempelkan, coba menjalankan dengan mode administrator Kamu juga dapat mengetik process id game yang akan ditempel)"; - SEARCH_GAME = u8"Pilih dari komputer"; + FROM_COMPUTER = u8"Pilih dari komputer"; PROCESSES = u8"Proses (*.exe)"; SAVE_SETTINGS = u8"Simpan pengaturan"; EXTEN_WINDOW_INSTRUCTIONS = u8R"(Drag and drop file ekstensi (.dll) kedalam sini dari komputer kamu untuk menambah ekstensi @@ -507,7 +508,7 @@ Klik dan tarik pinggiran jendela untuk memindahkan, atau sudut kanan bawah untuk EXTENSIONS = u8"Extensões"; SELECT_PROCESS = u8"Selecionar Processo"; ATTACH_INFO = u8R"(Se você não encontrar o processo o qual deseja anexar a, tente iniciar com permissão de Administrador. Você também pode digitar a ID do processo)"; - SEARCH_GAME = u8"Busque no Computador"; + FROM_COMPUTER = u8"Busque no Computador"; PROCESSES = u8"Executaveis (*.exe)"; SAVE_SETTINGS = u8"Salvar opções"; EXTEN_WINDOW_INSTRUCTIONS = u8R"(Arraste e solte a extensão (.dll) aqui para adicioná-la.