Some fixes for asset parsing via typetree

This commit is contained in:
VaDiM 2024-11-02 01:40:14 +03:00
parent c2095c4e7a
commit fca937e5e6
5 changed files with 12 additions and 8 deletions

View File

@ -517,6 +517,7 @@ namespace AssetStudio
{ {
Converters = { new JsonConverterHelper.ByteArrayConverter(), new JsonConverterHelper.PPtrConverter() }, Converters = { new JsonConverterHelper.ByteArrayConverter(), new JsonConverterHelper.PPtrConverter() },
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals, NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
PropertyNameCaseInsensitive = true,
IncludeFields = true, IncludeFields = true,
}; };

View File

@ -1,6 +1,7 @@
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace AssetStudio namespace AssetStudio
@ -32,6 +33,7 @@ namespace AssetStudio
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals, NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
ReferenceHandler = ReferenceHandler.IgnoreCycles, ReferenceHandler = ReferenceHandler.IgnoreCycles,
PropertyNameCaseInsensitive = true,
IncludeFields = true, IncludeFields = true,
WriteIndented = true, WriteIndented = true,
}; };
@ -63,7 +65,8 @@ namespace AssetStudio
string str = null; string str = null;
try try
{ {
str = JsonSerializer.Serialize(this, GetType(), jsonOptions).Replace(" ", " "); str = JsonSerializer.Deserialize<JsonObject>(JsonSerializer.SerializeToUtf8Bytes(this, GetType(), jsonOptions))
.ToJsonString(jsonOptions).Replace(" ", " ");
} }
catch catch
{ {

View File

@ -32,7 +32,7 @@ namespace AssetStudio
} }
else else
{ {
writer.WriteNumberValue((decimal)value); writer.WriteNumberValue((decimal)value + 0.0m);
} }
} }
} }

View File

@ -45,7 +45,7 @@ namespace AssetStudio
public override void Write(Utf8JsonWriter writer, PPtr<T> value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, PPtr<T> value, JsonSerializerOptions options)
{ {
JsonSerializer.Serialize(value); throw new NotImplementedException();
} }
} }
} }

View File

@ -32,17 +32,17 @@ namespace AssetStudio
var strKey = $"{kv.Key.Key}, {kv.Key.Value}"; var strKey = $"{kv.Key.Key}, {kv.Key.Value}";
jsonDict.Add(strKey, kv.Value); jsonDict.Add(strKey, kv.Value);
} }
var strValue = JsonSerializer.Serialize(jsonDict, options).Replace(" ", " "); var strValue = JsonSerializer.SerializeToUtf8Bytes(jsonDict, options);
writer.WriteRawValue(strValue); writer.WriteRawValue(strValue);
} }
} }
private class GUID private class GUID
{ {
[JsonPropertyName("data[0]")] public uint data0; [JsonPropertyName("data[0]")] public uint data0 { get; set; }
[JsonPropertyName("data[1]")] public uint data1; [JsonPropertyName("data[1]")] public uint data1 { get; set; }
[JsonPropertyName("data[2]")] public uint data2; [JsonPropertyName("data[2]")] public uint data2 { get; set; }
[JsonPropertyName("data[3]")] public uint data3; [JsonPropertyName("data[3]")] public uint data3 { get; set; }
public Guid Convert() public Guid Convert()
{ {