| 1 | // Copyright 2015 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/MenuBar.h" |
| 5 | |
| 6 | #include <future> |
| 7 | |
| 8 | #include <QAction> |
| 9 | #include <QActionGroup> |
| 10 | #include <QDesktopServices> |
| 11 | #include <QDirIterator> |
| 12 | #include <QFileDialog> |
| 13 | #include <QFontDialog> |
| 14 | #include <QInputDialog> |
| 15 | #include <QMap> |
| 16 | #include <QUrl> |
| 17 | |
| 18 | #include <fmt/format.h> |
| 19 | |
| 20 | #include "Common/Align.h" |
| 21 | #include "Common/CommonPaths.h" |
| 22 | #include "Common/FileUtil.h" |
| 23 | #include "Common/IOFile.h" |
| 24 | |
| 25 | #include "Core/AchievementManager.h" |
| 26 | #include "Core/CommonTitles.h" |
| 27 | #include "Core/Config/MainSettings.h" |
| 28 | #include "Core/ConfigManager.h" |
| 29 | #include "Core/Core.h" |
| 30 | #include "Core/Debugger/RSO.h" |
| 31 | #include "Core/HLE/HLE.h" |
| 32 | #include "Core/HW/AddressSpace.h" |
| 33 | #include "Core/HW/Memmap.h" |
| 34 | #include "Core/HW/WiiSave.h" |
| 35 | #include "Core/IOS/ES/ES.h" |
| 36 | #include "Core/IOS/FS/FileSystem.h" |
| 37 | #include "Core/IOS/IOS.h" |
| 38 | #include "Core/IOS/USB/Bluetooth/BTEmu.h" |
| 39 | #include "Core/Movie.h" |
| 40 | #include "Core/NetPlayProto.h" |
| 41 | #include "Core/PowerPC/JitInterface.h" |
| 42 | #include "Core/PowerPC/MMU.h" |
| 43 | #include "Core/PowerPC/PPCAnalyst.h" |
| 44 | #include "Core/PowerPC/PPCSymbolDB.h" |
| 45 | #include "Core/PowerPC/PowerPC.h" |
| 46 | #include "Core/PowerPC/SignatureDB/SignatureDB.h" |
| 47 | #include "Core/State.h" |
| 48 | #include "Core/System.h" |
| 49 | #include "Core/WiiUtils.h" |
| 50 | |
| 51 | #include "DiscIO/Enums.h" |
| 52 | #include "DiscIO/NANDImporter.h" |
| 53 | |
| 54 | #include "DolphinQt/Host.h" |
| 55 | #include "DolphinQt/NANDRepairDialog.h" |
| 56 | #include "DolphinQt/QtUtils/DolphinFileDialog.h" |
| 57 | #include "DolphinQt/QtUtils/ModalMessageBox.h" |
| 58 | #include "DolphinQt/QtUtils/NonAutodismissibleMenu.h" |
| 59 | #include "DolphinQt/QtUtils/ParallelProgressDialog.h" |
| 60 | #ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 61 | #include "DolphinQt/QtUtils/QueueOnObject.h" |
| 62 | #endif |
| 63 | #include "DolphinQt/QtUtils/SignalBlocking.h" |
| 64 | #include "DolphinQt/Settings.h" |
| 65 | #include "DolphinQt/Updater.h" |
| 66 | |
| 67 | #include "UICommon/AutoUpdate.h" |
| 68 | #include "UICommon/GameFile.h" |
| 69 | |
| 70 | #ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 71 | #include <rcheevos/include/rc_client_raintegration.h> |
| 72 | #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 73 | |
| 74 | QPointer<MenuBar> MenuBar::s_menu_bar; |
| 75 | |
| 76 | QString MenuBar::GetSignatureSelector() const |
| 77 | { |
| 78 | return QStringLiteral("%1 (*.dsy);; %2 (*.csv);; %3 (*.mega)") |
| 79 | .arg(tr("Dolphin Signature File"), tr("Dolphin Signature CSV File"), |
| 80 | tr("WiiTools Signature MEGA File")); |
| 81 | } |
| 82 | |
| 83 | MenuBar::MenuBar(QWidget* parent) : QMenuBar(parent) |
| 84 | { |
| 85 | s_menu_bar = this; |
| 86 | |
| 87 | AddFileMenu(); |
| 88 | AddEmulationMenu(); |
| 89 | AddMovieMenu(); |
| 90 | AddOptionsMenu(); |
| 91 | AddToolsMenu(); |
| 92 | AddViewMenu(); |
| 93 | AddJITMenu(); |
| 94 | AddSymbolsMenu(); |
| 95 | AddHelpMenu(); |
| 96 | |
| 97 | connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, |
| 98 | [=, this](Core::State state) { OnEmulationStateChanged(state); }); |
| 99 | connect(&Settings::Instance(), &Settings::ConfigChanged, this, &MenuBar::OnConfigChanged); |
| 100 | connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, |
| 101 | [this] { OnEmulationStateChanged(Core::GetState(Core::System::GetInstance())); }); |
| 102 | |
| 103 | OnEmulationStateChanged(Core::GetState(Core::System::GetInstance())); |
| 104 | connect(&Settings::Instance(), &Settings::DebugModeToggled, this, &MenuBar::OnDebugModeToggled); |
| 105 | |
| 106 | connect(this, &MenuBar::SelectionChanged, this, &MenuBar::OnSelectionChanged); |
| 107 | connect(this, &MenuBar::RecordingStatusChanged, this, &MenuBar::OnRecordingStatusChanged); |
| 108 | connect(this, &MenuBar::ReadOnlyModeChanged, this, &MenuBar::OnReadOnlyModeChanged); |
| 109 | } |
| 110 | |
| 111 | void MenuBar::OnEmulationStateChanged(Core::State state) |
| 112 | { |
| 113 | bool running = state != Core::State::Uninitialized; |
| 114 | bool playing = running && state != Core::State::Paused; |
| 115 | |
| 116 | // File |
| 117 | m_eject_disc->setEnabled(running); |
| 118 | m_change_disc->setEnabled(running); |
| 119 | |
| 120 | // Emulation |
| 121 | m_play_action->setEnabled(!playing); |
| 122 | m_play_action->setVisible(!playing); |
| 123 | m_pause_action->setEnabled(playing); |
| 124 | m_pause_action->setVisible(playing); |
| 125 | m_stop_action->setEnabled(running); |
| 126 | m_stop_action->setVisible(running); |
| 127 | m_reset_action->setEnabled(running); |
| 128 | m_fullscreen_action->setEnabled(running); |
| 129 | m_screenshot_action->setEnabled(running); |
| 130 | m_state_save_menu->setEnabled(running); |
| 131 | |
| 132 | const bool hardcore = AchievementManager::GetInstance().IsHardcoreModeActive(); |
| 133 | m_state_load_menu->setEnabled(running && !hardcore); |
| 134 | m_frame_advance_action->setEnabled(running && !hardcore); |
| 135 | |
| 136 | // Movie |
| 137 | m_recording_read_only->setEnabled(running); |
| 138 | if (!running) |
| 139 | { |
| 140 | m_recording_stop->setEnabled(false); |
| 141 | m_recording_export->setEnabled(false); |
| 142 | } |
| 143 | const bool can_start_from_boot = m_game_selected && state == Core::State::Uninitialized; |
| 144 | const bool can_start_from_savestate = |
| 145 | state == Core::State::Running || state == Core::State::Paused; |
| 146 | m_recording_play->setEnabled(can_start_from_boot && !hardcore); |
| 147 | m_recording_start->setEnabled((can_start_from_boot || can_start_from_savestate) && |
| 148 | !Core::System::GetInstance().GetMovie().IsPlayingInput()); |
| 149 | |
| 150 | // JIT |
| 151 | const bool jit_exists = Core::System::GetInstance().GetJitInterface().GetCore() != nullptr; |
| 152 | m_jit_interpreter_core->setEnabled(running); |
| 153 | m_jit_block_linking->setEnabled(!running); |
| 154 | m_jit_disable_cache->setEnabled(!running); |
| 155 | m_jit_disable_fastmem_arena->setEnabled(!running); |
| 156 | m_jit_disable_large_entry_points_map->setEnabled(!running); |
| 157 | m_jit_clear_cache->setEnabled(running); |
| 158 | m_jit_log_coverage->setEnabled(!running); |
| 159 | m_jit_search_instruction->setEnabled(running); |
| 160 | m_jit_wipe_profiling_data->setEnabled(jit_exists); |
| 161 | m_jit_write_cache_log_dump->setEnabled(jit_exists); |
| 162 | |
| 163 | // Symbols |
| 164 | m_symbols->setEnabled(running); |
| 165 | |
| 166 | UpdateStateSlotMenu(); |
| 167 | UpdateToolsMenu(state); |
| 168 | |
| 169 | OnDebugModeToggled(Settings::Instance().IsDebugModeEnabled()); |
| 170 | } |
| 171 | |
| 172 | void MenuBar::OnConfigChanged() |
| 173 | { |
| 174 | SignalBlocking(m_jit_profile_blocks) |
| 175 | ->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_ENABLE_PROFILING)); |
| 176 | SignalBlocking(m_movie_window)->setChecked(Config::Get(Config::MAIN_MOVIE_SHOW_OSD)); |
| 177 | } |
| 178 | |
| 179 | void MenuBar::OnDebugModeToggled(bool enabled) |
| 180 | { |
| 181 | // Options |
| 182 | m_boot_to_pause->setVisible(enabled); |
| 183 | m_reset_ignore_panic_handler->setVisible(enabled); |
| 184 | m_change_font->setVisible(enabled); |
| 185 | |
| 186 | // View |
| 187 | m_show_code->setVisible(enabled); |
| 188 | m_show_registers->setVisible(enabled); |
| 189 | m_show_threads->setVisible(enabled); |
| 190 | m_show_watch->setVisible(enabled); |
| 191 | m_show_breakpoints->setVisible(enabled); |
| 192 | m_show_memory->setVisible(enabled); |
| 193 | m_show_network->setVisible(enabled); |
| 194 | m_show_jit->setVisible(enabled); |
| 195 | m_show_assembler->setVisible(enabled); |
| 196 | |
| 197 | if (enabled) |
| 198 | { |
| 199 | addMenu(m_jit); |
| 200 | addMenu(m_symbols); |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | removeAction(m_jit->menuAction()); |
| 205 | removeAction(m_symbols->menuAction()); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void MenuBar::OnWipeJitBlockProfilingData() |
| 210 | { |
| 211 | auto& system = Core::System::GetInstance(); |
| 212 | system.GetJitInterface().WipeBlockProfilingData(Core::CPUThreadGuard{system}); |
| 213 | } |
| 214 | |
| 215 | void MenuBar::OnWriteJitBlockLogDump() |
| 216 | { |
| 217 | const std::string filename = fmt::format("{}{}.txt", File::GetUserPath(D_DUMPDEBUG_JITBLOCKS_IDX), |
| 218 | SConfig::GetInstance().GetGameID()); |
| 219 | File::IOFile f(filename, "w"); |
| 220 | if (!f) |
| 221 | { |
| 222 | ModalMessageBox::warning( |
| 223 | this, tr("Error"), |
| 224 | tr("Failed to open \"%1\" for writing.").arg(QString::fromStdString(filename))); |
| 225 | return; |
| 226 | } |
| 227 | auto& system = Core::System::GetInstance(); |
| 228 | system.GetJitInterface().JitBlockLogDump(Core::CPUThreadGuard{system}, f.GetHandle()); |
| 229 | if (static bool ignore = false; ignore == false) |
| 230 | { |
| 231 | const int button_pressed = ModalMessageBox::information( |
| 232 | this, tr("Success"), tr("Wrote to \"%1\".").arg(QString::fromStdString(filename)), |
| 233 | QMessageBox::Ok | QMessageBox::Ignore); |
| 234 | if (button_pressed == QMessageBox::Ignore) |
| 235 | ignore = true; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | void MenuBar::AddFileMenu() |
| 240 | { |
| 241 | QMenu* file_menu = addMenu(tr("&File")); |
| 242 | #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) |
| 243 | m_open_action = file_menu->addAction(tr("&Open..."), QKeySequence::Open, this, &MenuBar::Open); |
| 244 | #else |
| 245 | m_open_action = file_menu->addAction(tr("&Open..."), this, &MenuBar::Open, QKeySequence::Open); |
| 246 | #endif |
| 247 | |
| 248 | file_menu->addSeparator(); |
| 249 | |
| 250 | m_change_disc = file_menu->addAction(tr("Change &Disc..."), this, &MenuBar::ChangeDisc); |
| 251 | m_eject_disc = file_menu->addAction(tr("&Eject Disc"), this, &MenuBar::EjectDisc); |
| 252 | |
| 253 | file_menu->addSeparator(); |
| 254 | |
| 255 | m_open_user_folder = |
| 256 | file_menu->addAction(tr("Open &User Folder"), this, &MenuBar::OpenUserFolder); |
| 257 | |
| 258 | const std::string user_path = File::GetUserPath(D_USER_IDX); |
| 259 | if (user_path + CONFIG_DIR DIR_SEP != File::GetUserPath(D_CONFIG_IDX)) |
| 260 | { |
| 261 | m_open_config_folder = |
| 262 | file_menu->addAction(tr("Open &Config Folder"), this, &MenuBar::OpenConfigFolder); |
| 263 | } |
| 264 | if (user_path + CACHE_DIR DIR_SEP != File::GetUserPath(D_CACHE_IDX)) |
| 265 | { |
| 266 | m_open_cache_folder = |
| 267 | file_menu->addAction(tr("Open C&ache Folder"), this, &MenuBar::OpenCacheFolder); |
| 268 | } |
| 269 | |
| 270 | file_menu->addSeparator(); |
| 271 | |
| 272 | m_exit_action = file_menu->addAction(tr("E&xit"), this, &MenuBar::Exit); |
| 273 | m_exit_action->setShortcuts({QKeySequence::Quit, QKeySequence(Qt::ALT | Qt::Key_F4)}); |
| 274 | } |
| 275 | |
| 276 | void MenuBar::AddToolsMenu() |
| 277 | { |
| 278 | QMenu* tools_menu = addMenu(tr("&Tools")); |
| 279 | |
| 280 | tools_menu->addAction(tr("&Resource Pack Manager"), this, |
| 281 | [this] { emit ShowResourcePackManager(); }); |
| 282 | |
| 283 | tools_menu->addAction(tr("&Cheats Manager"), this, [this] { emit ShowCheatsManager(); }); |
| 284 | |
| 285 | tools_menu->addAction(tr("FIFO Player"), this, &MenuBar::ShowFIFOPlayer); |
| 286 | |
| 287 | auto* usb_device_menu = new QMenu(tr("Emulated USB Devices"), tools_menu); |
| 288 | usb_device_menu->addAction(tr("&Skylanders Portal"), this, &MenuBar::ShowSkylanderPortal); |
| 289 | usb_device_menu->addAction(tr("&Infinity Base"), this, &MenuBar::ShowInfinityBase); |
| 290 | usb_device_menu->addAction(tr("&Wii Speak"), this, &MenuBar::ShowWiiSpeakWindow); |
| 291 | usb_device_menu->addAction(tr("&Logitech USB Microphone"), this, &MenuBar::ShowLogitechMicWindow); |
| 292 | tools_menu->addMenu(usb_device_menu); |
| 293 | |
| 294 | tools_menu->addSeparator(); |
| 295 | |
| 296 | tools_menu->addAction(tr("Start &NetPlay..."), this, &MenuBar::StartNetPlay); |
| 297 | tools_menu->addAction(tr("Browse &NetPlay Sessions...."), this, &MenuBar::BrowseNetPlay); |
| 298 | |
| 299 | tools_menu->addSeparator(); |
| 300 | |
| 301 | #ifdef USE_RETRO_ACHIEVEMENTS |
| 302 | m_achievements_action = |
| 303 | tools_menu->addAction(tr("Achievements"), this, [this] { emit ShowAchievementsWindow(); }); |
| 304 | #ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 305 | m_achievements_dev_menu = tools_menu->addMenu(tr("RetroAchievements Development")); |
| 306 | m_raintegration_event_hook = AchievementManager::GetInstance().dev_menu_update_event.Register( |
| 307 | [this] { QueueOnObject(this, [this] { UpdateAchievementDevelopmentMenu(); }); }); |
| 308 | m_achievements_dev_menu->menuAction()->setVisible(false); |
| 309 | #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 310 | tools_menu->addSeparator(); |
| 311 | #endif // USE_RETRO_ACHIEVEMENTS |
| 312 | |
| 313 | QMenu* gc_ipl = tools_menu->addMenu(tr("Load GameCube Main Menu")); |
| 314 | |
| 315 | m_ntscj_ipl = gc_ipl->addAction(tr("NTSC-J"), this, |
| 316 | [this] { emit BootGameCubeIPL(DiscIO::Region::NTSC_J); }); |
| 317 | m_ntscu_ipl = gc_ipl->addAction(tr("NTSC-U"), this, |
| 318 | [this] { emit BootGameCubeIPL(DiscIO::Region::NTSC_U); }); |
| 319 | m_pal_ipl = |
| 320 | gc_ipl->addAction(tr("PAL"), this, [this] { emit BootGameCubeIPL(DiscIO::Region::PAL); }); |
| 321 | |
| 322 | m_dev_ipl = gc_ipl->addAction(tr("Triforce"), this, |
| 323 | [this] { emit BootGameCubeIPL(DiscIO::Region::Unknown); }); |
| 324 | |
| 325 | tools_menu->addAction(tr("Memory Card Manager"), this, [this] { emit ShowMemcardManager(); }); |
| 326 | |
| 327 | tools_menu->addSeparator(); |
| 328 | |
| 329 | // Label will be set by a NANDRefresh later |
| 330 | m_boot_sysmenu = tools_menu->addAction(QString{}, this, [this] { emit BootWiiSystemMenu(); }); |
| 331 | m_wad_install_action = tools_menu->addAction(tr("Install WAD..."), this, &MenuBar::InstallWAD); |
| 332 | m_manage_nand_menu = tools_menu->addMenu(tr("Manage NAND")); |
| 333 | m_import_backup = m_manage_nand_menu->addAction(tr("Import BootMii NAND Backup..."), this, |
| 334 | [this] { emit ImportNANDBackup(); }); |
| 335 | m_check_nand = m_manage_nand_menu->addAction(tr("Check NAND..."), this, &MenuBar::CheckNAND); |
| 336 | m_extract_certificates = m_manage_nand_menu->addAction(tr("Extract Certificates from NAND"), this, |
| 337 | &MenuBar::NANDExtractCertificates); |
| 338 | |
| 339 | m_boot_sysmenu->setEnabled(false); |
| 340 | |
| 341 | connect(&Settings::Instance(), &Settings::NANDRefresh, this, |
| 342 | [this] { UpdateToolsMenu(Core::State::Uninitialized); }); |
| 343 | |
| 344 | m_perform_online_update_menu = tools_menu->addMenu(tr("Perform Online System Update")); |
| 345 | m_perform_online_update_for_current_region = m_perform_online_update_menu->addAction( |
| 346 | tr("Current Region"), this, [this] { emit PerformOnlineUpdate(""); }); |
| 347 | m_perform_online_update_menu->addSeparator(); |
| 348 | m_perform_online_update_menu->addAction(tr("Europe"), this, |
| 349 | [this] { emit PerformOnlineUpdate("EUR"); }); |
| 350 | m_perform_online_update_menu->addAction(tr("Japan"), this, |
| 351 | [this] { emit PerformOnlineUpdate("JPN"); }); |
| 352 | m_perform_online_update_menu->addAction(tr("Korea"), this, |
| 353 | [this] { emit PerformOnlineUpdate("KOR"); }); |
| 354 | m_perform_online_update_menu->addAction(tr("United States"), this, |
| 355 | [this] { emit PerformOnlineUpdate("USA"); }); |
| 356 | |
| 357 | tools_menu->addSeparator(); |
| 358 | |
| 359 | m_import_wii_save = |
| 360 | tools_menu->addAction(tr("Import Wii Save..."), this, &MenuBar::ImportWiiSave); |
| 361 | m_import_wii_saves = |
| 362 | tools_menu->addAction(tr("Import Wii Saves..."), this, &MenuBar::ImportWiiSaves); |
| 363 | m_export_wii_saves = |
| 364 | tools_menu->addAction(tr("Export All Wii Saves"), this, &MenuBar::ExportWiiSaves); |
| 365 | |
| 366 | auto* const connect_wii_remotes_menu{ |
| 367 | new QtUtils::NonAutodismissibleMenu(tr("Connect Wii Remotes"), tools_menu)}; |
| 368 | |
| 369 | tools_menu->addSeparator(); |
| 370 | tools_menu->addMenu(connect_wii_remotes_menu); |
| 371 | |
| 372 | for (int i = 0; i < 4; i++) |
| 373 | { |
| 374 | m_wii_remotes[i] = connect_wii_remotes_menu->addAction( |
| 375 | tr("Connect Wii Remote %1").arg(i + 1), this, [this, i] { emit ConnectWiiRemote(i); }); |
| 376 | m_wii_remotes[i]->setCheckable(true); |
| 377 | } |
| 378 | |
| 379 | connect_wii_remotes_menu->addSeparator(); |
| 380 | |
| 381 | m_wii_remotes[4] = connect_wii_remotes_menu->addAction(tr("Connect Balance Board"), this, |
| 382 | [this] { emit ConnectWiiRemote(4); }); |
| 383 | m_wii_remotes[4]->setCheckable(true); |
| 384 | } |
| 385 | |
| 386 | void MenuBar::AddEmulationMenu() |
| 387 | { |
| 388 | QMenu* emu_menu = addMenu(tr("&Emulation")); |
| 389 | m_play_action = emu_menu->addAction(tr("&Play"), this, &MenuBar::Play); |
| 390 | m_pause_action = emu_menu->addAction(tr("&Pause"), this, &MenuBar::Pause); |
| 391 | m_stop_action = emu_menu->addAction(tr("&Stop"), this, &MenuBar::Stop); |
| 392 | m_reset_action = emu_menu->addAction(tr("&Reset"), this, &MenuBar::Reset); |
| 393 | m_fullscreen_action = emu_menu->addAction(tr("Toggle &Fullscreen"), this, &MenuBar::Fullscreen); |
| 394 | m_frame_advance_action = emu_menu->addAction(tr("&Frame Advance"), this, &MenuBar::FrameAdvance); |
| 395 | |
| 396 | m_screenshot_action = emu_menu->addAction(tr("Take Screenshot"), this, &MenuBar::Screenshot); |
| 397 | |
| 398 | emu_menu->addSeparator(); |
| 399 | |
| 400 | AddStateLoadMenu(emu_menu); |
| 401 | AddStateSaveMenu(emu_menu); |
| 402 | AddStateSlotMenu(emu_menu); |
| 403 | UpdateStateSlotMenu(); |
| 404 | |
| 405 | for (QMenu* menu : {m_state_load_menu, m_state_save_menu, m_state_slot_menu}) |
| 406 | connect(menu, &QMenu::aboutToShow, this, &MenuBar::UpdateStateSlotMenu); |
| 407 | } |
| 408 | |
| 409 | void MenuBar::AddStateLoadMenu(QMenu* emu_menu) |
| 410 | { |
| 411 | m_state_load_menu = emu_menu->addMenu(tr("&Load State")); |
| 412 | m_state_load_menu->addAction(tr("Load State from File"), this, &MenuBar::StateLoad); |
| 413 | m_state_load_menu->addAction(tr("Load State from Selected Slot"), this, &MenuBar::StateLoadSlot); |
| 414 | m_state_load_slots_menu = m_state_load_menu->addMenu(tr("Load State from Slot")); |
| 415 | m_state_load_menu->addAction(tr("Undo Load State"), this, &MenuBar::StateLoadUndo); |
| 416 | |
| 417 | for (int i = 1; i <= 10; i++) |
| 418 | { |
| 419 | QAction* action = m_state_load_slots_menu->addAction(QString{}); |
| 420 | |
| 421 | connect(action, &QAction::triggered, this, [=, this] { emit StateLoadSlotAt(i); }); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | void MenuBar::AddStateSaveMenu(QMenu* emu_menu) |
| 426 | { |
| 427 | m_state_save_menu = emu_menu->addMenu(tr("Sa&ve State")); |
| 428 | m_state_save_menu->addAction(tr("Save State to File"), this, &MenuBar::StateSave); |
| 429 | m_state_save_menu->addAction(tr("Save State to Selected Slot"), this, &MenuBar::StateSaveSlot); |
| 430 | m_state_save_menu->addAction(tr("Save State to Oldest Slot"), this, &MenuBar::StateSaveOldest); |
| 431 | m_state_save_slots_menu = m_state_save_menu->addMenu(tr("Save State to Slot")); |
| 432 | m_state_save_menu->addAction(tr("Undo Save State"), this, &MenuBar::StateSaveUndo); |
| 433 | |
| 434 | for (int i = 1; i <= 10; i++) |
| 435 | { |
| 436 | QAction* action = m_state_save_slots_menu->addAction(QString{}); |
| 437 | |
| 438 | connect(action, &QAction::triggered, this, [=, this] { emit StateSaveSlotAt(i); }); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | void MenuBar::AddStateSlotMenu(QMenu* emu_menu) |
| 443 | { |
| 444 | m_state_slot_menu = emu_menu->addMenu(tr("Select State Slot")); |
| 445 | m_state_slots = new QActionGroup(this); |
| 446 | |
| 447 | for (int i = 1; i <= 10; i++) |
| 448 | { |
| 449 | QAction* action = m_state_slot_menu->addAction(QString{}); |
| 450 | action->setCheckable(true); |
| 451 | action->setActionGroup(m_state_slots); |
| 452 | if (Settings::Instance().GetStateSlot() == i) |
| 453 | action->setChecked(true); |
| 454 | |
| 455 | connect(action, &QAction::triggered, this, [=, this] { emit SetStateSlot(i); }); |
| 456 | connect(this, &MenuBar::SetStateSlot, [action, i](const int slot) { |
| 457 | if (slot == i) |
| 458 | action->setChecked(true); |
| 459 | }); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void MenuBar::UpdateStateSlotMenu() |
| 464 | { |
| 465 | QList<QAction*> actions_slot = m_state_slots->actions(); |
| 466 | QList<QAction*> actions_load = m_state_load_slots_menu->actions(); |
| 467 | QList<QAction*> actions_save = m_state_save_slots_menu->actions(); |
| 468 | for (int i = 0; i < actions_slot.length(); i++) |
| 469 | { |
| 470 | int slot = i + 1; |
| 471 | QString info = QString::fromStdString(State::GetInfoStringOfSlot(slot)); |
| 472 | actions_load.at(i)->setText(tr("Load from Slot %1 - %2").arg(slot).arg(info)); |
| 473 | actions_save.at(i)->setText(tr("Save to Slot %1 - %2").arg(slot).arg(info)); |
| 474 | actions_slot.at(i)->setText(tr("Select Slot %1 - %2").arg(slot).arg(info)); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | void MenuBar::AddViewMenu() |
| 479 | { |
| 480 | auto* const view_menu{new QtUtils::NonAutodismissibleMenu(tr("&View"), this)}; |
| 481 | addMenu(view_menu); |
| 482 | QAction* show_log = view_menu->addAction(tr("Show &Log")); |
| 483 | show_log->setCheckable(true); |
| 484 | show_log->setChecked(Settings::Instance().IsLogVisible()); |
| 485 | |
| 486 | connect(show_log, &QAction::toggled, &Settings::Instance(), &Settings::SetLogVisible); |
| 487 | |
| 488 | QAction* show_log_config = view_menu->addAction(tr("Show Log &Configuration")); |
| 489 | show_log_config->setCheckable(true); |
| 490 | show_log_config->setChecked(Settings::Instance().IsLogConfigVisible()); |
| 491 | |
| 492 | connect(show_log_config, &QAction::toggled, &Settings::Instance(), |
| 493 | &Settings::SetLogConfigVisible); |
| 494 | |
| 495 | QAction* show_toolbar = view_menu->addAction(tr("Show &Toolbar")); |
| 496 | show_toolbar->setCheckable(true); |
| 497 | show_toolbar->setChecked(Settings::Instance().IsToolBarVisible()); |
| 498 | |
| 499 | connect(show_toolbar, &QAction::toggled, &Settings::Instance(), &Settings::SetToolBarVisible); |
| 500 | |
| 501 | connect(&Settings::Instance(), &Settings::LogVisibilityChanged, show_log, &QAction::setChecked); |
| 502 | connect(&Settings::Instance(), &Settings::LogConfigVisibilityChanged, show_log_config, |
| 503 | &QAction::setChecked); |
| 504 | connect(&Settings::Instance(), &Settings::ToolBarVisibilityChanged, show_toolbar, |
| 505 | &QAction::setChecked); |
| 506 | |
| 507 | QAction* lock_widgets = view_menu->addAction(tr("&Lock Widgets In Place")); |
| 508 | lock_widgets->setCheckable(true); |
| 509 | lock_widgets->setChecked(Settings::Instance().AreWidgetsLocked()); |
| 510 | |
| 511 | connect(lock_widgets, &QAction::toggled, &Settings::Instance(), &Settings::SetWidgetsLocked); |
| 512 | |
| 513 | view_menu->addSeparator(); |
| 514 | |
| 515 | m_show_code = view_menu->addAction(tr("&Code")); |
| 516 | m_show_code->setCheckable(true); |
| 517 | m_show_code->setChecked(Settings::Instance().IsCodeVisible()); |
| 518 | |
| 519 | connect(m_show_code, &QAction::toggled, &Settings::Instance(), &Settings::SetCodeVisible); |
| 520 | connect(&Settings::Instance(), &Settings::CodeVisibilityChanged, m_show_code, |
| 521 | &QAction::setChecked); |
| 522 | |
| 523 | m_show_registers = view_menu->addAction(tr("&Registers")); |
| 524 | m_show_registers->setCheckable(true); |
| 525 | m_show_registers->setChecked(Settings::Instance().IsRegistersVisible()); |
| 526 | |
| 527 | connect(m_show_registers, &QAction::toggled, &Settings::Instance(), |
| 528 | &Settings::SetRegistersVisible); |
| 529 | connect(&Settings::Instance(), &Settings::RegistersVisibilityChanged, m_show_registers, |
| 530 | &QAction::setChecked); |
| 531 | |
| 532 | m_show_threads = view_menu->addAction(tr("&Threads")); |
| 533 | m_show_threads->setCheckable(true); |
| 534 | m_show_threads->setChecked(Settings::Instance().IsThreadsVisible()); |
| 535 | |
| 536 | connect(m_show_threads, &QAction::toggled, &Settings::Instance(), &Settings::SetThreadsVisible); |
| 537 | connect(&Settings::Instance(), &Settings::ThreadsVisibilityChanged, m_show_threads, |
| 538 | &QAction::setChecked); |
| 539 | |
| 540 | // i18n: This kind of "watch" is used for watching emulated memory. |
| 541 | // It's not related to timekeeping devices. |
| 542 | m_show_watch = view_menu->addAction(tr("&Watch")); |
| 543 | m_show_watch->setCheckable(true); |
| 544 | m_show_watch->setChecked(Settings::Instance().IsWatchVisible()); |
| 545 | |
| 546 | connect(m_show_watch, &QAction::toggled, &Settings::Instance(), &Settings::SetWatchVisible); |
| 547 | connect(&Settings::Instance(), &Settings::WatchVisibilityChanged, m_show_watch, |
| 548 | &QAction::setChecked); |
| 549 | |
| 550 | m_show_breakpoints = view_menu->addAction(tr("&Breakpoints")); |
| 551 | m_show_breakpoints->setCheckable(true); |
| 552 | m_show_breakpoints->setChecked(Settings::Instance().IsBreakpointsVisible()); |
| 553 | |
| 554 | connect(m_show_breakpoints, &QAction::toggled, &Settings::Instance(), |
| 555 | &Settings::SetBreakpointsVisible); |
| 556 | connect(&Settings::Instance(), &Settings::BreakpointsVisibilityChanged, m_show_breakpoints, |
| 557 | &QAction::setChecked); |
| 558 | |
| 559 | m_show_memory = view_menu->addAction(tr("&Memory")); |
| 560 | m_show_memory->setCheckable(true); |
| 561 | m_show_memory->setChecked(Settings::Instance().IsMemoryVisible()); |
| 562 | |
| 563 | connect(m_show_memory, &QAction::toggled, &Settings::Instance(), &Settings::SetMemoryVisible); |
| 564 | connect(&Settings::Instance(), &Settings::MemoryVisibilityChanged, m_show_memory, |
| 565 | &QAction::setChecked); |
| 566 | |
| 567 | m_show_network = view_menu->addAction(tr("&Network")); |
| 568 | m_show_network->setCheckable(true); |
| 569 | m_show_network->setChecked(Settings::Instance().IsNetworkVisible()); |
| 570 | |
| 571 | connect(m_show_network, &QAction::toggled, &Settings::Instance(), &Settings::SetNetworkVisible); |
| 572 | connect(&Settings::Instance(), &Settings::NetworkVisibilityChanged, m_show_network, |
| 573 | &QAction::setChecked); |
| 574 | |
| 575 | m_show_jit = view_menu->addAction(tr("&JIT")); |
| 576 | m_show_jit->setCheckable(true); |
| 577 | m_show_jit->setChecked(Settings::Instance().IsJITVisible()); |
| 578 | connect(m_show_jit, &QAction::toggled, &Settings::Instance(), &Settings::SetJITVisible); |
| 579 | connect(&Settings::Instance(), &Settings::JITVisibilityChanged, m_show_jit, &QAction::setChecked); |
| 580 | |
| 581 | m_show_assembler = view_menu->addAction(tr("&Assembler")); |
| 582 | m_show_assembler->setCheckable(true); |
| 583 | m_show_assembler->setChecked(Settings::Instance().IsAssemblerVisible()); |
| 584 | connect(m_show_assembler, &QAction::toggled, &Settings::Instance(), |
| 585 | &Settings::SetAssemblerVisible); |
| 586 | connect(&Settings::Instance(), &Settings::AssemblerVisibilityChanged, m_show_assembler, |
| 587 | &QAction::setChecked); |
| 588 | |
| 589 | view_menu->addSeparator(); |
| 590 | |
| 591 | AddGameListTypeSection(view_menu); |
| 592 | view_menu->addSeparator(); |
| 593 | AddListColumnsMenu(view_menu); |
| 594 | view_menu->addSeparator(); |
| 595 | AddShowPlatformsMenu(view_menu); |
| 596 | AddShowRegionsMenu(view_menu); |
| 597 | |
| 598 | view_menu->addSeparator(); |
| 599 | QAction* const show_game_count = view_menu->addAction(tr("Show Game Count")); |
| 600 | show_game_count->setCheckable(true); |
| 601 | show_game_count->setChecked(Settings::Instance().IsGameCountVisible()); |
| 602 | connect(show_game_count, &QAction::toggled, &Settings::Instance(), |
| 603 | &Settings::SetGameCountVisible); |
| 604 | |
| 605 | view_menu->addSeparator(); |
| 606 | QAction* const purge_action = |
| 607 | view_menu->addAction(tr("Purge Game List Cache"), this, &MenuBar::PurgeGameListCache); |
| 608 | purge_action->setEnabled(false); |
| 609 | connect(&Settings::Instance(), &Settings::GameListRefreshRequested, purge_action, |
| 610 | [purge_action] { purge_action->setEnabled(false); }); |
| 611 | connect(&Settings::Instance(), &Settings::GameListRefreshStarted, purge_action, |
| 612 | [purge_action] { purge_action->setEnabled(true); }); |
| 613 | view_menu->addSeparator(); |
| 614 | #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) |
| 615 | view_menu->addAction(tr("Search"), QKeySequence::Find, this, &MenuBar::ShowSearch); |
| 616 | #else |
| 617 | view_menu->addAction(tr("Search"), this, &MenuBar::ShowSearch, QKeySequence::Find); |
| 618 | #endif |
| 619 | } |
| 620 | |
| 621 | void MenuBar::AddOptionsMenu() |
| 622 | { |
| 623 | auto* const options_menu{new QtUtils::NonAutodismissibleMenu(tr("&Options"), this)}; |
| 624 | addMenu(options_menu); |
| 625 | #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) |
| 626 | options_menu->addAction(tr("Co&nfiguration"), QKeySequence::Preferences, this, |
| 627 | &MenuBar::Configure); |
| 628 | #else |
| 629 | options_menu->addAction(tr("Co&nfiguration"), this, &MenuBar::Configure, |
| 630 | QKeySequence::Preferences); |
| 631 | #endif |
| 632 | options_menu->addSeparator(); |
| 633 | options_menu->addAction(tr("&Graphics Settings"), this, &MenuBar::ConfigureGraphics); |
| 634 | options_menu->addAction(tr("&Audio Settings"), this, &MenuBar::ConfigureAudio); |
| 635 | m_controllers_action = |
| 636 | options_menu->addAction(tr("&Controller Settings"), this, &MenuBar::ConfigureControllers); |
| 637 | options_menu->addAction(tr("&Hotkey Settings"), this, &MenuBar::ConfigureHotkeys); |
| 638 | options_menu->addAction(tr("&Free Look Settings"), this, &MenuBar::ConfigureFreelook); |
| 639 | |
| 640 | options_menu->addSeparator(); |
| 641 | |
| 642 | // Debugging mode only |
| 643 | m_boot_to_pause = options_menu->addAction(tr("Boot to Pause")); |
| 644 | m_boot_to_pause->setCheckable(true); |
| 645 | m_boot_to_pause->setChecked(SConfig::GetInstance().bBootToPause); |
| 646 | |
| 647 | connect(m_boot_to_pause, &QAction::toggled, this, |
| 648 | [](bool enable) { SConfig::GetInstance().bBootToPause = enable; }); |
| 649 | |
| 650 | m_reset_ignore_panic_handler = options_menu->addAction(tr("Reset Ignore Panic Handler")); |
| 651 | |
| 652 | connect(m_reset_ignore_panic_handler, &QAction::triggered, this, [] { |
| 653 | Config::DeleteKey(Config::LayerType::CurrentRun, Config::MAIN_USE_PANIC_HANDLERS); |
| 654 | }); |
| 655 | |
| 656 | m_change_font = options_menu->addAction(tr("&Font..."), this, &MenuBar::ChangeDebugFont); |
| 657 | } |
| 658 | |
| 659 | void MenuBar::InstallUpdateManually() |
| 660 | { |
| 661 | const std::string autoupdate_track = Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK); |
| 662 | const std::string manual_track = autoupdate_track.empty() ? "dev" : autoupdate_track; |
| 663 | auto* const updater = new Updater(this->parentWidget(), manual_track, |
| 664 | Config::Get(Config::MAIN_AUTOUPDATE_HASH_OVERRIDE)); |
| 665 | |
| 666 | updater->CheckForUpdate(); |
| 667 | } |
| 668 | |
| 669 | void MenuBar::AddHelpMenu() |
| 670 | { |
| 671 | QMenu* help_menu = addMenu(tr("&Help")); |
| 672 | |
| 673 | QAction* website = help_menu->addAction(tr("&Website")); |
| 674 | connect(website, &QAction::triggered, this, |
| 675 | [] { QDesktopServices::openUrl(QUrl(QStringLiteral("https://dolphin-emu.org/"))); }); |
| 676 | QAction* documentation = help_menu->addAction(tr("Online &Documentation")); |
| 677 | connect(documentation, &QAction::triggered, this, [] { |
| 678 | QDesktopServices::openUrl(QUrl(QStringLiteral("https://dolphin-emu.org/docs/guides"))); |
| 679 | }); |
| 680 | QAction* github = help_menu->addAction(tr("&GitHub Repository")); |
| 681 | connect(github, &QAction::triggered, this, [] { |
| 682 | QDesktopServices::openUrl(QUrl(QStringLiteral("https://github.com/dolphin-emu/dolphin"))); |
| 683 | }); |
| 684 | QAction* bugtracker = help_menu->addAction(tr("&Bug Tracker")); |
| 685 | connect(bugtracker, &QAction::triggered, this, [] { |
| 686 | QDesktopServices::openUrl( |
| 687 | QUrl(QStringLiteral("https://bugs.dolphin-emu.org/projects/emulator"))); |
| 688 | }); |
| 689 | |
| 690 | if (AutoUpdateChecker::SystemSupportsAutoUpdates()) |
| 691 | { |
| 692 | help_menu->addSeparator(); |
| 693 | |
| 694 | help_menu->addAction(tr("&Check for Updates..."), this, &MenuBar::InstallUpdateManually); |
| 695 | } |
| 696 | |
| 697 | #ifndef __APPLE__ |
| 698 | help_menu->addSeparator(); |
| 699 | #endif |
| 700 | |
| 701 | help_menu->addAction(tr("&About"), this, &MenuBar::ShowAboutDialog); |
| 702 | } |
| 703 | |
| 704 | void MenuBar::AddGameListTypeSection(QMenu* view_menu) |
| 705 | { |
| 706 | QAction* list_view = view_menu->addAction(tr("List View")); |
| 707 | list_view->setCheckable(true); |
| 708 | |
| 709 | QAction* grid_view = view_menu->addAction(tr("Grid View")); |
| 710 | grid_view->setCheckable(true); |
| 711 | |
| 712 | QActionGroup* list_group = new QActionGroup(this); |
| 713 | list_group->addAction(list_view); |
| 714 | list_group->addAction(grid_view); |
| 715 | |
| 716 | bool prefer_list = Settings::Instance().GetPreferredView(); |
| 717 | list_view->setChecked(prefer_list); |
| 718 | grid_view->setChecked(!prefer_list); |
| 719 | |
| 720 | connect(list_view, &QAction::triggered, this, &MenuBar::ShowList); |
| 721 | connect(grid_view, &QAction::triggered, this, &MenuBar::ShowGrid); |
| 722 | } |
| 723 | |
| 724 | void MenuBar::AddListColumnsMenu(QMenu* view_menu) |
| 725 | { |
| 726 | static const QMap<QString, const Config::Info<bool>*> columns{ |
| 727 | {tr("Platform"), &Config::MAIN_GAMELIST_COLUMN_PLATFORM}, |
| 728 | {tr("Banner"), &Config::MAIN_GAMELIST_COLUMN_BANNER}, |
| 729 | {tr("Title"), &Config::MAIN_GAMELIST_COLUMN_TITLE}, |
| 730 | {tr("Description"), &Config::MAIN_GAMELIST_COLUMN_DESCRIPTION}, |
| 731 | {tr("Maker"), &Config::MAIN_GAMELIST_COLUMN_MAKER}, |
| 732 | {tr("File Name"), &Config::MAIN_GAMELIST_COLUMN_FILE_NAME}, |
| 733 | {tr("File Path"), &Config::MAIN_GAMELIST_COLUMN_FILE_PATH}, |
| 734 | {tr("Game ID"), &Config::MAIN_GAMELIST_COLUMN_GAME_ID}, |
| 735 | {tr("Region"), &Config::MAIN_GAMELIST_COLUMN_REGION}, |
| 736 | {tr("File Size"), &Config::MAIN_GAMELIST_COLUMN_FILE_SIZE}, |
| 737 | {tr("File Format"), &Config::MAIN_GAMELIST_COLUMN_FILE_FORMAT}, |
| 738 | {tr("Block Size"), &Config::MAIN_GAMELIST_COLUMN_BLOCK_SIZE}, |
| 739 | {tr("Compression"), &Config::MAIN_GAMELIST_COLUMN_COMPRESSION}, |
| 740 | {tr("Time Played"), &Config::MAIN_GAMELIST_COLUMN_TIME_PLAYED}, |
| 741 | {tr("Tags"), &Config::MAIN_GAMELIST_COLUMN_TAGS}}; |
| 742 | |
| 743 | QActionGroup* column_group = new QActionGroup(this); |
| 744 | m_cols_menu = new QtUtils::NonAutodismissibleMenu(tr("List Columns"), view_menu); |
| 745 | view_menu->addMenu(m_cols_menu); |
| 746 | column_group->setExclusive(false); |
| 747 | |
| 748 | for (const auto& key : columns.keys()) |
| 749 | { |
| 750 | const Config::Info<bool>* const config = columns[key]; |
| 751 | QAction* action = column_group->addAction(m_cols_menu->addAction(key)); |
| 752 | action->setCheckable(true); |
| 753 | action->setChecked(Config::Get(*config)); |
| 754 | connect(action, &QAction::toggled, [this, config, key](bool value) { |
| 755 | Config::SetBase(*config, value); |
| 756 | emit ColumnVisibilityToggled(key, value); |
| 757 | }); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void MenuBar::AddShowPlatformsMenu(QMenu* view_menu) |
| 762 | { |
| 763 | static const QMap<QString, const Config::Info<bool>*> platform_map{ |
| 764 | {tr("Show Wii"), &Config::MAIN_GAMELIST_LIST_WII}, |
| 765 | {tr("Show GameCube"), &Config::MAIN_GAMELIST_LIST_GC}, |
| 766 | {tr("Show Triforce"), &Config::MAIN_GAMELIST_LIST_TRI}, |
| 767 | {tr("Show WAD"), &Config::MAIN_GAMELIST_LIST_WAD}, |
| 768 | {tr("Show ELF/DOL"), &Config::MAIN_GAMELIST_LIST_ELF_DOL}}; |
| 769 | |
| 770 | QActionGroup* platform_group = new QActionGroup(this); |
| 771 | auto* const plat_menu{new QtUtils::NonAutodismissibleMenu(tr("Show Platforms"), view_menu)}; |
| 772 | view_menu->addMenu(plat_menu); |
| 773 | platform_group->setExclusive(false); |
| 774 | |
| 775 | for (const auto& key : platform_map.keys()) |
| 776 | { |
| 777 | const Config::Info<bool>* const config = platform_map[key]; |
| 778 | QAction* action = platform_group->addAction(plat_menu->addAction(key)); |
| 779 | action->setCheckable(true); |
| 780 | action->setChecked(Config::Get(*config)); |
| 781 | connect(action, &QAction::toggled, [this, config, key](bool value) { |
| 782 | Config::SetBase(*config, value); |
| 783 | emit GameListPlatformVisibilityToggled(key, value); |
| 784 | }); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | void MenuBar::AddShowRegionsMenu(QMenu* view_menu) |
| 789 | { |
| 790 | static const QMap<QString, const Config::Info<bool>*> region_map{ |
| 791 | {tr("Show JPN"), &Config::MAIN_GAMELIST_LIST_JPN}, |
| 792 | {tr("Show PAL"), &Config::MAIN_GAMELIST_LIST_PAL}, |
| 793 | {tr("Show USA"), &Config::MAIN_GAMELIST_LIST_USA}, |
| 794 | {tr("Show Australia"), &Config::MAIN_GAMELIST_LIST_AUSTRALIA}, |
| 795 | {tr("Show France"), &Config::MAIN_GAMELIST_LIST_FRANCE}, |
| 796 | {tr("Show Germany"), &Config::MAIN_GAMELIST_LIST_GERMANY}, |
| 797 | {tr("Show Italy"), &Config::MAIN_GAMELIST_LIST_ITALY}, |
| 798 | {tr("Show Korea"), &Config::MAIN_GAMELIST_LIST_KOREA}, |
| 799 | {tr("Show Netherlands"), &Config::MAIN_GAMELIST_LIST_NETHERLANDS}, |
| 800 | {tr("Show Russia"), &Config::MAIN_GAMELIST_LIST_RUSSIA}, |
| 801 | {tr("Show Spain"), &Config::MAIN_GAMELIST_LIST_SPAIN}, |
| 802 | {tr("Show Taiwan"), &Config::MAIN_GAMELIST_LIST_TAIWAN}, |
| 803 | {tr("Show World"), &Config::MAIN_GAMELIST_LIST_WORLD}, |
| 804 | {tr("Show Unknown"), &Config::MAIN_GAMELIST_LIST_UNKNOWN}}; |
| 805 | |
| 806 | auto* const region_menu{new QtUtils::NonAutodismissibleMenu(tr("Show Regions"), view_menu)}; |
| 807 | view_menu->addMenu(region_menu); |
| 808 | const QAction* const show_all_regions = region_menu->addAction(tr("Show All")); |
| 809 | const QAction* const hide_all_regions = region_menu->addAction(tr("Hide All")); |
| 810 | region_menu->addSeparator(); |
| 811 | |
| 812 | for (const auto& key : region_map.keys()) |
| 813 | { |
| 814 | const Config::Info<bool>* const config = region_map[key]; |
| 815 | QAction* const menu_item = region_menu->addAction(key); |
| 816 | menu_item->setCheckable(true); |
| 817 | menu_item->setChecked(Config::Get(*config)); |
| 818 | |
| 819 | const auto set_visibility = [this, config, key, menu_item](bool visibility) { |
| 820 | menu_item->setChecked(visibility); |
| 821 | Config::SetBase(*config, visibility); |
| 822 | emit GameListRegionVisibilityToggled(key, visibility); |
| 823 | }; |
| 824 | const auto set_visible = std::bind(set_visibility, true); |
| 825 | const auto set_hidden = std::bind(set_visibility, false); |
| 826 | |
| 827 | connect(menu_item, &QAction::toggled, set_visibility); |
| 828 | connect(show_all_regions, &QAction::triggered, menu_item, set_visible); |
| 829 | connect(hide_all_regions, &QAction::triggered, menu_item, set_hidden); |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | void MenuBar::AddMovieMenu() |
| 834 | { |
| 835 | auto* const movie_menu{new QtUtils::NonAutodismissibleMenu(tr("&Movie"), this)}; |
| 836 | addMenu(movie_menu); |
| 837 | m_recording_start = |
| 838 | movie_menu->addAction(tr("Start Re&cording Input"), this, [this] { emit StartRecording(); }); |
| 839 | m_recording_play = |
| 840 | movie_menu->addAction(tr("P&lay Input Recording..."), this, [this] { emit PlayRecording(); }); |
| 841 | m_recording_stop = movie_menu->addAction(tr("Stop Playing/Recording Input"), this, |
| 842 | [this] { emit StopRecording(); }); |
| 843 | m_recording_export = |
| 844 | movie_menu->addAction(tr("Export Recording..."), this, [this] { emit ExportRecording(); }); |
| 845 | |
| 846 | m_recording_start->setEnabled(false); |
| 847 | m_recording_play->setEnabled(false); |
| 848 | m_recording_stop->setEnabled(false); |
| 849 | m_recording_export->setEnabled(false); |
| 850 | |
| 851 | m_recording_read_only = movie_menu->addAction(tr("&Read-Only Mode")); |
| 852 | m_recording_read_only->setCheckable(true); |
| 853 | m_recording_read_only->setChecked(Core::System::GetInstance().GetMovie().IsReadOnly()); |
| 854 | connect(m_recording_read_only, &QAction::toggled, |
| 855 | [](bool value) { Core::System::GetInstance().GetMovie().SetReadOnly(value); }); |
| 856 | |
| 857 | movie_menu->addAction(tr("TAS Input"), this, [this] { emit ShowTASInput(); }); |
| 858 | |
| 859 | movie_menu->addSeparator(); |
| 860 | |
| 861 | auto* pause_at_end = movie_menu->addAction(tr("Pause at End of Movie")); |
| 862 | pause_at_end->setCheckable(true); |
| 863 | pause_at_end->setChecked(Config::Get(Config::MAIN_MOVIE_PAUSE_MOVIE)); |
| 864 | connect(pause_at_end, &QAction::toggled, |
| 865 | [](bool value) { Config::SetBaseOrCurrent(Config::MAIN_MOVIE_PAUSE_MOVIE, value); }); |
| 866 | |
| 867 | m_movie_window = movie_menu->addAction(tr("Enable Movie Window")); |
| 868 | m_movie_window->setCheckable(true); |
| 869 | m_movie_window->setChecked(Config::Get(Config::MAIN_MOVIE_SHOW_OSD)); |
| 870 | connect(m_movie_window, &QAction::toggled, |
| 871 | [](bool value) { Config::SetBaseOrCurrent(Config::MAIN_MOVIE_SHOW_OSD, value); }); |
| 872 | |
| 873 | movie_menu->addAction(tr("Customize Movie Window"), this, &MenuBar::ConfigureOSD); |
| 874 | |
| 875 | movie_menu->addSeparator(); |
| 876 | |
| 877 | auto* dump_frames = movie_menu->addAction(tr("Dump Frames")); |
| 878 | dump_frames->setCheckable(true); |
| 879 | dump_frames->setChecked(Config::Get(Config::MAIN_MOVIE_DUMP_FRAMES)); |
| 880 | connect(dump_frames, &QAction::toggled, |
| 881 | [](bool value) { Config::SetBaseOrCurrent(Config::MAIN_MOVIE_DUMP_FRAMES, value); }); |
| 882 | |
| 883 | auto* dump_audio = movie_menu->addAction(tr("Dump Audio")); |
| 884 | dump_audio->setCheckable(true); |
| 885 | dump_audio->setChecked(Config::Get(Config::MAIN_DUMP_AUDIO)); |
| 886 | connect(dump_audio, &QAction::toggled, |
| 887 | [](bool value) { Config::SetBaseOrCurrent(Config::MAIN_DUMP_AUDIO, value); }); |
| 888 | } |
| 889 | |
| 890 | void MenuBar::AddJITMenu() |
| 891 | { |
| 892 | m_jit = new QtUtils::NonAutodismissibleMenu(tr("JIT"), this); |
| 893 | addMenu(m_jit); |
| 894 | |
| 895 | m_jit_interpreter_core = m_jit->addAction(tr("Interpreter Core")); |
| 896 | m_jit_interpreter_core->setCheckable(true); |
| 897 | m_jit_interpreter_core->setChecked(Config::Get(Config::MAIN_CPU_CORE) == |
| 898 | PowerPC::CPUCore::Interpreter); |
| 899 | |
| 900 | connect(m_jit_interpreter_core, &QAction::toggled, [](bool enabled) { |
| 901 | Core::System::GetInstance().GetPowerPC().SetMode(enabled ? PowerPC::CoreMode::Interpreter : |
| 902 | PowerPC::CoreMode::JIT); |
| 903 | }); |
| 904 | |
| 905 | m_jit->addSeparator(); |
| 906 | |
| 907 | m_jit_block_linking = m_jit->addAction(tr("JIT Block Linking Off")); |
| 908 | m_jit_block_linking->setCheckable(true); |
| 909 | m_jit_block_linking->setChecked(SConfig::GetInstance().bJITNoBlockLinking); |
| 910 | connect(m_jit_block_linking, &QAction::toggled, [this](bool enabled) { |
| 911 | SConfig::GetInstance().bJITNoBlockLinking = enabled; |
| 912 | ClearCache(); |
| 913 | }); |
| 914 | |
| 915 | m_jit_disable_cache = m_jit->addAction(tr("Disable JIT Cache")); |
| 916 | m_jit_disable_cache->setCheckable(true); |
| 917 | m_jit_disable_cache->setChecked(SConfig::GetInstance().bJITNoBlockCache); |
| 918 | connect(m_jit_disable_cache, &QAction::toggled, [this](bool enabled) { |
| 919 | SConfig::GetInstance().bJITNoBlockCache = enabled; |
| 920 | ClearCache(); |
| 921 | }); |
| 922 | |
| 923 | m_jit_disable_fastmem = m_jit->addAction(tr("Disable Fastmem")); |
| 924 | m_jit_disable_fastmem->setCheckable(true); |
| 925 | m_jit_disable_fastmem->setChecked(!Config::Get(Config::MAIN_FASTMEM)); |
| 926 | connect(m_jit_disable_fastmem, &QAction::toggled, |
| 927 | [](bool enabled) { Config::SetBaseOrCurrent(Config::MAIN_FASTMEM, !enabled); }); |
| 928 | |
| 929 | m_jit_disable_page_table_fastmem = m_jit->addAction(tr("Disable Page Table Fastmem")); |
| 930 | m_jit_disable_page_table_fastmem->setCheckable(true); |
| 931 | m_jit_disable_page_table_fastmem->setChecked(!Config::Get(Config::MAIN_PAGE_TABLE_FASTMEM)); |
| 932 | connect(m_jit_disable_page_table_fastmem, &QAction::toggled, [](bool enabled) { |
| 933 | Config::SetBaseOrCurrent(Config::MAIN_PAGE_TABLE_FASTMEM, !enabled); |
| 934 | }); |
| 935 | |
| 936 | m_jit_disable_fastmem_arena = m_jit->addAction(tr("Disable Fastmem Arena")); |
| 937 | m_jit_disable_fastmem_arena->setCheckable(true); |
| 938 | m_jit_disable_fastmem_arena->setChecked(!Config::Get(Config::MAIN_FASTMEM_ARENA)); |
| 939 | connect(m_jit_disable_fastmem_arena, &QAction::toggled, |
| 940 | [](bool enabled) { Config::SetBaseOrCurrent(Config::MAIN_FASTMEM_ARENA, !enabled); }); |
| 941 | |
| 942 | m_jit_disable_large_entry_points_map = m_jit->addAction(tr("Disable Large Entry Points Map")); |
| 943 | m_jit_disable_large_entry_points_map->setCheckable(true); |
| 944 | m_jit_disable_large_entry_points_map->setChecked( |
| 945 | !Config::Get(Config::MAIN_LARGE_ENTRY_POINTS_MAP)); |
| 946 | connect(m_jit_disable_large_entry_points_map, &QAction::toggled, [](bool enabled) { |
| 947 | Config::SetBaseOrCurrent(Config::MAIN_LARGE_ENTRY_POINTS_MAP, !enabled); |
| 948 | }); |
| 949 | |
| 950 | m_jit_clear_cache = m_jit->addAction(tr("Clear Cache"), this, &MenuBar::ClearCache); |
| 951 | |
| 952 | m_jit->addSeparator(); |
| 953 | |
| 954 | m_jit_log_coverage = |
| 955 | m_jit->addAction(tr("Log JIT Instruction Coverage"), this, &MenuBar::LogInstructions); |
| 956 | m_jit_search_instruction = |
| 957 | m_jit->addAction(tr("Search for an Instruction"), this, &MenuBar::SearchInstruction); |
| 958 | |
| 959 | m_jit->addSeparator(); |
| 960 | |
| 961 | m_jit_profile_blocks = m_jit->addAction(tr("Enable JIT Block Profiling")); |
| 962 | m_jit_profile_blocks->setCheckable(true); |
| 963 | m_jit_profile_blocks->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_ENABLE_PROFILING)); |
| 964 | connect(m_jit_profile_blocks, &QAction::toggled, [](bool enabled) { |
| 965 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_ENABLE_PROFILING, enabled); |
| 966 | }); |
| 967 | m_jit_wipe_profiling_data = m_jit->addAction(tr("Wipe JIT Block Profiling Data"), this, |
| 968 | &MenuBar::OnWipeJitBlockProfilingData); |
| 969 | m_jit_write_cache_log_dump = |
| 970 | m_jit->addAction(tr("Write JIT Block Log Dump"), this, &MenuBar::OnWriteJitBlockLogDump); |
| 971 | |
| 972 | m_jit->addSeparator(); |
| 973 | |
| 974 | m_jit_off = m_jit->addAction(tr("JIT Off (JIT Core)")); |
| 975 | m_jit_off->setCheckable(true); |
| 976 | m_jit_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_OFF)); |
| 977 | connect(m_jit_off, &QAction::toggled, |
| 978 | [](bool enabled) { Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_OFF, enabled); }); |
| 979 | |
| 980 | m_jit_loadstore_off = m_jit->addAction(tr("JIT LoadStore Off")); |
| 981 | m_jit_loadstore_off->setCheckable(true); |
| 982 | m_jit_loadstore_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_LOAD_STORE_OFF)); |
| 983 | connect(m_jit_loadstore_off, &QAction::toggled, [](bool enabled) { |
| 984 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_LOAD_STORE_OFF, enabled); |
| 985 | }); |
| 986 | |
| 987 | m_jit_loadstore_lbzx_off = m_jit->addAction(tr("JIT LoadStore lbzx Off")); |
| 988 | m_jit_loadstore_lbzx_off->setCheckable(true); |
| 989 | m_jit_loadstore_lbzx_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_LOAD_STORE_LBZX_OFF)); |
| 990 | connect(m_jit_loadstore_lbzx_off, &QAction::toggled, [](bool enabled) { |
| 991 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_LOAD_STORE_LBZX_OFF, enabled); |
| 992 | }); |
| 993 | |
| 994 | m_jit_loadstore_lxz_off = m_jit->addAction(tr("JIT LoadStore lXz Off")); |
| 995 | m_jit_loadstore_lxz_off->setCheckable(true); |
| 996 | m_jit_loadstore_lxz_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_LOAD_STORE_LXZ_OFF)); |
| 997 | connect(m_jit_loadstore_lxz_off, &QAction::toggled, [](bool enabled) { |
| 998 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_LOAD_STORE_LXZ_OFF, enabled); |
| 999 | }); |
| 1000 | |
| 1001 | m_jit_loadstore_lwz_off = m_jit->addAction(tr("JIT LoadStore lwz Off")); |
| 1002 | m_jit_loadstore_lwz_off->setCheckable(true); |
| 1003 | m_jit_loadstore_lwz_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_LOAD_STORE_LWZ_OFF)); |
| 1004 | connect(m_jit_loadstore_lwz_off, &QAction::toggled, [](bool enabled) { |
| 1005 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_LOAD_STORE_LWZ_OFF, enabled); |
| 1006 | }); |
| 1007 | |
| 1008 | m_jit_loadstore_floating_off = m_jit->addAction(tr("JIT LoadStore Floating Off")); |
| 1009 | m_jit_loadstore_floating_off->setCheckable(true); |
| 1010 | m_jit_loadstore_floating_off->setChecked( |
| 1011 | Config::Get(Config::MAIN_DEBUG_JIT_LOAD_STORE_FLOATING_OFF)); |
| 1012 | connect(m_jit_loadstore_floating_off, &QAction::toggled, [](bool enabled) { |
| 1013 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_LOAD_STORE_FLOATING_OFF, enabled); |
| 1014 | }); |
| 1015 | |
| 1016 | m_jit_loadstore_paired_off = m_jit->addAction(tr("JIT LoadStore Paired Off")); |
| 1017 | m_jit_loadstore_paired_off->setCheckable(true); |
| 1018 | m_jit_loadstore_paired_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_LOAD_STORE_PAIRED_OFF)); |
| 1019 | connect(m_jit_loadstore_paired_off, &QAction::toggled, [](bool enabled) { |
| 1020 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_LOAD_STORE_PAIRED_OFF, enabled); |
| 1021 | }); |
| 1022 | |
| 1023 | m_jit_floatingpoint_off = m_jit->addAction(tr("JIT FloatingPoint Off")); |
| 1024 | m_jit_floatingpoint_off->setCheckable(true); |
| 1025 | m_jit_floatingpoint_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_FLOATING_POINT_OFF)); |
| 1026 | connect(m_jit_floatingpoint_off, &QAction::toggled, [](bool enabled) { |
| 1027 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_FLOATING_POINT_OFF, enabled); |
| 1028 | }); |
| 1029 | |
| 1030 | m_jit_integer_off = m_jit->addAction(tr("JIT Integer Off")); |
| 1031 | m_jit_integer_off->setCheckable(true); |
| 1032 | m_jit_integer_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_INTEGER_OFF)); |
| 1033 | connect(m_jit_integer_off, &QAction::toggled, [](bool enabled) { |
| 1034 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_INTEGER_OFF, enabled); |
| 1035 | }); |
| 1036 | |
| 1037 | m_jit_paired_off = m_jit->addAction(tr("JIT Paired Off")); |
| 1038 | m_jit_paired_off->setCheckable(true); |
| 1039 | m_jit_paired_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_PAIRED_OFF)); |
| 1040 | connect(m_jit_paired_off, &QAction::toggled, [](bool enabled) { |
| 1041 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_PAIRED_OFF, enabled); |
| 1042 | }); |
| 1043 | |
| 1044 | m_jit_systemregisters_off = m_jit->addAction(tr("JIT SystemRegisters Off")); |
| 1045 | m_jit_systemregisters_off->setCheckable(true); |
| 1046 | m_jit_systemregisters_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_SYSTEM_REGISTERS_OFF)); |
| 1047 | connect(m_jit_systemregisters_off, &QAction::toggled, [](bool enabled) { |
| 1048 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_SYSTEM_REGISTERS_OFF, enabled); |
| 1049 | }); |
| 1050 | |
| 1051 | m_jit_branch_off = m_jit->addAction(tr("JIT Branch Off")); |
| 1052 | m_jit_branch_off->setCheckable(true); |
| 1053 | m_jit_branch_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_BRANCH_OFF)); |
| 1054 | connect(m_jit_branch_off, &QAction::toggled, [](bool enabled) { |
| 1055 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_BRANCH_OFF, enabled); |
| 1056 | }); |
| 1057 | |
| 1058 | m_jit_register_cache_off = m_jit->addAction(tr("JIT Register Cache Off")); |
| 1059 | m_jit_register_cache_off->setCheckable(true); |
| 1060 | m_jit_register_cache_off->setChecked(Config::Get(Config::MAIN_DEBUG_JIT_REGISTER_CACHE_OFF)); |
| 1061 | connect(m_jit_register_cache_off, &QAction::toggled, [](bool enabled) { |
| 1062 | Config::SetBaseOrCurrent(Config::MAIN_DEBUG_JIT_REGISTER_CACHE_OFF, enabled); |
| 1063 | }); |
| 1064 | } |
| 1065 | |
| 1066 | void MenuBar::AddSymbolsMenu() |
| 1067 | { |
| 1068 | m_symbols = addMenu(tr("Symbols")); |
| 1069 | |
| 1070 | m_symbols->addAction(tr("&Clear Symbols"), this, &MenuBar::ClearSymbols); |
| 1071 | |
| 1072 | auto* generate = m_symbols->addMenu(tr("&Generate Symbols From")); |
| 1073 | generate->addAction(tr("Address"), this, &MenuBar::GenerateSymbolsFromAddress); |
| 1074 | generate->addAction(tr("Signature Database"), this, &MenuBar::GenerateSymbolsFromSignatureDB); |
| 1075 | generate->addAction(tr("RSO Modules"), this, &MenuBar::GenerateSymbolsFromRSO); |
| 1076 | m_symbols->addSeparator(); |
| 1077 | |
| 1078 | m_symbols->addAction(tr("&Load Symbol Map"), this, &MenuBar::LoadSymbolMap); |
| 1079 | m_symbols->addAction(tr("&Save Symbol Map"), this, &MenuBar::SaveSymbolMap); |
| 1080 | m_symbols->addSeparator(); |
| 1081 | |
| 1082 | m_symbols->addAction(tr("Load &Other Map File..."), this, &MenuBar::LoadOtherSymbolMap); |
| 1083 | m_symbols->addAction(tr("Load &Bad Map File..."), this, &MenuBar::LoadBadSymbolMap); |
| 1084 | m_symbols->addAction(tr("Save Symbol Map &As..."), this, &MenuBar::SaveSymbolMapAs); |
| 1085 | m_symbols->addSeparator(); |
| 1086 | |
| 1087 | m_symbols->addAction(tr("Sa&ve Code"), this, &MenuBar::SaveCode); |
| 1088 | m_symbols->addSeparator(); |
| 1089 | |
| 1090 | m_symbols->addAction(tr("C&reate Signature File..."), this, &MenuBar::CreateSignatureFile); |
| 1091 | m_symbols->addAction(tr("Append to &Existing Signature File..."), this, |
| 1092 | &MenuBar::AppendSignatureFile); |
| 1093 | m_symbols->addAction(tr("Combine &Two Signature Files..."), this, |
| 1094 | &MenuBar::CombineSignatureFiles); |
| 1095 | m_symbols->addAction(tr("Appl&y Signature File..."), this, &MenuBar::ApplySignatureFile); |
| 1096 | m_symbols->addSeparator(); |
| 1097 | |
| 1098 | m_symbols->addAction(tr("&Patch HLE Functions"), this, &MenuBar::PatchHLEFunctions); |
| 1099 | } |
| 1100 | |
| 1101 | void MenuBar::UpdateToolsMenu(const Core::State state) |
| 1102 | { |
| 1103 | const bool is_uninitialized = state == Core::State::Uninitialized; |
| 1104 | const bool is_running = state == Core::State::Running || state == Core::State::Paused; |
| 1105 | |
| 1106 | m_boot_sysmenu->setEnabled(is_uninitialized); |
| 1107 | m_perform_online_update_menu->setEnabled(is_uninitialized); |
| 1108 | m_ntscj_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(JAP_DIR))); |
| 1109 | m_ntscu_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(USA_DIR))); |
| 1110 | m_pal_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(EUR_DIR))); |
| 1111 | m_dev_ipl->setEnabled(is_uninitialized && File::Exists(Config::GetBootROMPath(DEV_DIR))); |
| 1112 | m_wad_install_action->setEnabled(is_uninitialized); |
| 1113 | m_import_backup->setEnabled(is_uninitialized); |
| 1114 | m_check_nand->setEnabled(is_uninitialized); |
| 1115 | m_import_wii_save->setEnabled(is_uninitialized); |
| 1116 | m_import_wii_saves->setEnabled(is_uninitialized); |
| 1117 | m_export_wii_saves->setEnabled(is_uninitialized); |
| 1118 | |
| 1119 | if (is_uninitialized) |
| 1120 | { |
| 1121 | IOS::HLE::Kernel ios; |
| 1122 | const auto tmd = ios.GetESCore().FindInstalledTMD(Titles::SYSTEM_MENU); |
| 1123 | |
| 1124 | const QString sysmenu_version = |
| 1125 | tmd.IsValid() ? QString::fromStdString( |
| 1126 | DiscIO::GetSysMenuVersionString(tmd.GetTitleVersion(), tmd.IsvWii())) : |
| 1127 | QString{}; |
| 1128 | |
| 1129 | const QString sysmenu_text = (tmd.IsValid() && tmd.IsvWii()) ? tr("Load vWii System Menu %1") : |
| 1130 | tr("Load Wii System Menu %1"); |
| 1131 | |
| 1132 | m_boot_sysmenu->setText(sysmenu_text.arg(sysmenu_version)); |
| 1133 | |
| 1134 | m_boot_sysmenu->setEnabled(tmd.IsValid()); |
| 1135 | |
| 1136 | for (QAction* action : m_perform_online_update_menu->actions()) |
| 1137 | action->setEnabled(!tmd.IsValid()); |
| 1138 | m_perform_online_update_for_current_region->setEnabled(tmd.IsValid()); |
| 1139 | } |
| 1140 | |
| 1141 | const auto bt = WiiUtils::GetBluetoothEmuDevice(); |
| 1142 | const bool enable_wiimotes = is_running && bt != nullptr; |
| 1143 | |
| 1144 | for (std::size_t i = 0; i < m_wii_remotes.size(); i++) |
| 1145 | { |
| 1146 | QAction* const wii_remote = m_wii_remotes[i]; |
| 1147 | |
| 1148 | wii_remote->setEnabled(enable_wiimotes); |
| 1149 | if (enable_wiimotes) |
| 1150 | wii_remote->setChecked(bt->AccessWiimoteByIndex(i)->IsConnected()); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | #ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 1155 | void MenuBar::UpdateAchievementDevelopmentMenu() |
| 1156 | { |
| 1157 | auto* dev_menu = AchievementManager::GetInstance().GetDevelopmentMenu(); |
| 1158 | if (dev_menu) |
| 1159 | { |
| 1160 | m_achievements_dev_menu->menuAction()->setVisible(true); |
| 1161 | m_achievements_dev_menu->clear(); |
| 1162 | for (u32 i = 0; i < dev_menu->num_items; i++) |
| 1163 | { |
| 1164 | const auto& menu_item = dev_menu->items[i]; |
| 1165 | if (menu_item.label == nullptr) |
| 1166 | { |
| 1167 | m_achievements_dev_menu->addSeparator(); |
| 1168 | continue; |
| 1169 | } |
| 1170 | auto* ra_dev_menu_item = m_achievements_dev_menu->addAction( |
| 1171 | QString::fromStdString(menu_item.label), this, |
| 1172 | [menu_item] { AchievementManager::GetInstance().ActivateDevMenuItem(menu_item.id); }); |
| 1173 | ra_dev_menu_item->setEnabled(menu_item.enabled); |
| 1174 | // Recommended hardcode by RAIntegration.dll developer Jamiras |
| 1175 | ra_dev_menu_item->setCheckable(i < 2); |
| 1176 | ra_dev_menu_item->setChecked(menu_item.checked); |
| 1177 | } |
| 1178 | } |
| 1179 | else |
| 1180 | { |
| 1181 | m_achievements_dev_menu->menuAction()->setVisible(false); |
| 1182 | } |
| 1183 | } |
| 1184 | #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION |
| 1185 | |
| 1186 | void MenuBar::InstallWAD() |
| 1187 | { |
| 1188 | QString wad_file = DolphinFileDialog::getOpenFileName(this, tr("Select Title to Install to NAND"), |
| 1189 | QString(), tr("WAD files (*.wad)")); |
| 1190 | |
| 1191 | if (wad_file.isEmpty()) |
| 1192 | return; |
| 1193 | |
| 1194 | if (WiiUtils::InstallWAD(wad_file.toStdString())) |
| 1195 | { |
| 1196 | Settings::Instance().NANDRefresh(); |
| 1197 | ModalMessageBox::information(this, tr("Success"), |
| 1198 | tr("Successfully installed this title to the NAND.")); |
| 1199 | } |
| 1200 | else |
| 1201 | { |
| 1202 | ModalMessageBox::critical(this, tr("Failure"), tr("Failed to install this title to the NAND.")); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | void MenuBar::ImportWiiSave() |
| 1207 | { |
| 1208 | QString file = |
| 1209 | DolphinFileDialog::getOpenFileName(this, tr("Select Save File"), QDir::currentPath(), |
| 1210 | tr("Wii save files (*.bin);;" |
| 1211 | "All Files (*)")); |
| 1212 | |
| 1213 | if (file.isEmpty()) |
| 1214 | return; |
| 1215 | |
| 1216 | auto can_overwrite = [&] { |
| 1217 | return ModalMessageBox::question( |
| 1218 | this, tr("Save Import"), |
| 1219 | tr("Save data for this title already exists in the NAND. Consider backing up " |
| 1220 | "the current data before overwriting.\n\nOverwrite existing save data?")) == |
| 1221 | QMessageBox::Yes; |
| 1222 | }; |
| 1223 | |
| 1224 | const auto result = WiiSave::Import(file.toStdString(), can_overwrite); |
| 1225 | switch (result) |
| 1226 | { |
| 1227 | case WiiSave::CopyResult::Success: |
| 1228 | ModalMessageBox::information(this, tr("Save Import"), tr("Successfully imported save file.")); |
| 1229 | break; |
| 1230 | case WiiSave::CopyResult::CorruptedSource: |
| 1231 | ModalMessageBox::critical(this, tr("Save Import"), |
| 1232 | tr("Failed to import save file. The given file appears to be " |
| 1233 | "corrupted or is not a valid Wii save.")); |
| 1234 | break; |
| 1235 | case WiiSave::CopyResult::TitleMissing: |
| 1236 | ModalMessageBox::critical( |
| 1237 | this, tr("Save Import"), |
| 1238 | tr("Failed to import save file. Please launch the game once, then try again.")); |
| 1239 | break; |
| 1240 | case WiiSave::CopyResult::Cancelled: |
| 1241 | break; |
| 1242 | default: |
| 1243 | ModalMessageBox::critical( |
| 1244 | this, tr("Save Import"), |
| 1245 | tr("Failed to import save file. Your NAND may be corrupt, or something is preventing " |
| 1246 | "access to files within it. Try repairing your NAND (Tools -> Manage NAND -> Check " |
| 1247 | "NAND...), then import the save again.")); |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | void MenuBar::ImportWiiSaves() |
| 1253 | { |
| 1254 | QString folder = |
| 1255 | DolphinFileDialog::getExistingDirectory(this, tr("Select Save Folder"), QDir::currentPath()); |
| 1256 | |
| 1257 | if (folder.isEmpty()) |
| 1258 | return; |
| 1259 | |
| 1260 | QDirIterator it(folder, QStringList(QStringLiteral("*.bin")), QDir::Files, |
| 1261 | QDirIterator::Subdirectories); |
| 1262 | QStringList failure_details; |
| 1263 | size_t success_count = 0; |
| 1264 | size_t fail_count = 0; |
| 1265 | bool yes_all = false; |
| 1266 | bool no_all = false; |
| 1267 | |
| 1268 | while (it.hasNext()) |
| 1269 | { |
| 1270 | const QString file = it.next(); |
| 1271 | |
| 1272 | auto can_overwrite = [&] { |
| 1273 | if (yes_all) |
| 1274 | return true; |
| 1275 | if (no_all) |
| 1276 | return false; |
| 1277 | |
| 1278 | auto response = ModalMessageBox::question( |
| 1279 | this, tr("Save Import"), |
| 1280 | tr("%1: Save data for this title already exists in the NAND. Consider backing up " |
| 1281 | "the current data before overwriting.\n\nOverwrite existing save data?") |
| 1282 | .arg(file), |
| 1283 | QMessageBox::StandardButton::YesAll | QMessageBox::StandardButton::Yes | |
| 1284 | QMessageBox::StandardButton::No | QMessageBox::StandardButton::NoAll); |
| 1285 | |
| 1286 | if (response == QMessageBox::YesAll) |
| 1287 | { |
| 1288 | yes_all = true; |
| 1289 | return true; |
| 1290 | } |
| 1291 | else if (response == QMessageBox::NoAll) |
| 1292 | { |
| 1293 | no_all = true; |
| 1294 | return false; |
| 1295 | } |
| 1296 | return response == QMessageBox::Yes; |
| 1297 | }; |
| 1298 | |
| 1299 | const auto result = WiiSave::Import(file.toStdString(), can_overwrite); |
| 1300 | switch (result) |
| 1301 | { |
| 1302 | case WiiSave::CopyResult::Success: |
| 1303 | success_count++; |
| 1304 | break; |
| 1305 | case WiiSave::CopyResult::CorruptedSource: |
| 1306 | fail_count++; |
| 1307 | failure_details.append(tr("%1: Failed to import save file. The given file appears to be " |
| 1308 | "corrupted or is not a valid Wii save.") |
| 1309 | .arg(file)); |
| 1310 | break; |
| 1311 | case WiiSave::CopyResult::TitleMissing: |
| 1312 | fail_count++; |
| 1313 | failure_details.append( |
| 1314 | tr("%1: Failed to import save file. Please launch the game once, then try again.") |
| 1315 | .arg(file)); |
| 1316 | break; |
| 1317 | case WiiSave::CopyResult::Cancelled: |
| 1318 | break; |
| 1319 | default: |
| 1320 | fail_count++; |
| 1321 | failure_details.append( |
| 1322 | tr("%1: Failed to import save file. Your NAND may be corrupt, or something is preventing " |
| 1323 | "access to files within it. Try repairing your NAND (Tools -> Manage NAND -> Check " |
| 1324 | "NAND...), then import the save again.") |
| 1325 | .arg(file)); |
| 1326 | break; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | if (success_count == 0 && fail_count == 0) |
| 1331 | return; |
| 1332 | |
| 1333 | ModalMessageBox::information(this, tr("Save Import"), |
| 1334 | tr("Successfully imported %1 save file(s) with %2 failure(s)") |
| 1335 | .arg(success_count) |
| 1336 | .arg(fail_count), |
| 1337 | QMessageBox::Ok, QMessageBox::NoButton, Qt::WindowModal, |
| 1338 | failure_details.join(QStringLiteral("\n\n"))); |
| 1339 | } |
| 1340 | |
| 1341 | void MenuBar::ExportWiiSaves() |
| 1342 | { |
| 1343 | const QString export_dir = DolphinFileDialog::getExistingDirectory( |
| 1344 | this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)), |
| 1345 | QFileDialog::ShowDirsOnly); |
| 1346 | if (export_dir.isEmpty()) |
| 1347 | return; |
| 1348 | |
| 1349 | const size_t count = WiiSave::ExportAll(export_dir.toStdString()); |
| 1350 | ModalMessageBox::information(this, tr("Save Export"), |
| 1351 | tr("Exported %n save(s)", "", static_cast<int>(count))); |
| 1352 | } |
| 1353 | |
| 1354 | void MenuBar::CheckNAND() |
| 1355 | { |
| 1356 | IOS::HLE::Kernel ios; |
| 1357 | WiiUtils::NANDCheckResult result = WiiUtils::CheckNAND(ios); |
| 1358 | if (!result.bad) |
| 1359 | { |
| 1360 | const bool overfull = result.used_clusters_user > IOS::HLE::FS::USER_CLUSTERS || |
| 1361 | result.used_clusters_system > IOS::HLE::FS::SYSTEM_CLUSTERS; |
| 1362 | const QString user_cluster_message = |
| 1363 | tr("The user-accessible part of your NAND contains %1 blocks (%2 KiB) " |
| 1364 | "of data, out of an allowed maximum of %3 blocks (%4 KiB).") |
| 1365 | .arg(Common::AlignUp(result.used_clusters_user, IOS::HLE::FS::CLUSTERS_PER_BLOCK) / |
| 1366 | IOS::HLE::FS::CLUSTERS_PER_BLOCK) |
| 1367 | .arg((result.used_clusters_user * IOS::HLE::FS::CLUSTER_SIZE) / 1024) |
| 1368 | .arg(IOS::HLE::FS::USER_CLUSTERS / IOS::HLE::FS::CLUSTERS_PER_BLOCK) |
| 1369 | .arg((IOS::HLE::FS::USER_CLUSTERS * IOS::HLE::FS::CLUSTER_SIZE) / 1024); |
| 1370 | const QString system_cluster_message = |
| 1371 | tr("The system-reserved part of your NAND contains %1 blocks (%2 KiB) " |
| 1372 | "of data, out of an allowed maximum of %3 blocks (%4 KiB).") |
| 1373 | .arg(Common::AlignUp(result.used_clusters_system, IOS::HLE::FS::CLUSTERS_PER_BLOCK) / |
| 1374 | IOS::HLE::FS::CLUSTERS_PER_BLOCK) |
| 1375 | .arg((result.used_clusters_system * IOS::HLE::FS::CLUSTER_SIZE) / 1024) |
| 1376 | .arg(IOS::HLE::FS::SYSTEM_CLUSTERS / IOS::HLE::FS::CLUSTERS_PER_BLOCK) |
| 1377 | .arg((IOS::HLE::FS::SYSTEM_CLUSTERS * IOS::HLE::FS::CLUSTER_SIZE) / 1024); |
| 1378 | |
| 1379 | if (overfull) |
| 1380 | { |
| 1381 | ModalMessageBox::warning(this, tr("NAND Check"), |
| 1382 | QStringLiteral("<b>%1</b><br/><br/>%2<br/><br/>%3") |
| 1383 | .arg(tr("Your NAND contains more data than allowed. Wii " |
| 1384 | "software may behave incorrectly or not allow saving.")) |
| 1385 | .arg(user_cluster_message) |
| 1386 | .arg(system_cluster_message)); |
| 1387 | } |
| 1388 | else |
| 1389 | { |
| 1390 | ModalMessageBox::information(this, tr("NAND Check"), |
| 1391 | QStringLiteral("<b>%1</b><br/><br/>%2<br/><br/>%3") |
| 1392 | .arg(tr("No issues have been detected.")) |
| 1393 | .arg(user_cluster_message) |
| 1394 | .arg(system_cluster_message)); |
| 1395 | } |
| 1396 | return; |
| 1397 | } |
| 1398 | |
| 1399 | { |
| 1400 | NANDRepairDialog dialog(result, this); |
| 1401 | if (dialog.exec() != QDialog::Accepted) |
| 1402 | return; |
| 1403 | } |
| 1404 | |
| 1405 | if (WiiUtils::RepairNAND(ios)) |
| 1406 | { |
| 1407 | ModalMessageBox::information(this, tr("NAND Check"), tr("The NAND has been repaired.")); |
| 1408 | return; |
| 1409 | } |
| 1410 | |
| 1411 | ModalMessageBox::critical(this, tr("NAND Check"), |
| 1412 | tr("The NAND could not be repaired. It is recommended to back up " |
| 1413 | "your current data and start over with a fresh NAND.")); |
| 1414 | } |
| 1415 | |
| 1416 | void MenuBar::NANDExtractCertificates() |
| 1417 | { |
| 1418 | if (DiscIO::NANDImporter().ExtractCertificates()) |
| 1419 | { |
| 1420 | ModalMessageBox::information(this, tr("Success"), |
| 1421 | tr("Successfully extracted certificates from NAND")); |
| 1422 | } |
| 1423 | else |
| 1424 | { |
| 1425 | ModalMessageBox::critical(this, tr("Error"), tr("Failed to extract certificates from NAND")); |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | void MenuBar::OnSelectionChanged(const std::shared_ptr<const UICommon::GameFile>& game_file) |
| 1430 | { |
| 1431 | m_game_selected = !!game_file; |
| 1432 | |
| 1433 | auto& system = Core::System::GetInstance(); |
| 1434 | const bool can_start_from_boot = m_game_selected && Core::IsUninitialized(system); |
| 1435 | const bool can_start_from_savestate = Core::IsRunning(system); |
| 1436 | m_recording_play->setEnabled(can_start_from_boot); |
| 1437 | m_recording_start->setEnabled((can_start_from_boot || can_start_from_savestate) && |
| 1438 | !system.GetMovie().IsPlayingInput()); |
| 1439 | } |
| 1440 | |
| 1441 | void MenuBar::OnRecordingStatusChanged(bool recording) |
| 1442 | { |
| 1443 | auto& system = Core::System::GetInstance(); |
| 1444 | const bool can_start_from_boot = m_game_selected && Core::IsUninitialized(system); |
| 1445 | const bool can_start_from_savestate = Core::IsRunning(system); |
| 1446 | |
| 1447 | m_recording_start->setEnabled(!recording && (can_start_from_boot || can_start_from_savestate)); |
| 1448 | m_recording_stop->setEnabled(recording); |
| 1449 | m_recording_export->setEnabled(recording); |
| 1450 | } |
| 1451 | |
| 1452 | void MenuBar::OnReadOnlyModeChanged(bool read_only) |
| 1453 | { |
| 1454 | m_recording_read_only->setChecked(read_only); |
| 1455 | } |
| 1456 | |
| 1457 | void MenuBar::ChangeDebugFont() |
| 1458 | { |
| 1459 | bool okay; |
| 1460 | QFont font = QFontDialog::getFont(&okay, Settings::Instance().GetDebugFont(), this, |
| 1461 | tr("Pick a debug font")); |
| 1462 | |
| 1463 | if (okay) |
| 1464 | Settings::Instance().SetDebugFont(font); |
| 1465 | } |
| 1466 | |
| 1467 | void MenuBar::ClearSymbols() |
| 1468 | { |
| 1469 | auto result = ModalMessageBox::warning(this, tr("Confirmation"), |
| 1470 | tr("Do you want to clear the list of symbol names?"), |
| 1471 | QMessageBox::Yes | QMessageBox::Cancel); |
| 1472 | |
| 1473 | if (result == QMessageBox::Cancel) |
| 1474 | return; |
| 1475 | |
| 1476 | Core::System::GetInstance().GetPPCSymbolDB().Clear(); |
| 1477 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1478 | } |
| 1479 | |
| 1480 | void MenuBar::GenerateSymbolsFromAddress() |
| 1481 | { |
| 1482 | auto& system = Core::System::GetInstance(); |
| 1483 | auto& memory = system.GetMemory(); |
| 1484 | auto& ppc_symbol_db = system.GetPPCSymbolDB(); |
| 1485 | |
| 1486 | const Core::CPUThreadGuard guard(system); |
| 1487 | |
| 1488 | PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR, |
| 1489 | Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db); |
| 1490 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1491 | } |
| 1492 | |
| 1493 | void MenuBar::GenerateSymbolsFromSignatureDB() |
| 1494 | { |
| 1495 | auto& system = Core::System::GetInstance(); |
| 1496 | auto& memory = system.GetMemory(); |
| 1497 | auto& ppc_symbol_db = system.GetPPCSymbolDB(); |
| 1498 | |
| 1499 | const Core::CPUThreadGuard guard(system); |
| 1500 | |
| 1501 | PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR, |
| 1502 | Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db); |
| 1503 | SignatureDB db(SignatureDB::HandlerType::DSY); |
| 1504 | if (db.Load(File::GetSysDirectory() + TOTALDB)) |
| 1505 | { |
| 1506 | db.Apply(guard, &ppc_symbol_db); |
| 1507 | ModalMessageBox::information( |
| 1508 | this, tr("Information"), |
| 1509 | tr("Generated symbol names from '%1'").arg(QString::fromStdString(TOTALDB))); |
| 1510 | db.List(); |
| 1511 | } |
| 1512 | else |
| 1513 | { |
| 1514 | ModalMessageBox::critical( |
| 1515 | this, tr("Error"), |
| 1516 | tr("'%1' not found, no symbol names generated").arg(QString::fromStdString(TOTALDB))); |
| 1517 | } |
| 1518 | |
| 1519 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1520 | } |
| 1521 | |
| 1522 | void MenuBar::GenerateSymbolsFromRSO() |
| 1523 | { |
| 1524 | // i18n: RSO refers to a proprietary format for shared objects (like DLL files). |
| 1525 | const int ret = |
| 1526 | ModalMessageBox::question(this, tr("RSO auto-detection"), tr("Auto-detect RSO modules?")); |
| 1527 | if (ret == QMessageBox::Yes) |
| 1528 | return GenerateSymbolsFromRSOAuto(); |
| 1529 | |
| 1530 | const QString text = |
| 1531 | QInputDialog::getText(this, tr("Input"), tr("Enter the RSO module address:"), |
| 1532 | QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint); |
| 1533 | bool good; |
| 1534 | const uint address = text.toUInt(&good, 16); |
| 1535 | |
| 1536 | if (!good) |
| 1537 | { |
| 1538 | ModalMessageBox::warning(this, tr("Error"), tr("Invalid RSO module address: %1").arg(text)); |
| 1539 | return; |
| 1540 | } |
| 1541 | |
| 1542 | auto& system = Core::System::GetInstance(); |
| 1543 | const Core::CPUThreadGuard guard(system); |
| 1544 | |
| 1545 | RSOChainView rso_chain; |
| 1546 | if (rso_chain.Load(guard, static_cast<u32>(address))) |
| 1547 | { |
| 1548 | rso_chain.Apply(guard, &system.GetPPCSymbolDB()); |
| 1549 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1550 | } |
| 1551 | else |
| 1552 | { |
| 1553 | ModalMessageBox::warning(this, tr("Error"), tr("Failed to load RSO module at %1").arg(text)); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | void MenuBar::GenerateSymbolsFromRSOAuto() |
| 1558 | { |
| 1559 | ParallelProgressDialog progress(tr("Modules found: %1").arg(0), tr("Cancel"), 0, 0, this); |
| 1560 | progress.GetRaw()->setWindowTitle(tr("Detecting RSO Modules")); |
| 1561 | progress.GetRaw()->setMinimumDuration(1000 * 10); |
| 1562 | progress.GetRaw()->setWindowModality(Qt::WindowModal); |
| 1563 | |
| 1564 | auto future = std::async(std::launch::async, [&progress, this]() -> RSOVector { |
| 1565 | progress.SetValue(0); |
| 1566 | auto matches = DetectRSOModules(progress); |
| 1567 | progress.Reset(); |
| 1568 | |
| 1569 | return matches; |
| 1570 | }); |
| 1571 | progress.GetRaw()->exec(); |
| 1572 | |
| 1573 | const auto matches = future.get(); |
| 1574 | |
| 1575 | QStringList items; |
| 1576 | for (const auto& match : matches) |
| 1577 | { |
| 1578 | const QString item = QLatin1String("%1 %2"); |
| 1579 | items << item.arg(QString::number(match.first, 16), QString::fromStdString(match.second)); |
| 1580 | } |
| 1581 | |
| 1582 | if (items.empty()) |
| 1583 | { |
| 1584 | ModalMessageBox::warning(this, tr("Error"), tr("Unable to auto-detect RSO module")); |
| 1585 | return; |
| 1586 | } |
| 1587 | |
| 1588 | bool ok; |
| 1589 | const QString item = |
| 1590 | QInputDialog::getItem(this, tr("Input"), tr("Select the RSO module address:"), items, 0, |
| 1591 | false, &ok, Qt::WindowCloseButtonHint); |
| 1592 | |
| 1593 | if (!ok) |
| 1594 | return; |
| 1595 | |
| 1596 | RSOChainView rso_chain; |
| 1597 | const u32 address = item.mid(0, item.indexOf(QLatin1Char(' '))).toUInt(nullptr, 16); |
| 1598 | |
| 1599 | auto& system = Core::System::GetInstance(); |
| 1600 | const Core::CPUThreadGuard guard(system); |
| 1601 | |
| 1602 | if (rso_chain.Load(guard, address)) |
| 1603 | { |
| 1604 | rso_chain.Apply(guard, &system.GetPPCSymbolDB()); |
| 1605 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1606 | } |
| 1607 | else |
| 1608 | { |
| 1609 | ModalMessageBox::warning(this, tr("Error"), tr("Failed to load RSO module at %1").arg(address)); |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | RSOVector MenuBar::DetectRSOModules(ParallelProgressDialog& progress) |
| 1614 | { |
| 1615 | Core::CPUThreadGuard guard(Core::System::GetInstance()); |
| 1616 | |
| 1617 | constexpr std::array<std::string_view, 2> search_for = {".elf", ".plf"}; |
| 1618 | |
| 1619 | const AddressSpace::Accessors* accessors = |
| 1620 | AddressSpace::GetAccessors(AddressSpace::Type::Effective); |
| 1621 | |
| 1622 | RSOVector matches; |
| 1623 | |
| 1624 | // Find filepath to elf/plf commonly used by RSO modules |
| 1625 | for (const auto& str : search_for) |
| 1626 | { |
| 1627 | u32 next = 0; |
| 1628 | while (true) |
| 1629 | { |
| 1630 | if (progress.WasCanceled()) |
| 1631 | { |
| 1632 | return matches; |
| 1633 | } |
| 1634 | |
| 1635 | auto found_addr = accessors->Search(guard, next, reinterpret_cast<const u8*>(str.data()), |
| 1636 | str.size() + 1, true); |
| 1637 | |
| 1638 | if (!found_addr.has_value()) |
| 1639 | break; |
| 1640 | |
| 1641 | next = *found_addr + 1; |
| 1642 | |
| 1643 | // Non-null data can precede the module name. |
| 1644 | // Get the maximum name length that a module could have. |
| 1645 | auto get_max_module_name_len = [&guard, found_addr] { |
| 1646 | constexpr u32 MODULE_NAME_MAX_LENGTH = 260; |
| 1647 | u32 len = 0; |
| 1648 | |
| 1649 | for (; len < MODULE_NAME_MAX_LENGTH; ++len) |
| 1650 | { |
| 1651 | const auto res = PowerPC::MMU::HostRead<u8>(guard, *found_addr - (len + 1)); |
| 1652 | if (!std::isprint(res)) |
| 1653 | { |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | return len; |
| 1659 | }; |
| 1660 | |
| 1661 | if (progress.WasCanceled()) |
| 1662 | { |
| 1663 | return matches; |
| 1664 | } |
| 1665 | |
| 1666 | const auto max_name_length = get_max_module_name_len(); |
| 1667 | auto found = false; |
| 1668 | u32 module_name_length = 0; |
| 1669 | |
| 1670 | // Look for the Module Name Offset Field based on each possible length |
| 1671 | for (u32 i = 0; i < max_name_length; ++i) |
| 1672 | { |
| 1673 | if (progress.WasCanceled()) |
| 1674 | { |
| 1675 | return matches; |
| 1676 | } |
| 1677 | |
| 1678 | const auto lookup_addr = (*found_addr - max_name_length) + i; |
| 1679 | |
| 1680 | const std::array<u8, 4> ref = { |
| 1681 | static_cast<u8>(lookup_addr >> 24), static_cast<u8>(lookup_addr >> 16), |
| 1682 | static_cast<u8>(lookup_addr >> 8), static_cast<u8>(lookup_addr)}; |
| 1683 | |
| 1684 | // Get the field (Module Name Offset) that point to the string |
| 1685 | const auto module_name_offset_addr = |
| 1686 | accessors->Search(guard, lookup_addr, ref.data(), ref.size(), false); |
| 1687 | if (!module_name_offset_addr.has_value()) |
| 1688 | continue; |
| 1689 | |
| 1690 | // The next 4 bytes should be the module name length |
| 1691 | module_name_length = accessors->ReadU32(guard, *module_name_offset_addr + 4); |
| 1692 | if (module_name_length == max_name_length - i + str.length()) |
| 1693 | { |
| 1694 | found_addr = module_name_offset_addr; |
| 1695 | found = true; |
| 1696 | break; |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | if (!found) |
| 1701 | continue; |
| 1702 | |
| 1703 | const auto module_name_offset = accessors->ReadU32(guard, *found_addr); |
| 1704 | |
| 1705 | // Go to the beginning of the RSO header |
| 1706 | matches.emplace_back(*found_addr - 16, PowerPC::MMU::HostGetString(guard, module_name_offset, |
| 1707 | module_name_length)); |
| 1708 | |
| 1709 | progress.SetLabelText(tr("Modules found: %1").arg(matches.size())); |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | return matches; |
| 1714 | } |
| 1715 | |
| 1716 | void MenuBar::LoadSymbolMap() |
| 1717 | { |
| 1718 | auto& system = Core::System::GetInstance(); |
| 1719 | auto& memory = system.GetMemory(); |
| 1720 | auto& ppc_symbol_db = system.GetPPCSymbolDB(); |
| 1721 | |
| 1722 | std::string existing_map_file, writable_map_file; |
| 1723 | bool map_exists = PPCSymbolDB::FindMapFile(&existing_map_file, &writable_map_file); |
| 1724 | |
| 1725 | if (!map_exists) |
| 1726 | { |
| 1727 | ppc_symbol_db.Clear(); |
| 1728 | |
| 1729 | { |
| 1730 | const Core::CPUThreadGuard guard(system); |
| 1731 | |
| 1732 | PPCAnalyst::FindFunctions(guard, Memory::MEM1_BASE_ADDR + 0x1300000, |
| 1733 | Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(), &ppc_symbol_db); |
| 1734 | SignatureDB db(SignatureDB::HandlerType::DSY); |
| 1735 | if (db.Load(File::GetSysDirectory() + TOTALDB)) |
| 1736 | db.Apply(guard, &ppc_symbol_db); |
| 1737 | } |
| 1738 | |
| 1739 | ModalMessageBox::warning(this, tr("Warning"), |
| 1740 | tr("'%1' not found, scanning for common functions instead") |
| 1741 | .arg(QString::fromStdString(writable_map_file))); |
| 1742 | } |
| 1743 | else |
| 1744 | { |
| 1745 | const QString existing_map_file_path = QString::fromStdString(existing_map_file); |
| 1746 | |
| 1747 | if (!TryLoadMapFile(existing_map_file_path)) |
| 1748 | return; |
| 1749 | |
| 1750 | ModalMessageBox::information(this, tr("Information"), |
| 1751 | tr("Loaded symbols from '%1'").arg(existing_map_file_path)); |
| 1752 | } |
| 1753 | |
| 1754 | HLE::PatchFunctions(system); |
| 1755 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1756 | } |
| 1757 | |
| 1758 | void MenuBar::SaveSymbolMap() |
| 1759 | { |
| 1760 | std::string existing_map_file, writable_map_file; |
| 1761 | PPCSymbolDB::FindMapFile(&existing_map_file, &writable_map_file); |
| 1762 | |
| 1763 | TrySaveSymbolMap(QString::fromStdString(writable_map_file)); |
| 1764 | } |
| 1765 | |
| 1766 | void MenuBar::LoadOtherSymbolMap() |
| 1767 | { |
| 1768 | const QString file = DolphinFileDialog::getOpenFileName( |
| 1769 | this, tr("Load Map File"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)), |
| 1770 | tr("Dolphin Map File (*.map)")); |
| 1771 | |
| 1772 | if (file.isEmpty()) |
| 1773 | return; |
| 1774 | |
| 1775 | if (!TryLoadMapFile(file)) |
| 1776 | return; |
| 1777 | |
| 1778 | auto& system = Core::System::GetInstance(); |
| 1779 | HLE::PatchFunctions(system); |
| 1780 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1781 | } |
| 1782 | |
| 1783 | void MenuBar::LoadBadSymbolMap() |
| 1784 | { |
| 1785 | const QString file = DolphinFileDialog::getOpenFileName( |
| 1786 | this, tr("Load Map File"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)), |
| 1787 | tr("Dolphin Map File (*.map)")); |
| 1788 | |
| 1789 | if (file.isEmpty()) |
| 1790 | return; |
| 1791 | |
| 1792 | if (!TryLoadMapFile(file, true)) |
| 1793 | return; |
| 1794 | |
| 1795 | auto& system = Core::System::GetInstance(); |
| 1796 | HLE::PatchFunctions(system); |
| 1797 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1798 | } |
| 1799 | |
| 1800 | void MenuBar::SaveSymbolMapAs() |
| 1801 | { |
| 1802 | const std::string& title_id_str = SConfig::GetInstance().m_debugger_game_id; |
| 1803 | const QString file = DolphinFileDialog::getSaveFileName( |
| 1804 | this, tr("Save Map File"), |
| 1805 | QString::fromStdString(File::GetUserPath(D_MAPS_IDX) + "/" + title_id_str + ".map"), |
| 1806 | tr("Dolphin Map File (*.map)")); |
| 1807 | |
| 1808 | if (file.isEmpty()) |
| 1809 | return; |
| 1810 | |
| 1811 | TrySaveSymbolMap(file); |
| 1812 | } |
| 1813 | |
| 1814 | void MenuBar::SaveCode() |
| 1815 | { |
| 1816 | std::string existing_map_file, writable_map_file; |
| 1817 | PPCSymbolDB::FindMapFile(&existing_map_file, &writable_map_file); |
| 1818 | |
| 1819 | const std::string path = |
| 1820 | writable_map_file.substr(0, writable_map_file.find_last_of('.')) + "_code.map"; |
| 1821 | |
| 1822 | auto& system = Core::System::GetInstance(); |
| 1823 | if (!system.GetPPCSymbolDB().SaveCodeMap(Core::CPUThreadGuard{system}, path)) |
| 1824 | { |
| 1825 | ModalMessageBox::warning( |
| 1826 | this, tr("Error"), |
| 1827 | tr("Failed to save code map to path '%1'").arg(QString::fromStdString(path))); |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | bool MenuBar::TryLoadMapFile(const QString& path, const bool bad) |
| 1832 | { |
| 1833 | auto& system = Core::System::GetInstance(); |
| 1834 | auto& ppc_symbol_db = system.GetPPCSymbolDB(); |
| 1835 | |
| 1836 | if (!ppc_symbol_db.LoadMap(Core::CPUThreadGuard{system}, path.toStdString(), bad)) |
| 1837 | { |
| 1838 | ModalMessageBox::warning(this, tr("Error"), tr("Failed to load map file '%1'").arg(path)); |
| 1839 | return false; |
| 1840 | } |
| 1841 | |
| 1842 | return true; |
| 1843 | } |
| 1844 | |
| 1845 | void MenuBar::TrySaveSymbolMap(const QString& path) |
| 1846 | { |
| 1847 | if (Core::System::GetInstance().GetPPCSymbolDB().SaveSymbolMap(path.toStdString())) |
| 1848 | return; |
| 1849 | |
| 1850 | ModalMessageBox::warning(this, tr("Error"), |
| 1851 | tr("Failed to save symbol map to path '%1'").arg(path)); |
| 1852 | } |
| 1853 | |
| 1854 | void MenuBar::CreateSignatureFile() |
| 1855 | { |
| 1856 | const QString text = QInputDialog::getText( |
| 1857 | this, tr("Input"), tr("Only export symbols with prefix:\n(Blank for all symbols)"), |
| 1858 | QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint); |
| 1859 | |
| 1860 | const QString file = DolphinFileDialog::getSaveFileName(this, tr("Save Signature File"), |
| 1861 | QDir::homePath(), GetSignatureSelector()); |
| 1862 | if (file.isEmpty()) |
| 1863 | return; |
| 1864 | |
| 1865 | const std::string prefix = text.toStdString(); |
| 1866 | const std::string save_path = file.toStdString(); |
| 1867 | SignatureDB db(save_path); |
| 1868 | db.Populate(&Core::System::GetInstance().GetPPCSymbolDB(), prefix); |
| 1869 | |
| 1870 | if (!db.Save(save_path)) |
| 1871 | { |
| 1872 | ModalMessageBox::warning(this, tr("Error"), tr("Failed to save signature file '%1'").arg(file)); |
| 1873 | return; |
| 1874 | } |
| 1875 | |
| 1876 | db.List(); |
| 1877 | } |
| 1878 | |
| 1879 | void MenuBar::AppendSignatureFile() |
| 1880 | { |
| 1881 | const QString text = QInputDialog::getText( |
| 1882 | this, tr("Input"), tr("Only append symbols with prefix:\n(Blank for all symbols)"), |
| 1883 | QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint); |
| 1884 | |
| 1885 | const QString file = DolphinFileDialog::getSaveFileName(this, tr("Append Signature To"), |
| 1886 | QDir::homePath(), GetSignatureSelector()); |
| 1887 | if (file.isEmpty()) |
| 1888 | return; |
| 1889 | |
| 1890 | const std::string prefix = text.toStdString(); |
| 1891 | const std::string signature_path = file.toStdString(); |
| 1892 | SignatureDB db(signature_path); |
| 1893 | db.Populate(&Core::System::GetInstance().GetPPCSymbolDB(), prefix); |
| 1894 | db.List(); |
| 1895 | db.Load(signature_path); |
| 1896 | if (!db.Save(signature_path)) |
| 1897 | { |
| 1898 | ModalMessageBox::warning(this, tr("Error"), |
| 1899 | tr("Failed to append to signature file '%1'").arg(file)); |
| 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | db.List(); |
| 1904 | } |
| 1905 | |
| 1906 | void MenuBar::ApplySignatureFile() |
| 1907 | { |
| 1908 | const QString file = DolphinFileDialog::getOpenFileName(this, tr("Apply Signature File"), |
| 1909 | QDir::homePath(), GetSignatureSelector()); |
| 1910 | |
| 1911 | if (file.isEmpty()) |
| 1912 | return; |
| 1913 | |
| 1914 | auto& system = Core::System::GetInstance(); |
| 1915 | |
| 1916 | const std::string load_path = file.toStdString(); |
| 1917 | SignatureDB db(load_path); |
| 1918 | db.Load(load_path); |
| 1919 | db.Apply(Core::CPUThreadGuard{system}, &system.GetPPCSymbolDB()); |
| 1920 | db.List(); |
| 1921 | HLE::PatchFunctions(system); |
| 1922 | emit Host::GetInstance()->PPCSymbolsChanged(); |
| 1923 | } |
| 1924 | |
| 1925 | void MenuBar::CombineSignatureFiles() |
| 1926 | { |
| 1927 | const QString priorityFile = DolphinFileDialog::getOpenFileName( |
| 1928 | this, tr("Choose Priority Input File"), QDir::homePath(), GetSignatureSelector()); |
| 1929 | if (priorityFile.isEmpty()) |
| 1930 | return; |
| 1931 | |
| 1932 | const QString secondaryFile = DolphinFileDialog::getOpenFileName( |
| 1933 | this, tr("Choose Secondary Input File"), QDir::homePath(), GetSignatureSelector()); |
| 1934 | if (secondaryFile.isEmpty()) |
| 1935 | return; |
| 1936 | |
| 1937 | const QString saveFile = DolphinFileDialog::getSaveFileName( |
| 1938 | this, tr("Save Combined Output File As"), QDir::homePath(), GetSignatureSelector()); |
| 1939 | if (saveFile.isEmpty()) |
| 1940 | return; |
| 1941 | |
| 1942 | const std::string load_pathPriorityFile = priorityFile.toStdString(); |
| 1943 | const std::string load_pathSecondaryFile = secondaryFile.toStdString(); |
| 1944 | const std::string save_path = saveFile.toStdString(); |
| 1945 | SignatureDB db(load_pathPriorityFile); |
| 1946 | db.Load(load_pathPriorityFile); |
| 1947 | db.Load(load_pathSecondaryFile); |
| 1948 | if (!db.Save(save_path)) |
| 1949 | { |
| 1950 | ModalMessageBox::warning(this, tr("Error"), |
| 1951 | tr("Failed to save to signature file '%1'").arg(saveFile)); |
| 1952 | return; |
| 1953 | } |
| 1954 | |
| 1955 | db.List(); |
| 1956 | } |
| 1957 | |
| 1958 | void MenuBar::PatchHLEFunctions() |
| 1959 | { |
| 1960 | auto& system = Core::System::GetInstance(); |
| 1961 | HLE::PatchFunctions(system); |
| 1962 | } |
| 1963 | |
| 1964 | void MenuBar::ClearCache() |
| 1965 | { |
| 1966 | auto& system = Core::System::GetInstance(); |
| 1967 | system.GetJitInterface().ClearCache(Core::CPUThreadGuard{system}); |
| 1968 | } |
| 1969 | |
| 1970 | void MenuBar::LogInstructions() |
| 1971 | { |
| 1972 | PPCTables::LogCompiledInstructions(); |
| 1973 | } |
| 1974 | |
| 1975 | void MenuBar::SearchInstruction() |
| 1976 | { |
| 1977 | bool good; |
| 1978 | const QString op = |
| 1979 | QInputDialog::getText(this, tr("Search instruction"), tr("Instruction:"), QLineEdit::Normal, |
| 1980 | QString{}, &good, Qt::WindowCloseButtonHint); |
| 1981 | |
| 1982 | if (!good) |
| 1983 | return; |
| 1984 | |
| 1985 | auto& system = Core::System::GetInstance(); |
| 1986 | auto& memory = system.GetMemory(); |
| 1987 | |
| 1988 | const std::string op_std = op.toStdString(); |
| 1989 | const Core::CPUThreadGuard guard(system); |
| 1990 | |
| 1991 | bool found = false; |
| 1992 | for (u32 addr = Memory::MEM1_BASE_ADDR; addr < Memory::MEM1_BASE_ADDR + memory.GetRamSizeReal(); |
| 1993 | addr += 4) |
| 1994 | { |
| 1995 | if (op_std == PPCTables::GetInstructionName(PowerPC::MMU::HostRead<u32>(guard, addr), addr)) |
| 1996 | { |
| 1997 | NOTICE_LOG_FMT(POWERPC, "Found {} at {:08x}", op_std, addr); |
| 1998 | found = true; |
| 1999 | } |
| 2000 | } |
| 2001 | if (!found) |
| 2002 | NOTICE_LOG_FMT(POWERPC, "Opcode {} not found", op_std); |
| 2003 | } |