Exemplo n.º 1
0
        private string FormatCode()
        {
            UDecompilingState.AddTabs(1);
            string locals = FormatLocals();

            if (locals != String.Empty)
            {
                locals += "\r\n";
            }
            string code;

            try
            {
                code = DecompileScript();
            }
            catch (Exception e)
            {
                code = e.Message;
            }
            finally
            {
                UDecompilingState.RemoveTabs(1);
            }

            // Empty function!
            if (String.IsNullOrEmpty(locals) && String.IsNullOrEmpty(code))
            {
                return(String.Empty);
            }

            return(UnrealConfig.PrintBeginBracket() + "\r\n" +
                   locals +
                   code +
                   UnrealConfig.PrintEndBracket());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Decompiles this object into a text format of:
 ///
 /// enum NAME
 /// {
 ///     [ELEMENTS]
 /// };
 /// </summary>
 /// <returns></returns>
 public override string Decompile()
 {
     return(UDecompilingState.Tabs + FormatHeader() +
            UnrealConfig.PrintBeginBracket() +
            FormatNames() +
            UnrealConfig.PrintEndBracket() + ";");
 }
Exemplo n.º 3
0
        protected string FormatCPPText()
        {
            if (CppText == null)
            {
                return(String.Empty);
            }

            string output = String.Format("\r\n{0}{1}{2}\r\n",
                                          UDecompilingState.Tabs,
                                          CPPTextKeyword,
                                          UnrealConfig.PrintBeginBracket()
                                          );

            output += CppText.Decompile() + UnrealConfig.PrintEndBracket() + "\r\n";
            return(output);
        }
        /// <summary>
        /// Decompiles this object into a text format of:
        ///
        /// [FLAGS] state[()] NAME [extends NAME]
        /// {
        ///     [ignores Name[,Name];]
        ///
        ///     [FUNCTIONS]
        ///
        /// [STATE CODE]
        /// };
        /// </summary>
        /// <returns></returns>
        public override string Decompile()
        {
            string content = FormatHeader() + UnrealConfig.PrintBeginBracket();

            UDecompilingState.AddTabs(1);

            var locals = FormatLocals();

            if (locals != String.Empty)
            {
                content += "\r\n" + locals;
            }

            content += FormatIgnores() +
                       FormatConstants() +
                       FormatFunctions() +
                       DecompileScript();
            UDecompilingState.RemoveTabs(1);
            content += UnrealConfig.PrintEndBracket();
            return(content);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Decompiles this object into a text format of:
        ///
        /// struct [FLAGS] NAME [extends NAME]
        /// {
        ///     [STRUCTCPPTEXT]
        ///
        ///     [CONSTS]
        ///
        ///     [ENUMS]
        ///
        ///     [STRUCTS]
        ///
        ///     [VARIABLES]
        ///
        ///     [STRUCTDEFAULTPROPERTIES]
        /// };
        /// </summary>
        /// <returns></returns>
        public override string Decompile()
        {
            string content = UDecompilingState.Tabs + FormatHeader() +
                             UnrealConfig.PrintBeginBracket();

            UDecompilingState.AddTabs(1);
            string cpptext = FormatCPPText();
            string props   = FormatProperties();

            string defProps = FormatDefaultProperties();

            if (defProps.Length != 0)
            {
                defProps += "\r\n";
            }
            UDecompilingState.RemoveTabs(1);
            content += cpptext + props + defProps;
            if (content.EndsWith("\r\n"))
            {
                content = content.TrimEnd('\r', '\n');
            }
            return(content + UnrealConfig.PrintEndBracket() + ";");
        }
Exemplo n.º 6
0
        public string FormatReplication()
        {
            if (DataScriptSize <= 0)
            {
                return(string.Empty);
            }

            var replicatedObjects = new List <IUnrealNetObject>();

            if (Variables != null)
            {
                replicatedObjects.AddRange(Variables.Where(prop => prop.HasPropertyFlag(Flags.PropertyFlagsLO.Net) && prop.RepOffset != ushort.MaxValue));
            }

            if (Package.Version < VReliableDeprecation && Functions != null)
            {
                replicatedObjects.AddRange(Functions.Where(func => func.HasFunctionFlag(Flags.FunctionFlags.Net) && func.RepOffset != ushort.MaxValue));
            }

            if (replicatedObjects.Count == 0)
            {
                return(string.Empty);
            }

            var statements = new Dictionary <uint, List <IUnrealNetObject> >();

            replicatedObjects.Sort((ro, ro2) => ro.RepKey.CompareTo(ro2.RepKey));
            for (int netIndex = 0; netIndex < replicatedObjects.Count; ++netIndex)
            {
                var firstObject = replicatedObjects[netIndex];
                var netObjects  = new List <IUnrealNetObject> {
                    firstObject
                };
                for (int nextIndex = netIndex + 1; nextIndex < replicatedObjects.Count; ++nextIndex)
                {
                    var nextObject = replicatedObjects[nextIndex];
                    if (nextObject.RepOffset != firstObject.RepOffset ||
                        nextObject.RepReliable != firstObject.RepReliable
                        )
                    {
                        netIndex = nextIndex - 1;
                        break;
                    }
                    netObjects.Add(nextObject);
                }

                netObjects.Sort((o, o2) => string.Compare(o.Name, o2.Name, StringComparison.Ordinal));
                if (!statements.ContainsKey(firstObject.RepKey))
                {
                    statements.Add(firstObject.RepKey, netObjects);
                }
            }
            replicatedObjects.Clear();

            var output = new StringBuilder("\r\n" + "replication" + UnrealConfig.PrintBeginBracket());

            UDecompilingState.AddTab();

            foreach (var statement in statements)
            {
                try
                {
                    var pos = (ushort)(statement.Key & 0x0000FFFF);
                    var rel = Convert.ToBoolean(statement.Key & 0xFFFF0000);

                    output.Append("\r\n" + UDecompilingState.Tabs);
                    if (!UnrealConfig.SuppressComments)
                    {
                        output.AppendFormat("// Pos:0x{0:X3}\r\n{1}", pos, UDecompilingState.Tabs);
                    }

                    ByteCodeManager.Deserialize();
                    ByteCodeManager.JumpTo(pos);
                    string statementCode;
                    try
                    {
                        statementCode = ByteCodeManager.CurrentToken.Decompile();
                    }
                    catch (Exception e)
                    {
                        statementCode = string.Format("/* An exception occurred while decompiling condition ({0}) */", e);
                    }
                    var statementType   = Package.Version < VReliableDeprecation ? rel ? "reliable" : "unreliable" : string.Empty;
                    var statementFormat = string.Format("{0} if({1})", statementType, statementCode);
                    output.Append(statementFormat);

                    UDecompilingState.AddTab();
                    // NetObjects
                    for (int i = 0; i < statement.Value.Count; ++i)
                    {
                        var shouldSplit = i % 2 == 0;
                        if (shouldSplit)
                        {
                            output.Append("\r\n" + UDecompilingState.Tabs);
                        }

                        var netObject = statement.Value[i];
                        output.Append(netObject.Name);

                        var isNotLast = i != statement.Value.Count - 1;
                        output.Append(isNotLast ? ", " : ";");
                    }
                    UDecompilingState.RemoveTab();

                    // IsNotLast
                    if (statements.Last().Key != statement.Key)
                    {
                        output.Append("\r\n");
                    }
                }
                catch (Exception e)
                {
                    output.AppendFormat("/* An exception occurred while decompiling a statement! ({0}) */", e);
                }
            }
            UDecompilingState.RemoveTab();
            output.Append(UnrealConfig.PrintEndBracket() + "\r\n");
            return(output.ToString());
        }