Exemple #1
0
        public AssetsFile(string fileName, EndianStream fileStream)
        {
            //if (memFile != null) { Stream = new EndianStream(memFile, endianType); }
            //else { Stream = new EndianStream(File.OpenRead(fileName), endianType); }
            a_Stream = fileStream;

            filePath = fileName;
            int tableSize = a_Stream.ReadInt32();
            int dataEnd = a_Stream.ReadInt32();
            fileGen = a_Stream.ReadInt32();
            int dataOffset = a_Stream.ReadInt32();
            sharedAssetsList[0].fileName = Path.GetFileName(fileName); //reference itself because sharedFileIDs start from 1

            switch (fileGen)
            {
                case 6://2.5.0 - 2.6.1
                    {
                        a_Stream.Position = (dataEnd - tableSize);
                        a_Stream.Position += 1;
                        break;
                    }
                case 7://3.0.0 beta
                    {
                        a_Stream.Position = (dataEnd - tableSize);
                        a_Stream.Position += 1;
                        m_Version = a_Stream.ReadStringToNull();
                        break;
                    }
                case 8://3.0.0 - 3.4.2
                    {
                        a_Stream.Position = (dataEnd - tableSize);
                        a_Stream.Position += 1;
                        m_Version = a_Stream.ReadStringToNull();
                        platform = a_Stream.ReadInt32();
                        break;
                    }
                case 9://3.5.0 - 4.6.x
                    {
                        a_Stream.Position += 4;//azero
                        m_Version = a_Stream.ReadStringToNull();
                        platform = a_Stream.ReadInt32();
                        break;
                    }
                case 14://5.0.0 beta and final
                case 15://5.0.1 and up
                    {
                        a_Stream.Position += 4;//azero
                        m_Version = a_Stream.ReadStringToNull();
                        platform = a_Stream.ReadInt32();
                        baseDefinitions = a_Stream.ReadBoolean();
                        break;
                    }
                default:
                    {
                        //MessageBox.Show("Unsupported Unity version!", "Unity Studio Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
            }

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

            switch (platform)
            {
                case -2: platformStr = "Unity Package"; break;
                case 4: platformStr = "OSX"; break;
                case 5: platformStr = "PC"; break;
                case 6: platformStr = "Web"; break;
                case 7: platformStr = "Web streamed"; break;
                case 9: platformStr = "iOS"; break;
                case 10: platformStr = "PS3"; break;
                case 11: platformStr = "Xbox 360"; break;
                case 13: platformStr = "Android"; break;
                case 16: platformStr = "Google NaCl"; break;
                case 21: platformStr = "WP8"; break;
                case 25: platformStr = "Linux"; break;
            }

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

                    StringBuilder cb = new StringBuilder();
                    for (int m = 0; m < memberCount; m++) { readBase(cb, 1); }

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

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

            int assetCount = a_Stream.ReadInt32();

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

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

                AssetPreloadData asset = new AssetPreloadData();
                if (fileGen < 14) { asset.m_PathID = a_Stream.ReadInt32(); }
                else { asset.m_PathID = a_Stream.ReadInt64(); }
                asset.Offset = a_Stream.ReadInt32();
                asset.Offset += dataOffset;
                asset.Size = a_Stream.ReadInt32();
                asset.Type1 = a_Stream.ReadInt32();
                asset.Type2 = a_Stream.ReadUInt16();
                a_Stream.Position += 2;
                if (fileGen >= 15)
                {
                    byte unknownByte = a_Stream.ReadByte();
                    //this is a single byte, not an int32
                    //the next entry is aligned after this
                    //but not the last!
                    if (unknownByte != 0)
                    {
                        bool investigate = true;
                    }
                }

                asset.TypeString = asset.Type2.ToString();
                if (UnityClassID.Names[asset.Type2] != null)
                {
                    asset.TypeString = UnityClassID.Names[asset.Type2];
                }

                asset.uniqueID = i.ToString(assetIDfmt);

                asset.exportSize = asset.Size;
                asset.sourceFile = this;

                preloadTable.Add(asset.m_PathID, asset);

                #region read BuildSettings to get version for unity 2.x files
                if (asset.Type2 == 141 && fileGen == 6)
                {
                    long nextAsset = a_Stream.Position;

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

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

            buildType = m_Version.Split(new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries);
            string[] strver = (m_Version.Split(new string[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries));
            version = Array.ConvertAll(strver, int.Parse);

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

            int sharedFileCount = a_Stream.ReadInt32();
            for (int i = 0; i < sharedFileCount; i++)
            {
                UnityShared shared = new UnityShared();
                shared.aName = a_Stream.ReadStringToNull();
                a_Stream.Position += 20;
                string sharedFileName = a_Stream.ReadStringToNull(); //relative path
                shared.fileName = sharedFileName.Replace("/", "\\");
                sharedAssetsList.Add(shared);
            }
        }
Exemple #2
0
        public AssetsFile(string fileName, EndianStream fileStream = null)
        {
            List <UnityShared> list1 = new List <UnityShared> {
                new UnityShared()
            };

            this.sharedAssetsList = list1;
            this.UnityClassID     = new ClassIDReference();
            this.baseDefinitions  = false;
            if (fileStream == null)
            {
                fileStream = new EndianStream(File.OpenRead(fileName), EndianType.BigEndian);
            }
            this.a_Stream = fileStream;
            this.filePath = fileName;
            int num  = this.a_Stream.ReadInt32();
            int num2 = this.a_Stream.ReadInt32();

            this.fileGen = this.a_Stream.ReadInt32();
            int num3 = this.a_Stream.ReadInt32();

            this.sharedAssetsList[0].fileName = Path.GetFileName(fileName);
            switch (this.fileGen)
            {
            case 6:
                this.a_Stream.Position  = num2 - num;
                this.a_Stream.Position += 1L;
                break;

            case 7:
                this.a_Stream.Position  = num2 - num;
                this.a_Stream.Position += 1L;
                this.m_Version          = this.a_Stream.ReadStringToNull();
                break;

            case 8:
                this.a_Stream.Position  = num2 - num;
                this.a_Stream.Position += 1L;
                this.m_Version          = this.a_Stream.ReadStringToNull();
                this.platform           = this.a_Stream.ReadInt32();
                break;

            case 9:
                this.a_Stream.Position += 4L;
                this.m_Version          = this.a_Stream.ReadStringToNull();
                this.platform           = this.a_Stream.ReadInt32();
                break;

            case 10:
            case 11:
            case 12:
            case 13:
                return;

            case 14:
            case 15:
                this.a_Stream.Position += 4L;
                this.m_Version          = this.a_Stream.ReadStringToNull();
                this.platform           = this.a_Stream.ReadInt32();
                this.baseDefinitions    = this.a_Stream.ReadBoolean();
                break;

            default:
                return;
            }
            if ((this.platform > 0xff) || (this.platform < 0))
            {
                byte[] bytes = BitConverter.GetBytes(this.platform);
                Array.Reverse(bytes);
                this.platform        = BitConverter.ToInt32(bytes, 0);
                this.a_Stream.endian = EndianType.LittleEndian;
            }
            switch (this.platform)
            {
            case -2:
                this.platformStr = "Unity Package";
                break;

            case 4:
                this.platformStr = "OSX";
                break;

            case 5:
                this.platformStr = "PC";
                break;

            case 6:
                this.platformStr = "Web";
                break;

            case 7:
                this.platformStr = "Web streamed";
                break;

            case 9:
                this.platformStr = "iOS";
                break;

            case 10:
                this.platformStr = "PS3";
                break;

            case 11:
                this.platformStr = "Xbox 360";
                break;

            case 13:
                this.platformStr = "Android";
                break;

            case 0x10:
                this.platformStr = "Google NaCl";
                break;

            case 0x15:
                this.platformStr = "WP8";
                break;

            case 0x19:
                this.platformStr = "Linux";
                break;
            }
            int num4 = this.a_Stream.ReadInt32();

            for (int i = 0; i < num4; i++)
            {
                if (this.fileGen < 14)
                {
                    int    num10 = this.a_Stream.ReadInt32();
                    string str2  = this.a_Stream.ReadStringToNull();
                    string str3  = this.a_Stream.ReadStringToNull();
                    this.a_Stream.Position += 20L;
                    int           num11 = this.a_Stream.ReadInt32();
                    StringBuilder cb    = new StringBuilder();
                    for (int m = 0; m < num11; m++)
                    {
                        this.readBase(cb, 1);
                    }
                }
                else
                {
                    this.readBase5();
                }
            }
            if ((this.fileGen >= 7) && (this.fileGen < 14))
            {
                this.a_Stream.Position += 4L;
            }
            int    num5   = this.a_Stream.ReadInt32();
            string format = "D" + num5.ToString().Length.ToString();

            for (int j = 0; j < num5; j++)
            {
                if (this.fileGen >= 14)
                {
                    this.a_Stream.AlignStream(4);
                }
                AssetPreloadData data = new AssetPreloadData();
                if (this.fileGen < 14)
                {
                    data.m_PathID = this.a_Stream.ReadInt32();
                }
                else
                {
                    data.m_PathID = this.a_Stream.ReadInt64();
                }
                data.Offset             = this.a_Stream.ReadInt32();
                data.Offset            += num3;
                data.Size               = this.a_Stream.ReadInt32();
                data.Type1              = this.a_Stream.ReadInt32();
                data.Type2              = this.a_Stream.ReadUInt16();
                this.a_Stream.Position += 2L;
                if ((this.fileGen >= 15) && (this.a_Stream.ReadByte() > 0))
                {
                }
                if (this.UnityClassID.Names[data.Type2] == null)
                {
                    data.TypeString = this.UnityClassID.Names[data.Type2];
                }
                data.uniqueID   = j.ToString(format);
                data.exportSize = data.Size;
                data.sourceFile = this;
                this.preloadTable.Add(data.m_PathID, data);
                if ((data.Type2 == 0x8d) && (this.fileGen == 6))
                {
                    long          position = this.a_Stream.Position;
                    BuildSettings settings = new BuildSettings(data);
                    this.m_Version         = settings.m_Version;
                    this.a_Stream.Position = position;
                }
            }
            string[] separator = new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
            this.buildType = this.m_Version.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            string[] textArray2 = new string[] {
                ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
                "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n"
            };
            string[] array = this.m_Version.Split(textArray2, StringSplitOptions.RemoveEmptyEntries);
            this.version = Array.ConvertAll <string, int>(array, new Converter <string, int>(int.Parse));
            if (this.fileGen >= 14)
            {
                int num17 = this.a_Stream.ReadInt32();
                for (int n = 0; n < num17; n++)
                {
                    int num19 = this.a_Stream.ReadInt32();
                    this.a_Stream.AlignStream(4);
                    long num20 = this.a_Stream.ReadInt64();
                }
            }
            int num6 = this.a_Stream.ReadInt32();

            for (int k = 0; k < num6; k++)
            {
                UnityShared item = new UnityShared {
                    aName = this.a_Stream.ReadStringToNull()
                };
                this.a_Stream.Position += 20L;
                item.fileName           = this.a_Stream.ReadStringToNull().Replace("/", @"\");
                this.sharedAssetsList.Add(item);
            }
        }
Exemple #3
0
        public AssetsFile(string fileName, EndianStream fileStream)
        {
            //if (memFile != null) { Stream = new EndianStream(memFile, endianType); }
            //else { Stream = new EndianStream(File.OpenRead(fileName), endianType); }
            a_Stream = fileStream;

            filePath = fileName;
            int tableSize = a_Stream.ReadInt32();
            int dataEnd   = a_Stream.ReadInt32();

            fileGen = a_Stream.ReadInt32();
            int dataOffset = a_Stream.ReadInt32();

            sharedAssetsList[0].fileName = Path.GetFileName(fileName); //reference itself because sharedFileIDs start from 1
            switch (fileGen)
            {
            case 6:    //2.5.0 - 2.6.1
            {
                a_Stream.Position  = (dataEnd - tableSize);
                a_Stream.Position += 1;
                break;
            }

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

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

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

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

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

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

            switch (platform)
            {
            case -2: platformStr = "Unity Package"; break;

            case 4: platformStr = "OSX"; break;

            case 5: platformStr = "PC"; break;

            case 6: platformStr = "Web"; break;

            case 7: platformStr = "Web streamed"; break;

            case 9: platformStr = "iOS"; break;

            case 10: platformStr = "PS3"; break;

            case 11: platformStr = "Xbox 360"; break;

            case 13: platformStr = "Android"; break;

            case 16: platformStr = "Google NaCl"; break;

            case 21: platformStr = "WP8"; break;

            case 25: platformStr = "Linux"; break;
            }

            int baseCount = a_Stream.ReadInt32();

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

                    StringBuilder cb = new StringBuilder();
                    for (int m = 0; m < memberCount; m++)
                    {
                        readBase(cb, 1);
                    }

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

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

            int assetCount = a_Stream.ReadInt32();

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

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

                AssetPreloadData asset = new AssetPreloadData();
                if (fileGen < 14)
                {
                    asset.m_PathID = a_Stream.ReadInt32();
                }
                else
                {
                    asset.m_PathID = a_Stream.ReadInt64();
                }

                if (fileGen > 15)
                {
                    asset.Offset = a_Stream.ReadInt32();
                    int tmp = asset.Offset;
                    asset.Offset += dataOffset;
                    asset.Size    = a_Stream.ReadInt32();
                    int classIndex = a_Stream.ReadUInt16();
                    if (classIDLookup.ContainsKey(classIndex))
                    {
                        asset.Type2 = classIDLookup[classIndex];
                    }
                }
                else
                {
                    asset.Offset       = a_Stream.ReadInt32();
                    asset.Offset      += dataOffset;
                    asset.Size         = a_Stream.ReadInt32();
                    asset.Type1        = a_Stream.ReadInt32();
                    asset.Type2        = a_Stream.ReadUInt16();
                    a_Stream.Position += 2;
                    if (fileGen >= 15)
                    {
                        a_Stream.ReadByte();
                        //this is a single byte, not an int32
                        //the next entry is aligned after this
                        //but not the last!
                    }
                }

                if (UnityClassID.Names[asset.Type2] != null)
                {
                    asset.TypeString = UnityClassID.Names[asset.Type2];
                }

                asset.uniqueID = i.ToString(assetIDfmt);

                asset.exportSize = asset.Size;
                asset.sourceFile = this;

                preloadTable.Add(asset.m_PathID, asset);

                #region read BuildSettings to get version for unity 2.x files
                if (asset.Type2 == 141 && fileGen == 6)
                {
                    long nextAsset = a_Stream.Position;

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

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

            buildType = m_Version.Split(new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries);
            string[] strver = (m_Version.Split(new string[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries));
            version = Array.ConvertAll <string, int>(strver, int.Parse);

            if (fileGen > 15)
            {
                a_Stream.Position += 2;
            }

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

            int sharedFileCount = a_Stream.ReadInt32();
            for (int i = 0; i < sharedFileCount; i++)
            {
                UnityShared shared = new UnityShared();
                shared.aName       = a_Stream.ReadStringToNull();
                a_Stream.Position += 20;
                string sharedFileName = a_Stream.ReadStringToNull(); //relative path
                shared.fileName = sharedFileName.Replace("/", "\\");
                sharedAssetsList.Add(shared);
            }
        }
        public AssetsFile(string fullName, EndianStream fileStream)
        {
            //if (memFile != null) { Stream = new EndianStream(memFile, endianType); }
            //else { Stream = new EndianStream(File.OpenRead(fileName), endianType); }
            a_Stream = fileStream;

            filePath = fullName;
            fileName = Path.GetFileName(fullName);
            int tableSize = a_Stream.ReadInt32();
            int dataEnd   = a_Stream.ReadInt32();

            fileGen = a_Stream.ReadInt32();
            uint dataOffset = a_Stream.ReadUInt32();

            sharedAssetsList[0].fileName = Path.GetFileName(fullName); //reference itself because sharedFileIDs start from 1

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

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

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

            case 9:                     //3.5.0 - 4.6.x
            {
                a_Stream.Position += 4; //azero
                m_Version          = a_Stream.ReadStringToNull();
                platform           = a_Stream.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
            {
                a_Stream.Position += 4; //azero
                m_Version          = a_Stream.ReadStringToNull();
                platform           = a_Stream.ReadInt32();
                baseDefinitions    = a_Stream.ReadBoolean();
                break;
            }

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

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

            switch (platform)
            {
            case -2: platformStr = "Unity Package"; break;

            case 4: platformStr = "OSX"; break;

            case 5: platformStr = "PC"; break;

            case 6: platformStr = "Web"; break;

            case 7: platformStr = "Web streamed"; break;

            case 9: platformStr = "iOS"; break;

            case 10: platformStr = "PS3"; break;

            case 11: platformStr = "Xbox 360"; break;

            case 13: platformStr = "Android"; break;

            case 16: platformStr = "Google NaCl"; break;

            case 21: platformStr = "WP8"; break;

            case 25: platformStr = "Linux"; break;

            case 29: platformStr = "Wii U"; break;

            default: platformStr = "Unknown Platform"; break;
            }

            int baseCount = a_Stream.ReadInt32();

            for (int i = 0; i < baseCount; i++)
            {
                if (fileGen < 14)
                {
                    int    classID  = a_Stream.ReadInt32();
                    string baseType = a_Stream.ReadStringToNull();
                    string baseName = a_Stream.ReadStringToNull();
                    a_Stream.Position += 20;
                    int memberCount = a_Stream.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)
            {
                a_Stream.Position += 4;
            }                                                            //azero

            int assetCount = a_Stream.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)
                {
                    a_Stream.AlignStream(4);
                }

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

                string typeString;
                if (ClassIDReference.Names.TryGetValue(asset.Type2, out typeString))
                {
                    asset.TypeString = typeString;
                }
                else
                {
                    asset.TypeString = "Unknown Type " + asset.Type2;
                }

                asset.uniqueID = i.ToString(assetIDfmt);

                asset.sourceFile = this;

                preloadTable.Add(asset.m_PathID, asset);

                #region read BuildSettings to get version for unity 2.x files
                if (asset.Type2 == 141 && fileGen == 6)
                {
                    long nextAsset = a_Stream.Position;

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

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

            buildType = m_Version.Split(buildTypeSplit, StringSplitOptions.RemoveEmptyEntries);
            var strver = m_Version.Split(strverSplit, StringSplitOptions.RemoveEmptyEntries);
            version = Array.ConvertAll(strver, int.Parse);

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

            int sharedFileCount = a_Stream.ReadInt32();
            for (int i = 0; i < sharedFileCount; i++)
            {
                UnityShared shared = new UnityShared();
                shared.aName       = a_Stream.ReadStringToNull();
                a_Stream.Position += 20;
                string sharedFileName = a_Stream.ReadStringToNull(); //relative path
                shared.fileName = sharedFileName.Replace("/", "\\");
                sharedAssetsList.Add(shared);
            }
        }
Exemple #5
0
        public AssetsFile(string fileName, EndianStream fileStream)
        {
            //if (memFile != null) { Stream = new EndianStream(memFile, endianType); }
            //else { Stream = new EndianStream(File.OpenRead(fileName), endianType); }
            a_Stream = fileStream;

            filePath = fileName;
            int tableSize = a_Stream.ReadInt32();
            int dataEnd = a_Stream.ReadInt32();
            fileGen = a_Stream.ReadInt32();
            int dataOffset = a_Stream.ReadInt32();
            sharedAssetsList[0].fileName = Path.GetFileName(fileName); //reference itself because sharedFileIDs start from 1

            switch (fileGen)
            {
                case 6:
                    {
                        a_Stream.Position = (dataEnd - tableSize);
                        a_Stream.Position += 1;
                        break;
                    }
                case 7://beta
                    {
                        a_Stream.Position = (dataEnd - tableSize);
                        a_Stream.Position += 1;
                        m_Version = a_Stream.ReadStringToNull();
                        break;
                    }
                case 8:
                    {
                        a_Stream.Position = (dataEnd - tableSize);
                        a_Stream.Position += 1;
                        m_Version = a_Stream.ReadStringToNull();
                        platform = a_Stream.ReadInt32();
                        break;
                    }
                case 9:
                    {
                        a_Stream.Position += 4;//azero
                        m_Version = a_Stream.ReadStringToNull();
                        platform = a_Stream.ReadInt32();
                        break;
                    }
                case 14:
                case 15://not fully tested!s
                    {
                        a_Stream.Position += 4;//azero
                        m_Version = a_Stream.ReadStringToNull();
                        platform = a_Stream.ReadInt32();
                        baseDefinitions = a_Stream.ReadBoolean();
                        break;
                    }
                default:
                    {
                        //MessageBox.Show("Unsupported Unity version!", "Unity Studio Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
            }

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

            /*Platform list:
               -2:  unitypackage
                4:  OSX
                5:  PC
                6:  Web
                7:  Web_streamed
                9:  iOS
                10: PS3(big)
                11: Xbox360(big)
                13: Android
                16: Google_NaCl
                21: WP8
                25: Linux
            */

            int baseCount = a_Stream.ReadInt32();
            for (int i = 0; i < baseCount; i++)
            {
                if (fileGen < 14)
                {
                    int baseType = a_Stream.ReadInt32();
                    readBase();
                }
                else { readBase5(); }
            }

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

            int assetCount = a_Stream.ReadInt32();
            if (fileGen >= 14) { a_Stream.AlignStream(4); }

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

            for (int i = 0; i < assetCount; i++)
            {
                AssetPreloadData asset = new AssetPreloadData();
                if (fileGen < 14) { asset.m_PathID = a_Stream.ReadInt32(); }
                else { asset.m_PathID = a_Stream.ReadInt64(); }
                asset.Offset = a_Stream.ReadInt32();
                asset.Offset += dataOffset;
                asset.Size = a_Stream.ReadInt32();
                asset.Type1 = a_Stream.ReadInt32();
                asset.Type2 = a_Stream.ReadUInt16();
                a_Stream.Position += 2;
                if (fileGen >= 15) { int azero = a_Stream.ReadInt32(); }

                asset.TypeString = asset.Type2.ToString();
                if (UnityClassID.Names[asset.Type2] != null)
                {
                    asset.TypeString = UnityClassID.Names[asset.Type2];
                }

                asset.uniqueID = i.ToString(assetIDfmt);

                asset.exportSize = asset.Size;
                asset.sourceFile = this;

                preloadTable.Add(asset.m_PathID, asset);

                //this should be among the first nodes in mainData and it contains the version - useful for unity 2.x files
                if (asset.Type2 == 141 && fileGen == 6)
                {
                    long nextAsset = a_Stream.Position;

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

                    a_Stream.Position = nextAsset;
                }
            }

            buildType = m_Version.Split(new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries);
            string[] strver = (m_Version.Split(new string[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries));
            version = Array.ConvertAll(strver, int.Parse);

            if (fileGen >= 14)
            {
                int someCount = a_Stream.ReadInt32();
                a_Stream.Position += someCount * 12;
            }

            int sharedFileCount = a_Stream.ReadInt32();
            for (int i = 0; i < sharedFileCount; i++)
            {
                UnityShared shared = new UnityShared();
                shared.aName = a_Stream.ReadStringToNull();
                a_Stream.Position += 20;
                string sharedFileName = a_Stream.ReadStringToNull(); //relative path
                shared.fileName = sharedFileName.Replace("/", "\\");
                sharedAssetsList.Add(shared);
            }
        }