Skip to content

Commit

Permalink
Deprecate TinyJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
slxdy committed Jan 23, 2025
1 parent dd19d5c commit e9d2b1e
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 102 deletions.
41 changes: 27 additions & 14 deletions Dependencies/Il2CppAssemblyGenerator/RemoteAPI.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using Semver;

#pragma warning disable 0649

namespace MelonLoader.Il2CppAssemblyGenerator
{
internal static class RemoteAPI
Expand Down Expand Up @@ -122,27 +122,40 @@ internal static class Melon

internal static InfoStruct Contact(string response_str)
{
ResponseStruct responseobj = MelonUtils.ParseJSONStringtoStruct<ResponseStruct>(response_str);
ResponseStruct responseobj = JsonSerializer.Deserialize<ResponseStruct>(response_str);
if (responseobj == null)
return null;

InfoStruct returninfo = new InfoStruct();
returninfo.ForceDumperVersion = responseobj.forceCpp2IlVersion;
returninfo.ObfuscationRegex = responseobj.obfuscationRegex;
returninfo.MappingURL = responseobj.mappingUrl;
returninfo.MappingFileSHA512 = responseobj.mappingFileSHA512;
returninfo.ForceDumperVersion = responseobj.ForceCpp2IlVersion;
returninfo.ObfuscationRegex = responseobj.ObfuscationRegex;
returninfo.MappingURL = responseobj.MappingUrl;
returninfo.MappingFileSHA512 = responseobj.MappingFileSHA512;
return returninfo;
}

internal class ResponseStruct
{
public string gameSlug = null;
public string gameName = null;
public string mappingUrl = null;
public string mappingFileSHA512 = null;
public string forceCpp2IlVersion = null;
public string forceUnhollowerVersion = null; //TODO: Remove this from the API
public string obfuscationRegex = null;
[JsonPropertyName("gameSlug")]
public string GameSlug { get; set; }

[JsonPropertyName("gameName")]
public string GameName { get; set; }

[JsonPropertyName("mappingUrl")]
public string MappingUrl { get; set; }

[JsonPropertyName("mappingFileSHA512")]
public string MappingFileSHA512 { get; set; }

[JsonPropertyName("forceCpp2IlVersion")]
public string ForceCpp2IlVersion { get; set; }

[JsonPropertyName("forceUnhollowerVersion")]
public string ForceUnhollowerVersion { get; set; } //TODO: Remove this from the API

[JsonPropertyName("obfuscationRegex")]
public string ObfuscationRegex { get; set; }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using MelonLoader.ICSharpCode.SharpZipLib.Zip.Compression;
using System;
using System.IO;

namespace MelonLoader.ICSharpCode.SharpZipLib.GZip
{
using static Zip.Compression.Deflater;

/// <summary>
/// An example class to demonstrate compression and decompression of GZip streams.
/// </summary>
Expand Down Expand Up @@ -68,7 +67,7 @@ public static void Compress(Stream inStream, Stream outStream, bool isStreamOwne
if (bufferSize < 512)
throw new ArgumentOutOfRangeException(nameof(bufferSize), "Deflate buffer size must be >= 512");

if (level < NO_COMPRESSION || level > BEST_COMPRESSION)
if (level < Deflater.NO_COMPRESSION || level > Deflater.BEST_COMPRESSION)
throw new ArgumentOutOfRangeException(nameof(level), "Compression level must be 0-9");

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using MelonLoader.ICSharpCode.SharpZipLib.Zip.Compression;
using System;
using System.IO;
using static MelonLoader.ICSharpCode.SharpZipLib.Zip.Compression.Deflater;
using static MelonLoader.ICSharpCode.SharpZipLib.Zip.ZipEntryFactory;

namespace MelonLoader.ICSharpCode.SharpZipLib.Zip
{
Expand Down Expand Up @@ -198,14 +196,14 @@ public FastZip()
{
}

/// <summary>
/// Initialise a new instance of <see cref="FastZip"/> using the specified <see cref="TimeSetting"/>
/// </summary>
/// <param name="timeSetting">The <see cref="TimeSetting">time setting</see> to use when creating or extracting <see cref="ZipEntry">Zip entries</see>.</param>
/// <remarks>Using <see cref="TimeSetting.LastAccessTime">TimeSetting.LastAccessTime</see><see cref="TimeSetting.LastAccessTimeUtc">[Utc]</see> when
/// creating an archive will set the file time to the moment of reading.
/// </remarks>
public FastZip(TimeSetting timeSetting)
/// <summary>
/// Initialise a new instance of <see cref="FastZip"/> using the specified <see cref="ZipEntryFactory.TimeSetting"/>
/// </summary>
/// <param name="timeSetting">The <see cref="ZipEntryFactory.TimeSetting">time setting</see> to use when creating or extracting <see cref="ZipEntry">Zip entries</see>.</param>
/// <remarks>Using <see cref="ZipEntryFactory.TimeSetting.LastAccessTime">TimeSetting.LastAccessTime</see><see cref="ZipEntryFactory.TimeSetting.LastAccessTimeUtc">[Utc]</see> when
/// creating an archive will set the file time to the moment of reading.
/// </remarks>
public FastZip(ZipEntryFactory.TimeSetting timeSetting)
{
entryFactory_ = new ZipEntryFactory(timeSetting);
restoreDateTimeOnExtract_ = true;
Expand Down Expand Up @@ -763,31 +761,31 @@ private void ExtractFileEntry(ZipEntry entry, string targetName)
{
switch (entryFactory_.Setting)
{
case TimeSetting.CreateTime:
case ZipEntryFactory.TimeSetting.CreateTime:
File.SetCreationTime(targetName, entry.DateTime);
break;

case TimeSetting.CreateTimeUtc:
case ZipEntryFactory.TimeSetting.CreateTimeUtc:
File.SetCreationTimeUtc(targetName, entry.DateTime);
break;

case TimeSetting.LastAccessTime:
case ZipEntryFactory.TimeSetting.LastAccessTime:
File.SetLastAccessTime(targetName, entry.DateTime);
break;

case TimeSetting.LastAccessTimeUtc:
case ZipEntryFactory.TimeSetting.LastAccessTimeUtc:
File.SetLastAccessTimeUtc(targetName, entry.DateTime);
break;

case TimeSetting.LastWriteTime:
case ZipEntryFactory.TimeSetting.LastWriteTime:
File.SetLastWriteTime(targetName, entry.DateTime);
break;

case TimeSetting.LastWriteTimeUtc:
case ZipEntryFactory.TimeSetting.LastWriteTimeUtc:
File.SetLastWriteTimeUtc(targetName, entry.DateTime);
break;

case TimeSetting.Fixed:
case ZipEntryFactory.TimeSetting.Fixed:
File.SetLastWriteTime(targetName, entryFactory_.FixedDateTime);
break;

Expand Down Expand Up @@ -869,31 +867,31 @@ private void ExtractEntry(ZipEntry entry)
{
switch (entryFactory_.Setting)
{
case TimeSetting.CreateTime:
case ZipEntryFactory.TimeSetting.CreateTime:
Directory.SetCreationTime(dirName, entry.DateTime);
break;

case TimeSetting.CreateTimeUtc:
case ZipEntryFactory.TimeSetting.CreateTimeUtc:
Directory.SetCreationTimeUtc(dirName, entry.DateTime);
break;

case TimeSetting.LastAccessTime:
case ZipEntryFactory.TimeSetting.LastAccessTime:
Directory.SetLastAccessTime(dirName, entry.DateTime);
break;

case TimeSetting.LastAccessTimeUtc:
case ZipEntryFactory.TimeSetting.LastAccessTimeUtc:
Directory.SetLastAccessTimeUtc(dirName, entry.DateTime);
break;

case TimeSetting.LastWriteTime:
case ZipEntryFactory.TimeSetting.LastWriteTime:
Directory.SetLastWriteTime(dirName, entry.DateTime);
break;

case TimeSetting.LastWriteTimeUtc:
case ZipEntryFactory.TimeSetting.LastWriteTimeUtc:
Directory.SetLastWriteTimeUtc(dirName, entry.DateTime);
break;

case TimeSetting.Fixed:
case ZipEntryFactory.TimeSetting.Fixed:
Directory.SetLastWriteTime(dirName, entryFactory_.FixedDateTime);
break;

Expand Down Expand Up @@ -968,7 +966,7 @@ private static bool NameIsValid(string name)
private IEntryFactory entryFactory_ = new ZipEntryFactory();
private INameTransform extractNameTransform_;
private UseZip64 useZip64_ = UseZip64.Dynamic;
private CompressionLevel compressionLevel_ = CompressionLevel.DEFAULT_COMPRESSION;
private Deflater.CompressionLevel compressionLevel_ = Deflater.CompressionLevel.DEFAULT_COMPRESSION;

private string password_;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using MelonLoader.ICSharpCode.SharpZipLib.Core;
using static MelonLoader.ICSharpCode.SharpZipLib.Zip.ZipEntryFactory;

namespace MelonLoader.ICSharpCode.SharpZipLib.Zip
{
Expand Down Expand Up @@ -54,15 +53,15 @@ public interface IEntryFactory
/// </summary>
INameTransform NameTransform { get; set; }

/// <summary>
/// Get the <see cref="TimeSetting"/> in use.
/// </summary>
TimeSetting Setting { get; }
/// <summary>
/// Get the <see cref="ZipEntryFactory.TimeSetting"/> in use.
/// </summary>
ZipEntryFactory.TimeSetting Setting { get; }

/// <summary>
/// Get the <see cref="DateTime"/> value to use when <see cref="Setting"/> is set to <see cref="TimeSetting.Fixed"/>,
/// or if not specified, the value of <see cref="DateTime.Now"/> when the class was the initialized
/// </summary>
DateTime FixedDateTime { get; }
/// <summary>
/// Get the <see cref="DateTime"/> value to use when <see cref="Setting"/> is set to <see cref="ZipEntryFactory.TimeSetting.Fixed"/>,
/// or if not specified, the value of <see cref="DateTime.Now"/> when the class was the initialized
/// </summary>
DateTime FixedDateTime { get; }
}
}
3 changes: 2 additions & 1 deletion MelonLoader/BackwardsCompatibility/TinyJSON/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace MelonLoader.TinyJSON
{
public sealed class Decoder : IDisposable
[Obsolete("Please use Newtonsoft.Json or System.Text.Json instead. This will be removed in a future version.", true)]
public sealed class Decoder : IDisposable
{
const string whiteSpace = " \t\n\r";
const string wordBreak = " \t\n\r{}[],:\"";
Expand Down
3 changes: 2 additions & 1 deletion MelonLoader/BackwardsCompatibility/TinyJSON/EncodeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace MelonLoader.TinyJSON
{
[Flags]
public enum EncodeOptions
[Obsolete("Please use Newtonsoft.Json or System.Text.Json instead. This will be removed in a future version.", true)]
public enum EncodeOptions
{
None = 0,
PrettyPrint = 1,
Expand Down
3 changes: 2 additions & 1 deletion MelonLoader/BackwardsCompatibility/TinyJSON/Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

namespace MelonLoader.TinyJSON
{
public sealed class Encoder
[Obsolete("Please use Newtonsoft.Json or System.Text.Json instead. This will be removed in a future version.", true)]
public sealed class Encoder
{
static readonly Type includeAttrType = typeof(Include);
static readonly Type excludeAttrType = typeof(Exclude);
Expand Down
3 changes: 2 additions & 1 deletion MelonLoader/BackwardsCompatibility/TinyJSON/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

namespace MelonLoader.TinyJSON
{
public static class Extensions
[Obsolete("Please use Newtonsoft.Json or System.Text.Json instead. This will be removed in a future version.", true)]
public static class Extensions
{
public static bool AnyOfType<TSource>( this IEnumerable<TSource> source, Type expectedType )
{
Expand Down
Loading

0 comments on commit e9d2b1e

Please sign in to comment.