Пример #1
0
		/// <summary>
		/// Find the string that is expected to be located at <paramref name="offset"/> 
		/// in <paramref name="ste"/> and return its entry data
		/// </summary>
		/// <param name="offset"></param>
		/// <param name="ste"></param>
		/// <returns></returns>
		public static ScriptStringEntry Seach(int offset, ScriptStringEntry[] ste)
		{
			int low = 0, high = ste.Length;
			int mid;
			while (low <= high)
			{
				mid = (high + low) / 2;

				if (ste[mid].Offset < offset) low = mid;
				else if (offset < ste[mid].Offset) high = mid;
				else return ste[mid];
			}

			return Null;
		}
Пример #2
0
		public static ScriptStringEntry[] FromData(TagInterface.Data data, byte garbage_id)
		{
			int offset = 0;
			System.Text.StringBuilder stringEntry;
			ScriptStringEntry[] ste;
			List<ScriptStringEntry> value = new List<ScriptStringEntry>();

			for (int x = 0; x < data.Size; x++)
			{
				stringEntry = new StringBuilder();
				byte btchar = 0;

				#region (try to) get the string entry...
				try
				{
					do
					{
						if (offset < data.Size)
						{
							btchar = data[offset];

							if (btchar != 0) stringEntry.Append((char)btchar);
						}

						offset++;

					} while ((btchar != 0 || btchar != garbage_id) && offset < data.Size);
				}
				catch (IndexOutOfRangeException ex)
				{
					throw new Debug.ExceptionLog(ex, "Offset was outside the bounds of the data array.");
				}
				#endregion

				// ...and add it
				value.Add(new ScriptStringEntry(stringEntry.ToString(), offset - (stringEntry.Length + 1)));

				// we're in the padding area now
				if (btchar == garbage_id) break;
			}

			bool found_empty = false;
			for (int x = 0; x < value.Count; x++)
			{
				if (!found_empty) // do this shit until we find the first empty string...
				{
					found_empty = value[x].Data == "";
					continue;
				}

				// then do this for every empty string we may find
				if (value[x].Data == "" && found_empty)
					value.RemoveAt(x--);
			}

			// find the shit we only care for and return it
			ste = new ScriptStringEntry[value.Count];
			for (int x = 0; x < value.Count; x++)
				ste[x] = value[x];

			return ste;
		}
Пример #3
0
        public static ScriptStringEntry[] FromData(TagInterface.Data data, byte garbage_id)
        {
            int offset = 0;

            System.Text.StringBuilder stringEntry;
            ScriptStringEntry[]       ste;
            List <ScriptStringEntry>  value = new List <ScriptStringEntry>();

            for (int x = 0; x < data.Size; x++)
            {
                stringEntry = new StringBuilder();
                byte btchar = 0;

                #region (try to) get the string entry...
                try
                {
                    do
                    {
                        if (offset < data.Size)
                        {
                            btchar = data[offset];

                            if (btchar != 0)
                            {
                                stringEntry.Append((char)btchar);
                            }
                        }

                        offset++;
                    } while ((btchar != 0 || btchar != garbage_id) && offset < data.Size);
                }
                catch (IndexOutOfRangeException ex)
                {
                    throw new Debug.ExceptionLog(ex, "Offset was outside the bounds of the data array.");
                }
                #endregion

                // ...and add it
                value.Add(new ScriptStringEntry(stringEntry.ToString(), offset - (stringEntry.Length + 1)));

                // we're in the padding area now
                if (btchar == garbage_id)
                {
                    break;
                }
            }

            bool found_empty = false;
            for (int x = 0; x < value.Count; x++)
            {
                if (!found_empty)                 // do this shit until we find the first empty string...
                {
                    found_empty = value[x].Data == "";
                    continue;
                }

                // then do this for every empty string we may find
                if (value[x].Data == "" && found_empty)
                {
                    value.RemoveAt(x--);
                }
            }

            // find the shit we only care for and return it
            ste = new ScriptStringEntry[value.Count];
            for (int x = 0; x < value.Count; x++)
            {
                ste[x] = value[x];
            }

            return(ste);
        }