Dolphin Emulator

repository·master·Indexed 12 days ago

https://github.com/dolphin-emu/dolphin

Documentation for the Dolphin emulator, including system requirements for Windows, Linux, macOS, and Android, and instructions for building from source. Includes a CLI reference for automation, the dolphin-tool utility for converting, verifying, and extracting disc images, and guides for building DSPSpy and the GameCube DSP User's Manual.

Tokens
15K
Snippets
28
Records
65
Agent score
97%

What's inside Dolphin

  1. Understand the `wia_except_list_t` structure in WIA files

    master

    In WIA files, each wia_group_t of Wii partition data contains one or more wia_except_list_t structs. These structs describe differences between the hashes of the partition data and the original hashes.

    Key details for implementation:

    • Quantity: The number of wia_except_list_t structs per wia_group_t is calculated as chunk_size / 0x200000. This applies even if the group contains less data than a full chunk.
    • Capacity: When writing code to read WIA files, assume a single wia_except_list_t can handle at least 3328 exceptions (52 * 64).
    • Compression Behavior:
      • PURGE: Structs are stored uncompressed (before the first wia_segment_t).
      • BZIP2, LZMA, LZMA2: Structs are compressed along with the rest of the data.
      • NONE and PURGE: If the end offset of the last wia_except_list_t is not divisible by 4, 4-byte alignment padding is inserted. This padding is not used for other compression methods.

    Structure:

    • u16 n_exceptions: The number of wia_exception_t structs.
    • wia_exception_t exception[n_exceptions]: The actual exception data.
  2. Understand the Dolphin AutoUpdate mechanism

    master

    Dolphin's auto-update system uses a separate application to modify the main Dolphin executable and its files, as applications cannot overwrite themselves.

    Key Constraints & Behavior:

    • Platform Support: Only supported on Windows and macOS.
    • Update Tracks: There are four frequency tracks: Dev (every commit), Beta (a few times a year), Stable (rarely), and Disabled.
    • Updater Lifecycle: When an update is triggered, the system creates a copy of the updater application. This copy updates both Dolphin and the original updater. To prevent clutter, Dolphin deletes any existing updater copy automatically upon launch.
  3. Understand `wia_exception_t` and hash exceptions

    master

    A wia_exception_t represents a 20-byte difference between recalculated hash data and the original hash data. This is used to restore hashes for Wii partition data.

    Implementation Details:

    • When recalculating hashes for a wia_group_t not evenly divisible by 2 MiB, missing bytes should be treated as zeroes.
    • Dolphin vs wit: wit only outputs exceptions for mismatches in actual hash data. Dolphin outputs exceptions for both hash data and padding data.
    • If Dolphin writes exceptions for a 32-byte padding area, it writes two wia_exception_t structs (one for the first 20 bytes and one for the last 20 bytes), resulting in a 12-byte overlap.
  4. WIA file format overview

    master

    WIA (version 1.00) is a compressed disc image format for GameCube and Wii discs, implemented in wit v2.40a.

    Key Features:

    • Supports bzip2, LZMA, and LZMA2 compression algorithms.
    • Wii partition data is stored decrypted and without hashes, which improves compression efficiency.
    • Data is divided into blocks (chunks) that are compressed separately, enabling random access to compressed data.

    Technical Constraints:

    • All integers are big endian unless otherwise noted.
    • The type sha1_hash_t refers to a 20-byte array.
    • Data can be stored in any order unless specified.
  5. Understand Wii partition data in WIA

    master

    WIA handles Wii partition data differently than standard disc data. In a WIA file, Wii partition data is stored decrypted and with hashes removed to allow for better compression.

    Key Details:

    • For every 0x8000 bytes on the original disc, only 0x7C00 bytes are stored in the WIA file (prior to compression).
    • To recover the original hashes, a reader must recalculate them and then apply hash exceptions stored in wia_except_list_t.
    • Partition data is managed via wia_part_t structs, which contain a 128-bit AES part_key for re-encryption.
    • wia_part_t splits data into two segments: pd[0] (management data like boot/fst) and pd[1] (remaining data).
  6. Use `wia_segment_t` with the PURGE compression method

    master

    The wia_segment_t struct is used specifically by the PURGE compression method to store runs of zeroes efficiently.

    How it works: Each PURGE chunk contains zero or more wia_segment_t structs ordered by ascending offset. Any bytes in the decompressed data not covered by a segment are treated as 0x00. A SHA-1 hash (0x14 bytes) follows the segments, covering the wia_except_list_t structs (if any) and the wia_segment_t structs.

    Structure:

    • u32 offset: The offset of data within the decompressed data (excluding wia_except_list_t structs).
    • u32 size: The number of bytes in data.
    • u8 data[size]: The actual data payload.
  7. Differences between RVZ and WIA file formats

    master

    RVZ is a derivative of the WIA format with several key enhancements and changes:

    • Zstandard Support: Added as a compression method. In wia_disc_t, compression is set to 5. Note that compr_level must be treated as a signed integer to support Zstandard's negative compression levels.
    • PURGE Removal: The PURGE compression method is removed in RVZ.
    • Smaller Chunk Sizes: Supports chunks smaller than 2 MiB.
      • Must be at least 32 KiB and a power of two.
      • For Wii partition data, each chunk contains exactly one wia_except_list_t specific to that chunk.
      • Offset 0 refers to the first hash of the current chunk, not the start of a 2 MiB block.
    • Expanded wia_group_t: Uses rvz_group_t which modifies the meaning of the most significant bit of data_size and adds rvz_packed_size.
    • Lossless Padding: Pseudorandom padding data is stored using a specific RVZ packing encoding scheme.
  8. Use /dev/dolphin to detect Dolphin Emulator

    master

    Dolphin provides a virtual IOS device at /dev/dolphin. Homebrew applications and game mods can attempt to open() this device to determine if they are running within the Dolphin emulator.

    If the open() call is successful, the application is running on Dolphin and can safely skip tasks that are only necessary on real hardware (such as patching IOS) or enable emulator-specific features.

  9. How the AutoUpdate flow works

    master

    The update process follows a specific lifecycle involving checking, prompting, and executing the update via a separate process:

    1. Triggering the Check:
      • Automatic: When Dolphin launches (in non-NoGUI/non-batch modes), a background thread is spawned to call AutoUpdateChecker::CheckForUpdate().
      • Manual: Users can select Help -> Check for Updates... in the main menu. This temporarily forces the update track to dev to ensure the latest version is checked.
    2. User Prompting: If an update is found, OnUpdateAvailable() is triggered, displaying a changelog and offering options: Update now, Update after Dolphin closes, Not update, or Never auto-update.
    3. Execution: If an update is accepted, AutoUpdateChecker::TriggerUpdate() creates a copy of the updater executable and runs it as a new process.
    4. The Updater Process:
      • Windows: The updater checks for write access to the Dolphin directory. If it lacks permissions, it attempts to relaunch itself with Administrator privileges (triggering a UAC prompt).
      • macOS: The updater starts via NSApplicationMain and passes arguments to the common update logic.
      • Common Logic: The updater fetches file manifests, calculates diffs, downloads/replaces files, and verifies file hashes against the manifest.
  10. Use the Custom Pipeline feature for graphics mods

    master

    Dolphin allows content creators to overwrite internal graphics pipeline data (currently limited to the pixel shader) using graphics mods. To trigger this capability, you must use the custom_pipeline action type within your mod's feature definitions.

    Action Data Requirements

    The custom_pipeline action requires a passes array. Currently, Dolphin only supports a single pass in this array. Each pass must include a pixel_material_asset identifier, which refers to the name of a material asset defined in your mod's assets section.

    {
        "features": [
            {
                "action": "custom_pipeline",
                "action_data": {
                  "passes":  [
                    {
                      "pixel_material_asset": "material_replace_normal"
                    }
                  ]
                },
                "group": "PipelineTarget"
            }
        ]
    }
  11. Set up an Android development environment for Dolphin

    master
    To contribute to the Dolphin Android project, you must first install Android Studio with default options. Once installed, open the Source/Android project directory in Android Studio. Allow background tasks to complete so that Android Studio can automatically download the necessary SDK components and tooling required for the project.