protected void ExportNdfExecute(object obj) { var vm = CollectionViewSource.GetDefaultView(OpenFiles).CurrentItem as EdataFileViewModel; if (vm == null) { return; } var ndf = vm.FilesCollectionView.CurrentItem as EdataContentFile; if (ndf == null) { return; } Settings settings = SettingsManager.Load(); byte[] content = new NdfbinReader().GetUncompressedNdfbinary(vm.EdataManager.GetRawData(ndf)); var f = new FileInfo(ndf.Path); using (var fs = new FileStream(Path.Combine(settings.SavePath, f.Name), FileMode.OpenOrCreate)) { fs.Write(content, 0, content.Length); fs.Flush(); } }
private Model.Ndfbin.NdfBinary ReadTextureBindings(Stream s, MeshFile file) { var buffer = new byte[file.SubHeader.MeshMaterial.Size]; s.Seek(file.SubHeader.MeshMaterial.Offset, SeekOrigin.Begin); s.Read(buffer, 0, buffer.Length); var ndfReader = new NdfbinReader(); return(ndfReader.Read(buffer)); }
/// <summary> /// Virtual call /// </summary> /// <param name="content"></param> public NdfEditorMainViewModel(byte[] content) { OwnerFile = null; EdataFileViewModel = null; var ndfbinReader = new NdfbinReader(); NdfBinary = ndfbinReader.Read(content); InitializeNdfEditor(); SaveNdfbinCommand = new ActionCommand(SaveNdfbinExecute, () => false); }
public NdfEditorMainViewModel(EdataContentFile contentFile, EdataFileViewModel ownerVm) { OwnerFile = contentFile; EdataFileViewModel = ownerVm; var ndfbinReader = new NdfbinReader(); NdfBinary = ndfbinReader.Read(ownerVm.EdataManager.GetRawData(contentFile)); //var ndfbinManager = new NdfbinManager(ownerVm.EdataManager.GetRawData(contentFile)); //NdfbinManager = ndfbinManager; //ndfbinManager.Initialize(); InitializeNdfEditor(); }
public ScenarioFile Read(Stream s) { var f = new ScenarioFile(); var buffer = new byte[10]; s.Read(buffer, 0, buffer.Length); if (!Utils.ByteArrayCompare(Encoding.ASCII.GetBytes("SCENARIO\r\n"), buffer)) { throw new InvalidDataException("Wrong scenario header magic!"); } buffer = new byte[16]; s.Read(buffer, 0, buffer.Length); f.Checksum = buffer; s.Seek(2, SeekOrigin.Current); buffer = new byte[4]; s.Read(buffer, 0, buffer.Length); f.Version = BitConverter.ToInt32(buffer, 0); s.Read(buffer, 0, buffer.Length); int subFilesCount = BitConverter.ToInt32(buffer, 0); for (int i = 0; i < subFilesCount; i++) { f.lastPartStartByte = s.Position; s.Read(buffer, 0, buffer.Length); var contentFileBuffer = new byte[BitConverter.ToUInt32(buffer, 0)]; s.Read(contentFileBuffer, 0, contentFileBuffer.Length); f.ContentFiles.Add(contentFileBuffer); } var reader = new NdfbinReader(); f.NdfBinary = reader.Read(f.ContentFiles[1]); f.ZoneData = ReadZoneData(f.ContentFiles[0]); uncompressedPrintToFile(f.ContentFiles[2], "thirdPart"); return(f); }
public DataType GetDataSource <DataType>(string sourceDataPath) { var separator = sourceDataPath.LastIndexOf(':'); var sourceDataFile = sourceDataPath.Substring(0, separator); var dataObjectPath = sourceDataPath.Substring(separator + 1); if (!_dataSources.ContainsKey(sourceDataFile)) { EdataManager eManager = new EdataManager(sourceDataFile); eManager.ParseEdataFile(); _dataSources.Add(sourceDataFile, new Tuple <EdataManager, Dictionary <string, object> >(eManager, new Dictionary <string, object>())); } var src = _dataSources[sourceDataFile]; var dataManager = src.Item1; var dataObjectDic = src.Item2; var dataObject = dataObjectDic.FirstOrDefault(x => x.Key == dataObjectPath).Value; if (dataObject != null) { return((DataType)dataObject); } else { var dataContentFile = dataManager.Files.FirstOrDefault(f => f.Path.Contains(dataObjectPath)); if (typeof(DataType) == typeof(NdfBinary)) { var ndfbinReader = new NdfbinReader(); object ndfBinary = ndfbinReader.Read(dataManager.GetRawData(dataContentFile)); dataObjectDic.Add(dataObjectPath, ndfBinary); return((DataType)ndfBinary); } if (typeof(DataType) == typeof(TradManager)) { object tm = new TradManager(dataManager.GetRawData(dataContentFile)); dataObjectDic.Add(dataObjectPath, tm); return((DataType)tm); } // Other types not implemented. throw new NotImplementedException(); } }
public NdfDatabase(string fileName) { string everythingNdfbinPattern = @".*everything.ndfbin"; Regex regex = new Regex(everythingNdfbinPattern, RegexOptions.IgnoreCase); var ndfbinReader = new NdfbinReader(); var edataManager = new EdataManager(fileName); edataManager.ParseEdataFile(); var everythingNdfbinRaw = edataManager.Files.Where(t => regex.IsMatch(t.ToString())).First(); everythingNdfbin = ndfbinReader.Read(edataManager.GetRawData(everythingNdfbinRaw)); tShowRoomDeckSerializer = everythingNdfbin.Classes.Where(cls => cls.Name == "TShowRoomDeckSerializer").First(); tUniteAuSolDescriptor = everythingNdfbin.Classes.Where(cls => cls.Name == "TUniteAuSolDescriptor").First(); tUniteDescriptor = everythingNdfbin.Classes.Where(cls => cls.Name == "TUniteDescriptor").First(); tTransportableModuleDescriptor = everythingNdfbin.Classes.Where(cls => cls.Name == "TTransportableModuleDescriptor").First(); tShowRoomDeckRuleManager = everythingNdfbin.Classes.Where(cls => cls.Name == "TShowRoomDeckRuleManager").First(); deckRulesManagerProperties = tShowRoomDeckRuleManager.Instances[0].PropertyValues; }