コード例 #1
0
        public async Task <bool> BatchImport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            OpenFolderDialog ofd = new OpenFolderDialog();

            ofd.Title = "Select import directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                ImportBatch            dialog     = new ImportBatch(workspace, selection, dir, ".png");
                List <ImportBatchInfo> batchInfos = await dialog.ShowDialog <List <ImportBatchInfo> >(win);

                foreach (ImportBatchInfo batchInfo in batchInfos)
                {
                    AssetContainer cont = batchInfo.cont;

                    AssetTypeValueField baseField = workspace.GetBaseField(cont);

                    string file = batchInfo.importFile;

                    byte[] byteData = File.ReadAllBytes(file);
                    baseField.Get("m_Script").GetValue().Set(byteData);

                    byte[] savedAsset = baseField.WriteToByteArray();

                    var replacer = new AssetsReplacerFromMemory(
                        0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                    workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public async Task <bool> SingleExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            AssetContainer cont = selection[0];

            SaveFileDialog sfd = new SaveFileDialog();

            AssetTypeValueField baseField = workspace.GetBaseField(cont);
            string name = baseField.Get("m_Name").GetValue().AsString();

            sfd.Title   = "Save text file";
            sfd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "TXT file", Extensions = new List <string>()
                    {
                        "txt"
                    }
                }
            };
            sfd.InitialFileName = $"{name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.txt";

            string file = await sfd.ShowAsync(win);

            if (file != null && file != string.Empty)
            {
                byte[] byteData = baseField.Get("m_Script").GetValue().AsStringBytes();
                File.WriteAllBytes(file, byteData);

                return(true);
            }
            return(false);
        }
コード例 #3
0
        public async Task <bool> BatchExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            OpenFolderDialog ofd = new OpenFolderDialog();

            ofd.Title = "Select export directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                foreach (AssetContainer cont in selection)
                {
                    AssetTypeValueField baseField = workspace.GetBaseField(cont);

                    string name     = baseField.Get("m_Name").GetValue().AsString();
                    byte[] byteData = baseField.Get("m_Script").GetValue().AsStringBytes();

                    string file = Path.Combine(dir, $"{name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.txt");

                    File.WriteAllBytes(file, byteData);
                }
                return(true);
            }
            return(false);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: nesrak1/UABEA
        public async Task <bool> SingleExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            AssetContainer cont = selection[0];

            AssetTypeValueField texBaseField = TextureHelper.GetByteArrayTexture(workspace, cont).GetBaseField();
            TextureFile         texFile      = TextureFile.ReadTextureFile(texBaseField);
            SaveFileDialog      sfd          = new SaveFileDialog();

            sfd.Title   = "Save texture";
            sfd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "PNG file", Extensions = new List <string>()
                    {
                        "png"
                    }
                }
            };
            sfd.InitialFileName = $"{texFile.m_Name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.png";

            string file = await sfd.ShowAsync(win);

            if (file != null && file != string.Empty)
            {
                string errorAssetName = $"{Path.GetFileName(cont.FileInstance.path)}/{cont.PathId}";

                //bundle resS
                if (!GetResSTexture(texFile, cont))
                {
                    string resSName = Path.GetFileName(texFile.m_StreamData.path);
                    await MessageBoxUtil.ShowDialog(win, "Error", $"[{errorAssetName}]: resS was detected but {resSName} was not found in bundle");

                    return(false);
                }

                byte[] data = TextureHelper.GetRawTextureBytes(texFile, cont.FileInstance);

                if (data == null)
                {
                    string resSName = Path.GetFileName(texFile.m_StreamData.path);
                    await MessageBoxUtil.ShowDialog(win, "Error", $"[{errorAssetName}]: resS was detected but {resSName} was not found on disk");

                    return(false);
                }

                bool success = TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat);
                if (!success)
                {
                    string texFormat = ((TextureFormat)texFile.m_TextureFormat).ToString();
                    await MessageBoxUtil.ShowDialog(win, "Error", $"[{errorAssetName}]: Failed to decode texture format {texFormat}");
                }
                return(success);
            }
            return(false);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: nesrak1/UABEA
 public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
 {
     if (selection.Count > 1)
     {
         return(await BatchExport(win, workspace, selection));
     }
     else
     {
         return(await SingleExport(win, workspace, selection));
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: nesrak1/UABEA
        public static AssetTypeInstance GetByteArrayTexture(AssetWorkspace workspace, AssetContainer tex)
        {
            AssetTypeTemplateField textureTemp = workspace.GetTemplateField(tex.FileInstance.file, tex.ClassId, tex.MonoId);
            AssetTypeTemplateField image_data  = textureTemp.children.FirstOrDefault(f => f.name == "image data");

            if (image_data == null)
            {
                return(null);
            }
            image_data.valueType = EnumValueTypes.ByteArray;
            AssetTypeInstance textureTypeInstance = new AssetTypeInstance(new[] { textureTemp }, tex.FileReader, tex.FilePosition);

            return(textureTypeInstance);
        }
コード例 #7
0
        public AssetTypeValueField GetByteArrayTexture(AssetWorkspace workspace, AssetExternal tex)
        {
            ClassDatabaseType      textureType = AssetHelper.FindAssetClassByID(workspace.am.classFile, tex.info.curFileType);
            AssetTypeTemplateField textureTemp = new AssetTypeTemplateField();

            textureTemp.FromClassDatabase(workspace.am.classFile, textureType, 0);
            AssetTypeTemplateField image_data = textureTemp.children.FirstOrDefault(f => f.name == "image data");

            if (image_data == null)
            {
                return(null);
            }
            image_data.valueType = EnumValueTypes.ByteArray;
            AssetTypeInstance   textureTypeInstance = new AssetTypeInstance(new[] { textureTemp }, tex.file.file.reader, tex.info.absoluteFilePos);
            AssetTypeValueField textureBase         = textureTypeInstance.GetBaseField();

            return(textureBase);
        }
コード例 #8
0
        public async Task <bool> SingleImport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            AssetContainer cont = selection[0];

            OpenFileDialog ofd = new OpenFileDialog();

            AssetTypeValueField baseField = workspace.GetBaseField(cont);

            ofd.Title   = "Open text file";
            ofd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "TXT file", Extensions = new List <string>()
                    {
                        "txt"
                    }
                }
            };

            string[] fileList = await ofd.ShowAsync(win);

            if (fileList.Length == 0)
            {
                return(false);
            }

            string file = fileList[0];

            if (file != null && file != string.Empty)
            {
                byte[] byteData = File.ReadAllBytes(file);
                baseField.Get("m_Script").GetValue().Set(byteData);

                byte[] savedAsset = baseField.WriteToByteArray();

                var replacer = new AssetsReplacerFromMemory(
                    0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
            }
            return(false);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: nesrak1/UABEA
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            for (int i = 0; i < selection.Count; i++)
            {
                selection[i] = new AssetContainer(selection[i], TextureHelper.GetByteArrayTexture(workspace, selection[i]));
            }

            OpenFolderDialog ofd = new OpenFolderDialog();

            ofd.Title = "Select import directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                ImportBatch            dialog     = new ImportBatch(workspace, selection, dir, ".png");
                List <ImportBatchInfo> batchInfos = await dialog.ShowDialog <List <ImportBatchInfo> >(win);

                bool success = await ImportTextures(win, batchInfos);

                if (success)
                {
                    //some of the assets may not get modified, but
                    //uabe still makes replacers for those anyway
                    foreach (AssetContainer cont in selection)
                    {
                        byte[] savedAsset = cont.TypeInstance.WriteToByteArray();

                        var replacer = new AssetsReplacerFromMemory(
                            0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                        workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: nesrak1/UABEA
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            AssetContainer cont = selection[0];

            AssetTypeValueField texBaseField = TextureHelper.GetByteArrayTexture(workspace, cont).GetBaseField();
            TextureFile         texFile      = TextureFile.ReadTextureFile(texBaseField);
            EditDialog          dialog       = new EditDialog(texFile.m_Name, texFile, texBaseField);
            bool saved = await dialog.ShowDialog <bool>(win);

            if (saved)
            {
                byte[] savedAsset = texBaseField.WriteToByteArray();

                var replacer = new AssetsReplacerFromMemory(
                    0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                return(true);
            }
            return(false);
        }
コード例 #11
0
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetExternal> selection)
        {
            AssetExternal       tex          = selection[0];
            AssetTypeValueField texBaseField = tex.instance.GetBaseField();
            TextureFile         texFile      = TextureFile.ReadTextureFile(texBaseField);
            EditDialog          dialog       = new EditDialog(texFile.m_Name, texFile, texBaseField);
            bool saved = await dialog.ShowDialog <bool>(win);

            if (saved)
            {
                byte[] savedAsset = texBaseField.WriteToByteArray();

                var replacer = new AssetsReplacerFromMemory(
                    0, tex.info.index, (int)tex.info.curFileType,
                    AssetHelper.GetScriptIndex(tex.file.file, tex.info), savedAsset);

                workspace.AddReplacer(tex.file, replacer, new MemoryStream(savedAsset));
                return(true);
            }
            return(false);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: nesrak1/UABEA
        public async Task <bool> BatchExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            for (int i = 0; i < selection.Count; i++)
            {
                selection[i] = new AssetContainer(selection[i], TextureHelper.GetByteArrayTexture(workspace, selection[i]));
            }

            OpenFolderDialog ofd = new OpenFolderDialog();

            ofd.Title = "Select export directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                StringBuilder errorBuilder = new StringBuilder();

                foreach (AssetContainer cont in selection)
                {
                    string errorAssetName = $"{Path.GetFileName(cont.FileInstance.path)}/{cont.PathId}";

                    AssetTypeValueField texBaseField = cont.TypeInstance.GetBaseField();
                    TextureFile         texFile      = TextureFile.ReadTextureFile(texBaseField);

                    //0x0 texture, usually called like Font Texture or smth
                    if (texFile.m_Width == 0 && texFile.m_Height == 0)
                    {
                        continue;
                    }

                    string file = Path.Combine(dir, $"{texFile.m_Name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.png");

                    //bundle resS
                    if (!GetResSTexture(texFile, cont))
                    {
                        string resSName = Path.GetFileName(texFile.m_StreamData.path);
                        errorBuilder.AppendLine($"[{errorAssetName}]: resS was detected but {resSName} was not found in bundle");
                        continue;
                    }

                    byte[] data = TextureHelper.GetRawTextureBytes(texFile, cont.FileInstance);

                    if (data == null)
                    {
                        string resSName = Path.GetFileName(texFile.m_StreamData.path);
                        errorBuilder.AppendLine($"[{errorAssetName}]: resS was detected but {resSName} was not found on disk");
                        continue;
                    }

                    bool success = TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat);
                    if (!success)
                    {
                        string texFormat = ((TextureFormat)texFile.m_TextureFormat).ToString();
                        errorBuilder.AppendLine($"[{errorAssetName}]: Failed to decode texture format {texFormat}");
                        continue;
                    }
                }

                if (errorBuilder.Length > 0)
                {
                    string[] firstLines    = errorBuilder.ToString().Split('\n').Take(20).ToArray();
                    string   firstLinesStr = string.Join('\n', firstLines);
                    await MessageBoxUtil.ShowDialog(win, "Some errors occurred while exporting", firstLinesStr);
                }

                return(true);
            }
            return(false);
        }
コード例 #13
0
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetExternal> selection)
        {
            await MessageBoxUtil.ShowDialog(win, "Not Implemented", "Import png option not supported,\nbut you can still import an image\nwith Edit. Use that instead.");

            return(false);
        }
コード例 #14
0
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetExternal> selection)
        {
            AssetExternal tex = selection[0];

            AssetTypeValueField texBaseField = GetByteArrayTexture(workspace, tex);
            TextureFile         texFile      = TextureFile.ReadTextureFile(texBaseField);
            SaveFileDialog      sfd          = new SaveFileDialog();

            sfd.Title   = "Save texture";
            sfd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "PNG file", Extensions = new List <string>()
                    {
                        "png"
                    }
                }
            };

            string file = await sfd.ShowAsync(win);

            if (file != null && file != string.Empty)
            {
                //bundle resS
                TextureFile.StreamingInfo streamInfo = texFile.m_StreamData;
                if (streamInfo.path != null && streamInfo.path != "" && tex.file.parentBundle != null)
                {
                    //some versions apparently don't use archive:/
                    string searchPath = streamInfo.path;
                    if (searchPath.StartsWith("archive:/"))
                    {
                        searchPath = searchPath.Substring(9);
                    }

                    searchPath = Path.GetFileName(searchPath);

                    AssetBundleFile bundle = tex.file.parentBundle.file;

                    AssetsFileReader             reader = bundle.reader;
                    AssetBundleDirectoryInfo06[] dirInf = bundle.bundleInf6.dirInf;
                    bool foundFile = false;
                    for (int i = 0; i < dirInf.Length; i++)
                    {
                        AssetBundleDirectoryInfo06 info = dirInf[i];
                        if (info.name == searchPath)
                        {
                            reader.Position             = bundle.bundleHeader6.GetFileDataOffset() + info.offset + streamInfo.offset;
                            texFile.pictureData         = reader.ReadBytes((int)streamInfo.size);
                            texFile.m_StreamData.offset = 0;
                            texFile.m_StreamData.size   = 0;
                            texFile.m_StreamData.path   = "";
                            foundFile = true;
                            break;
                        }
                    }
                    if (!foundFile)
                    {
                        await MessageBoxUtil.ShowDialog(win, "Error", "resS was detected but no file was found in bundle");

                        return(false);
                    }
                }

                byte[] data = GetRawTextureBytes(texFile, tex.file);

                bool success = await TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat);

                return(success);
            }
            return(false);
        }