This commit is contained in:
Razmoth
2023-01-06 22:33:59 +04:00
parent a3cf868dfb
commit 2b31232b30
178 changed files with 5213 additions and 23780 deletions

View File

@@ -1,7 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SevenZip;
using System.Collections.Generic;
using System.Collections.Generic;
namespace AssetStudio
{
@@ -21,94 +18,52 @@ namespace AssetStudio
public class UnityPropertySheet
{
private const string HDRPostfixName = "_HDR";
private const string STPostfixName = "_ST";
private const string TexelSizePostfixName = "_TexelSize";
public Dictionary<string, UnityTexEnv> m_TexEnvs;
public Dictionary<string, int> m_Ints;
public Dictionary<string, float> m_Floats;
public Dictionary<string, Color> m_Colors;
public KeyValuePair<string, UnityTexEnv>[] m_TexEnvs;
public KeyValuePair<string, int>[] m_Ints;
public KeyValuePair<string, float>[] m_Floats;
public KeyValuePair<string, Color>[] m_Colors;
public UnityPropertySheet(ObjectReader reader)
{
var version = reader.version;
int m_TexEnvsSize = reader.ReadInt32();
m_TexEnvs = new Dictionary<string, UnityTexEnv>(m_TexEnvsSize);
m_TexEnvs = new KeyValuePair<string, UnityTexEnv>[m_TexEnvsSize];
for (int i = 0; i < m_TexEnvsSize; i++)
{
m_TexEnvs.Add(reader.ReadAlignedString(), new UnityTexEnv(reader));
m_TexEnvs[i] = new KeyValuePair<string, UnityTexEnv>(reader.ReadAlignedString(), new UnityTexEnv(reader));
}
if (version[0] >= 2021) //2021.1 and up
{
int m_IntsSize = reader.ReadInt32();
m_Ints = new Dictionary<string, int>(m_IntsSize);
m_Ints = new KeyValuePair<string, int>[m_IntsSize];
for (int i = 0; i < m_IntsSize; i++)
{
m_Ints.Add(reader.ReadAlignedString(), reader.ReadInt32());
m_Ints[i] = new KeyValuePair<string, int>(reader.ReadAlignedString(), reader.ReadInt32());
}
}
int m_FloatsSize = reader.ReadInt32();
m_Floats = new Dictionary<string, float>(m_FloatsSize);
m_Floats = new KeyValuePair<string, float>[m_FloatsSize];
for (int i = 0; i < m_FloatsSize; i++)
{
m_Floats.Add(reader.ReadAlignedString(), reader.ReadSingle());
m_Floats[i] = new KeyValuePair<string, float>(reader.ReadAlignedString(), reader.ReadSingle());
}
int m_ColorsSize = reader.ReadInt32();
m_Colors = new Dictionary<string, Color>(m_ColorsSize);
m_Colors = new KeyValuePair<string, Color>[m_ColorsSize];
for (int i = 0; i < m_ColorsSize; i++)
{
m_Colors.Add(reader.ReadAlignedString(), reader.ReadColor4());
m_Colors[i] = new KeyValuePair<string, Color>(reader.ReadAlignedString(), reader.ReadColor4());
}
}
public string FindPropertyNameByCRC28(uint crc)
{
foreach (var property in m_TexEnvs.Keys)
{
string hdrName = property + HDRPostfixName;
if (CRC.Verify28DigestUTF8(hdrName, crc))
{
return hdrName;
}
string stName = property + STPostfixName;
if (CRC.Verify28DigestUTF8(stName, crc))
{
return stName;
}
string texelName = property + TexelSizePostfixName;
if (CRC.Verify28DigestUTF8(texelName, crc))
{
return texelName;
}
}
foreach (var property in m_Floats.Keys)
{
if (CRC.Verify28DigestUTF8(property, crc))
{
return property;
}
}
foreach (var property in m_Colors.Keys)
{
if (CRC.Verify28DigestUTF8(property, crc))
{
return property;
}
}
return null;
}
}
public sealed class Material : NamedObject
{
public PPtr<Shader> m_Shader;
public UnityPropertySheet m_SavedProperties;
public Dictionary<string, string> m_StringTagMap;
public Material(ObjectReader reader) : base(reader)
{
@@ -119,16 +74,25 @@ namespace AssetStudio
var m_ShaderKeywords = reader.ReadStringArray();
}
if (version[0] >= 5) //5.0 and up
if (version[0] > 2021 || (version[0] == 2021 && version[1] >= 3)) //2021.3 and up
{
var m_ValidKeywords = reader.ReadStringArray();
var m_InvalidKeywords = reader.ReadStringArray();
}
else if (version[0] >= 5) //5.0 ~ 2021.2
{
var m_ShaderKeywords = reader.ReadAlignedString();
}
if (version[0] >= 5) //5.0 and up
{
var m_LightmapFlags = reader.ReadUInt32();
}
if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
{
var m_EnableInstancingVariants = reader.ReadBoolean();
var m_DoubleSidedGI = reader.ReadBoolean(); //2017 and up
//var m_DoubleSidedGI = a_Stream.ReadBoolean(); //2017 and up
reader.AlignStream();
}
@@ -140,15 +104,18 @@ namespace AssetStudio
if (version[0] > 5 || (version[0] == 5 && version[1] >= 1)) //5.1 and up
{
var stringTagMapSize = reader.ReadInt32();
m_StringTagMap = new Dictionary<string, string>(stringTagMapSize);
for (int i = 0; i < stringTagMapSize; i++)
{
var first = reader.ReadAlignedString();
var second = reader.ReadAlignedString();
m_StringTagMap.Add(first, second);
}
}
if (reader.Game.Type.IsNaraka())
{
var value = reader.ReadInt32();
}
if (version[0] > 5 || (version[0] == 5 && version[1] >= 6)) //5.6 and up
{
var disabledShaderPasses = reader.ReadStringArray();
@@ -158,10 +125,5 @@ namespace AssetStudio
//vector m_BuildTextureStacks 2020 and up
}
public string FindPropertyNameByCRC28(uint crc)
{
return m_SavedProperties.FindPropertyNameByCRC28(crc);
}
}
}