From d594f90fec0df248ef2f364b00dd5583712a790c Mon Sep 17 00:00:00 2001 From: Razmoth <32140579+Razmoth@users.noreply.github.com> Date: Tue, 19 Sep 2023 19:06:08 +0400 Subject: [PATCH] - [Core] fix issue with parsing `Texture2D` [GI] --- AssetStudio/Classes/Shader.cs | 2 +- AssetStudio/Classes/Texture2D.cs | 9 +++++---- AssetStudio/SerializedType.cs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/AssetStudio/Classes/Shader.cs b/AssetStudio/Classes/Shader.cs index 0bc6eef8..07863df0 100644 --- a/AssetStudio/Classes/Shader.cs +++ b/AssetStudio/Classes/Shader.cs @@ -578,7 +578,7 @@ public class SerializedSubProgram public UAVParameter[] m_UAVParams; public SamplerParameter[] m_Samplers; - public static bool HasGlobalLocalKeywordIndices(SerializedType type) => type.Match("E99740711222CD922E9A6F92FF1EB07A") || type.Match("450A058C218DAF000647948F2F59DA6D"); + public static bool HasGlobalLocalKeywordIndices(SerializedType type) => type.Match("E99740711222CD922E9A6F92FF1EB07A", "450A058C218DAF000647948F2F59DA6D"); public static bool HasInstancedStructuredBuffers(SerializedType type) => type.Match("E99740711222CD922E9A6F92FF1EB07A"); public SerializedSubProgram(ObjectReader reader) diff --git a/AssetStudio/Classes/Texture2D.cs b/AssetStudio/Classes/Texture2D.cs index e7c22ff8..87f2d9d7 100644 --- a/AssetStudio/Classes/Texture2D.cs +++ b/AssetStudio/Classes/Texture2D.cs @@ -63,7 +63,8 @@ public sealed class Texture2D : Texture public ResourceReader image_data; public StreamingInfo m_StreamData; - private static bool HasGNFTexture(ObjectReader reader) => reader.serializedType.Match("1D52BB98AA5F54C67C22C39E8B2E400F"); + private static bool HasGNFTexture(SerializedType type) => type.Match("1D52BB98AA5F54C67C22C39E8B2E400F"); + private static bool HasExternalMipRelativeOffset(SerializedType type) => type.Match("1D52BB98AA5F54C67C22C39E8B2E400F", "5390A985F58D5524F95DB240E8789704"); public Texture2D(ObjectReader reader) : base(reader) { m_Width = reader.ReadInt32(); @@ -85,7 +86,7 @@ public Texture2D(ObjectReader reader) : base(reader) if (version[0] > 2 || (version[0] == 2 && version[1] >= 6)) //2.6.0 and up { var m_IsReadable = reader.ReadBoolean(); - if (reader.Game.Type.IsGI() && HasGNFTexture(reader)) + if (reader.Game.Type.IsGI() && HasGNFTexture(reader.serializedType)) { var m_IsGNFTexture = reader.ReadBoolean(); } @@ -110,7 +111,7 @@ public Texture2D(ObjectReader reader) : base(reader) var m_StreamingMipmaps = reader.ReadBoolean(); } reader.AlignStream(); - if (reader.Game.Type.IsGI() && HasGNFTexture(reader)) + if (reader.Game.Type.IsGI() && HasGNFTexture(reader.serializedType)) { var m_TextureGroup = reader.ReadInt32(); } @@ -137,7 +138,7 @@ public Texture2D(ObjectReader reader) : base(reader) var image_data_size = reader.ReadInt32(); if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up { - if (reader.Game.Type.IsGI() && HasGNFTexture(reader)) + if (reader.Game.Type.IsGI() && HasExternalMipRelativeOffset(reader.serializedType)) { var m_externalMipRelativeOffset = reader.ReadUInt32(); } diff --git a/AssetStudio/SerializedType.cs b/AssetStudio/SerializedType.cs index 81d44c98..63e38f5b 100644 --- a/AssetStudio/SerializedType.cs +++ b/AssetStudio/SerializedType.cs @@ -18,7 +18,7 @@ public class SerializedType public string m_NameSpace; public string m_AsmName; - public bool Match(string hash) => Convert.ToHexString(m_OldTypeHash) == hash; + public bool Match(params string[] hashes) => hashes.Any(x => x == Convert.ToHexString(m_OldTypeHash)); public override string ToString() { var sb = new StringBuilder();