/// <summary> /// Recalculates the information for all WEM identities. /// </summary> private void RecalculateAllIdentities() { uint currentOffset = 0; for (int idx = 0; idx < WEMFilesInternal.Length; idx++) { WEMFile file = WEMFilesInternal[idx]; IdentitiesInternal[idx] = new WEMFileIdentity { WemID = file.ID, Offset = currentOffset, Size = (uint)file.Data.Length }; currentOffset += (uint)file.Data.Length; // Offset seems to be bound to the closest multiple of 4 byte, (e.g. if the length is 7, offset will be bumped up to 8 and the remaining space assumed to be null.) currentOffset = RoundToNearestMultOf4(currentOffset); } }
/// <summary> /// Construct a new WEM Marshaller from a list of identities and the condensed byte array of every included WEM file. /// </summary> /// <param name="identities">The identity array.</param> /// <param name="condensedWEMFileArray">The WEM file identity.</param> public WEMMarshaller(WEMFileIdentity[] identities, byte[] condensedWEMFileArray) { IdentitiesInternal = identities; RawAllWEMFilesInternal = condensedWEMFileArray; WEMFilesInternal = new WEMFile[identities.Length]; // Convert the byte array to the list. List <byte> wemFileList = condensedWEMFileArray.ToList(); for (int idx = 0; idx < identities.Length; idx++) { WEMFileIdentity identity = identities[idx]; // FastSkip is a custom implementation of Skip optimized exclusively for List types. Compared to stock usage of Skip, FastSkip offers a >500% speed increase. // See ArrayUtil.FastSkip for credits. byte[] data = wemFileList.FastSkip((int)identity.Offset).Take((int)identity.Size).ToArray(); WEMFilesInternal[idx] = new WEMFile() { ID = identity.WemID, Data = data }; } }
/// <summary> /// Gets a WEM file by identity, or null if it doesn't exist. /// </summary> /// <param name="identity">The file identity.</param> /// <returns></returns> public WEMFile GetWemFile(WEMFileIdentity identity) { return(GetWemFile(identity.WemID)); }