SteveLeafo / Budford

Budford: Cemu configuration, settings and auto update tool. Per game settings and more...
Mozilla Public License 2.0
24 stars 3 forks source link

Adding support for WUD games #8

Closed dkr88 closed 6 years ago

dkr88 commented 6 years ago

I'm trying to put together a PR for supporting .wud game files in addition to loadiine, but I'm stuck trying to calculate the hash for the SaveDir.

Does anyone know how Cemu calculates the hash for the .wud games? Running the hash algorithm from GenerateHashFromRpxRawData over the .wud file doesn't produce the expected hash (never mind that it takes forever, even when optimized).

SteveLeafo commented 6 years ago

The SaveDir is basically the result of the Hash algorithm run over the game's launch file (.RPX).

To get this out of a .WUD file, you would have to first extract the .RPX file out of the .WUD file the run the hash algorithm on it. I believe you would need a key before you can extract the file, these could be read from Cemu's Keys.txt file.

A tool like Crediar's DiscU tool can extract files from a .WUD. It may have a command line option to extract a single file. Perhaps that's a starting point.

SteveLeafo commented 6 years ago

OK - I have found one solution that may be workable, I wrote a test app using JWUDTool and I was able to extract the .RPX file from a .WUD and generate the required SaveDir hash.

Budford could simply ask for the path to JWUDTool and execute it. (which would require Java)

Now to implement this into Budford, we need to access the game's key to use in decryption, the code I wrote was using keys.txt in the Cemu folder and was just trying each key one at a time, is this how you would expect it to work?

The code looks something like this little mess:

        foreach (var key in keys)
        {
            ProcessStartInfo start = new ProcessStartInfo();
            start.Arguments = "-jar \"D:\\Wii-U\\WUP-P-ALAP\\JWUDTool.jar\" -in \"D:\\Wii-U\\WUP-P-ALAP\\legomovie.wud\" -decryptFile /code/.*.rpx -out \"D:\\Wii-U\\WUP-P-ALAP\\temp\" -commonkey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -titlekey " + key;
            start.FileName = "java";
            var process = Process.Start(start);

                   ...

I would be much faster if would define a way to pair the .WUD file with the game.key file that Wupdump generates.

But I guess we only need to do this once per game and we can save the results.

dkr88 commented 6 years ago

Yeah the JWUDTool seemed like a good approach. I was thinking maybe just prompting the user to enter a key when a .wud is discovered and have that key associated with the game profile. Budford could then update the keys.txt file automatically.

Also would probably want to extract the meta.xml and thumbnail images so that all the game details would be available to display in Budford just as with a loadiine game.

SteveLeafo commented 6 years ago

V60 now comes with support for the WUD files.

To use WUD files, you will need to set your Common key in Budford's configuration form.

When decryping the WUD files, Budford will first look for a file called game.key in the same file as the .WUD file. If this file doesn't exist it will try all the keys in the keys.txt from the current Cemu installation. Once the correct key has been found the following files are extracted into a WudData folder:

After experimenting with JWUDTool, I decided there was too much of a performance hit loading the JVM each time we ran it, especially if there were large numbers of keys to try. I saw that JWUDTool was using the JNUSLib, so I decided to port JNUSLib to C# and use that. It definately works a lot more efficiently. (You can find my JNUSLib port here: https://github.com/SteveLeafo/CNUSLib)

So, I need to port a little bit more of the JNUSLib to support WUX files, but I will finish that next weekend and then I will add support for them in too.

Thanks for raising this issue, I think it was a really good idea.

Regards, SteveLeafo