コード例 #1
0
        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);
        }
コード例 #2
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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public static LuaDecompiler.DecompiledOPCode CallFunctionWithoutParameters(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     if (opCode.C > 1)
     {
         string returnRegisters = opCode.A.ToString();
         int    oldStartCount   = function.returnValCount;
         string returnStrings   = function.getNewReturnVal();
         if (opCode.C > 2)
         {
             for (int j = opCode.A + 1; j < opCode.A + opCode.C - 1; j++)
             {
                 returnRegisters += ", " + j.ToString();
                 string returnVal = function.getNewReturnVal();
                 returnStrings += ", " + returnVal;
                 //function.Registers[j] = returnVal;
             }
         }
         LuaDecompiler.DecompiledOPCode str = new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, String.Format("local {0} = {1}()",
                                                                                                                                returnStrings,
                                                                                                                                function.Registers[opCode.A]));
         function.returnValCount      = oldStartCount;
         function.Registers[opCode.A] = function.getNewReturnVal();
         if (opCode.C > 2)
         {
             for (int j = opCode.A + 1; j < opCode.A + opCode.C - 1; j++)
             {
                 function.Registers[j] = function.getNewReturnVal();
             }
         }
         return(str);
     }
     else
     {
         if (function.OPCodes[index + 1].OPCode == 0x2 || function.OPCodes[index + 1].OPCode == 0x4C || function.OPCodes[index + 1].OPCode == 0x16)
         {
             if (function.OPCodes[index + 1].B == 0)
             {
                 function.Registers[opCode.A] = String.Format("{0}()", function.Registers[opCode.A]);
                 return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.empty, ""));
             }
         }
         return(new LuaDecompiler.DecompiledOPCode(LuaDecompiler.opCodeType.String, String.Format("{0}()",
                                                                                                  function.Registers[opCode.A])));
     }
 }
コード例 #5
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);
        }