public Expression DecompileContext(bool isClass = false) { PopByte(); var left = DecompileExpression(); if (left == null) { return(null); // ERROR } ReadInt16(); // discard MemSize value. (size of expr-right in half-bytes) ReadObject(); // discard RetValRef. ReadByte(); // discard unknown byte. isInClassContext = isClass; var right = DecompileExpression(); if (right == null) { return(null); // ERROR } isInClassContext = false; if (isClass) { var builder = new CodeBuilderVisitor(); // what a wonderful hack, TODO. left.AcceptVisitor(builder); var str = builder.GetCodeString() + ".static"; left = new SymbolReference(null, null, null, str); } StartPositions.Pop(); return(new CompositeSymbolRef(left, right, null, null)); }
public DynArrayFindStructMember DecompileDynArrayFindStructMember() { PopByte(); var arr = DecompileExpression(); if (arr == null) { return(null); } ReadInt16(); // MemSize var memberNameArg = DecompileExpression(); if (memberNameArg == null) { return(null); } var valueArg = DecompileExpression(); if (valueArg == null) { return(null); } PopByte(); //EndFuncParms StartPositions.Pop(); return(new DynArrayFindStructMember(arr, memberNameArg, valueArg)); }
public Expression DecompilePrimitiveCast() { PopByte(); var typeToken = ReadByte(); var expr = DecompileExpression(); if (expr == null) { return(null); // ERROR } // TODO: map this out, possibly most are implicit? string type = PrimitiveCastTable[typeToken]; StartPositions.Pop(); if (typeToken == (byte)ECast.ByteToInt && expr is IntegerLiteral || typeToken == (byte)ECast.InterfaceToObject) { return(expr); } //re-enable this once testing is complete //if (typeToken == (byte)ECast.IntToFloat && expr is IntegerLiteral shouldBeFloat) //{ // return new FloatLiteral(shouldBeFloat.Value); //} return(new PrimitiveCast((ECast)typeToken, new VariableType(type), expr, null, null)); }
public Expression DecompileNew() { PopByte(); var parms = new List <Expression>(); for (int n = 0; n < 5; n++) { if (CurrentIs(OpCodes.Nothing)) { PopByte(); parms.Add(null); continue; } var param = DecompileExpression(); if (param == null) { return(null); // ERROR } parms.Add(param); } StartPositions.Pop(); return(new NewOperator(parms[0], parms[1], parms[2], parms[3], parms[4])); }
public ReturnStatement DecompileReturn() { PopByte(); Expression expr = null; if (CurrentIs(StandardByteCodes.ReturnNullValue)) { // TODO: research this a bit, seems to be the zero-equivalent value for the return type. PopByte(); var retVal = ReadObject(); expr = new SymbolReference(null, null, null, "null"); // TODO: faulty obv, kind of illustrates the thing though. } else if (CurrentIs(StandardByteCodes.Nothing)) { PopByte(); } else { expr = DecompileExpression(); if (expr == null && PopByte() != (byte)StandardByteCodes.Nothing) { return(null); //ERROR ? } } var statement = new ReturnStatement(null, null, expr); StatementLocations.Add(StartPositions.Pop(), statement); return(statement); }
public Expression DecompileConditionalExpression() { PopByte(); var cond = DecompileExpression(); if (cond == null) { return(null); // ERROR } ReadInt16(); // MemSizeA var trueExpr = DecompileExpression(); if (trueExpr == null) { return(null); // ERROR } ReadInt16(); // MemSizeB var falseExpr = DecompileExpression(); if (falseExpr == null) { return(null); // ERROR } StartPositions.Pop(); return(new ConditionalExpression(cond, trueExpr, falseExpr, null, null)); }
public DynArrayInsertItem DecompileDynArrayInsertItem() { PopByte(); var arr = DecompileExpression(); if (arr == null) { return(null); } ReadInt16(); // MemSize var indexArg = DecompileExpression(); if (indexArg == null) { return(null); } var valueArg = DecompileExpression(); if (valueArg == null) { return(null); } PopByte(); //EndFuncParms StartPositions.Pop(); return(new DynArrayInsertItem(arr, indexArg, valueArg)); }
public Expression DecompileInOpNaive(String opName, bool useEndOfParms = false, bool isStruct = false) { // TODO: ugly, wrong. PopByte(); if (isStruct) { ReadObject(); // struct type? } var left = DecompileExpression(); if (left == null) { return(null); // ERROR } var right = DecompileExpression(); if (right == null) { return(null); // ERROR } if (useEndOfParms) { PopByte(); } StartPositions.Pop(); var op = new InOpDeclaration(opName, 0, true, null, null, null, null, null, null, null); return(new InOpReference(op, left, right, null, null)); }
public DynArrayInsert DecompileDynArrayInsert() { PopByte(); var arr = DecompileExpression(); if (arr == null) { return(null); } var indexArg = DecompileExpression(); if (indexArg == null) { return(null); } var countArg = DecompileExpression(); if (countArg == null) { return(null); } PopByte(); //EndFuncParms StartPositions.Pop(); return(new DynArrayInsert(arr, indexArg, countArg)); }
public Statement DecompileForEach(bool isDynArray = false) { PopByte(); var scopeStatements = new List <Statement>(); var iteratorFunc = DecompileExpression(); if (iteratorFunc == null) { return(null); } if (isDynArray) { Expression dynArrVar = DecompileExpression(); bool hasIndex = Convert.ToBoolean(ReadByte()); Expression dynArrIndex = DecompileExpression(); iteratorFunc = new DynArrayIterator(iteratorFunc, dynArrVar, dynArrIndex); } var scopeEnd = ReadUInt16(); // MemOff ForEachScopes.Push(scopeEnd); Scopes.Add(scopeStatements); CurrentScope.Push(Scopes.Count - 1); while (Position < Size) { if (CurrentIs(OpCodes.IteratorNext)) { PopByte(); // IteratorNext if (PeekByte == (byte)OpCodes.IteratorPop) { StatementLocations[(ushort)(Position - 1)] = new IteratorNext(); StatementLocations[(ushort)Position] = new IteratorPop(); PopByte(); // IteratorPop break; } Position--; } var current = DecompileStatement(); if (current == null) { return(null); // ERROR ? } scopeStatements.Add(current); } CurrentScope.Pop(); ForEachScopes.Pop(); var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements)) { iteratorPopPos = Position - 1 }; StatementLocations.Add(StartPositions.Pop(), statement); return(statement); }
public Expression DecompileInstanceDelegate() // TODO: check code, seems ok? { PopByte(); var name = PCC.GetName(ReadNameRef()); StartPositions.Pop(); return(new SymbolReference(null, null, null, "UNSUPPORTED: InstanceDelegate: " + name)); }
public Expression DecompileNativeParm() // TODO: see code { PopByte(); var obj = ReadObject(); StartPositions.Pop(); return(new SymbolReference(null, "UNSUPPORTED: NativeParm: " + obj.ObjectName.Instanced + " : " + obj.ClassName, null, null)); }
public Expression DecompileInstanceDelegate() // TODO: check code, seems ok? { PopByte(); var name = ReadNameReference(); StartPositions.Pop(); return(new SymbolReference(null, name)); }
public StringLiteral DecompileStringConst() { PopByte(); var value = ReadNullTerminatedString(); StartPositions.Pop(); return(new StringLiteral(value)); }
public ObjectLiteral DecompileObjectConst() { PopByte(); var value = ReadObject(); StartPositions.Pop(); return(new ObjectLiteral(new NameLiteral(value.ClassName == "Class" || value.Parent == ContainingClass.Export ? value.ObjectName.Instanced : value.InstancedFullPath), new VariableType(value.ClassName))); }
public IntegerLiteral DecompileByteConst() { PopByte(); var value = ReadByte(); StartPositions.Pop(); return(new IntegerLiteral(value, null, null)); }
public Expression DecompileDelegateProperty() // TODO: is this proper? Is it even used in ME3? { PopByte(); var name = ReadNameReference(); var obj = ReadObject(); StartPositions.Pop(); return(new SymbolReference(null, name, null, null)); }
public NameLiteral DecompileNameConst() { PopByte(); var value = ReadNameReference(); StartPositions.Pop(); return(new NameLiteral(value.Instanced)); }
public IntegerLiteral DecompileIntConst() { PopByte(); var value = ReadInt32(); StartPositions.Pop(); return(new IntegerLiteral(value)); }
public FloatLiteral DecompileFloatConst() { PopByte(); var value = ReadFloat(); StartPositions.Pop(); return(new FloatLiteral(value)); }
public StringRefLiteral DecompileStringRefConst() { PopByte(); var value = ReadInt32(); StartPositions.Pop(); return(new StringRefLiteral(value)); }
public NameLiteral DecompileNameConst() { PopByte(); var value = PCC.GetName(ReadNameRef()); StartPositions.Pop(); return(new NameLiteral(value, null, null)); }
public RotatorLiteral DecompileRotationConst() { PopByte(); var pitch = ReadInt32(); var yaw = ReadInt32(); var roll = ReadInt32(); StartPositions.Pop(); return(new RotatorLiteral(pitch, yaw, roll)); }
public Expression /*ObjectLiteral*/ DecompileObjectConst() // TODO: properly { PopByte(); var value = ReadObject(); StartPositions.Pop(); //return new ObjectLiteral(value, null, null); return(new SymbolReference(null, null, null, value.ClassName + "'" + value.ObjectName + "'")); }
public VectorLiteral DecompileVectorConst() { PopByte(); var x = ReadFloat(); var y = ReadFloat(); var z = ReadFloat(); StartPositions.Pop(); return(new VectorLiteral(x, y, z)); }
public Expression DecompileDelegateProperty() // TODO: is this proper? Is it even used in ME3? { PopByte(); var name = PCC.GetName(ReadNameRef()); var obj = ReadObject(); // probably the delegate StartPositions.Pop(); var objName = obj != null ? obj.ObjectName : "None"; return(new SymbolReference(null, null, null, name + "(" + objName + ")")); }
public Expression DecompileDefaultReference() { var obj = ReadObject(); if (obj == null) { return(null); // ERROR } StartPositions.Pop(); return(new DefaultReference(null, obj.ObjectName.Instanced)); }
public Expression DecompileObjectLookup() { var obj = ReadObject(); if (obj == null) { return(null); // ERROR } StartPositions.Pop(); return(new SymbolReference(null, null, null, obj.ObjectName)); }
public IntegerLiteral DecompileByteConst(string numType) { PopByte(); var value = ReadByte(); StartPositions.Pop(); return(new IntegerLiteral(value) { NumType = numType }); }
public Expression /*RotationLiteral*/ DecompileRotationConst() // TODO: properly { PopByte(); var Pitch = ReadInt32(); var Yaw = ReadInt32(); var Roll = ReadInt32(); StartPositions.Pop(); var str = "rot(0x" + Pitch.ToString("X8") + ", 0x" + Yaw.ToString("X8") + ", 0x" + Roll.ToString("X8") + ")"; return(new SymbolReference(null, null, null, str)); }