diff --git a/AssetTools.NET/AssetsTools.NET.nuspec b/AssetTools.NET/AssetsTools.NET.nuspec index 19a3a5d..95eea86 100644 --- a/AssetTools.NET/AssetsTools.NET.nuspec +++ b/AssetTools.NET/AssetsTools.NET.nuspec @@ -2,7 +2,7 @@ AssetsTools.NET - 3.0.2 + 3.0.3 nesrak1 nesrak1 false @@ -11,10 +11,12 @@ icon.png An assets/bundle library, inspired by UABE's AssetsTools An assets/bundle library, inspired by UABE's AssetsTools. Read and write assets and bundle files from engine versions 5.x and later. For most cases, you'll need the class data file which you can find in the AssetRipper/Tpk repo. See the wiki for usage and examples. - v3.0.2 - bug fixes, template field [] syntax, lz4 fast compress option + v3.0.3 - added back .net 3.5 support, fixed typetrees with unicode, added field iterator helper class https://github.com/nesrak1/AssetsTools.NET + + @@ -24,6 +26,9 @@ + + + diff --git a/AssetTools.NET/Extra/AssetsManager/AssetsManager.Bundle.cs b/AssetTools.NET/Extra/AssetsManager/AssetsManager.Bundle.cs index d0af9b3..addb584 100644 --- a/AssetTools.NET/Extra/AssetsManager/AssetsManager.Bundle.cs +++ b/AssetTools.NET/Extra/AssetsManager/AssetsManager.Bundle.cs @@ -4,6 +4,11 @@ namespace AssetsTools.NET.Extra { public partial class AssetsManager { + public static string GetBundleLookupKey(string path) + { + return Path.GetFullPath(path); + } + /// /// Load a from a stream with a path. /// Use the version of this method to skip the path argument. @@ -17,7 +22,7 @@ public partial class AssetsManager public BundleFileInstance LoadBundleFile(Stream stream, string path, bool unpackIfPacked = true) { BundleFileInstance bunInst; - string lookupKey = GetFileLookupKey(path); + string lookupKey = GetBundleLookupKey(path); if (BundleLookup.TryGetValue(lookupKey, out bunInst)) return bunInst; @@ -68,7 +73,7 @@ public BundleFileInstance LoadBundleFile(string path, bool unpackIfPacked = true /// True if the file was found and closed, and false if it wasn't found. public bool UnloadBundleFile(string path) { - string lookupKey = GetFileLookupKey(path); + string lookupKey = GetBundleLookupKey(path); if (BundleLookup.TryGetValue(lookupKey, out BundleFileInstance bunInst)) { bunInst.file.Close(); @@ -109,7 +114,7 @@ public bool UnloadBundleFile(BundleFileInstance bunInst) if (Bundles.Contains(bunInst)) { - string lookupKey = GetFileLookupKey(bunInst.path); + string lookupKey = GetBundleLookupKey(bunInst.path); lock (BundleLookup) { lock (Bundles) diff --git a/AssetTools.NET/Extra/AssetsManager/AssetsManager.Deserialization.cs b/AssetTools.NET/Extra/AssetsManager/AssetsManager.Deserialization.cs index 969ea63..c98e2e2 100644 --- a/AssetTools.NET/Extra/AssetsManager/AssetsManager.Deserialization.cs +++ b/AssetTools.NET/Extra/AssetsManager/AssetsManager.Deserialization.cs @@ -60,7 +60,8 @@ public AssetTypeTemplateField GetTemplateBaseField( AssetTypeTemplateField baseField = null; // if non-monobehaviour type is in cache, return the cached item - if (UseTemplateFieldCache && typeId != (int)AssetClassID.MonoBehaviour && templateFieldCache.TryGetValue(typeId, out baseField)) + bool isMonoBehaviourTypeId = typeId == (int)AssetClassID.MonoBehaviour || typeId < 0; + if (UseTemplateFieldCache && !isMonoBehaviourTypeId && templateFieldCache.TryGetValue(typeId, out baseField)) { return baseField; } @@ -74,7 +75,7 @@ public AssetTypeTemplateField GetTemplateBaseField( // load from that instead if (hasTypeTree && (!forceFromCldb || ClassDatabase == null)) { - if (UseMonoTemplateFieldCache && typeId == (int)AssetClassID.MonoBehaviour) + if (UseMonoTemplateFieldCache && isMonoBehaviourTypeId) { if (monoTypeTreeTemplateFieldCache.TryGetValue(inst, out ConcurrentDictionary templates) && templates.TryGetValue(scriptIndex, out baseField)) @@ -89,11 +90,11 @@ public AssetTypeTemplateField GetTemplateBaseField( baseField = new AssetTypeTemplateField(); baseField.FromTypeTree(ttType); - if (UseTemplateFieldCache && typeId != (int)AssetClassID.MonoBehaviour) + if (UseTemplateFieldCache && !isMonoBehaviourTypeId) { templateFieldCache[typeId] = baseField; } - else if (UseMonoTemplateFieldCache && typeId == (uint)AssetClassID.MonoBehaviour) + else if (UseMonoTemplateFieldCache && isMonoBehaviourTypeId) { if (!monoTypeTreeTemplateFieldCache.TryGetValue(inst, out ConcurrentDictionary templates)) { @@ -107,9 +108,9 @@ public AssetTypeTemplateField GetTemplateBaseField( } // if we cached a monobehaviour from a class database, clone a copy - if (UseTemplateFieldCache && UseMonoTemplateFieldCache && typeId == (int)AssetClassID.MonoBehaviour) + if (UseTemplateFieldCache && UseMonoTemplateFieldCache && isMonoBehaviourTypeId) { - if (templateFieldCache.TryGetValue(typeId, out baseField)) + if (templateFieldCache.TryGetValue((int)AssetClassID.MonoBehaviour, out baseField)) { baseField = baseField.Clone(); } @@ -125,7 +126,9 @@ public AssetTypeTemplateField GetTemplateBaseField( return null; } - ClassDatabaseType cldbType = ClassDatabase.FindAssetClassByID(typeId); + int fixedTypeId = isMonoBehaviourTypeId ? (int)AssetClassID.MonoBehaviour : typeId; + + ClassDatabaseType cldbType = ClassDatabase.FindAssetClassByID(fixedTypeId); if (cldbType == null) { return null; @@ -138,13 +141,13 @@ public AssetTypeTemplateField GetTemplateBaseField( if (UseTemplateFieldCache) { - if (typeId == (int)AssetClassID.MonoBehaviour) + if (fixedTypeId == (int)AssetClassID.MonoBehaviour) { - templateFieldCache[typeId] = baseField.Clone(); + templateFieldCache[fixedTypeId] = baseField.Clone(); } else { - templateFieldCache[typeId] = baseField; + templateFieldCache[fixedTypeId] = baseField; } } } @@ -155,7 +158,7 @@ public AssetTypeTemplateField GetTemplateBaseField( // but this is safer) and then passing the script from there to // the temp generator. we then append those fields to the base. bool skipMonoBehaviourFields = Net35Polyfill.HasFlag(readFlags, AssetReadFlags.SkipMonoBehaviourFields); - if (typeId == (int)AssetClassID.MonoBehaviour && MonoTempGenerator != null && !skipMonoBehaviourFields && reader != null) + if (isMonoBehaviourTypeId && MonoTempGenerator != null && !skipMonoBehaviourFields && reader != null) { AssetTypeValueField mbBaseField = baseField.MakeValue(reader, absByteStart); AssetPPtr msPtr = AssetPPtr.FromField(mbBaseField["m_Script"]); @@ -280,7 +283,7 @@ public AssetTypeTemplateField CreateTemplateBaseField(AssetsFileInstance inst, i } else { - if (id != (int)AssetClassID.MonoBehaviour || scriptIndex == 0xffff) + if ((id != (int)AssetClassID.MonoBehaviour && id >= 0) || scriptIndex == 0xffff) { var cldbType = ClassDatabase.FindAssetClassByID(id); templateField.FromClassDatabase(ClassDatabase, cldbType); diff --git a/AssetTools.NET/Extra/MonoDeserializer/CommonMonoTemplateHelper.cs b/AssetTools.NET/Extra/MonoDeserializer/CommonMonoTemplateHelper.cs index 22f4141..f22e3e4 100644 --- a/AssetTools.NET/Extra/MonoDeserializer/CommonMonoTemplateHelper.cs +++ b/AssetTools.NET/Extra/MonoDeserializer/CommonMonoTemplateHelper.cs @@ -88,45 +88,19 @@ public static class CommonMonoTemplateHelper ["System.String"] = "string" }; - private static readonly Dictionary baseToAssetValueType = new Dictionary() - { - ["System.Boolean"] = AssetValueType.UInt8, - ["System.SByte"] = AssetValueType.Int8, - ["System.Byte"] = AssetValueType.UInt8, - ["System.Char"] = AssetValueType.UInt16, - ["System.Int16"] = AssetValueType.Int16, - ["System.UInt16"] = AssetValueType.UInt16, - ["System.Int32"] = AssetValueType.Int32, - ["System.UInt32"] = AssetValueType.UInt32, - ["System.Int64"] = AssetValueType.Int64, - ["System.UInt64"] = AssetValueType.UInt64, - ["System.Double"] = AssetValueType.Double, - ["System.Single"] = AssetValueType.Float, - ["System.String"] = AssetValueType.String - }; - - #endregion - - #region Checks - - public static string ConvertBaseToPrimitive(string name) { if (baseToPrimitive.TryGetValue(name, out string primitiveName)) { return primitiveName; } + return name; } - public static AssetValueType ConvertBaseToAssetValueType(string name) - { - if (baseToAssetValueType.TryGetValue(name, out AssetValueType value)) - { - return value; - } - return AssetValueType.None; - } + #endregion + + #region Checks public static bool IsSpecialUnityType(string fullName) { @@ -145,20 +119,18 @@ public static bool IsPrimitiveType(string fullName) public static bool TypeAligns(AssetValueType valueType) { - if (valueType.Equals(AssetValueType.Bool) || - valueType.Equals(AssetValueType.Int8) || - valueType.Equals(AssetValueType.UInt8) || - valueType.Equals(AssetValueType.Int16) || - valueType.Equals(AssetValueType.UInt16)) - return true; - return false; + return valueType.Equals(AssetValueType.Bool) + || valueType.Equals(AssetValueType.Int8) + || valueType.Equals(AssetValueType.UInt8) + || valueType.Equals(AssetValueType.Int16) + || valueType.Equals(AssetValueType.UInt16); } public static int GetSerializationLimit(UnityVersion unityVersion) { - if (unityVersion.major > 2020 || - (unityVersion.major == 2020 && (unityVersion.minor >= 2 || (unityVersion.minor == 1 && unityVersion.patch >= 4))) || - (unityVersion.major == 2019 && unityVersion.minor == 4 && unityVersion.patch >= 9)) + if (unityVersion.major > 2020 + || (unityVersion.major == 2020 && (unityVersion.minor > 1 || (unityVersion.minor == 1 && unityVersion.patch >= 4))) + || (unityVersion.major == 2019 && unityVersion.minor == 4 && unityVersion.patch >= 9)) { return 10; } @@ -210,13 +182,16 @@ public static List Array(AssetTypeTemplateField field) { Name = "Array", Type = "Array", - ValueType = field.ValueType == AssetValueType.UInt8 ? AssetValueType.ByteArray : AssetValueType.Array, + ValueType = field.ValueType == AssetValueType.UInt8 + ? AssetValueType.ByteArray + : AssetValueType.Array, IsArray = true, IsAligned = true, HasValue = true, Children = new List { - Int("size"), CreateTemplateField("data", field.Type, field.ValueType, field.Children) + Int("size"), + CreateTemplateField("data", field.Type, field.ValueType, field.Children) } }; @@ -232,10 +207,18 @@ public static List ManagedReference(UnityVersion unityVe { if (unityVersion.major > 2021 || (unityVersion.major == 2021 && unityVersion.minor >= 2)) { - return new List { Long("rid") }; + return new List + { + Long("rid") + }; + } + else + { + return new List + { + Int("id") + }; } - - return new List { Int("id") }; } public static AssetTypeTemplateField ManagedReferencesRegistry(string name, UnityVersion unityVersion) => @@ -244,10 +227,20 @@ public static List ManagedReferencesRegistry(UnityVersio { if (unityVersion.major > 2021 || (unityVersion.major == 2021 && unityVersion.minor >= 2)) { - return new List { Int("version"), Vector(ReferencedObject("RefIds", unityVersion)) }; + return new List + { + Int("version"), + Vector(ReferencedObject("RefIds", unityVersion)) + }; + } + else + { + return new List + { + Int("version"), + ReferencedObject("00000000", unityVersion) + }; } - - return new List { Int("version"), ReferencedObject("00000000", unityVersion) }; } public static AssetTypeTemplateField ReferencedObject(string name, UnityVersion unityVersion) => CreateTemplateField(name, "ReferencedObject", ReferencedObject(unityVersion)); @@ -255,16 +248,32 @@ public static List ReferencedObject(UnityVersion unityVe { if (unityVersion.major > 2021 || (unityVersion.major == 2021 && unityVersion.minor >= 2)) { - return new List { Long("rid"), ReferencedManagedType("type"), CreateTemplateField("data", "ReferencedObjectData", AssetValueType.None) }; + return new List + { + Long("rid"), + ReferencedManagedType("type"), + CreateTemplateField("data", "ReferencedObjectData", AssetValueType.None) + }; + } + else + { + return new List + { + ReferencedManagedType("type"), + CreateTemplateField("data", "ReferencedObjectData", AssetValueType.None) + }; } - - return new List { ReferencedManagedType("type"), CreateTemplateField("data", "ReferencedObjectData", AssetValueType.None) }; } public static AssetTypeTemplateField ReferencedManagedType(string name) => CreateTemplateField(name, "ReferencedManagedType", ReferencedManagedType()); public static List ReferencedManagedType() { - return new List { String("class"), String("ns"), String("asm") }; + return new List + { + String("class"), + String("ns"), + String("asm") + }; } #endregion @@ -274,131 +283,362 @@ public static List ReferencedManagedType() public static AssetTypeTemplateField Gradient(string name, UnityVersion unityVersion) => CreateTemplateField(name, "Gradient", Gradient(unityVersion)); public static List Gradient(UnityVersion unityVersion) { - if (unityVersion.major > 2022 || (unityVersion.major == 2022 && unityVersion.minor >= 2)) + if (unityVersion.major > 5 || (unityVersion.major == 5 && unityVersion.minor >= 6)) { - return new List { - RGBAf("key0"), RGBAf("key1"), RGBAf("key2"), RGBAf("key3"), RGBAf("key4"), RGBAf("key5"), RGBAf("key6"), RGBAf("key7"), - UShort("ctime0"), UShort("ctime1"), UShort("ctime2"), UShort("ctime3"), UShort("ctime4"), UShort("ctime5"), UShort("ctime6"), UShort("ctime7"), - UShort("atime0"), UShort("atime1"), UShort("atime2"), UShort("atime3"), UShort("atime4"), UShort("atime5"), UShort("atime6"), UShort("atime7"), - Byte("m_Mode"), SByte("m_ColorSpace"), Byte("m_NumColorKeys"), Byte("m_NumAlphaKeys", true) + List fields = new List + { + RGBAf("key0"), + RGBAf("key1"), + RGBAf("key2"), + RGBAf("key3"), + RGBAf("key4"), + RGBAf("key5"), + RGBAf("key6"), + RGBAf("key7"), + UShort("ctime0"), + UShort("ctime1"), + UShort("ctime2"), + UShort("ctime3"), + UShort("ctime4"), + UShort("ctime5"), + UShort("ctime6"), + UShort("ctime7"), + UShort("atime0"), + UShort("atime1"), + UShort("atime2"), + UShort("atime3"), + UShort("atime4"), + UShort("atime5"), + UShort("atime6"), + UShort("atime7") }; - } - return new List { - RGBAf("key0"), RGBAf("key1"), RGBAf("key2"), RGBAf("key3"), RGBAf("key4"), RGBAf("key5"), RGBAf("key6"), RGBAf("key7"), - UShort("ctime0"), UShort("ctime1"), UShort("ctime2"), UShort("ctime3"), UShort("ctime4"), UShort("ctime5"), UShort("ctime6"), UShort("ctime7"), - UShort("atime0"), UShort("atime1"), UShort("atime2"), UShort("atime3"), UShort("atime4"), UShort("atime5"), UShort("atime6"), UShort("atime7"), - Int("m_Mode"), Byte("m_NumColorKeys"), Byte("m_NumAlphaKeys", true) - }; + if (unityVersion.major > 2022 || (unityVersion.major == 2022 && unityVersion.minor >= 2)) + { + fields.Add(Byte("m_Mode")); + fields.Add(SByte("m_ColorSpace")); + } + else + { + fields.Add(Int("m_Mode")); + } + + fields.Add(Byte("m_NumColorKeys")); + fields.Add(Byte("m_NumAlphaKeys", true)); + + return fields; + } + else + { + return new List() + { + RGBAi("key0"), + RGBAi("key1"), + RGBAi("key2"), + RGBAi("key3"), + RGBAi("key4"), + RGBAi("key5"), + RGBAi("key6"), + RGBAi("key7") + }; + } } public static AssetTypeTemplateField AnimationCurve(string name, UnityVersion unityVersion) => CreateTemplateField(name, "AnimationCurve", AnimationCurve(unityVersion)); public static List AnimationCurve(UnityVersion unityVersion) { - return new List { - Vector(Keyframe("m_Curve", unityVersion)), Int("m_PreInfinity"), Int("m_PostInfinity"), Int("m_RotationOrder") + List fields = new List + { + Vector(Keyframe("m_Curve", unityVersion)), + Int("m_PreInfinity"), + Int("m_PostInfinity") }; + + if (unityVersion.major > 5 || (unityVersion.major == 5 && unityVersion.minor >= 3)) + { + fields.Add(Int("m_RotationOrder")); + } + + return fields; } - //only supports 2019 right now public static AssetTypeTemplateField GUIStyle(string name, UnityVersion unityVersion) => CreateTemplateField(name, "GUIStyle", GUIStyle(unityVersion)); public static List GUIStyle(UnityVersion unityVersion) { - return new List { + List fields = new List + { String("m_Name"), - GUIStyleState("m_Normal", unityVersion), GUIStyleState("m_Hover", unityVersion), GUIStyleState("m_Active", unityVersion), GUIStyleState("m_Focused", unityVersion), - GUIStyleState("m_OnNormal", unityVersion), GUIStyleState("m_OnHover", unityVersion), GUIStyleState("m_OnActive", unityVersion), GUIStyleState("m_OnFocused", unityVersion), - RectOffset("m_Border"), RectOffset("m_Margin"), RectOffset("m_Padding"), RectOffset("m_Overflow"), - PPtr("m_Font", "Font", unityVersion), Int("m_FontSize"), Int("m_FontStyle"), - Int("m_Alignment"), Bool("m_WordWrap"), Bool("m_RichText", true), - Int("m_TextClipping"), Int("m_ImagePosition"), Vector2f("m_ContentOffset"), - Float("m_FixedWidth"), Float("m_FixedHeight"), Bool("m_StretchWidth"), Bool("m_StretchHeight", true) + GUIStyleState("m_Normal", unityVersion), + GUIStyleState("m_Hover", unityVersion), + GUIStyleState("m_Active", unityVersion), + GUIStyleState("m_Focused", unityVersion), + GUIStyleState("m_OnNormal", unityVersion), + GUIStyleState("m_OnHover", unityVersion), + GUIStyleState("m_OnActive", unityVersion), + GUIStyleState("m_OnFocused", unityVersion), + RectOffset("m_Border"), }; + + if (unityVersion.major >= 4) + { + fields.Add(RectOffset("m_Margin")); + fields.Add(RectOffset("m_Padding")); + } + else + { + fields.Add(RectOffset("m_Padding")); + fields.Add(RectOffset("m_Margin")); + } + + fields.Add(RectOffset("m_Overflow")); + fields.Add(PPtr("m_Font", "Font", unityVersion)); + + if (unityVersion.major >= 4) + { + fields.Add(Int("m_FontSize")); + fields.Add(Int("m_FontStyle")); + fields.Add(Int("m_Alignment")); + fields.Add(Bool("m_WordWrap")); + fields.Add(Bool("m_RichText", true)); + } + else + { + fields.Add(Int("m_ImagePosition")); + fields.Add(Int("m_Alignment")); + fields.Add(Bool("m_WordWrap", true)); + } + + fields.Add(Int("m_TextClipping")); + + if (unityVersion.major >= 4) + { + fields.Add(Int("m_ImagePosition")); + } + + fields.Add(Vector2f("m_ContentOffset")); + + if (unityVersion.major < 4) + { + fields.Add(Vector2f("m_ClipOffset")); + } + + fields.Add(Float("m_FixedWidth")); + fields.Add(Float("m_FixedHeight")); + + if (unityVersion.major >= 4) + { + fields.Add(Bool("m_StretchWidth")); + } + else + { + fields.Add(Int("m_FontSize")); + fields.Add(Int("m_FontStyle")); + fields.Add(Bool("m_StretchWidth", true)); + } + + fields.Add(Bool("m_StretchHeight", true)); + + return fields; } public static AssetTypeTemplateField Keyframe(string name, UnityVersion unityVersion) => CreateTemplateField(name, "Keyframe", Keyframe(unityVersion)); public static List Keyframe(UnityVersion unityVersion) { + List fields = new List + { + Float("time"), + Float("value"), + Float("inSlope"), + Float("outSlope") + }; + if (unityVersion.major >= 2018) { - return new List { - Float("time"), Float("value"), Float("inSlope"), Float("outSlope"), - Int("weightedMode"), Float("inWeight"), Float("outWeight") - }; + fields.Add(Int("weightedMode")); + fields.Add(Float("inWeight")); + fields.Add(Float("outWeight")); } - return new List { Float("time"), Float("value"), Float("inSlope"), Float("outSlope") }; + + return fields; } public static AssetTypeTemplateField GUIStyleState(string name, UnityVersion unityVersion) => CreateTemplateField(name, "GUIStyleState", GUIStyleState(unityVersion)); public static List GUIStyleState(UnityVersion unityVersion) { - return new List { PPtr("m_Background", "Texture2D", unityVersion), RGBAf("m_TextColor") }; + return new List + { + PPtr("m_Background", "Texture2D", unityVersion), + RGBAf("m_TextColor") + }; + } + + public static AssetTypeTemplateField SphericalHarmonicsL2(string name, UnityVersion unityVersion) => CreateTemplateField(name, "SphericalHarmonicsL2", SphericalHarmonicsL2(unityVersion)); + public static List SphericalHarmonicsL2(UnityVersion unityVersion) + { + List fields = new List(); + + if (unityVersion.major >= 5) + { + fields.Add(Float("sh[ 0]")); + fields.Add(Float("sh[ 1]")); + fields.Add(Float("sh[ 2]")); + fields.Add(Float("sh[ 3]")); + fields.Add(Float("sh[ 4]")); + fields.Add(Float("sh[ 5]")); + fields.Add(Float("sh[ 6]")); + fields.Add(Float("sh[ 7]")); + fields.Add(Float("sh[ 8]")); + fields.Add(Float("sh[ 9]")); + } + else + { + fields.Add(Float("sh[0]")); + fields.Add(Float("sh[1]")); + fields.Add(Float("sh[2]")); + fields.Add(Float("sh[3]")); + fields.Add(Float("sh[4]")); + fields.Add(Float("sh[5]")); + fields.Add(Float("sh[6]")); + fields.Add(Float("sh[7]")); + fields.Add(Float("sh[8]")); + fields.Add(Float("sh[9]")); + } + + fields.Add(Float("sh[10]")); + fields.Add(Float("sh[11]")); + fields.Add(Float("sh[12]")); + fields.Add(Float("sh[13]")); + fields.Add(Float("sh[14]")); + fields.Add(Float("sh[15]")); + fields.Add(Float("sh[16]")); + fields.Add(Float("sh[17]")); + fields.Add(Float("sh[18]")); + fields.Add(Float("sh[19]")); + fields.Add(Float("sh[20]")); + fields.Add(Float("sh[21]")); + fields.Add(Float("sh[22]")); + fields.Add(Float("sh[23]")); + fields.Add(Float("sh[24]")); + fields.Add(Float("sh[25]")); + fields.Add(Float("sh[26]")); + + return fields; } public static AssetTypeTemplateField RGBAf(string name) => CreateTemplateField(name, "ColorRGBA", RGBAf()); public static List RGBAf() { - return new List { Float("r"), Float("g"), Float("b"), Float("a") }; + return new List + { + Float("r"), + Float("g"), + Float("b"), + Float("a") + }; } public static AssetTypeTemplateField RGBAi(string name) => CreateTemplateField(name, "ColorRGBA", RGBAi()); public static List RGBAi() { - return new List { UInt("rgba") }; + return new List + { + UInt("rgba") + }; } public static AssetTypeTemplateField AABB(string name) => CreateTemplateField(name, "AABB", AABB()); public static List AABB() { - return new List { Vector3f("m_Center"), Vector3f("m_Extent") }; + return new List + { + Vector3f("m_Center"), + Vector3f("m_Extent") + }; } public static AssetTypeTemplateField BoundsInt(string name) => CreateTemplateField(name, "BoundsInt", BoundsInt()); public static List BoundsInt() { - return new List { Vector3Int("m_Position"), Vector3Int("m_Size") }; + return new List + { + Vector3Int("m_Position"), + Vector3Int("m_Size") + }; } public static AssetTypeTemplateField BitField(string name) => CreateTemplateField(name, "BitField", BitField()); public static List BitField() { - return new List { UInt("m_Bits") }; + return new List + { + UInt("m_Bits") + }; } public static AssetTypeTemplateField Rectf(string name) => CreateTemplateField(name, "Rectf", Rectf()); public static List Rectf() { - return new List { Float("x"), Float("y"), Float("width"), Float("height") }; + return new List + { + Float("x"), + Float("y"), + Float("width"), + Float("height") + }; } public static AssetTypeTemplateField RectOffset(string name) => CreateTemplateField(name, "RectOffset", RectOffset()); public static List RectOffset() { - return new List { Int("m_Left"), Int("m_Right"), Int("m_Top"), Int("m_Bottom") }; + return new List + { + Int("m_Left"), + Int("m_Right"), + Int("m_Top"), + Int("m_Bottom") + }; } public static AssetTypeTemplateField Vector2Int(string name) => CreateTemplateField(name, "int2_storage", Vector2Int()); public static List Vector2Int() { - return new List { Int("x"), Int("y") }; + return new List + { + Int("x"), + Int("y") + }; } public static AssetTypeTemplateField Vector3Int(string name) => CreateTemplateField(name, "int3_storage", Vector3Int()); public static List Vector3Int() { - return new List { Int("x"), Int("y"), Int("z") }; + return new List + { + Int("x"), + Int("y"), + Int("z") + }; } public static AssetTypeTemplateField Vector2f(string name) => CreateTemplateField(name, "Vector2f", Vector2f()); public static List Vector2f() { - return new List { Float("x"), Float("y") }; + return new List + { + Float("x"), + Float("y") + }; } public static AssetTypeTemplateField Vector3f(string name) => CreateTemplateField(name, "Vector3f", Vector3f()); public static List Vector3f() { - return new List { Float("x"), Float("y"), Float("z") }; + return new List + { + Float("x"), + Float("y"), + Float("z") + }; } public static AssetTypeTemplateField PPtr(string name, string typeName, UnityVersion unityVersion) => CreateTemplateField(name, $"PPtr<{typeName}>", PPtr(unityVersion)); @@ -406,17 +646,49 @@ public static List PPtr(UnityVersion unityVersion) { if (unityVersion.major >= 5) { - return new List { Int("m_FileID"), Long("m_PathID") }; + return new List + { + Int("m_FileID"), + Long("m_PathID") + }; + } + else + { + return new List + { + Int("m_FileID"), + Int("m_PathID") + }; } - - return new List { Int("m_FileID"), Int("m_PathID") }; } - // yes, there is a double string here - public static AssetTypeTemplateField PropertyName(string name) => CreateTemplateField(name, "string", PropertyName()); - public static List PropertyName() + public static AssetTypeTemplateField PropertyName(string name, UnityVersion unityVersion) => CreateTemplateField(name, "string", PropertyName(unityVersion)); + public static List PropertyName(UnityVersion unityVersion) { - return new List { String("id") }; + if (unityVersion.major > 2020 + || (unityVersion.major == 2020 && + (unityVersion.minor > 2 || (unityVersion.minor == 2 && (unityVersion.type != "a" || unityVersion.typeNum >= 16)))) + || (unityVersion.major == 2020 && + (unityVersion.minor > 1 || (unityVersion.minor == 1 && unityVersion.type != "a" && (unityVersion.type != "b" || unityVersion.typeNum >= 15)))) + || (unityVersion.major == 2019 && + (unityVersion.minor > 4 || (unityVersion.minor == 4 && (unityVersion.type != "a" || unityVersion.patch >= 3)))) + || (unityVersion.major == 2018 && + (unityVersion.minor > 4 || (unityVersion.minor == 4 && (unityVersion.type != "a" || unityVersion.patch >= 25)))) + ) + { + // yes, there is a double string here + return new List + { + String("id") + }; + } + else + { + return new List + { + Int("id") + }; + } } #endregion diff --git a/AssetTools.NET/Standard/AssetTypeClass/AssetTypeValueIterator.cs b/AssetTools.NET/Standard/AssetTypeClass/AssetTypeValueIterator.cs index c6d7807..cfbdd58 100644 --- a/AssetTools.NET/Standard/AssetTypeClass/AssetTypeValueIterator.cs +++ b/AssetTools.NET/Standard/AssetTypeClass/AssetTypeValueIterator.cs @@ -210,11 +210,11 @@ public bool ReadNext() case AssetValueType.Int32: case AssetValueType.UInt32: case AssetValueType.Float: - case AssetValueType.Double: reader.Position += 4; break; case AssetValueType.Int64: case AssetValueType.UInt64: + case AssetValueType.Double: reader.Position += 8; break; case AssetValueType.String: @@ -249,8 +249,7 @@ public bool ReadNext() // because we create child iterators for arrays rather than depend // on the template field. if (topField.Current != null - && topField.Current.IsArray - && topField.Current.ValueType != AssetValueType.ByteArray + && (!topField.Current.IsArray || topField.Current.ValueType != AssetValueType.ByteArray) && topField.Current.IsAligned) { reader.Align(); diff --git a/AssetsTools.NET.Cpp2IL/Cpp2IlTempGenerator.cs b/AssetsTools.NET.Cpp2IL/Cpp2IlTempGenerator.cs index f6a14f4..818caa6 100644 --- a/AssetsTools.NET.Cpp2IL/Cpp2IlTempGenerator.cs +++ b/AssetsTools.NET.Cpp2IL/Cpp2IlTempGenerator.cs @@ -502,7 +502,8 @@ private List SpecialUnity(TypeDefWithSelfRef type, int a "GUIStyle" => CommonMonoTemplateHelper.GUIStyle(_unityVersion), "Vector2Int" => CommonMonoTemplateHelper.Vector2Int(), "Vector3Int" => CommonMonoTemplateHelper.Vector3Int(), - "PropertyName" => CommonMonoTemplateHelper.PropertyName(), + "PropertyName" => CommonMonoTemplateHelper.PropertyName(_unityVersion), + "SphericalHarmonicsL2" => CommonMonoTemplateHelper.SphericalHarmonicsL2(_unityVersion), _ => Serialized(type, availableDepth) }; } diff --git a/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs b/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs index 1282f90..97ee6a7 100644 --- a/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs +++ b/AssetsTools.NET.MonoCecil/MonoCecilTempGenerator.cs @@ -425,7 +425,8 @@ private List SpecialUnity( "GUIStyle" => CommonMonoTemplateHelper.GUIStyle(unityVersion), "Vector2Int" => CommonMonoTemplateHelper.Vector2Int(), "Vector3Int" => CommonMonoTemplateHelper.Vector3Int(), - "PropertyName" => CommonMonoTemplateHelper.PropertyName(), + "PropertyName" => CommonMonoTemplateHelper.PropertyName(unityVersion), + "SphericalHarmonicsL2" => CommonMonoTemplateHelper.SphericalHarmonicsL2(unityVersion), _ => Serialized(type, availableDepth, ref usingManagedReference) }; }