コード例 #1
0
        protected override void PrintChildren(TextBuilder result, LabelTableToken labelTable, bool showStartOffsets)
        {
            result.PushIndent();
            bool indented = false;

            for (int i = 0; i < Children.Count; i++)
            {
                var stmt = Children[i];
                if (stmt.Token is CaseToken || stmt.Token is DefaultToken)
                {
                    if (indented)
                    {
                        result.PopIndent();
                        indented = false;
                    }
                    result.Indent().Append(stmt.Token.ToString()).Append(":").NewLine();
                }
                else
                {
                    if (!indented)
                    {
                        indented = true;
                        result.PushIndent();
                    }
                    stmt.Print(result, labelTable, showStartOffsets);
                }
            }
            if (indented)
            {
                result.PopIndent();
            }
            result.PopIndent();
        }
コード例 #2
0
 public void Print(TextBuilder result, LabelTableToken labelTable, bool showStartOffset)
 {
     result.PushIndent();
     statements.ForEach(s => s.Print(result, labelTable, showStartOffset));
     result.PopIndent();
 }
コード例 #3
0
        public void Decompile(TextBuilder result, bool createControlStatements)
        {
            result.Indent();
            if (Native)
            {
                result.Append("native");
                if (_nativeIndex > 0)
                {
                    result.Append("(").Append(_nativeIndex).Append(")");
                }
                result.Append(" ");
            }

            _flags.Except("Native", "Event", "Delegate", "Defined", "Public", "HasDefaults", "HasOutParms").Each(f => result.Append(f.ToLower() + " "));

            if (HasFlag("Event"))
            {
                result.Append("event ");
            }
            else if (HasFlag("Delegate"))
            {
                result.Append("delegate ");
            }
            else
            {
                result.Append("function ");
            }
            string type = GetReturnType();

            if (type != null)
            {
                result.Append(type).Append(" ");
            }
            result.Append(_self.ObjectName.Instanced).Append("(");
            int paramCount = 0;
            var locals     = new List <ExportEntry>();

            Tokens     = new List <BytecodeSingularToken>();
            Statements = ReadBytecode();
            List <ExportEntry> childrenReversed = _self.FileRef.Exports.Where(x => x.idxLink == _self.UIndex).ToList();

            childrenReversed.Reverse();

            //Get local children of this function
            foreach (ExportEntry export in childrenReversed)
            {
                //Reading parameters info...
                if (export.ClassName.EndsWith("Property"))
                {
                    UnrealFlags.EPropertyFlags ObjectFlagsMask = (UnrealFlags.EPropertyFlags)BitConverter.ToUInt64(export.Data, 0x18);
                    if (ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.Parm) && !ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.ReturnParm))
                    {
                        if (paramCount > 0)
                        {
                            result.Append(", ");
                        }

                        if (export.ClassName == "ObjectProperty" || export.ClassName == "StructProperty")
                        {
                            var    uindexOfOuter = BitConverter.ToInt32(export.Data, export.Data.Length - 4);
                            IEntry entry         = export.FileRef.GetEntry(uindexOfOuter);
                            if (entry != null)
                            {
                                result.Append($"{entry.ObjectName.Instanced} ");
                            }
                        }
                        else
                        {
                            result.Append($"{GetPropertyType(export)} ");
                        }

                        result.Append(export.ObjectName.Instanced);
                        paramCount++;

                        if (ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.OptionalParm) && Statements.Count > 0)
                        {
                            if (Statements[0].Token is NothingToken)
                            {
                                Statements.RemoveRange(0, 1);
                            }
                            else if (Statements[0].Token is DefaultParamValueToken)
                            {
                                result.Append(" = ").Append(Statements[0].Token.ToString());
                                Statements.RemoveRange(0, 1);
                            }
                        }
                    }
                    if (ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.ReturnParm))
                    {
                        break; //return param
                    }
                }

                //object instance = export.ReadInstance();
                //if (instance is UnClassProperty)
                //{
                //    var prop = (UnClassProperty)instance;
                //    if (prop.Parm)
                //    {
                //        if (!prop.ReturnParm)
                //        {
                //            if (paramCount > 0)
                //                result.Append(", ");

                //            prop.Flags.Except("Parm").Each(f => result.Append(f.ToLower() + " "));
                //            result.Append(prop.GetPropertyType()).Append(" ").Append(export.ObjectName);
                //            if (prop.OptionalParm && statements.Count > 0)
                //            {
                //                if (statements[0].Token is NothingToken)
                //                    statements.RemoveRange(0, 1);
                //                else if (statements[0].Token is DefaultParamValueToken)
                //                {
                //                    result.Append(" = ").Append(statements[0].Token.ToString());
                //                    statements.RemoveRange(0, 1);
                //                }
                //            }
                //            paramCount++;
                //        }
                //    }
                //    else
                //    {
                //        locals.Add(prop);
                //    }
                //}
            }
            result.Append(")");

            FunctionSignature = result.ToString();
            if (HasFlag("Defined"))
            {
                result.NewLine().Indent().Append("{").NewLine();
                result.PushIndent();
                foreach (var local in locals)
                {
                    result.Indent().Append("local ").Append(GetPropertyType(local)).Append(" ").Append(local.ObjectName.Instanced).Append(";").NewLine();
                }
                result.PopIndent();   // will be pushed again in DecompileBytecode()
                DecompileBytecode(Statements, result, createControlStatements);
                result.Indent().Append("}").NewLine().NewLine();
            }
            else
            {
                result.Append(";").NewLine().NewLine();
            }
        }