public ThirdGenLanguageGlobals(ThirdGenCacheFile cacheFile, StructureValueCollection values, IndexOffsetConverter converter, BuildInformation buildInfo) { _cacheFile = cacheFile; _converter = converter; _languages = LoadLanguages(values, converter, buildInfo); _alignment = buildInfo.LocaleAlignment; }
public ThirdGenLanguage(ThirdGenLanguageGlobals languageGlobals, StructureValueCollection values, IndexOffsetConverter converter, BuildInformation buildInfo) { _languageGlobals = languageGlobals; _pointerLayout = buildInfo.GetLayout("locale index table entry"); _encryptionKey = buildInfo.LocaleKey; _symbols = buildInfo.LocaleSymbols; _converter = converter; _pageSize = buildInfo.LocaleAlignment; Load(values, converter); }
public MetaInformation(BuildInformation buildInfo, TagEntry tag, ICacheFile cache) { InitializeComponent(); lblTagName.Text = tag.TagFileName != null ? tag.TagFileName : "0x" + tag.RawTag.Index.Value.ToString("X"); lblDatum.Text = string.Format("Datum Index: {0}", tag.RawTag.Index); lblAddress.Text = string.Format("Memory Address: 0x{0:X8}", tag.RawTag.MetaLocation.AsAddress()); lblOffset.Text = string.Format("File Offset: 0x{0:X}", tag.RawTag.MetaLocation.AsOffset()); }
private void Load(IReader reader, StructureValueCollection values, MetaAddressConverter addrConverter, IStringIDSource stringIDs, ExpressionTable expressions, BuildInformation buildInfo) { Name = stringIDs.GetString(new StringID((int)values.GetNumber("name index"))); ExecutionType = (short)values.GetNumber("execution type"); ReturnType = (short)values.GetNumber("return type"); DatumIndex rootExpr = new DatumIndex(values.GetNumber("first expression index")); if (rootExpr.IsValid) RootExpression = expressions.FindExpression(rootExpr); if (Name == null) Name = "script_" + rootExpr.Value.ToString("X8"); Parameters = LoadParameters(reader, values, addrConverter, buildInfo); }
private void Load(IReader reader, StructureValueCollection values, MetaAddressConverter converter, BuildInformation buildInfo) { if (values.GetNumber("magic") != CharConstant.FromString("tags")) throw new ArgumentException("Invalid index table header magic"); // Classes int numClasses = (int)values.GetNumber("number of classes"); Pointer classTableLocation = new Pointer(values.GetNumber("class table address"), converter); _classes = ReadClasses(reader, classTableLocation, numClasses, buildInfo); // Tags int numTags = (int)values.GetNumber("number of tags"); Pointer tagTableLocation = new Pointer(values.GetNumber("tag table address"), converter); _tags = ReadTags(reader, tagTableLocation, numTags, buildInfo, converter); }
private IList<IScriptParameter> LoadParameters(IReader reader, StructureValueCollection values, MetaAddressConverter addrConverter, BuildInformation buildInfo) { int paramCount = (int)values.GetNumber("number of parameters"); Pointer paramListLocation = new Pointer(values.GetNumber("address of parameter list"), addrConverter); StructureLayout layout = buildInfo.GetLayout("script parameter entry"); List<IScriptParameter> result = new List<IScriptParameter>(); reader.SeekTo(paramListLocation.AsOffset()); for (int i = 0; i < paramCount; i++) { StructureValueCollection paramValues = StructureReader.ReadStructure(reader, layout); result.Add(new ThirdGenScriptParameter(paramValues)); } return result; }
private void Load(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, BuildInformation buildInfo) { StringTableReader stringReader = new StringTableReader(); ScriptExpressions = LoadScriptExpressions(values, reader, addrConverter, stringReader, buildInfo.GetLayout("script expression entry")); ScriptObjects = LoadScriptObjects(values, reader, addrConverter, stringIDs, buildInfo.GetLayout("script object entry")); ScriptGlobals = LoadScriptGlobals(values, reader, addrConverter, ScriptExpressions, buildInfo.GetLayout("script global entry")); Scripts = LoadScripts(values, reader, addrConverter, stringIDs, ScriptExpressions, buildInfo.GetLayout("script entry"), buildInfo); CachedStringTable strings = LoadStrings(values, reader, stringReader, addrConverter); foreach (IExpression expr in ScriptExpressions) { // FIXME: hax if (expr != null) ((ThirdGenExpression)expr).ResolveStrings(strings); } }
public PluginEditor(BuildInformation buildInfo, TagEntry tag, MetaContainer parent, MetaEditor sibling) { InitializeComponent(); txtPlugin.TextArea.TextEntered += PluginTextEntered; _parent = parent; _sibling = sibling; LoadSyntaxHighlighting(); LoadCodeCompletion(); Settings.SettingsChanged += Settings_SettingsChanged; string className = VariousFunctions.SterilizeTagClassName(CharConstant.ToString(tag.RawTag.Class.Magic)); _pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins", buildInfo.PluginFolder, className); LoadPlugin(); }
public MetaContainer(BuildInformation buildInfo, TagEntry tag, TagHierarchy tags, ICacheFile cache, IStreamManager streamManager) { InitializeComponent(); _tag = tag; _buildInfo = buildInfo; _cache = cache; tbMetaEditors.SelectedIndex = (int)Settings.halomapLastSelectedMetaEditor; // Create Meta Information Tab MetaInformation metaInformation = new MetaInformation(_buildInfo, _tag, _cache); tabTagInfo.Content = metaInformation; // Create Meta Editor Tab MetaEditor metaEditor = new MetaEditor(_buildInfo, _tag, tags, _cache, streamManager); tabMetaEditor.Content = metaEditor; // Create Plugin Editor Tab PluginEditor pluginEditor = new PluginEditor(_buildInfo, _tag, this, metaEditor); tabPluginEditor.Content = pluginEditor; }
public MetaEditor(BuildInformation buildInfo, TagEntry tag, TagHierarchy tags, ICacheFile cache, IStreamManager streamManager) { InitializeComponent(); _tag = tag; _tags = tags; _buildInfo = buildInfo; _cache = cache; _streamManager = streamManager; _searchTimer = new Timer(SearchTimer); // Load Plugin Path string className = VariousFunctions.SterilizeTagClassName(CharConstant.ToString(tag.RawTag.Class.Magic)); _pluginPath = string.Format("{0}\\{1}\\{2}.xml", VariousFunctions.GetApplicationLocation() + @"Plugins", _buildInfo.PluginFolder, className); // Set Invisibility box cbShowInvisibles.IsChecked = Settings.pluginsShowInvisibles; // Load Meta RefreshEditor(); // Set init finished hasInitFinished = true; }
public ThirdGenScenarioMeta(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, BuildInformation buildInfo) { Load(values, reader, addrConverter, stringIDs, buildInfo); }
private List<IScript> LoadScripts(StructureValueCollection values, IReader reader, MetaAddressConverter addrConverter, IStringIDSource stringIDs, ExpressionTable expressions, StructureLayout entryLayout, BuildInformation buildInfo) { int script = (int)values.GetNumber("number of scripts"); ScriptsLocation = new Pointer(values.GetNumber("script table address"), addrConverter); // Read all of the script entries first, then go back and create the objects // ThirdGenScript reads parameters from its constructor - this may or may not need cleaning up to make this more obvious reader.SeekTo(ScriptsLocation.AsOffset()); List<StructureValueCollection> scriptData = new List<StructureValueCollection>(); for (int i = 0; i < script; i++) scriptData.Add(StructureReader.ReadStructure(reader, entryLayout)); List<IScript> result = new List<IScript>(); foreach (StructureValueCollection scriptValues in scriptData) result.Add(new ThirdGenScript(reader, scriptValues, addrConverter, stringIDs, expressions, buildInfo)); return result; }
public ThirdGenCacheFile(IReader reader, BuildInformation buildInfo, string buildString) { _buildInfo = buildInfo; Load(reader, buildInfo, buildString); }
private ThirdGenTagTable LoadTags(IReader reader, BuildInformation buildInfo) { reader.SeekTo(_header.IndexHeaderLocation.AsOffset()); StructureValueCollection values = StructureReader.ReadStructure(reader, buildInfo.GetLayout("index header")); return new ThirdGenTagTable(reader, values, _header.MetaPointerConverter, buildInfo); }
public ThirdGenHeader(StructureValueCollection values, BuildInformation info, string buildString) { BuildString = buildString; HeaderSize = info.HeaderSize; Load(values); }
public ThirdGenFileNameSource(IReader reader, int count, int tableSize, Pointer indexTableLocation, Pointer dataLocation, BuildInformation buildInfo) { _strings = new ThirdGenStringTable(reader, count, tableSize, indexTableLocation, dataLocation, buildInfo.FileNameKey); }
private ThirdGenHeader LoadHeader(IReader reader, BuildInformation buildInfo, string buildString) { reader.SeekTo(0); StructureValueCollection values = StructureReader.ReadStructure(reader, buildInfo.GetLayout("header")); return new ThirdGenHeader(values, buildInfo, buildString); }
private ThirdGenFileNameSource LoadFileNames(IReader reader, BuildInformation buildInfo) { return new ThirdGenFileNameSource(reader, _header.FileNameCount, _header.FileNameTableSize, _header.FileNameIndexTableLocation, _header.FileNameDataLocation, buildInfo); }
private void Load(IReader reader, BuildInformation buildInfo, string buildString) { _header = LoadHeader(reader, buildInfo, buildString); _fileNames = LoadFileNames(reader, buildInfo); _stringIds = LoadStringIDs(reader, buildInfo); _tags = LoadTags(reader, buildInfo); _languageInfo = LoadLanguageGlobals(reader, buildInfo); _scenario = LoadScenario(reader, buildInfo); _localeGroups = LoadLocaleGroups(reader, buildInfo); BuildLanguageList(); }
private void FindLanguageTable(BuildInformation buildInfo, out ITag tag, out StructureLayout layout) { // Check for a PATG tag, and if one isn't found, then use MATG tag = null; layout = null; if (buildInfo.HasLayout("patg")) { tag = FindTagByClass(PatgMagic); layout = buildInfo.GetLayout("patg"); } if (tag == null) { tag = FindTagByClass(MatgMagic); layout = buildInfo.GetLayout("matg"); } if (tag == null || layout == null) throw new InvalidOperationException("The cache file is missing locale information."); }
public void InitalizeMap() { _mapManager = new FileStreamManager(_cacheLocation); using (Stream fileStream = _mapManager.OpenRead()) { EndianReader reader = new EndianReader(fileStream, Endian.BigEndian); Dispatcher.Invoke(new Action(delegate { StatusUpdater.Update("Opened File"); })); _version = new ThirdGenVersionInfo(reader); _supportedBuilds = XDocument.Load(VariousFunctions.GetApplicationLocation() + @"Formats\SupportedBuilds.xml"); _layoutLoader = new BuildInfoLoader(_supportedBuilds, VariousFunctions.GetApplicationLocation() + @"Formats\"); _buildInfo = _layoutLoader.LoadBuild(_version.BuildString); Dispatcher.Invoke(new Action(delegate { StatusUpdater.Update("Loaded Build Definitions"); })); if (_buildInfo == null) { Dispatcher.Invoke(new Action(delegate { if (!_0xabad1dea.IWff.Heman(reader)) { StatusUpdater.Update("Not a supported cache build"); MetroMessageBox.Show("Unable to open cache file", "Unsupported blam engine build \"" + _version.BuildString + "\". Why not add support in the 'Formats' folder?"); } else { StatusUpdater.Update("HEYYEYAAEYAAAEYAEYAA"); } Settings.homeWindow.ExternalTabClose((TabItem)this.Parent); })); return; } Dispatcher.Invoke(new Action(delegate { if (Settings.startpageHideOnLaunch) Settings.homeWindow.ExternalTabClose(Windows.Home.TabGenre.StartPage); })); // Load the cache file _cacheFile = new ThirdGenCacheFile(reader, _buildInfo, _version.BuildString); Dispatcher.Invoke(new Action(delegate { StatusUpdater.Update("Loaded Cache File"); })); // Add to Recents Dispatcher.Invoke(new Action(delegate { RecentFiles.AddNewEntry(System.IO.Path.GetFileName(_cacheLocation), _cacheLocation, _buildInfo.ShortName, Settings.RecentFileType.Cache); StatusUpdater.Update("Added To Recents"); })); LoadHeader(); LoadTags(); LoadLocales(); LoadScripts(); } }
private static void LoadAllLocaleSymbols(XDocument localeSymbolDocument, BuildInformation info) { // Make sure there is a root <symbols> tag XContainer localeSymbolContainer = localeSymbolDocument.Element("symbols"); if (localeSymbolContainer == null) throw new ArgumentException("Invalid symbols document"); // Symbol tags have the format: // <symbol code="0x(the byte array)" display="(Friendly Name)" /> foreach (XElement symbol in localeSymbolContainer.Elements("symbol")) { XAttribute codeAttrib = symbol.Attribute("code"); XAttribute displayAttrib = symbol.Attribute("display"); if (codeAttrib == null) throw new ArgumentException("Symbol tags must have a \"code\" attribute"); if (displayAttrib == null) throw new ArgumentException("Symbol tags must have a \"display\" attribute"); // Convert code to int codeAttrib.Value = codeAttrib.Value.Replace("0x",""); byte[] code = FunctionHelpers.HexStringToBytes(codeAttrib.Value); string codeString = Encoding.UTF8.GetString(code); char codeChar = codeString[0]; info.LocaleSymbols.AddSymbol(codeChar, displayAttrib.Value); } }
private ThirdGenLanguageGlobals LoadLanguageGlobals(IReader reader, BuildInformation buildInfo) { // Find the language data ITag languageTag; StructureLayout tagLayout; FindLanguageTable(buildInfo, out languageTag, out tagLayout); // Read it reader.SeekTo(languageTag.MetaLocation.AsOffset()); StructureValueCollection values = StructureReader.ReadStructure(reader, tagLayout); ThirdGenLanguageGlobals result = new ThirdGenLanguageGlobals(this, values, _header.LocalePointerConverter, buildInfo); // If the locale data offset/size is 0, then calculate them if (_header.LocaleDataLocation.AsOffset() == 0 && result.Languages.Count > 0) _header.LocaleDataLocation = result.Languages[0].LocaleIndexTableLocation; if (_header.LocaleDataSize == 0 && result.Languages.Count > 0) { ThirdGenLanguage first = result.Languages[0]; ThirdGenLanguage last = result.Languages[result.Languages.Count - 1]; int size = (int)(last.LocaleDataLocation.AsOffset() + last.LocaleTableSize - first.LocaleIndexTableLocation.AsOffset()); _header.LocaleDataSize = (size + buildInfo.LocaleAlignment - 1) & ~(buildInfo.LocaleAlignment - 1); } return result; }
public ThirdGenScript(IReader reader, StructureValueCollection values, MetaAddressConverter addrConverter, IStringIDSource stringIDs, ExpressionTable expressions, BuildInformation buildInfo) { Load(reader, values, addrConverter, stringIDs, expressions, buildInfo); }
private List<ThirdGenLanguage> LoadLanguages(StructureValueCollection values, IndexOffsetConverter converter, BuildInformation buildInfo) { StructureValueCollection[] languageSet = values.GetArray("languages"); var result = from language in languageSet select new ThirdGenLanguage(this, language, converter, buildInfo); return result.ToList<ThirdGenLanguage>(); }
private List<ILocaleGroup> LoadLocaleGroups(IReader reader, BuildInformation buildInfo) { List<ILocaleGroup> result = new List<ILocaleGroup>(); // Locale groups are stored in unic tags StructureLayout layout = buildInfo.GetLayout("unic"); foreach (ITag tag in _tags.Tags) { if (tag != null && tag.Class != null && tag.Class.Magic == UnicMagic && tag.MetaLocation.AsAddress() > 0) { reader.SeekTo(tag.MetaLocation.AsOffset()); StructureValueCollection values = StructureReader.ReadStructure(reader, layout); result.Add(new ThirdGenLocaleGroup(values, tag.Index)); } } return result; }
/// <summary> /// Loads all of the structure layouts defined in an XML document. /// </summary> /// <param name="layoutDocument">The XML document containing the structure layouts.</param> /// <param name="info">The BuildInformation object to add the layout to.</param> /// <exception cref="ArgumentException">Thrown if the XML document contains invalid layout information.</exception> private static void LoadAllLayouts(XDocument layoutDocument, BuildInformation info) { // Make sure there is a root <layouts> tag XContainer layoutContainer = layoutDocument.Element("layouts"); if (layoutContainer == null) throw new ArgumentException("Invalid layout document"); // Layout tags have the format: // <layout for="(layout's purpose)">(structure fields)</layout> foreach (XElement layout in layoutContainer.Elements("layout")) { XAttribute forAttrib = layout.Attribute("for"); if (forAttrib == null) throw new ArgumentException("Layout tags must have a \"for\" attribute"); info.AddLayout(forAttrib.Value, XMLLayoutLoader.LoadLayout(layout)); } }
private ThirdGenScenarioMeta LoadScenario(IReader reader, BuildInformation buildInfo) { if (!buildInfo.HasLayout("scnr")) return null; ITag scnr = FindTagByClass(ScnrMagic); if (scnr == null) throw new InvalidOperationException("The cache file is missing a scnr tag."); reader.SeekTo(scnr.MetaLocation.AsOffset()); StructureValueCollection values = StructureReader.ReadStructure(reader, buildInfo.GetLayout("scnr")); return new ThirdGenScenarioMeta(values, reader, _header.MetaPointerConverter, _stringIds, buildInfo); }
/// <summary> /// Loads all of the structure layouts defined for a specified build. /// </summary> /// <param name="buildName">The build version to load structure layouts for.</param> /// <returns>The build's information.</returns> public BuildInformation LoadBuild(string buildName) { // Build tags have the format: // <build name="(name of this build of the engine)" // version="(build version string)" // localeKey="(key used to decrypt the locales)" // Optional // requiresTaglist="bool indication if the build requires a taglist)" // Optional // headerSize="(size of the header, in hex)" // filename="(filename containing layouts)" /> // // Just find the first build tag whose version matches and load its file. XElement buildElement = _builds.Elements("build").FirstOrDefault(e => e.Attribute("version") != null && e.Attribute("version").Value == buildName); if (buildElement == null) return null; XAttribute gameNameAttrib = buildElement.Attribute("name"); XAttribute localeKeyAttrib = buildElement.Attribute("localeKey"); XAttribute stringidKeyAttrib = buildElement.Attribute("stringidKey"); XAttribute stringidModifiersAttrib = buildElement.Attribute("stringidModifiers"); // NOTE: Deprecated - use stringidDefinitions instead! XAttribute stringidDefinitionsAttrib = buildElement.Attribute("stringidDefinitions"); XAttribute filenameKeyAttrib = buildElement.Attribute("filenameKey"); XAttribute headerSizeAttrib = buildElement.Attribute("headerSize"); XAttribute loadStringsAttrib = buildElement.Attribute("loadStrings"); XAttribute shortNameAttrib = buildElement.Attribute("shortName"); XAttribute filenameAttrib = buildElement.Attribute("filename"); XAttribute localeSymbolsAttrib = buildElement.Attribute("localeSymbols"); XAttribute pluginFolderAttrib = buildElement.Attribute("pluginFolder"); XAttribute scriptDefinitionsAttrib = buildElement.Attribute("scriptDefinitions"); XAttribute localeAlignmentAttrib = buildElement.Attribute("localeAlignment"); if (gameNameAttrib == null || filenameAttrib == null || headerSizeAttrib == null || shortNameAttrib == null || pluginFolderAttrib == null) return null; bool loadStrings = true; string localeKey = null; string stringidKey = null; string filenameKey = null; string localeSymbols = null; string scriptOpcodes = null; int localeAlignment = 0x1000; int headerSize = ParseNumber(headerSizeAttrib.Value); if (filenameKeyAttrib != null) filenameKey = filenameKeyAttrib.Value; if (localeSymbolsAttrib != null) localeSymbols = localeSymbolsAttrib.Value; if (stringidKeyAttrib != null) stringidKey = stringidKeyAttrib.Value; if (localeKeyAttrib != null) localeKey = localeKeyAttrib.Value; if (loadStringsAttrib != null) loadStrings = Convert.ToBoolean(loadStringsAttrib.Value); if (scriptDefinitionsAttrib != null) scriptOpcodes = _basePath + @"Scripting\" + scriptDefinitionsAttrib.Value; if (localeAlignmentAttrib != null) localeAlignment = ParseNumber(localeAlignmentAttrib.Value); // StringID Modifers, this is a bitch IStringIDResolver stringIdResolver = null; if (stringidModifiersAttrib != null) { StringIDModifierResolver modifierResolver = new StringIDModifierResolver(); stringIdResolver = modifierResolver; string[] sets = stringidModifiersAttrib.Value.Split('|'); foreach (string set in sets) { string[] parts = set.Split(','); /* Format: * Identifier * Modifier * MathSymbol (+/-) * Direction (>/<) */ int identifier = int.Parse(parts[0].Replace("0x", ""), NumberStyles.AllowHexSpecifier); int modifier = int.Parse(parts[1].Replace("0x", ""), NumberStyles.AllowHexSpecifier); bool isAddition = parts[2] == "+"; bool isGreaterThan = parts[3] == ">"; modifierResolver.AddModifier(identifier, modifier, isGreaterThan, isAddition); } } else if (stringidDefinitionsAttrib != null) { StringIDSetResolver setResolver = new StringIDSetResolver(); stringIdResolver = setResolver; XDocument stringIdDocument = XDocument.Load(_basePath + @"StringIDs\" + stringidDefinitionsAttrib.Value); StringIDSetLoader.LoadAllStringIDSets(stringIdDocument, setResolver); } else { // Use a blank modifier stringIdResolver = new StringIDModifierResolver(); } BuildInformation info = new BuildInformation(gameNameAttrib.Value, localeKey, stringidKey, stringIdResolver, filenameKey, headerSize, loadStrings, filenameAttrib.Value, shortNameAttrib.Value, pluginFolderAttrib.Value, scriptOpcodes, localeAlignment); XDocument layoutDocument = XDocument.Load(_basePath + filenameAttrib.Value); LoadAllLayouts(layoutDocument, info); if (localeSymbols != null) { XDocument localeSymbolDocument = XDocument.Load(_basePath + @"LocaleSymbols\" + localeSymbols); LoadAllLocaleSymbols(localeSymbolDocument, info); } return info; }
private ThirdGenStringIDSource LoadStringIDs(IReader reader, BuildInformation buildInfo) { return new ThirdGenStringIDSource(reader, _header.StringIDCount, _header.StringIDTableSize, _header.StringIDIndexTableLocation, _header.StringIDDataLocation, buildInfo); }