SharpTune.RomMod.Blob.TryGetUInt32 C# (CSharp) Method

TryGetUInt32() public method

Try to get an unsigned 32-bit integer from the blob at the given offset. If successful, increment the offset.
public TryGetUInt32 ( uint &result, int &offset ) : bool
result uint
offset int
return bool
        public bool TryGetUInt32(ref uint result, ref int offset)
        {
            if (this.Content.Count < offset + 4)
            {
                return false;
            }

            result = 0;
            byte temp = 0;
            if (!this.TryGetByte(ref temp, ref offset))
            {
                return false;
            }

            result |= temp;
            if (!this.TryGetByte(ref temp, ref offset))
            {
                return false;
            }

            result <<= 8;
            result |= temp;

            if (!this.TryGetByte(ref temp, ref offset))
            {
                return false;
            }

            result <<= 8;
            result |= temp;
            if (!this.TryGetByte(ref temp, ref offset))
            {
                return false;
            }

            result <<= 8;
            result |= temp;
            return true;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Read a single string from the metadata blob.
        /// </summary>
        /// <remarks>
        /// Consider returning false, printing error message.  But, need to
        /// be certain to abort the whole process at that point...
        /// </remarks>
        public bool TryReadDefData(Blob metadata, out string metaString, out uint metaOffset, ref int offset)
        {
            metaString = null;
            metaOffset = 0;
            UInt32      cookie       = 0;
            List <byte> tempbytelist = new List <byte>();

            metadata.TryGetUInt32(ref metaOffset, ref offset);


            while ((metadata.Content.Count > offset + 8) &&
                   metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if ((cookie < 0x43210010 && cookie > 0x43210000) || cookie == 0x00090009)
                {
                    if (cookie != 0x00090009)
                    {
                        offset -= 4;
                    }

                    char[] splitter   = { '\0' };
                    string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray());
                    metaString = tempstring.Split(splitter)[0];
                    return(true);
                }

                byte tempbyte = new byte();
                offset -= 4;
                for (int i = 0; i < 4; i++)
                {
                    if (!metadata.TryGetByte(ref tempbyte, ref offset))
                    {
                        return(false);
                    }
                    tempbytelist.Add(tempbyte);
                }
            }

            tempbytelist.ToString();
            return(false);
        }
All Usage Examples Of SharpTune.RomMod.Blob::TryGetUInt32