Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>Returns the decrypted version of the gamesave after checking whether the gamesave is encrypted or not. Returns true if the gamesave is encrypted; otherwise false.</summary>
- /// <param name="decrypted">The string to return the decrypted gamesave.</param>
- /// <returns>Returns true if the gamesave is encrypted; otherwise false.</returns>
- public static bool TryDecryptGamesave(out string decrypted)
- {
- string path = GDLocalData + "\\CCGameManager.dat";
- string gamesave = "";
- bool isEncrypted = CheckIfGamesaveIsEncrypted();
- if (isEncrypted)
- gamesave = DecryptGamesave();
- else
- gamesave = Encoding.UTF8.GetString(File.ReadAllBytes(path));
- decrypted = gamesave;
- doneDecryptingGamesave = true;
- return isEncrypted;
- }
- public static bool CheckIfGamesaveIsEncrypted()
- {
- string path = GDLocalData + "\\CCGameManager.dat";
- string gamesave = Encoding.UTF8.GetString(File.ReadAllBytes(path));
- int checks = 0;
- string[] tests = { "<k>bgVolume</k>", "<k>sfxVolume</k>", "<k>playerUDID</k>", "<k>playerName</k>", "<k>playerUserID</k>" };
- for (int i = 0; i < tests.Length; i++)
- if (gamesave.Contains(tests[i]))
- checks++;
- return checks != tests.Length;
- }
- public static string DecryptGamesave()
- {
- string path = GDLocalData + "\\CCGameManager.dat"; // Get the path
- string gamesave = GetData(path); // Get the gamesave data
- return GDGamesaveDecrypt(gamesave);
- }
- /// <summary>Returns the decrypted version of the level data after checking whether the level data is encrypted or not. Returns true if the level data is encrypted; otherwise false.</summary>
- /// <param name="decrypted">The string to return the decrypted level data.</param>
- /// <returns>Returns true if the level data is encrypted; otherwise false.</returns>
- public static bool TryDecryptLevelData(out string decrypted)
- {
- string path = GDLocalData + "\\CCLocalLevels.dat";
- string levelData = "";
- bool isEncrypted = CheckIfLevelDataIsEncrypted();
- if (isEncrypted)
- levelData = DecryptLevelData();
- else
- levelData = Encoding.UTF8.GetString(File.ReadAllBytes(path));
- decrypted = levelData;
- return isEncrypted;
- }
- public static bool CheckIfLevelDataIsEncrypted()
- {
- string path = GDLocalData + "\\CCLocalLevels.dat";
- string levelData = Encoding.UTF8.GetString(File.ReadAllBytes(path));
- string test = "<?xml version=\"1.0\"?><plist version=\"1.0\" gjver=\"2.0\">";
- return !levelData.Contains(test);
- }
- public static string DecryptLevelData()
- {
- string path = GDLocalData + "\\CCLocalLevels.dat"; // Get the path
- string levelData = GetData(path); // Get the gamesave data
- return GDGamesaveDecrypt(levelData);
- }
- public static string GetData(string path)
- {
- StreamReader sr = new StreamReader(path);
- string readfile = sr.ReadToEnd();
- sr.Close();
- return readfile;
- }
- public static byte[] Base64Decrypt(string encodedData)
- {
- while (encodedData.Length % 4 != 0)
- encodedData += "=";
- byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData);
- return encodedDataAsBytes;
- }
- public static string Base64Encrypt(byte[] decryptedData)
- {
- return Convert.ToBase64String(decryptedData);
- }
- public static byte[] Decompress(byte[] data)
- {
- using (var compressedStream = new MemoryStream(data))
- using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
- using (var resultStream = new MemoryStream())
- {
- var buffer = new byte[4096];
- int read;
- while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0)
- resultStream.Write(buffer, 0, read);
- return resultStream.ToArray();
- }
- }
- public static byte[] Compress(byte[] data)
- {
- using (var decompressedStream = new MemoryStream(data))
- using (var zipStream = new GZipStream(decompressedStream, CompressionMode.Compress))
- using (var resultStream = new MemoryStream())
- {
- var buffer = new byte[4096];
- int read;
- while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0)
- resultStream.Write(buffer, 0, read);
- return resultStream.ToArray();
- }
- }
- public static string XORDecrypt(string text, int key)
- {
- byte[] result = new byte[text.Length];
- for (int c = 0; c < text.Length; c++)
- result[c] = (byte)((uint)text[c] ^ key);
- string dexored = Encoding.UTF8.GetString(result);
- return dexored;
- }
- public static string XOR11Decrypt(string text)
- {
- byte[] result = new byte[text.Length];
- for (int c = 0; c < text.Length - 1; c++)
- result[c] = (byte)((uint)text[c] ^ 11);
- string dexored = Encoding.UTF8.GetString(result);
- return dexored;
- }
- public static string GDGamesaveDecrypt(string data)
- {
- string xored = XOR11Decrypt(data); // Decrypt XOR ^ 11
- string replaced = xored.Replace('-', '+').Replace('_', '/').Replace("\0", string.Empty); // Replace characters
- byte[] gzipb64 = Decompress(Base64Decrypt(replaced)); // Decompress
- string result = Encoding.ASCII.GetString(gzipb64); // Change to string
- return result;
- }
- public static string GDLevelStringDecrypt(string ls)
- {
- string replaced = ls.Replace('-', '+').Replace('_', '/').Replace("\0", string.Empty); // Replace characters
- //string fixedBase64 = replaced.FixBase64String();
- byte[] gzipb64 = Base64Decrypt(replaced);
- if (replaced.StartsWith("H4sIAAAAAAAA"))
- gzipb64 = Decompress(gzipb64); // Decompress
- else throw new ArgumentException("The level string is not valid.");
- string result = Encoding.ASCII.GetString(gzipb64); // Change to string
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement