Wii U support in Dolphin

Discussion in 'Wii U - Hacking & Backup Loaders' started by CarlKenner, Jun 17, 2014.

  1. CarlKenner
    OP

    CarlKenner Member

    Newcomer
    16
    39
    Jun 17, 2014
    I started adding Wii U support to the Dolphin emulator.
    Currently it can recognize your Wii U games (in addition to your GameCube and Wii games) in either WUD or ISO format, recognize what region it is, what size it is, get the game ID, and most importantly read the file system and extract files for all partitions except the game partition. Also it lets you open RPX files, although they don't load correctly.
    It can only find the partitions and read the file system for games where the title key has been released. Don't ask me how to rip your games from your WiiU, because I don't know, but some people seem to manage it.

    Currently this is only useful for hackers who want to examine the update partition (I heard some exploit authors wanted binaries), or collectors who want to show off their list of games, or people who are curious what's on those discs, or people who want to work on emulating the Wii U.
    IT DOES NOT PLAY WII U GAMES YET.

    The source code is here on github (requires Visual Studio 2013, or if you are on linux you may need to modify the build system to include the extra files in the DiscIO module):
    https://github.com/CarlKenner/dolphin/tree/WiiU

    There is a bug with at least 3 of the file names on SM3DW, where the names are not read correctly, which I believe is caused by the filenames being split across the cluster boundary. Which means there is probably also a bug which corrupts some of the contents of other files where that happens. So don't rely on files being 100% accurate. The files whose formats I can understand, like app.xml or update.inf.USA, seem to be working perfectly (which is an especially good sign because those files are actually garbled when you decrypt the entire disc image with OpenSSL, at least on SM3DW).

    I hope this will provide a starting point for other people who want to work on adding Wii U support to Dolphin. I believe the next step should be to try to get RPX files to load and to be viewable in Dolphin's debugger (use the command line option -d I think). Then we can work on getting simple hello world rpx files to work with high level emulation of SDK functions.

    EDIT: I should point out that this is not in the official dolphin builds, just in my unofficial branch that I posted above.

    EDIT: Screenshot
     


  2. TyBlood13

    TyBlood13 Weeaboo Trash

    Member
    1,487
    589
    Jul 1, 2012
    United States
    Kentucky
    Very intriguing. Keep up the good work!
     
    Margen67 and CarlKenner like this.
  3. GamingAori

    GamingAori GBAtemp Advanced Fan

    Member
    596
    51
    Mar 16, 2014
    Gambia, The
    I think this isn't work and the games doesn't run in fullspeed.
     
  4. DeadPixelMan

    DeadPixelMan Advanced Member

    Newcomer
    86
    34
    Aug 30, 2013
    United States
    I hope your being sarcastic otherwise your extremely retarded. Did you even read the post?
     
  5. GamingAori

    GamingAori GBAtemp Advanced Fan

    Member
    596
    51
    Mar 16, 2014
    Gambia, The
    yeah i read this. but in future i think early in 2-4 years.
     
  6. Flame

    Flame Me > You

    Member
    3,832
    4,941
    Jul 15, 2008
    Oh really? and we expecting that it run full speed on a Gameboy flashcart.




    anyway this is great and as all ways great work by the dolphin team.. hopefully we will swim in Wii U games in no time with Dolphin.
     
  7. driverdis

    driverdis I am Justice

    Member
    2,353
    886
    Sep 21, 2011
    United States
    1.048596β
    even if we can get Wii U games to start on dolphin, they will be unplayable for years to come, as the processor is roughly a 3 core Wii running at twice the clock speed. The problem is that currently, high end PCs struggle emulating some Wii games, yet alone any Wii U games.
     
  8. the_randomizer

    the_randomizer The Temp's official fox whisperer

    Member
    20,780
    9,783
    Apr 29, 2011
    United States
    Dr. Wahwee's castle

    Really? You don't say! There's nothing wrong with them allowing this for debugging, hacking, etc.
     
    Margen67 and Bladexdsl like this.
  9. Bladexdsl

    Bladexdsl ZOMG my posts...it's over 9000!!!

    Member
    15,993
    3,685
    Nov 17, 2008
    Australia
    Queensland
    there's nothing stopping an exploit now. NOTHING!

    nah it's possible you just need an 8 core cpu, 128gb ram, and 2 gtx titan Z SLI together. EASY :creep:
     
    Margen67 and the_randomizer like this.
  10. lampdemon

    lampdemon GBAtemp Regular

    Member
    151
    56
    Oct 28, 2013
    Canada
    Where the land sea lions live.
    High end PCs shouldn't have problems running Wii games these day, do the ones that struggle also lag when played on the Wii?

    Unless you're talking about running them at max settings...
     
    Tomato Hentai, Margen67 and yuyuyup like this.
  11. DaRk_ViVi

    DaRk_ViVi Sending you back... to the future!

    Member
    1,062
    55
    Apr 13, 2004
    Italy
    Asti, Italy
    Mario Kart 8 hangs just after I finish a GP, I demand a fix ASAP!!!!

    Joking, great work btw! :lol:
     
    Tomato Hentai likes this.
  12. the_randomizer

    the_randomizer The Temp's official fox whisperer

    Member
    20,780
    9,783
    Apr 29, 2011
    United States
    Dr. Wahwee's castle

    Some games like Xenoblade and The Last Story still have issues with speed on most CPUs, unless you overclock :P But yeah, most Wii games should run very well.
     
    Tomato Hentai likes this.
  13. Bladexdsl

    Bladexdsl ZOMG my posts...it's over 9000!!!

    Member
    15,993
    3,685
    Nov 17, 2008
    Australia
    Queensland
    that's what happens in the digital version you need the physical copy and it won't freeze :creep:
     
  14. Huntereb

    Huntereb GBAtemp Addict

    Member
    2,748
    948
    Sep 1, 2013
    United States
    I thought this thread was going to be a "how u play wii u gaems on dolphin??/" thread...

    But it's actually the start of something great, so nice job!
     
    Tomato Hentai and Margen67 like this.
  15. CarlKenner
    OP

    CarlKenner Member

    Newcomer
    16
    39
    Jun 17, 2014
    English isn't his native language, so I'm sure he meant that it won't run at full speed if we ever get it running games at all.
    And that's probably true, but I don't really care about that myself. For me it's more about the principle that we should be able to emulate things, and less about the practicality for end users. I know other people have different priorities though, and that's OK.
    The 3 cores aren't really a problem, since Dolphin currently leaves many of your CPU's cores doing nothing. The sensible thing to do would be to have each core running on its own core, so it wouldn't slow anything down significantly. Twice the clock speed is still an issue, but many games might not be using 100% of the CPU anyway, since many games don't look any more demanding than Wii games. I'm hoping Wii U games don't use as much low-level code, and we won't have to emulate half the hardware if we just emulate the OS calls that the game makes. But I don't really know. It could end up being super slow or running at playable speeds. We'll just have to try and see, and hopefully let people much more capable than me have a go at coding.

    Anyway, it's way too early to think about running actual games... I'm taking little baby steps here. But now Dolphin knows there is such a thing as a Wii U game and can read some of its files. Later we might be able to get a hello world RPX file (like in the leaked SDK) to load and maybe even run, and output some debug prints to the Dolphin console. Exciting if you are a hacker, but not useful for anyone else.
     
  16. Bug_Checker_

    Bug_Checker_ GBAtemp Advanced Fan

    Member
    950
    444
    Jun 10, 2006
    United States

    Nice job so far.
    The "bug" you speak of is that each and every encrypted cluster/sector size of 0x10000(65536 bytes in size according to blu ray specs) must be decrypted individually or the first 16 bytes of each cluster/sector WILL be incorrect. That is why you can't just run it through openssl.
    If you are decrypting correctly,You will notice that empty decrypted cluster/sectors will be numbered "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 xx". Also since app.xml starts on a new cluster/sector if you just run it through openssl the 1st 16 bytes will be screwed up. Only makes sense that the FST will work the same way.(Well actually Nintendo can do it anyway they want and for consistance probably kept it similiar to the wii format.
    Be careful and look out for unecrypted cluster/sector after update partition but right before encrypted FST of game partition (appears to be different between some games). Good luck.
     
  17. CarlKenner
    OP

    CarlKenner Member

    Newcomer
    16
    39
    Jun 17, 2014
    Well, that explains OpenSSL. However, as far as I was aware, I was decrypting each cluster individually (with an IV initialized to zero). But since that would explain my bug, and why it was affecting three filenames rather than one, it must be the problem.

    Clusters appear to be 0x8000, not 0x10000, so I'm (trying to) decrypt each 0x8000 individually. Is that the problem? Should I be using 0x10000 blocks for decryption? FST blocks usually seem to start on a 0x8000 boundary after an unecrypted cluster, so I'm not sure how I could decrypt in 0x10000 blocks anyway.

    I didn't look at empty decrypted sectors except in the bugged OpenSSL decrypted file.

    Here's my code (and yes, I know the read current block part would be more efficient inside the next if):
    Code:
    bool CVolumeWiiUCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer) const
    {
        if (m_pReader == nullptr)
        {
            return(false);
        }
     
        // The first cluster of a partition is unencrypted
        if (_ReadOffset < 0x8000)
            return RAWRead(_ReadOffset + m_VolumeOffset + dataOffset, _Length, _pBuffer);
     
        while (_Length > 0)
        {
     
            // math block offset
            u64 Block  = _ReadOffset / 0x8000;
            u64 Offset = _ReadOffset % 0x8000;
     
            // read current block
            if (!m_pReader->Read(m_VolumeOffset + dataOffset + Block * 0x8000, 0x8000, m_pBuffer))
            {
                return(false);
            }
     
            if (m_LastDecryptedBlockOffset != Block)
            {
                u8 IV[16] = { 0 };
                aes_crypt_cbc(m_AES_ctx, AES_DECRYPT, 0x8000, IV, m_pBuffer, m_LastDecryptedBlock);
     
                m_LastDecryptedBlockOffset = Block;
            }
     
            // copy the encrypted data
            u64 MaxSizeToCopy = 0x8000 - Offset;
            u64 CopySize = (_Length > MaxSizeToCopy) ? MaxSizeToCopy : _Length;
            memcpy(_pBuffer, &m_LastDecryptedBlock[Offset], (size_t)CopySize);
     
            // increase buffers
            _Length -= CopySize;
            _pBuffer    += CopySize;
            _ReadOffset += CopySize;
        }
     
        return(true);
    }
    Actually... those 3 filenames were correct in the OpenSSL decrypted file. It's just my code they were wrong in.
     
  18. CosmoCortney

    CosmoCortney The Hacker Furry

    Member
    1,538
    1,462
    Apr 18, 2013
    Germany
    on the cool side of the pillow
    Too bad it can't read the fst of the game partition, yet (I am really curious about if there are all these beta levels in the WW remake or even new test stages).
    But nice job anyways :)
    Are there any screenshots or is there a demonstration video of it?
    (i dont have any Wii U game rip so i can'T try it out on myself)
     
  19. julialy

    julialy Homebrewer

    Member
    1,628
    557
    Nov 26, 2012
    United States
    United States
    you can't play games yet
     
  20. CosmoCortney

    CosmoCortney The Hacker Furry

    Member
    1,538
    1,462
    Apr 18, 2013
    Germany
    on the cool side of the pillow

    I know. I was talking about the function to read and extract the fst

    EDIT: also about screenshots/vids of the current progress
     
    CydoniaDS and CarlKenner like this.