diff --git a/app/backend.cpp b/app/backend.cpp index c0ed81e..44363a0 100644 --- a/app/backend.cpp +++ b/app/backend.cpp @@ -173,6 +173,19 @@ void Backend::setButton(int button, int32_t value) } } +void Backend::setRegion(int region) +{ + if (m_pipe) { + m_pipeMutex.lock(); + writeByte(m_pipeOut, VANILLA_PIPE_IN_REGION); + int8_t regionSized = region; + write(m_pipeOut, ®ionSized, sizeof(regionSized)); + m_pipeMutex.unlock(); + } else { + vanilla_set_region(region); + } +} + void Backend::sync(const QString &wirelessInterface, uint16_t code) { if (m_pipe) { diff --git a/app/backend.h b/app/backend.h index a975da2..68843fe 100644 --- a/app/backend.h +++ b/app/backend.h @@ -55,6 +55,7 @@ public slots: void updateTouch(int x, int y); void setButton(int button, int32_t value); void requestIDR(); + void setRegion(int region); private: BackendPipe *m_pipe; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 6e25c6d..1225f2e 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -102,16 +102,18 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) m_regionComboBox = new QComboBox(settingsGroupBox); - m_regionComboBox->addItem(tr("Japan")); - m_regionComboBox->addItem(tr("North America")); - m_regionComboBox->addItem(tr("Europe")); - m_regionComboBox->addItem(tr("China (Unused)")); - m_regionComboBox->addItem(tr("South Korea (Unused)")); - m_regionComboBox->addItem(tr("Taiwan (Unused)")); - m_regionComboBox->addItem(tr("Australia (Unused)")); + m_regionComboBox->addItem(tr("Japan"), VANILLA_REGION_JAPAN); + m_regionComboBox->addItem(tr("North America"), VANILLA_REGION_AMERICA); + m_regionComboBox->addItem(tr("Europe"), VANILLA_REGION_EUROPE); + m_regionComboBox->addItem(tr("China (Unused)"), VANILLA_REGION_CHINA); + m_regionComboBox->addItem(tr("South Korea (Unused)"), VANILLA_REGION_SOUTH_KOREA); + m_regionComboBox->addItem(tr("Taiwan (Unused)"), VANILLA_REGION_TAIWAN); + m_regionComboBox->addItem(tr("Australia (Unused)"), VANILLA_REGION_AUSTRALIA); - // TODO: Should probably save this somewhere - m_regionComboBox->setCurrentIndex(1); + // TODO: Should probably save/load this from a config file + m_regionComboBox->setCurrentIndex(VANILLA_REGION_AMERICA); + + connect(m_regionComboBox, &QComboBox::currentIndexChanged, this, &MainWindow::updateRegion); configLayout->addWidget(m_regionComboBox, row, 1); } @@ -337,6 +339,7 @@ void MainWindow::setConnectedState(bool on) QMetaObject::invokeMethod(m_backend, "connectToConsole", Qt::QueuedConnection, Q_ARG(QString, m_wirelessInterfaceComboBox->currentText())); updateVolumeAxis(); + updateRegion(); } else { if (m_backend) { m_backend->interrupt(); @@ -426,4 +429,9 @@ void MainWindow::takeScreenshot() } ss.save(s); } +} + +void MainWindow::updateRegion() +{ + m_backend->setRegion(m_regionComboBox->currentData().toInt()); } \ No newline at end of file diff --git a/app/mainwindow.h b/app/mainwindow.h index 9492950..d591e91 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -70,6 +70,8 @@ private slots: void volumeChanged(int val); + void updateRegion(); + void showInputConfigDialog(); void recordingError(int err); diff --git a/lib/gamepad/command.c b/lib/gamepad/command.c index 22fd665..1d6e824 100644 --- a/lib/gamepad/command.c +++ b/lib/gamepad/command.c @@ -53,16 +53,11 @@ typedef struct static_assert(offsetof(GenericPacket, generic_cmd_header) == 0x8); static_assert(sizeof(GenericPacket) == 0x61C); -enum Region +int current_region = VANILLA_REGION_AMERICA; +void set_region(int region) { - REGION_JAPAN = 0, - REGION_AMERICA = 1, - REGION_EUROPE = 2, - REGION_CHINA = 3, - REGION_SOUTH_KOREA = 4, - REGION_TAIWAN = 5, - REGION_AUSTRALIA = 6, -}; + current_region = region; +} typedef struct { @@ -265,8 +260,9 @@ void handle_generic_packet(int skt, GenericPacket *request) EEPROM *e = (EEPROM *)&response.payload[4]; - // TODO make this configurable - e->region = REGION_EUROPE;//REGION_AMERICA;//REGION_JAPAN; + print_info("Setting region to: %i", current_region); + + e->region = current_region; e->region_crc = crc16(&e->region, sizeof(e->region)); e->touchpad_calibration.new_min_x = htons(0); diff --git a/lib/gamepad/command.h b/lib/gamepad/command.h index bbac082..881cebb 100644 --- a/lib/gamepad/command.h +++ b/lib/gamepad/command.h @@ -3,4 +3,6 @@ void *listen_command(void *x); +void set_region(int region); + #endif // GAMEPAD_COMMAND_H \ No newline at end of file diff --git a/lib/vanilla.c b/lib/vanilla.c index 9c2050e..329d7f7 100644 --- a/lib/vanilla.c +++ b/lib/vanilla.c @@ -5,6 +5,7 @@ #include #include +#include "gamepad/command.h" #include "gamepad/gamepad.h" #include "gamepad/input.h" #include "gamepad/video.h" @@ -139,4 +140,9 @@ void vanilla_retrieve_sps_pps_data(void *data, size_t *size) memcpy(data, sps_pps_params, MIN(*size, sizeof(sps_pps_params))); } *size = sizeof(sps_pps_params); +} + +void vanilla_set_region(int region) +{ + set_region(region); } \ No newline at end of file diff --git a/lib/vanilla.h b/lib/vanilla.h index 951d6cb..7097dc2 100644 --- a/lib/vanilla.h +++ b/lib/vanilla.h @@ -64,6 +64,17 @@ enum VanillaEvent VANILLA_EVENT_VIBRATE }; +enum VanillaRegion +{ + VANILLA_REGION_JAPAN = 0, + VANILLA_REGION_AMERICA = 1, + VANILLA_REGION_EUROPE = 2, + VANILLA_REGION_CHINA = 3, + VANILLA_REGION_SOUTH_KOREA = 4, + VANILLA_REGION_TAIWAN = 5, + VANILLA_REGION_AUSTRALIA = 6, +}; + /** * Event handler used by caller to receive events */ @@ -142,6 +153,15 @@ void vanilla_request_idr(); */ void vanilla_retrieve_sps_pps_data(void *data, size_t *size); +/** + * Sets the region Vanilla should present itself to the console + * + * The gamepad is region locked and the console will complain if the gamepad doesn't match. + * + * Set to a member of the VanillaRegion enum. + */ +void vanilla_set_region(int region); + #if defined(__cplusplus) } #endif diff --git a/pipe/main.c b/pipe/main.c index 103d50c..5ccb64c 100644 --- a/pipe/main.c +++ b/pipe/main.c @@ -244,6 +244,13 @@ int main() vanilla_request_idr(); break; } + case VANILLA_PIPE_IN_REGION: + { + int8_t region; + read(fd_in, ®ion, sizeof(region)); + vanilla_set_region(region); + break; + } case VANILLA_PIPE_IN_QUIT: m_quit = 1; break; diff --git a/pipe/pipe.h b/pipe/pipe.h index 354bfd5..7ee7a37 100644 --- a/pipe/pipe.h +++ b/pipe/pipe.h @@ -7,6 +7,7 @@ #define VANILLA_PIPE_IN_BUTTON 0x03 #define VANILLA_PIPE_IN_TOUCH 0x04 #define VANILLA_PIPE_IN_REQ_IDR 0x05 +#define VANILLA_PIPE_IN_REGION 0x06 #define VANILLA_PIPE_IN_INTERRUPT 0x1E #define VANILLA_PIPE_IN_QUIT 0x1F