Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structs (Rebased) #203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ set(SRCS ${DolphinProcessSrc}
GUI/MemViewer/MemViewerWidget.cpp
GUI/MainWindow.cpp
GUI/Widgets/AddressInputWidget.cpp
GUI/StructEditor/StructEditorWidget.cpp
GUI/StructEditor/StructDetailModel.cpp
GUI/StructEditor/StructSelectModel.cpp
Structs/StructTreeNode.cpp
Structs/StructDef.cpp
Structs/FieldDef.cpp
Resources/resource.qrc
${ExeIconSrc}
main.cpp)
Expand Down
12 changes: 12 additions & 0 deletions Source/Common/MemoryCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ size_t getSizeForType(const MemType type, const size_t length)
return length;
case MemType::type_byteArray:
return length;
case MemType::type_struct:
return length;
default:
return 0;
}
Expand All @@ -96,6 +98,8 @@ bool shouldBeBSwappedForType(const MemType type)
return false;
case MemType::type_byteArray:
return false;
case MemType::type_struct:
return false;
default:
return false;
}
Expand All @@ -119,6 +123,8 @@ int getNbrBytesAlignmentForType(const MemType type)
return 1;
case MemType::type_byteArray:
return 1;
case MemType::type_struct:
return 1;
default:
return 1;
}
Expand Down Expand Up @@ -455,6 +461,12 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
index++;
}
actualLength = bytes.size();
break;
}

default:
{
break;
}
}
return buffer;
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/MemoryCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ enum class MemType
type_double,
type_string,
type_byteArray,
type_struct,
type_none // Placeholder for the entry of a child node of a collapsed container
};

enum class MemBase
Expand Down
15 changes: 14 additions & 1 deletion Source/GUI/GUICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ QStringList g_memTypeNames =
QCoreApplication::translate("Common", "Float"),
QCoreApplication::translate("Common", "Double"),
QCoreApplication::translate("Common", "String"),
QCoreApplication::translate("Common", "Array of bytes")});
QCoreApplication::translate("Common", "Array of bytes"),
QCoreApplication::translate("Common", "Struct")});

QStringList g_memBaseNames = QStringList({QCoreApplication::translate("Common", "Decimal"),
QCoreApplication::translate("Common", "Hexadecimal"),
Expand Down Expand Up @@ -46,6 +47,7 @@ QString getStringFromType(const Common::MemType type, const size_t length)
case Common::MemType::type_word:
case Common::MemType::type_float:
case Common::MemType::type_double:
case Common::MemType::type_struct:
return GUICommon::g_memTypeNames.at(static_cast<int>(type));
case Common::MemType::type_string:
return QString::fromStdString("string[" + std::to_string(length) + "]");
Expand Down Expand Up @@ -73,6 +75,17 @@ QString getNameFromBase(const Common::MemBase base)
}
}

bool isContainerType(const Common::MemType type)
{
switch (type)
{
case Common::MemType::type_struct:
return true;
default:
return false;
}
}

void changeApplicationStyle(const ApplicationStyle style)
{
QApplication::setStyle(QStringLiteral("fusion"));
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/GUICommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern QStringList g_memBaseNames;

QString getStringFromType(Common::MemType type, size_t length = 0);
QString getNameFromBase(Common::MemBase base);
bool isContainerType(Common::MemType type);

enum class ApplicationStyle
{
Expand Down
36 changes: 36 additions & 0 deletions Source/GUI/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MainWindow::MainWindow()
makeMenus();
DolphinComm::DolphinAccessor::init();
makeMemViewer();
makeStructEditor();

m_autoHookTimer.setInterval(1000);
connect(&m_autoHookTimer, &QTimer::timeout, this, &MainWindow::onHookIfNotHooked);
Expand All @@ -41,6 +42,9 @@ MainWindow::MainWindow()
GUICommon::changeApplicationStyle(
static_cast<GUICommon::ApplicationStyle>(SConfig::getInstance().getTheme()));

m_structEditor->restoreStructTree(SConfig::getInstance().getStructDefs());
m_watcher->setStructDefs(m_structEditor->getStructDefs(), m_structEditor->getStructMap());
m_viewer->setStructDefs(m_structEditor->getStructDefs());
m_actAutoloadLastFile->setChecked(SConfig::getInstance().getAutoloadLastFile());

if (m_actAutoloadLastFile->isChecked() && !SConfig::getInstance().getLastLoadedFile().isEmpty())
Expand All @@ -56,6 +60,20 @@ MainWindow::MainWindow()

m_actAutoHook->setChecked(SConfig::getInstance().getAutoHook());

// Connect struct updates to mem watch widget
connect(m_structEditor, &StructEditorWidget::updateStructName, m_watcher,
&MemWatchWidget::onUpdateStructName);
connect(m_structEditor, &StructEditorWidget::updateStructDetails, m_watcher,
&MemWatchWidget::onUpdateStructDetails);
connect(m_structEditor, &StructEditorWidget::structAddedRemoved, m_watcher,
&MemWatchWidget::onStructDefAddRemove);

// Connect load/save structs on load/save watch file
connect(m_watcher, &MemWatchWidget::loadStructDefsFromJson, m_structEditor,
&StructEditorWidget::readStructDefMapFromJson);
connect(m_watcher, &MemWatchWidget::writeStructDefsToJson, m_structEditor,
&StructEditorWidget::writeStructDefMapToJson);

if (m_actAutoHook->isChecked())
onHookAttempt();
else
Expand All @@ -67,6 +85,7 @@ MainWindow::~MainWindow()
delete m_copier;
delete m_viewer;
delete m_watcher;
delete m_structEditor;
DolphinComm::DolphinAccessor::free();
}

Expand Down Expand Up @@ -105,6 +124,7 @@ void MainWindow::makeMenus()
QSignalBlocker signalBlocker(m_actScanner);
m_actScanner->setChecked(m_splitter->sizes()[0] > 0);
});
m_actStructEditor = new QAction(tr("Struct &Editor"), this);

m_actQuit = new QAction(tr("&Quit"), this);
m_actAbout = new QAction(tr("&About"), this);
Expand Down Expand Up @@ -136,6 +156,7 @@ void MainWindow::makeMenus()
connect(m_actMemoryViewer, &QAction::triggered, this, &MainWindow::onOpenMenViewer);
connect(m_actCopyMemory, &QAction::triggered, this, &MainWindow::onCopyMemory);
connect(m_actScanner, &QAction::toggled, this, &MainWindow::onScannerActionToggled);
connect(m_actStructEditor, &QAction::triggered, this, &MainWindow::onOpenStructEditor);

connect(m_actQuit, &QAction::triggered, this, &MainWindow::onQuit);
connect(m_actAbout, &QAction::triggered, this, &MainWindow::onAbout);
Expand Down Expand Up @@ -169,6 +190,7 @@ void MainWindow::makeMenus()
m_menuView->addAction(m_actMemoryViewer);
m_menuView->addAction(m_actCopyMemory);
m_menuView->addAction(m_actScanner);
m_menuView->addAction(m_actStructEditor);

m_menuHelp = menuBar()->addMenu(tr("&Help"));
m_menuHelp->addAction(m_actAbout);
Expand Down Expand Up @@ -587,6 +609,12 @@ void MainWindow::onQuit()
close();
}

void MainWindow::onOpenStructEditor()
{
m_structEditor->show();
m_structEditor->raise();
}

void MainWindow::closeEvent(QCloseEvent* event)
{
SConfig::getInstance().setAutoHook(m_actAutoHook->isChecked());
Expand All @@ -597,6 +625,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
{
SConfig::getInstance().setWatchModel(m_watcher->saveWatchModel());
}
SConfig::getInstance().setStructDefs(m_structEditor->saveStructTree());
SConfig::getInstance().setMainWindowGeometry(saveGeometry());
SConfig::getInstance().setMainWindowState(saveState());

Expand All @@ -612,6 +641,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
}

m_viewer->close();
m_structEditor->close();
event->accept();
}

Expand Down Expand Up @@ -719,3 +749,9 @@ void MainWindow::updateStatusBar()
const QString toolTip{toolTipLines.join("\n\n")};
m_statusLabel->parentWidget()->setToolTip(toolTip);
}

void MainWindow::makeStructEditor()
{
m_structEditor = new StructEditorWidget(nullptr);
m_structEditor->setWindowIcon(windowIcon());
}
5 changes: 5 additions & 0 deletions Source/GUI/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MemScanner/MemScanWidget.h"
#include "MemViewer/MemViewerWidget.h"
#include "MemWatcher/MemWatchWidget.h"
#include "StructEditor/StructEditorWidget.h"

class MainWindow : public QMainWindow
{
Expand Down Expand Up @@ -58,20 +59,23 @@ class MainWindow : public QMainWindow
void onQuit();

void onAutoLoadLastFileTriggered(bool checked);
void onOpenStructEditor();

private:
void makeMenus();
void initialiseWidgets();
void makeLayouts();
void makeMemViewer();
void updateStatusBar();
void makeStructEditor();

QSplitter* m_splitter{};

MemWatchWidget* m_watcher{};
MemScanWidget* m_scanner{};
MemViewerWidget* m_viewer{};
DlgCopy* m_copier{};
StructEditorWidget* m_structEditor{};

QTimer m_autoHookTimer;

Expand All @@ -95,6 +99,7 @@ class MainWindow : public QMainWindow
QAction* m_actMemoryViewer{};
QAction* m_actCopyMemory{};
QAction* m_actScanner{};
QAction* m_actStructEditor{};
QAction* m_actQuit{};
QAction* m_actAbout{};
QLabel* m_statusIcon{};
Expand Down
8 changes: 7 additions & 1 deletion Source/GUI/MemViewer/MemViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ void MemViewer::memoryValidityChanged(const bool valid)
viewport()->update();
}

void MemViewer::setStructDefs(StructTreeNode* baseNode)
{
m_structDefs = baseNode;
}

void MemViewer::updateMemoryData()
{
std::swap(m_updatedRawMemoryData, m_lastRawMemoryData);
Expand Down Expand Up @@ -499,7 +504,8 @@ void MemViewer::addByteIndexAsWatch(int index)
{
MemWatchEntry* entry = new MemWatchEntry();
entry->setConsoleAddress(m_currentFirstAddress + index);
DlgAddWatchEntry dlg(true, entry, this);
DlgAddWatchEntry dlg(true, entry, m_structDefs->getStructNames(), this);

if (dlg.exec() == QDialog::Accepted)
{
emit addWatch(dlg.stealEntry());
Expand Down
4 changes: 4 additions & 0 deletions Source/GUI/MemViewer/MemViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../../Common/CommonTypes.h"
#include "../../Common/MemoryCommon.h"
#include "../../MemoryWatch/MemWatchEntry.h"
#include "../../Structs/StructTreeNode.h"

class MemViewer : public QAbstractScrollArea
{
Expand All @@ -38,6 +39,7 @@ class MemViewer : public QAbstractScrollArea
void jumpToAddress(u32 address);
void updateViewer();
void memoryValidityChanged(bool valid);
void setStructDefs(StructTreeNode* baseNode);

signals:
void memErrorOccured();
Expand Down Expand Up @@ -119,4 +121,6 @@ class MemViewer : public QAbstractScrollArea
QRect* m_curosrRect{};
QShortcut* m_copyShortcut{};
QElapsedTimer m_elapsedTimer;

StructTreeNode* m_structDefs;
};
5 changes: 5 additions & 0 deletions Source/GUI/MemViewer/MemViewerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ void MemViewerWidget::goToAddress(u32 address)
{
m_memViewer->jumpToAddress(address);
}

void MemViewerWidget::setStructDefs(StructTreeNode* baseNode)
{
m_memViewer->setStructDefs(baseNode);
}
2 changes: 2 additions & 0 deletions Source/GUI/MemViewer/MemViewerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "MemViewer.h"

#include "../../Structs/StructTreeNode.h"
#include "../Widgets/AddressInputWidget.h"

class MemViewerWidget : public QWidget
Expand All @@ -28,6 +29,7 @@ class MemViewerWidget : public QWidget
void hookStatusChanged(bool hook);
void onMEM2StatusChanged(bool enabled);
void goToAddress(u32 address);
void setStructDefs(StructTreeNode* baseNode);

signals:
void mustUnhook();
Expand Down
Loading
Loading