public ScriptTable LoadScripts(IReader reader) { StructureValueCollection values; if (_scriptTag != null) { values = LoadScriptTag(reader); } else { values = LoadTag(reader); } var result = new ScriptTable(); var stringReader = new StringTableReader(); result.Scripts = LoadScripts(reader, values); result.Globals = LoadGlobals(reader, values); result.Variables = LoadVariables(reader, values); result.Expressions = LoadExpressions(reader, values, stringReader); CachedStringTable strings = LoadStrings(reader, values, stringReader); foreach (ScriptExpression expr in result.Expressions.Where(e => (e != null))) { expr.ResolveStrings(strings); } return(result); }
private void Load(StructureValueCollection values, ushort index, StringTableReader stringReader) { ushort salt = (ushort)values.GetInteger("datum index salt"); Index = new DatumIndex(salt, index); Opcode = (ushort)values.GetInteger("opcode"); ValueType = (short)values.GetInteger("value type"); Type = (ExpressionType)values.GetInteger("expression type"); _nextIndex = new DatumIndex(values.GetInteger("next expression index")); _stringTableOffset = (int)values.GetInteger("string table offset"); Value = values.GetInteger("value"); LineNumber = (short)values.GetInteger("source line"); stringReader.RequestString(_stringTableOffset); }
private void Load(StructureValueCollection values, IReader reader, FileSegmentGroup metaArea, StringIDSource stringIDs, BuildInformation buildInfo) { StringTableReader stringReader = new StringTableReader(); ScriptExpressions = LoadScriptExpressions(values, reader, metaArea, stringReader, buildInfo.GetLayout("script expression entry")); ScriptObjects = LoadScriptObjects(values, reader, metaArea, stringIDs, buildInfo.GetLayout("script object entry")); ScriptGlobals = LoadScriptGlobals(values, reader, metaArea, ScriptExpressions, buildInfo.GetLayout("script global entry")); Scripts = LoadScripts(values, reader, metaArea, stringIDs, ScriptExpressions, buildInfo.GetLayout("script entry"), buildInfo); CachedStringTable strings = LoadStrings(values, reader, stringReader, metaArea); foreach (IExpression expr in ScriptExpressions) { // FIXME: hax if (expr != null) ((ThirdGenExpression)expr).ResolveStrings(strings); } }
private ScriptExpressionTable LoadExpressions(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var count = (int)values.GetInteger("number of script expressions"); uint address = values.GetInteger("script expression table address"); StructureLayout layout = _buildInfo.Layouts.GetLayout("script expression entry"); StructureValueCollection[] entries = ReflexiveReader.ReadReflexive(reader, count, address, layout, _metaArea); var result = new ScriptExpressionTable(); result.AddExpressions(entries.Select((e, i) => new ScriptExpression(e, (ushort)i, stringReader))); foreach (ScriptExpression expr in result.Where(expr => expr != null)) { expr.ResolveReferences(result); } return(result); }
public ScriptTable LoadScripts(IReader reader) { StructureValueCollection values = LoadScriptTag(reader, _scnrTag); ulong strSize = values.GetInteger("script string table size"); var result = new ScriptTable(); var stringReader = new StringTableReader(); result.Scripts = LoadScripts(reader, values); result.Globals = LoadGlobals(reader, values); result.Expressions = LoadExpressions(reader, values, stringReader); CachedStringTable strings = LoadStrings(reader, values, stringReader); foreach (ScriptExpression expr in result.Expressions.Where(e => (e != null))) { expr.ResolveStrings(strings); } return(result); }
private ScriptExpressionTable LoadExpressions(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var stringsSize = (int)values.GetInteger("script string table size"); var count = (int)values.GetInteger("number of script expressions"); uint address = (uint)values.GetInteger("script expression table address"); long expand = _expander.Expand(address); StructureLayout layout = _buildInfo.Layouts.GetLayout("script expression element"); StructureValueCollection[] entries = TagBlockReader.ReadTagBlock(reader, count, expand, layout, _metaArea); var result = new ScriptExpressionTable(); result.AddExpressions(entries.Select((e, i) => new ScriptExpression(e, (ushort)i, stringReader, stringsSize))); foreach (ScriptExpression expr in result.Where(expr => expr != null)) { expr.ResolveReferences(result); } return(result); }
private CachedStringTable LoadStrings(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var stringsSize = (int)values.GetInteger("script string table size"); if (stringsSize == 0) { return(new CachedStringTable()); } var result = new CachedStringTable(); uint tableAddr = (uint)values.GetInteger("script string table address"); long expand = _expander.Expand(tableAddr); int tableOffset = _metaArea.PointerToOffset(expand); stringReader.ReadRequestedStrings(reader, tableOffset, result); return(result); }
public static void Init() { StringTableReader window = (StringTableReader)EditorWindow.GetWindow(typeof(StringTableReader)); }
private void Deserialize(Stream input, Endian endian) { var version = input.ReadValueU16(endian); if (IsValidVersion(version) == false) { throw new FormatException("invalid or unsupported wad version"); } this.Version = version; if (version == 0x101 || version >= 0x200) { this.Flags = input.ReadValueEnum <Wad.ArchiveFlags>(endian); } else { this.Flags = Wad.ArchiveFlags.None; } if (version >= 0x202) { var headerXmlLength = input.ReadValueU32(endian); this.HeaderXml = input.ReadBytes(headerXmlLength); } var stringTableSize = input.ReadValueU32(endian); using (var stringTableData = new MemoryStream()) { if (version >= 0x200) { stringTableData.WriteFromStream(input, stringTableSize); stringTableData.Position = 0; } this.DataTypes.Clear(); if ((this.Flags & Wad.ArchiveFlags.HasDataTypes) == Wad.ArchiveFlags.HasDataTypes) { uint count = input.ReadValueU32(endian); for (uint i = 0; i < count; i++) { var item = new Wad.DataType(); item.Index = input.ReadValueU32(endian); item.Unknown2 = input.ReadValueU32(endian); this.DataTypes.Add(item); } } var totalFileCount = input.ReadValueU32(endian); var totalDirectoryCount = input.ReadValueU32(endian); this.DataOffsets.Clear(); if (version >= 0x200) { uint count = input.ReadValueU32(endian); for (uint i = 0; i < count; i++) { this.DataOffsets.Add(input.ReadValueU32(endian)); } } else { // don't know how to handle this situation throw new InvalidOperationException(); } if (version == 0x100) { stringTableData.WriteFromStream(input, stringTableSize); stringTableData.Position = 0; } var stringTableReader = new StringTableReader(stringTableData); using (var fileTableData = input.ReadToMemoryStream((totalDirectoryCount + totalFileCount) * 16)) { while (fileTableData.Position < fileTableData.Length) { var dir = new Wad.DirectoryEntry(null); dir.Deserialize(fileTableData, endian, stringTableReader); this.Directories.Add(dir); } if (this.TotalFileCount != totalFileCount || this.TotalDirectoryCount != totalDirectoryCount) { throw new InvalidOperationException(); } if (fileTableData.Position != fileTableData.Length) { throw new InvalidOperationException(); } } } }
private CachedStringTable LoadStrings(IReader reader, StructureValueCollection values, StringTableReader stringReader) { var stringsSize = (int)values.GetInteger("script string table size"); if (stringsSize == 0) { return(new CachedStringTable()); } var result = new CachedStringTable(); uint tableOffset = values.GetInteger("script string table address"); tableOffset = (uint)addrFix + (tableOffset & 0xFFFFFFF); int myPointer = _metaArea.PointerToOffset(tableOffset); //int tableOffset = _metaArea.PointerToOffset(values.GetInteger("script string table address")); stringReader.ReadRequestedStrings(reader, myPointer, result); return(result); }
private ExpressionTable LoadScriptExpressions(StructureValueCollection values, IReader reader, FileSegmentGroup metaArea, StringTableReader stringReader, StructureLayout entryLayout) { int exprCount = (int)values.GetInteger("number of script expressions"); if (exprCount == 0) return new ExpressionTable(); ScriptExpressionsLocation = SegmentPointer.FromPointer(values.GetInteger("script expression table address"), metaArea); ExpressionTable result = new ExpressionTable(); reader.SeekTo(ScriptExpressionsLocation.AsOffset()); for (int i = 0; i < exprCount; i++) { StructureValueCollection exprValues = StructureReader.ReadStructure(reader, entryLayout); result.AddExpression(new ThirdGenExpression(exprValues, (ushort)i, stringReader)); } foreach (IExpression expr in result) { // FIXME: hax if (expr != null) ((ThirdGenExpression)expr).ResolveReferences(result); } return result; }
private CachedStringTable LoadStrings(StructureValueCollection values, IReader reader, StringTableReader stringReader, FileSegmentGroup metaArea) { int stringsSize = (int)values.GetInteger("script string table size"); if (stringsSize == 0) return new CachedStringTable(); SegmentPointer stringsLocation = SegmentPointer.FromPointer(values.GetInteger("script string table address"), metaArea); CachedStringTable result = new CachedStringTable(); stringReader.ReadRequestedStrings(reader, stringsLocation, result); return result; }
public ThirdGenExpression(StructureValueCollection values, ushort index, StringTableReader stringReader) { Load(values, index, stringReader); }