protected override void PrintHead(TextBuilder result) { var foreachToken = (ForeachToken)Token; result.Append("foreach ").Append(foreachToken.Expr.ToString()); if (foreachToken.IteratorExpr != null) { result.Append("(").Append(foreachToken.IteratorExpr.ToString()).Append(")"); } }
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"); } }
protected void PrintLabel(LabelTableToken labelTable, TextBuilder result) { if (labelTable != null) { var label = labelTable.GetLabel(StartOffset); if (label != null) { result.Append(label).Append(":").NewLine(); } } }
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(); if (statementList.Count > 0) { DecompileReplicationBlock(result, statementList); } //if (_defaults != null) //{ // DecompileDefaultProperties(result); //} }
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(); }
public override void Print(TextBuilder result, LabelTableToken labelTable, bool showStartOffsets, bool addEmptyLine = true) { PrintLabel(labelTable, result); result.Indent(); PrintHead(result); result.Append("\n"); result.Indent().Append("{\n"); PrintChildren(result, labelTable, showStartOffsets); result.Indent().Append("}"); // result.Append(" // ").Append(_endOffset.ToString()); if (addEmptyLine) { result.NewLine(); } }
protected override void PrintHead(TextBuilder result) { result.Append("switch (").Append(Token.ToString()).Append(")"); }
protected override void PrintHead(TextBuilder result) { result.Append("else"); }
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(); } }