aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-01 20:01:42 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-01 20:01:42 +0200
commitd529048e9ba286af275d9cefc0ebae9800c34f76 (patch)
tree3932d770a2e32c05e11a4f01fae779a9a06785cc
parentffe81214b6bd99544d072545be47dac745786794 (diff)
WIP packet injection
-rw-r--r--src/frontend/qt_sdl/LocalMP.cpp6
-rw-r--r--src/frontend/qt_sdl/Window.cpp45
-rw-r--r--src/frontend/qt_sdl/Window.h6
-rw-r--r--src/vsr.h13
4 files changed, 65 insertions, 5 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -45,6 +40,7 @@
#include "Platform.h"
#include <stdint.h>
+#include "../../vsr.h"
#ifdef VSR_DUMP_MESSAGES
#include <pcap/pcap.h>
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 <fstream>
+
+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<uint8_t> start(is), end;
+ std::vector<uint8_t> 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
+