Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        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;
                }
            }
        }
Esempio n. 3
0
        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;
                }
            }
        }