コード例 #1
0
        public static void DoOperator(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, string Operator)
        {
            if (opCode.C > 255)
            {
                function.DisassembleStrings.Add(String.Format("r({0}) = c[{1}] {6} r({2}) // {3} = {4} {6} {5}",
                                                              opCode.A,
                                                              opCode.C - 256,
                                                              opCode.B,
                                                              "returnval" + function.returnValCount,
                                                              function.Strings[opCode.C - 256].String,
                                                              function.Registers[opCode.B],
                                                              Operator));
            }
            else
            {
                function.DisassembleStrings.Add(String.Format("r({0}) = r({1}) {6} r({2}) // {3} = {4} {6} {5}",
                                                              opCode.A,
                                                              opCode.C,
                                                              opCode.B,
                                                              "returnval" + function.returnValCount,
                                                              function.Registers[opCode.C],
                                                              function.Registers[opCode.B],
                                                              Operator));
            }

            function.Registers[opCode.A] = function.getNewReturnVal();
        }
コード例 #2
0
        public static void SkipLines(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
        {
            string suffix = "";

            if (opCode.B == 0)
            {
                if (function.OPCodes[index + opCode.C + 2].OPCode == 0xE && !function.foreachPositions.Contains(index + opCode.C + 2))
                {
                    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++;
                    suffix = " + start of foreach loop";
                    function.foreachPositions.Add(index + opCode.C + 2);
                }
                function.DisassembleStrings.Add(String.Format("skip the next [{0}] opcodes // advance {0} lines{1}",
                                                              opCode.C + 1,
                                                              suffix));
            }
            else
            {
                if (function.OPCodes[index + opCode.sBx + 1].OPCode == 0xE && !function.foreachPositions.Contains(index + opCode.sBx + 1))
                {
                    int baseVal = function.OPCodes[index + opCode.sBx + 1].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++;
                    suffix = " + start of foreach loop";
                    function.foreachPositions.Add(index + opCode.sBx + 1);
                }
                function.DisassembleStrings.Add(String.Format("skip the next [{0}] opcodes // advance {0} lines",
                                                              opCode.sBx));
            }
        }
コード例 #3
0
 public static void Return(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     if (index > 0)
     {
         if (function.OPCodes[index - 1].OPCode == 0x16)
         {
             opCode.B = 1;
         }
     }
     if (opCode.B > 1)
     {
         string registers = opCode.A.ToString();
         string returns   = function.Registers[opCode.A];
         for (int i = opCode.A + 1; i <= opCode.A + opCode.B - 2; i++)
         {
             registers += ", " + i;
             returns   += ", " + function.Registers[i];
         }
         function.DisassembleStrings.Add(String.Format("return r({0}) // {1}", registers, returns));
     }
     else
     {
         function.DisassembleStrings.Add("return");
     }
 }
コード例 #4
0
 public static void VarArg(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "...";
     function.DisassembleStrings.Add(String.Format("r({0}) = VarArg // {1} ",
                                                   opCode.A,
                                                   function.Registers[opCode.A]));
 }
コード例 #5
0
        public static void SetList(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
        {
            string tableString    = "{";
            string tableRegisters = "";

            if (opCode.B > 0)
            {
                tableString    += function.Registers[opCode.A + 1];
                tableRegisters += opCode.A + 1;
                if (opCode.B > 1)
                {
                    for (int j = opCode.A + 2; j <= opCode.A + opCode.B; j++)
                    {
                        tableString    += ", " + function.Registers[j];
                        tableRegisters += ", " + j;
                    }
                }
            }
            tableString += "}";
            function.Registers[opCode.A] = function.Registers[opCode.A];

            function.DisassembleStrings.Add(String.Format("r({0}) = r({1}) // {2} = {3}",
                                                          opCode.A,
                                                          tableRegisters,
                                                          function.Registers[opCode.A],
                                                          tableString));
        }
コード例 #6
0
 public static void Length(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "#" + function.Registers[opCode.B];
     function.DisassembleStrings.Add(String.Format("r({0}) = len(r({1})) // {2}",
                                                   opCode.A,
                                                   opCode.B,
                                                   function.Registers[opCode.B]));
 }
コード例 #7
0
 public static void GetUpValue(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = function.UpvalsStrings[opCode.B];
     function.DisassembleStrings.Add(String.Format("r({0}) = upval({1}) // {2}",
                                                   opCode.A,
                                                   opCode.B,
                                                   function.UpvalsStrings[opCode.B]));
 }
コード例 #8
0
 public static void IfIsTrueFalse(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.DisassembleStrings.Add(String.Format("if r({0}) == {1}, skip next opcode // if {2}{3} then skip next line",
                                                   opCode.A,
                                                   (opCode.C == 1) ? "false" : "true",
                                                   (opCode.C == 1) ? "not " : "",
                                                   function.Registers[opCode.A]));
 }
コード例 #9
0
 /// <summary>
 /// Puts a register value in another register
 /// </summary>
 /// <param name="function"></param>
 /// <param name="opCode"></param>
 public static void RegisterToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = function.Registers[opCode.B];
     function.DisassembleStrings.Add(String.Format("r({0}) = r({1}) // {2}",
                                                   opCode.A,
                                                   opCode.B,
                                                   function.Registers[opCode.A]));
 }
コード例 #10
0
 public static void GlobalRegisterToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = function.Strings[opCode.Bx].String;
     function.DisassembleStrings.Add(String.Format("r({0}) = g[{1}] // {2}",
                                                   opCode.A,
                                                   opCode.Bx,
                                                   function.Strings[opCode.Bx].getString()));
 }
コード例 #11
0
 public static void RegisterToGlobal(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.DisassembleStrings.Add(String.Format("g[c[{0}]] = r({1}) // {2} = {3}",
                                                   opCode.Bx,
                                                   opCode.A,
                                                   function.Strings[opCode.Bx].String,
                                                   function.Registers[opCode.A]));
 }
コード例 #12
0
 public static void LocalConstantToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = function.Strings[opCode.Bx].getString();
     function.DisassembleStrings.Add(String.Format("r({0}) = c[{1}] // {2}",
                                                   opCode.A,
                                                   opCode.Bx,
                                                   function.Registers[opCode.A]));
 }
コード例 #13
0
 public static void StartForEachLoop(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.DisassembleStrings.Add(String.Format("Start a foreach loop with val r({0}), stop: r({1}), inc: r({2}) // use these values: {3} and {4}",
                                                   opCode.A,
                                                   opCode.A + 1,
                                                   opCode.A + 2,
                                                   function.Registers[opCode.A + 3],
                                                   function.Registers[opCode.A + 4]));
 }
コード例 #14
0
 /// <summary>
 /// Connects a register value and a constant value with a .
 /// </summary>
 /// <param name="function"></param>
 /// <param name="opCode"></param>
 public static void ConnectWithDot(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = function.Registers[opCode.B] + "." + function.Strings[opCode.C].String;
     function.DisassembleStrings.Add(String.Format("r({0}) = r({1}).field({2}) // {3}",
                                                   opCode.A,
                                                   opCode.B,
                                                   opCode.C,
                                                   function.Registers[opCode.A]));
 }
コード例 #15
0
 public static void Not(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.DisassembleStrings.Add(String.Format("r({0}) = not r({1}) // {2} = not {3}",
                                                   opCode.A,
                                                   opCode.B,
                                                   "returnval" + function.returnValCount,
                                                   function.Registers[opCode.B]));
     function.Registers[opCode.A] = function.getNewReturnVal();
 }
コード例 #16
0
 public static void EmptyTable(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = "table" + function.tableCount;
     function.tableCount++;
     function.DisassembleStrings.Add(String.Format("r({0}) = {4} // {3} = {4} Index: {2} Hash: {1}",
                                                   opCode.A,
                                                   opCode.C,
                                                   opCode.B,
                                                   function.Registers[opCode.A], "{}"));
 }
コード例 #17
0
 public static void Closure(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A] = String.Format("__FUNC_{0:X}_", function.subFunctions[opCode.Bx].beginPosition);
     function.doingUpvals         = opCode.A;
     function.lastFunctionClosure = opCode.Bx;
     function.DisassembleStrings.Add(String.Format("r({0}) = closure({1}) // {2}",
                                                   opCode.A,
                                                   opCode.Bx,
                                                   function.Registers[opCode.A]));
 }
コード例 #18
0
 public static void StartForLoop(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.Registers[opCode.A + 3] = "index" + ((function.forLoopCount > 0) ? function.forLoopCount.ToString() : "");
     function.forLoopCount++;
     function.DisassembleStrings.Add(String.Format("for {6}=r({0}), {6} < r({1}), r({2}) do // for {6}={3}, {4}, {5} do",
                                                   opCode.A, opCode.A + 1, opCode.A + 2,
                                                   function.Registers[opCode.A],
                                                   function.Registers[opCode.A + 1],
                                                   function.Registers[opCode.A + 2],
                                                   function.Registers[opCode.A + 3]));
 }
コード例 #19
0
 public static void DoOperatorBackWards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, string Operator)
 {
     function.DisassembleStrings.Add(String.Format("r({0}) = c({2}) {6} r({1}) // {3} = {5} {6} {4}",
                                                   opCode.A,
                                                   opCode.C,
                                                   opCode.B,
                                                   "returnval" + function.returnValCount,
                                                   function.Registers[opCode.C],
                                                   function.Strings[opCode.B].String,
                                                   Operator));
     function.Registers[opCode.A] = function.getNewReturnVal();
 }
コード例 #20
0
 public static void EndForLoop(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index)
 {
     if (opCode.B == 0)
     {
         function.DisassembleStrings.Add(String.Format("skip the next [{0}] opcodes // advance {0} lines",
                                                       opCode.C + 1));
     }
     else
     {
         function.DisassembleStrings.Add(String.Format("skip the next [{0}] opcodes // advance {0} lines",
                                                       opCode.sBx));
     }
 }
コード例 #21
0
 public static void NilToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     for (int i = opCode.A; i <= (opCode.B); i++)
     {
         function.Registers[i] = "nil";
     }
     if ((opCode.B) > opCode.A)
     {
         function.DisassembleStrings.Add(String.Format("r({0} to {1}) inclusive = nil", opCode.A, opCode.B));
     }
     else
     {
         function.DisassembleStrings.Add(String.Format("r({0}) = nil", opCode.A));
     }
 }
コード例 #22
0
 public static void BooleanToRegister(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     if (opCode.B == 0)
     {
         function.Registers[opCode.A] = "false";
     }
     else
     {
         function.Registers[opCode.A] = "true";
     }
     function.DisassembleStrings.Add(String.Format("r({0}) = {1}{2}",
                                                   opCode.A,
                                                   function.Registers[opCode.A],
                                                   (opCode.C == 1) ? " // skip next opcode" : ""));
 }
コード例 #23
0
        /// <summary>
        /// Connects 2 register values with a double .
        /// </summary>
        /// <param name="function"></param>
        /// <param name="opCode"></param>
        public static void ConnectWithDoubleDot(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
        {
            string output    = "(" + function.Registers[opCode.B];
            string registers = "r(" + opCode.B + ")";

            for (int i = opCode.B + 1; i <= opCode.C; i++)
            {
                output    += " .. " + function.Registers[i];
                registers += "..r(" + i + ")";
            }
            output += ")";
            function.Registers[opCode.A] = output;
            function.DisassembleStrings.Add(String.Format("r({0}) = {1} // {2}",
                                                          opCode.A,
                                                          registers,
                                                          function.Registers[opCode.A]));
        }
コード例 #24
0
 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 + "]";
         function.DisassembleStrings.Add(String.Format("r({0}) = r({1})[c[{2}]] // {3}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C - 256,
                                                       function.Registers[opCode.A]));
     }
     else
     {
         function.Registers[opCode.A] = function.Registers[opCode.B] + "[" + function.Registers[opCode.C] + "]";
         function.DisassembleStrings.Add(String.Format("r({0}) = r({1})[r({2})] // {3}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C,
                                                       function.Registers[opCode.A]));
     }
 }
コード例 #25
0
 public static void LargerThan(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     if (opCode.C > 255)
     {
         function.DisassembleStrings.Add(String.Format("if {4}r({0}) > c[{1}], skip next opcode // if {4}{2} > {3} then skip next line",
                                                       opCode.B,
                                                       opCode.C - 256,
                                                       function.Registers[opCode.B],
                                                       function.Strings[opCode.C - 256].getString(),
                                                       (opCode.A == 1) ? "not " : ""));
     }
     else
     {
         function.DisassembleStrings.Add(String.Format("if {4}r({0}) > r({1}), skip next opcode // if {4}{2} > {3} then skip next line",
                                                       opCode.B,
                                                       opCode.C,
                                                       function.Registers[opCode.B],
                                                       function.Registers[opCode.C],
                                                       (opCode.A == 0) ? "not " : ""));
     }
 }
コード例 #26
0
 /// <summary>
 /// Connects a register value and a constant value with a :
 /// </summary>
 /// <param name="function"></param>
 /// <param name="opCode"></param>
 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;
         function.DisassembleStrings.Add(String.Format("r({0}) = r({1}):c[{2}] // {3}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C - 256,
                                                       function.Registers[opCode.A]));
     }
     else
     {
         function.Registers[opCode.A] = function.Registers[opCode.B] + ":" + function.Registers[opCode.C];
         function.DisassembleStrings.Add(String.Format("r({0}) = r({1}):r({2}) // {3}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C,
                                                       function.Registers[opCode.A]));
     }
 }
コード例 #27
0
 public static void CallFunctionWithoutParameters(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     if (opCode.C > 1)
     {
         string returnRegisters = opCode.A.ToString();
         string returnStrings   = function.getNewReturnVal();
         if (opCode.C > 2)
         {
             for (int j = opCode.A + 1; j < opCode.A + opCode.C - 1; j++)
             {
                 returnRegisters      += ", " + j.ToString();
                 returnStrings        += ", returnval" + function.returnValCount;
                 function.Registers[j] = function.getNewReturnVal();
             }
         }
         function.DisassembleStrings.Add(String.Format("r({0}) = call r({1}) // {2} = {3}()",
                                                       returnRegisters,
                                                       opCode.A,
                                                       returnStrings,
                                                       function.Registers[opCode.A]));
         for (int j = opCode.A; j < opCode.A + opCode.C - 1; j++)
         {
             function.returnValCount--;
         }
         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();
             }
         }
     }
     else
     {
         function.DisassembleStrings.Add(String.Format("call r({0}) // {1}()",
                                                       opCode.A,
                                                       function.Registers[opCode.A]));
     }
 }
コード例 #28
0
 public static void SetField(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode, int index, bool isString = false)
 {
     if (opCode.C > 255)
     {
         if (function.Strings[opCode.C - 256].StringType == LuaFile.StringType.String)
         {
             isString = true;
         }
         function.DisassembleStrings.Add(String.Format("r({0}).field(c[{1}]) = c[{2}] // {3}.{4} = {5}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C - 256,
                                                       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;
                     break;
                 }
             }
         }
         function.DisassembleStrings.Add(String.Format("r({0}).field(c[{1}]) = r({2}) // {3}.{4} = {5}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C,
                                                       function.Registers[opCode.A],
                                                       function.Strings[opCode.B].String,
                                                       (isString) ? "\"" + function.Registers[opCode.C] + "\"" : function.Registers[opCode.C]));
     }
 }
コード例 #29
0
 public static void SetTableBackwards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     if (opCode.C > 255)
     {
         function.DisassembleStrings.Add(String.Format("r({0})[c[{1}]] = c[{2}] // {3}[{4}] = {5}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C - 256,
                                                       function.Registers[opCode.A],
                                                       function.Strings[opCode.B].getString(),
                                                       function.Strings[opCode.C - 256].getString()));
     }
     else
     {
         function.DisassembleStrings.Add(String.Format("r({0})[c[{1}]] = r({2}) // {3}[{4}] = {5}",
                                                       opCode.A,
                                                       opCode.B,
                                                       opCode.C,
                                                       function.Registers[opCode.A],
                                                       function.Strings[opCode.B].getString(),
                                                       function.Registers[opCode.C]));
     }
 }
コード例 #30
0
 public static void IfIsEqualBackwards(LuaFile.LuaFunction function, LuaFile.LuaOPCode opCode)
 {
     function.DisassembleStrings.Add("; Unhandled OP: (OPCODE_EQ_BK)");
 }