Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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, "...");
            }
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
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]));
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        public Expression DecompileInstanceDelegate() // TODO: check code, seems ok?
        {
            PopByte();
            var name = ReadNameReference();

            StartPositions.Pop();
            return(new SymbolReference(null, name));
        }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
        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);
        }
Esempio n. 19
0
        public IntegerLiteral DecompileIntConst()
        {
            PopByte();

            var value = ReadInt32();

            StartPositions.Pop();
            return(new IntegerLiteral(value));
        }
Esempio n. 20
0
        public NameLiteral DecompileNameConst()
        {
            PopByte();

            var value = ReadNameReference();

            StartPositions.Pop();
            return(new NameLiteral(value.Instanced));
        }
Esempio n. 21
0
        public StringLiteral DecompileStringConst()
        {
            PopByte();

            var value = ReadNullTerminatedString();

            StartPositions.Pop();
            return(new StringLiteral(value));
        }
Esempio n. 22
0
        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)));
        }
Esempio n. 23
0
        public FloatLiteral DecompileFloatConst()
        {
            PopByte();

            var value = ReadFloat();

            StartPositions.Pop();
            return(new FloatLiteral(value));
        }
Esempio n. 24
0
        public StringRefLiteral DecompileStringRefConst()
        {
            PopByte();

            var value = ReadInt32();

            StartPositions.Pop();
            return(new StringRefLiteral(value));
        }
Esempio n. 25
0
        public NameLiteral DecompileNameConst()
        {
            PopByte();

            var value = PCC.GetName(ReadNameRef());

            StartPositions.Pop();
            return(new NameLiteral(value, null, null));
        }
Esempio n. 26
0
        public IntegerLiteral DecompileByteConst()
        {
            PopByte();

            var value = ReadByte();

            StartPositions.Pop();
            return(new IntegerLiteral(value, null, null));
        }
Esempio n. 27
0
        public RotatorLiteral DecompileRotationConst()
        {
            PopByte();
            var pitch = ReadInt32();
            var yaw   = ReadInt32();
            var roll  = ReadInt32();

            StartPositions.Pop();
            return(new RotatorLiteral(pitch, yaw, roll));
        }
Esempio n. 28
0
        public VectorLiteral DecompileVectorConst()
        {
            PopByte();
            var x = ReadFloat();
            var y = ReadFloat();
            var z = ReadFloat();

            StartPositions.Pop();
            return(new VectorLiteral(x, y, z));
        }
Esempio n. 29
0
        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 + "'"));
        }
Esempio n. 30
0
        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);
        }