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 for 2.2 #37

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Examples/Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="JetBrains.Profiler.Api" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="JetBrains.Profiler.Api" Version="1.4.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions GeometryDashAPI.Tests/GeometryDashAPI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="FluentAssertions" Version="6.0.0-alpha0002" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
25 changes: 12 additions & 13 deletions GeometryDashAPI/Crypt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -34,24 +35,22 @@ public static string XOR(string text, string key)
return result.ToString();
}

public static string GZipDecompress(byte[] data)
public static Stream? GZipDecompress(byte[] data)
{
if (data == null || data.Length <= 0)
return string.Empty;
using var stream = new MemoryStream(data);
using var zip = new GZipStream(stream, CompressionMode.Decompress);
using var reader = new StreamReader(zip);
return reader.ReadToEnd();
return null;

var stream = new MemoryStream(data);
return new GZipStream(stream, CompressionMode.Decompress);
}

public static string ZLibDecompress(byte[] data)
public static Stream? ZLibDecompress(byte[] data)
{
if (data == null || data.Length <= 0)
return string.Empty;
using var stream = new MemoryStream(data);
using var zip = new InflaterInputStream(stream);
using var reader = new StreamReader(zip);
return reader.ReadToEnd();
return null;

var stream = new MemoryStream(data);
return new InflaterInputStream(stream);
}

public static byte[] GZipCompress(byte[] data)
Expand Down
6 changes: 5 additions & 1 deletion GeometryDashAPI/Data/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public virtual async Task LoadAsync(string fileName)
var gZipDecompress =
Crypt.GZipDecompress(
GameConvert.FromBase64(Encoding.ASCII.GetString(xor, 0, index >= 0 ? index : xor.Length)));
DataPlist = new Plist(Encoding.ASCII.GetBytes(gZipDecompress));

if (gZipDecompress is null)
throw new InvalidOperationException("Data was empty");

DataPlist = new Plist(gZipDecompress);
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions GeometryDashAPI/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace GeometryDashAPI
Expand Down Expand Up @@ -75,6 +76,12 @@ public static GameType GetGameType(this OfficialLevel level)
};
}

internal static string StreamToString(this Stream stream)
{
using var streamReader = new StreamReader(stream);
return streamReader.ReadToEnd();
}

internal static IEnumerable<KeyValuePair<T, T>> Pairs<T>(this IEnumerable<T> source)
{
var first = false;
Expand Down
4 changes: 2 additions & 2 deletions GeometryDashAPI/GeometryDashAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="csFastFloat" Version="4.1.0" />
<PackageReference Include="csFastFloat" Version="4.1.4" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="UrlBase64" Version="0.1.2" />
<PackageReference Include="UrlBase64" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions GeometryDashAPI/Levels/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ public string SaveAsString(bool compress = true)
public static string Decompress(string data)
{
var bytes = GameConvert.FromBase64(data);

if (bytes[0] == 0x78)
return Crypt.ZLibDecompress(bytes);
return Crypt.ZLibDecompress(bytes)?.StreamToString();

if (bytes[0] == 0x1F && bytes[1] == 0x8B)
return Crypt.GZipDecompress(bytes);
return Crypt.GZipDecompress(bytes)?.StreamToString();

throw new InvalidOperationException(
"Unsupported data signature. There is no gzip and zlib. Please check your level data. If your level is correct and works in the game, please create an issue: https://github.com/Folleach/GeometryDashAPI/issues. Or fix it yourself: https://github.com/Folleach/GeometryDashAPI/blob/master/GeometryDashAPI/Levels/Level.cs");
}
Expand Down
1 change: 1 addition & 0 deletions GeometryDashAPI/Serialization/Plist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Plist : Dictionary<string, dynamic>
{
private static readonly XmlReaderSettings xmlSettings = new XmlReaderSettings()
{
CheckCharacters = false, // to skip XML reserved characters
DtdProcessing = DtdProcessing.Ignore,
XmlResolver = null
};
Expand Down
Loading