From dd76e50140c55ec8844a481ae39b9b4ffe7629c0 Mon Sep 17 00:00:00 2001 From: burninrubber0 Date: Wed, 29 Apr 2026 12:07:53 -0400 Subject: [PATCH 1/2] Replace JSON library Use System.Text.Json instead of Newtonsoft.Json. --- BundleManager/BundleManager.csproj | 1 - VaultFormat/AttribSysVaultForm.cs | 10 ++++++++-- VaultFormat/VaultFormat.csproj | 3 --- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/BundleManager/BundleManager.csproj b/BundleManager/BundleManager.csproj index b0081f6..0e57966 100644 --- a/BundleManager/BundleManager.csproj +++ b/BundleManager/BundleManager.csproj @@ -12,7 +12,6 @@ - diff --git a/VaultFormat/AttribSysVaultForm.cs b/VaultFormat/AttribSysVaultForm.cs index a89fa55..35c2005 100644 --- a/VaultFormat/AttribSysVaultForm.cs +++ b/VaultFormat/AttribSysVaultForm.cs @@ -1,12 +1,12 @@ using BundleUtilities; using LangEditor; -using Newtonsoft.Json; using PluginAPI; using System; using System.Collections; using System.ComponentModel; using System.Globalization; using System.IO; +using System.Text.Json; using System.Windows.Forms; namespace VaultFormat @@ -14,6 +14,11 @@ namespace VaultFormat public delegate void Notify(); // delegate public partial class AttribSysVaultForm : Form, IEntryEditor { + private readonly JsonSerializerOptions jsonSerializerOptions = new() + { + WriteIndented = true + }; + public AttribSysVaultForm() { InitializeComponent(); @@ -148,7 +153,8 @@ private void exportVaultToolStripMenuItem_Click(object sender, EventArgs e) try { // Convertion of the AttribSys. Might need smarter structure to only keep the essential data concerning the configuration of the vehicle - string jsonContent = JsonConvert.SerializeObject(AttribSys, Formatting.Indented); + + string jsonContent = JsonSerializer.Serialize(AttribSys, jsonSerializerOptions); File.WriteAllText(saveDialog.FileName, jsonContent); diff --git a/VaultFormat/VaultFormat.csproj b/VaultFormat/VaultFormat.csproj index 232e433..8d2457e 100644 --- a/VaultFormat/VaultFormat.csproj +++ b/VaultFormat/VaultFormat.csproj @@ -4,9 +4,6 @@ Library true - - - From a3b29252805b1eb296bea85d99100f88206b5458 Mon Sep 17 00:00:00 2001 From: burninrubber0 Date: Wed, 29 Apr 2026 13:33:17 -0400 Subject: [PATCH 2/2] Replace compression library Use System.IO.Compression instead of LibDeflate.NET. --- BundleFormat/BundleEntry.cs | 2 +- BundleFormat/BundleFormat.csproj | 3 --- BundleFormat/Extensions.cs | 27 ++++++++++++++------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/BundleFormat/BundleEntry.cs b/BundleFormat/BundleEntry.cs index 70956bb..0844533 100644 --- a/BundleFormat/BundleEntry.cs +++ b/BundleFormat/BundleEntry.cs @@ -20,7 +20,7 @@ public byte[] Data return null; if (Compressed) - return RawData.Decompress((int)UncompressedSize); + return RawData.Decompress(); return RawData; } diff --git a/BundleFormat/BundleFormat.csproj b/BundleFormat/BundleFormat.csproj index 494662b..96808d3 100644 --- a/BundleFormat/BundleFormat.csproj +++ b/BundleFormat/BundleFormat.csproj @@ -4,9 +4,6 @@ Library true - - - diff --git a/BundleFormat/Extensions.cs b/BundleFormat/Extensions.cs index ebb3080..7caf4a5 100644 --- a/BundleFormat/Extensions.cs +++ b/BundleFormat/Extensions.cs @@ -1,19 +1,15 @@ using System; -using System.Buffers; using System.Buffers.Binary; using System.Collections.Generic; +using System.IO; +using System.IO.Compression; using System.Numerics; using System.Text; -using System.Windows.Forms; -using LibDeflate; namespace BundleFormat { public static class Extensions { - private static Decompressor decompressor = new ZlibDecompressor(); - private static Compressor compressor = new ZlibCompressor(9); - public static string AsString(this byte[] self) { if (self == null) @@ -45,18 +41,23 @@ public static string MakePreview(this byte[] self, int start, int end) public static byte[] Compress(this byte[] self) { - return compressor.Compress(self).Memory.ToArray(); + MemoryStream uncompressed = new(self); + MemoryStream compressed = new(); + using (ZLibStream zlibStream = new(compressed, CompressionLevel.SmallestSize, true)) + { + uncompressed.CopyTo(zlibStream); + } + return compressed.ToArray(); } - public static byte[] Decompress(this byte[] self, int uncompressedSize) + public static byte[] Decompress(this byte[] self) { - var status = decompressor.Decompress(self, uncompressedSize, out var owner, out var bytesRead); - if (status != OperationStatus.Done) + MemoryStream decompressed = new(); + using (ZLibStream zlibStream = new(new MemoryStream(self), CompressionMode.Decompress)) { - MessageBox.Show("Error decompressing data, status: " + status.ToString() + ", read: " + bytesRead.ToString(), "Error", MessageBoxButtons.OK); - return null; + zlibStream.CopyTo(decompressed); } - return owner.Memory.ToArray(); + return decompressed.ToArray(); } public static bool Matches(this byte[] self, byte[] other)