public static void NilToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     for (int i = opCode.A; i <= (opCode.B); i++)
     {
         function.Registers[i] = "nil";
     }
 }
 public static void BooleanToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     if (index > 2)
     {
         if (LuaConditions.isConditioOpCode(function.OPCodes[index - 2].OPCode))
         {
             if (function.OPCodes[index].C == 1)
             {
                 return;
             }
         }
         else if (LuaConditions.isConditioOpCode(function.OPCodes[index - 3].OPCode))
         {
             if (function.OPCodes[index - 1].C == 1)
             {
                 return;
             }
         }
     }
     if (opCode.B == 0)
     {
         function.Registers[opCode.A] = "false";
     }
     else
     {
         function.Registers[opCode.A] = "true";
     }
 }
Esempio n. 3
0
 public static void Closure(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index, int functionLevel, LuaDecompiler luaDecomp)
 {
     function.Registers[opCode.A] = String.Format("__FUNC_{0:X}_", function.subFunctions[opCode.Bx].beginPosition);
     function.doingUpvals         = opCode.A;
     function.lastFunctionClosure = opCode.Bx;
     if (function.OPCodes[index + 1].OPCode != 0x54 && function.getName() != "__INIT__")
     {
         luaDecomp.doFunctionClosure(function, functionLevel);
     }
 }
 public static void GetIndex(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     if (opCode.C > 255)
     {
         function.Registers[opCode.A] = function.Registers[opCode.B] + "[" + function.Strings[opCode.C - 256].String + "]";
     }
     else
     {
         function.Registers[opCode.A] = function.Registers[opCode.B] + "[" + function.Registers[opCode.C] + "]";
     }
 }
Esempio n. 5
0
 public static void ConnectWithColon(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     if (opCode.C > 255)
     {
         function.Registers[opCode.A] = function.Registers[opCode.B] + ":" + function.Strings[opCode.C - 256].String;
     }
     else
     {
         function.Registers[opCode.A] = function.Registers[opCode.B] + ":" + function.Registers[opCode.C];
     }
 }
Esempio n. 6
0
        public static void ConnectWithDoubleDot(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
        {
            string output = "(" + function.Registers[opCode.B];

            for (int i = opCode.B + 1; i <= opCode.C; i++)
            {
                output += " .. " + function.Registers[i];
            }
            output += ")";
            function.Registers[opCode.A] = output;
        }
Esempio n. 7
0
        public static LuaDecompiler.DecompiledOPCode IfIsTrueFalse(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
        {
            try
            {
                if (orString.Length < 1)
                {
                    orString       = "";
                    codeBlockStart = -1;
                }
            }
            catch
            {
                codeBlockStart = -1;
            }
            string neworstring = orString;

            orString = "";
            return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.skipLines, String.Format("if {2}{0}{1} then",
                                                                                                        (opCode.C == 1) ? "not " : "",
                                                                                                        function.Registers[opCode.A], neworstring), getSkipLines(function, index + 1)));
        }
 public static LuaDecompiler.DecompiledOPCode Power(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(DoOperator(function, opCode, "^"));
 }
 public static void UnaryMinus(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "-" + function.Registers[opCode.B];
 }
Esempio n. 10
0
 public static LuaDecompiler.DecompiledOPCode LessOrEqualThanBackwards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     return(doConditionBackward(function, index, "<=", ">"));
 }
Esempio n. 11
0
 public static void ConnectWithDot(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = function.Registers[opCode.B] + "." + function.Strings[opCode.C].String;
 }
 public static LuaDecompiler.DecompiledOPCode NotR1(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, "-- Unhandled OP: (OPCODE_NOT_R1)"));
 }
Esempio n. 13
0
 public static LuaDecompiler.DecompiledOPCode IfIsEqualBackwards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     return(doConditionBackward(function, index, "==", "~="));
 }
 public static void Close(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "";
 }
 public static void VarArg(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "...";
 }
 public static LuaDecompiler.DecompiledOPCode TestSet(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, "-- Unhandled OP: (OPCODE_TESTSET)"));
 }
 public static LuaDecompiler.DecompiledOPCode BinaryOr(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, "-- Unhandled OP: (OPCODE_BIT_OR)"));
 }
 public static LuaDecompiler.DecompiledOPCode ShiftLeftBackwards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, "-- Unhandled OP: (OPCODE_LEFT_SHIFT_BK)"));
 }
Esempio n. 19
0
 public static LuaDecompiler.DecompiledOPCode SkipLines(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     if (index + getSkipLines(function, index) < function.OPCodes.Count)
     {
         if (function.OPCodes[index + getSkipLines(function, index) + 1].OPCode == 0xE)
         {
             int startPos = index + getSkipLines(function, index) + 2 + getSkipLines(function, index + getSkipLines(function, index) + 2);
             if (index == startPos)
             {
                 int baseVal = function.OPCodes[index + opCode.C + 2].A + 3;
                 function.Registers[baseVal]     = "index" + ((function.forLoopCount > 0) ? function.forLoopCount.ToString() : "");
                 function.Registers[baseVal + 1] = "value" + ((function.forLoopCount > 0) ? function.forLoopCount.ToString() : "");
                 function.forLoopCount++;
                 return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.forEach, String.Format("for {0},{1} in {2}, {3}, {4} do",
                                                                                                           function.Registers[baseVal], function.Registers[baseVal + 1], function.Registers[baseVal - 3], function.Registers[baseVal - 2]
                                                                                                           , function.Registers[baseVal - 1]), getSkipLines(function, index)));
             }
         }
     }
     if (index + getSkipLines(function, index) < function.OPCodes.Count)
     {
         if (function.OPCodes[index + getSkipLines(function, index)].OPCode == 0x1C)
         {
             if (isConditioOpCode(function.OPCodes[index - 1].OPCode) && !isConditioOpCode(function.OPCodes[index + getSkipLines(function, index) - 1].OPCode))
             {
                 return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.Else, "", getSkipLines(function, index), getSkipLines(function, index + getSkipLines(function, index))));
             }
         }
     }
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.empty, ""));
 }
 public static LuaDecompiler.DecompiledOPCode SetupVal(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, "-- Unhandled OP: (OPCODE_SETUPVAL)"));
 }
Esempio n. 21
0
        public static LuaDecompiler.DecompiledOPCode Not(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
        {
            string returnVal = function.getNewReturnVal();

            LuaDecompiler.DecompiledOPCode str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, String.Format("local {0} = not {1}",
                                                                                                                                   returnVal,
                                                                                                                                   function.Registers[opCode.B]));
            function.Registers[opCode.A] = returnVal;
            return(str);
        }
 public static void Length(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "#" + function.Registers[opCode.B];
 }
Esempio n. 23
0
 public static LuaDecompiler.DecompiledOPCode LessThan(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     return(doCondition(function, index, "<", ">="));
 }
        public static LuaDecompiler.DecompiledOPCode DoOperator(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, string Operator)
        {
            LuaDecompiler.DecompiledOPCode str;
            string returnVal = function.getNewReturnVal();

            if (opCode.C > 255)
            {
                str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, String.Format("local {0} = {1} {2} {3}",
                                                                                                        returnVal,
                                                                                                        function.Strings[opCode.C - 256].String,
                                                                                                        Operator,
                                                                                                        function.Registers[opCode.B]));
            }
            else
            {
                str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, String.Format("local {0} = {1} {2} {3}",
                                                                                                        returnVal,
                                                                                                        function.Registers[opCode.C],
                                                                                                        Operator,
                                                                                                        function.Registers[opCode.B]));
            }

            function.Registers[opCode.A] = returnVal;
            return(str);
        }
Esempio n. 25
0
        private static LuaDecompiler.DecompiledOPCode doCondition(LuaFile.LuaFunction function, int index, string Oper, string OperFalse)
        {
            LuaFile.LuaOPCode opCode = function.OPCodes[index];
            try
            {
                if (orString.Length < 1)
                {
                    orString       = "";
                    codeBlockStart = -1;
                }
            }
            catch
            {
                orString       = "";
                codeBlockStart = -1;
            }
            bool conditionToReg = false;

            if (function.OPCodes.Count > index + 3)
            {
                if (function.OPCodes[index + 2].OPCode == 0xD && function.OPCodes[index + 3].OPCode == 0xD)
                {
                    conditionToReg = true;
                }
            }

            /*Console.WriteLine("now: " + index);
             * Console.WriteLine("next: " + (function.OPCodes[index + getSkipLines(function, index + 1) + 1].OPCode));*/
            //Console.WriteLine("next: " + isConditioOpCode(function.OPCodes[index + getSkipLines(function, index + 1)].OPCode));
            if (isConditioOpCode(function.OPCodes[index + getSkipLines(function, index + 1)].OPCode))
            {
                if (orString.Length < 1)
                {
                    orString = "";
                }
                string cond = "or";

                /*if (index + getSkipLines(function, index + 1) < codeBlockStart)
                 * {
                 *  cond = "and";
                 *  opCode.A = (byte)(1 - opCode.A);
                 * }
                 * else
                 *  cond = "or";*/
                string old = Oper;
                Oper      = OperFalse;
                OperFalse = old;
                if (opCode.C > 255)
                {
                    orString += String.Format("{0} {2} {1} {3} ", function.Registers[opCode.B], function.Strings[opCode.C - 256].getString(), (opCode.A == 0) ? Oper : OperFalse, cond);
                }
                else
                {
                    orString += String.Format("{0} {2} {1} {3} ", function.Registers[opCode.B], function.Registers[opCode.C], (opCode.A == 0) ? Oper : OperFalse, cond);
                }

                if (codeBlockStart == -1)
                {
                    codeBlockStart = index + getSkipLines(function, index + 1);
                }
                return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.orCondition, orString));
            }
            LuaDecompiler.DecompiledOPCode str;
            int elseLines = 0;

            if (function.OPCodes[index + getSkipLines(function, index + 1) + 1].OPCode == 0x1C)
            {
                if (!isConditioOpCode(function.OPCodes[index + getSkipLines(function, index + 1) - 2].OPCode))
                {
                    elseLines = getSkipLines(function, index + getSkipLines(function, index + 1) + 1);
                }
            }
            if (opCode.C > 255)
            {
                if (conditionToReg)
                {
                    string returnVal = function.getNewReturnVal();
                    str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.conditionToReg, String.Format("local {4} = ({3}{0} {2} {1})",
                                                                                                                    function.Registers[opCode.B],
                                                                                                                    function.Strings[opCode.C - 256].getString(),
                                                                                                                    (opCode.A == 0) ? Oper : OperFalse, orString, returnVal));
                    function.Registers[function.OPCodes[index + 2].A] = returnVal;
                }
                else
                {
                    str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.skipLines, String.Format("if {3}{0} {2} {1} then",
                                                                                                               function.Registers[opCode.B],
                                                                                                               function.Strings[opCode.C - 256].getString(),
                                                                                                               (opCode.A == 0) ? Oper : OperFalse, orString), getSkipLines(function, index + 1), elseLines);
                }
            }
            else
            {
                if (conditionToReg)
                {
                    string returnVal = function.getNewReturnVal();
                    str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.conditionToReg, String.Format("local {4} = ({3}{0} {2} {1})",
                                                                                                                    function.Registers[opCode.B],
                                                                                                                    function.Registers[opCode.C],
                                                                                                                    (opCode.A == 0) ? Oper : OperFalse, orString, returnVal));
                    function.Registers[function.OPCodes[index + 2].A] = returnVal;
                }
                else
                {
                    str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.skipLines, String.Format("if {3}{0} {2} {1} then",
                                                                                                               function.Registers[opCode.B],
                                                                                                               function.Registers[opCode.C],
                                                                                                               (opCode.A == 0) ? Oper : OperFalse, orString), getSkipLines(function, index + 1), elseLines);
                }
            }
            if (orString.Length > 0)
            {
                orString = "";
            }
            codeBlockStart = -1;
            return(str);
        }
 public static LuaDecompiler.DecompiledOPCode Multiply(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(DoOperator(function, opCode, "*"));
 }
Esempio n. 27
0
 public static LuaDecompiler.DecompiledOPCode SetField(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index, bool isString = false)
 {
     if (opCode.C > 255)
     {
         return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, (String.Format("{0}.{1} = {2}",
                                                                                                   function.Registers[opCode.A],
                                                                                                   function.Strings[opCode.B].String,
                                                                                                   function.Strings[opCode.C - 256].getString()))));
     }
     else
     {
         if (function.Registers[opCode.C].Contains("__FUNC") &&
             (function.OPCodes[index - 1].OPCode == 0x4A || function.OPCodes[index - 1].OPCode == 0x54) &&
             (function.Registers[opCode.A].Substring(0, 3) == "CoD" || function.Registers[opCode.A].Substring(0, 3) == "LUI"))
         {
             for (int i = index; i > 0; i--)
             {
                 if (function.OPCodes[i].OPCode == 0x4A)
                 {
                     function.subFunctions[function.OPCodes[i].Bx].functionName = function.Registers[opCode.A] + "." + function.Strings[opCode.B].String;
                     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.empty, ""));
                 }
             }
         }
         else
         {
             return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, (String.Format("{0}.{1} = {2}",
                                                                                                       function.Registers[opCode.A],
                                                                                                       function.Strings[opCode.B].String,
                                                                                                       function.Registers[opCode.C]))));
         }
     }
     return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, "idk"));
 }
 public static LuaDecompiler.DecompiledOPCode ModuloBackWards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(DoOperatorBackWards(function, opCode, "%"));
 }
 public static LuaDecompiler.DecompiledOPCode Subtract(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     return(DoOperator(function, opCode, "-"));
 }
        public static LuaDecompiler.DecompiledOPCode DoOperatorBackWards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, string Operator)
        {
            string returnVal = function.getNewReturnVal();

            LuaDecompiler.DecompiledOPCode str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, String.Format("local {0} = {1} {2} {3}",
                                                                                                                                   returnVal,
                                                                                                                                   function.Strings[opCode.B].String,
                                                                                                                                   Operator,
                                                                                                                                   function.Registers[opCode.C]));
            function.Registers[opCode.A] = returnVal;
            return(str);
        }