Added Amiibo support (#1390)

* Fixed conflict with nfp

* Few fixups for nfc

* Conflict 2

* Fixed AttachAvailabilityChangeEvent

* Conflict 3

* Fixed byte padding

* Refactored amiibo to not reside in "System"

* Removed remaining references of nfc from system

* used enum for Nfc GetStateOld

* Added missing newline

* Moved file operations to front end

* Conflict 4

* Amiibos now use structs and added mutexes

* Removed amiibo_path
This commit is contained in:
David
2018-10-24 10:28:17 +11:00
committed by bunnei
parent 5edb2403c2
commit 50e4e81fd3
12 changed files with 386 additions and 80 deletions

View File

@ -122,6 +122,7 @@ void Config::ReadValues() {
qt_config->beginGroup("System");
Settings::values.use_docked_mode = qt_config->value("use_docked_mode", false).toBool();
Settings::values.enable_nfc = qt_config->value("enable_nfc", true).toBool();
Settings::values.username = qt_config->value("username", "yuzu").toString().toStdString();
Settings::values.language_index = qt_config->value("language_index", 1).toInt();
qt_config->endGroup();
@ -258,6 +259,7 @@ void Config::SaveValues() {
qt_config->beginGroup("System");
qt_config->setValue("use_docked_mode", Settings::values.use_docked_mode);
qt_config->setValue("enable_nfc", Settings::values.enable_nfc);
qt_config->setValue("username", QString::fromStdString(Settings::values.username));
qt_config->setValue("language_index", Settings::values.language_index);
qt_config->endGroup();

View File

@ -31,6 +31,7 @@ void ConfigureGeneral::setConfiguration() {
ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme));
ui->use_cpu_jit->setChecked(Settings::values.use_cpu_jit);
ui->use_docked_mode->setChecked(Settings::values.use_docked_mode);
ui->enable_nfc->setChecked(Settings::values.enable_nfc);
}
void ConfigureGeneral::PopulateHotkeyList(const HotkeyRegistry& registry) {
@ -45,4 +46,5 @@ void ConfigureGeneral::applyConfiguration() {
Settings::values.use_cpu_jit = ui->use_cpu_jit->isChecked();
Settings::values.use_docked_mode = ui->use_docked_mode->isChecked();
Settings::values.enable_nfc = ui->enable_nfc->isChecked();
}

View File

@ -68,19 +68,26 @@
<property name="title">
<string>Emulation</string>
</property>
<layout class="QHBoxLayout" name="EmulationHorizontalLayout">
<layout class="QHBoxLayout" name="EmulationHorizontalLayout">
<item>
<layout class="QVBoxLayout" name="EmulationVerticalLayout">
<item>
<layout class="QVBoxLayout" name="EmulationVerticalLayout">
<item>
<widget class="QCheckBox" name="use_docked_mode">
<property name="text">
<string>Enable docked mode</string>
</property>
</widget>
</item>
</layout>
<widget class="QCheckBox" name="use_docked_mode">
<property name="text">
<string>Enable docked mode</string>
</property>
</widget>
</item>
</layout>
<item>
<widget class="QCheckBox" name="enable_nfc">
<property name="text">
<string>Enable NFC</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>

View File

@ -60,6 +60,8 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
#include "core/hle/kernel/process.h"
#include "core/hle/service/filesystem/filesystem.h"
#include "core/hle/service/filesystem/fsp_ldr.h"
#include "core/hle/service/nfp/nfp.h"
#include "core/hle/service/sm/sm.h"
#include "core/loader/loader.h"
#include "core/perf_stats.h"
#include "core/settings.h"
@ -424,6 +426,7 @@ void GMainWindow::ConnectMenuEvents() {
connect(ui.action_Select_SDMC_Directory, &QAction::triggered, this,
[this] { OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget::SDMC); });
connect(ui.action_Exit, &QAction::triggered, this, &QMainWindow::close);
connect(ui.action_Load_Amiibo, &QAction::triggered, this, &GMainWindow::OnLoadAmiibo);
// Emulation
connect(ui.action_Start, &QAction::triggered, this, &GMainWindow::OnStartGame);
@ -692,6 +695,7 @@ void GMainWindow::ShutdownGame() {
ui.action_Stop->setEnabled(false);
ui.action_Restart->setEnabled(false);
ui.action_Report_Compatibility->setEnabled(false);
ui.action_Load_Amiibo->setEnabled(false);
render_window->hide();
game_list->show();
game_list->setFilterFocus();
@ -1191,6 +1195,7 @@ void GMainWindow::OnStartGame() {
ui.action_Report_Compatibility->setEnabled(true);
discord_rpc->Update();
ui.action_Load_Amiibo->setEnabled(true);
}
void GMainWindow::OnPauseGame() {
@ -1295,6 +1300,27 @@ void GMainWindow::OnConfigure() {
}
}
void GMainWindow::OnLoadAmiibo() {
const QString extensions{"*.bin"};
const QString file_filter = tr("Amiibo File (%1);; All Files (*.*)").arg(extensions);
const QString filename = QFileDialog::getOpenFileName(this, tr("Load Amiibo"), "", file_filter);
if (!filename.isEmpty()) {
Core::System& system{Core::System::GetInstance()};
Service::SM::ServiceManager& sm = system.ServiceManager();
auto nfc = sm.GetService<Service::NFP::Module::Interface>("nfp:user");
if (nfc != nullptr) {
auto nfc_file = FileUtil::IOFile(filename.toStdString(), "rb");
if (!nfc_file.IsOpen()) {
return;
}
std::vector<u8> amiibo_buffer(nfc_file.GetSize());
nfc_file.ReadBytes(amiibo_buffer.data(), amiibo_buffer.size());
nfc_file.Close();
nfc->LoadAmiibo(amiibo_buffer);
}
}
}
void GMainWindow::OnAbout() {
AboutDialog aboutDialog(this);
aboutDialog.exec();
@ -1335,15 +1361,17 @@ void GMainWindow::UpdateStatusBar() {
void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
QMessageBox::StandardButton answer;
QString status_message;
const QString common_message = tr(
"The game you are trying to load requires additional files from your Switch to be dumped "
"before playing.<br/><br/>For more information on dumping these files, please see the "
"following wiki page: <a "
"href='https://yuzu-emu.org/wiki/"
"dumping-system-archives-and-the-shared-fonts-from-a-switch-console/'>Dumping System "
"Archives and the Shared Fonts from a Switch Console</a>.<br/><br/>Would you like to quit "
"back to the game list? Continuing emulation may result in crashes, corrupted save "
"data, or other bugs.");
const QString common_message =
tr("The game you are trying to load requires additional files from your Switch to be "
"dumped "
"before playing.<br/><br/>For more information on dumping these files, please see the "
"following wiki page: <a "
"href='https://yuzu-emu.org/wiki/"
"dumping-system-archives-and-the-shared-fonts-from-a-switch-console/'>Dumping System "
"Archives and the Shared Fonts from a Switch Console</a>.<br/><br/>Would you like to "
"quit "
"back to the game list? Continuing emulation may result in crashes, corrupted save "
"data, or other bugs.");
switch (result) {
case Core::System::ResultStatus::ErrorSystemFiles: {
QString message = "yuzu was unable to locate a Switch system archive";
@ -1374,9 +1402,12 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det
this, tr("Fatal Error"),
tr("yuzu has encountered a fatal error, please see the log for more details. "
"For more information on accessing the log, please see the following page: "
"<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How to "
"Upload the Log File</a>.<br/><br/>Would you like to quit back to the game list? "
"Continuing emulation may result in crashes, corrupted save data, or other bugs."),
"<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How "
"to "
"Upload the Log File</a>.<br/><br/>Would you like to quit back to the game "
"list? "
"Continuing emulation may result in crashes, corrupted save data, or other "
"bugs."),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
status_message = "Fatal Error encountered";
break;

View File

@ -166,6 +166,7 @@ private slots:
void OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget target);
void OnMenuRecentFile();
void OnConfigure();
void OnLoadAmiibo();
void OnAbout();
void OnToggleFilterBar();
void OnDisplayTitleBars(bool);

View File

@ -57,8 +57,8 @@
<string>Recent Files</string>
</property>
</widget>
<addaction name="action_Install_File_NAND" />
<addaction name="separator"/>
<addaction name="action_Install_File_NAND"/>
<addaction name="separator"/>
<addaction name="action_Load_File"/>
<addaction name="action_Load_Folder"/>
<addaction name="separator"/>
@ -68,6 +68,8 @@
<addaction name="action_Select_NAND_Directory"/>
<addaction name="action_Select_SDMC_Directory"/>
<addaction name="separator"/>
<addaction name="action_Load_Amiibo"/>
<addaction name="separator"/>
<addaction name="action_Exit"/>
</widget>
<widget class="QMenu" name="menu_Emulation">
@ -117,11 +119,14 @@
<addaction name="menu_Tools" />
<addaction name="menu_Help"/>
</widget>
<action name="action_Install_File_NAND">
<property name="text">
<string>Install File to NAND...</string>
</property>
</action>
<action name="action_Install_File_NAND">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Install File to NAND...</string>
</property>
</action>
<action name="action_Load_File">
<property name="text">
<string>Load File...</string>
@ -253,6 +258,14 @@
<string>Restart</string>
</property>
</action>
<action name="action_Load_Amiibo">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Load Amiibo...</string>
</property>
</action>
<action name="action_Report_Compatibility">
<property name="enabled">
<bool>false</bool>