From e92d96bb087e8f739db8b2ccb69b8b1036c50b39 Mon Sep 17 00:00:00 2001 From: VaDiM Date: Mon, 23 Mar 2026 19:25:30 +0300 Subject: [PATCH] Replace Newtonsoft.Json with System.Text.Json for MonoBehaviour assets --- AssetStudio/Classes/Object.cs | 12 ++++++------ AssetStudioCLI/AssetStudioCLI.csproj | 4 ---- AssetStudioCLI/Exporter.cs | 3 +-- AssetStudioGUI/AssetStudioGUI.csproj | 1 - AssetStudioGUI/AssetStudioGUIForm.cs | 3 +-- AssetStudioGUI/Exporter.cs | 3 +-- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/AssetStudio/Classes/Object.cs b/AssetStudio/Classes/Object.cs index 10018a9..bec509a 100644 --- a/AssetStudio/Classes/Object.cs +++ b/AssetStudio/Classes/Object.cs @@ -8,6 +8,7 @@ namespace AssetStudio { public class Object { + public static readonly JsonSerializerOptions JsonOptions; [JsonIgnore] public SerializedFile assetsFile; [JsonIgnore] @@ -25,11 +26,10 @@ namespace AssetStudio public uint byteSize; [JsonIgnore] public string Name; - private static readonly JsonSerializerOptions jsonOptions; static Object() { - jsonOptions = new JsonSerializerOptions + JsonOptions = new JsonSerializerOptions { Converters = { new JsonConverterHelper.FloatConverter() }, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, @@ -72,8 +72,8 @@ namespace AssetStudio m_Mesh.ProcessData(); } - str = JsonSerializer.Deserialize(JsonSerializer.SerializeToUtf8Bytes(this, GetType(), jsonOptions)) - .ToJsonString(jsonOptions).Replace(" ", " "); + str = JsonSerializer.Deserialize(JsonSerializer.SerializeToUtf8Bytes(this, GetType(), JsonOptions)) + .ToJsonString(JsonOptions).Replace(" ", " "); } catch { @@ -108,7 +108,7 @@ namespace AssetStudio { if (typeDict != null) { - return JsonSerializer.SerializeToDocument(typeDict, jsonOptions); + return JsonSerializer.SerializeToDocument(typeDict, JsonOptions); } if (this is Mesh m_Mesh) @@ -116,7 +116,7 @@ namespace AssetStudio m_Mesh.ProcessData(); } - return JsonSerializer.SerializeToDocument(this, GetType(), jsonOptions); + return JsonSerializer.SerializeToDocument(this, GetType(), JsonOptions); } catch { diff --git a/AssetStudioCLI/AssetStudioCLI.csproj b/AssetStudioCLI/AssetStudioCLI.csproj index e848d60..08f3d89 100644 --- a/AssetStudioCLI/AssetStudioCLI.csproj +++ b/AssetStudioCLI/AssetStudioCLI.csproj @@ -11,10 +11,6 @@ embedded - - - - diff --git a/AssetStudioCLI/Exporter.cs b/AssetStudioCLI/Exporter.cs index 90260b1..9ed3f87 100644 --- a/AssetStudioCLI/Exporter.cs +++ b/AssetStudioCLI/Exporter.cs @@ -1,6 +1,5 @@ using AssetStudio; using AssetStudioCLI.Options; -using Newtonsoft.Json; using System.Collections.Generic; using System.IO; using System.Linq; @@ -143,7 +142,7 @@ namespace AssetStudioCLI } if (type != null) { - var str = JsonConvert.SerializeObject(type, Formatting.Indented); + var str = System.Text.Json.JsonSerializer.Serialize(type, Object.JsonOptions); File.WriteAllText(exportFullPath, str); Logger.Debug($"{item.TypeString} \"{item.Text}\" exported to \"{exportFullPath}\""); diff --git a/AssetStudioGUI/AssetStudioGUI.csproj b/AssetStudioGUI/AssetStudioGUI.csproj index a68dae0..1ce458f 100644 --- a/AssetStudioGUI/AssetStudioGUI.csproj +++ b/AssetStudioGUI/AssetStudioGUI.csproj @@ -60,7 +60,6 @@ - diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index d32a2f0..1d7e9b7 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -1,5 +1,4 @@ using AssetStudio; -using Newtonsoft.Json; using OpenTK.Graphics.OpenGL; using System; using System.Collections.Generic; @@ -1259,7 +1258,7 @@ namespace AssetStudioGUI var type = MonoBehaviourToTypeTree(m_MonoBehaviour); obj = m_MonoBehaviour.ToType(type); } - var str = JsonConvert.SerializeObject(obj, Formatting.Indented); + var str = System.Text.Json.JsonSerializer.Serialize(obj, AssetStudio.Object.JsonOptions); PreviewText(str); } diff --git a/AssetStudioGUI/Exporter.cs b/AssetStudioGUI/Exporter.cs index 271efe1..a0efbd4 100644 --- a/AssetStudioGUI/Exporter.cs +++ b/AssetStudioGUI/Exporter.cs @@ -1,5 +1,4 @@ using AssetStudio; -using Newtonsoft.Json; using System.Collections.Generic; using System.IO; using System.Linq; @@ -121,7 +120,7 @@ namespace AssetStudioGUI var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour); type = m_MonoBehaviour.ToType(m_Type); } - var str = JsonConvert.SerializeObject(type, Formatting.Indented); + var str = System.Text.Json.JsonSerializer.Serialize(type, Object.JsonOptions); File.WriteAllText(exportFullPath, str); return true; }