forked from zappatic/Spelunky2X64DbgPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
189 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <QDialog> | ||
#include <QLineEdit> | ||
#include <QSize> | ||
#include <QString> | ||
#include <QWidget> | ||
#include <cstdint> | ||
|
||
namespace S2Plugin | ||
{ | ||
enum class MemoryFieldType; | ||
|
||
class DialogEditString : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
// size without the last char (null termination) | ||
DialogEditString(const QString& fieldName, QString initialValue, uintptr_t memoryAddress, int size, MemoryFieldType type, QWidget* parent = nullptr); | ||
|
||
protected: | ||
QSize minimumSizeHint() const override; | ||
QSize sizeHint() const override; | ||
|
||
private slots: | ||
void cancelBtnClicked(); | ||
void changeBtnClicked(); | ||
|
||
private: | ||
QLineEdit* mLineEdit; | ||
uintptr_t mMemoryAddress; | ||
MemoryFieldType mFieldType; | ||
}; | ||
} // namespace S2Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "QtHelpers/DialogEditString.h" | ||
#include "Configuration.h" | ||
#include "QtPlugin.h" | ||
#include "pluginmain.h" | ||
#include <QGridLayout> | ||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
#include <QPushButton> | ||
#include <QVBoxLayout> | ||
#include <string> | ||
|
||
S2Plugin::DialogEditString::DialogEditString(const QString& fieldName, QString value, uintptr_t memoryAddress, int size, MemoryFieldType type, QWidget* parent) | ||
: QDialog(parent, Qt::WindowCloseButtonHint | Qt::WindowTitleHint), mMemoryAddress(memoryAddress), mFieldType(type) | ||
{ | ||
setModal(true); | ||
setWindowTitle("Change value"); | ||
setWindowIcon(getCavemanIcon()); | ||
auto layout = new QVBoxLayout(this); | ||
|
||
// FIELDS | ||
auto gridLayout = new QGridLayout(); | ||
|
||
gridLayout->addWidget(new QLabel(QString("Change value of %1").arg(fieldName), this), 0, 0, 1, 2); | ||
gridLayout->addWidget(new QLabel("New text:", this), 1, 0); | ||
|
||
mLineEdit = new QLineEdit(this); | ||
mLineEdit->setMaxLength(size); | ||
mLineEdit->setText(value); | ||
gridLayout->addWidget(mLineEdit, 1, 1); | ||
|
||
// BUTTONS | ||
auto buttonLayout = new QHBoxLayout(); | ||
|
||
auto cancelBtn = new QPushButton("Cancel", this); | ||
QObject::connect(cancelBtn, &QPushButton::clicked, this, &DialogEditString::cancelBtnClicked); | ||
cancelBtn->setAutoDefault(false); | ||
auto changeBtn = new QPushButton("Change", this); | ||
QObject::connect(changeBtn, &QPushButton::clicked, this, &DialogEditString::changeBtnClicked); | ||
changeBtn->setAutoDefault(true); | ||
|
||
buttonLayout->addStretch(); | ||
buttonLayout->addWidget(cancelBtn); | ||
buttonLayout->addWidget(changeBtn); | ||
|
||
layout->addLayout(gridLayout); | ||
layout->addStretch(); | ||
layout->addLayout(buttonLayout); | ||
|
||
mLineEdit->setFocus(); | ||
mLineEdit->selectAll(); | ||
} | ||
|
||
QSize S2Plugin::DialogEditString::minimumSizeHint() const | ||
{ | ||
|
||
return QSize(350, 150); | ||
} | ||
|
||
QSize S2Plugin::DialogEditString::sizeHint() const | ||
{ | ||
return minimumSizeHint(); | ||
} | ||
|
||
void S2Plugin::DialogEditString::cancelBtnClicked() | ||
{ | ||
reject(); | ||
} | ||
|
||
void S2Plugin::DialogEditString::changeBtnClicked() | ||
{ | ||
switch (mFieldType) | ||
{ | ||
case MemoryFieldType::UTF16Char: | ||
{ | ||
ushort v = mLineEdit->text().isEmpty() ? 0 : mLineEdit->text()[0].unicode(); | ||
Script::Memory::WriteWord(mMemoryAddress, v); | ||
break; | ||
} | ||
case MemoryFieldType::UTF16StringFixedSize: | ||
{ | ||
auto v = mLineEdit->text().toStdWString(); | ||
Script::Memory::Write(mMemoryAddress, v.data(), (v.size() + 1) * 2, nullptr); // +1 to include null character | ||
break; | ||
} | ||
case MemoryFieldType::ConstCharPointer: | ||
case MemoryFieldType::UTF8StringFixedSize: | ||
{ | ||
auto v = mLineEdit->text().toStdString(); | ||
Script::Memory::Write(mMemoryAddress, v.data(), v.size() + 1, nullptr); // +1 to include null character | ||
break; | ||
} | ||
} | ||
accept(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters