Ejemplo n.º 1
0
        /// <summary>
        /// Makes this section out of a byte array. This assumes the start of the byte array is the start of the section.
        /// </summary>
        /// <param name="inputData">The byte array</param>
        public static SectionDIDX MakeSectionFromByteArray(byte[] inputData)
        {
            string name = ConvertFourBytesToString(inputData);

            if (name != SECTION_IDENTITY)
            {
                throw new InvalidCastException("The specified byte array is not of the type " + SECTION_IDENTITY + "(Got " + name + ")");
            }

            SectionDIDX sect = new SectionDIDX();

            sect.Identity = name;
            sect.Length   = BitConverter.ToUInt32(inputData, 4);

            // This is where things get a tad bit complex? Not really.
            // Basically, every "data block" or, as I call it here, WEM File Identity, is 12 bytes long.
            List <WEMFileIdentity> identities = new List <WEMFileIdentity>();

            for (int idx = 8; idx < sect.Length; idx += 12)
            {
                WEMFileIdentity identity = new WEMFileIdentity();

                // The 12 bytes are made up of three uints (each taking 4 bytes, of course).
                identity.WemID  = BitConverter.ToUInt32(inputData, idx);                // This is the ID of the WEM file, that long string of numbers you get for the filename specifically.
                identity.Offset = BitConverter.ToUInt32(inputData, idx + 4);            // This is where it is in the DATA section.
                identity.Size   = BitConverter.ToUInt32(inputData, idx + 8);            // And this is how big the file is.

                // Using all of these we can map out the specific locations of WEM files (See SectionDATA.GetWemFile for example)
                identities.Add(identity);
            }
            sect.WEMFileIdentities = identities.ToArray();

            return(sect);
        }
Ejemplo n.º 2
0
        // <summary>
        // Every WEM file in this BNK file as a distinct object. Do not reference this until calling <seealso cref="PopulateWEMFileArray(SectionDIDX)"/>
        // </summary>
        //public WEMFile[] WEMFiles = null;

        /// <summary>
        /// Gets a specific WEM file from a WEMFileIdentity. This returns the byte array representing the file. See <seealso cref="WEMFiles"/> for a list of distinct objects.<para/>
        /// Editing the contents of this byte array will not modify the data inside of the BNK. See <seealso cref="WEMMarshaller"/> for managing and updating WEM files.
        /// </summary>
        /// <param name="identity">The WEMFileIdentity that represents the target WEM file.</param>
        /// <returns></returns>
        public byte[] GetWEMFile(WEMFileIdentity identity)
        {
            return(RawAllWEMFiles.Skip((int)identity.Offset).Take((int)identity.Size).ToArray());
        }