예제 #1
0
        private void btnImport_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Title = "Open Tag Container",
                Filter = "Tag Container Files|*.tagc"
            };
            bool? result = ofd.ShowDialog();
            if (!result.Value)
                return;

            TagContainer container;
            using (var reader = new EndianReader(File.OpenRead(ofd.FileName), Endian.BigEndian))
                container = TagContainerReader.ReadTagContainer(reader);

            var injector = new TagContainerInjector(_cacheFile, container);
            using (IStream stream = _mapManager.OpenReadWrite())
            {
                foreach (ExtractedTag tag in container.Tags)
                    injector.InjectTag(tag, stream);

                injector.SaveChanges(stream);
            }

            // Fix the SID trie
            foreach (StringID sid in injector.InjectedStringIDs)
                _stringIdTrie.Add(_cacheFile.StringIDs.GetString(sid));

            LoadTags();
            MetroMessageBox.Show("Import Successful",
                "Imported " + injector.InjectedTags.Count + " tag(s), " + injector.InjectedBlocks.Count + " data block(s), " +
                injector.InjectedPages.Count + " resource page pointer(s), " + injector.InjectedResources.Count +
                " resource pointer(s), and " + injector.InjectedStringIDs.Count +
                " stringID(s).\r\n\r\nPlease remember that you cannot poke to injected or modified tags without causing problems. Load the modified map in the game first.\r\n\r\nAdditionally, if applicable, make sure that your game executable is patched so that any map header hash checks are bypassed. Using an executable which only has RSA checks patched out will refuse to load the map.");
        }
예제 #2
0
        private void contextDuplicate_Click(object sender, RoutedEventArgs e)
        {
            // Get the menu item and the tag
            var item = e.Source as MenuItem;
            if (item == null)
                return;
            var tag = item.DataContext as TagEntry;
            if (tag == null)
                return;

            // TODO: Make this into a dialog with more options
            string newName;
            while (true)
            {
                newName = MetroInputBox.Show("Duplicate Tag", "Please enter a name for the new tag.", tag.TagFileName, "Enter a name.");
                if (newName == null)
                    return;
                if (newName != tag.TagFileName && _cacheFile.Tags.FindTagByName(newName, tag.RawTag.Class, _cacheFile.FileNames) == null)
                    break;
                MetroMessageBox.Show("Duplicate Tag", "Please enter a name that is different from the original and that is not in use.");
            }

            // Make a tag container for the tag and then inject it
            // TODO: A lot of this was copied and pasted from the tag extraction code...need to clean things up
            var container = new TagContainer();
            using (var stream = _mapManager.OpenReadWrite())
            {
                // Get the plugin path
                string className = VariousFunctions.SterilizeTagClassName(CharConstant.ToString(tag.RawTag.Class.Magic)).Trim();
                string pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins",
                    _buildInfo.Settings.GetSetting<string>("plugins"), className);

                // Extract data blocks
                var builder = new DataBlockBuilder(stream, tag.RawTag, _cacheFile, _buildInfo);
                using (XmlReader pluginReader = XmlReader.Create(pluginPath))
                    AssemblyPluginLoader.LoadPlugin(pluginReader, builder);
                foreach (var block in builder.DataBlocks)
                {
                    // Remove non-datablock fixups because those are still valid
                    // TODO: A better approach might be to just make DataBlockBuilder ignore these in the first place
                    block.StringIDFixups.Clear();
                    block.ShaderFixups.Clear();
                    block.ResourceFixups.Clear();
                    block.TagFixups.Clear();
                    container.AddDataBlock(block);
                }
                var extracted = new ExtractedTag(tag.RawTag.Index, tag.RawTag.MetaLocation.AsPointer(), tag.RawTag.Class.Magic, newName);
                container.AddTag(extracted);

                // Now inject the container
                var injector = new TagContainerInjector(_cacheFile, container);
                injector.InjectTag(extracted, stream);
                injector.SaveChanges(stream);
            }

            LoadTags();
            MetroMessageBox.Show("Duplicate Tag", "Tag duplicated successfully!");
        }