private bool IsLVLScriptChunk(long current, byte[] data)
        {
            bool retVal = false;
            long loc    = BinSearch.GetLocationOfGivenBytes(current, ASCIIEncoding.ASCII.GetBytes("lvl_"), data, 10);

            if (loc == current)
            {
                retVal = true;
            }

            return(retVal);
        }
        /// <summary>
        /// Searched through 'data' for the givenBytes.
        /// </summary>
        /// <param name="startLocation">Where to start in 'data'</param>
        /// <param name="givenBytes">the stuff to look for</param>
        /// <param name="data">the big data to look through</param>
        /// <returns>location of the givenBytes, -1L if not found.</returns>
        public static long GetLocationOfGivenBytes(long startLocation, byte[] givenBytes, byte[] data)
        {
            long num = (long)(data.Length - givenBytes.Length);

            for (long location = startLocation; location < num; ++location)
            {
                if (BinSearch.Find(givenBytes, location, data))
                {
                    return(location);
                }
            }
            return(-1L);
        }
        public static List <long> GetLocationsOfGivenBytes(long startLocation, byte[] givenBytes, byte[] data)
        {
            List <long> retVal = new List <long>();
            long        num    = (long)(data.Length - givenBytes.Length);

            for (long location = startLocation; location < num; ++location)
            {
                if (BinSearch.Find(givenBytes, location, data))
                {
                    retVal.Add(location);
                    location += givenBytes.Length;
                }
            }
            return(retVal);
        }
 /// <summary>
 /// Searched through 'data' for the givenBytes going backwards.
 /// </summary>
 /// <param name="startLocation">Where to start in 'data'</param>
 /// <param name="givenBytes">the stuff to look for</param>
 /// <param name="data">the big data to look through</param>
 /// <param name="maxLookback">the maximum number of bytes to backup.</param>
 /// <returns>location of the givenBytes, -1L if not found.</returns>
 public static long GetLocationOfGivenBytesBackup(long startLocation, byte[] givenBytes, byte[] data, int maxLookback)
 {
     //long num = (long)(data.Length - givenBytes.Length);
     for (long location = startLocation; location > 0; --location)
     {
         if (BinSearch.Find(givenBytes, location, data))
         {
             return(location);
         }
         else if (location < (startLocation - maxLookback))
         {
             break;
         }
     }
     return(-1L);
 }
        /// <summary>
        /// Searched through 'data' for the givenBytes.
        /// </summary>
        /// <param name="startLocation">Where to start in 'data'</param>
        /// <param name="givenBytes">the stuff to look for</param>
        /// <param name="data">the big data to look through</param>
        /// <returns>location of the givenBytes, -1L if not found.</returns>
        public static long GetLocationOfGivenBytes(long startLocation, byte[] givenBytes, byte[] data, long maxDistance)
        {
            long retVal = -1L;
            long num    = (long)(data.Length - givenBytes.Length);

            for (long location = startLocation; location < num; ++location)
            {
                if (BinSearch.Find(givenBytes, location, data))
                {
                    retVal = location;
                    break;
                }
                else if (maxDistance < location - startLocation)
                {
                    break;
                }
            }
            return(retVal);
        }
        /// <summary> Gets the name of the source file that was munged into this data. </summary>
        public string GetName()
        {
            int    headChunkLength = -1;
            string name            = "";
            long   loc1            = -1;
            long   loc             = BinSearch.GetLocationOfGivenBytes(mLocation, ASCIIEncoding.ASCII.GetBytes("scr_"), mData, 40);

            if (loc < 0)
            {
                loc1 = BinSearch.GetLocationOfGivenBytes(mLocation, ASCIIEncoding.ASCII.GetBytes("mcfg"), mData, 80);
                if (loc1 > 0)
                {
                    headChunkLength = MissionMergeForm.GetLengthAtLocation(loc1 + 4, mData);
                    loc1            = BinSearch.GetLocationOfGivenBytes(loc1 + headChunkLength - 8, ASCIIEncoding.ASCII.GetBytes("scr_"), mData, 80);
                }
            }
            else
            {
                loc1 = loc;
            }

            if (loc1 > 0)
            {
                loc = BinSearch.GetLocationOfGivenBytes(loc1, ASCIIEncoding.ASCII.GetBytes("NAME"), mData, 80);
            }
            if (loc > -1)
            {
                int nameLen = mData[(int)loc + 4] - 1; // -1 for null byte
                if (loc > 0)
                {
                    // NAME + 4 bytes later = 8
                    name = Encoding.ASCII.GetString(mData, (int)loc + 8, (int)nameLen);
                }
            }
            return(name);
        }
 /// <summary> Returns the File chunk associated with this item </summary>
 public byte[] GetAssetData()
 {
     byte[] assetData = BinSearch.GetArrayChunk(mData, mLocation, BodyLength + 8);
     return(assetData);
 }
        //private static byte[] data = (byte[])null;

        #region OldMain
        private static int SearchMain(string[] args)
        {
            if (args.Length < 2)
            {
                Console.Error.WriteLine("USAGE: <FileName> <hex search number>");
                Console.Error.WriteLine("OR: <FileName> <hex search number> <hex search number2> offset");
                return(1);
            }
            byte[] data      = (byte[])null;
            bool   useOffset = false;
            string str       = args[0];
            string lower1    = args[1].ToLower();

            if (args.Length == 4)
            {
                useOffset = true;
            }
            if (!File.Exists(str))
            {
                Console.Error.WriteLine("File '{0}' Does not exist!!");
                return(2);
            }
            Match match = new Regex("0x([0-9a-f]+)$").Match(lower1);

            match.Groups[1].ToString();
            if (match == Match.Empty)
            {
                Console.Error.WriteLine("You must pass a valid hex number");
                return(3);
            }
            if (lower1.Length % 2 == 1)
            {
                Console.Error.WriteLine("ERROR!!! You must pass a number with an even amount of digits.");
                return(4);
            }
            try
            {
                long       length     = new FileInfo(str).Length;
                FileStream fileStream = new FileStream(str, FileMode.Open);
                byte[]     buffer     = new byte[(int)length];
                fileStream.Read(buffer, 0, (int)length);
                fileStream.Close();
                data = buffer;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
            byte[] hexNumber1 = BinSearch.GetHexNumber(lower1);
            long   num        = (long)(data.Length - hexNumber1.Length);

            if (useOffset)
            {
                string lower2 = args[2].ToLower();
                string s      = args[3].ToLower();
                if (s.StartsWith("0x"))
                {
                    s = s.Substring(2);
                }
                byte[] hexNumber2 = BinSearch.GetHexNumber(lower2);
                int    offset     = int.Parse(s, NumberStyles.AllowHexSpecifier);
                for (long location = 0; location < num; ++location)
                {
                    if (BinSearch.Find_Offset(hexNumber1, hexNumber2, offset, location, data))
                    {
                        Console.WriteLine("{0:x}", (object)location);
                    }
                }
            }
            else
            {
                long location = GetLocationOfGivenBytes(0, hexNumber1, data);
                if (location > -1L)
                {
                    Console.WriteLine("{0:x}", (object)location);
                }
            }
            return(0);
        }