예제 #1
0
        public static void LoadBlocksData(string data)
        {
            Dictionary <Block, bool> dictionary = new Dictionary <Block, bool>();

            data = data.Replace("\r", string.Empty);
            string[] array = data.Split(new char[1]
            {
                '\n'
            }, StringSplitOptions.RemoveEmptyEntries);
            string[] array2 = null;
            for (int i = 0; i < array.Length; i++)
            {
                string[] array3 = array[i].Split(';');
                if (i == 0)
                {
                    array2 = new string[array3.Length - 1];
                    Array.Copy(array3, 1, array2, 0, array3.Length - 1);
                    continue;
                }
                if (array3.Length != array2.Length + 1)
                {
                    throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 2), (array3.Length != 0) ? array3[0] : LanguageControl.Get("Usual", "unknown")));
                }
                string typeName = array3[0];
                if (string.IsNullOrEmpty(typeName))
                {
                    continue;
                }
                Block block = m_blocks.FirstOrDefault((Block v) => v.GetType().Name == typeName);
                if (block == null)
                {
                    throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 3), typeName));
                }
                if (dictionary.ContainsKey(block))
                {
                    throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 4), typeName));
                }
                dictionary.Add(block, value: true);
                Dictionary <string, FieldInfo> dictionary2 = new Dictionary <string, FieldInfo>();
                foreach (FieldInfo runtimeField in block.GetType().GetRuntimeFields())
                {
                    if (runtimeField.IsPublic && !runtimeField.IsStatic)
                    {
                        dictionary2.Add(runtimeField.Name, runtimeField);
                    }
                }
                for (int j = 1; j < array3.Length; j++)
                {
                    string text  = array2[j - 1];
                    string text2 = array3[j];
                    if (!string.IsNullOrEmpty(text2))
                    {
                        if (!dictionary2.TryGetValue(text, out FieldInfo value))
                        {
                            throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 5), text));
                        }
                        object obj = null;
                        if (text2.StartsWith("#"))
                        {
                            string refTypeName = text2.Substring(1);
                            obj = ((!string.IsNullOrEmpty(refTypeName)) ? ((object)(m_blocks.FirstOrDefault((Block v) => v.GetType().Name == refTypeName) ?? throw new InvalidOperationException(string.Format(LanguageControl.Get("BlocksManager", 6), refTypeName))).BlockIndex) : ((object)block.BlockIndex));
                        }
                        else
                        {
                            obj = HumanReadableConverter.ConvertFromString(value.FieldType, text2);
                        }
                        value.SetValue(block, obj);
                    }
                }
            }
        }