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 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 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)); }
private void CutText() { int lesserHighlightIndex = StartPositions.Min(); int greaterHighlightIndex = EndPositions.Max(); int startCutIndex = lesserHighlightIndex - _cutOffset < 0 ? 0 : lesserHighlightIndex - _cutOffset; int cutLenght = greaterHighlightIndex - lesserHighlightIndex + startCutIndex + _cutOffset * 2 > Text.Length ? Text.Length - startCutIndex : greaterHighlightIndex - lesserHighlightIndex + _cutOffset * 2; Text = Text.Substring(startCutIndex, cutLenght); if (startCutIndex != 0) { Text = Text.Insert(0, "..."); startCutIndex -= 3; } for (int i = 0; i < StartPositions.Count; i++) { StartPositions[i] -= startCutIndex; EndPositions[i] -= startCutIndex; } if (cutLenght == greaterHighlightIndex - lesserHighlightIndex + _cutOffset * 2) { Text = Text.Insert(Text.Length, "..."); } }
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 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)); }
protected override void CalculateItemsSize() { StartPositions.Clear(); if (Canvas.Children.Count == 0) { _ActiveListHeight = 0; _ActiveListWidth = 0; return; } StartPositions.Add(0); UIElementBase element = Canvas.Children[0]; int max = element.Bottom; for (int i = 1; i < Canvas.Children.Count; i++) { element = Canvas.Children[i]; max = Math.Max(max, element.Bottom); } int v = max + BottomPadding; StartPositions.Add(v); _ActiveListHeight = v; }
private void SetStartPositions(List <NativeItemData> nid) { int c = 0; StartPositions.Clear(); if (ItemCount == 0) { _ActiveListHeight = 0; _ActiveListWidth = 0; return; } for (int i = 0; i < ItemCount; i++) { StartPositions.Add(c); if (ShowGroupHeader) { //if (IsItemNewGroup(nItem) && item.Group != null && rItem.Top >= rListRect.Top) if (IsItemNewGroup(i) && nid[i].Group != null) { c += Settings.GroupPixHeight; } } c += Settings.ListItemPixSize; } StartPositions.Add(c); //The end of tha last item _ActiveListHeight = c; ScrollTo(0); }
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 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 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 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 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 = ReadNameReference(); StartPositions.Pop(); return(new SymbolReference(null, 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 = PCC.GetName(ReadNameRef()); StartPositions.Pop(); return(new SymbolReference(null, null, null, "UNSUPPORTED: InstanceDelegate: " + name)); }
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)); }
private void SetStartPositions(List <NativeItemData> nid) { int c = 0; StartPositions.Clear(); if (ItemCount == 0) { _ActiveListHeight = 0; _ActiveListWidth = 0; return; } var hdcMem = OffScreenGraphics.GetHdc(); try { using (Gdi g = Gdi.FromHdc(hdcMem, Rectangle.Empty)) { g.Font = Settings.SecondaryTextFontGdi; g.TextAlign = Win32.TextAlign.TA_LEFT; for (int i = 0; i < ItemCount; i++) { StartPositions.Add(c); //nid[i].SecondaryTextLines = TextFormatHelper.CutTextToLines(nid[i].SecondaryText, Width - UISettings.CalcPix(40), 0, g); nid[i].SecondaryTextLines = TextFormatHelper.CutTextToLines(nid[i].SecondaryText, Width - UISettings.CalcPix(29), Settings.SecondaryTextLinesCount, g); //SecondaryTextLinesCount c += (Settings.ListItemPixSize + (nid[i].SecondaryTextLines.Count + 1) * UISettings.CalcPix(11)); if (ShowGroupHeader) { //if (IsItemNewGroup(nItem) && item.Group != null && rItem.Top >= rListRect.Top) if (IsItemNewGroup(i) && nid[i].Group != null) { c += Settings.GroupPixHeight; } } //c += Settings.ListItemPixSize; } } } finally { OffScreenGraphics.ReleaseHdc(hdcMem); } StartPositions.Add(c); //The end of tha last item _ActiveListHeight = c; ScrollTo(0); }
public IntegerLiteral DecompileIntConst() { PopByte(); var value = ReadInt32(); StartPositions.Pop(); return(new IntegerLiteral(value)); }
public NameLiteral DecompileNameConst() { PopByte(); var value = ReadNameReference(); StartPositions.Pop(); return(new NameLiteral(value.Instanced)); }
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 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 IntegerLiteral DecompileByteConst() { PopByte(); var value = ReadByte(); StartPositions.Pop(); return(new IntegerLiteral(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 VectorLiteral DecompileVectorConst() { PopByte(); var x = ReadFloat(); var y = ReadFloat(); var z = ReadFloat(); StartPositions.Pop(); return(new VectorLiteral(x, y, z)); }
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 L1Maze(string[] input) { var fields = input.SelectMany((line, y) => line.Select((c, x) => (p: (x, y), c))).ToArray(); Corridors = new HashSet <(int, int)>(fields.Where(f => f.c != '#').Select(f => f.p)); Keys = fields.Where(f => char.IsLower(f.c)).ToDictionary(f => f.p, f => BitForKey(char.ToUpper(f.c))); Doors = fields.Where(f => char.IsUpper(f.c)).ToDictionary(f => f.p, f => BitForKey(f.c)); StartPositions = fields.Where(f => f.c == '@').Select(f => f.p).ToArray(); StartPosition = StartPositions.First(); AllKeys = Keys.Values.Aggregate(0u, (a, k) => a | k); }