Exemplo n.º 1
0
        private static List <Tuple <string, string> > GenerateProperties(BINClass metaClass, Dictionary <uint, string> classNames, Dictionary <uint, string> fieldNames)
        {
            List <Tuple <string, string> > properties = new List <Tuple <string, string> >();

            foreach (BINProperty metaProperty in metaClass.properties)
            {
                string propertyType = GeneratePropertyType(metaProperty, classNames);
                string propertyName = GuessPropertyName(metaProperty.hash, fieldNames);
                string attribute    = "";

                if (!Regex.IsMatch(propertyName, @"^m\d+"))
                {
                    attribute = string.Format(@"[BINValue(""{0}"")]", propertyName);

                    if (propertyName[0] == 'm' && char.IsUpper(propertyName[1]))
                    {
                        propertyName = propertyName.Substring(1);
                    }
                    else if (char.IsLower(propertyName[0]))
                    {
                        propertyName = char.ToUpper(propertyName[0]) + propertyName.Substring(1);
                    }
                }
                else
                {
                    attribute = string.Format(@"[BINValue({0})]", metaProperty.hash);
                }

                properties.Add(new Tuple <string, string>(attribute, propertyType + " " + propertyName + " { get; set; }"));
            }

            return(properties);
        }
Exemplo n.º 2
0
        public static IEnumerable <string> GenerateClasses(List <BINClass> metaClasses, Dictionary <uint, string> classNames, Dictionary <uint, string> fieldNames)
        {
            foreach (BINClass metaClass in metaClasses)
            {
                yield return(GenerateClass(metaClass, GetInterfaces(metaClass), classNames, fieldNames));
            }

            List <BINClass> GetInterfaces(BINClass metaClass)
            {
                List <BINClass> interfaces = new List <BINClass>();

                if (metaClass.parentClass != 0)
                {
                    BINClass parent = metaClasses.Find(x => x.hash == metaClass.parentClass);

                    if (parent.isInterface)
                    {
                        interfaces.AddRange(GetInterfaces(parent));
                        interfaces.Add(parent);
                    }
                }

                if (metaClass.implements.Count != 0)
                {
                    foreach (uint[] implement in metaClass.implements)
                    {
                        BINClass metaInterface = metaClasses.Find(x => x.hash == implement[0]);

                        interfaces.AddRange(GetInterfaces(metaInterface));
                        interfaces.Add(metaInterface);
                    }
                }

                return(interfaces);
            }
        }
Exemplo n.º 3
0
        public static string GenerateClass(BINClass metaClass, List <BINClass> interfaces, Dictionary <uint, string> classNames, Dictionary <uint, string> fieldNames)
        {
            string definition = "";
            string name       = GuessClassName(metaClass.hash, classNames);
            List <Tuple <string, string> > properties = new List <Tuple <string, string> >();

            if (!metaClass.isInterface)
            {
                foreach (BINClass interfaceClass in interfaces)
                {
                    properties.AddRange(GenerateProperties(interfaceClass, classNames, fieldNames));
                }
            }

            properties.AddRange(GenerateProperties(metaClass, classNames, fieldNames));


            definition += "public ";
            definition += metaClass.isInterface ? "interface " : "class ";
            definition += name;

            //Check class inheritance
            bool inheritsClass = metaClass.parentClass != 0;

            if (inheritsClass)
            {
                definition += " : " + GuessClassName(metaClass.parentClass, classNames);
            }

            //Check interface implementations
            if (metaClass.implements.Count != 0)
            {
                if (!inheritsClass)
                {
                    definition += " : ";
                }
                else
                {
                    definition += ", ";
                }

                for (int i = 0; i < metaClass.implements.Count; i++)
                {
                    definition += GuessClassName(metaClass.implements[i][0], classNames);

                    if (i + 1 != metaClass.implements.Count)
                    {
                        definition += ", ";
                    }
                }
            }

            definition += "\n{\n";

            foreach (Tuple <string, string> property in properties)
            {
                if (metaClass.isInterface)
                {
                    definition += string.Format("    {0} {1}\n", property.Item1, property.Item2);
                }
                else
                {
                    definition += string.Format("    {0} public {1}\n", property.Item1, property.Item2);
                }
            }

            if (!metaClass.isInterface)
            {
                definition += "\n";
                definition += "    public " + name + "()" + "\n    {\n" + "\n    }\n";
            }


            definition += "}";

            return(definition);
        }