From d529048e9ba286af275d9cefc0ebae9800c34f76 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 1 May 2024 20:01:42 +0200 Subject: WIP packet injection --- src/frontend/qt_sdl/LocalMP.cpp | 6 +----- src/frontend/qt_sdl/Window.cpp | 45 +++++++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/Window.h | 6 ++++++ src/vsr.h | 13 ++++++++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/vsr.h diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index b2e307e..7fe4f64 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -16,11 +16,6 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ -// VSR-specific experiments - -// #define VSR_MESSAGE_FIDDLING 1 -#define VSR_DUMP_MESSAGES 1 - #include #include #include @@ -45,6 +40,7 @@ #include "Platform.h" #include +#include "../../vsr.h" #ifdef VSR_DUMP_MESSAGES #include diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 23ba784..d1f16a1 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -81,6 +81,37 @@ #include "ArchiveUtil.h" #include "CameraManager.h" +#include "../../vsr.h" + +#ifdef VSR_INJECTION +#include + +void MainWindow::injectPacket(int type) { + QString input_path = QFileDialog::getOpenFileName(this, + "Select packet data file", QDir::currentPath(), "Raw data (*.bin)"); + + if (input_path.length() == 0) { + printf("[VSR] inject packet aborted!\n"); + return; + } + + printf("[VSR] injecting %s...\n", input_path.toStdString().c_str()); + + std::ifstream is(input_path.toStdString()); + std::istream_iterator start(is), end; + std::vector buf(start, end); + + // TODO: is this melonDS::NDS::SysTimestamp??? + melonDS::u64 timestamp = 0; + + switch(type) { + case 0: return (void) LocalMP::SendPacket(buf.data(), buf.size(), timestamp); + case 1: return (void) LocalMP::SendCmd(buf.data(), buf.size(), timestamp); + case 3: return (void) LocalMP::SendAck(buf.data(), buf.size(), timestamp); + } +} +#endif + using namespace melonDS; // TEMP @@ -574,6 +605,20 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actAudioSync->setCheckable(true); connect(actAudioSync, &QAction::triggered, this, &MainWindow::onChangeAudioSync); } +#ifdef VSR_INJECTION + { + QMenu* menu = menubar->addMenu("Inject"); + + QAction* actInjectNormal = menu->addAction("Normal..."); + connect(actInjectNormal, &QAction::triggered, this, [this](){ injectPacket(0); }); + + QAction* actInjectCmd = menu->addAction("CMD..."); + connect(actInjectCmd, &QAction::triggered, this, [this](){ injectPacket(1); }); + + QAction* actInjectAck = menu->addAction("ACK..."); + connect(actInjectAck, &QAction::triggered, this, [this](){ injectPacket(3); }); + } +#endif setMenuBar(menubar); resize(Config::WindowWidth, Config::WindowHeight); diff --git a/src/frontend/qt_sdl/Window.h b/src/frontend/qt_sdl/Window.h index bc20748..f8d3e95 100644 --- a/src/frontend/qt_sdl/Window.h +++ b/src/frontend/qt_sdl/Window.h @@ -35,6 +35,8 @@ #include "Screen.h" +#include "../../vsr.h" + class EmuThread; @@ -223,6 +225,10 @@ private: void createScreenPanel(); +#ifdef VSR_INJECTION + void injectPacket(int type); +#endif + bool pausedManually = false; int oldW, oldH; diff --git a/src/vsr.h b/src/vsr.h new file mode 100644 index 0000000..78b4950 --- /dev/null +++ b/src/vsr.h @@ -0,0 +1,13 @@ +#pragma once + +/** This is a central file for contolling VSR-specific experiments */ + +// corrupt instance=0's messages after 20 seconds +// #define VSR_MESSAGE_FIDDLING + +// dump all sent Ni-Fi packets +// #define VSR_DUMP_MESSAGES + +// add "Inject" menu bar item +#define VSR_INJECTION + -- cgit v1.2.3