Exemplo n.º 1
0
        public static string_id ReadStringID(this BinaryReader reader)
        {
            // Read a string_id object from the stream.
            string_id sid = new string_id();

            sid.handle = reader.ReadInt32();

            return(sid);
        }
Exemplo n.º 2
0
        public static string_id _CreateStringId(string str_const)
        {
            // Create a local buffer and copy the string constant to it.
            char[] safe_buffer = new char[string_id.k_string_id_value_length + 1];
            Array.Copy(str_const.ToCharArray(), safe_buffer, Math.Min(str_const.Length, string_id.k_string_id_value_length));

            // Format the string constant to remove any bad characters.
            _FormatStringId(ref safe_buffer);

            // "cast" the string buffer to an actual string.
            str_const = new string(safe_buffer).Replace("\0", "");

            // Try to get the handle for this string constant from the string_id globals hashtable.
            string_id handle = _GetStringIdHandle(str_const);

            if (handle != string_id._string_id_invalid)
            {
                return(handle);
            }

            // Check if the string_id table is full.
            if (Engine.Engine.g_string_id_count == Engine.Engine.k_maximum_string_ids)
            {
                return(string_id._string_id_invalid);
            }

            // Get the length of the string constant.
            int length = str_const.Length;

            // Check if there is enough room in the g_string_id_storage buffer to hold the string constant.
            if (Engine.Engine._g_string_id_storage_size + length + 1 > Engine.Engine.k_maximum_string_id_storage)
            {
                return(string_id._string_id_invalid);
            }

            // Store the address of the new string constant into the g_string_id_index_buffer array.
            Engine.Engine.g_string_id_index_buffer[Engine.Engine.g_string_id_count] = Engine.Engine._g_string_id_storage_size;

            // Increment g_string_id_count.
            Engine.Engine.g_string_id_count++;

            // Copy the string into the string_id storage buffer.
            Array.Copy(safe_buffer, 0, Engine.Engine.g_string_id_storage, Engine.Engine._g_string_id_storage_size, length);
            Engine.Engine._g_string_id_storage_size += length + 1;

            // Create the string_id handle from the index and length of the string constant.
            handle = new string_id((byte)length, (uint)Engine.Engine.g_string_id_count - 1);

            // Add the string constant to the string_id globals hashtable.
            Engine.Engine.g_string_id_globals.Add(str_const, handle);

            // Return the string_id handle we just created.
            return(handle);
        }
Exemplo n.º 3
0
        public static string string_id_get_string_const(string_id handle)
        {
            // Check that the index is less than the number of string_id's currently created.
            if (handle.ToIndex() >= Engine.Engine.g_string_id_count)
            {
                return(string.Empty);
            }

            // Get the pointer for the string constant from the string_id index buffer.
            int index = Engine.Engine.g_string_id_index_buffer[handle.ToIndex()];

            if (index == -1)
            {
                return(string.Empty);
            }

            // Cast the buffer from g_string_id_storage to a string.
            return(new string(Engine.Engine.g_string_id_storage, index, handle.Length));
        }
Exemplo n.º 4
0
        public static string_id _GetStringIdHandle(string str_const)
        {
            // Create a local buffer and copy the string constant to it.
            char[] safe_buffer = new char[string_id.k_string_id_value_length + 1];
            Array.Copy(str_const.ToCharArray(), safe_buffer, Math.Min(str_const.Length, string_id.k_string_id_value_length));

            // Format the string constant to remove any bad characters.
            _FormatStringId(ref safe_buffer);

            // "cast" the string buffer to an actual string.
            str_const = new string(safe_buffer).Replace("\0", "");

            // Check if the string_id globals hashtable has an entry for this string constant.
            string_id handle = string_id._string_id_invalid;

            Engine.Engine.g_string_id_globals.ContainsValue(str_const, ref handle);

            // Return the key that was or wasn't found.
            return(handle);
        }
Exemplo n.º 5
0
 public static void Write(this BinaryWriter writer, string_id sid)
 {
     // Write a string_id object to the stream.
     writer.Write(sid.handle);
 }