/// <summary> /// Writes data to a reflexive, reallocating the original. /// </summary> /// <param name="entries">The entries to write.</param> /// <param name="oldCount">The old count.</param> /// <param name="oldAddress">The old address.</param> /// <param name="newCount">The number of entries to write.</param> /// <param name="layout">The layout of the data to write.</param> /// <param name="metaArea">The meta area of the cache file.</param> /// <param name="allocator">The cache file's meta allocator.</param> /// <param name="stream">The stream to manipulate.</param> /// <returns>The address of the new reflexive, or 0 if the entry list is empty and the reflexive was freed.</returns> public static uint WriteReflexive(IEnumerable<StructureValueCollection> entries, int oldCount, uint oldAddress, int newCount, StructureLayout layout, FileSegmentGroup metaArea, MetaAllocator allocator, IStream stream) { if (newCount == 0) { // Free the old reflexive and return if (oldCount > 0 && oldAddress != 0) allocator.Free(oldAddress, oldCount*layout.Size); return 0; } uint newAddress = oldAddress; if (newCount != oldCount) { // Reallocate the reflexive int oldSize = oldCount*layout.Size; int newSize = newCount*layout.Size; if (oldCount > 0 && oldAddress != 0) newAddress = allocator.Reallocate(oldAddress, oldSize, newSize, stream); else newAddress = allocator.Allocate(newSize, stream); } // Write the new values WriteReflexive(entries.Take(newCount), newAddress, layout, metaArea, stream); return newAddress; }
public static void WriteStructure(StructureValueCollection values, StructureLayout layout, IWriter writer) { var structWriter = new StructureWriter(values, writer); layout.Accept(structWriter); if (layout.Size > 0) structWriter.SeekWriter(layout.Size); }
public FourthGenLanguage(GameLanguage language, StructureValueCollection values, FileSegmenter segmenter, FileSegmentGroup localeArea, EngineDescription buildInfo) { Language = language; _pointerLayout = buildInfo.Layouts.GetLayout("locale index table entry"); _encryptionKey = buildInfo.LocaleKey; _sizeAlign = (_encryptionKey != null) ? AES.BlockSize : 1; Load(values, segmenter, localeArea); }
/// <summary> /// Reads a structure from a stream by following a predefined structure layout. /// </summary> /// <param name="reader">The IReader to read the structure from.</param> /// <param name="layout">The structure layout to follow.</param> /// <returns>A collection of the values that were read.</returns> /// <seealso cref="StructureLayout" /> public static StructureValueCollection ReadStructure(IReader reader, StructureLayout layout) { var structReader = new StructureReader(reader); layout.Accept(structReader); if (layout.Size > 0) structReader.SeekReader(layout.Size); return structReader._collection; }
/// <summary> /// Reads an array of values from the stream and adds it to the value /// collection which is currently being built. /// </summary> /// <param name="name">The name to store the array under.</param> /// <param name="offset">The array's offset (in bytes) from the beginning of the structure.</param> /// <param name="count">The number of elements to read into the array.</param> /// <param name="entryLayout">The layout to follow for each entry in the array.</param> public void VisitArrayField(string name, int offset, int count, StructureLayout entryLayout) { var arrayValue = new StructureValueCollection[count]; for (int i = 0; i < count; i++) { _reader.SeekTo(_baseOffset + offset + i*entryLayout.Size); arrayValue[i] = ReadStructure(_reader, entryLayout); } _collection.SetArray(name, arrayValue); }
/// <summary> /// Writes data to a reflexive at a particular address. /// </summary> /// <param name="entries">The entries to write.</param> /// <param name="address">The address to write to.</param> /// <param name="layout">The layout of the data to write.</param> /// <param name="metaArea">The meta area of the cache file.</param> /// <param name="writer">The stream to write to.</param> public static void WriteReflexive(IEnumerable<StructureValueCollection> entries, uint address, StructureLayout layout, FileSegmentGroup metaArea, IWriter writer) { int offset = metaArea.PointerToOffset(address); int index = 0; foreach (StructureValueCollection entry in entries) { writer.SeekTo(offset + index*layout.Size); StructureWriter.WriteStructure(entry, layout, writer); index++; } }
public void VisitArrayField(string name, int offset, int count, StructureLayout entryLayout) { if (!_collection.HasArray(name)) return; StructureValueCollection[] arrayValue = _collection.GetArray(name); for (int i = 0; i < count; i++) { _writer.SeekTo(_baseOffset + offset + i*entryLayout.Size); WriteStructure(arrayValue[i], entryLayout, _writer); } }
/// <summary> /// Reads a structure from a stream by following a predefined structure layout. /// </summary> /// <param name="reader">The IReader to read the structure from.</param> /// <param name="layout">The structure layout to follow.</param> /// <returns>A collection of the values that were read.</returns> /// <seealso cref="StructureLayout" /> public static StructureValueCollection ReadStructure(IReader reader, StructureLayout layout) { var structReader = new StructureReader(reader); layout.Accept(structReader); if (layout.Size > 0) { structReader.SeekReader(layout.Size); } return(structReader._collection); }
/// <summary> /// Initializes a new instance of the <see cref="DataBlockBuilder" /> class. /// </summary> /// <param name="reader">The stream to read from.</param> /// <param name="tag">The tag to load data blocks for.</param> /// <param name="cacheFile">The cache file.</param> /// <param name="buildInfo">The build info for the cache file.</param> public DataBlockBuilder(IReader reader, ITag tag, ICacheFile cacheFile, EngineDescription buildInfo) { _reader = reader; _tag = tag; _cacheFile = cacheFile; _languageCache = new CachedLanguagePackLoader(_cacheFile.Languages); _tagRefLayout = buildInfo.Layouts.GetLayout("tag reference"); _tagBlockLayout = buildInfo.Layouts.GetLayout("tag block"); _dataRefLayout = buildInfo.Layouts.GetLayout("data reference"); DataBlocks = new List<DataBlock>(); ReferencedTags = new HashSet<DatumIndex>(); ReferencedResources = new HashSet<DatumIndex>(); }
public void VisitArrayField(string name, int offset, int count, StructureLayout entryLayout) { if (!_collection.HasArray(name)) { return; } StructureValueCollection[] arrayValue = _collection.GetArray(name); for (int i = 0; i < count; i++) { _writer.SeekTo(_baseOffset + offset + i * entryLayout.Size); WriteStructure(arrayValue[i], entryLayout, _writer); } }
public ThirdGenShaderStreamer(ICacheFile cacheFile, EngineDescription desc) { _cacheFile = cacheFile; if (desc.Layouts.HasLayout("pixel shader info")) _pixelShaderInfoLayout = desc.Layouts.GetLayout("pixel shader info"); if (desc.Layouts.HasLayout("vertex shader info")) _vertexShaderInfoLayout = desc.Layouts.GetLayout("vertex shader info"); if (desc.Layouts.HasLayout("shader debug info")) _debugInfoLayout = desc.Layouts.GetLayout("shader debug info"); if (desc.Layouts.HasLayout("updb pointer")) _updbPointerLayout = desc.Layouts.GetLayout("updb pointer"); if (desc.Layouts.HasLayout("code info")) _codeInfoLayout = desc.Layouts.GetLayout("code info"); }
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"); }
/// <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("tag block"); _tagRefLayout = buildInfo.Layouts.GetLayout("tag reference"); _dataRefLayout = buildInfo.Layouts.GetLayout("data reference"); }
/// <summary> /// Reads a structure from the stream and adds it to the value /// collection which is currently being built. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param> /// <param name="layout">The layout of the data in the structure.</param> public void VisitStructField(string name, int offset, StructureLayout layout) { SeekReader(offset); var values = ReadStructure(_reader, layout); _collection.SetStruct(name, values); if (layout.Size > 0) { _offset += layout.Size; } else { _offset = _reader.Position; } }
public void VisitStructField(string name, int offset, StructureLayout layout) { if (!_collection.HasStruct(name)) { return; } SeekWriter(offset); WriteStructure(_collection.GetStruct(name), layout, _writer); if (layout.Size > 0) { _offset += layout.Size; } else { _offset = _writer.Position; } }
public static StructureValueCollection[] ReadReflexive(IReader reader, int count, uint address, StructureLayout entryLayout, FileSegmentGroup metaArea) { if (entryLayout.Size == 0) throw new ArgumentException("The entry layout must have a size associated with it."); // Handle null pointers if (count <= 0 || !metaArea.ContainsPointer(address)) return new StructureValueCollection[0]; // Convert the address to an offset and seek to it int offset = metaArea.PointerToOffset(address); reader.SeekTo(offset); // Read the entries var result = new StructureValueCollection[count]; for (int i = 0; i < count; i++) result[i] = StructureReader.ReadStructure(reader, entryLayout); return result; }
/// <summary> /// Reads a structure from a stream by following a predefined structure layout. /// </summary> /// <param name="reader">The IReader to read the structure from.</param> /// <param name="cache">The cache file to read from.</param> /// <param name="buildInfo"></param> /// <param name="layout">The structure layout to follow.</param> /// <returns>A collection of the values that were read.</returns> /// <seealso cref="StructureLayout" /> public static StructureValueCollection ReadStructure(IReader reader, ICacheFile cache, EngineDescription buildInfo, StructureLayout layout) { var structReader = new CacheStructureReader(reader, cache, buildInfo); layout.Accept(structReader); if (layout.Size > 0) { structReader.SeekReader(layout.Size); } return(structReader._collection); }
/// <summary> /// Initializes a new instance of the <see cref="StructField"/> class. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param> /// <param name="layout">The layout of the data in the structure.</param> public StructField(string name, int offset, StructureLayout layout) : base(name, offset) { _layout = layout; }
/// <summary> /// Adds an array field to the structure layout. /// </summary> /// <param name="name">The name of the array.</param> /// <param name="offset">The offset (in bytes) of the array from the beginning of the structure.</param> /// <param name="count">The number of entries in the array.</param> /// <param name="entryLayout">The layout of each entry in the array.</param> public void AddArrayField(string name, int offset, int count, StructureLayout entryLayout) { AddField(new ArrayField(name, offset, count, entryLayout)); }
public void VisitStructField(string name, int offset, StructureLayout layout) { if (!_collection.HasStruct(name)) return; SeekWriter(offset); WriteStructure(_collection.GetStruct(name), layout, _writer); if (layout.Size > 0) _offset += layout.Size; else _offset = _writer.Position; }
/// <summary> /// Reads a structure from the stream and adds it to the value /// collection which is currently being built. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param> /// <param name="layout">The layout of the data in the structure.</param> public void VisitStructField(string name, int offset, StructureLayout layout) { SeekReader(offset); var values = ReadStructure(_reader, layout); _collection.SetStruct(name, values); if (layout.Size > 0) _offset += layout.Size; else _offset = _reader.Position; }
/// <summary> /// Writes data to a reflexive, reallocating the original. /// </summary> /// <param name="entries">The entries to write.</param> /// <param name="oldCount">The old count.</param> /// <param name="oldAddress">The old address.</param> /// <param name="layout">The layout of the data to write.</param> /// <param name="metaArea">The meta area of the cache file.</param> /// <param name="allocator">The cache file's meta allocator.</param> /// <param name="stream">The stream to manipulate.</param> /// <returns>The address of the new reflexive, or 0 if the entry list is empty and the reflexive was freed.</returns> public static uint WriteReflexive(ICollection<StructureValueCollection> entries, int oldCount, uint oldAddress, StructureLayout layout, FileSegmentGroup metaArea, MetaAllocator allocator, IStream stream) { return WriteReflexive(entries, oldCount, oldAddress, entries.Count, layout, metaArea, allocator, stream); }
public void AddTagBlockField(string name, int offset, StructureLayout entryLayout) { AddField(new TagBlockField(name, offset, entryLayout)); }
public TagBlockField(string name, int offset, StructureLayout entryLayout) : base(name, offset) { _layout = entryLayout; }
/// <summary> /// Adds a layout to the collection, associating it with a certain name. /// </summary> /// <param name="name">The name to associate the layout with.</param> /// <param name="layout">The StructureLayout to add.</param> public void AddLayout(string name, StructureLayout layout) { _layouts[name] = layout; }
/// <summary> /// Constructs a new array field. /// </summary> /// <param name="name">The name of the array.</param> /// <param name="offset">The offset (in bytes) of the array from the beginning of the structure.</param> /// <param name="count">The number of entries in the array.</param> /// <param name="entryLayout">The layout of each entry in the array.</param> public ArrayField(string name, int offset, int count, StructureLayout entryLayout) : base(name, offset) { _count = count; _subLayout = entryLayout; }
/// <summary> /// Adds a structure field to the structure layout. /// </summary> /// <param name="name">The name of the field.</param> /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param> /// <param name="layout">The layout of the data in the structure.</param> public void AddStructField(string name, int offset, StructureLayout layout) { AddField(new StructField(name, offset, layout)); }
public FourthGenMultilingualStringList(IReader reader, ITag tag, EngineDescription buildInfo) { _layout = buildInfo.Layouts.GetLayout("unic"); Tag = tag; Load(reader); }
public FourthGenMultilingualStringList(ITag tag, StringRange[] ranges, EngineDescription buildInfo) { _layout = buildInfo.Layouts.GetLayout("unic"); Tag = tag; Ranges = ranges; }
private bool FindLanguageTable(out ITag tag, out StructureLayout layout) { tag = null; layout = null; if (_tags == null) return false; // Check for a PATG tag, and if one isn't found, then use MATG if (_buildInfo.Layouts.HasLayout("patg")) { tag = _tags.FindTagByClass("patg"); layout = _buildInfo.Layouts.GetLayout("patg"); } if (tag == null) { tag = _tags.FindTagByClass("matg"); layout = _buildInfo.Layouts.GetLayout("matg"); } return (tag != null && layout != null); }