示例#1
0
        /// <summary>
        /// Translates a stringID into an index into the global debug strings array.
        /// </summary>
        /// <param name="id">The StringID to translate.</param>
        /// <returns>The index of the string in the global debug strings array.</returns>
        public int StringIDToIndex(StringID id)
        {
            int closestSetIndex = ListSearching.BinarySearch<byte>(_setsByID.Keys, id.Set);
            if (closestSetIndex < 0)
            {
                // BinarySearch returns the bitwise complement of the index of the next highest value if not found
                // So, use the set that comes before it...
                closestSetIndex = ~closestSetIndex - 1;
                if (closestSetIndex < 0)
                    return id.Value; // No previous set defined - just return the handle
            }

            // If the index falls outside the set's min value, then put it into the previous set
            if (id.Index < _setsByID.Values[closestSetIndex].MinIndex)
            {
                closestSetIndex--;
                if (closestSetIndex < 0)
                    return id.Value;
            }

            // Calculate the array index by subtracting the value of the first ID in the set
            // and then adding the index in the global array of the set's first string
            StringIDSet set = _setsByID.Values[closestSetIndex];
            StringID firstId = new StringID(set.ID, set.MinIndex);
            return id.Value - firstId.Value + set.GlobalIndex;
        }
示例#2
0
 public StringIDData(string name, uint offset, uint address, StringID sid, StringIDSource source, Trie autocompleteTrie, uint pluginLine)
     : base(name, offset, address, pluginLine)
 {
     _value = sid;
     _source = source;
     _autocompleteTrie = autocompleteTrie;
 }
示例#3
0
        /// <summary>
        ///     Returns the string that corresponds with the given StringID.
        /// </summary>
        /// <param name="id">The StringID of the string to retrieve.</param>
        /// <returns>The string if it exists, or null otherwise.</returns>
        public string GetString(StringID id)
        {
            int index = StringIDToIndex(id);

            if (index != -1)
            {
                return(GetString(index));
            }
            return(null);
        }
示例#4
0
        /// <summary>
        ///     Sets a stringID's corresponding string.
        /// </summary>
        /// <param name="id">The stringID of the string to set.</param>
        /// <param name="str">The new value of the string.</param>
        public void SetString(StringID id, string str)
        {
            int index = StringIDToIndex(id);

            if (index == -1)
            {
                throw new ArgumentException("StringID does not exist");
            }
            SetString(index, str);
        }
        /// <summary>
        /// Translates a string index into a stringID which can be written to the file.
        /// </summary>
        /// <param name="index">The index of the string in the global strings array.</param>
        /// <returns>The stringID associated with the index.</returns>
        public StringID IndexToStringID(int index)
        {
            // Determine which set the index belongs to by finding the set with the closest global index that comes before it
            int closestSetIndex = ListSearching.BinarySearch<int>(_setsByGlobalIndex.Keys, index);
            if (closestSetIndex < 0)
            {
                // BinarySearch returns the bitwise complement of the index of the next highest value if not found
                // So negate it and subtract 1 to get the closest global index that comes before it
                closestSetIndex = ~closestSetIndex - 1;
                if (closestSetIndex < 0)
                    return new StringID((uint)index); // No previous set defined - just return the index
            }

            // Calculate the StringID by subtracting the set's global array index
            // and then adding the value of the first stringID in the set
            StringIDSet set = _setsByGlobalIndex.Values[closestSetIndex];
            StringID firstId = new StringID(set.ID, set.MinIndex, IDLayout);
            return new StringID((uint)(index - set.GlobalIndex + firstId.Value));
        }
        /// <summary>
        /// Translates a stringID into an index into the global debug strings array.
        /// </summary>
        /// <param name="id">The StringID to translate.</param>
        /// <returns>The index of the string in the global debug strings array.</returns>
        public int StringIDToIndex(StringID id)
        {
            foreach (StringIDModifier modifier in _modifiers)
            {
                bool modify = false;

                if (modifier.IsGreaterThan)
                    modify = (id.Value > modifier.Identifier);
                else
                    modify = (id.Value < modifier.Identifier);

                if (modify)
                {
                    if (modifier.IsAddition)
                        return id.Value + modifier.Modifier;
                    else
                        return id.Value - modifier.Modifier;
                }
            }
            return id.Value;
        }
        /// <summary>
        ///     Translates a string index into a stringID which can be written to the file.
        /// </summary>
        /// <param name="index">The index of the string in the global strings array.</param>
        /// <returns>The stringID associated with the index.</returns>
        public StringID IndexToStringID(int index)
        {
            // Determine which set the index belongs to by finding the set with the closest global index that comes before it
            int closestSetIndex = ListSearching.BinarySearch(_setsByGlobalIndex.Keys, index);

            if (closestSetIndex < 0)
            {
                // BinarySearch returns the bitwise complement of the index of the next highest value if not found
                // So negate it and subtract 1 to get the closest global index that comes before it
                closestSetIndex = ~closestSetIndex - 1;
                if (closestSetIndex < 0)
                {
                    return(new StringID((uint)index));                     // No previous set defined - just return the index
                }
            }

            // Calculate the StringID by subtracting the set's global array index
            // and then adding the value of the first stringID in the set
            StringIDSet set     = _setsByGlobalIndex.Values[closestSetIndex];
            var         firstId = new StringID(set.ID, set.MinIndex, IDLayout);

            return(new StringID((uint)(index - set.GlobalIndex + firstId.Value)));
        }
示例#8
0
 /// <summary>
 ///     Translates a stringID read from the file into an index in the table.
 /// </summary>
 /// <param name="id">The StringID to translate.</param>
 /// <returns>The index of the string in the table, or -1 if not found.</returns>
 public abstract int StringIDToIndex(StringID id);
 /// <summary>
 /// Translates a stringID into an index into the global debug strings array.
 /// </summary>
 /// <param name="id">The StringID to translate.</param>
 /// <returns>The index of the string in the global debug strings array.</returns>
 public int StringIDToIndex(StringID id)
 {
     return (int)id.GetIndex(IDLayout);
 }
示例#10
0
		private void ReadStringId(DataBlock block, uint offset)
		{
			SeekToOffset(block, offset);
			var sid = new StringID(_reader.ReadUInt32());
			if (sid == StringID.Null) return;

			var str = _cacheFile.StringIDs.GetString(sid);
			if (str == null) return;

			var fixup = new DataBlockStringIDFixup(str, (int) offset);
			block.StringIDFixups.Add(fixup);
		}
 /// <summary>
 /// Translates a stringID into an index into the global debug strings array.
 /// </summary>
 /// <param name="id">The StringID to translate.</param>
 /// <returns>The index of the string in the global debug strings array.</returns>
 public int StringIDToIndex(StringID id)
 {
     return (int)id.Index;
 }
示例#12
0
 public override int StringIDToIndex(StringID id)
 {
     if (_resolver != null)
         return _resolver.StringIDToIndex(id);
     return -1;
 }
示例#13
0
 /// <summary>
 /// Constructs a new Locale.
 /// </summary>
 /// <param name="id">The locale's stringID.</param>
 /// <param name="value">The localized string.</param>
 public Locale(StringID id, string value)
 {
     ID = id;
     Value = value;
 }
 /// <summary>
 ///     Translates a stringID into an index into the global debug strings array.
 /// </summary>
 /// <param name="id">The StringID to translate.</param>
 /// <returns>The index of the string in the global debug strings array.</returns>
 public int StringIDToIndex(StringID id)
 {
     return(id.GetIndex(IDLayout));
 }