/// <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++)
            {
                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]);

            return f;
        }
Beispiel #4
0
        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);
        }
        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();
            }
        }