public void InitalizeMap() { using (FileStream fileStream = File.OpenRead(_cacheLocation)) { var reader = new EndianReader(fileStream, Endian.BigEndian); try { _cacheFile = CacheFileLoader.LoadCacheFile(reader, App.AssemblyStorage.AssemblySettings.DefaultDatabase, out _buildInfo); #if DEBUG Dispatcher.Invoke(new Action(() => contentTabs.Items.Add(new CloseableTabItem { Header = new ContentControl { Content = "Debug Tools", ContextMenu = BaseContextMenu }, Content = new DebugTools(_cacheFile) }))); #endif } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { if (!_0xabad1dea.IWff.Heman(reader)) { StatusUpdater.Update("Not a supported target engine"); MetroMessageBox.Show("Unable to open cache file", ex.Message + ".\r\nWhy not add support in the 'Formats' folder?"); } else { StatusUpdater.Update("HEYYEYAAEYAAAEYAEYAA"); } App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(_tab); })); return; } _mapManager = new FileStreamManager(_cacheLocation, reader.Endianness); // Build SID trie _stringIdTrie = new Trie(); if (_cacheFile.StringIDs != null) _stringIdTrie.AddRange(_cacheFile.StringIDs); Dispatcher.Invoke(new Action(delegate { if (App.AssemblyStorage.AssemblySettings.StartpageHideOnLaunch) App.AssemblyStorage.AssemblySettings.HomeWindow.ExternalTabClose(Home.TabGenre.StartPage); })); // Set up RTE switch (_cacheFile.Engine) { case EngineType.SecondGeneration: _rteProvider = new H2VistaRTEProvider("halo2.exe"); break; case EngineType.ThirdGeneration: _rteProvider = new XBDMRTEProvider(App.AssemblyStorage.AssemblySettings.Xbdm); break; } Dispatcher.Invoke(new Action(() => StatusUpdater.Update("Loaded Cache File"))); // Add to Recents Dispatcher.Invoke(new Action(delegate { RecentFiles.AddNewEntry(Path.GetFileName(_cacheLocation), _cacheLocation, _buildInfo.Settings.GetSetting<string>("shortName"), Settings.RecentFileType.Cache); StatusUpdater.Update("Added To Recents"); })); /*ITag dice = _cacheFile.Tags[0x0102]; IRenderModel diceModel = _cacheFile.ResourceMetaLoader.LoadRenderModelMeta(dice, reader); var resourceTable = _cacheFile.Resources.LoadResourceTable(reader); Resource diceResource = resourceTable.Resources[diceModel.ModelResourceIndex.Index]; ICacheFile resourceFile = _cacheFile; Stream resourceStream = fileStream; if (diceResource.Location.PrimaryPage.FilePath != null) { resourceStream = File.OpenRead(Path.Combine(Path.GetDirectoryName(_cacheLocation), Path.GetFileName(diceResource.Location.PrimaryPage.FilePath))); resourceFile = new ThirdGenCacheFile(new EndianReader(resourceStream, Endian.BigEndian), _buildInfo, _cacheFile.BuildString); } ResourcePageExtractor extractor = new ResourcePageExtractor(resourceFile); string path = Path.GetTempFileName(); FileStream pageStream = File.Open(path, FileMode.Create, FileAccess.ReadWrite); extractor.ExtractPage(diceResource.Location.PrimaryPage, resourceStream, pageStream); if (resourceStream != fileStream) resourceStream.Close(); IReader pageReader = new EndianReader(pageStream, Endian.BigEndian); pageReader.SeekTo(diceResource.Location.PrimaryOffset); ObjExporter exporter = new ObjExporter("C:\\Users\\Aaron\\Desktop\\test.obj"); System.Collections.BitArray sections = new System.Collections.BitArray(diceModel.Sections.Length, true); //sections[3] = true; //sections[1] = true; ModelReader.ReadModelData(pageReader, diceModel, sections, _buildInfo, exporter); exporter.Close(); pageReader.Close();*/ LoadHeader(); LoadTags(); LoadLocales(); LoadScripts(); } }
public void InitalizeMap() { using (var fileStream = File.OpenRead(_cacheLocation)) { var reader = new EndianReader(fileStream, Endian.BigEndian); var formatsPath = Path.Combine(VariousFunctions.GetApplicationLocation(), "Formats"); var supportedBuildsPath = Path.Combine(formatsPath, "SupportedBuilds.xml"); _layoutLoader = new BuildInfoLoader(supportedBuildsPath, formatsPath); try { _cacheFile = CacheFileLoader.LoadCacheFile(reader, _layoutLoader, out _buildInfo); } catch (NotSupportedException ex) { Dispatcher.Invoke(new Action(delegate { if (!_0xabad1dea.IWff.Heman(reader)) { StatusUpdater.Update("Not a supported target engine"); MetroMessageBox.Show("Unable to open cache file", ex.Message + ".\r\nWhy not add support in the 'Formats' folder?"); } else { StatusUpdater.Update("HEYYEYAAEYAAAEYAEYAA"); } Settings.homeWindow.ExternalTabClose((TabItem)Parent); })); return; } _mapManager = new FileStreamManager(_cacheLocation, reader.Endianness); // Build SID trie _stringIDTrie = new Trie(); _stringIDTrie.AddRange(_cacheFile.StringIDs); Dispatcher.Invoke(new Action(delegate { if (Settings.startpageHideOnLaunch) Settings.homeWindow.ExternalTabClose(Home.TabGenre.StartPage); })); // Set up RTE switch (_cacheFile.Engine) { case EngineType.SecondGeneration: _rteProvider = new H2VistaRTEProvider("halo2.exe"); break; case EngineType.ThirdGeneration: _rteProvider = new XBDMRTEProvider(Settings.xbdm); break; } Dispatcher.Invoke(new Action(() => StatusUpdater.Update("Loaded Cache File"))); // Add to Recents Dispatcher.Invoke(new Action(delegate { RecentFiles.AddNewEntry(Path.GetFileName(_cacheLocation), _cacheLocation, _buildInfo.ShortName, Settings.RecentFileType.Cache); StatusUpdater.Update("Added To Recents"); })); LoadHeader(); LoadMetaData(); LoadTags(); LoadLocales(); LoadScripts(); } }