Exemplo n.º 1
0
        public void AddToMod(IGameFile file)
        {
            var pm      = ServiceLocator.Default.ResolveType <IProjectManager>();
            var project = ((EditorProject)(pm.ActiveProject));

            switch (project.GameType)
            {
            case GameType.Witcher3:
            {
                var witcherProject = project as Tw3Project;
                var DiskPath       = Path.Combine(witcherProject.ModCookedDirectory, file.Name);
                Directory.CreateDirectory(Path.GetDirectoryName(DiskPath));
                using (FileStream fs = new FileStream(DiskPath, FileMode.Create))
                {
                    file.Extract(fs);
                }
                break;
            }

            case GameType.Cyberpunk2077:
            {
                var cyberpunkProject = project as Cp77Project;
                var DiskPath         = Path.Combine(cyberpunkProject.ModDirectory, file.Name);
                Directory.CreateDirectory(Path.GetDirectoryName(DiskPath));
                using (FileStream fs = new FileStream(DiskPath, FileMode.Create))
                {
                    file.Extract(fs);
                }
                break;
            }

            default:
                break;
            }
        }
        private static void PreviewWem(PropertiesViewModel propertiesViewModel, IFileSystemViewModel selectedItem, IGameFile selectedGameFile)
        {
            propertiesViewModel.IsAudioPreviewVisible = true;

            var managerCacheDir = ISettingsManager.GetTemp_Audio_importPath();

            _ = Directory.CreateDirectory(managerCacheDir);

            var endPath = Path.Combine(managerCacheDir, Path.GetFileName(selectedItem.Name) ?? throw new InvalidOperationException());

            foreach (var f in Directory.GetFiles(managerCacheDir))
            {
                try
                {
                    File.Delete(f);
                }
                catch
                {
                    // ignored
                }
            }

            using (var fs = new FileStream(endPath, FileMode.Create, FileAccess.Write))
            {
                selectedGameFile.Extract(fs);
            }

            if (File.Exists(endPath))
            {
                propertiesViewModel.AddAudioItem(endPath);
            }
        }
        private static void PreviewMesh(PropertiesViewModel propertiesViewModel, RedFileViewModel selectedItem, IGameFile selectedGameFile)
        {
            propertiesViewModel.AB_MeshPreviewVisible = true;

            var managerCacheDir = ISettingsManager.GetTemp_MeshPath();

            _ = Directory.CreateDirectory(managerCacheDir);
            foreach (var f in Directory.GetFiles(managerCacheDir))
            {
                try
                {
                    File.Delete(f);
                }
                catch
                {
                    // ignored
                }
            }

            using (var meshStream = new MemoryStream())
            {
                selectedGameFile.Extract(meshStream);
                meshStream.Seek(0, SeekOrigin.Begin);
                string outPath = Path.Combine(ISettingsManager.GetTemp_OBJPath(), Path.GetFileName(selectedItem.Name) ?? throw new InvalidOperationException());
                outPath = Path.ChangeExtension(outPath, ".glb");
                if (Locator.Current.GetService <MeshTools>().ExportMeshPreviewer(meshStream, new FileInfo(outPath)))
                {
                    propertiesViewModel.LoadModel(outPath);
                }
                meshStream.Dispose();
                meshStream.Close();
            }
        }
Exemplo n.º 4
0
        private async void PreviewTexture(PropertiesViewModel propertiesViewModel, FileEntryViewModel selectedItem, IGameFile selectedGameFile)
        {
            propertiesViewModel.IsImagePreviewVisible = true;

            var man = ServiceLocator.Default.ResolveType <ModTools>();

            // extract cr2w to stream
            await using var cr2wstream = new MemoryStream();
            selectedGameFile.Extract(cr2wstream);

            // convert xbm to dds stream
            await using var ddsstream = new MemoryStream();
            var expargs = new XbmExportArgs {
                Flip = false, UncookExtension = EUncookExtension.tga
            };

            man.ConvertXbmToDdsStream(cr2wstream, ddsstream, out _);

            // try loading it in pfim
            try
            {
                var qa = await ImageDecoder.RenderToBitmapSourceDds(ddsstream);

                if (qa != null)
                {
                    StaticReferences.GlobalPropertiesView.LoadImage(qa);
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 5
0
        public string ExportMeshWithoutRigPreviewer(IGameFile file, string FilePath, string tempmodels, bool LodFilter = true, bool isGLBinary = true)
        {
            using var meshStream = new MemoryStream();
            file.Extract(meshStream);
            meshStream.Seek(0, SeekOrigin.Begin);
            var cr2w = _wolvenkitFileService.TryReadRED4File(meshStream);

            return(ExportMeshWithoutRigPreviewerInner(meshStream, cr2w, FilePath, tempmodels, LodFilter, isGLBinary));
        }
Exemplo n.º 6
0
        public string ExportMeshSimple(IGameFile file, string FilePath, string v)
        {
            using var meshStream = new MemoryStream();
            file.Extract(meshStream);
            meshStream.Seek(0, SeekOrigin.Begin);
            var cr2w = _wolvenkitFileService.TryReadRED4File(meshStream);

            if (cr2w == null || !cr2w.Chunks.Select(_ => _.Data).OfType <rendRenderMeshBlob>().Any() || !cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().Any())
            {
                return("");
            }
            var ms = GetMeshBufferStream(meshStream, cr2w);

            var meshinfo = GetMeshesinfo(cr2w);

            var expMeshes = ContainRawMesh(ms, meshinfo, true);

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

            if (Directory.GetFiles(v).Length > 5)
            {
                foreach (var f in Directory.GetFiles(v))
                {
                    try
                    {
                        File.Delete(f);
                    }
                    catch
                    {
                    }
                }
            }

            ModelRoot model = RawMeshesToMinimalGLTF(expMeshes);
            string    outfile;


            if (true)
            {
                outfile = Path.Combine(v, Path.GetFileNameWithoutExtension(FilePath) + ".glb");
                model.SaveGLB(outfile);
            }

            meshStream.Dispose();
            meshStream.Close();

            return(outfile);
        }
Exemplo n.º 7
0
        private void AddToMod(IGameFile file)
        {
            var project = _projectManager.ActiveProject;

            switch (project.GameType)
            {
            case GameType.Witcher3:
            {
                //if (project is Tw3Project witcherProject)
                //{
                //    var diskPathInfo = new FileInfo(Path.Combine(witcherProject.ModCookedDirectory, file.Name));
                //    if (diskPathInfo.Directory == null)
                //    {
                //        break;
                //    }

                //    Directory.CreateDirectory(diskPathInfo.Directory.FullName);
                //    using var fs = new FileStream(diskPathInfo.FullName, FileMode.Create);
                //    file.Extract(fs);
                //}
                break;
            }

            case GameType.Cyberpunk2077:
            {
                if (project is Cp77Project cyberpunkProject)
                {
                    var diskPathInfo = new FileInfo(Path.Combine(cyberpunkProject.ModDirectory, file.Name));
                    if (diskPathInfo.Directory == null)
                    {
                        break;
                    }

                    Directory.CreateDirectory(diskPathInfo.Directory.FullName);
                    using var fs = new FileStream(diskPathInfo.FullName, FileMode.Create);
                    file.Extract(fs);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 8
0
        private async void PreviewTexture(PropertiesViewModel propertiesViewModel, RedFileViewModel selectedItem, IGameFile selectedGameFile)
        {
            propertiesViewModel.IsImagePreviewVisible = true;
            propertiesViewModel.SelectedIndex         = 3;

            var man = Locator.Current.GetService <IModTools>();

            // extract cr2w to stream
            await using var cr2wstream = new MemoryStream();
            selectedGameFile.Extract(cr2wstream);

            // convert xbm to dds stream
            await using var ddsstream = new MemoryStream();
            var expargs = new XbmExportArgs {
                Flip = false, UncookExtension = EUncookExtension.tga
            };

            if (man != null)
            {
                man.ConvertXbmToDdsStream(cr2wstream, ddsstream, out _);
            }

            // try loading it in pfim
            try
            {
                var qa = await ImageDecoder.RenderToBitmapSourceDds(ddsstream);

                if (qa != null)
                {
                    propertiesViewModel.LoadImage(qa);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
Exemplo n.º 9
0
        private void AddToMod(IGameFile file)
        {
            var project = _projectManager.ActiveProject;

            switch (project.GameType)
            {
            case GameType.Witcher3:
            {
                //if (project is Tw3Project witcherProject)
                //{
                //    var diskPathInfo = new FileInfo(Path.Combine(witcherProject.ModCookedDirectory, file.Name));
                //    if (diskPathInfo.Directory == null)
                //    {
                //        break;
                //    }

                //    Directory.CreateDirectory(diskPathInfo.Directory.FullName);
                //    using var fs = new FileStream(diskPathInfo.FullName, FileMode.Create);
                //    file.Extract(fs);
                //}
                break;
            }

            case GameType.Cyberpunk2077:
            {
                if (project is Cp77Project cyberpunkProject)
                {
                    var diskPathInfo = new FileInfo(Path.Combine(cyberpunkProject.ModDirectory, file.Name));
                    if (diskPathInfo.Directory == null)
                    {
                        break;
                    }

                    if (File.Exists(diskPathInfo.FullName))
                    {
                        if (MessageBox.Show($"The file {file.Name} already exists in project - overwrite it with game file?", $"Confirm overwrite: {file.Name}", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            using var fs = new FileStream(diskPathInfo.FullName, FileMode.Create);
                            file.Extract(fs);
                            _loggerService.Success($"Overwrote existing file with game file: {file.Name}");
                        }
                        else
                        {
                            _loggerService.Info($"Declined to overwrite existing file: {file.Name}");
                        }
                    }
                    else
                    {
                        Directory.CreateDirectory(diskPathInfo.Directory.FullName);
                        using var fs = new FileStream(diskPathInfo.FullName, FileMode.Create);
                        file.Extract(fs);
                        _loggerService.Success($"Added game file to project: {file.Name}");
                    }
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }