예제 #1
0
        public void CloneChanges(ObservableCollection <MetaField> changedFields, FieldChangeTracker tracker,
                                 FieldChangeSet changes)
        {
            for (int i = 0; i < changedFields.Count; i++)
            {
                MetaField field     = changedFields[i];
                var       reflexive = field as ReflexiveData;
                bool      changed   = changes.HasChanged(field);
                if (field != null && (changed || reflexive != null))
                {
                    if (_fields[i] == null)
                    {
                        _fields[i] = field.CloneValue();
                        tracker.AttachTo(_fields[i]);
                        if (changed)
                        {
                            tracker.MarkChanged(_fields[i]);
                        }
                        tracker.MarkUnchanged(field);

                        if (reflexive != null)
                        {
                            reflexive.ResetPages();
                        }
                    }
                    else if (field != _fields[i])
                    {
                        throw new InvalidOperationException("Cannot cache changes in a meta field from a different page");
                    }
                }
            }
        }
예제 #2
0
		public void CloneChanges(ObservableCollection<MetaField> changedFields, FieldChangeTracker tracker,
			FieldChangeSet changes)
		{
			for (int i = 0; i < changedFields.Count; i++)
			{
				MetaField field = changedFields[i];
				var reflexive = field as ReflexiveData;
				bool changed = changes.HasChanged(field);
				if (field != null && (changed || reflexive != null))
				{
					if (_fields[i] == null)
					{
						_fields[i] = field.CloneValue();
						tracker.AttachTo(_fields[i]);
						if (changed)
							tracker.MarkChanged(_fields[i]);
						tracker.MarkUnchanged(field);

						if (reflexive != null)
							reflexive.ResetPages();
					}
					else if (field != _fields[i])
					{
						throw new InvalidOperationException("Cannot cache changes in a meta field from a different page");
					}
				}
			}
		}
예제 #3
0
 public MetaReader(IStreamManager streamManager, uint baseOffset, ICacheFile cache, FieldChangeSet ignore)
 {
     _streamManager = streamManager;
     _baseOffset = baseOffset;
     _cache = cache;
     _ignoredFields = ignore;
 }
예제 #4
0
 /// <summary>
 /// Save meta to the Blam Cache File
 /// </summary>
 public MetaWriter(IWriter writer, uint baseOffset, ICacheFile cache, SaveType type, FieldChangeSet changes)
 {
     _writer = writer;
     _baseOffset = baseOffset;
     _cache = cache;
     _type = type;
     _changes = changes;
 }
예제 #5
0
        public MetaReader(IStreamManager streamManager, uint baseOffset, ICacheFile cache, BuildInformation buildInfo, FieldChangeSet ignore)
        {
            _streamManager = streamManager;
            BaseOffset = baseOffset;
            _cache = cache;
            _ignoredFields = ignore;

            // Load layouts
            _reflexiveLayout = buildInfo.GetLayout("reflexive");
            _tagRefLayout = buildInfo.GetLayout("tag reference");
            _dataRefLayout = buildInfo.GetLayout("data reference");
        }
예제 #6
0
        /// <summary>
        /// Save meta to the Blam Cache File
        /// </summary>
        public MetaWriter(IWriter writer, uint baseOffset, ICacheFile cache, BuildInformation buildInfo, SaveType type, FieldChangeSet changes)
        {
            _writer = writer;
            _baseOffset = baseOffset;
            _cache = cache;
            _type = type;
            _changes = changes;

            // Load layouts
            _reflexiveLayout = buildInfo.GetLayout("reflexive");
            _tagRefLayout = buildInfo.GetLayout("tag reference");
            _dataRefLayout = buildInfo.GetLayout("data reference");
        }
예제 #7
0
		public FlattenedReflexive(FlattenedReflexive parent, ReflexiveData template,
			ObservableCollection<MetaField> topLevelFields, FieldChangeTracker tracker, FieldChangeSet changes)
		{
			_parent = parent;
			_template = template;
			_activeReflexive = template;
			_synchronizedReflexives.Add(template);
			if (template.HasChildren)
				_lastPage = template.Pages[template.CurrentIndex];
			_topLevelFields = topLevelFields;
			_tracker = tracker;
			_changes = changes;
		}
예제 #8
0
        public MetaReader(IStreamManager streamManager, uint baseOffset, ICacheFile cache, EngineDescription buildInfo,
			LoadType type, FieldChangeSet ignore)
        {
            _streamManager = streamManager;
            BaseOffset = baseOffset;
            _cache = cache;
            _ignoredFields = ignore;
            _type = type;

            // Load layouts
            _tagBlockLayout = buildInfo.Layouts.GetLayout("tag block");
            _tagRefLayout = buildInfo.Layouts.GetLayout("tag reference");
            _dataRefLayout = buildInfo.Layouts.GetLayout("data reference");
        }
예제 #9
0
        public MetaReader(IStreamManager streamManager, long baseOffset, ICacheFile cache, EngineDescription buildInfo,
                          LoadType type, FieldChangeSet ignore)
        {
            _streamManager = streamManager;
            BaseOffset     = baseOffset;
            _cache         = cache;
            _ignoredFields = ignore;
            _type          = type;

            // Load layouts
            _tagBlockLayout = buildInfo.Layouts.GetLayout("tag block");
            _tagRefLayout   = buildInfo.Layouts.GetLayout("tag reference");
            _dataRefLayout  = buildInfo.Layouts.GetLayout("data reference");
        }
예제 #10
0
        /// <summary>
        ///     Save meta to the Blam Cache File
        /// </summary>
        public MetaWriter(IWriter writer, uint baseOffset, ICacheFile cache, EngineDescription buildInfo, SaveType type,
			FieldChangeSet changes, Trie stringIdTrie)
        {
            _writer = writer;
            _baseOffset = baseOffset;
            _cache = cache;
            _type = type;
            _changes = changes;
            _stringIdTrie = stringIdTrie;

            // Load layouts
            _reflexiveLayout = buildInfo.Layouts.GetLayout("reflexive");
            _tagRefLayout = buildInfo.Layouts.GetLayout("tag reference");
            _dataRefLayout = buildInfo.Layouts.GetLayout("data reference");
        }
예제 #11
0
 public FlattenedReflexive(FlattenedReflexive parent, ReflexiveData template,
                           ObservableCollection <MetaField> topLevelFields, FieldChangeTracker tracker, FieldChangeSet changes)
 {
     _parent          = parent;
     _template        = template;
     _activeReflexive = template;
     _synchronizedReflexives.Add(template);
     if (template.HasChildren)
     {
         _lastPage = template.Pages[template.CurrentIndex];
     }
     _topLevelFields = topLevelFields;
     _tracker        = tracker;
     _changes        = changes;
 }
예제 #12
0
        /// <summary>
        ///     Save meta to the Blam Cache File
        /// </summary>
        public MetaWriter(IWriter writer, long baseOffset, ICacheFile cache, EngineDescription buildInfo, SaveType type,
                          FieldChangeSet changes, Trie stringIdTrie)
        {
            _writer       = writer;
            _baseOffset   = baseOffset;
            _cache        = cache;
            _type         = type;
            _changes      = changes;
            _stringIdTrie = stringIdTrie;

            // Load layouts
            _tagBlockLayout = buildInfo.Layouts.GetLayout("tag block");
            _tagRefLayout   = buildInfo.Layouts.GetLayout("tag reference");
            _dataRefLayout  = buildInfo.Layouts.GetLayout("data reference");
        }
예제 #13
0
 /// <summary>
 /// Registers a FieldChangeSet with the tracker.
 /// Any time a field is changed, it will be added to all registered sets.
 /// </summary>
 /// <param name="set">The FieldChangeSet to register.</param>
 /// <seealso cref="UnregisterChangeSets"/>
 public void RegisterChangeSet(FieldChangeSet set)
 {
     _changeSets.Add(set);
 }
예제 #14
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;
            }

            // Set the stream manager and base offset to use based upon the LoadType
            IStreamManager streamManager = null;
            uint 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 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);
        }
예제 #15
0
        public void RefreshEditor()
        {
            if (File.Exists(_pluginPath))
            {
                // Load Plugin File
                using (XmlReader xml = XmlReader.Create(_pluginPath))
                {
                    _pluginVisitor = new ThirdGenPluginVisitor(_tags, _cache.StringIDs, _stringIDTrie, Settings.pluginsShowInvisibles);
                    AssemblyPluginLoader.LoadPlugin(xml, _pluginVisitor);
                }

                _changeTracker = new FieldChangeTracker();
                _fileChanges = new FieldChangeSet();
                _memoryChanges = new FieldChangeSet();

                uint baseOffset = (uint)_tag.RawTag.MetaLocation.AsOffset();
                MetaReader metaReader = new MetaReader(_streamManager, baseOffset, _cache, _buildInfo, _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);
            }
            else
            {
                UpdateMetaButtons(false);
                StatusUpdater.Update("Plugin doesn't exist. It can't be loaded for this tag.");
            }
        }
예제 #16
0
 /// <summary>
 ///     Registers a FieldChangeSet with the tracker.
 ///     Any time a field is changed, it will be added to all registered sets.
 /// </summary>
 /// <param name="set">The FieldChangeSet to register.</param>
 /// <seealso cref="UnregisterChangeSets" />
 public void RegisterChangeSet(FieldChangeSet set)
 {
     _changeSets.Add(set);
 }
예제 #17
0
 public ReflexiveFlattener(MetaReader reader, FieldChangeTracker tracker, FieldChangeSet changes)
 {
     _reader = reader;
     _tracker = tracker;
     _changes = changes;
 }
예제 #18
0
        private void ReallocateCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var field = GetWrappedField(e.OriginalSource) as ReflexiveData;
            if (field == null)
                return;
            var newCount = MetroTagBlockReallocator.Show(_cache, field);
            if (newCount == null || (int)newCount == field.Length)
                return; // Canceled

            var oldAddress = field.FirstEntryAddress;
            var oldSize = field.Length * field.EntrySize;
            var newSize = (int)newCount * field.EntrySize;
            uint newAddress;
            using (var stream = _fileManager.OpenReadWrite())
            {
                // Reallocate the block
                newAddress = _cache.Allocator.Reallocate(oldAddress, (int)oldSize, (int)newSize, (uint)field.Align, stream);
                _cache.SaveChanges(stream);

                // If the block was made larger, zero extra data
                if (newAddress != 0 && newSize > oldSize)
                {
                    stream.SeekTo(_cache.MetaArea.PointerToOffset(newAddress) + oldSize);
                    StreamUtil.Fill(stream, 0, (int)(newSize - oldSize));
                }
            }

            // Changing these causes a read from the file, so the stream has to be closed first
            field.Length = (int)newCount;
            field.FirstEntryAddress = newAddress;

            using (var stream = _fileManager.OpenReadWrite())
            {
                // Force a save back to the file
                var changes = new FieldChangeSet();
                changes.MarkChanged(field);
                var metaUpdate = new MetaWriter(stream, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo,
                    MetaWriter.SaveType.File, changes, _stringIdTrie);
                metaUpdate.WriteFields(_pluginVisitor.Values);
                _fileChanges.MarkUnchanged(field);
            }
            if (newAddress == oldAddress)
            {
                MetroMessageBox.Show("Tag Block Reallocator - Assembly",
                    "The tag block was resized successfully. Its address did not change.");
            }
            else if (oldAddress == 0)
            {
                MetroMessageBox.Show("Tag Block Reallocator - Assembly",
                    "The tag block was allocated successfully. Its address is 0x" + newAddress.ToString("X8") + ".");
            }
            else if (newAddress != 0)
            {
                MetroMessageBox.Show("Tag Block Reallocator - Assembly",
                    "The tag block was reallocated successfully. Its new address is 0x" + newAddress.ToString("X8") + ".");
            }
            else
            {
                MetroMessageBox.Show("Tag Block Reallocator - Assembly",
                    "The tag block was freed successfully.");
            }
        }
예제 #19
0
 public ReflexiveFlattener(MetaReader reader, FieldChangeTracker tracker, FieldChangeSet changes)
 {
     _reader  = reader;
     _tracker = tracker;
     _changes = changes;
 }
예제 #20
0
 public TagBlockFlattener(MetaReader reader, FieldChangeTracker tracker, FieldChangeSet changes)
 {
     _reader  = reader;
     _tracker = tracker;
     _changes = changes;
 }