public uint AddressToOffset(uint currentOffset, uint address) { var resourceAddress = new CacheResourceAddress(address); if (resourceAddress.Type != CacheResourceAddressType.Definition) { throw new InvalidOperationException("Cannot dereference a resource address of type " + resourceAddress.Type); } return((uint)resourceAddress.Offset); }
/// <summary> /// Deserializes a tag block (list of values). /// </summary> /// <param name="reader">The reader.</param> /// <param name="context">The serialization context to use.</param> /// <param name="valueType">The type of the value to deserialize.</param> /// <returns>The deserialized tag block.</returns> public object DeserializeTagBlock(EndianReader reader, ISerializationContext context, Type valueType) { var result = Activator.CreateInstance(valueType); var elementType = valueType.GenericTypeArguments[0]; TagStructureAttribute structure; try { structure = TagStructure.GetTagStructureInfo(elementType, Version).Structure; } catch { structure = null; } // Read count and offset var startOffset = reader.BaseStream.Position; var count = reader.ReadInt32(); var pointer = new CacheResourceAddress(reader.ReadUInt32()); if (count == 0 || pointer.Value == 0) { // Null tag block reader.BaseStream.Position = startOffset + (Version > CacheVersion.Halo2Vista ? 0xC : 0x8); return(result); } // // Read each value // var addMethod = valueType.GetMethod("Add"); reader.BaseStream.Position = context.AddressToOffset((uint)startOffset + 4, pointer.Value); for (var i = 0; i < count; i++) { var element = DeserializeValue(reader, context, null, elementType); addMethod.Invoke(result, new[] { element }); } reader.BaseStream.Position = startOffset + (Version > CacheVersion.Halo2Vista ? 0xC : 0x8); return(result); }
public TagBlock(int count, CacheResourceAddress address) { Count = count; Address = address; Elements = new List <T>(); }
public void AddResourceBlock(int count, CacheResourceAddress address, IList block) { throw new NotImplementedException(); }
public TagData(int size, CacheResourceAddress address) { Size = size; Address = address; }