示例#1
0
 private static void AddAsset(ModelInfoGroup group, string assetname, bool executable = true)
 {
     try {
         group.Add(new ModelInfo {
             filename = "",
             title    = assetname,
             //text = new StreamReader(Assets.Open(assetname + ".txt")).ReadToEnd(), // old Android assets
             text       = SharedAssets.TextAsset(assetname + ".txt"),
             date       = DateTime.Now,
             executable = executable,
         });
     } catch { }
 }
示例#2
0
 public /* Interface KGuiControl */ void GuiRestoreInput()
 {
     try {
         string path = MacControls.CreateKaemikaDataDirectory() + "/save.txt";
         if (File.Exists(path))
         {
             this.GuiInputSetText(File.ReadAllText(path));
         }
         else
         {
             this.GuiInputSetText(SharedAssets.TextAsset("StartHere.txt"));
         }
     } catch { }
 }
示例#3
0
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            this.reader   = reader;
            filePath      = fullName;
            fileName      = Path.GetFileName(fullName);
            upperFileName = fileName.ToUpper();
            try
            {
                int tableSize = this.reader.ReadInt32();
                int dataEnd   = this.reader.ReadInt32();
                fileGen = this.reader.ReadInt32();
                uint dataOffset = this.reader.ReadUInt32();
                sharedAssetsList[0].fileName = fileName; //reference itself because sharedFileIDs start from 1

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

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

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

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

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

                if (fileGen > 6 && m_Version == "")
                {
                    return;
                }

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

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

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

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

                    AssetPreloadData asset = new AssetPreloadData();
                    asset.m_PathID = fileGen < 14 ? this.reader.ReadInt32() : this.reader.ReadInt64();
                    asset.Offset   = this.reader.ReadUInt32();
                    asset.Offset  += dataOffset;
                    asset.Size     = this.reader.ReadInt32();
                    if (fileGen > 15)
                    {
                        int index = this.reader.ReadInt32();
                        asset.Type1 = classIDs[index][0];
                        asset.Type2 = classIDs[index][1];
                    }
                    else
                    {
                        asset.Type1           = this.reader.ReadInt32();
                        asset.Type2           = this.reader.ReadUInt16();
                        this.reader.Position += 2;
                    }
                    if (fileGen == 15)
                    {
                        byte unknownByte = this.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 && fileGen == 6)
                    {
                        long nextAsset = this.reader.Position;

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

                        this.reader.Position = nextAsset;
                    }
                    #endregion
                }
                #endregion

                buildType = Regex.Replace(m_Version, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                var firstVersion = int.Parse(m_Version.Split('.')[0]);
                version = Regex.Matches(m_Version, @"\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;
                }
                if (fileGen >= 14)
                {
                    //this looks like a list of assets that need to be preloaded in memory before anytihng else
                    int someCount = this.reader.ReadInt32();
                    for (int i = 0; i < someCount; i++)
                    {
                        int num1 = this.reader.ReadInt32();
                        this.reader.AlignStream(4);
                        long m_PathID = this.reader.ReadInt64();
                    }
                }

                int sharedFileCount = this.reader.ReadInt32();
                for (int i = 0; i < sharedFileCount; i++)
                {
                    var shared = new SharedAssets();
                    shared.aName          = this.reader.ReadStringToNull();
                    this.reader.Position += 20;
                    var sharedFilePath = this.reader.ReadStringToNull(); //relative path
                    shared.fileName = Path.GetFileName(sharedFilePath);
                    sharedAssetsList.Add(shared);
                }
                valid = true;
            }
            catch
            {
            }
        }
示例#4
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
            {
            }
        }