Skip to content

Commit 21ed109

Browse files
authored
Merge pull request #29 from flightlex/master
gd options and other (check desc)
2 parents aac1bb1 + d407e0f commit 21ed109

File tree

9 files changed

+400
-50
lines changed

9 files changed

+400
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using BenchmarkDotNet.Attributes;
2+
using GeometryDashAPI.Data;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace GeometryDashAPI.Benchmarks.Benchmarks
10+
{
11+
[MemoryDiagnoser]
12+
public class GameDataBenchmark
13+
{
14+
private GameManager manager;
15+
16+
[Benchmark]
17+
public void ParseSplit()
18+
{
19+
manager = GameManager.LoadFile(null);
20+
}
21+
}
22+
}

GeometryDashAPI.Benchmarks/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
BenchmarkSwitcher.FromAssembly(Assembly.GetAssembly(typeof(Program))).Run(args,
66
ManualConfig.Create(DefaultConfig.Instance)
7-
.With(ConfigOptions.DisableOptimizationsValidator));
7+
.With(ConfigOptions.DisableOptimizationsValidator));

GeometryDashAPI.Tests/GeometryDashAPI.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
1111
<PackageReference Include="FluentAssertions" Version="6.0.0-alpha0002" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
13-
<PackageReference Include="NUnit" Version="3.13.0" />
13+
<PackageReference Include="NUnit" Version="3.13.3" />
1414
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

GeometryDashAPI/Attributes/GamePropertyAttribute.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace GeometryDashAPI.Attributes
66
public class GamePropertyAttribute : Attribute
77
{
88
public string Key { get; }
9-
public object DefaultValue { get; }
9+
public object? DefaultValue { get; }
1010
public bool AlwaysSet { get; }
1111
public int KeyOverride { get; set; }
1212
public int Order { get; set; } = int.MaxValue;
1313

14-
public GamePropertyAttribute(string key, object defaultValue = null, bool alwaysSet = false)
14+
public GamePropertyAttribute(string key, object? defaultValue = null, bool alwaysSet = false)
1515
{
1616
Key = key;
1717
DefaultValue = defaultValue;

GeometryDashAPI/Data/GameData.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ public virtual async Task LoadAsync(string fileName)
2828
if (!File.Exists(fileName))
2929
throw new FileNotFoundException($"file does not exists: '{fileName}'");
3030

31-
// File > Bytes > XOR > ToString > Replace > Base64 > Gzip
3231
#if NETSTANDARD2_1
33-
var data = await File.ReadAllBytesAsync(fileName);
32+
await using var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true);
3433
#else
3534
using var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true);
36-
var data = new byte[file.Length];
37-
var read = await file.ReadAsync(data, 0, data.Length);
3835
#endif
39-
var dataZip = Encoding.ASCII.GetString(Crypt.XOR(data, 0xB)).Split('\0')[0];
40-
var resultPlist = Crypt.GZipDecompress(GameConvert.FromBase64(dataZip));
36+
var data = new byte[file.Length];
37+
await file.ReadAsync(data, 0, data.Length);
4138

42-
DataPlist = new Plist(Encoding.ASCII.GetBytes(resultPlist));
43-
}
39+
var xor = Crypt.XOR(data, 0xB);
40+
var index = xor.AsSpan().IndexOf((byte)0);
41+
var gZipDecompress = Crypt.GZipDecompress(GameConvert.FromBase64(Encoding.ASCII.GetString(xor, 0, index >= 0 ? index : xor.Length)));
4442

43+
DataPlist = new Plist(Encoding.ASCII.GetBytes(gZipDecompress));
44+
}
45+
4546
/// <summary>
4647
/// Saves class data to a file as a game save<br/><br/>
4748
/// Before saving, make sure that you have closed the game. Otherwise, after closing, the game will overwrite the file<br/>

0 commit comments

Comments
 (0)