コード例 #1
0
        public static bool ExportTexture2D(AssetItem item, string exportPathName)
        {
            var m_Texture2D = (Texture2D)item.Asset;

            if (Properties.Settings.Default.convertTexture)
            {
                var bitmap = m_Texture2D.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                ImageFormat format = null;
                var         ext    = Properties.Settings.Default.convertType;
                bool        tga    = false;
                switch (ext)
                {
                case "BMP":
                    format = ImageFormat.Bmp;
                    break;

                case "PNG":
                    format = ImageFormat.Png;
                    break;

                case "JPEG":
                    format = ImageFormat.Jpeg;
                    break;

                case "TGA":
                    tga = true;
                    break;
                }
                var exportFullName = GetExportFullName(exportPathName, item.Text, "." + ext.ToLower());
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullName);
                }
                else
                {
                    bitmap.Save(exportFullName, format);
                }
                bitmap.Dispose();
                return(true);
            }
            else
            {
                var exportFullName = GetExportFullName(exportPathName, item.Text, ".tex");
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                File.WriteAllBytes(exportFullName, m_Texture2D.image_data.GetData());
                return(true);
            }
        }
コード例 #2
0
        public void ResizeImage(Bitmap image, int newWidth, int newHeight, string path)
        {
            Rectangle destRect  = new Rectangle(0, 0, newWidth, newHeight);
            Bitmap    destImage = new Bitmap(newWidth, newHeight);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode    = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
            TGA dest = new TGA(destImage);

            dest.Save(path);
        }
コード例 #3
0
        public static bool ExportSprite(AssetItem item, string exportPath)
        {
            ImageFormat format = null;
            var         type   = Properties.Settings.Default.convertType;
            var         tga    = false;

            switch (type)
            {
            case "BMP":
                format = ImageFormat.Bmp;
                break;

            case "PNG":
                format = ImageFormat.Png;
                break;

            case "JPEG":
                format = ImageFormat.Jpeg;
                break;

            case "TGA":
                tga = true;
                break;
            }

            if (!TryExportFile(exportPath, item, "." + type.ToLower(), out var exportFullPath))
            {
                return(false);
            }
            var bitmap = ((Sprite)item.Asset).GetImage();

            if (bitmap == null)
            {
                return(false);
            }
            if (tga)
            {
                var file = new TGA(bitmap);
                file.Save(exportFullPath);
            }
            else
            {
                try
                {
                    bitmap.Save(exportFullPath, format);
                    bitmap.Dispose();
                }
                catch (ExternalException)
                {
                    return(ExportSprite(item, exportPath));
                }
            }

            return(true);
        }
コード例 #4
0
        public static bool ExportSprite(AssetItem item, string exportPath)
        {
            ImageFormat format = null;
            var         type   = Properties.Settings.Default.convertType;
            bool        tga    = false;

            switch (type)
            {
            case "BMP":
                format = ImageFormat.Bmp;
                break;

            case "PNG":
                format = ImageFormat.Png;
                break;

            case "JPEG":
                format = ImageFormat.Jpeg;
                break;

            case "TGA":
                tga = true;
                break;
            }
            var exportFullName = GetExportFullName(exportPath, item.Text, "." + type.ToLower());

            if (ExportFileExists(exportFullName))
            {
                return(false);
            }
            var bitmap = ((Sprite)item.Asset).GetImage();

            if (bitmap != null)
            {
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullName);
                }
                else
                {
                    bitmap.Save(exportFullName, format);
                }
                bitmap.Dispose();
                return(true);
            }
            return(false);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: huangwwmm/TGASharpLib
        private void buttonSaveSelected_Click(object sender, EventArgs e)
        {
            if (T == null)
            {
                return;
            }

            string OutDir = @"D:\TGA\";

            if (!Directory.Exists(OutDir))
            {
                Directory.CreateDirectory(OutDir);
            }

            T.Save(Path.Combine(OutDir, Path.GetFileName("___T.tga")));
        }
コード例 #6
0
        private static bool ExportBitmap(AssetItem item, string exportPath, System.Drawing.Bitmap bitmap, string postfix = "")
        {
            if (bitmap == null)
            {
                return(false);
            }
            ImageFormat format = null;
            var         ext    = Properties.Settings.Default.convertType;
            bool        tga    = false;

            switch (ext)
            {
            case "BMP":
                format = ImageFormat.Bmp;
                break;

            case "PNG":
                format = ImageFormat.Png;
                break;

            case "JPEG":
                format = ImageFormat.Jpeg;
                break;

            case "TGA":
                tga = true;
                break;
            }
            if (!TryExportFile(exportPath, item, postfix + "." + ext.ToLower(), out var exportFullPath))
            {
                return(false);
            }
            if (tga)
            {
                var file = new TGA(bitmap);
                file.Save(exportFullPath);
            }
            else
            {
                bitmap.Save(exportFullPath, format);
            }
            bitmap.Dispose();
            return(true);
        }
コード例 #7
0
        static string vtf2png(string vtf)
        {
            string matname = Path.GetFileNameWithoutExtension(vtf.Split("/").Last());
            string png     = $"tmp\\{matname}.png";

            if (File.Exists(png))
            {
                return(png);
            }
            try
            {
                string tga = vtf2tga(vtf);
                Bitmap bmp = new TGA(tga).ToBitmap();
                bmp.Save(png, ImageFormat.Png);
                File.Delete(tga);
            }
            catch { }
            return(png);
        }
コード例 #8
0
        private void ConvertTexture2D(Texture2D m_Texture2D, string name)
        {
            var iTex = ImportedHelpers.FindTexture(name, TextureList);

            if (iTex != null)
            {
                return;
            }

            var bitmap = m_Texture2D.ConvertToBitmap(true);

            if (bitmap != null)
            {
                using (var stream = new MemoryStream())
                {
                    switch (imageFormat)
                    {
                    case "BMP":
                        bitmap.Save(stream, ImageFormat.Bmp);
                        break;

                    case "PNG":
                        bitmap.Save(stream, ImageFormat.Png);
                        break;

                    case "JPEG":
                        bitmap.Save(stream, ImageFormat.Jpeg);
                        break;

                    case "TGA":
                        var tga = new TGA(bitmap);
                        tga.Save(stream);
                        break;
                    }
                    iTex = new ImportedTexture(stream, name);
                    TextureList.Add(iTex);
                    bitmap.Dispose();
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Converts a bitmap var into a byte array that can be saved as a VTF
        /// </summary>
        /// <param name="bitmap">The image to be converted</param>
        /// <param name="launcher">An instance of the Source SDK lib</param>
        /// <returns></returns>
        public static byte[] FromBitmap(Bitmap bitmap, Launcher launcher)
        {
            if (bitmap == null || launcher == null)
            {
                return(null);
            }

            string gamePath = launcher.GetCurrentGame().installPath;
            string modPath  = launcher.GetCurrentMod().installPath;
            string filePath = modPath + "\\materialsrc";

            string vtexPath = gamePath + "\\bin\\vtex.exe";

            var tga = new TGA(bitmap);

            Directory.CreateDirectory(filePath);
            tga.Save(filePath + "\\temp.tga");
            File.WriteAllText(filePath + "\\temp.txt", "nolod 1\r\nnomip 1");

            Process process = new Process();

            process.StartInfo.FileName         = vtexPath;
            process.StartInfo.Arguments        = "-mkdir -quiet -nopause -shader UnlitGeneric temp.tga";
            process.StartInfo.WorkingDirectory = filePath;
            process.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
            process.Start();
            process.WaitForExit();

            byte[] result = File.ReadAllBytes(modPath + "\\materials\\temp.vtf");

            File.Delete(filePath + "\\temp.tga");
            File.Delete(filePath + "\\temp.txt");
            File.Delete(modPath + "\\materials\\temp.vtf");
            File.Delete(modPath + "\\materials\\temp.vmt");

            return(result);
        }
コード例 #10
0
        public void Convert(string InFile, string OutFile)
        {
            // Resize image to square of larger proportional
            Bitmap Image       = new Bitmap(InFile);
            Bitmap SquareImage = ResizeImage(Image);

            string MaterialSrc = $"{this.TeamFortress2Folder}\\tf\\materialsrc";

            // Create materialsrc (ensure it exists)
            Directory.CreateDirectory(MaterialSrc);

            // Save image as .tga (cast using TGASharpLib)
            TGA TGASquareImage = (TGA)SquareImage;

            TGASquareImage.Save($"{MaterialSrc}\\temp.tga");

            // Convert using VTEX
            VTEXConvert(MaterialSrc, "temp");

            // Path to VTEX output file
            string VTFLocation = $"{this.TeamFortress2Folder}\\tf\\materials\\temp.vtf";

            // Create absolute path to output folder and make directory
            string[] PathInfo = OutFile.Split(new char[] { '\\', '/' });
            PathInfo[PathInfo.Length - 1] = "";
            string FolderPath = String.Join("\\", PathInfo);

            Directory.CreateDirectory(FolderPath);

            // Copy vtf from vtex output to user defined path
            File.Copy(VTFLocation, OutFile, true);

            // Delete temporary tga and vtex output
            File.Delete($"{MaterialSrc}\\temp.tga");
            File.Delete($"{MaterialSrc}\\temp.txt");
            File.Delete(VTFLocation);
        }
コード例 #11
0
ファイル: Exporter.cs プロジェクト: xa8et67/AssetStudio
        public static bool ExportTexture2D(AssetItem item, string exportPathName)
        {
            var converter      = new Texture2DConverter((Texture2D)item.Asset);
            var convertTexture = (bool)Properties.Settings.Default["convertTexture"];

            if (convertTexture)
            {
                var bitmap = converter.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                ImageFormat format = null;
                var         ext    = (string)Properties.Settings.Default["convertType"];
                bool        tga    = false;
                switch (ext)
                {
                case "BMP":
                    format = ImageFormat.Bmp;
                    break;

                case "PNG":
                    format = ImageFormat.Png;
                    break;

                case "JPEG":
                    format = ImageFormat.Jpeg;
                    break;

                case "TGA":
                    tga = true;
                    break;
                }
                var exportFullName = exportPathName + item.Text + "." + ext.ToLower();
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullName);
                }
                else
                {
                    bitmap.Save(exportFullName, format);
                }
                bitmap.Dispose();
                return(true);
            }
            else
            {
                var exportFullName = exportPathName + item.Text + converter.GetExtensionName();
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                File.WriteAllBytes(exportFullName, converter.ConvertToContainer());
                return(true);
            }
        }
コード例 #12
0
        private void InjectButton_Click(object sender, EventArgs e)
        {
            if (SortTitleTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the SortTitle!", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (PublisherTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Publisher!", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (GamecodeTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Game Code!", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (GamecodeTextbox.Text.Length < 5 || GamecodeTextbox.Text.Length > 5)
            {
                MessageBox.Show("Enter the unique Game Code (between AAAAA and ZZZZZ)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (CopyrightTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Copyright!", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (GametitleTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Game Title!", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Overscan box 1", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox.Text.Length < 1 || OverscanTextbox.Text.Length > 1)
            {
                MessageBox.Show("Enter the Overscan box 1 between (0 and 9)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox2.Text == string.Empty)
            {
                MessageBox.Show("Enter the Overscan box 2", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox2.Text.Length < 1 || OverscanTextbox2.Text.Length > 1)
            {
                MessageBox.Show("Enter the Overscan box 2 between (0 and 9)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox3.Text == string.Empty)
            {
                MessageBox.Show("Enter the Overscan box 3", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox3.Text.Length < 1 || OverscanTextbox3.Text.Length > 1)
            {
                MessageBox.Show("Enter the Overscan box 3 between (0 and 9)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox4.Text == string.Empty)
            {
                MessageBox.Show("Enter the Overscan box 4", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (OverscanTextbox4.Text.Length < 1 || OverscanTextbox4.Text.Length > 1)
            {
                MessageBox.Show("Enter the Overscan box 4 between (0 and 9)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (FadeinTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Fade In box 1", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (FadeinTextbox.Text.Length < 1 || FadeinTextbox.Text.Length > 1)
            {
                MessageBox.Show("Enter the Fade In box 1 between (0 and 9)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (FadeinTextbox2.Text == string.Empty)
            {
                MessageBox.Show("Enter the Fade In box 2", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (FadeinTextbox2.Text.Length < 1 || FadeinTextbox2.Text.Length > 1)
            {
                MessageBox.Show("Enter the Fade In box 2 between (0 and 9)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (VolumeTextbox.Text.Length < 1 || VolumeTextbox.Text.Length > 2)
            {
                MessageBox.Show("Enter the Volume (1-99)", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (VolumeTextbox.Text == string.Empty)
            {
                MessageBox.Show("Enter the Volume", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (GamepathTextbox.Text == string.Empty)
            {
                MessageBox.Show("Invalid Game path", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (Coverpath1Textbox.Text == string.Empty)
            {
                MessageBox.Show("Invalid Cover path 400x300", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (Coverpath2Textbox.Text == string.Empty)
            {
                MessageBox.Show("Invalid Cover path 355x512", "Error.", MessageBoxButtons.OK);
                return;
            }
            else if (TitledbTextbox.Text == string.Empty)
            {
                MessageBox.Show("Invalid Title DB path", "Error.", MessageBoxButtons.OK);
                return;
            }

            string line;

            using (StreamReader CheckGamecode = new StreamReader(TitledbTextbox.Text))

                if ((line = CheckGamecode.ReadToEnd()) != null)
                {
                    if (line.Contains(GamecodeTextbox.Text))
                    {
                        MessageBox.Show("Gamecode " + GamecodeTextbox.Text + " already exist in the TitleDB", "Error");
                        return;
                    }
                }

            if (JPCheckbox.Checked == false)
            {
                string filecheck20 = "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/HLV-C-" + GamecodeTextbox.Text + "\\" + "HLV-C-" + GamecodeTextbox.Text + ".xtx.z";
                if (File.Exists(filecheck20))
                {
                    MessageBox.Show("Cover file " + GamecodeTextbox.Text + " already exist", "Error");
                    return;
                }
                string filecheck24 = "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/HLV-C-" + GamecodeTextbox.Text + "\\" + "HLV-C-" + GamecodeTextbox.Text + "00.xtx.z";
                if (File.Exists(filecheck24))
                {
                    MessageBox.Show("Cover file 355x512 " + GamecodeTextbox.Text + " already exist", "Error");
                    return;
                }
                string filecheck21 = "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/HLV-C-" + GamecodeTextbox.Text + "\\" + "HLV-C-" + GamecodeTextbox.Text + ".nes";
                if (File.Exists(filecheck21))
                {
                    MessageBox.Show("Game file " + GamecodeTextbox.Text + " already exist in the TitleDB", "Error");
                    return;
                }
            }
            if (JPCheckbox.Checked)
            {
                string filecheck22 = "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/CLV-G-" + GamecodeTextbox.Text + "\\" + "CLV-G-" + GamecodeTextbox.Text + ".xtx.z";
                if (File.Exists(filecheck22))
                {
                    MessageBox.Show("Cover file 400x300 " + GamecodeTextbox.Text + " already exist", "Error");
                    return;
                }
                string filecheck23 = "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/CLV-G-" + GamecodeTextbox.Text + "\\" + "CLV-G-" + GamecodeTextbox.Text + "00.xtx.z";
                if (File.Exists(filecheck23))
                {
                    MessageBox.Show("Cover file 355x512 " + GamecodeTextbox.Text + " already exist", "Error");
                    return;
                }
                string filecheck25 = "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/CLV-G-" + GamecodeTextbox.Text + "\\" + "CLV-G-" + GamecodeTextbox.Text + ".nes";
                if (File.Exists(filecheck25))
                {
                    MessageBox.Show("Game file " + GamecodeTextbox.Text + " already exist in the TitleDB", "Error");
                    return;
                }
            }

            string filecheck1 = "cover.xtx";

            if (File.Exists(filecheck1))
            {
                File.Delete(@"cover.xtx");
            }
            string filecheck2 = "screenshot.xtx";

            if (File.Exists(filecheck2))
            {
                File.Delete(@"screenshot.xtx");
            }
            string filecheck3 = "cover.xtx.zlib";

            if (File.Exists(filecheck3))
            {
                File.Delete(@"cover.xtx.zlib");
            }
            string filecheck4 = "screenshot.xtx.zlib";

            if (File.Exists(filecheck4))
            {
                File.Delete(@"screenshot.xtx.zlib");
            }
            string filecheck5 = "temp/cover.tga";

            if (File.Exists(filecheck5))
            {
                File.Delete(@"temp/cover.tga");
            }
            string filecheck6 = "temp/screenshot.tga";

            if (File.Exists(filecheck6))
            {
                File.Delete(@"temp/screenshot.tga");
            }
            string filecheck7 = "temp/lclassics.titlesdb";

            if (File.Exists(filecheck7))
            {
                File.Delete(@"temp/lclassics.titlesdb");
            }
            string filecheck8 = "temp";

            if (Directory.Exists(filecheck8))
            {
                Directory.Delete(@"temp");
            }

            if (JPCheckbox.Checked == false)
            {
                Directory.CreateDirectory("NES_ONLINE_Mod");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100D870045B6000");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100D870045B6000/romfs");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/HLV-C-" + GamecodeTextbox.Text);

                Directory.CreateDirectory("temp");

                string FileFormat1 = @Coverpath1Textbox.Text;
                string tga0        = Path.GetExtension(FileFormat1);
                if (tga0 == ".tga")
                {
                    File.Copy(@Coverpath1Textbox.Text, "temp/cover.tga");
                }
                string FileFormat = @Coverpath1Textbox.Text;
                string tga        = Path.GetExtension(FileFormat);
                if (tga == ".jpg")
                {
                    using (Bitmap original = new Bitmap(@Coverpath1Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/cover.tga");
                }
                string FileFormat2 = @Coverpath1Textbox.Text;
                string tga1        = Path.GetExtension(FileFormat2);
                if (tga1 == ".png")
                {
                    using (Bitmap original = new Bitmap(@Coverpath1Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/cover.tga");
                }

                string FileFormat00 = @Coverpath2Textbox.Text;
                string tga00        = Path.GetExtension(FileFormat00);
                if (tga00 == ".tga")
                {
                    File.Copy(@Coverpath2Textbox.Text, "temp/screenshot.tga");
                }
                string FileFormat3 = @Coverpath2Textbox.Text;
                string tga3        = Path.GetExtension(FileFormat3);
                if (tga3 == ".jpg")
                {
                    using (Bitmap original = new Bitmap(@Coverpath2Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/screenshot.tga");
                }
                string FileFormat4 = @Coverpath2Textbox.Text;
                string tga4        = Path.GetExtension(FileFormat4);
                if (tga4 == ".png")
                {
                    using (Bitmap original = new Bitmap(Coverpath2Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/screenshot.tga");
                }

                string filecheck9 = "cover.tga";
                if (File.Exists(filecheck9))
                {
                    File.Delete(@"cover.tga");
                }

                string filecheck10 = "screenshot.tga";
                if (File.Exists(filecheck10))
                {
                    File.Delete(@"screenshot.tga");
                }

                File.Move(@"temp/screenshot.tga", "screenshot.tga");
                File.Move(@"temp/cover.tga", "cover.tga");

                Nconvert.RunCommand($"-i cover.tga -o cover.xtx --mip-filter box --minmip 5 -f rgba8");
                Nconvert.RunCommand($"-i screenshot.tga -o screenshot.xtx --mip-filter box --minmip 5 -f rgba8");

                Zconvert.RunCommand($"cover.xtx");
                File.Copy(@"cover.xtx.zlib", "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/HLV-C-" + GamecodeTextbox.Text + "\\" + "HLV-C-" + GamecodeTextbox.Text + "00.xtx.z");
                File.Delete(@"cover.xtx");
                File.Delete(@"cover.xtx.zlib");

                Zconvert.RunCommand($"screenshot.xtx");
                File.Copy(@"screenshot.xtx.zlib", "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/HLV-C-" + GamecodeTextbox.Text + "\\" + "HLV-C-" + GamecodeTextbox.Text + ".xtx.z");
                File.Delete(@"screenshot.xtx");
                File.Delete(@"screenshot.xtx.zlib");

                File.Copy(@GamepathTextbox.Text, "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/HLV-C-" + GamecodeTextbox.Text + "\\" + "HLV-C-" + GamecodeTextbox.Text + ".nes");

                File.Copy(@TitledbTextbox.Text, "temp/lclassics.titlesdb");
                string filecheck11 = "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/lclassics.titlesdb";
                if (File.Exists(filecheck11))
                {
                    File.Delete(@"NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/lclassics.titlesdb");
                }
                File.Move(@"temp/lclassics.titlesdb", "NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/lclassics.titlesdb");
                Directory.Delete(@"temp");

                var lines2 = File.ReadAllLines("NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/lclassics.titlesdb");
                File.WriteAllLines("NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/lclassics.titlesdb", lines2.Take(lines2.Length - 2).ToArray());
                using (StreamWriter db = new FileInfo("NES_ONLINE_Mod/titles/0100D870045B6000/romfs/titles/lclassics.titlesdb").AppendText())
                {
                    db.WriteLine("        ,");
                    db.WriteLine("        {");
                    db.WriteLine("            \"sort_title\": \"" + SortTitleTextbox.Text + "\",");
                    db.WriteLine("            \"publisher\": \"" + PublisherTextbox.Text + "\",");
                    db.WriteLine("            \"code\": \"HLV-C-" + GamecodeTextbox.Text + "\",");
                    db.WriteLine("            \"rom\": \"/titles/HLV-C-" + GamecodeTextbox.Text + "/HLV-C-" + GamecodeTextbox.Text + ".nes\",");
                    db.WriteLine("            \"copyright\": \"" + CopyrightTextbox.Text + "\",");
                    db.WriteLine("            \"title\": \"" + GametitleTextbox.Text + "\",");
                    db.WriteLine("            \"volume\": " + VolumeTextbox.Text + ",");
                    db.WriteLine("            \"release_date\": \"1987-12-01\",");
                    db.WriteLine("            \"players_count\": 1,");
                    db.WriteLine("            \"cover\": \"/titles/HLV-C-" + GamecodeTextbox.Text + "/HLV-C-" + GamecodeTextbox.Text + ".xtx.z\",");
                    db.WriteLine("            \"overscan\": [" + OverscanTextbox.Text + ", " + OverscanTextbox2.Text + ", " + OverscanTextbox3.Text + ", " + OverscanTextbox4.Text + "],");
                    db.WriteLine("            \"armet_version\": \"v1\",");
                    db.WriteLine("            \"lcla6_release_date\": \"2018-09-01\",");
                    db.WriteLine("            \"save_count\": 0,");
                    if (SimultanusFalseRadioButton.Checked)
                    {
                        db.WriteLine("            \"simultaneous\": false,");
                    }
                    ;
                    if (SimultanusTrueRadioButton.Checked)
                    {
                        db.WriteLine("            \"simultaneous\": true,");
                    }
                    ;
                    db.WriteLine("            \"fadein\": [" + FadeinTextbox.Text + ", " + FadeinTextbox2.Text + "],");
                    db.WriteLine("            \"details_screen\": \"/titles/HLV-C-" + GamecodeTextbox.Text + "/HLV-C-" + GamecodeTextbox.Text + "00.xtx.z\",");
                    db.WriteLine("            \"armet_threshold\": 80,");
                    db.WriteLine("            \"sort_publisher\": \"" + PublisherTextbox.Text + "\"");
                    db.WriteLine("        }");
                    db.WriteLine("    ]");
                    db.WriteLine("}");
                    db.Close();
                }
            }
            else if (JPCheckbox.Checked)
            {
                Directory.CreateDirectory("NES_ONLINE_Mod");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100B4E00444C000");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles");
                Directory.CreateDirectory("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/CLV-G-" + GamecodeTextbox.Text);

                Directory.CreateDirectory("temp");

                string FileFormat1 = @Coverpath1Textbox.Text;
                string tga0        = Path.GetExtension(FileFormat1);
                if (tga0 == ".tga")
                {
                    File.Copy(@Coverpath1Textbox.Text, "temp/cover.tga");
                }
                string FileFormat = @Coverpath1Textbox.Text;
                string tga        = Path.GetExtension(FileFormat);
                if (tga == ".jpg")
                {
                    using (Bitmap original = new Bitmap(@Coverpath1Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/cover.tga");
                }
                string FileFormat2 = @Coverpath1Textbox.Text;
                string tga1        = Path.GetExtension(FileFormat2);
                if (tga1 == ".png")
                {
                    using (Bitmap original = new Bitmap(@Coverpath1Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/cover.tga");
                }

                string FileFormat00 = @Coverpath2Textbox.Text;
                string tga00        = Path.GetExtension(FileFormat00);
                if (tga00 == ".tga")
                {
                    File.Copy(@Coverpath2Textbox.Text, "temp/screenshot.tga");
                }
                string FileFormat3 = @Coverpath2Textbox.Text;
                string tga3        = Path.GetExtension(FileFormat3);
                if (tga3 == ".jpg")
                {
                    using (Bitmap original = new Bitmap(@Coverpath2Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/screenshot.tga");
                }
                string FileFormat4 = @Coverpath2Textbox.Text;
                string tga4        = Path.GetExtension(FileFormat4);
                if (tga4 == ".png")
                {
                    using (Bitmap original = new Bitmap(Coverpath2Textbox.Text))
                        using (Bitmap clone = new Bitmap(original))
                            using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                                T = (TGA)newbmp;
                    T.Save("temp/screenshot.tga");
                }

                string filecheck9 = "cover.tga";
                if (File.Exists(filecheck9))
                {
                    File.Delete(@"cover.tga");
                }

                string filecheck10 = "screenshot.tga";
                if (File.Exists(filecheck10))
                {
                    File.Delete(@"screenshot.tga");
                }

                File.Move(@"temp/cover.tga", "cover.tga");
                File.Move(@"temp/screenshot.tga", "screenshot.tga");

                Nconvert.RunCommand($"-i cover.tga -o cover.xtx --mip-filter box --minmip 5 -f rgba8");
                Nconvert.RunCommand($"-i screenshot.tga -o screenshot.xtx --mip-filter box --minmip 5 -f rgba8");

                Zconvert.RunCommand($"cover.xtx");
                File.Copy(@"cover.xtx.zlib", "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/CLV-G-" + GamecodeTextbox.Text + "\\" + "CLV-G-" + GamecodeTextbox.Text + "00.xtx.z");
                File.Delete(@"cover.xtx");
                File.Delete(@"cover.xtx.zlib");

                Zconvert.RunCommand($"screenshot.xtx");
                File.Copy(@"screenshot.xtx.zlib", "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/CLV-G-" + GamecodeTextbox.Text + "\\" + "CLV-G-" + GamecodeTextbox.Text + ".xtx.z");
                File.Delete(@"screenshot.xtx");
                File.Delete(@"screenshot.xtx.zlib");

                File.Copy(@GamepathTextbox.Text, "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/CLV-G-" + GamecodeTextbox.Text + "\\" + "CLV-G-" + GamecodeTextbox.Text + ".nes");

                File.Copy(@TitledbTextbox.Text, "temp/lclassics.titlesdb");
                string filecheck11 = "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb";
                if (File.Exists(filecheck11))
                {
                    File.Delete(@"NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb");
                }
                File.Move(@"temp/lclassics.titlesdb", "NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb");
                Directory.Delete(@"temp");

                if (SimultanusFalseRadioButton.Checked)
                {
                    string fileContent1 = File.ReadAllText("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb");
                    fileContent1 = fileContent1.Remove(fileContent1.Length - 2) +
                                   " ,{\"sort_title\": \"" + SortTitleTextbox.Text + "\", " +
                                   "\"publisher\": \"" + PublisherTextbox.Text + "\", " +
                                   "\"code\": \"CLV-G-" + GamecodeTextbox.Text + "\", " +
                                   "\"rom\": \"/titles/CLV-G-" + GamecodeTextbox.Text + "/CLV-G-" + GamecodeTextbox.Text + ".nes\", " +
                                   "\"copyright\": \"" + CopyrightTextbox.Text + "\", " +
                                   "\"title\": \"" + GametitleTextbox.Text + "\", " +
                                   "\"volume\": " + VolumeTextbox.Text + ", " +
                                   "\"release_date\": \"1987-12-01\", " +
                                   "\"players_count\": 1," +
                                   "\"cover\": \"/titles/CLV-G-" + GamecodeTextbox.Text + "/CLV-G-" + GamecodeTextbox.Text + ".xtx.z\"," +
                                   "\"overscan\": [" + OverscanTextbox.Text + ", " + OverscanTextbox2.Text + ", " + OverscanTextbox3.Text + ", " + OverscanTextbox4.Text + "]," +
                                   "\"armet_version\": \"v1\"," +
                                   "\"lcla6_release_date\": \"2018-09-01\"," +
                                   "\"save_count\": 0," +
                                   "\"simultaneous\": false," +
                                   "\"fadein\": [" + FadeinTextbox.Text + ", " + FadeinTextbox2.Text + "]," +
                                   "\"details_screen\": \"/titles/CLV-G-" + GamecodeTextbox.Text + "/CLV-G-" + GamecodeTextbox.Text + "00.xtx.z\"," +
                                   "\"armet_threshold\": 80," +
                                   "\"sort_publisher\": \"" + PublisherTextbox.Text + "\"" + "}]}";
                    File.WriteAllText("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb", fileContent1);
                }
                ;
                if (SimultanusTrueRadioButton.Checked)
                {
                    string fileContent2 = File.ReadAllText("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb");
                    fileContent2 = fileContent2.Remove(fileContent2.Length - 2) +
                                   " ,{\"sort_title\": \"" + SortTitleTextbox.Text + "\", " +
                                   "\"publisher\": \"" + PublisherTextbox.Text + "\", " +
                                   "\"code\": \"CLV-G-" + GamecodeTextbox.Text + "\", " +
                                   "\"rom\": \"/titles/CLV-G-" + GamecodeTextbox.Text + "/CLV-G-" + GamecodeTextbox.Text + ".nes\", " +
                                   "\"copyright\": \"" + CopyrightTextbox.Text + "\", " +
                                   "\"title\": \"" + GametitleTextbox.Text + "\", " +
                                   "\"volume\": " + VolumeTextbox.Text + ", " +
                                   "\"release_date\": \"1987-12-01\", " +
                                   "\"players_count\": 1," +
                                   "\"cover\": \"/titles/CLV-G-" + GamecodeTextbox.Text + "/CLV-G-" + GamecodeTextbox.Text + ".xtx.z\"," +
                                   "\"overscan\": [" + OverscanTextbox.Text + ", " + OverscanTextbox2.Text + ", " + OverscanTextbox3.Text + ", " + OverscanTextbox4.Text + "]," +
                                   "\"armet_version\": \"v1\"," +
                                   "\"lcla6_release_date\": \"2018-09-01\"," +
                                   "\"save_count\": 0," +
                                   "\"simultaneous\": true," +
                                   "\"fadein\": [" + FadeinTextbox.Text + ", " + FadeinTextbox2.Text + "]," +
                                   "\"details_screen\": \"/titles/CLV-G-" + GamecodeTextbox.Text + "/CLV-G-" + GamecodeTextbox.Text + "00.xtx.z\"," +
                                   "\"armet_threshold\": 80," +
                                   "\"sort_publisher\": \"" + PublisherTextbox.Text + "\"" + "}]}";
                    File.WriteAllText("NES_ONLINE_Mod/titles/0100B4E00444C000/romfs/titles/lclassics.titlesdb", fileContent2);
                }
                ;
            }
            InjectCompleted();
        }
コード例 #13
0
        public static bool ExportTexture2D(AssetItem item, string exportPath)
        {
            var m_Texture2D = (Texture2D)item.Asset;

            if (Properties.Settings.Default.convertTexture)
            {
                var bitmap = m_Texture2D.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                ImageFormat format = null;
                var         ext    = Properties.Settings.Default.convertType;
                var         tga    = false;
                switch (ext)
                {
                case "BMP":
                    format = ImageFormat.Bmp;
                    break;

                case "PNG":
                    format = ImageFormat.Png;
                    break;

                case "JPEG":
                    format = ImageFormat.Jpeg;
                    break;

                case "TGA":
                    tga = true;
                    break;
                }

                if (!TryExportFile(exportPath, item, "." + ext.ToLower(), out var exportFullPath))
                {
                    return(false);
                }
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullPath);
                }
                else
                {
                    try
                    {
                        bitmap.Save(exportFullPath, format);
                        bitmap.Dispose();
                    }
                    catch (ExternalException)
                    {
                        return(ExportTexture2D(item, exportPath));
                    }
                }

                return(true);
            }
            else
            {
                if (!TryExportFile(exportPath, item, ".tex", out var exportFullPath))
                {
                    return(false);
                }
                File.WriteAllBytes(exportFullPath, m_Texture2D.image_data.GetData());
                return(true);
            }
        }