public RenderMaterial(Direct3D.Device device, HaloOnlineCacheContext cacheContext, TagTool.Geometry.RenderMaterial material) { if (material.RenderMethod == null) { return; } using (var cacheStream = cacheContext.OpenTagCacheRead()) { var renderMethod = (RenderMethod)cacheContext.Deserialize( new TagSerializationContext(cacheStream, cacheContext, material.RenderMethod), TagDefinition.Find(material.RenderMethod.Group)); var template = cacheContext.Deserialize <RenderMethodTemplate>( new TagSerializationContext(cacheStream, cacheContext, renderMethod.ShaderProperties[0].Template)); Textures = new Dictionary <string, RenderTexture>(); for (var shaderMapIndex = 0; shaderMapIndex < renderMethod.ShaderProperties[0].ShaderMaps.Count; shaderMapIndex++) { var shaderMapName = cacheContext.GetString(template.SamplerArguments[shaderMapIndex].Name); if (Textures.ContainsKey(shaderMapName)) { continue; } var shaderMap = renderMethod.ShaderProperties[0].ShaderMaps[shaderMapIndex]; var shaderMapDefinition = cacheContext.Deserialize <Bitmap>(new TagSerializationContext(cacheStream, cacheContext, shaderMap.Bitmap)); Textures[shaderMapName] = new RenderTexture(device, cacheContext, shaderMapDefinition, shaderMap.BitmapIndex); } } }
public override object Deserialize(Stream stream, CachedTag instance) { var definitionType = TagDefinition.Find(instance.Group); var context = new ModPackageTagSerializationContext(stream, this, BaseModPackage, (CachedTagHaloOnline)instance); return(Deserializer.Deserialize(context, definitionType)); }
private CachedTagInstance ConvertCachedTagInstance(ModPackageExtended modPack, CachedTagInstance modTag) { // Determine if tag requires conversion if (modPack.Tags.Index[modTag.Index] == null) { return(CacheContext.TagCache.Index[modTag.Index]); // references an HO tag } else { // tag has already been converted if (TagMapping.ContainsKey(modTag.Index)) { return(CacheContext.TagCache.Index[TagMapping[modTag.Index]]); // get the matching tag in the destination package } else { CachedTagInstance newTag; if (modTag.Index <= MagicNumber) { newTag = CacheContext.GetTag(modTag.Index); } else if (!CacheContext.TryGetTag($"{modTag.Name}.{modTag.Group}", out newTag)) { newTag = CacheContext.TagCache.AllocateTag(modTag.Group); newTag.Name = modTag.Name; } TagMapping.Add(modTag.Index, newTag.Index); var definitionType = TagDefinition.Find(modTag.Group.Tag); var tagDefinition = CacheContext.Deserialize(new ModPackageTagSerializationContext(modPack.TagsStream, CacheContext, modPack, modTag), definitionType); tagDefinition = ConvertData(modPack, tagDefinition); if (definitionType == typeof(ForgeGlobalsDefinition)) { tagDefinition = ConvertForgeGlobals((ForgeGlobalsDefinition)tagDefinition); } else if (definitionType == typeof(Scenario)) { tagDefinition = ConvertScenario(modPack, (Scenario)tagDefinition); } CacheContext.Serialize(CacheStream, newTag, tagDefinition); foreach (var resourcePointer in modTag.ResourcePointerOffsets) { newTag.AddResourceOffset(resourcePointer); } return(newTag); } } }
private bool GetShader( Mutex mutex, Stream stream, CachedTagInstance instance, IEnumerable <int> shader_rmdfs_ids, out RenderMethod rm_shader_definition, out Type rm_shader_type, out TagSerializationContext rm_shader_context, out string rmdf_name ) { // get shader rm_shader_definition = null; rm_shader_type = null; rm_shader_context = null; rmdf_name = null; { stream.Position = 0; rm_shader_context = new TagSerializationContext(stream, CacheContext, instance); // if there is no dependency on the rmsh, early exit if (shader_rmdfs_ids != null && !rm_shader_context.Tag.Dependencies.Intersect(shader_rmdfs_ids).Any()) { mutex.ReleaseMutex(); return(true); } rm_shader_type = TagDefinition.Find(rm_shader_context.Tag.Group.Tag); rm_shader_definition = CacheContext.Deserializer.Deserialize(rm_shader_context, rm_shader_type) as RenderMethod; // double check to make sure this is the correct render method definition if (shader_rmdfs_ids != null && !shader_rmdfs_ids.Contains(rm_shader_definition.BaseRenderMethod.Index)) { mutex.ReleaseMutex(); return(true); } var rmdf_index = rm_shader_definition.BaseRenderMethod.Index; rmdf_name = CacheContext.GetTag(rmdf_index)?.Name ?? rmdf_index.ToString("X"); } return(false); }
public override object Execute(List <string> args) { if (args.Count != 1) { return(false); } var destDir = new DirectoryInfo(args[0]); if (!destDir.Exists) { destDir.Create(); } foreach (var entry in TagGroup.Instances) { if (entry.Key.Value == -1) { continue; } var tagGroupName = CacheContext.GetString(entry.Value.Name).ToSnakeCase(); var tagStructureInfo = TagStructure.GetTagStructureInfo(TagDefinition.Find(entry.Key), CacheContext.Version); foreach (var type in tagStructureInfo.Types.Reverse <Type>()) { var info = type.GetCustomAttributes <TagStructureAttribute>(false).Where(attr => CacheVersionDetection.IsBetween(CacheContext.Version, attr.MinVersion, attr.MaxVersion)).First(); if (info.Name == null) { Console.WriteLine($"WARNING: {type.FullName} has no tag structure name defined!"); continue; } ExportType(type, new FileInfo(Path.Combine(destDir.FullName, $"{info.Name}.hpp"))); } } return(true); }
private void CopyTagNames(Stream cacheStream, CachedTagInstance edTag, CacheFile.IndexItem blamTag) { if (CopiedTags.ContainsKey(blamTag.GroupTag)) { foreach (var name in CopiedTags[blamTag.GroupTag]) { if (name == blamTag.Name) { return; } } } else { CopiedTags[blamTag.GroupTag] = new List <string>(); } CopiedTags[blamTag.GroupTag].Add(blamTag.Name); var edDef = CacheContext.Deserialize(cacheStream, edTag); var blamDef = BlamCache.Deserializer.Deserialize( new CacheSerializationContext(ref BlamCache, blamTag), TagDefinition.Find(blamTag.GroupTag)); var edInfo = TagStructure.GetTagStructureInfo(edDef.GetType(), CacheContext.Version); var blamInfo = TagStructure.GetTagStructureInfo(blamDef.GetType(), BlamCache.Version); var oldName = edTag.Name; edTag.Name = blamTag.Name; if (edTag.Name != oldName) { NewNameCount++; } CopyTagNames(cacheStream, edDef, edInfo, blamDef, blamInfo); }
public void GetRMDF_IDs(string template_name, out IEnumerable <int> shader_rmdfs_ids, out Type template_type) { template_type = null; shader_rmdfs_ids = null; IEnumerable <CachedTagInstance> shader_rmdfs = null; switch (template_name) { case "shader_templates": case "shader_template": template_type = typeof(Shader); //shader_rmdfs = CacheContext.TagNames.Where(item => item.Value == @"shaders\shader").Select(item => CacheContext.GetTag(item.Key)).ToList(); break; case "cortana_templates": case "cortana_template": template_type = typeof(ShaderCortana); //shader_rmdfs = CacheContext.TagNames.Where(item => item.Value == @"shaders\cortana").Select(item => CacheContext.GetTag(item.Key)).ToList(); break; case null: case "*": break; default: Console.WriteLine("Invalid template_type"); break; } if (shader_rmdfs != null) { shader_rmdfs = shader_rmdfs.Where(rmdf => TagDefinition.Find(rmdf.Group.Tag) == typeof(RenderMethodDefinition)); shader_rmdfs_ids = shader_rmdfs.Select(rmdf => rmdf.Index); shader_rmdfs_ids = new int[] { shader_rmdfs_ids.FirstOrDefault() }; } }
public override object Execute(List <string> args) { if (args.Count < 1 || args.Count > 2) { return(false); } begin: var groupTagString = args[0]; if (groupTagString.Length > 4) { Console.WriteLine($"ERROR: Invalid group tag: {groupTagString}"); return(true); } if (!Cache.TryParseGroupTag(groupTagString, out var groupTag)) { var chars = new char[] { ' ', ' ', ' ', ' ' }; for (var i = 0; i < chars.Length; i++) { chars[i] = groupTagString[i]; } groupTag = new Tag(new string(chars)); } if (!TagGroup.Instances.ContainsKey(groupTag)) { Console.WriteLine($"ERROR: No tag group definition for group tag '{groupTag}'!"); Console.Write($"(BE CAREFUL WITH THIS!!!) Define '{groupTag}' tag group? [y/n]: "); var answer = Console.ReadLine().ToLower(); if (answer != "y" && answer != "yes") { return(true); } Console.WriteLine("Enter the tag group specification in the following format"); Console.WriteLine("<group tag> [parent group tag] [grandparent group tag] <group name>:"); Console.WriteLine(); Console.Write($"{groupTag} specification> "); answer = Console.ReadLine(); var groupArgs = ArgumentParser.ParseCommand(answer, out string redirect); switch (groupArgs.Count) { case 2: new TagGroup(new Tag(groupArgs[0]), Tag.Null, Tag.Null, Cache.StringTable.GetStringId(groupArgs[1])); break; case 3: new TagGroup(new Tag(groupArgs[0]), new Tag(groupArgs[1]), Tag.Null, Cache.StringTable.GetStringId(groupArgs[2])); break; case 4: new TagGroup(new Tag(groupArgs[0]), new Tag(groupArgs[1]), new Tag(groupArgs[2]), Cache.StringTable.GetStringId(groupArgs[3])); break; default: return(false); } goto begin; } CachedTag instance = null; TagGroup.Instances.TryGetValue(groupTag, out var tagGroup); using (var stream = Cache.OpenCacheReadWrite()) { if (args.Count == 2) { var tagIndex = -1; if (!Cache.TryGetCachedTag(args[1], out instance)) { if (args[1].StartsWith("0x")) { tagIndex = Convert.ToInt32(args[1], 16); } else { return(false); } } else { tagIndex = instance.Index; } while (tagIndex >= Cache.TagCache.Count) { Cache.TagCache.AllocateTag(TagGroup.None); } if (tagIndex < Cache.TagCache.Count) { if (Cache.TagCacheGenHO.Tags[tagIndex] != null) { var oldInstance = Cache.TagCacheGenHO.Tags[tagIndex]; Cache.TagCacheGenHO.Tags[tagIndex] = null; Cache.TagCacheGenHO.SetTagDataRaw(stream, oldInstance, new byte[] { }); } instance = Cache.TagCache.CreateCachedTag(tagIndex, TagGroup.Instances[groupTag]); Cache.TagCacheGenHO.Tags[tagIndex] = (CachedTagHaloOnline)instance; } } if (instance == null) { instance = Cache.TagCache.AllocateTag(TagGroup.Instances[groupTag]); } Cache.Serialize(stream, instance, Activator.CreateInstance(TagDefinition.Find(groupTag))); } var tagName = instance.Name ?? $"0x{instance.Index:X4}"; Console.WriteLine($"[Index: 0x{instance.Index:X4}] {tagName}.{Cache.StringTable.GetString(instance.Group.Name)}"); return(true); }
public override object Execute(List <string> args) { if (args.Count < 2) { return(false); } var outputPath = args[0]; // Load each file and do version detection var infos = new List <HaloOnlineCacheContext>(); foreach (var path in args.Skip(1)) { Console.WriteLine("Loading {0}...", path); // Load the cache file var cacheContext = new HaloOnlineCacheContext(new FileInfo(path).Directory); infos.Add(cacheContext); } var result = new TagVersionMap(); using (var baseStream = CacheContext.OpenTagCacheRead()) { // Get the scenario tags for this cache Console.WriteLine("Finding base scenario tags..."); var baseScenarios = FindScenarios(CacheContext, baseStream); var baseVersion = CacheContext.Version; var baseTagData = new Dictionary <int, object>(); foreach (var scenario in baseScenarios) { baseTagData[scenario.Tag.Index] = scenario.Data; } // Now compare with each of the other caches foreach (var info in infos) { using (var stream = info.OpenTagCacheRead()) { Console.WriteLine("Finding scenario tags in {0}...", info.TagCacheFile.FullName); // Get the scenario tags and connect them to the base tags var scenarios = FindScenarios(info, stream); var tagsToCompare = new Queue <QueuedTag>(); for (var i = 0; i < scenarios.Count; i++) { tagsToCompare.Enqueue(scenarios[i]); if (i < baseScenarios.Count) { result.Add(baseVersion, baseScenarios[i].Tag.Index, info.Version, scenarios[i].Tag.Index); } } // Process each tag in the queue, enqueuing all of its dependencies as well while (tagsToCompare.Count > 0) { // Get the tag and its data var tag = tagsToCompare.Dequeue(); TagPrinter.PrintTagShort(tag.Tag); var data = tag.Data; if (data == null) { // No data yet - deserialize it var context = new TagSerializationContext(stream, info, tag.Tag); var type = TagDefinition.Find(tag.Tag.Group.Tag); data = info.Deserializer.Deserialize(context, type); } // Now get the data for the base tag var baseTag = result.Translate(info.Version, tag.Tag.Index, baseVersion); if (baseTag == -1 || CacheContext.TagCache.Index[baseTag].Group.Tag != tag.Tag.Group.Tag) { continue; } if (!baseTagData.TryGetValue(baseTag, out object baseData)) { // No data yet - deserialize it var context = new TagSerializationContext(baseStream, CacheContext, CacheContext.TagCache.Index[baseTag]); var type = TagDefinition.Find(tag.Tag.Group.Tag); baseData = CacheContext.Deserializer.Deserialize(context, type); baseTagData[baseTag] = baseData; } // Compare the two blocks CompareBlocks(baseData, baseVersion, data, info.Version, result, tagsToCompare); } } } } // Write out the CSV Console.WriteLine("Writing results..."); using (var writer = new StreamWriter(File.Open(outputPath, FileMode.Create, FileAccess.Write))) result.WriteCsv(writer); Console.WriteLine("Done!"); return(true); }
public override object Execute(List <string> args) { if (args.Count != 2) { return(false); } var groupTagInput = args[0]; var blamTagName = args[1]; var groupTag = Tag.Null; if (TagDefinition.Exists(groupTagInput)) { groupTag = new Tag(groupTagInput); } else { foreach (var tagGroup in BlamCache.IndexItems.ClassList) { if (groupTagInput == BlamCache.Strings.GetItemByID(tagGroup.StringID)) { var chars = new char[4] { ' ', ' ', ' ', ' ' }; for (var i = 0; i < 4; i++) { chars[i] = tagGroup.ClassCode[i]; } groupTag = new Tag(new string(chars)); break; } } } CacheFile.IndexItem tag = null; foreach (var blamTag in BlamCache.IndexItems) { if ((blamTag.GroupTag == groupTag.ToString()) && (blamTagName == "*" || blamTag.Name == blamTagName)) { tag = blamTag; break; } } if (tag == null) { throw new Exception(); } var tagName = $"(0x{tag.ID:X8}) {tag.Name.Substring(tag.Name.LastIndexOf('\\') + 1)}"; var tagType = TagDefinition.Find(groupTag); var definition = (TagStructure)BlamCache.Deserializer.Deserialize(new CacheSerializationContext(ref BlamCache, tag), tagType); var structure = definition.GetTagStructureInfo(BlamCache.Version); var oldContext = ContextStack.Context; var commandContext = new CommandContext(ContextStack.Context, string.Format("{0}.{1}", tagName, groupTagInput)); commandContext.AddCommand(new ListFieldsCommand(BlamCache, structure, definition)); commandContext.AddCommand(new EditBlockCommand(ContextStack, BlamCache, tag, definition)); commandContext.AddCommand(new CopyBlockElementsCommand(ContextStack, BlamCache, tag, structure, definition)); commandContext.AddCommand(new Editing.ExitToCommand(ContextStack)); ContextStack.Push(commandContext); Console.WriteLine($"Tag {tagName}.{groupTagInput} has been opened for editing."); Console.WriteLine("New commands are now available. Enter \"help\" to view them."); Console.WriteLine("Use \"exit\" to return to {0}.", oldContext.Name); return(true); }
public static CommandContext Create(CommandContextStack contextStack, HaloOnlineCacheContext cacheContext, CachedTagInstance tag, object definition) { var documentationPath = $"{new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName}\\TagTool.xml"; if (Documentation.ChildNodes.Count == 0 && File.Exists(documentationPath)) { Documentation.Load(documentationPath); } var groupName = cacheContext.GetString(tag.Group.Name); var tagName = tag?.Name ?? $"0x{tag.Index:X4}"; var commandContext = new CommandContext(contextStack.Context, string.Format("{0}.{1}", tagName, groupName)); switch (tag.Group.Tag.ToString()) { case "bink": VideoContextFactory.Populate(commandContext, cacheContext, tag, (Bink)definition); break; case "bitm": // bitmap BitmapContextFactory.Populate(commandContext, cacheContext, tag, (Bitmap)definition); break; case "coll": CollisionModelContextFactory.Populate(commandContext, cacheContext, tag, (CollisionModel)definition); break; case "hlmt": // model ModelContextFactory.Populate(commandContext, cacheContext, tag, (Model)definition); break; case "jmad": AnimationContextFactory.Populate(commandContext, cacheContext, tag, (ModelAnimationGraph)definition); break; case "Lbsp": LightmapContextFactory.Populate(commandContext, cacheContext, tag, (ScenarioLightmapBspData)definition); break; case "mode": // render_model RenderModelContextFactory.Populate(commandContext, cacheContext, tag, (RenderModel)definition); break; case "pmdf": ParticleModelContextFactory.Populate(commandContext, cacheContext, tag, (ParticleModel)definition); break; case "rm ": // render_method case "rmsh": // shader case "rmd ": // shader_decal case "rmfl": // shader_foliage case "rmhg": // shader_halogram case "rmss": // shader_screen case "rmtr": // shader_terrain case "rmw ": // shader_water case "rmzo": // shader_zonly case "rmcs": // shader_custom RenderMethodContextFactory.Populate(commandContext, cacheContext, tag, (RenderMethod)definition); break; case "sbsp": BSPContextFactory.Populate(commandContext, cacheContext, tag, (ScenarioStructureBsp)definition); break; case "scnr": ScnrContextFactory.Populate(commandContext, cacheContext, tag, (Scenario)definition); break; case "snd!": SoundContextFactory.Populate(commandContext, cacheContext, tag, (Sound)definition); break; case "unic": // multilingual_unicode_string_list UnicodeContextFactory.Populate(commandContext, cacheContext, tag, (MultilingualUnicodeStringList)definition); break; case "vfsl": // vfiles_list VFilesContextFactory.Populate(commandContext, cacheContext, tag, (VFilesList)definition); break; case "pixl": Shaders.ShaderContextFactory <PixelShader> .Populate(commandContext, cacheContext, tag, (PixelShader)definition); break; case "vtsh": Shaders.ShaderContextFactory <VertexShader> .Populate(commandContext, cacheContext, tag, (VertexShader)definition); break; case "glps": Shaders.ShaderContextFactory <GlobalPixelShader> .Populate(commandContext, cacheContext, tag, (GlobalPixelShader)definition); break; case "glvs": Shaders.ShaderContextFactory <GlobalVertexShader> .Populate(commandContext, cacheContext, tag, (GlobalVertexShader)definition); break; case "rmt2": Shaders.RenderMethodTemplateContextFactory.Populate(commandContext, cacheContext, tag, (RenderMethodTemplate)definition); break; } var structure = TagStructure.GetTagStructureInfo(TagDefinition.Find(tag.Group.Tag), cacheContext.Version); commandContext.AddCommand(new ListFieldsCommand(cacheContext, structure, definition)); commandContext.AddCommand(new SetFieldCommand(contextStack, cacheContext, tag, structure, definition)); commandContext.AddCommand(new EditBlockCommand(contextStack, cacheContext, tag, definition)); commandContext.AddCommand(new AddBlockElementsCommand(contextStack, cacheContext, tag, structure, definition)); commandContext.AddCommand(new RemoveBlockElementsCommand(contextStack, cacheContext, tag, structure, definition)); commandContext.AddCommand(new CopyBlockElementsCommand(contextStack, cacheContext, tag, structure, definition)); commandContext.AddCommand(new PasteBlockElementsCommand(contextStack, cacheContext, tag, structure, definition)); commandContext.AddCommand(new ForEachCommand(contextStack, cacheContext, tag, structure, definition)); commandContext.AddCommand(new SaveTagChangesCommand(cacheContext, tag, definition)); commandContext.AddCommand(new PokeTagChangesCommand(cacheContext, tag, definition)); commandContext.AddCommand(new ExitToCommand(contextStack)); return(commandContext); }
private object GetTagDefinition(Stream stream, CachedTagInstance tag) { object definition = null; if (!LoadedDefinitions.ContainsKey(tag.Index)) { var context = new TagSerializationContext(stream, CacheContext, tag); definition = LoadedDefinitions[tag.Index] = CacheContext.Deserializer.Deserialize(context, TagDefinition.Find(tag.Group.Tag)); } else { definition = LoadedDefinitions[tag.Index]; } return(definition); }
private CachedTag ConvertCachedTagInstance(ModPackage modPack, CachedTag modTag) { Console.WriteLine($"Converting {modTag.Name}.{modTag.Group}..."); // tag has already been converted if (TagMapping.ContainsKey(modTag.Index)) { return(CacheContext.TagCache.GetTag(TagMapping[modTag.Index])); // get the matching tag in the destination package } // Determine if tag requires conversion if (modTag.DefinitionOffset == ((CachedTagHaloOnline)modTag).TotalSize) { //modtag references a base tag, figure out which one is it and add it to the mapping CachedTag baseTag = null; if (modTag.Index < CacheContext.TagCache.Count) { baseTag = CacheContext.TagCache.GetTag(modTag.Index); } // mod tag has a name, first check if baseTag name is null, else if the names don't match or group don't match if (baseTag != null && baseTag.Group == modTag.Group && baseTag.Name != null && baseTag.Name == modTag.Name) { TagMapping[modTag.Index] = baseTag.Index; return(baseTag); } else { // tag name/group doesn't match base tag, try to look for it CachedTag cacheTag; if (CacheTagsByName.TryGetValue($"{modTag.Name}.{modTag.Group}", out cacheTag)) { TagMapping[modTag.Index] = cacheTag.Index; return(cacheTag); } // Failed to find tag in base cache Console.Error.WriteLine($"Failed to find {modTag.Name}.{modTag.Group.ToString()} in the base cache, returning null tag reference."); //return null; throw new Exception("Failed to find tag when applying."); } } else { CachedTag newTag; if (!CacheTagsByName.TryGetValue($"{modTag.Name}.{modTag.Group}", out newTag)) { newTag = CacheContext.TagCache.AllocateTag(modTag.Group); newTag.Name = modTag.Name; } TagMapping.Add(modTag.Index, newTag.Index); var definitionType = TagDefinition.Find(modTag.Group.Tag); var deserializer = new TagDeserializer(CacheVersion.HaloOnline106708); var tagDefinition = deserializer.Deserialize(new ModPackageTagSerializationContext(modPack.TagCachesStreams[0], CacheContext, modPack, (CachedTagHaloOnline)modTag), definitionType); tagDefinition = ConvertData(modPack, tagDefinition); if (definitionType == typeof(ForgeGlobalsDefinition)) { tagDefinition = ConvertForgeGlobals((ForgeGlobalsDefinition)tagDefinition); } else if (definitionType == typeof(Scenario)) { tagDefinition = ConvertScenario(modPack, (Scenario)tagDefinition); } CacheContext.Serialize(CacheStream, newTag, tagDefinition); foreach (var resourcePointer in ((CachedTagHaloOnline)modTag).ResourcePointerOffsets) { var newTagHo = newTag as CachedTagHaloOnline; newTagHo.AddResourceOffset(resourcePointer); } return(newTag); } }
public void LoadTagEditor(CachedTagInstance tag) { if (tag == null || (CurrentTag != null && CurrentTag.Index == tag.Index)) { return; } LoadingTag = true; object definition = null; if (CurrentTags.ContainsKey(tag.Index)) { definition = CurrentTags[tag.Index]; } tagTreeView.Enabled = false; tagEditorPanel.Controls.Clear(); var tagName = tag.Name ?? $"0x{tag.Index:X4}"; var groupName = CacheContext.GetString(tag.Group.Name); statusLabel.Text = $"Loading {tagName}.{ groupName}..."; progressBar.Style = ProgressBarStyle.Marquee; progressBar.MarqueeAnimationSpeed = 30; if (definition == null) { using (var stream = CacheContext.OpenTagCacheRead()) definition = CacheContext.Deserializer.Deserialize( new TagSerializationContext(stream, CacheContext, tag), TagDefinition.Find(tag.Group.Tag)); } if (tagName.Contains("\\")) { var index = tagName.LastIndexOf('\\') + 1; tagName = tagName.Substring(index, tagName.Length - index); } statusLabel.Text = $"Generating {groupName} interface..."; Application.DoEvents(); var point = new Point(); if (tag.IsInGroup("matg") || tag.IsInGroup("mulg") || tag.IsInGroup("scnr") || tag.IsInGroup("sbsp")) { var control = new StructMultiControl(this, CacheContext, tag, definition) { Dock = DockStyle.Fill }; control.GetFieldValue(null, definition, definition); tagEditorPanel.Controls.Add(control); } else if (tag.IsInGroup("bitm") || tag.IsInGroup("obje")) { var splitContainer = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Horizontal }; splitContainer.FixedPanel = FixedPanel.Panel1; tagEditorPanel.Controls.Add(splitContainer); splitContainer.BringToFront(); if (tag.IsInGroup("bitm")) { splitContainer.SplitterDistance = Math.Min((short)512, Math.Max((short)16, ((TagTool.Tags.Definitions.Bitmap)definition).Images[0].Height)); } else if (tag.IsInGroup("obje")) { splitContainer.SplitterDistance = 384; } if (tag.IsInGroup("bitm")) { var bitmDefinition = (TagTool.Tags.Definitions.Bitmap)definition; var bitmapControl = new BitmapControl(CacheContext, bitmDefinition) { Dock = DockStyle.Fill }; splitContainer.Panel1.Controls.Add(bitmapControl); bitmapControl.BringToFront(); } else if (tag.IsInGroup("obje")) { var modelControl = new ObjectControl(CacheContext, (GameObject)definition) { Dock = DockStyle.Fill }; splitContainer.Panel1.Controls.Add(modelControl); modelControl.BringToFront(); } var control = tag.IsInGroup("obje") ? (Control) new StructMultiControl(this, CacheContext, tag, definition) { Dock = DockStyle.Fill } : new StructControl(this, CacheContext, definition.GetType(), null); ((IFieldControl)control).GetFieldValue(null, definition, definition); control.Location = point; splitContainer.Panel2.Controls.Add(control); splitContainer.Panel2.AutoScroll = true; } else { if (tag.IsInGroup("snd!")) { var soundControl = new SoundControl(CacheContext, tag, (TagTool.Tags.Definitions.Sound)definition) { Dock = DockStyle.Top }; tagEditorPanel.Controls.Add(soundControl); soundControl.BringToFront(); point.Y = soundControl.Bottom; } var control = new StructControl(this, CacheContext, definition.GetType(), null); control.GetFieldValue(null, definition, definition); control.Location = point; tagEditorPanel.Controls.Add(control); } statusLabel.Text = ""; progressBar.Style = ProgressBarStyle.Continuous; progressBar.MarqueeAnimationSpeed = 0; tagTreeView.Enabled = true; CurrentTag = tag; if (!CurrentTags.ContainsKey(tag.Index)) { CurrentTags[tag.Index] = definition; var item = new TagInstanceItem { CacheContext = CacheContext, Tag = tag }; currentTagsComboBox.Items.Add(item); currentTagsComboBox.SelectedItem = item; } else { for (var i = 0; i < currentTagsComboBox.Items.Count; i++) { var item = (TagInstanceItem)currentTagsComboBox.Items[i]; if (item.Tag.Index == tag.Index) { currentTagsComboBox.SelectedIndex = i; break; } } } LoadingTag = false; }
public CachedTagInstance[] GetShaderInstances(Type template_type) { CachedTagInstance[] shader_instances = null; if (template_type != null) { shader_instances = CacheContext.TagCache.Index.Where(instance => instance != null && TagDefinition.Find(instance.Group.Tag) == template_type).ToArray(); } else { shader_instances = CacheContext.TagCache.Index.Where(instance => instance != null && SupportedShaderTypes.Contains(TagDefinition.Find(instance.Group.Tag))).ToArray(); } return(shader_instances); }
public override object Deserialize(Stream stream, CachedTag instance) => Deserialize(new Gen1SerializationContext(stream, this, (CachedTagGen1)instance), TagDefinition.Find(instance.Group.Tag));
public object Deserialize(Stream stream, CachedTagGen2 instance) => Deserialize(new Gen2SerializationContext(stream, this, instance), TagDefinition.Find(instance.Group.Tag));
public override object Execute(List <string> args) { if (args.Count > 1) { return(false); } Process process; if (args.Count == 1) { if (!int.TryParse(args[0], NumberStyles.HexNumber, null, out int processId) || processId < 0) { return(false); } #if !DEBUG try { #endif process = Process.GetProcessById(processId); #if !DEBUG } catch (ArgumentException) { Console.Error.WriteLine("Unable to find a process with an ID of 0x{0:X}", processId); return(true); } #endif } else { var processes = Process.GetProcessesByName("eldorado"); if (processes.Length == 0) { Console.Error.WriteLine("Unable to find any eldorado.exe processes."); return(true); } process = processes[0]; } using (var processStream = new ProcessMemoryStream(process)) { var address = GetTagAddress(processStream, Tag.Index); var runtimeContext = new RuntimeSerializationContext(CacheContext, processStream); processStream.Position = address + Tag.DefinitionOffset; var definition = CacheContext.Deserializer.Deserialize(runtimeContext, TagDefinition.Find(Tag.Group.Tag)); CacheContext.Serializer.Serialize(runtimeContext, Value); if (address != 0) { Console.WriteLine("Tag 0x{0:X} is loaded at 0x{1:X8} in process 0x{2:X}.", Tag.Index, address, process.Id); } else { Console.Error.WriteLine("Tag 0x{0:X} is not loaded in process 0x{1:X}.", Tag.Index, process.Id); } } return(true); }