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

TryGetByte() public method

Try to get a byte from the blob at the given offset. If successful, increment the offset.
public TryGetByte ( byte &result, int &offset ) : bool
result byte
offset int
return bool
        public bool TryGetByte(ref byte result, ref int offset)
        {
            if (this.Content.Count > offset)
            {
                result = this.Content[offset];
                offset++;
                return true;
            }

            return false;
        }

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::TryGetByte