Browse Source

Migrated to (and added) Newtonsoft.Json

pull/46/head
Anairkoen Schno 5 years ago
parent
commit
a4a3cf14bd
11 changed files with 110 additions and 1421 deletions
  1. +1
    -1
      IPA/Program.cs
  2. +2
    -2
      IPA/Properties/AssemblyInfo.cs
  3. +9
    -2
      IllusionInjector/IllusionInjector.csproj
  4. +81
    -38
      IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs
  5. +6
    -23
      IllusionInjector/Updating/ModsaberML/Updater.cs
  6. +1
    -1
      IllusionInjector/Updating/SelfPlugin.cs
  7. +8
    -0
      IllusionInjector/Utilities/LoneFunctions.cs
  8. +0
    -1353
      IllusionInjector/Utilities/SimpleJson.cs
  9. +1
    -1
      IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache
  10. +1
    -0
      IllusionInjector/packages.config
  11. BIN
      Libs/System.Runtime.Serialization.dll

+ 1
- 1
IPA/Program.cs View File

@ -18,7 +18,7 @@ namespace IPA {
Unknown
}
private static Version Version => new Version(Application.ProductVersion);
private static Version Version => Assembly.GetEntryAssembly().GetName().Version;
static void Main(string[] args)
{


+ 2
- 2
IPA/Properties/AssemblyInfo.cs View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.8.5")]
[assembly: AssemblyFileVersion("3.8.5")]
[assembly: AssemblyVersion("3.8.6.*")]
[assembly: AssemblyFileVersion("3.8.6")]

+ 9
- 2
IllusionInjector/IllusionInjector.csproj View File

@ -47,6 +47,9 @@
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
@ -84,7 +87,6 @@
<Compile Include="Updating\SelfPlugin.cs" />
<Compile Include="Utilities\Extensions.cs" />
<Compile Include="Utilities\LoneFunctions.cs" />
<Compile Include="Utilities\SimpleJson.cs" />
<Compile Include="Utilities\SteamCheck.cs" />
</ItemGroup>
<ItemGroup>
@ -96,7 +98,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="..\Libs\System.Runtime.Serialization.dll">
<Link>RequiredMonoLibs\System.Runtime.Serialization.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>


+ 81
- 38
IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs View File

@ -1,6 +1,9 @@
using IllusionInjector.Utilities;
using SimpleJSON;
using IllusionInjector.Logging;
using IllusionInjector.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -18,61 +21,101 @@ namespace IllusionInjector.Updating.ModsaberML
public const string GetApprovedEndpoint = "registry/{0}";
#endif
class HexArrayConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(byte[]);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
if (reader.TokenType == JsonToken.String)
{
try
{
return LoneFunctions.StringToByteArray((string)reader.Value);
}
catch (Exception ex)
{
throw new Exception(string.Format("Error parsing version string: {0}", reader.Value), ex);
}
}
throw new Exception(string.Format("Unexpected token or value when parsing hex string. Token: {0}, Value: {1}", reader.TokenType, reader.Value));
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
}
else
{
if (!(value is byte[]))
{
throw new JsonSerializationException("Expected byte[] object value");
}
writer.WriteValue(LoneFunctions.ByteArrayToString(value as byte[]));
}
}
}
[Serializable]
public class Mod
{
#pragma warning disable CS0649
[JsonProperty("name")]
public string Name;
[JsonProperty("version"),
JsonConverter(typeof(VersionConverter))]
public Version Version;
[JsonProperty("approved")]
public bool Approved;
[JsonProperty("title")]
public string Title;
[JsonProperty("gameVersion"),
JsonConverter(typeof(VersionConverter))]
public Version GameVersion;
[JsonProperty("author")]
public string Author;
#pragma warning restore CS0649
[Serializable]
public class PlatformFile
{
public byte[] Hash = new byte[20]; // 20 byte because sha1 is fucky
[JsonProperty("hash"),
JsonConverter(typeof(HexArrayConverter))]
public byte[] Hash = new byte[20];
[JsonProperty("files", ItemConverterType = typeof(HexArrayConverter))]
public Dictionary<string, byte[]> FileHashes = new Dictionary<string, byte[]>();
[JsonProperty("url")]
public string DownloadPath = null;
}
public PlatformFile SteamFile = null;
public PlatformFile OculusFile = null;
public static Mod DecodeJSON(JSONObject obj)
{
var outp = new Mod
public override string ToString()
{
Name = obj["name"],
Version = new Version(obj["version"]),
Approved = obj["approved"].AsBool,
Title = obj["title"],
GameVersion = new Version(obj["gameVersion"]),
Author = obj["author"]
};
foreach (var item in obj["files"])
{
var key = item.Key;
var pfile = new PlatformFile()
{
DownloadPath = item.Value["url"],
Hash = LoneFunctions.StringToByteArray(item.Value["hash"])
};
foreach (var file in item.Value["files"])
pfile.FileHashes.Add(file.Key, LoneFunctions.StringToByteArray(file.Value));
if (key == "steam")
outp.SteamFile = pfile;
if (key == "oculus")
outp.OculusFile = pfile;
return $"{LoneFunctions.ByteArrayToString(Hash)}@{DownloadPath}({string.Join(",",FileHashes.Select(o=>$"\"{o.Key}\":\"{LoneFunctions.ByteArrayToString(o.Value)}\""))})";
}
return outp;
}
[Serializable]
public class FilesObject
{
[JsonProperty("steam")]
public PlatformFile Steam = null;
[JsonProperty("oculus")]
public PlatformFile Oculus = null;
}
[JsonProperty("files")]
public FilesObject Files = null;
public override string ToString()
{
return $"{{\"{Title} ({Name})\"v{Version} for {GameVersion} by {Author} with \"{SteamFile}\" and \"{OculusFile}\"}}";
return $"{{\"{Title} ({Name})\"v{Version} for {GameVersion} by {Author} with \"{Files.Steam}\" and \"{Files.Oculus}\"}}";
}
}


+ 6
- 23
IllusionInjector/Updating/ModsaberML/Updater.cs View File

@ -1,7 +1,7 @@
using IllusionInjector.Updating.Backup;
using IllusionInjector.Utilities;
using Ionic.Zip;
using SimpleJSON;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
@ -89,28 +89,11 @@ namespace IllusionInjector.Updating.ModsaberML
var json = request.downloadHandler.text;
JSONObject obj = null;
try
{
obj = JSON.Parse(json).AsObject;
}
catch (InvalidCastException)
{
Logger.log.Error($"Parse error while trying to update mods");
Logger.log.Error($"Response doesn't seem to be a JSON object");
continue;
}
catch (Exception e)
{
Logger.log.Error($"Parse error while trying to update mods");
Logger.log.Error(e);
continue;
}
ApiEndpoint.Mod modRegistry;
try
{
modRegistry = ApiEndpoint.Mod.DecodeJSON(obj);
modRegistry = JsonConvert.DeserializeObject<ApiEndpoint.Mod>(json);
Logger.log.Debug(modRegistry.ToString());
}
catch (Exception e)
{
@ -290,10 +273,10 @@ namespace IllusionInjector.Updating.ModsaberML
Logger.log.Debug($"Steam avaliable: {SteamCheck.IsAvailable}");
ApiEndpoint.Mod.PlatformFile platformFile;
if (SteamCheck.IsAvailable || item.externInfo.OculusFile == null)
platformFile = item.externInfo.SteamFile;
if (SteamCheck.IsAvailable || item.externInfo.Files.Oculus == null)
platformFile = item.externInfo.Files.Steam;
else
platformFile = item.externInfo.OculusFile;
platformFile = item.externInfo.Files.Oculus;
string url = platformFile.DownloadPath;


+ 1
- 1
IllusionInjector/Updating/SelfPlugin.cs View File

@ -12,7 +12,7 @@ namespace IllusionInjector.Updating
internal class SelfPlugin : IBeatSaberPlugin
{
internal const string IPA_Name = "Beat Saber IPA";
internal const string IPA_Version = "3.8.5";
internal const string IPA_Version = "3.8.6";
public string Name => IPA_Name;


+ 8
- 0
IllusionInjector/Utilities/LoneFunctions.cs View File

@ -18,6 +18,14 @@ namespace IllusionInjector.Utilities
return bytes;
}
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
// Copyright (c) 2008-2013 Hafthor Stefansson
// Distributed under the MIT/X11 software license
// Ref: http://www.opensource.org/licenses/mit-license.php.


+ 0
- 1353
IllusionInjector/Utilities/SimpleJson.cs
File diff suppressed because it is too large
View File


+ 1
- 1
IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
f6d2b3a83d839d28f9c6280f831d88c7c7de66f4
71a44b54b01a27b264d5e56666d3bd427569aee5

+ 1
- 0
IllusionInjector/packages.config View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Ionic.Zip" version="1.9.1.8" targetFramework="net46" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net46" />
</packages>

BIN
Libs/System.Runtime.Serialization.dll View File


Loading…
Cancel
Save