Example #1
0
 public LayerConstant(EndianBinaryReader reader, int[] version)
 {
     m_StateMachineIndex          = reader.ReadUInt32();
     m_StateMachineMotionSetIndex = reader.ReadUInt32();
     m_BodyMask                 = new HumanPoseMask(reader, version);
     m_SkeletonMask             = new SkeletonMask(reader);
     m_Binding                  = reader.ReadUInt32();
     m_LayerBlendingMode        = reader.ReadInt32();
     m_DefaultWeight            = reader.ReadSingle();
     m_IKPass                   = reader.ReadBoolean();
     m_SyncedLayerAffectsTiming = reader.ReadBoolean();
     reader.AlignStream(4);
 }
Example #2
0
        private SerializedType ReadSerializedType()
        {
            var type = new SerializedType();

            type.classID = reader.ReadInt32();

            if (header.m_Version >= 16)
            {
                type.m_IsStrippedType = reader.ReadBoolean();
            }

            if (header.m_Version >= 17)
            {
                type.m_ScriptTypeIndex = reader.ReadInt16();
            }

            if (header.m_Version >= 13)
            {
                if ((header.m_Version < 16 && type.classID < 0) || (header.m_Version >= 16 && type.classID == 114))
                {
                    type.m_ScriptID = reader.ReadBytes(16); //Hash128
                }
                type.m_OldTypeHash = reader.ReadBytes(16);  //Hash128
            }

            if (m_EnableTypeTree)
            {
                var typeTree = new List <TypeTreeNode>();
                if (header.m_Version >= 12 || header.m_Version == 10)
                {
                    TypeTreeBlobRead(typeTree);
                }
                else
                {
                    ReadTypeTree(typeTree);
                }

                if (header.m_Version >= 21)
                {
                    var count = reader.ReadInt32();
                    if (count > 0)
                    {
                        reader.Position += 4 * count;
                    }
                }

                type.m_Nodes = typeTree;
            }

            return(type);
        }
Example #3
0
        public ValueArray(EndianBinaryReader reader, int[] version)
        {
            if (version[0] < 5 || (version[0] == 5 && version[1] < 5)) //5.5 down
            {
                int numBools = reader.ReadInt32();
                m_BoolValues = new bool[numBools];
                for (int i = 0; i < numBools; i++)
                {
                    m_BoolValues[i] = reader.ReadBoolean();
                }

                reader.AlignStream(4);

                m_IntValues   = reader.ReadInt32Array(reader.ReadInt32());
                m_FloatValues = reader.ReadSingleArray(reader.ReadInt32());
            }

            int numPosValues = reader.ReadInt32();

            m_PositionValues = new object[numPosValues];
            for (int i = 0; i < numPosValues; i++)
            {
                m_PositionValues[i] = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? (object)reader.ReadVector3() : (object)reader.ReadVector4(); //5.4 and up
            }

            m_QuaternionValues = reader.ReadVector4Array(reader.ReadInt32());

            int numScaleValues = reader.ReadInt32();

            m_ScaleValues = new object[numScaleValues];
            for (int i = 0; i < numScaleValues; i++)
            {
                m_ScaleValues[i] = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? (object)reader.ReadVector3() : (object)reader.ReadVector4(); //5.4 adn up
            }

            if (version[0] > 5 || (version[0] == 5 && version[1] >= 5)) //5.5 and up
            {
                m_FloatValues = reader.ReadSingleArray(reader.ReadInt32());
                m_IntValues   = reader.ReadInt32Array(reader.ReadInt32());

                int numBools = reader.ReadInt32();
                m_BoolValues = new bool[numBools];
                for (int i = 0; i < numBools; i++)
                {
                    m_BoolValues[i] = reader.ReadBoolean();
                }

                reader.AlignStream(4);
            }
        }
Example #4
0
        private SerializedType ReadSerializedType(bool isRefType)
        {
            var type = new SerializedType();

            type.classID = reader.ReadInt32();

            if (header.m_Version >= SerializedFileFormatVersion.kRefactoredClassId)
            {
                type.m_IsStrippedType = reader.ReadBoolean();
            }

            if (header.m_Version >= SerializedFileFormatVersion.kRefactorTypeData)
            {
                type.m_ScriptTypeIndex = reader.ReadInt16();
            }

            if (header.m_Version >= SerializedFileFormatVersion.kHasTypeTreeHashes)
            {
                if (isRefType && type.m_ScriptTypeIndex >= 0)
                {
                    type.m_ScriptID = reader.ReadBytes(16);
                }
                else if ((header.m_Version < SerializedFileFormatVersion.kRefactoredClassId && type.classID < 0) || (header.m_Version >= SerializedFileFormatVersion.kRefactoredClassId && type.classID == 114))
                {
                    type.m_ScriptID = reader.ReadBytes(16);
                }
                type.m_OldTypeHash = reader.ReadBytes(16);
            }

            if (m_EnableTypeTree)
            {
                type.m_Type         = new TypeTree();
                type.m_Type.m_Nodes = new List <TypeTreeNode>();
                if (header.m_Version >= SerializedFileFormatVersion.kUnknown_12 || header.m_Version == SerializedFileFormatVersion.kUnknown_10)
                {
                    TypeTreeBlobRead(type.m_Type);
                }
                else
                {
                    ReadTypeTree(type.m_Type);
                }
                if (header.m_Version >= SerializedFileFormatVersion.kStoresTypeDependencies)
                {
                    if (isRefType)
                    {
                        type.m_KlassName = reader.ReadStringToNull();
                        type.m_NameSpace = reader.ReadStringToNull();
                        type.m_AsmName   = reader.ReadStringToNull();
                    }
                    else
                    {
                        type.m_TypeDependencies = reader.ReadInt32Array();
                    }
                }
            }

            return(type);
        }
Example #5
0
        public SelectorStateConstant(EndianBinaryReader reader)
        {
            int numTransitions = reader.ReadInt32();

            m_TransitionConstantArray = new SelectorTransitionConstant[numTransitions];
            for (int i = 0; i < numTransitions; i++)
            {
                m_TransitionConstantArray[i] = new SelectorTransitionConstant(reader);
            }

            m_FullPathID = reader.ReadUInt32();
            m_isEntry    = reader.ReadBoolean();
            reader.AlignStream(4);
        }
Example #6
0
        public TransitionConstant(EndianBinaryReader reader, int[] version)
        {
            int numConditions = reader.ReadInt32();

            m_ConditionConstantArray = new ConditionConstant[numConditions];
            for (int i = 0; i < numConditions; i++)
            {
                m_ConditionConstantArray[i] = new ConditionConstant(reader);
            }

            m_DestinationState = reader.ReadUInt32();
            if (version[0] >= 5) //5.0 and up
            {
                m_FullPathID = reader.ReadUInt32();
            }

            m_ID                 = reader.ReadUInt32();
            m_UserID             = reader.ReadUInt32();
            m_TransitionDuration = reader.ReadSingle();
            m_TransitionOffset   = reader.ReadSingle();
            if (version[0] >= 5) //5.0 and up
            {
                m_ExitTime         = reader.ReadSingle();
                m_HasExitTime      = reader.ReadBoolean();
                m_HasFixedDuration = reader.ReadBoolean();
                reader.AlignStream(4);
                m_InterruptionSource  = reader.ReadInt32();
                m_OrderedInterruption = reader.ReadBoolean();
            }
            else
            {
                m_Atomic = reader.ReadBoolean();
            }

            m_CanTransitionToSelf = reader.ReadBoolean();
            reader.AlignStream(4);
        }
Example #7
0
        public BlendTreeNodeConstant(EndianBinaryReader reader, int[] version)
        {
            m_BlendType     = reader.ReadUInt32();
            m_BlendEventID  = reader.ReadUInt32();
            m_BlendEventYID = reader.ReadUInt32();
            m_ChildIndices  = reader.ReadUInt32Array(reader.ReadInt32());
            m_Blend1dData   = new Blend1dDataConstant(reader);
            m_Blend2dData   = new Blend2dDataConstant(reader);
            if (version[0] >= 5) //5.0 and up
            {
                m_BlendDirectData = new BlendDirectDataConstant(reader);
            }

            m_ClipID = reader.ReadUInt32();
            if (version[0] < 5) //5.0 down
            {
                m_ClipIndex = reader.ReadUInt32();
            }

            m_Duration    = reader.ReadSingle();
            m_CycleOffset = reader.ReadSingle();
            m_Mirror      = reader.ReadBoolean();
            reader.AlignStream(4);
        }
Example #8
0
        private void readBase5()
        {
            int classID = reader.ReadInt32();

            if (fileGen > 15)//5.5.0 and up
            {
                reader.ReadByte();
                int type1;
                if ((type1 = reader.ReadInt16()) >= 0)
                {
                    type1 = -1 - type1;
                }
                else
                {
                    type1 = classID;
                }
                classIDs.Add(new[] { type1, classID });
                if (classID == 114)
                {
                    reader.Position += 16;
                }
                classID = type1;
            }
            else if (classID < 0)
            {
                reader.Position += 16;
            }
            reader.Position += 16;

            if (baseDefinitions)
            {
                int varCount   = reader.ReadInt32();
                int stringSize = reader.ReadInt32();

                reader.Position += varCount * 24;
                using (var stringReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringSize))))
                {
                    string className = "";
                    var    classVar  = new List <ClassMember>();
                    //build Class Structures
                    reader.Position -= varCount * 24 + stringSize;
                    for (int i = 0; i < varCount; i++)
                    {
                        ushort num0    = reader.ReadUInt16();
                        byte   level   = reader.ReadByte();
                        bool   isArray = reader.ReadBoolean();

                        ushort varTypeIndex = reader.ReadUInt16();
                        ushort test         = reader.ReadUInt16();
                        string varTypeStr;
                        if (test == 0) //varType is an offset in the string block
                        {
                            stringReader.BaseStream.Position = varTypeIndex;
                            varTypeStr = stringReader.ReadStringToNull();
                        }
                        else //varType is an index in an internal strig array
                        {
                            varTypeStr = baseStrings.ContainsKey(varTypeIndex) ? baseStrings[varTypeIndex] : varTypeIndex.ToString();
                        }

                        ushort varNameIndex = reader.ReadUInt16();
                        test = reader.ReadUInt16();
                        string varNameStr;
                        if (test == 0)
                        {
                            stringReader.BaseStream.Position = varNameIndex;
                            varNameStr = stringReader.ReadStringToNull();
                        }
                        else
                        {
                            varNameStr = baseStrings.ContainsKey(varNameIndex) ? baseStrings[varNameIndex] : varNameIndex.ToString();
                        }

                        int size  = reader.ReadInt32();
                        int index = reader.ReadInt32();
                        int flag  = reader.ReadInt32();

                        if (index == 0)
                        {
                            className = varTypeStr + " " + varNameStr;
                        }
                        else
                        {
                            classVar.Add(new ClassMember
                            {
                                Level = level - 1,
                                Type  = varTypeStr,
                                Name  = varNameStr,
                                Size  = size,
                                Flag  = flag
                            });
                        }
                    }
                    reader.Position += stringSize;
                    var aClass = new ClassStruct {
                        ID = classID, Text = className, members = classVar
                    };
                    aClass.SubItems.Add(classID.ToString());
                    ClassStructures[classID] = aClass;
                }
            }
        }
Example #9
0
        public SerializedFile(AssetsManager assetsManager, string fullName, EndianBinaryReader reader)
        {
            this.assetsManager = assetsManager;
            this.reader        = reader;
            this.fullName      = fullName;
            fileName           = Path.GetFileName(fullName);

            //ReadHeader
            header = new SerializedFileHeader();
            header.m_MetadataSize = reader.ReadUInt32();
            header.m_FileSize     = reader.ReadUInt32();
            header.m_Version      = reader.ReadUInt32();
            header.m_DataOffset   = reader.ReadUInt32();

            if (header.m_Version >= 9)
            {
                header.m_Endianess = reader.ReadByte();
                header.m_Reserved  = reader.ReadBytes(3);
                m_FileEndianess    = (EndianType)header.m_Endianess;
            }
            else
            {
                reader.Position = header.m_FileSize - header.m_MetadataSize;
                m_FileEndianess = (EndianType)reader.ReadByte();
            }

            if (header.m_Version >= 22)
            {
                header.m_MetadataSize = reader.ReadUInt32();
                header.m_FileSize     = reader.ReadInt64();
                header.m_DataOffset   = reader.ReadInt64();
                reader.ReadInt64(); // unknown
            }

            //ReadMetadata
            if (m_FileEndianess == EndianType.LittleEndian)
            {
                reader.endian = EndianType.LittleEndian;
            }
            if (header.m_Version >= 7)
            {
                unityVersion = reader.ReadStringToNull();
                SetVersion(unityVersion);
            }
            if (header.m_Version >= 8)
            {
                m_TargetPlatform = (BuildTarget)reader.ReadInt32();
                if (!Enum.IsDefined(typeof(BuildTarget), m_TargetPlatform))
                {
                    m_TargetPlatform = BuildTarget.UnknownPlatform;
                }
            }
            if (header.m_Version >= 13)
            {
                m_EnableTypeTree = reader.ReadBoolean();
            }

            //ReadTypes
            int typeCount = reader.ReadInt32();

            m_Types = new List <SerializedType>(typeCount);
            for (int i = 0; i < typeCount; i++)
            {
                m_Types.Add(ReadSerializedType());
            }

            var bigIDEnabled = 0;

            if (header.m_Version >= 7 && header.m_Version < 14)
            {
                bigIDEnabled = reader.ReadInt32();
            }

            //ReadObjects
            int objectCount = reader.ReadInt32();

            m_Objects  = new List <ObjectInfo>(objectCount);
            Objects    = new List <Object>(objectCount);
            ObjectsDic = new Dictionary <long, Object>(objectCount);
            for (int i = 0; i < objectCount; i++)
            {
                var objectInfo = new ObjectInfo();
                if (bigIDEnabled != 0)
                {
                    objectInfo.m_PathID = reader.ReadInt64();
                }
                else if (header.m_Version < 14)
                {
                    objectInfo.m_PathID = reader.ReadInt32();
                }
                else
                {
                    reader.AlignStream();
                    objectInfo.m_PathID = reader.ReadInt64();
                }

                if (header.m_Version >= 22)
                {
                    objectInfo.byteStart = reader.ReadInt64();
                }
                else
                {
                    objectInfo.byteStart = reader.ReadUInt32();
                }

                objectInfo.byteStart += header.m_DataOffset;
                objectInfo.byteSize   = reader.ReadUInt32();
                objectInfo.typeID     = reader.ReadInt32();
                if (header.m_Version < 16)
                {
                    objectInfo.classID        = reader.ReadUInt16();
                    objectInfo.serializedType = m_Types.Find(x => x.classID == objectInfo.typeID);
                }
                else
                {
                    var type = m_Types[objectInfo.typeID];
                    objectInfo.serializedType = type;
                    objectInfo.classID        = type.classID;
                }
                if (header.m_Version < 11)
                {
                    var isDestroyed = reader.ReadUInt16();
                }
                if (header.m_Version >= 11 && header.m_Version < 17)
                {
                    var m_ScriptTypeIndex = reader.ReadInt16();
                    if (objectInfo.serializedType != null)
                    {
                        objectInfo.serializedType.m_ScriptTypeIndex = m_ScriptTypeIndex;
                    }
                }
                if (header.m_Version == 15 || header.m_Version == 16)
                {
                    var stripped = reader.ReadByte();
                }
                m_Objects.Add(objectInfo);
            }

            if (header.m_Version >= 11)
            {
                int scriptCount = reader.ReadInt32();
                m_ScriptTypes = new List <LocalSerializedObjectIdentifier>(scriptCount);
                for (int i = 0; i < scriptCount; i++)
                {
                    var m_ScriptType = new LocalSerializedObjectIdentifier();
                    m_ScriptType.localSerializedFileIndex = reader.ReadInt32();
                    if (header.m_Version < 14)
                    {
                        m_ScriptType.localIdentifierInFile = reader.ReadInt32();
                    }
                    else
                    {
                        reader.AlignStream();
                        m_ScriptType.localIdentifierInFile = reader.ReadInt64();
                    }
                    m_ScriptTypes.Add(m_ScriptType);
                }
            }

            int externalsCount = reader.ReadInt32();

            m_Externals = new List <FileIdentifier>(externalsCount);
            for (int i = 0; i < externalsCount; i++)
            {
                var m_External = new FileIdentifier();
                if (header.m_Version >= 6)
                {
                    var tempEmpty = reader.ReadStringToNull();
                }
                if (header.m_Version >= 5)
                {
                    m_External.guid = new Guid(reader.ReadBytes(16));
                    m_External.type = reader.ReadInt32();
                }
                m_External.pathName = reader.ReadStringToNull();
                m_External.fileName = Path.GetFileName(m_External.pathName);
                m_Externals.Add(m_External);
            }

            if (header.m_Version >= 20)
            {
                int refTypesCount = reader.ReadInt32();
                m_RefTypes = new List <SerializedType>(refTypesCount);
                for (int i = 0; i < refTypesCount; i++)
                {
                    m_RefTypes.Add(ReadSerializedType());
                }
            }

            if (header.m_Version >= 5)
            {
                var userInformation = reader.ReadStringToNull();
            }

            //reader.AlignStream(16);
        }
Example #10
0
        public ClipMuscleConstant(EndianBinaryReader reader, int[] version)
        {
            m_DeltaPose = new HumanPose(reader, version);
            m_StartX    = new xform(reader, version);
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 5))//5.5 and up
            {
                m_StopX = new xform(reader, version);
            }
            m_LeftFootStartX  = new xform(reader, version);
            m_RightFootStartX = new xform(reader, version);
            if (version[0] < 5)//5.0 down
            {
                m_MotionStartX = new xform(reader, version);
                m_MotionStopX  = new xform(reader, version);
            }
            m_AverageSpeed        = version[0] > 5 || (version[0] == 5 && version[1] >= 4) ? (object)reader.ReadVector3() : (object)reader.ReadVector4();//5.4 and up
            m_Clip                = new Clip(reader, version);
            m_StartTime           = reader.ReadSingle();
            m_StopTime            = reader.ReadSingle();
            m_OrientationOffsetY  = reader.ReadSingle();
            m_Level               = reader.ReadSingle();
            m_CycleOffset         = reader.ReadSingle();
            m_AverageAngularSpeed = reader.ReadSingle();

            int numIndices = reader.ReadInt32();

            m_IndexArray = reader.ReadInt32Array(numIndices);

            int numDeltas = reader.ReadInt32();

            m_ValueArrayDelta = new List <ValueDelta>(numDeltas);
            for (int i = 0; i < numDeltas; i++)
            {
                m_ValueArrayDelta.Add(new ValueDelta(reader));
            }
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 3))//5.3 and up
            {
                m_ValueArrayReferencePose = reader.ReadSingleArray(reader.ReadInt32());
            }

            m_Mirror               = reader.ReadBoolean();
            m_LoopTime             = reader.ReadBoolean();
            m_LoopBlend            = reader.ReadBoolean();
            m_LoopBlendOrientation = reader.ReadBoolean();
            m_LoopBlendPositionY   = reader.ReadBoolean();
            m_LoopBlendPositionXZ  = reader.ReadBoolean();
            if (version[0] > 5 || (version[0] == 5 && version[1] >= 5))//5.5 and up
            {
                m_StartAtOrigin = reader.ReadBoolean();
            }
            m_KeepOriginalOrientation = reader.ReadBoolean();
            m_KeepOriginalPositionY   = reader.ReadBoolean();
            m_KeepOriginalPositionXZ  = reader.ReadBoolean();
            m_HeightFromFeet          = reader.ReadBoolean();
            reader.AlignStream(4);
        }
Example #11
0
        public static void ReadClassStruct(StringBuilder sb, List <ClassMember> members, EndianBinaryReader reader)
        {
            for (int i = 0; i < members.Count; i++)
            {
                var    member     = members[i];
                var    level      = member.Level;
                var    varTypeStr = member.Type;
                var    varNameStr = member.Name;
                object value      = null;
                var    align      = (member.Flag & 0x4000) != 0;
                var    append     = true;
                if (member.alignBefore)
                {
                    reader.AlignStream(4);
                }
                switch (varTypeStr)
                {
                case "SInt8":
                    value = reader.ReadSByte();
                    break;

                case "UInt8":
                    value = reader.ReadByte();
                    break;

                case "short":
                case "SInt16":
                    value = reader.ReadInt16();
                    break;

                case "UInt16":
                case "unsigned short":
                    value = reader.ReadUInt16();
                    break;

                case "int":
                case "SInt32":
                    value = reader.ReadInt32();
                    break;

                case "UInt32":
                case "unsigned int":
                case "Type*":
                    value = reader.ReadUInt32();
                    break;

                case "long long":
                case "SInt64":
                    value = reader.ReadInt64();
                    break;

                case "UInt64":
                case "unsigned long long":
                    value = reader.ReadUInt64();
                    break;

                case "float":
                    value = reader.ReadSingle();
                    break;

                case "double":
                    value = reader.ReadDouble();
                    break;

                case "bool":
                    value = reader.ReadBoolean();
                    break;

                case "string":
                    append = false;
                    var str = reader.ReadAlignedString();
                    sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str);
                    i += 3;    //skip
                    break;

                case "Array":
                {
                    append = false;
                    if ((members[i - 1].Flag & 0x4000) != 0)
                    {
                        align = true;
                    }
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    var size = reader.ReadInt32();
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                    var array = ReadArray(members, level, i);
                    for (int j = 0; j < size; j++)
                    {
                        sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 1)), j);
                        ReadClassStruct(sb, array, reader);
                    }
                    i += array.Count + 1;        //skip
                    break;
                }

                case "TypelessData":
                {
                    append = false;
                    var size = reader.ReadInt32();
                    reader.ReadBytes(size);
                    i += 2;
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                    break;
                }

                default:
                    append = false;
                    if (align)
                    {
                        align = false;
                        SetAlignBefore(members, level, i + 1);
                    }
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    break;
                }
                if (append)
                {
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value);
                }
                if (align)
                {
                    reader.AlignStream(4);
                }
            }
        }
Example #12
0
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            assetsFileReader = reader;
            filePath         = fullName;
            fileName         = Path.GetFileName(fullName);
            upperFileName    = fileName.ToUpper();
            try
            {
                int tableSize = assetsFileReader.ReadInt32();
                int dataEnd   = assetsFileReader.ReadInt32();
                fileGen = assetsFileReader.ReadInt32();
                uint dataOffset = assetsFileReader.ReadUInt32();
                sharedAssetsList[0].fileName = fileName; //reference itself because sharedFileIDs start from 1

                switch (fileGen)
                {
                case 6:     //2.5.0 - 2.6.1
                {
                    assetsFileReader.Position  = (dataEnd - tableSize);
                    assetsFileReader.Position += 1;
                    break;
                }

                case 7:     //3.0.0 beta
                {
                    assetsFileReader.Position  = (dataEnd - tableSize);
                    assetsFileReader.Position += 1;
                    m_Version = assetsFileReader.ReadStringToNull();
                    break;
                }

                case 8:     //3.0.0 - 3.4.2
                {
                    assetsFileReader.Position  = (dataEnd - tableSize);
                    assetsFileReader.Position += 1;
                    m_Version = assetsFileReader.ReadStringToNull();
                    platform  = assetsFileReader.ReadInt32();
                    break;
                }

                case 9:                             //3.5.0 - 4.6.x
                {
                    assetsFileReader.Position += 4; //azero
                    m_Version = assetsFileReader.ReadStringToNull();
                    platform  = assetsFileReader.ReadInt32();
                    break;
                }

                case 14:                            //5.0.0 beta and final
                case 15:                            //5.0.1 - 5.4
                case 16:                            //??.. no sure
                case 17:                            //5.5.0 and up
                {
                    assetsFileReader.Position += 4; //azero
                    m_Version       = assetsFileReader.ReadStringToNull();
                    platform        = assetsFileReader.ReadInt32();
                    baseDefinitions = assetsFileReader.ReadBoolean();
                    break;
                }

                default:
                {
                    //MessageBox.Show("Unsupported version!" + fileGen, "AssetStudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                }

                if (platform > 255 || platform < 0)
                {
                    byte[] b32 = BitConverter.GetBytes(platform);
                    Array.Reverse(b32);
                    platform = BitConverter.ToInt32(b32, 0);
                    assetsFileReader.endian = EndianType.LittleEndian;
                }

                platformStr = Enum.IsDefined(typeof(BuildTarget), platform) ? ((BuildTarget)platform).ToString() : "Unknown Platform";

                int baseCount = assetsFileReader.ReadInt32();
                for (int i = 0; i < baseCount; i++)
                {
                    if (fileGen < 14)
                    {
                        int    classID  = assetsFileReader.ReadInt32();
                        string baseType = assetsFileReader.ReadStringToNull();
                        string baseName = assetsFileReader.ReadStringToNull();
                        assetsFileReader.Position += 20;
                        int memberCount = assetsFileReader.ReadInt32();

                        var cb = new List <ClassMember>();
                        for (int m = 0; m < memberCount; m++)
                        {
                            readBase(cb, 1);
                        }

                        var aClass = new ClassStruct {
                            ID = classID, Text = (baseType + " " + baseName), members = cb
                        };
                        aClass.SubItems.Add(classID.ToString());
                        ClassStructures.Add(classID, aClass);
                    }
                    else
                    {
                        readBase5();
                    }
                }

                if (fileGen >= 7 && fileGen < 14)
                {
                    assetsFileReader.Position += 4; //azero
                }

                int assetCount = assetsFileReader.ReadInt32();

                #region asset preload table
                string assetIDfmt = "D" + assetCount.ToString().Length; //format for unique ID

                for (int i = 0; i < assetCount; i++)
                {
                    //each table entry is aligned individually, not the whole table
                    if (fileGen >= 14)
                    {
                        assetsFileReader.AlignStream(4);
                    }

                    AssetPreloadData asset = new AssetPreloadData();
                    asset.m_PathID = fileGen < 14 ? assetsFileReader.ReadInt32() : assetsFileReader.ReadInt64();
                    asset.Offset   = assetsFileReader.ReadUInt32();
                    asset.Offset  += dataOffset;
                    asset.Size     = assetsFileReader.ReadInt32();
                    if (fileGen > 15)
                    {
                        int index = assetsFileReader.ReadInt32();
                        asset.Type1 = classIDs[index][0];
                        asset.Type2 = classIDs[index][1];
                    }
                    else
                    {
                        asset.Type1 = assetsFileReader.ReadInt32();
                        asset.Type2 = assetsFileReader.ReadUInt16();
                        assetsFileReader.Position += 2;
                    }
                    if (fileGen == 15)
                    {
                        byte unknownByte = assetsFileReader.ReadByte();
                        //this is a single byte, not an int32
                        //the next entry is aligned after this
                        //but not the last!
                    }

                    if (Enum.IsDefined(typeof(ClassIDReference), asset.Type2))
                    {
                        asset.Type       = (ClassIDReference)asset.Type2;
                        asset.TypeString = asset.Type.ToString();
                    }
                    else
                    {
                        asset.Type       = ClassIDReference.UnknownType;
                        asset.TypeString = "UnknownType " + asset.Type2;
                    }

                    asset.uniqueID = i.ToString(assetIDfmt);

                    asset.fullSize   = asset.Size;
                    asset.sourceFile = this;

                    preloadTable.Add(asset.m_PathID, asset);

                    #region read BuildSettings to get version for version 2.x files
                    if (asset.Type == ClassIDReference.BuildSettings && fileGen == 6)
                    {
                        long nextAsset = assetsFileReader.Position;

                        BuildSettings BSettings = new BuildSettings(asset);
                        m_Version = BSettings.m_Version;

                        assetsFileReader.Position = nextAsset;
                    }
                    #endregion
                }
                #endregion

                buildType = Regex.Replace(m_Version, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                version   = Regex.Matches(m_Version, @"\d").Cast <Match>().Select(m => int.Parse(m.Value)).ToArray();
                if (version[0] == 2 && version[1] == 0 && version[2] == 1 && version[3] == 7)//2017.x
                {
                    var nversion = new int[version.Length - 3];
                    nversion[0] = 2017;
                    Array.Copy(version, 4, nversion, 1, version.Length - 4);
                    version = nversion;
                }
                if (fileGen >= 14)
                {
                    //this looks like a list of assets that need to be preloaded in memory before anytihng else
                    int someCount = assetsFileReader.ReadInt32();
                    for (int i = 0; i < someCount; i++)
                    {
                        int num1 = assetsFileReader.ReadInt32();
                        assetsFileReader.AlignStream(4);
                        long m_PathID = assetsFileReader.ReadInt64();
                    }
                }

                int sharedFileCount = assetsFileReader.ReadInt32();
                for (int i = 0; i < sharedFileCount; i++)
                {
                    var shared = new SharedAssets();
                    shared.aName = assetsFileReader.ReadStringToNull();
                    assetsFileReader.Position += 20;
                    var sharedFilePath = assetsFileReader.ReadStringToNull(); //relative path
                    shared.fileName = Path.GetFileName(sharedFilePath);
                    sharedAssetsList.Add(shared);
                }
                valid = true;
            }
            catch
            {
            }
        }
Example #13
0
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            this.reader   = reader;
            filePath      = fullName;
            fileName      = Path.GetFileName(fullName);
            upperFileName = fileName.ToUpper();
            try
            {
                //SerializedFile::ReadHeader
                header = new SerializedFileHeader();
                header.m_MetadataSize = reader.ReadUInt32();
                header.m_FileSize     = reader.ReadUInt32();
                header.m_Version      = reader.ReadUInt32();
                header.m_DataOffset   = reader.ReadUInt32();

                if (header.m_Version >= 9)
                {
                    header.m_Endianess = reader.ReadByte();
                    header.m_Reserved  = reader.ReadBytes(3);
                    m_FileEndianess    = (EndianType)header.m_Endianess;
                }
                else
                {
                    reader.Position = header.m_FileSize - header.m_MetadataSize;
                    m_FileEndianess = (EndianType)reader.ReadByte();
                }

                //SerializedFile::ReadMetadata
                if (m_FileEndianess == EndianType.LittleEndian)
                {
                    reader.endian = EndianType.LittleEndian;
                }
                if (header.m_Version >= 7)
                {
                    unityVersion = reader.ReadStringToNull();
                }
                if (header.m_Version >= 8)
                {
                    m_TargetPlatform = (BuildTarget)reader.ReadInt32();
                    if (!Enum.IsDefined(typeof(BuildTarget), m_TargetPlatform))
                    {
                        m_TargetPlatform = BuildTarget.UnknownPlatform;
                    }
                }
                platformStr = m_TargetPlatform.ToString();
                if (header.m_Version >= 13)
                {
                    m_EnableTypeTree = reader.ReadBoolean();
                }

                //Read types
                int typeCount = reader.ReadInt32();
                m_Types = new List <SerializedType>(typeCount);
                for (int i = 0; i < typeCount; i++)
                {
                    m_Types.Add(ReadSerializedType());
                }

                if (header.m_Version >= 7 && header.m_Version < 14)
                {
                    var bigIDEnabled = reader.ReadInt32();
                }

                //Read Objects
                int objectCount = reader.ReadInt32();

                var assetIDfmt = "D" + objectCount.ToString().Length; //format for unique ID

                m_Objects = new Dictionary <long, ObjectInfo>(objectCount);
                for (int i = 0; i < objectCount; i++)
                {
                    var objectInfo = new ObjectInfo();
                    if (header.m_Version < 14)
                    {
                        objectInfo.m_PathID = reader.ReadInt32();
                    }
                    else
                    {
                        reader.AlignStream(4);
                        objectInfo.m_PathID = reader.ReadInt64();
                    }
                    objectInfo.byteStart  = reader.ReadUInt32();
                    objectInfo.byteStart += header.m_DataOffset;
                    objectInfo.byteSize   = reader.ReadUInt32();
                    objectInfo.typeID     = reader.ReadInt32();
                    if (header.m_Version < 16)
                    {
                        objectInfo.classID        = reader.ReadUInt16();
                        objectInfo.serializedType = m_Types.Find(x => x.classID == objectInfo.typeID);
                        objectInfo.isDestroyed    = reader.ReadUInt16();
                    }
                    else
                    {
                        var type = m_Types[objectInfo.typeID];
                        objectInfo.serializedType = type;
                        objectInfo.classID        = type.classID;
                    }
                    if (header.m_Version == 15 || header.m_Version == 16)
                    {
                        var stripped = reader.ReadByte();
                    }
                    m_Objects.Add(objectInfo.m_PathID, objectInfo);

                    //Create AssetPreloadData
                    var asset = new AssetPreloadData(this, objectInfo, i.ToString(assetIDfmt));
                    preloadTable.Add(asset.m_PathID, asset);

                    #region read BuildSettings to get version for version 2.x files
                    if (asset.Type == ClassIDType.BuildSettings && header.m_Version == 6)
                    {
                        var nextAsset = reader.Position;

                        var BSettings = new BuildSettings(asset);
                        unityVersion = BSettings.m_Version;

                        reader.Position = nextAsset;
                    }
                    #endregion
                }

                if (header.m_Version >= 11)
                {
                    int scriptCount = reader.ReadInt32();
                    m_ScriptTypes = new List <LocalSerializedObjectIdentifier>(scriptCount);
                    for (int i = 0; i < scriptCount; i++)
                    {
                        var m_ScriptType = new LocalSerializedObjectIdentifier();
                        m_ScriptType.localSerializedFileIndex = reader.ReadInt32();
                        if (header.m_Version < 14)
                        {
                            m_ScriptType.localIdentifierInFile = reader.ReadInt32();
                        }
                        else
                        {
                            reader.AlignStream(4);
                            m_ScriptType.localIdentifierInFile = reader.ReadInt64();
                        }
                        m_ScriptTypes.Add(m_ScriptType);
                    }
                }

                int externalsCount = reader.ReadInt32();
                m_Externals = new List <FileIdentifier>(externalsCount);
                for (int i = 0; i < externalsCount; i++)
                {
                    var m_External = new FileIdentifier();
                    if (header.m_Version >= 6)
                    {
                        var tempEmpty = reader.ReadStringToNull();
                    }
                    if (header.m_Version >= 5)
                    {
                        m_External.guid = new Guid(reader.ReadBytes(16));
                        m_External.type = reader.ReadInt32();
                    }
                    m_External.pathName = reader.ReadStringToNull();
                    m_External.fileName = Path.GetFileName(m_External.pathName);
                    m_Externals.Add(m_External);
                }

                if (header.m_Version >= 5)
                {
                    //var userInformation = reader.ReadStringToNull();
                }

                buildType = Regex.Replace(unityVersion, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                var firstVersion = int.Parse(unityVersion.Split('.')[0]);
                version = Regex.Matches(unityVersion, @"\d").Cast <Match>().Select(m => int.Parse(m.Value)).ToArray();
                if (firstVersion > 5)//2017 and up
                {
                    var nversion = new int[version.Length - 3];
                    nversion[0] = firstVersion;
                    Array.Copy(version, 4, nversion, 1, version.Length - 4);
                    version = nversion;
                }

                valid = true;
            }
            catch
            {
            }
        }
Example #14
0
        public StateConstant(EndianBinaryReader reader, int[] version)
        {
            int numTransistions = reader.ReadInt32();

            m_TransitionConstantArray = new TransitionConstant[numTransistions];
            for (int i = 0; i < numTransistions; i++)
            {
                m_TransitionConstantArray[i] = new TransitionConstant(reader, version);
            }

            int numBlendIndices = reader.ReadInt32();

            m_BlendTreeConstantIndexArray = new int[numBlendIndices];
            for (int i = 0; i < numBlendIndices; i++)
            {
                m_BlendTreeConstantIndexArray[i] = reader.ReadInt32();
            }

            if (version[0] < 5) //5.0 down
            {
                int numInfos = reader.ReadInt32();
                m_LeafInfoArray = new LeafInfoConstant[numInfos];
                for (int i = 0; i < numInfos; i++)
                {
                    m_LeafInfoArray[i] = new LeafInfoConstant(reader);
                }
            }

            int numBlends = reader.ReadInt32();

            m_BlendTreeConstantArray = new BlendTreeConstant[numBlends];
            for (int i = 0; i < numBlends; i++)
            {
                m_BlendTreeConstantArray[i] = new BlendTreeConstant(reader, version);
            }

            m_NameID = reader.ReadUInt32();
            m_PathID = reader.ReadUInt32();
            if (version[0] >= 5) //5.0 and up
            {
                m_FullPathID = reader.ReadUInt32();
            }

            m_TagID = reader.ReadUInt32();
            if (version[0] >= 5) //5.0 and up
            {
                m_SpeedParamID       = reader.ReadUInt32();
                m_MirrorParamID      = reader.ReadUInt32();
                m_CycleOffsetParamID = reader.ReadUInt32();
            }

            if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up
            {
                var m_TimeParamID = reader.ReadUInt32();
            }

            m_Speed       = reader.ReadSingle();
            m_CycleOffset = reader.ReadSingle();
            m_IKOnFeet    = reader.ReadBoolean();
            if (version[0] >= 5) //5.0 and up
            {
                m_WriteDefaultValues = reader.ReadBoolean();
            }

            m_Loop   = reader.ReadBoolean();
            m_Mirror = reader.ReadBoolean();
            reader.AlignStream(4);
        }
Example #15
0
 public BlendDirectDataConstant(EndianBinaryReader reader)
 {
     m_ChildBlendEventIDArray = reader.ReadUInt32Array(reader.ReadInt32());
     m_NormalizedBlendValues  = reader.ReadBoolean();
     reader.AlignStream(4);
 }
Example #16
0
        public Human(EndianBinaryReader reader, int[] version)
        {
            m_RootX        = new xform(reader, version);
            m_Skeleton     = new Skeleton(reader, version);
            m_SkeletonPose = new SkeletonPose(reader, version);
            m_LeftHand     = new Hand(reader);
            m_RightHand    = new Hand(reader);

            if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down
            {
                int numHandles = reader.ReadInt32();
                m_Handles = new List <Handle>(numHandles);
                for (int i = 0; i < numHandles; i++)
                {
                    m_Handles.Add(new Handle(reader, version));
                }

                int numColliders = reader.ReadInt32();
                m_ColliderArray = new List <Collider>(numColliders);
                for (int i = 0; i < numColliders; i++)
                {
                    m_ColliderArray.Add(new Collider(reader, version));
                }
            }

            int numIndexes = reader.ReadInt32();

            m_HumanBoneIndex = new List <int>(numIndexes);
            for (int i = 0; i < numIndexes; i++)
            {
                m_HumanBoneIndex.Add(reader.ReadInt32());
            }

            int numMasses = reader.ReadInt32();

            m_HumanBoneMass = new List <float>(numMasses);
            for (int i = 0; i < numMasses; i++)
            {
                m_HumanBoneMass.Add(reader.ReadSingle());
            }

            if (version[0] < 2018 || (version[0] == 2018 && version[1] < 2)) //2018.2 down
            {
                int numColliderIndexes = reader.ReadInt32();
                m_ColliderIndex = new List <int>(numColliderIndexes);
                for (int i = 0; i < numColliderIndexes; i++)
                {
                    m_ColliderIndex.Add(reader.ReadInt32());
                }
            }

            m_Scale         = reader.ReadSingle();
            m_ArmTwist      = reader.ReadSingle();
            m_ForeArmTwist  = reader.ReadSingle();
            m_UpperLegTwist = reader.ReadSingle();
            m_LegTwist      = reader.ReadSingle();
            m_ArmStretch    = reader.ReadSingle();
            m_LegStretch    = reader.ReadSingle();
            m_FeetSpacing   = reader.ReadSingle();
            m_HasLeftHand   = reader.ReadBoolean();
            m_HasRightHand  = reader.ReadBoolean();
            m_HasTDoF       = reader.ReadBoolean();
            reader.AlignStream(4);
        }
Example #17
0
        private void ReadTypeTree5()
        {
            int classID = reader.ReadInt32();

            if (header.m_Version > 15)//5.5.0 and up
            {
                reader.ReadByte();
                int typeID = reader.ReadInt16();
                if (typeID >= 0)
                {
                    typeID = -1 - typeID;
                }
                else
                {
                    typeID = classID;
                }
                classIDs.Add(new[] { typeID, classID });
                if (classID == 114)
                {
                    reader.Position += 16;
                }
                classID = typeID;
            }
            else if (classID < 0)
            {
                reader.Position += 16;
            }
            reader.Position += 16;

            if (serializedTypeTrees)
            {
                int varCount   = reader.ReadInt32();
                int stringSize = reader.ReadInt32();

                reader.Position += varCount * 24;
                using (var stringReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringSize))))
                {
                    var typeTreeList = new List <TypeTree>();
                    reader.Position -= varCount * 24 + stringSize;
                    for (int i = 0; i < varCount; i++)
                    {
                        var typeTree = new TypeTree();
                        typeTreeList.Add(typeTree);
                        typeTree.m_Version = reader.ReadUInt16();
                        typeTree.m_Depth   = reader.ReadByte();
                        typeTree.m_IsArray = reader.ReadBoolean() ? 1 : 0;

                        ushort varTypeIndex = reader.ReadUInt16();
                        ushort test         = reader.ReadUInt16();
                        if (test == 0) //varType is an offset in the string block
                        {
                            stringReader.BaseStream.Position = varTypeIndex;
                            typeTree.m_Type = stringReader.ReadStringToNull();
                        }
                        else //varType is an index in an internal strig array
                        {
                            typeTree.m_Type = baseStrings.ContainsKey(varTypeIndex) ? baseStrings[varTypeIndex] : varTypeIndex.ToString();
                        }

                        ushort varNameIndex = reader.ReadUInt16();
                        test = reader.ReadUInt16();
                        if (test == 0)
                        {
                            stringReader.BaseStream.Position = varNameIndex;
                            typeTree.m_Name = stringReader.ReadStringToNull();
                        }
                        else
                        {
                            typeTree.m_Name = baseStrings.ContainsKey(varNameIndex) ? baseStrings[varNameIndex] : varNameIndex.ToString();
                        }

                        typeTree.m_ByteSize = reader.ReadInt32();
                        typeTree.m_Index    = reader.ReadInt32();
                        typeTree.m_MetaFlag = reader.ReadInt32();
                    }
                    reader.Position += stringSize;
                    m_Type[classID]  = typeTreeList;
                }
            }
        }
Example #18
0
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            this.reader   = reader;
            filePath      = fullName;
            fileName      = Path.GetFileName(fullName);
            upperFileName = fileName.ToUpper();
            try
            {
                //SerializedFile::ReadHeader
                header = new SerializedFileHeader();
                header.m_MetadataSize = reader.ReadUInt32();
                header.m_FileSize     = reader.ReadUInt32();
                header.m_Version      = reader.ReadUInt32();
                header.m_DataOffset   = reader.ReadUInt32();

                if (header.m_Version >= 9)
                {
                    header.m_Endianess = reader.ReadByte();
                    header.m_Reserved  = reader.ReadBytes(3);
                    m_FileEndianess    = (EndianType)header.m_Endianess;
                }
                else
                {
                    reader.Position = header.m_FileSize - header.m_MetadataSize;
                    m_FileEndianess = (EndianType)reader.ReadByte();
                }

                //SerializedFile::ReadMetadata
                if (m_FileEndianess == EndianType.LittleEndian)
                {
                    reader.endian = EndianType.LittleEndian;
                }
                if (header.m_Version >= 7)
                {
                    unityVersion = reader.ReadStringToNull();
                }
                if (header.m_Version >= 8)
                {
                    m_TargetPlatform = (BuildTarget)reader.ReadInt32();
                    if (!Enum.IsDefined(typeof(BuildTarget), m_TargetPlatform))
                    {
                        m_TargetPlatform = BuildTarget.UnknownPlatform;
                    }
                }
                platformStr = m_TargetPlatform.ToString();
                if (header.m_Version >= 14)
                {
                    serializedTypeTrees = reader.ReadBoolean();
                }

                // Read	types
                int typeCount = reader.ReadInt32();
                for (int i = 0; i < typeCount; i++)
                {
                    if (header.m_Version < 14)
                    {
                        int classID      = reader.ReadInt32();
                        var typeTreeList = new List <TypeTree>();
                        ReadTypeTree(typeTreeList, 0);
                        m_Type.Add(classID, typeTreeList);
                    }
                    else
                    {
                        ReadTypeTree5();
                    }
                }

                if (header.m_Version >= 7 && header.m_Version < 14)
                {
                    var bigIDEnabled = reader.ReadInt32();
                }

                // Read Objects
                int objectCount = reader.ReadInt32();

                string assetIDfmt = "D" + objectCount.ToString().Length; //format for unique ID

                for (int i = 0; i < objectCount; i++)
                {
                    //each table entry is aligned individually, not the whole table
                    if (header.m_Version >= 14)
                    {
                        reader.AlignStream(4);
                    }

                    AssetPreloadData asset = new AssetPreloadData();
                    asset.m_PathID = header.m_Version < 14 ? reader.ReadInt32() : reader.ReadInt64();
                    asset.Offset   = reader.ReadUInt32();
                    asset.Offset  += header.m_DataOffset;
                    asset.Size     = reader.ReadInt32();
                    if (header.m_Version > 15)
                    {
                        int index = reader.ReadInt32();
                        asset.Type1 = classIDs[index][0];
                        asset.Type2 = classIDs[index][1];
                    }
                    else
                    {
                        asset.Type1      = reader.ReadInt32();
                        asset.Type2      = reader.ReadUInt16();
                        reader.Position += 2;
                    }
                    if (header.m_Version == 15)
                    {
                        byte unknownByte = reader.ReadByte();
                        //this is a single byte, not an int32
                        //the next entry is aligned after this
                        //but not the last!
                    }

                    if (Enum.IsDefined(typeof(ClassIDReference), asset.Type2))
                    {
                        asset.Type       = (ClassIDReference)asset.Type2;
                        asset.TypeString = asset.Type.ToString();
                    }
                    else
                    {
                        asset.Type       = ClassIDReference.UnknownType;
                        asset.TypeString = "UnknownType " + asset.Type2;
                    }

                    asset.uniqueID = i.ToString(assetIDfmt);

                    asset.fullSize   = asset.Size;
                    asset.sourceFile = this;

                    preloadTable.Add(asset.m_PathID, asset);

                    #region read BuildSettings to get version for version 2.x files
                    if (asset.Type == ClassIDReference.BuildSettings && header.m_Version == 6)
                    {
                        long nextAsset = reader.Position;

                        BuildSettings BSettings = new BuildSettings(asset);
                        unityVersion = BSettings.m_Version;

                        reader.Position = nextAsset;
                    }
                    #endregion
                }

                if (header.m_Version >= 14)
                {
                    //this looks like a list of assets that need to be preloaded in memory before anytihng else
                    int someCount = reader.ReadInt32();
                    for (int i = 0; i < someCount; i++)
                    {
                        int num1 = reader.ReadInt32();
                        reader.AlignStream(4);
                        long m_PathID = reader.ReadInt64();
                    }
                }

                sharedAssetsList[0].fileName = fileName; //reference itself because sharedFileIDs start from 1
                int sharedFileCount = reader.ReadInt32();
                for (int i = 0; i < sharedFileCount; i++)
                {
                    var shared = new SharedAssets();
                    shared.aName     = reader.ReadStringToNull();
                    reader.Position += 20;
                    var sharedFilePath = reader.ReadStringToNull(); //relative path
                    shared.fileName = Path.GetFileName(sharedFilePath);
                    sharedAssetsList.Add(shared);
                }

                buildType = Regex.Replace(unityVersion, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                var firstVersion = int.Parse(unityVersion.Split('.')[0]);
                version = Regex.Matches(unityVersion, @"\d").Cast <Match>().Select(m => int.Parse(m.Value)).ToArray();
                if (firstVersion > 5)//2017 and up
                {
                    var nversion = new int[version.Length - 3];
                    nversion[0] = firstVersion;
                    Array.Copy(version, 4, nversion, 1, version.Length - 4);
                    version = nversion;
                }

                valid = true;
            }
            catch
            {
            }
        }
Example #19
0
        private static object ReadValue(List <TypeTree> members, EndianBinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    level      = member.m_Depth;
            var    varTypeStr = member.m_Type;
            object value;
            var    align = (member.m_MetaFlag & 0x4000) != 0;

            switch (varTypeStr)
            {
            case "SInt8":
                value = reader.ReadSByte();
                break;

            case "UInt8":
                value = reader.ReadByte();
                break;

            case "short":
            case "SInt16":
                value = reader.ReadInt16();
                break;

            case "UInt16":
            case "unsigned short":
                value = reader.ReadUInt16();
                break;

            case "int":
            case "SInt32":
                value = reader.ReadInt32();
                break;

            case "UInt32":
            case "unsigned int":
            case "Type*":
                value = reader.ReadUInt32();
                break;

            case "long long":
            case "SInt64":
                value = reader.ReadInt64();
                break;

            case "UInt64":
            case "unsigned long long":
                value = reader.ReadUInt64();
                break;

            case "float":
                value = reader.ReadSingle();
                break;

            case "double":
                value = reader.ReadDouble();
                break;

            case "bool":
                value = reader.ReadBoolean();
                break;

            case "string":
                value = reader.ReadAlignedString();
                i    += 3;
                break;

            case "vector":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var size   = reader.ReadInt32();
                var list   = new List <object>(size);
                var vector = GetMembers(members, level, i);
                i += vector.Count - 1;
                vector.RemoveRange(0, 3);
                for (int j = 0; j < size; j++)
                {
                    int tmp = 0;
                    list.Add(ReadValue(vector, reader, ref tmp));
                }
                value = list;
                break;
            }

            case "map":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var size = reader.ReadInt32();
                var dic  = new List <KeyValuePair <object, object> >(size);
                var map  = GetMembers(members, level, i);
                i += map.Count - 1;
                map.RemoveRange(0, 4);
                var first = GetMembers(map, map[0].m_Depth, 0);
                map.RemoveRange(0, first.Count);
                var second = map;
                for (int j = 0; j < size; j++)
                {
                    int tmp1 = 0;
                    int tmp2 = 0;
                    dic.Add(new KeyValuePair <object, object>(ReadValue(first, reader, ref tmp1), ReadValue(second, reader, ref tmp2)));
                }
                value = dic;
                break;
            }

            case "TypelessData":
            {
                var size = reader.ReadInt32();
                value = reader.ReadBytes(size);
                i    += 2;
                break;
            }

            default:
            {
                if (i != members.Count && members[i + 1].m_Type == "Array")
                {
                    goto case "vector";
                }
                var @class = GetMembers(members, level, i);
                @class.RemoveAt(0);
                i += @class.Count;
                var obj    = new ExpandoObject();
                var objdic = (IDictionary <string, object>)obj;
                for (int j = 0; j < @class.Count; j++)
                {
                    var classmember = @class[j];
                    var name        = classmember.m_Name;
                    objdic[name] = ReadValue(@class, reader, ref j);
                }
                value = obj;
                break;
            }
            }
            if (align)
            {
                reader.AlignStream(4);
            }
            return(value);
        }
Example #20
0
        private static void ReadStringValue(StringBuilder sb, List <TypeTree> members, EndianBinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    level      = member.m_Depth;
            var    varTypeStr = member.m_Type;
            var    varNameStr = member.m_Name;
            object value      = null;
            var    append     = true;
            var    align      = (member.m_MetaFlag & 0x4000) != 0;

            switch (varTypeStr)
            {
            case "SInt8":
                value = reader.ReadSByte();
                break;

            case "UInt8":
                value = reader.ReadByte();
                break;

            case "short":
            case "SInt16":
                value = reader.ReadInt16();
                break;

            case "UInt16":
            case "unsigned short":
                value = reader.ReadUInt16();
                break;

            case "int":
            case "SInt32":
                value = reader.ReadInt32();
                break;

            case "UInt32":
            case "unsigned int":
            case "Type*":
                value = reader.ReadUInt32();
                break;

            case "long long":
            case "SInt64":
                value = reader.ReadInt64();
                break;

            case "UInt64":
            case "unsigned long long":
                value = reader.ReadUInt64();
                break;

            case "float":
                value = reader.ReadSingle();
                break;

            case "double":
                value = reader.ReadDouble();
                break;

            case "bool":
                value = reader.ReadBoolean();
                break;

            case "string":
                append = false;
                var str = reader.ReadAlignedString();
                sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str);
                i += 3;
                break;

            case "vector":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 1)), "Array", "Array");
                var size = reader.ReadInt32();
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level + 1)), "int", "size", size);
                var vector = GetMembers(members, level, i);
                i += vector.Count - 1;
                vector.RemoveRange(0, 3);
                for (int j = 0; j < size; j++)
                {
                    sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 2)), j);
                    int tmp = 0;
                    ReadStringValue(sb, vector, reader, ref tmp);
                }
                break;
            }

            case "map":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 1)), "Array", "Array");
                var size = reader.ReadInt32();
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level + 1)), "int", "size", size);
                var map = GetMembers(members, level, i);
                i += map.Count - 1;
                map.RemoveRange(0, 4);
                var first = GetMembers(map, map[0].m_Depth, 0);
                map.RemoveRange(0, first.Count);
                var second = map;
                for (int j = 0; j < size; j++)
                {
                    sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 2)), j);
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 2)), "pair", "data");
                    int tmp1 = 0;
                    int tmp2 = 0;
                    ReadStringValue(sb, first, reader, ref tmp1);
                    ReadStringValue(sb, second, reader, ref tmp2);
                }
                break;
            }

            case "TypelessData":
            {
                append = false;
                var size = reader.ReadInt32();
                reader.ReadBytes(size);
                i += 2;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                break;
            }

            default:
            {
                if (i != members.Count && members[i + 1].m_Type == "Array")
                {
                    goto case "vector";
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                var @class = GetMembers(members, level, i);
                @class.RemoveAt(0);
                i += @class.Count;
                for (int j = 0; j < @class.Count; j++)
                {
                    ReadStringValue(sb, @class, reader, ref j);
                }
                break;
            }
            }
            if (append)
            {
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value);
            }
            if (align)
            {
                reader.AlignStream(4);
            }
        }