コード例 #1
0
ファイル: MetaDumpClass.cs プロジェクト: Hengle/LeagueToolkit
        internal List <uint> GetInterfacesRecursive(List <MetaDumpClass> classes, bool includeMainParent)
        {
            List <uint> interfaces = new();

            if (includeMainParent && classes.FirstOrDefault(x => x.Hash == this.ParentClass && x.IsInterface) is MetaDumpClass parentInterface)
            {
                interfaces.Add(parentInterface.Hash);
                interfaces.AddRange(parentInterface.GetInterfacesRecursive(classes, true));
            }

            for (int i = 0; i < this.Implements.Count; i++)
            {
                uint          interfaceHash  = this.Implements[i][0];
                MetaDumpClass interfaceClass = classes.FirstOrDefault(x => x.Hash == interfaceHash && x.IsInterface);

                interfaces.Add(interfaceHash);

                if (interfaceClass is not null)
                {
                    interfaces.AddRange(interfaceClass.GetInterfacesRecursive(classes, true));
                }
                else
                {
                    throw new InvalidOperationException("Failed to find interface: " + interfaceHash);
                }
            }

            return(interfaces);
        }
コード例 #2
0
 private void WriteClassAttribute(StreamWriter sw, string dumpClassHash, MetaDumpClass dumpClass, Dictionary <uint, string> classNames)
 {
     if (classNames.TryGetValue(Convert.ToUInt32(dumpClassHash, 16), out string className))
     {
         sw.WriteLineIndented(1, @"[MetaClass(""{0}"")]", className);
     }
     else
     {
         sw.WriteLineIndented(1, "[MetaClass({0})]", Convert.ToUInt32(dumpClassHash, 16));
     }
 }
コード例 #3
0
        private void WriteClass(StreamWriter sw, MetaDumpClass dumpClass, Dictionary <uint, string> classNames, Dictionary <uint, string> propertyNames)
        {
            WriteClassAttribute(sw, dumpClass, classNames);

            sw.Write("    public ");
            sw.Write(dumpClass.IsInterface ? "interface" : "class");
            sw.Write(" {0}", GetClassNameOrDefault(dumpClass.Hash, classNames));

            MetaDumpClass mainParent = this.Classes.FirstOrDefault(x => x.Hash == dumpClass.ParentClass);

            if (mainParent is null)
            {
                sw.Write(" : ");
                sw.Write("IMetaClass");
            }
            else
            {
                sw.Write(" : ");
                sw.Write(GetClassNameOrDefault(mainParent.Hash, classNames));
            }

            // Write interfaces
            List <uint> interfaces = dumpClass.GetInterfaces(this.Classes, false);

            if (interfaces.Count != 0)
            {
                sw.Write(", ");

                for (int i = 0; i < interfaces.Count; i++)
                {
                    uint   interfaceHash = interfaces[i];
                    string interfaceName = GetClassNameOrDefault(interfaceHash, classNames);

                    sw.Write(" {0}", interfaceName);

                    if (i + 1 != dumpClass.Implements.Count)
                    {
                        sw.Write(',');
                    }
                }
            }

            // End declaration
            sw.WriteLine();

            // Start members
            sw.WriteLineIndented(1, "{");

            WriteClassProperties(sw, dumpClass, classNames, propertyNames);

            // End members
            sw.WriteLineIndented(1, "}");
        }
コード例 #4
0
        private void WriteClass(StreamWriter sw, string classHash, MetaDumpClass dumpClass, Dictionary <uint, string> classNames, Dictionary <uint, string> propertyNames)
        {
            WriteClassAttribute(sw, classHash, dumpClass, classNames);

            sw.Write("    public ");
            sw.Write(dumpClass.Is.Interface ? "interface" : "class");
            sw.Write(" {0}", GetClassNameOrDefault(classHash, classNames));

            if (dumpClass.ParentClass is not null && this.Classes.ContainsKey(dumpClass.ParentClass))
            {
                sw.Write(" : ");
                sw.Write(GetClassNameOrDefault(dumpClass.ParentClass, classNames));
            }
コード例 #5
0
        private void WriteProperty(StreamWriter sw, MetaDumpClass dumpClass, MetaDumpProperty property, bool isPublic, Dictionary <uint, string> classNames, Dictionary <uint, string> propertyNames)
        {
            WritePropertyAttribute(sw, property, propertyNames);

            string visibility      = isPublic ? "public " : string.Empty;
            string typeDeclaration = GetPropertyTypeDeclaration(property, classNames);
            string propertyName    = StylizePropertyName(GetPropertyNameOrDefault(property.Hash, propertyNames));

            // Check that property name isn't the same as the class name
            string className = GetClassNameOrDefault(dumpClass.Hash, classNames);

            if (className == propertyName)
            {
                propertyName = 'm' + propertyName;
            }

            string formatted = string.Format("{0}{1} {2}", visibility, typeDeclaration, propertyName);

            sw.WriteLineIndented(2, formatted + " { get; set; }");
        }
コード例 #6
0
        private void WriteClassProperties(StreamWriter sw, MetaDumpClass dumpClass, Dictionary <uint, string> classNames, Dictionary <uint, string> propertyNames)
        {
            // Write properties of interfaces
            if (dumpClass.IsInterface is false)
            {
                foreach (uint interfaceHash in dumpClass.GetInterfacesRecursive(this.Classes, true))
                {
                    if (this.Classes.FirstOrDefault(x => x.Hash == interfaceHash && x.IsInterface) is MetaDumpClass interaceClass)
                    {
                        foreach (MetaDumpProperty property in interaceClass.Properties)
                        {
                            WriteProperty(sw, interaceClass, property, true, classNames, propertyNames);
                        }
                    }
                }
            }

            foreach (MetaDumpProperty property in dumpClass.Properties)
            {
                WriteProperty(sw, dumpClass, property, !dumpClass.IsInterface, classNames, propertyNames);
            }
        }