Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decrypt compatibility with .NET6 and above #24

Closed
wants to merge 1 commit into from

Conversation

SergejKiller
Copy link

No description provided.

@hadeutscher
Copy link
Owner

have you made sure this works in game after decrypting and re-encrypting the file? do you mind attaching a sample savegame for which this issue arises?

the reason I'm suspicious about this is because the code you're modifying is literally copied from the game's code after decompiling. So if this code really is buggy, the game itself should have trouble parsing the file as well

@hadeutscher
Copy link
Owner

Another thing that may have happened is that some recent patch modified this code and introduced the possibility of non 16 bytes aligned savegames. Assuming you have a recently patched Overcooked 2 installation, do you mind opening the executable with ILSpy and checking if the Deobfuscate function changed? (that's the function's original name, I didn't change it)

@SergejKiller
Copy link
Author

Unfortunately I cannot attach the random file types. So I've attached the json file, which you can manually encrypt and decrypt and see if the content says the same.

This issue might an artifact of switching to .NET 8.0 runtime.

CoopSlot_SaveFile_0.json

@hadeutscher
Copy link
Owner

Unfortunately I cannot attach the random file types. So I've attached the json file, which you can manually encrypt and decrypt and see if the content says the same.

This issue might an artifact of switching to .NET 8.0 runtime.

CoopSlot_SaveFile_0.json

Thanks; is this JSON file the output you got when decrypting with or without this patch? I don't see any extra bytes at the end as you described in the issue

@SergejKiller
Copy link
Author

That's the correct file. If you encrypt it and then immediately decrypt it using the old tool, do you get the same file size?

@SergejKiller
Copy link
Author

It seems .NET6+ change in behavior: dotnet/core#6895

@SergejKiller SergejKiller changed the title Handle save files which size is not a multiple of 16 Fix decrypt compatibility with .NET6 and above May 12, 2024
@hadeutscher
Copy link
Owner

I don't have the game installed; can you check what they did on their code? Was the game even upgraded to .NET >= 6 or is it on some older version that doesn't have this change?

@SergejKiller
Copy link
Author

As .NET3 is obsolete I've been using OvercookedTool with .NET8 and run into that problem. My change should be compatible with .NET3 framework as well, but I do not have it to verify.

@hadeutscher
Copy link
Owner

I understand, but I'm afraid of diverging much from the original code as this is decompiled code. Can you make this change as small as possible (e.g. just add a second cryptoStream.Read(...); on the remainder right below the existing call) and document carefully that this line was not present in the original code, but was added to make the code compatible with recent .NET versions?

kevinoid added a commit to kevinoid/OvercookedTool that referenced this pull request Jul 8, 2024
.NET 6 changed `System.Security.Cryptography.CryptoStream.Read()` such
that it may produce short reads (i.e. read less than the requested
number of bytes) before the end of the stream is reached.  This is
documented in [Partial and zero-byte reads in DeflateStream, GZipStream,
and CryptoStream][partial-reads].

To support .NET 6 and later versions, call .Read() repeatedly, until the
expected number of bytes has been read or end-of-stream has been
reached.

[partial-reads]: https://learn.microsoft.com/dotnet/core/compatibility/core-libraries/6.0/partial-byte-reads-in-streams

Fixes: hadeutscher#23
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Based-on: hadeutscher#24
Based-on-patch-by: Sergej Salnikov <sergejkiller@gmail.com>
@hadeutscher
Copy link
Owner

Superseded by #27

@hadeutscher hadeutscher closed this Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants