public static void Load() { var asmPlugins = new AssemblyPluginLoader(); if (asmPlugins.plugins != null) { foreach (var p in asmPlugins.plugins) { PluginManager.Register(p); } } if (asmPlugins.templates != null) { foreach (var p in asmPlugins.templates) { TemplateManager.Register(p); } } var xmlPlugins = new XmlBasePluginLoader(); if (xmlPlugins.plugins != null) { foreach (var p in xmlPlugins.plugins) { PluginManager.Register(p); } } }
/// <summary> /// Loads the example "view value as" plugin. /// </summary> /// <returns>The fields created from the "view value as" plugin.</returns> private IList <MetaField> LoadViewValueAsPlugin() { string path = string.Format("{0}\\Examples\\ThirdGenExample.xml", VariousFunctions.GetApplicationLocation() + @"Plugins"); XmlReader reader = XmlReader.Create(path); var plugin = new ThirdGenPluginVisitor(_tags, _stringIdTrie, _cache.MetaArea, true); AssemblyPluginLoader.LoadPlugin(reader, plugin); reader.Close(); return(plugin.Values); }
public override object Execute(List <string> args) { if (args.Count != 3) { return(false); } var inDir = args[0]; var type = args[1]; var outDir = args[2]; TagLayoutWriter writer; switch (type) { case "c#": writer = new CSharpLayoutWriter(); break; case "c++": writer = new CppLayoutWriter(); break; default: return(false); } Directory.CreateDirectory(outDir); // For each tag whose tag group hasn't been processed yet, load its // plugin into a TagLayout and then write it using the layout // writer for the output type. We need an actual tag reference in // order to look up the group name without using a static table. var processedGroups = new HashSet <Tag>(); var numConflicts = 0; foreach (var tag in CacheContext.TagCache.Index.NonNull().Where(tag => !processedGroups.Contains(tag.Group.Tag))) { processedGroups.Add(tag.Group.Tag); // Get the plugin path and skip it if it doesn't exist var pluginFileName = SanitizeGroupTagName(tag.Group.Tag.ToString()) + ".xml"; var pluginPath = Path.Combine(inDir, pluginFileName); if (!File.Exists(pluginPath)) { Console.Error.WriteLine("WARNING: No plugin found for the '{0}' tag group", tag.Group.Tag); continue; } Console.WriteLine("Converting {0}...", pluginFileName); // Load the plugin into a layout AssemblyPluginLoadResults loadedPlugin; var groupName = CacheContext.GetString(tag.Group.Name); using (var reader = XmlReader.Create(pluginPath)) loadedPlugin = AssemblyPluginLoader.LoadPlugin(reader, groupName, tag.Group.Tag); // Warn the user about conflicts numConflicts += loadedPlugin.Conflicts.Count; foreach (var conflict in loadedPlugin.Conflicts) { Console.WriteLine("WARNING: Field \"{0}\" at offset 0x{1:X} in block \"{2}\" conflicts!", conflict.Name, conflict.Offset, conflict.Block ?? "(root)"); } // Write it var outPath = Path.Combine(outDir, writer.GetSuggestedFileName(loadedPlugin.Layout)); writer.WriteLayout(loadedPlugin.Layout, outPath); } Console.WriteLine("Successfully converted {0} plugins!", processedGroups.Count); if (numConflicts > 0) { Console.WriteLine("However, {0} conflicts were found. You MUST fix these yourself!", numConflicts); } return(true); }
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; } } }
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 } } } }