Skip to content

Commit

Permalink
Eat dessert
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Oct 7, 2024
1 parent ab945f9 commit 20480fe
Showing 1 changed file with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Microsoft.UI.Xaml;
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Buffers.Text;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;

Expand All @@ -13,6 +15,8 @@ internal sealed class GameTypeZenlessVersion : GameVersionBase
{
#region Properties
private RSA SleepyInstance { get; set; }
internal string SleepyIdentity { get; set; }
internal string SleepyArea { get; set; }
#endregion

#region Initialize Sleepy
Expand Down Expand Up @@ -58,11 +62,34 @@ private void InitializeSleepy(PresetConfig gamePreset)
DataCooker.GetServeV3DataSize(keyUtf8Base64, out long servedCompressedSize, out long servedDecompressedSize);
Span<byte> outServeData = keyUtf8Base64.AsSpan(keyFromBase64Len, (int)servedDecompressedSize);
DataCooker.ServeV3Data(keyUtf8Base64.AsSpan(0, keyFromBase64Len), outServeData, (int)servedCompressedSize, (int)servedDecompressedSize, out int dataWritten);


// Time for dessert!!!
ReadOnlySpan<byte> cheeseCake = outServeData.Slice(0, dataWritten);
int identityN = BinaryPrimitives.ReadInt16LittleEndian(cheeseCake.Slice(dataWritten - 4));
int identityN2 = identityN * 2;
int areaN = BinaryPrimitives.ReadInt16LittleEndian(cheeseCake.Slice(dataWritten - 2));
int areaN2 = areaN * 2;

int nInBite = identityN2 + areaN2;
int wine = dataWritten - (4 + nInBite);
Span<byte> applePie = outServeData.Slice(wine, nInBite);

// And eat good
int len = applePie.Length;
int i = 0;
NomNom:
int pos = wine % ((len - i) & unchecked((int)0xFFFFFFFF));
applePie[i] ^= outServeData[0x10 | pos];
if (++i < len) goto NomNom;

// Then sleep
SleepyIdentity = MemoryMarshal.Cast<byte, char>(applePie.Slice(0, identityN2)).ToString();
SleepyArea = MemoryMarshal.Cast<byte, char>(applePie.Slice(identityN2, areaN2)).ToString();

// Load the load
SleepyInstance.ImportRSAPrivateKey(outServeData.Slice(0, dataWritten), out int bytesRead);

// If you're food poisoned, then go to the hospital
// If you felt food poisoned since last night's dinner, then go to the hospital
if (0 == bytesRead)
goto QuitFail;

Expand All @@ -79,11 +106,13 @@ private void InitializeSleepy(PresetConfig gamePreset)
// Close the door
void DisableRepairAndCacheInstance(PresetConfig config)
{
#if !DEBUG
config.IsRepairEnabled = false;
config.IsCacheUpdateEnabled = false;
#endif
}
}
#endregion
#endregion

public GameTypeZenlessVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfig gamePreset, string gameName, string gameRegion)
: base(parentUIElement, gameRegionProp, gameName, gameRegion)
Expand Down

0 comments on commit 20480fe

Please sign in to comment.