public void LoadReference(PackFile file, bool updateSkeleton = false) { _logger.Here().Information($"Loading reference model - {_packFileService.GetFullPath(file)}"); SceneLoader loader = new SceneLoader(_packFileService, _resourceLibary); var outSkeletonName = ""; var result = loader.Load(file, null, _animationView.Player, ref outSkeletonName); if (result == null) { _logger.Here().Error("Unable to load model"); return; } result.ForeachNode((node) => { node.IsEditable = false; if (node is ISelectable selectable) { selectable.IsSelectable = false; } }); ReferenceMeshRoot.AddObject(result); //_animationView.SetActiveSkeleton(result.f.Header.SkeletonName); }
public static MetaDataFile ParseFile(PackFile file, PackFileService pf) { var fileContent = file.DataSource.ReadData(); var contentLength = fileContent.Count(); MetaDataFile outputFile = new MetaDataFile() { FileName = pf.GetFullPath(file), Version = BitConverter.ToInt32(fileContent, 0) }; if (outputFile.Version != 2) { throw new Exception($"Unknown version - {outputFile.Version} for {outputFile.FileName}"); } if (contentLength > 8) { MetaDataTagItem currentElement = null; int numElements = BitConverter.ToInt32(fileContent, 4); int currentIndex = 0 + 8; // First 4 bytes is the number of elements, next 2 is unknown while (currentIndex != contentLength && (currentElement = GetElement(currentIndex, fileContent, outputFile.FileName, out currentIndex)) != null) { outputFile.TagItems.Add(currentElement); } if (numElements != outputFile.TagItems.Count) { throw new Exception($"Not the expected amount elements. Expected {numElements}, got {outputFile.TagItems.Count}"); } } return(outputFile); }
public void Save() { try { var inputFile = _kitbasherViewModel.MainFile as PackFile; byte[] bytes = GetBytesToSave(); var path = _packFileService.GetFullPath(inputFile); var res = SaveHelper.Save(_packFileService, path, inputFile, bytes); if (res != null) { _kitbasherViewModel.MainFile = res; } } catch (Exception e) { _logger.Here().Error("Error saving model - " + e.ToString()); MessageBox.Show("Saving failed!"); } }
void OnItemDoubleClicked(DataTableRow row) { if (row == null) { return; } var file = _pf.FindFile(row.FileName); var nameSize = row.TagName.Length + 2; using (var stream = new MemoryStream((file as PackFile).DataSource.ReadData())) { var editor = new WpfHexaEditor.HexEditor { Stream = stream, ReadOnlyMode = true, ByteGrouping = WpfHexaEditor.Core.ByteSpacerGroup.FourByte, ByteSpacerPositioning = WpfHexaEditor.Core.ByteSpacerPosition.HexBytePanel, ByteSpacerVisualStyle = WpfHexaEditor.Core.ByteSpacerVisual.Dash, ByteSpacerWidthTickness = WpfHexaEditor.Core.ByteSpacerWidth.Normal, DataStringVisual = WpfHexaEditor.Core.DataVisualType.Decimal, OffSetStringVisual = WpfHexaEditor.Core.DataVisualType.Decimal, CustomBackgroundBlockItems = new List <WpfHexaEditor.Core.CustomBackgroundBlock>() { new WpfHexaEditor.Core.CustomBackgroundBlock() { Color = new SolidColorBrush(Colors.LightGreen), StartOffset = row.DataItem.Start, Length = row.DataItem.Size }, new WpfHexaEditor.Core.CustomBackgroundBlock() { Color = new SolidColorBrush(Colors.LightBlue), StartOffset = row.DataItem.Start - nameSize, Length = nameSize } } }; var form = new Window { Title = _pf.GetFullPath(file as PackFile), Content = editor }; form.ShowDialog(); } }
public static void Save(PackFileService packFileService, PackFile inputFile) { var selectedEditabelPackFile = packFileService.GetEditablePack(); var filePackFileConainer = packFileService.GetPackFileContainer(inputFile); if (selectedEditabelPackFile == null) { MessageBox.Show("No editable pack selected!"); return; } if (filePackFileConainer != selectedEditabelPackFile) { var filePath = packFileService.GetFullPath(inputFile, filePackFileConainer); packFileService.CopyFileFromOtherPackFile(filePackFileConainer, filePath, selectedEditabelPackFile); } }
public void AddAnimationToFragment() { // Find stuff in active slot. var selectedAnimationSlot = MountLinkController.SelectedRiderTag.SelectedItem; AnimationClip newRiderClip = null; if (MountAnimationGeneratorService.IsCopyOnlyAnimation(selectedAnimationSlot.Entry.Value.Slot.Value)) { newRiderClip = _rider.AnimationClip; } else { newRiderClip = CreateAnimationGenerator().GenerateMountAnimation(_mount.AnimationClip, _rider.AnimationClip); } var fileResult = MountAnimationGeneratorService.SaveAnimation(_pfs, _rider.AnimationName.AnimationFile, SavePrefixText.Value, EnsureUniqeFileName.Value, newRiderClip, _newAnimation.Skeleton); if (fileResult == null) { return; } var newAnimSlot = selectedAnimationSlot.Entry.Value.Clone(); newAnimSlot.AnimationFile = _pfs.GetFullPath(fileResult); newAnimSlot.Slot = ActiveFragmentSlot.SelectedItem.Entry.Value.Slot.Clone(); var toRemove = ActiveOutputFragment.SelectedItem.Fragments.FirstOrDefault(x => x.Slot.Id == ActiveFragmentSlot.SelectedItem.Entry.Value.Slot.Id); ActiveOutputFragment.SelectedItem.Fragments.Remove(toRemove); ActiveOutputFragment.SelectedItem.Fragments.Add(newAnimSlot); var bytes = ActiveOutputFragment.SelectedItem.ParentAnimationPack.ToByteArray(); SaveHelper.Save(_pfs, "animations\\animation_tables\\" + ActiveOutputFragment.SelectedItem.ParentAnimationPack.FileName, null, bytes, false); // Update status for the slot thing var possibleValues = ActiveOutputFragment.SelectedItem.Fragments.Select(x => new FragmentStatusSlotItem(x)); ActiveFragmentSlot.UpdatePossibleValues(possibleValues); MountLinkController.ReloadFragments(true, false); }
void BrowseTexture() { using (var browser = new PackFileBrowserWindow(_packfileService)) { browser.ViewModel.Filter.SetExtentions(new List <string>() { ".dds", ".png", }); if (browser.ShowDialog() == true && browser.SelectedFile != null) { try { Path = _packfileService.GetFullPath(browser.SelectedFile); _meshNode.UpdateTexture(Path, _texureType); } catch { UpdateUseTexture(false); } } } }
public void ConfigureAsDecoder() { using (new WaitCursor()) { var allMetaFiles = _pf.FindAllWithExtention(".meta"); //allMetaFiles = allMetaFiles.Where(f => f.Name.Contains("anm.meta")).ToList(); List <MetaDataFile> allMetaData = new List <MetaDataFile>(); MetaDataFile master = new MetaDataFile() { FileName = "Master collection" }; var errorList = new List <Tuple <string, string> >(); foreach (var file in allMetaFiles) { try { var res = MetaDataFileParser.ParseFile(file, _pf); allMetaData.Add(res); foreach (var resultDataItem in res.TagItems) { var masterDataItem = master.TagItems.FirstOrDefault(x => x.Name == resultDataItem.Name && x.Version == resultDataItem.Version); if (masterDataItem == null) { master.TagItems.Add(new MetaDataTagItem() { Name = resultDataItem.Name, Version = resultDataItem.Version }); masterDataItem = master.TagItems.Last(); } foreach (var tag in resultDataItem.DataItems) { masterDataItem.DataItems.Add(tag); } } } catch (Exception e) { errorList.Add(new Tuple <string, string>(_pf.GetFullPath(file), e.Message)); } } var outputFolder = @"C:\temp\MetaDataDecoded\"; foreach (var propSetType in master.TagItems) { var filename = $"{propSetType.DisplayName}_{propSetType.DataItems.Count}.csv"; StringBuilder stringBuilder = new StringBuilder(); var tableDef = _schemaManager.GetMetaDataDefinition(propSetType.Name, propSetType.Version); if (tableDef != null) { var headers = new List <string>() { "FileName", "Error" }; for (int outputRowIndex = 0; outputRowIndex < tableDef.ColumnDefinitions.Count; outputRowIndex++) { headers.Add(tableDef.ColumnDefinitions[outputRowIndex].Name + " - " + tableDef.ColumnDefinitions[outputRowIndex].Type.ToString()); } WriteRow(stringBuilder, headers); for (int i = 0; i < propSetType.DataItems.Count(); i++) { var outputRow = new List <string>(); for (int outputRowIndex = 0; outputRowIndex < tableDef.ColumnDefinitions.Count + 2; outputRowIndex++) { outputRow.Add(""); } var dataRow = new DataTableRow(propSetType.DisplayName, i, tableDef.ColumnDefinitions, propSetType.DataItems[i]); outputRow[0] = propSetType.DataItems[i].ParentFileName; outputRow[1] = dataRow.GetError(); if (string.IsNullOrEmpty(outputRow[1])) { for (int valueIndex = 0; valueIndex < dataRow.Values.Count; valueIndex++) { outputRow[valueIndex + 2] = dataRow.Values[valueIndex].Value; } } WriteRow(stringBuilder, outputRow); } } else { var headers = new List <string>() { "FileName", "Size" }; WriteRow(stringBuilder, headers); for (int i = 0; i < propSetType.DataItems.Count(); i++) { var outputRow = new List <string>() { propSetType.DataItems[i].ParentFileName, propSetType.DataItems[i].Size.ToString() }; WriteRow(stringBuilder, outputRow); } } DirectoryHelper.EnsureCreated(outputFolder); File.WriteAllText(outputFolder + filename, stringBuilder.ToString()); } master.TagItems = master.TagItems.OrderBy(x => x.DisplayName).ToList(); ActiveMentaDataContent.File = master; } }
public static PackFile Save(PackFileService packFileService, string filename, PackFile packFile, byte[] updatedData = null, bool promptSaveOverride = true) { filename = filename.ToLower(); var selectedEditabelPackFile = packFileService.GetEditablePack(); if (selectedEditabelPackFile == null) { MessageBox.Show("No editable pack selected!"); return(null); } var existingFile = packFileService.FindFile(filename, selectedEditabelPackFile); if (existingFile != null && promptSaveOverride) { var fullPath = packFileService.GetFullPath(existingFile as PackFile, selectedEditabelPackFile); if (MessageBox.Show($"Replace existing file?\n{fullPath} \nin packfile:{selectedEditabelPackFile.Name}", "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { var extention = Path.GetExtension(fullPath); using (var browser = new SavePackFileWindow(packFileService)) { browser.ViewModel.Filter.SetExtentions(new List <string>() { extention }); if (browser.ShowDialog() == true) { var path = browser.FilePath; if (path.Contains(extention) == false) { path += extention; } filename = path; existingFile = null; } else { return(null); } } } } if (existingFile == null) { var directoryPath = Path.GetDirectoryName(filename); var justFileName = Path.GetFileName(filename); var data = updatedData; if (data == null) { data = packFile.DataSource.ReadData(); } var newPackFile = new PackFile(justFileName, new MemorySource(data)); packFileService.AddFileToPack(selectedEditabelPackFile, directoryPath, newPackFile); return(newPackFile); } else { if (updatedData == null) { throw new Exception("Trying to update an existing file, but no data is provided"); } packFileService.SaveFile(existingFile as PackFile, updatedData); return(existingFile as PackFile); } }