예제 #1
0
 public virtual void Print(TextBuilder result, LabelTableToken labelTable, bool showStartOffset, bool addEmptyline = true)
 {
     if (Token.ToString() == "")
     {
         return;
     }
     PrintLabel(labelTable, result);
     result.Indent();
     if (showStartOffset)
     {
         result.Append("/* ").Append(StartOffset).Append(" */ ");
     }
     result.Append(Token.ToString(), StartOffset, EndOffset).Append(";");
     if (addEmptyline)
     {
         result.Append("\n");
     }
 }
예제 #2
0
        public override void Decompile(TextBuilder result)
        {
            result.Append("class ").Append(_self.ObjectName.Instanced);
            if (_super != null)
            {
                result.Append(" extends ").Append(_super.ObjectName.Instanced);
            }
            if (_outerInstance != null && _outerInstance.ObjectName != "Object")
            {
                result.NewLine().Append("    within ").Append(_outerInstance.ObjectName.Instanced);
            }
            if (_hideCategories.Count > 0)
            {
                result.NewLine().Append("    hidecategories(").Append(string.Join(",", _hideCategories.ToArray())).Append(")");
            }
            if (_interfaces.Count > 0)
            {
                var intfNames = _interfaces.ConvertAll(e => e.ObjectName.Instanced).ToArray();
                result.NewLine().Append("    implements(").Append(string.Join(",", intfNames)).Append(")");
            }
            if (_config != "None")
            {
                result.NewLine().Append("    config(").Append(_config).Append(")");
            }
            _flags.Except("Compiled", "Parsed", "Config", "Localized").Each(f => result.NewLine().Append("    ").Append(f.ToLower()));
            result.Append(";").NewLine().NewLine();
            //DecompileChildren(result, false);

            var statementList = ReadBytecode(out var _);

            if (statementList.Count > 0)
            {
                DecompileReplicationBlock(result, statementList);
            }
            //if (_defaults != null)
            //{
            //    DecompileDefaultProperties(result);
            //}
        }
예제 #3
0
 private void DecompileReplicationBlock(TextBuilder result, StatementList statementList)
 {
     result.Append("replication\n{\n").PushIndent();
     for (int i = 0; i < statementList.Count; i++)
     {
         List <string> names = FindReplicatedProperties(statementList[i].StartOffset);
         if (names.Count > 0)
         {
             result.Indent().Append("if (").Append(statementList[i].Token.ToString()).Append(")").NewLine();
             result.Indent().Append("    ");
             foreach (string name in names)
             {
                 result.Append(name);
                 if (name != names.Last())
                 {
                     result.Append(", ");
                 }
             }
             result.Append(";").NewLine().NewLine();
         }
     }
     result.Append("}").NewLine().NewLine().PopIndent();
 }
예제 #4
0
        public void DecompileBytecode(StatementList statements, TextBuilder result, bool createControlStatements)
        {
            var labelTableStatement = statements.Find(s => s.Token is LabelTableToken);
            var labelTable          = (LabelTableToken)labelTableStatement?.Token;

            result.HasErrors = statements.HasErrors();
            if (createControlStatements)
            {
                try
                {
                    statements.CreateControlStatements();
                }
                catch (Exception)
                {
                    ProblemRegistry.RegisterIncompleteControlFlow(this);
                }
                if (statements.IsIncompleteControlFlow())
                {
                    ProblemRegistry.RegisterIncompleteControlFlow(this);
                }
                statements.RemoveRedundantReturns();
            }
            statements.Print(result, labelTable, !createControlStatements);
        }
예제 #5
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(out var bytecodeReader);

            // UI only
            // Man this code is bad
            // sorry
#if !DEBUG && !AZURE
            try
            {
#endif
            var s = bytecodeReader._reader;
            if (Export.ClassName == "State")
            {
                s.BaseStream.Skip(0x10); //Unknown
                var stateFlags       = s.ReadInt32();
                var unknown          = s.ReadInt16();
                var functionMapCount = s.ReadInt32();
                for (int i = 0; i < functionMapCount; i++)
                {
                    int spos  = (int)s.BaseStream.Position;
                    var name  = bytecodeReader.ReadName();
                    var entry = bytecodeReader.ReadEntryRef(out var _);
                    Statements.statements.Add(new Statement(spos, (int)s.BaseStream.Position, new NothingToken(spos, $"  {name} => {entry.FullPath}()"), bytecodeReader));
                }
            }
#if !DEBUG && !AZURE
        }

        catch (Exception e)
        {
            Debug.WriteLine("Exception..");
        }
#endif
            NameReferences  = bytecodeReader.NameReferences;
            EntryReferences = bytecodeReader.EntryReferences;
            //var childIdx = EndianReader.ToInt32(Export.DataReadOnly, 0x18, Export.FileRef.Endian);
            var childIdx = EndianReader.ToInt32(Export.Data, 0x18, Export.FileRef.Endian);
            var children = new List <ExportEntry>();
            while (Export.FileRef.TryGetUExport(childIdx, out var parsingExp))
            {
                children.Add(parsingExp);
                //childIdx = EndianReader.ToInt32(parsingExp.DataReadOnly, 0x10, Export.FileRef.Endian);
                childIdx = EndianReader.ToInt32(parsingExp.Data, 0x10, Export.FileRef.Endian);
            }

            //Get local children of this function
            foreach (ExportEntry export in children)
            {
                //Reading parameters info...
                if (export.ClassName.EndsWith("Property"))
                {
                    UnrealFlags.EPropertyFlags ObjectFlagsMask = (UnrealFlags.EPropertyFlags)EndianReader.ToUInt64(export.Data, 0x18, export.FileRef.Endian);
                    //UnrealFlags.EPropertyFlags ObjectFlagsMask = (UnrealFlags.EPropertyFlags)EndianReader.ToUInt64(export.DataReadOnly, 0x18, export.FileRef.Endian);
                    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 = EndianReader.ToInt32(export.DataReadOnly, export.DataSize - 4, export.FileRef.Endian);
                            var    uindexOfOuter = EndianReader.ToInt32(export.Data, export.Data.Length - 4, export.FileRef.Endian);
                            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();
            }
        }
예제 #6
0
 public override void Decompile(TextBuilder result)
 {
     Decompile(result, true);
 }
예제 #7
0
 protected override void PrintHead(TextBuilder result)
 {
     result.Append("switch (").Append(Token.ToString()).Append(")");
 }
예제 #8
0
 protected override void PrintHead(TextBuilder result)
 {
     result.Append("else");
 }
예제 #9
0
 protected abstract void PrintHead(TextBuilder result);
예제 #10
0
 public void Print(TextBuilder result, LabelTableToken labelTable, bool showStartOffset)
 {
     result.PushIndent();
     statements.ForEach(s => s.Print(result, labelTable, showStartOffset));
     result.PopIndent();
 }
예제 #11
0
 protected virtual void PrintChildren(TextBuilder result, LabelTableToken labelTable, bool showStartOffsets)
 {
     _children.Print(result, labelTable, showStartOffsets);
 }
예제 #12
0
 public abstract void Decompile(TextBuilder result);