A GameCube/Wii emulator and debugger written in Rust.
load dols via gecko launcher
Layle02cd918dad29
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rsindex 8b2fc7a..ca58024 100644--- a/crates/app/src/app.rs+++ b/crates/app/src/app.rs@@ -36,7 +36,9 @@ pub enum Message {SearchChanged(String),MenuChooseLibrary(Platform),MenuOpenGame,+ MenuOpenDol(Platform),GameFilePicked(Option<PathBuf>),+ DolFilePicked(Platform, Option<PathBuf>),GameFileLoaded(Result<Box<Game>, String>),MenuRescan,MenuQuit,@@ -323,6 +325,23 @@ impl App {},Message::GameFilePicked,),+ Message::MenuOpenDol(platform) => {+ let title = match platform {+ Platform::Gcn => "Open GameCube DOL",+ Platform::Wii => "Open Wii DOL",+ };+ Task::perform(+ async move {+ rfd::AsyncFileDialog::new()+ .set_title(title)+ .add_filter("DOL executables", &["dol"])+ .pick_file()+ .await+ .map(|h| h.path().to_path_buf())+ },+ move |opt| Message::DolFilePicked(platform, opt),+ )+ }Message::GameFilePicked(None) => Task::none(),Message::GameFilePicked(Some(path)) => {let Some(format) = Format::from_path(&path) else {@@ -339,6 +358,15 @@ impl App {Message::GameFileLoaded,)}+ Message::DolFilePicked(_, None) => Task::none(),+ Message::DolFilePicked(platform, Some(path)) => Task::perform(+ async move {+ tokio::task::spawn_blocking(move || library::load_dol(&path, platform).map(Box::new))+ .await+ .unwrap_or_else(|err| Err(err.to_string()))+ },+ Message::GameFileLoaded,+ ),Message::GameFileLoaded(Err(err)) => {tracing::warn!(%err, "failed to load picked game");Task::none()diff --git a/crates/app/src/game.rs b/crates/app/src/game.rsindex 5c87c05..9171164 100644--- a/crates/app/src/game.rs+++ b/crates/app/src/game.rs@@ -77,6 +77,7 @@ pub enum Format {Iso,Rvz,Zip,+ Dol,}impl Format {@@ -95,6 +96,7 @@ impl Format {Format::Iso => "ISO",Format::Rvz => "RVZ",Format::Zip => "ZIP",+ Format::Dol => "DOL",}}}@@ -190,6 +192,33 @@ impl Game {}}+ pub fn from_dol(path: &Path, data: &[u8], platform: Platform) -> Self {+ let file_name = path.file_name().and_then(|s| s.to_str()).unwrap_or("").to_owned();+ let title = path.file_stem().and_then(|s| s.to_str()).unwrap_or("DOL").to_owned();+ let game_id = gecko::jit::cache::dol_cache_id(data);++ let title_lc = title.to_lowercase();+ let file_name_lc = file_name.to_lowercase();+ let game_id_lc = game_id.to_lowercase();++ Game {+ path: path.to_owned(),+ file_name,+ game_id,+ maker_code: String::new(),+ disc_id: 0,+ title,+ region: Region::Unknown,+ platform,+ format: Format::Dol,+ banner: None,+ title_lc,+ file_name_lc,+ game_id_lc,+ banner_handle: Arc::new(OnceLock::new()),+ }+ }+pub fn matches_lc(&self, query: &str) -> bool {if query.is_empty() {return true;diff --git a/crates/app/src/library.rs b/crates/app/src/library.rsindex 1def863..162c2f8 100644--- a/crates/app/src/library.rs+++ b/crates/app/src/library.rs@@ -6,7 +6,7 @@ use futures::stream::Stream;use walkdir::WalkDir;use crate::cache::{CacheEntry, FileFingerprint, LibraryCache};-use crate::game::{Format, Game};+use crate::game::{Format, Game, Platform};#[derive(Debug, Clone)]pub enum ScanProgress {@@ -144,3 +144,8 @@ pub fn load_one(path: &Path, format: Format) -> Result<Game, String> {}));result.map_err(|_| "image::load_dvd panicked".to_owned())}++pub fn load_dol(path: &Path, platform: Platform) -> Result<Game, String> {+ let data = std::fs::read(path).map_err(|e| e.to_string())?;+ Ok(Game::from_dol(path, &data, platform))+}diff --git a/crates/app/src/player/state.rs b/crates/app/src/player/state.rsindex 71c2214..be45cf0 100644--- a/crates/app/src/player/state.rs+++ b/crates/app/src/player/state.rs@@ -14,11 +14,12 @@ use iced::keyboard::key::{Code, Physical};use iced::mouse::Button as MouseButton;use crate::config::{Config, DSP_COEF_FILE, DSP_ROM_FILE, IPL_FILE};-use crate::game::{Game, Platform};+use crate::game::{Format, Game, Platform};use crate::player::{audio, emu_thread, input};struct BootParams {disc_path: PathBuf,+ format: Format,dsp_path: Option<PathBuf>,coef_path: Option<PathBuf>,ipl_path: Option<PathBuf>,@@ -74,11 +75,12 @@ impl PlayerState {let dsp = Config::resolve_in_dir(&config.dsp_rom, &system_dir, DSP_ROM_FILE);let coef = Config::resolve_in_dir(&config.dsp_coef, &system_dir, DSP_COEF_FILE);let ipl = Config::resolve_in_dir(&config.ipl, &system_dir, IPL_FILE);- let boot_error = self::validate(game.platform, &dsp, &coef, &ipl, &system_dir);+ let boot_error = self::validate(game.platform, game.format, &dsp, &coef, &ipl, &system_dir);Arc::new(Self {boot: Mutex::new(Some(BootParams {disc_path: game.path.clone(),+ format: game.format,dsp_path: dsp,coef_path: coef,ipl_path: ipl,@@ -232,68 +234,74 @@ fn player_thread(queue: wgpu::Queue,format: wgpu::TextureFormat,) {- let shutdown = state.shutdown.clone();tracing::warn!(?format, path = %params.disc_path.display(), "player booting");- let dvd_data = match std::fs::read(¶ms.disc_path) {+ let data = match std::fs::read(¶ms.disc_path) {Ok(b) => b,Err(err) => {tracing::error!(?err, path = %params.disc_path.display(), "read disc");return;}};- if shutdown.load(Ordering::Relaxed) {+ if state.shutdown.load(Ordering::Relaxed) {return;}- let dvd = image::load_dvd(dvd_data);- let game_id = dvd.header().game_id();let (renderer, sink) = Renderer::new(device, queue, format, state.aspect, state.upscale);{let first_frame = state.first_frame.clone();renderer.set_frame_ready_callback(move |_| {- if !first_frame.swap(true, Ordering::Relaxed) {- tracing::warn!("first emu frame ready");- }+ first_frame.store(true, Ordering::Relaxed);});}- match state.platform {- Platform::Wii => {- let mut emu = Wii::apploader_hle(dvd).build();- self::configure_emu(&mut emu, ¶ms, sink, state.fps.clone());- emu.apply_host_input(&HostInput::neutral_for(system::WII));- let audio = self::install_audio_sink(&mut emu);- let _ = emu.load_jit_cache(&game_id);- self::set_initialized(&state, renderer, audio, &game_id);- emu_thread::run::<{ system::WII }>(- emu,- state.input.clone(),- params.input_config.clone(),- Some(game_id),- state.throttle.clone(),- shutdown,- );+ if params.format == Format::Dol {+ let game_id = gecko::jit::cache::dol_cache_id(&data);+ let dol = image::Dol::parse(data);+ match state.platform {+ Platform::Wii => self::finish_boot(state, params, renderer, sink, Wii::with_image(&dol), game_id),+ Platform::Gcn => self::finish_boot(state, params, renderer, sink, GameCube::with_image(&dol), game_id),}+ return;+ }++ let dvd = image::load_dvd(data);+ let game_id = dvd.header().game_id();++ match state.platform {+ Platform::Wii => self::finish_boot(state, params, renderer, sink, Wii::apploader_hle(dvd).build(), game_id),Platform::Gcn => {- let mut emu = self::build_gamecube(dvd, ¶ms);- self::configure_emu(&mut emu, ¶ms, sink, state.fps.clone());- emu.apply_host_input(&HostInput::neutral_for(system::GC));- let audio = self::install_audio_sink(&mut emu);- let _ = emu.load_jit_cache(&game_id);- self::set_initialized(&state, renderer, audio, &game_id);- emu_thread::run::<{ system::GC }>(- emu,- state.input.clone(),- params.input_config.clone(),- Some(game_id),- state.throttle.clone(),- shutdown,- );+ let emu = self::build_gamecube(dvd, ¶ms);+ self::finish_boot(state, params, renderer, sink, emu, game_id);}}}+fn finish_boot<const S: gecko::system::SystemId>(+ state: Arc<PlayerState>,+ params: BootParams,+ renderer: Renderer,+ sink: backend_wgpu::sink::ThreadedSink,+ mut emu: gecko::system::System<S>,+ game_id: String,+) {+ self::configure_emu(&mut emu, ¶ms, sink, state.fps.clone());+ emu.apply_host_input(&HostInput::neutral_for(S));++ let audio = self::install_audio_sink(&mut emu);+ let _ = emu.load_jit_cache(&game_id);+ self::set_initialized(&state, renderer, audio, &game_id);++ emu_thread::run::<S>(+ emu,+ state.input.clone(),+ params.input_config,+ Some(game_id),+ state.throttle.clone(),+ state.shutdown.clone(),+ );+}+fn build_gamecube(dvd: Box<dyn image::Dvd>, params: &BootParams) -> gecko::system::System<{ system::GC }> {let Some(ipl_path) = params.ipl_path.as_deref() else {return GameCube::with_ipl_hle(dvd);@@ -334,6 +342,7 @@ fn set_initialized(state: &Arc<PlayerState>, renderer: Renderer, audio: Option<cfn validate(platform: Platform,+ format: Format,dsp: &Option<PathBuf>,coef: &Option<PathBuf>,ipl: &Option<PathBuf>,@@ -346,7 +355,7 @@ fn validate(if coef.is_none() {missing.push(DSP_COEF_FILE);}- if platform == Platform::Gcn && ipl.is_none() {+ if platform == Platform::Gcn && format != Format::Dol && ipl.is_none() {missing.push(IPL_FILE);}@@ -354,9 +363,13 @@ fn validate(return None;}- let needed = match platform {- Platform::Gcn => "GameCube games require IPL.bin, dsp_rom.bin and dsp_coef.bin",- Platform::Wii => "Wii games require dsp_rom.bin and dsp_coef.bin",+ let needed = if format == Format::Dol {+ "DOL executables require dsp_rom.bin and dsp_coef.bin"+ } else {+ match platform {+ Platform::Gcn => "GameCube games require IPL.bin, dsp_rom.bin and dsp_coef.bin",+ Platform::Wii => "Wii games require dsp_rom.bin and dsp_coef.bin",+ }};Some(format!(diff --git a/crates/app/src/widgets/menubar.rs b/crates/app/src/widgets/menubar.rsindex 0d2f9c6..e375c7a 100644--- a/crates/app/src/widgets/menubar.rs+++ b/crates/app/src/widgets/menubar.rs@@ -184,6 +184,18 @@ fn section_header(palette: &Palette, label: &'static str) -> Element<'static, Mefn file_menu(palette: &Palette) -> Menu<'static, Message, iced::Theme, iced::Renderer> {Menu::new(vec![Item::new(self::menu_item(palette, "Open Game", Message::MenuOpenGame, None)),+ Item::new(self::menu_item(+ palette,+ "Open GameCube DOL",+ Message::MenuOpenDol(Platform::Gcn),+ None,+ )),+ Item::new(self::menu_item(+ palette,+ "Open Wii DOL",+ Message::MenuOpenDol(Platform::Wii),+ None,+ )),Item::new(self::separator(palette)),Item::new(self::menu_item(palette,diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rsindex cfe9354..e1084e6 100644--- a/crates/debugger/src/main.rs+++ b/crates/debugger/src/main.rs@@ -430,7 +430,9 @@ fn main() {let mut game_id: Option<String> = None;let mut emulator = if let Some(ref dol) = args.dol {- let dol = Dol::parse(std::fs::read(dol).expect("failed to read DOL"));+ let data = std::fs::read(dol).expect("failed to read DOL");+ game_id = Some(gecko::jit::cache::dol_cache_id(&data));+ let dol = Dol::parse(data);if args.wii {EmulatorVariant::Wii(Wii::with_image(&dol))} else {diff --git a/crates/gecko/src/jit/cache.rs b/crates/gecko/src/jit/cache.rsindex 292c593..577882e 100644--- a/crates/gecko/src/jit/cache.rs+++ b/crates/gecko/src/jit/cache.rs@@ -53,6 +53,28 @@ pub fn hash_words(words: impl IntoIterator<Item = u32>) -> u64 {h}+#[inline]+pub fn hash_bytes(data: &[u8]) -> u64 {+ let mut h: u64 = 0xcbf29ce484222325;++ let mut chunks = data.chunks_exact(8);+ for c in &mut chunks {+ h ^= u64::from_le_bytes(c.try_into().unwrap());+ h = h.wrapping_mul(0x100000001b3);+ }++ for &b in chunks.remainder() {+ h ^= b as u64;+ h = h.wrapping_mul(0x100000001b3);+ }++ h+}++pub fn dol_cache_id(data: &[u8]) -> String {+ format!("dol-{:016x}", self::hash_bytes(data))+}+pub fn cache_dir(game_id: &str) -> PathBuf {PathBuf::from("cache").join(game_id)}diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rsindex a6fd996..d79afbc 100644--- a/crates/tinyapp/src/main.rs+++ b/crates/tinyapp/src/main.rs@@ -221,15 +221,17 @@ fn main() {// --ipl [+ --dvd] : GameCube real IPL boot (with_ipl)// --dvd <path> : autodetect Wii vs GC, HLE boot via apploaderif let Some(ref dol) = args.dol {- let dol = Dol::parse(std::fs::read(dol).expect("failed to read DOL"));+ let data = std::fs::read(dol).expect("failed to read DOL");+ let game_id = gecko::jit::cache::dol_cache_id(&data);+ let dol = Dol::parse(data);if args.wii {let mut emulator = Wii::with_image(&dol);configure(&mut emulator, &args);- run(emulator, present_mode, &args, None);+ run(emulator, present_mode, &args, Some(game_id));} else {let mut emulator = GameCube::with_image(&dol);configure(&mut emulator, &args);- run(emulator, present_mode, &args, None);+ run(emulator, present_mode, &args, Some(game_id));}} else if let Some(ref ipl_path) = args.ipl {let ipl_data = std::fs::read(ipl_path).expect("failed to read IPL");