public int GetSwitchOffset(int index)
        {
            if (Instruction != Instruction.RAGE_SWITCH)
            {
                throw new Exception("Not A Switch Statement");
            }

            int cases;

            if (Program.RdrOpcodes)
            {
                if ((cases = BitConverter.ToUInt16(_operands, 0)) <= index)
                {
                    throw new Exception("Out of range script case");
                }
                var length = BitConverter.ToInt16(_operands, 6 + index * 6);
                return(Offset + 8 + 1 + index * 6 + (Program.SwapEndian ? Utils.SwapEndian(length) : length));
            }
            else
            {
                if ((cases = GetOperand(0)) <= index)
                {
                    throw new Exception("Out Or Range Script Case");
                }
                var length = BitConverter.ToInt16(_operands, 5 + index * 6);
                return(Offset + 8 + index * 6 + (Program.SwapEndian ? Utils.SwapEndian(length) : length));
            }
        }
Пример #2
0
        public void SWritePointer(int pointer)
        {
            if (pointer == 0)
            {
                Write(0);
                return;
            }

            Write(Utils.SwapEndian((pointer & 0xFFFFFF) | 0x50000000));
        }
        /*public int GetSwitchCase(int index)
         *      {
         *              if (instruction == Instruction.Switch)
         *              {
         *                      int cases = GetOperand(0);
         *                      if (index >= cases)
         *                              throw new Exception("Out Or Range Script Case");
         *                      return Utils.SwapEndian(BitConverter.ToInt32(operands, 1 + index * 6));
         *              }
         *              throw new Exception("Not A Switch Statement");
         *      }*/

        public string GetSwitchStringCase(int index)
        {
            if (Instruction != Instruction.RAGE_SWITCH)
            {
                throw new Exception("Not A Switch Statement");
            }

            int cases;

            if (Program.RdrOpcodes)
            {
                if ((cases = BitConverter.ToUInt16(_operands, 0)) <= index)
                {
                    throw new Exception("Out Or Range Script Case");
                }

                if (Program.IntStyle == Program.IntType.Uint)
                {
                    var hash = BitConverter.ToUInt32(_operands, 2 + index * 6);
                    return(Program.Hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
                }
                else
                {
                    var hash = BitConverter.ToInt32(_operands, 2 + index * 6);
                    return(Program.Hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
                }
            }

            if ((cases = GetOperand(0)) <= index)
            {
                throw new Exception("Out Or Range Script Case");
            }

            if (Program.IntStyle == Program.IntType.Uint)
            {
                var hash = BitConverter.ToUInt32(_operands, 1 + index * 6);
                return(Program.Hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
            }
            else
            {
                var hash = BitConverter.ToInt32(_operands, 1 + index * 6);
                return(Program.Hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
            }
        }
Пример #4
0
        private void GetFunctions()
        {
            var returnPos = -3;

            while (_offset < _codeTable.Count)
            {
                switch (CodeSet.Map(_codeTable[_offset]))
                {
                case Instruction.RAGE_PUSH_CONST_U8:
                    Advpos(1);
                    break;

                case Instruction.RAGE_PUSH_CONST_U8_U8:
                    Advpos(2);
                    break;

                case Instruction.RAGE_PUSH_CONST_U8_U8_U8:
                    Advpos(3);
                    break;

                case Instruction.RAGE_PUSH_CONST_U32:
                case Instruction.RAGE_PUSH_CONST_F:
                    Advpos(4);
                    break;

                case Instruction.RAGE_NATIVE:
                    Advpos(3);
                    break;

                case Instruction.RAGE_ENTER:
                    AddFunction(_offset, returnPos + 3);
                    ;
                    Advpos(_codeTable[_offset + 4] + 4);
                    break;

                case Instruction.RAGE_LEAVE:
                    returnPos = _offset;
                    Advpos(2);
                    break;

                case Instruction.RAGE_ARRAY_U8:
                case Instruction.RAGE_ARRAY_U8_LOAD:
                case Instruction.RAGE_ARRAY_U8_STORE:
                case Instruction.RAGE_LOCAL_U8:
                case Instruction.RAGE_LOCAL_U8_LOAD:
                case Instruction.RAGE_LOCAL_U8_STORE:
                case Instruction.RAGE_STATIC_U8:
                case Instruction.RAGE_STATIC_U8_LOAD:
                case Instruction.RAGE_STATIC_U8_STORE:
                case Instruction.RAGE_IADD_U8:
                case Instruction.RAGE_IMUL_U8:
                case Instruction.RAGE_IOFFSET_U8:
                case Instruction.RAGE_IOFFSET_U8_LOAD:
                case Instruction.RAGE_IOFFSET_U8_STORE:
                    Advpos(1);
                    break;

                case Instruction.RAGE_PUSH_CONST_S16:
                case Instruction.RAGE_IADD_S16:
                case Instruction.RAGE_IMUL_S16:
                case Instruction.RAGE_IOFFSET_S16:
                case Instruction.RAGE_IOFFSET_S16_LOAD:
                case Instruction.RAGE_IOFFSET_S16_STORE:
                case Instruction.RAGE_ARRAY_U16:
                case Instruction.RAGE_ARRAY_U16_LOAD:
                case Instruction.RAGE_ARRAY_U16_STORE:
                case Instruction.RAGE_LOCAL_U16:
                case Instruction.RAGE_LOCAL_U16_LOAD:
                case Instruction.RAGE_LOCAL_U16_STORE:
                case Instruction.RAGE_STATIC_U16:
                case Instruction.RAGE_STATIC_U16_LOAD:
                case Instruction.RAGE_STATIC_U16_STORE:
                case Instruction.RAGE_GLOBAL_U16:
                case Instruction.RAGE_GLOBAL_U16_LOAD:
                case Instruction.RAGE_GLOBAL_U16_STORE:
                case Instruction.RAGE_J:
                case Instruction.RAGE_JZ:
                case Instruction.RAGE_IEQ_JZ:
                case Instruction.RAGE_INE_JZ:
                case Instruction.RAGE_IGT_JZ:
                case Instruction.RAGE_IGE_JZ:
                case Instruction.RAGE_ILT_JZ:
                case Instruction.RAGE_ILE_JZ:
                    Advpos(2);
                    break;

                case Instruction.RAGE_CALL:
                case Instruction.RAGE_GLOBAL_U24:
                case Instruction.RAGE_GLOBAL_U24_LOAD:
                case Instruction.RAGE_GLOBAL_U24_STORE:
                case Instruction.RAGE_PUSH_CONST_U24:
                    Advpos(3);
                    break;

                case Instruction.RAGE_SWITCH:
                {
                    if (Program.RdrOpcodes)
                    {
                        var length = (_codeTable[_offset + 2] << 8) | _codeTable[_offset + 1];
                        Advpos(2 + 6 * (Program.SwapEndian ? Utils.SwapEndian(length) : length));
                    }
                    else
                    {
                        Advpos(1 + 6 * _codeTable[_offset + 1]);
                    }

                    break;
                }

                case Instruction.RAGE_TEXT_LABEL_ASSIGN_STRING:
                case Instruction.RAGE_TEXT_LABEL_ASSIGN_INT:
                case Instruction.RAGE_TEXT_LABEL_APPEND_STRING:
                case Instruction.RAGE_TEXT_LABEL_APPEND_INT:
                    Advpos(1);
                    break;
                }

                Advpos(1);
            }

            _offset = 0;
            GetFunctionCode();
        }
Пример #5
0
        private void AddFunction(int start1, int start2)
        {
            var namelen = _codeTable[start1 + 4];
            var name    = "";

            if (namelen > 0)
            {
                for (var i = 0; i < namelen; i++)
                {
                    name += (char)_codeTable[start1 + 5 + i];
                }
            }
            else if (start1 == 0)
            {
                name = "__EntryFunction__";
            }
            else
            {
                name = "func_" + Functions.Count;
            }
            int pcount = _codeTable[_offset + 1];
            int tmp1 = _codeTable[_offset + 2], tmp2 = _codeTable[_offset + 3];
            var vcount = Program.SwapEndian ? (tmp1 << 0x8) | tmp2 : (tmp2 << 0x8) | tmp1;

            if (vcount < 0)
            {
                throw new Exception("Well this shouldnt have happened");
            }
            var temp = start1 + 5 + namelen;

            while (CodeSet.Map(_codeTable[temp]) != Instruction.RAGE_LEAVE)
            {
                switch (CodeSet.Map(_codeTable[temp]))
                {
                case Instruction.RAGE_PUSH_CONST_U8:
                    temp += 1;
                    break;

                case Instruction.RAGE_PUSH_CONST_U8_U8:
                    temp += 2;
                    break;

                case Instruction.RAGE_PUSH_CONST_U8_U8_U8:
                    temp += 3;
                    break;

                case Instruction.RAGE_PUSH_CONST_U32:
                case Instruction.RAGE_PUSH_CONST_F:
                    temp += 4;
                    break;

                case Instruction.RAGE_NATIVE:
                    temp += 3;
                    break;

                case Instruction.RAGE_ENTER: throw new Exception("Return Expected");

                case Instruction.RAGE_LEAVE: throw new Exception("Return Expected");

                case Instruction.RAGE_ARRAY_U8:
                case Instruction.RAGE_ARRAY_U8_LOAD:
                case Instruction.RAGE_ARRAY_U8_STORE:
                case Instruction.RAGE_LOCAL_U8:
                case Instruction.RAGE_LOCAL_U8_LOAD:
                case Instruction.RAGE_LOCAL_U8_STORE:
                case Instruction.RAGE_STATIC_U8:
                case Instruction.RAGE_STATIC_U8_LOAD:
                case Instruction.RAGE_STATIC_U8_STORE:
                case Instruction.RAGE_IADD_U8:
                case Instruction.RAGE_IMUL_U8:
                case Instruction.RAGE_IOFFSET_U8:
                case Instruction.RAGE_IOFFSET_U8_LOAD:
                case Instruction.RAGE_IOFFSET_U8_STORE:
                    temp += 1;
                    break;

                case Instruction.RAGE_PUSH_CONST_S16:
                case Instruction.RAGE_IADD_S16:
                case Instruction.RAGE_IMUL_S16:
                case Instruction.RAGE_IOFFSET_S16:
                case Instruction.RAGE_IOFFSET_S16_LOAD:
                case Instruction.RAGE_IOFFSET_S16_STORE:
                case Instruction.RAGE_ARRAY_U16:
                case Instruction.RAGE_ARRAY_U16_LOAD:
                case Instruction.RAGE_ARRAY_U16_STORE:
                case Instruction.RAGE_LOCAL_U16:
                case Instruction.RAGE_LOCAL_U16_LOAD:
                case Instruction.RAGE_LOCAL_U16_STORE:
                case Instruction.RAGE_STATIC_U16:
                case Instruction.RAGE_STATIC_U16_LOAD:
                case Instruction.RAGE_STATIC_U16_STORE:
                case Instruction.RAGE_GLOBAL_U16:
                case Instruction.RAGE_GLOBAL_U16_LOAD:
                case Instruction.RAGE_GLOBAL_U16_STORE:
                case Instruction.RAGE_J:
                case Instruction.RAGE_JZ:
                case Instruction.RAGE_IEQ_JZ:
                case Instruction.RAGE_INE_JZ:
                case Instruction.RAGE_IGT_JZ:
                case Instruction.RAGE_IGE_JZ:
                case Instruction.RAGE_ILT_JZ:
                case Instruction.RAGE_ILE_JZ:
                    temp += 2;
                    break;

                case Instruction.RAGE_CALL:
                case Instruction.RAGE_GLOBAL_U24:
                case Instruction.RAGE_GLOBAL_U24_LOAD:
                case Instruction.RAGE_GLOBAL_U24_STORE:
                case Instruction.RAGE_PUSH_CONST_U24:
                    temp += 3;
                    break;

                case Instruction.RAGE_SWITCH:
                {
                    if (Program.RdrOpcodes)
                    {
                        var length = (_codeTable[temp + 2] << 8) | _codeTable[temp + 1];
                        temp += 2 + 6 * (Program.SwapEndian ? Utils.SwapEndian(length) : length);
                    }
                    else
                    {
                        temp += 1 + 6 * _codeTable[temp + 1];
                    }

                    break;
                }

                case Instruction.RAGE_TEXT_LABEL_ASSIGN_STRING:
                case Instruction.RAGE_TEXT_LABEL_ASSIGN_INT:
                case Instruction.RAGE_TEXT_LABEL_APPEND_STRING:
                case Instruction.RAGE_TEXT_LABEL_APPEND_INT:
                    temp += 1;
                    break;
                }

                temp += 1;
            }

            int rcount   = _codeTable[temp + 2];
            var location = start2;

            if (start1 == start2)
            {
                var baseFunction = new Function(this, name, pcount, vcount, rcount, location);
                Functions.Add(baseFunction);
                if (Program.AggregateFunctions)
                {
                    var aggregateFunction = new Function(this, name, pcount, vcount, rcount, location, -1, true);
                    aggregateFunction.BaseFunction = baseFunction;
                    AggFunctions.Add(aggregateFunction);
                }
            }
            else
            {
                var baseFunction = new Function(this, name, pcount, vcount, rcount, location, start1);
                Functions.Add(baseFunction);
                if (Program.AggregateFunctions)
                {
                    var aggregateFunction = new Function(this, name, pcount, vcount, rcount, location, start1, true);
                    aggregateFunction.BaseFunction = baseFunction;
                    AggFunctions.Add(aggregateFunction);
                }
            }
        }
Пример #6
0
 public short SReadInt16()
 {
     return(Utils.SwapEndian(ReadInt16()));
 }
Пример #7
0
 public long SReadInt64()
 {
     return(Utils.SwapEndian(ReadInt64()));
 }
Пример #8
0
 public int SReadInt32()
 {
     return(Utils.SwapEndian(ReadInt32()));
 }
Пример #9
0
 public void SWrite(long num)
 {
     Write(Utils.SwapEndian(num));
 }
Пример #10
0
 public void SWrite(int num)
 {
     Write(Utils.SwapEndian(num));
 }
Пример #11
0
 public void SWrite(ushort num)
 {
     Write(Utils.SwapEndian(num));
 }