private async void ReloadContextClick(object sender, RoutedEventArgs e) { IEnumerable <ICompletionData> completionData = await Task.Run(() => GenerateStaticCompletionData()); _staticCompletionData = completionData; StatusUpdater.Update("Context Reloaded"); }
private static void ValidateHistory() { char[] fakeHistory = histroyOfEggs.ToArray(); Array.Reverse(fakeHistory); string realHistory = new string(fakeHistory).ToLower(); if (realHistory.EndsWith("comic")) { try { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/Assembly;component/Helpers/0xabad1dea/TragicSans.xaml", UriKind.Relative) }); } catch { } } else if (realHistory.EndsWith("dingdong")) { try { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/Assembly;component/Helpers/0xabad1dea/DingDong.xaml", UriKind.Relative) }); } catch { } } else if (realHistory.EndsWith("autoaim")) { try { if (IWff.Play()) { StatusUpdater.Update("I know what you did."); } } catch { } } else if (realHistory.EndsWith("wtfisthis")) { try { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("/Assembly;component/Metro/Controls/MetroFonts.xaml", UriKind.Relative) }); } catch { } } }
private void RefreshMeta() { DependencyObject parent = VisualTreeHelper.GetParent(this); while (parent != null) { var haloMap = parent as HaloMap; if (haloMap != null) { haloMap.RefreshTags(); StatusUpdater.Update("Meta Refreshed"); return; } else { parent = VisualTreeHelper.GetParent(parent); } } }
private async void CompileClick(object sender, RoutedEventArgs e) { // Logger Setup string folder = "Compiler"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string logPath = Path.Combine(folder, "ScriptCompiler.log"); using (var logStream = File.Create(logPath)) { // Create the logger and the exception collector. They are used for debugging. var traceListener = new TextWriterTraceListener(logStream); var logger = new ScriptCompilerLogger(traceListener); var exceptionCollector = new ParsingExceptionCollector(); logger.Information($"Attempting to compile: {_scriptFile.Name}, Time: {DateTime.Now}"); try { // Get the script file. string hsc = txtScript.Text; // Measure the time it took to compile the scripts. var stopWatch = Stopwatch.StartNew(); // Compile the scripts. ScriptData compileData = await Task.Run(() => CompileScripts(hsc, _progress, logger, exceptionCollector)); stopWatch.Stop(); var timeSpan = stopWatch.Elapsed; string compilationMessage = $"The scripts were successfully compiled in {Math.Round(timeSpan.TotalSeconds, 3)} seconds."; logger.Information(compilationMessage); // Show the message box. var saveResult = MetroMessageBox.Show("Scripts Compiled", compilationMessage + "\nWARNING: This compiler is not 100% accurate and could corrupt the map in rare cases. Making a backup before proceeding is advisable." + "\n\nDo you want to save the changes to the file?", MetroMessageBox.MessageBoxButtons.YesNo); if (saveResult == MetroMessageBox.MessageBoxResult.Yes) { //TODO: Move this to its own function. await Task.Run(() => { using (IStream stream = _streamManager.OpenReadWrite()) { _scriptFile.SaveScripts(compileData, stream, _progress); _cashefile.SaveChanges(stream); } }); RefreshMeta(); StatusUpdater.Update("Scripts saved"); } } // Handle Parsing Errors. catch (OperationCanceledException opEx) { if (exceptionCollector.ContainsExceptions) { HandleParsingErrors(opEx, exceptionCollector, logger); } else { MetroMessageBox.Show("Operation Canceled", opEx.Message); } } // Handle Compiler Errors. catch (CompilerException compEx) { HandleCompilerErrors(compEx, logger); } finally { logger.Flush(); ResetProgressBar(); } } }
public void RefreshEditor(MetaReader.LoadType type) { // Load Plugin Path string groupName = VariousFunctions.SterilizeTagGroupName(CharConstant.ToString(_tag.RawTag.Group.Magic)).Trim(); _pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins", _buildInfo.Settings.GetSetting <string>("plugins"), groupName); if (!File.Exists(_pluginPath) && _buildInfo.Settings.PathExists("fallbackPlugins")) { _pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins", _buildInfo.Settings.GetSetting <string>("fallbackPlugins"), groupName); } if (_pluginPath == null || !File.Exists(_pluginPath)) { UpdateMetaButtons(false); StatusUpdater.Update("Plugin doesn't exist. It can't be loaded for this tag."); return; } // Store the current search selection so it can be restored int searchSelectedItem = comboSearchResults.SelectedIndex; // Set the stream manager and base offset to use based upon the LoadType IStreamManager streamManager = null; long baseOffset = 0; switch (type) { case MetaReader.LoadType.File: streamManager = _fileManager; baseOffset = (uint)_tag.RawTag.MetaLocation.AsOffset(); break; case MetaReader.LoadType.Memory: if (_rteProvider == null) { goto default; } if (_rteProvider.GetMetaStream(_cache) == null) { ShowConnectionError(); return; } streamManager = new RTEStreamManager(_rteProvider, _cache); baseOffset = _tag.RawTag.MetaLocation.AsPointer(); break; default: MetroMessageBox.Show("Not Supported", "That feature is not supported for this game."); return; } // Load Plugin File using (XmlReader xml = XmlReader.Create(_pluginPath)) { _pluginVisitor = new ThirdGenPluginVisitor(_tags, _stringIdTrie, _cache.MetaArea, App.AssemblyStorage.AssemblySettings.PluginsShowInvisibles); AssemblyPluginLoader.LoadPlugin(xml, _pluginVisitor); } _changeTracker = new FieldChangeTracker(); _fileChanges = new FieldChangeSet(); _memoryChanges = new FieldChangeSet(); var metaReader = new MetaReader(streamManager, baseOffset, _cache, _buildInfo, type, _fileChanges); _flattener = new TagBlockFlattener(metaReader, _changeTracker, _fileChanges); _flattener.Flatten(_pluginVisitor.Values); metaReader.ReadFields(_pluginVisitor.Values); panelMetaComponents.ItemsSource = _pluginVisitor.Values; // Start monitoring fields for changes _changeTracker.RegisterChangeSet(_fileChanges); _changeTracker.RegisterChangeSet(_memoryChanges); _changeTracker.Attach(_pluginVisitor.Values); // Update Meta Toolbar UpdateMetaButtons(true); // Refresh search if needed if (searchSelectedItem != -1) { SearchTimer(null); if (searchSelectedItem <= (comboSearchResults.Items.Count - 1)) { comboSearchResults.SelectedIndex = searchSelectedItem; } } }
private void UpdateMeta(MetaWriter.SaveType type, bool onlyUpdateChanged, bool showActionDialog = true) { if (type == MetaWriter.SaveType.File) { if (!ConfirmNewStringIds()) { return; } using (IStream stream = _fileManager.OpenReadWrite()) { #if DEBUG_SAVE_ALL MetaWriter metaUpdate = new MetaWriter(writer, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo, type, null, _stringIdTrie); #else var metaUpdate = new MetaWriter(stream, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo, type, _fileChanges, _stringIdTrie); #endif metaUpdate.WriteFields(_pluginVisitor.Values); _cache.SaveChanges(stream); _fileChanges.MarkAllUnchanged(); } if (showActionDialog) { MetroMessageBox.Show("Tag Saved", "The changes have been saved back to the original file." + (_buildInfo.UsesCompression && _cache.Engine == EngineType.SecondGeneration ? "\r\n\r\nNote: This file must be compressed from the Tools menu before attempting to load ingame." : "")); } } else if (_rteProvider != null) { var rteProvider = _rteProvider; if (App.AssemblyStorage.AssemblyNetworkPoke.NetworkRteProvider != null) { rteProvider = App.AssemblyStorage.AssemblyNetworkPoke.NetworkRteProvider; } using (IStream metaStream = rteProvider.GetMetaStream(_cache)) { if (metaStream != null) { FieldChangeSet changes = onlyUpdateChanged ? _memoryChanges : null; var metaUpdate = new MetaWriter(metaStream, _tag.RawTag.MetaLocation.AsPointer(), _cache, _buildInfo, type, changes, _stringIdTrie); metaUpdate.WriteFields(_pluginVisitor.Values); if (showActionDialog) { if (onlyUpdateChanged) { StatusUpdater.Update("All changed fields have been poked to the game."); } else { StatusUpdater.Update("The changes have been poked to the game."); } } } else { ShowConnectionError(); } } } }
public void RefreshEditor(MetaReader.LoadType type) { if (!File.Exists(_pluginPath)) { UpdateMetaButtons(false); StatusUpdater.Update("Plugin doesn't exist. It can't be loaded for this tag."); return; } // Store the current search selection so it can be restored int searchSelectedItem = comboSearchResults.SelectedIndex; // Set the stream manager and base offset to use based upon the LoadType IStreamManager streamManager = null; uint baseOffset = 0; uint headerOffset = 0; switch (type) { case MetaReader.LoadType.File: streamManager = _fileManager; baseOffset = (uint)_tag.RawTag.MetaLocation.AsOffset(); headerOffset = _tag.RawTag.HeaderLocation == null ? 0 : (uint)_tag.RawTag.HeaderLocation.AsOffset(); break; case MetaReader.LoadType.Memory: if (_rteProvider == null) { goto default; } using (var testStream = _rteProvider.GetMetaStream(_cache, _tag.RawTag)) { if (testStream == null) { ShowConnectionError(); return; } } streamManager = new RTEStreamManager(_rteProvider, _cache, _tag.RawTag); baseOffset = _tag.RawTag.MetaLocation.AsPointer(); break; default: MetroMessageBox.Show("Not Supported", "That feature is not supported for this game."); return; } // Load Plugin File using (XmlReader xml = XmlReader.Create(_pluginPath)) { _pluginVisitor = new ThirdGenPluginVisitor(_tags, _stringIdTrie, _cache.MetaArea, App.AssemblyStorage.AssemblySettings.PluginsShowInvisibles); AssemblyPluginLoader.LoadPlugin(xml, _pluginVisitor); } _changeTracker = new FieldChangeTracker(); _fileChanges = new FieldChangeSet(); _memoryChanges = new FieldChangeSet(); var metaReader = new MetaReader(streamManager, headerOffset, baseOffset, _cache, _buildInfo, type, _fileChanges); _flattener = new ReflexiveFlattener(metaReader, _changeTracker, _fileChanges); _flattener.Flatten(_pluginVisitor.Values); metaReader.ReadFields(_pluginVisitor.Values); panelMetaComponents.ItemsSource = _pluginVisitor.Values; // Start monitoring fields for changes _changeTracker.RegisterChangeSet(_fileChanges); _changeTracker.RegisterChangeSet(_memoryChanges); _changeTracker.Attach(_pluginVisitor.Values); // Update Meta Toolbar UpdateMetaButtons(true); // Refresh search if needed if (searchSelectedItem != -1) { SearchTimer(null); if (searchSelectedItem <= (comboSearchResults.Items.Count - 1)) { comboSearchResults.SelectedIndex = searchSelectedItem; } } }
public void ProcessTag(ITag bitmapTag) { // I don't feel like writing structure definitions, poaching extraction code // #TODO: Wrap all of this up under a neat function for other uses bitmapTagData = null; processedPages.Clear(); string groupName = VariousFunctions.SterilizeTagGroupName(CharConstant.ToString(bitmapTag.Group.Magic)).Trim(); string pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins", _buildInfo.Settings.GetSetting <string>("plugins"), groupName); if (!File.Exists(pluginPath) && _buildInfo.Settings.PathExists("fallbackPlugins")) { pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins", _buildInfo.Settings.GetSetting <string>("fallbackPlugins"), groupName); } if (pluginPath == null || !File.Exists(pluginPath)) { StatusUpdater.Update("Plugin doesn't exist for 'bitmap', yet somehow you managed to get to the bitmap tab..."); return; } using (IReader reader = _streamManager.OpenRead()) { bitmapTagData = new DataBlockBuilder(reader, bitmapTag, _cache, _buildInfo); using (XmlReader pluginReader = XmlReader.Create(pluginPath)) { AssemblyPluginLoader.LoadPlugin(pluginReader, bitmapTagData); } } bool multiResouceMagic = false; // debugging 8k textures spread across space and time // Resource check if (bitmapTagData.ReferencedResources.Count == 0) { StatusUpdater.Update("Unable to find any resources in the current tag to get bitmap data from!"); return; } else { if (bitmapTagData.ReferencedResources.Count > 1) { multiResouceMagic = true; } if (_cache.Resources != null) // mandrill compiled debugging cache { using (IReader reader = _streamManager.OpenRead()) { resourceTable = _cache.Resources.LoadResourceTable(reader); } } else { StatusUpdater.Update("Unable to find any resources in the cache file at all! Failed to display bitmap."); return; } } // Grab all the raw pages required foreach (DatumIndex resourceDatum in bitmapTagData.ReferencedResources) { Resource currentResource = resourceTable.Resources[resourceDatum.Index]; if (currentResource.Location == null) { StatusUpdater.Update("A bitmap resource had a null location, bad doo doo! Fix yo compiler nerd."); return; } foreach (ResourcePage currentPage in currentResource.Location.PagesToArray()) { if (currentPage == null) { continue; } using (FileStream fileStream = File.OpenRead(_cacheLocation)) { ThirdGenCacheFile resourceFile = (ThirdGenCacheFile)_cache; Stream resourceStream = fileStream; if (currentPage.FilePath != null) // Mandrill compiles everything into a single cache { ResourceCacheInfo resourceCacheInfo = App.AssemblyStorage.AssemblySettings.HalomapResourceCachePaths.FirstOrDefault(r => r.EngineName == _buildInfo.Name); string resourceCachePath = (resourceCacheInfo != null && resourceCacheInfo.ResourceCachePath != "") ? resourceCacheInfo.ResourceCachePath : Path.GetDirectoryName(_cacheLocation); resourceCachePath = Path.Combine(resourceCachePath ?? "", Path.GetFileName(currentPage.FilePath)); if (!File.Exists(resourceCachePath)) { StatusUpdater.Update("Bitmap exists outside of the local cache, was unable to find this cache: " + Path.GetFileName(resourceCachePath)); return; } resourceStream = File.OpenRead(resourceCachePath); resourceFile = new ThirdGenCacheFile(new EndianReader(resourceStream, _cache.Endianness), _buildInfo, Path.GetFileName(_cacheLocation), _cache.BuildString); } byte[] pageData; ResourcePageExtractor pageExtractor = new ResourcePageExtractor(resourceFile); using (MemoryStream pageStream = new MemoryStream()) { pageExtractor.ExtractPage(currentPage, resourceStream, pageStream); pageData = new byte[pageStream.Length]; Buffer.BlockCopy(pageStream.GetBuffer(), 0, pageData, 0, (int)pageStream.Length); } processedPages.Add(pageData); // Store the page for use } } } }