Advertisement
Astekk

Lib.cs

Jan 4th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.17 KB | None | 0 0
  1. public class Lib
  2.     {
  3.         public static void And_Int32(uint address, int input)
  4.         {
  5.             int input2 = Lib.ReadInt32(address) & input;
  6.             Lib.WriteInt32(address, input2);
  7.         }
  8.         public static bool CompareByteArray(byte[] a, byte[] b)
  9.         {
  10.             int num = 0;
  11.             for (int i = 0; i < a.Length; i++)
  12.             {
  13.                 if (a[i] == b[i])
  14.                 {
  15.                     num++;
  16.                 }
  17.             }
  18.             return num == a.Length;
  19.         }
  20.         public static void Or_Int32(uint address, int input)
  21.         {
  22.             int input2 = Lib.ReadInt32(address) | input;
  23.             Lib.WriteInt32(address, input2);
  24.         }
  25.         public static bool ReadBool(uint address)
  26.         {
  27.             return PS3.GetMemory(address, 1)[0] != 0;
  28.         }
  29.         public static byte ReadByte(uint address)
  30.         {
  31.             return PS3.GetMemory(address, 1)[0];
  32.         }
  33.         public static byte[] ReadBytes(uint address, int length)
  34.         {
  35.             return PS3.GetMemory(address, length);
  36.         }
  37.         public static double ReadDouble(uint address)
  38.         {
  39.             byte[] memory = PS3.GetMemory(address, 8);
  40.             Array.Reverse(memory, 0, 8);
  41.             return BitConverter.ToDouble(memory, 0);
  42.         }
  43.         public static double[] ReadDouble(uint address, int length)
  44.         {
  45.             byte[] memory = PS3.GetMemory(address, length * 8);
  46.             Lib.ReverseBytes(memory);
  47.             double[] array = new double[length];
  48.             for (int i = 0; i < length; i++)
  49.             {
  50.                 array[i] = (double)BitConverter.ToSingle(memory, (length - 1 - i) * 8);
  51.             }
  52.             return array;
  53.         }
  54.         public static short ReadInt16(uint address)
  55.         {
  56.             byte[] memory = PS3.GetMemory(address, 2);
  57.             Array.Reverse(memory, 0, 2);
  58.             return BitConverter.ToInt16(memory, 0);
  59.         }
  60.         public static short[] ReadInt16(uint address, int length)
  61.         {
  62.             byte[] memory = PS3.GetMemory(address, length * 2);
  63.             Lib.ReverseBytes(memory);
  64.             short[] array = new short[length];
  65.             for (int i = 0; i < length; i++)
  66.             {
  67.                 array[i] = BitConverter.ToInt16(memory, (length - 1 - i) * 2);
  68.             }
  69.             return array;
  70.         }
  71.         public static int ReadInt32(uint address)
  72.         {
  73.             byte[] memory = PS3.GetMemory(address, 4);
  74.             Array.Reverse(memory, 0, 4);
  75.             return BitConverter.ToInt32(memory, 0);
  76.         }
  77.         public static int[] ReadInt32(uint address, int length)
  78.         {
  79.             byte[] memory = PS3.GetMemory(address, length * 4);
  80.             Lib.ReverseBytes(memory);
  81.             int[] array = new int[length];
  82.             for (int i = 0; i < length; i++)
  83.             {
  84.                 array[i] = BitConverter.ToInt32(memory, (length - 1 - i) * 4);
  85.             }
  86.             return array;
  87.         }
  88.         public static long ReadInt64(uint address)
  89.         {
  90.             byte[] memory = PS3.GetMemory(address, 8);
  91.             Array.Reverse(memory, 0, 8);
  92.             return BitConverter.ToInt64(memory, 0);
  93.         }
  94.         public static long[] ReadInt64(uint address, int length)
  95.         {
  96.             byte[] memory = PS3.GetMemory(address, length * 8);
  97.             Lib.ReverseBytes(memory);
  98.             long[] array = new long[length];
  99.             for (int i = 0; i < length; i++)
  100.             {
  101.                 array[i] = BitConverter.ToInt64(memory, (length - 1 - i) * 8);
  102.             }
  103.             return array;
  104.         }
  105.         public static sbyte ReadSByte(uint address)
  106.         {
  107.             return (sbyte)PS3.GetMemory(address, 1)[0];
  108.         }
  109.         public static sbyte[] ReadSBytes(uint address, int length)
  110.         {
  111.             byte[] memory = PS3.GetMemory(address, length);
  112.             sbyte[] array = new sbyte[length];
  113.             for (int i = 0; i < length; i++)
  114.             {
  115.                 array[i] = (sbyte)memory[i];
  116.             }
  117.             return array;
  118.         }
  119.         public static float ReadSingle(uint address)
  120.         {
  121.             byte[] memory = PS3.GetMemory(address, 4);
  122.             Array.Reverse(memory, 0, 4);
  123.             return BitConverter.ToSingle(memory, 0);
  124.         }
  125.         public static float[] ReadSingle(uint address, int length)
  126.         {
  127.             byte[] memory = PS3.GetMemory(address, length * 4);
  128.             Lib.ReverseBytes(memory);
  129.             float[] array = new float[length];
  130.             for (int i = 0; i < length; i++)
  131.             {
  132.                 array[i] = BitConverter.ToSingle(memory, (length - 1 - i) * 4);
  133.             }
  134.             return array;
  135.         }
  136.         public static string ReadString(uint address)
  137.         {
  138.             int num = 40;
  139.             int num2 = 0;
  140.             string text = "";
  141.             do
  142.             {
  143.                 byte[] memory = PS3.GetMemory(address + (uint)num2, num);
  144.                 text += Encoding.UTF8.GetString(memory);
  145.                 num2 += num;
  146.             }
  147.             while (!text.Contains('\0'));
  148.             int length = text.IndexOf('\0');
  149.             string result = text.Substring(0, length);
  150.             text = string.Empty;
  151.             return result;
  152.         }
  153.         public static ushort ReadUInt16(uint address)
  154.         {
  155.             byte[] memory = PS3.GetMemory(address, 2);
  156.             Array.Reverse(memory, 0, 2);
  157.             return BitConverter.ToUInt16(memory, 0);
  158.         }
  159.         public static ushort[] ReadUInt16(uint address, int length)
  160.         {
  161.             byte[] memory = PS3.GetMemory(address, length * 2);
  162.             Lib.ReverseBytes(memory);
  163.             ushort[] array = new ushort[length];
  164.             for (int i = 0; i < length; i++)
  165.             {
  166.                 array[i] = BitConverter.ToUInt16(memory, (length - 1 - i) * 2);
  167.             }
  168.             return array;
  169.         }
  170.         public static uint ReadUInt32(uint address)
  171.         {
  172.             byte[] memory = PS3.GetMemory(address, 4);
  173.             Array.Reverse(memory, 0, 4);
  174.             return BitConverter.ToUInt32(memory, 0);
  175.         }
  176.         public static uint[] ReadUInt32(uint address, int length)
  177.         {
  178.             byte[] memory = PS3.GetMemory(address, length * 4);
  179.             Lib.ReverseBytes(memory);
  180.             uint[] array = new uint[length];
  181.             for (int i = 0; i < length; i++)
  182.             {
  183.                 array[i] = BitConverter.ToUInt32(memory, (length - 1 - i) * 4);
  184.             }
  185.             return array;
  186.         }
  187.         public static ulong ReadUInt64(uint address)
  188.         {
  189.             byte[] memory = PS3.GetMemory(address, 8);
  190.             Array.Reverse(memory, 0, 8);
  191.             return BitConverter.ToUInt64(memory, 0);
  192.         }
  193.         public static ulong[] ReadUInt64(uint address, int length)
  194.         {
  195.             byte[] memory = PS3.GetMemory(address, length * 8);
  196.             Lib.ReverseBytes(memory);
  197.             ulong[] array = new ulong[length];
  198.             for (int i = 0; i < length; i++)
  199.             {
  200.                 array[i] = BitConverter.ToUInt64(memory, (length - 1 - i) * 8);
  201.             }
  202.             return array;
  203.         }
  204.         public static byte[] ReverseBytes(byte[] toReverse)
  205.         {
  206.             Array.Reverse(toReverse);
  207.             return toReverse;
  208.         }
  209.         public static void WriteBool(uint address, bool input)
  210.         {
  211.             byte[] bytes = new byte[]
  212.             {
  213.                
  214.             };
  215.             PS3.SetMemory(address, bytes);
  216.         }
  217.         public static void WriteByte(uint address, byte input)
  218.         {
  219.             PS3.SetMemory(address, new byte[]
  220.             {
  221.                 input
  222.             });
  223.         }
  224.         public static void WriteBytes(uint address, byte[] input)
  225.         {
  226.             PS3.SetMemory(address, input);
  227.         }
  228.         public static bool WriteBytesToggle(uint Offset, byte[] On, byte[] Off)
  229.         {
  230.             bool flag = Lib.ReadByte(Offset) == On[0];
  231.             Lib.WriteBytes(Offset, (!flag) ? On : Off);
  232.             return flag;
  233.         }
  234.         public static void WriteDouble(uint address, double input)
  235.         {
  236.             byte[] array = new byte[8];
  237.             BitConverter.GetBytes(input).CopyTo(array, 0);
  238.             Array.Reverse(array, 0, 8);
  239.             PS3.SetMemory(address, array);
  240.         }
  241.         public static void WriteDouble(uint address, double[] input)
  242.         {
  243.             int num = input.Length;
  244.             byte[] array = new byte[num * 8];
  245.             for (int i = 0; i < num; i++)
  246.             {
  247.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 8);
  248.             }
  249.             PS3.SetMemory(address, array);
  250.         }
  251.         public static void WriteInt16(uint address, short input)
  252.         {
  253.             byte[] array = new byte[2];
  254.             Lib.ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
  255.             PS3.SetMemory(address, array);
  256.         }
  257.         public static void WriteInt16(uint address, short[] input)
  258.         {
  259.             int num = input.Length;
  260.             byte[] array = new byte[num * 2];
  261.             for (int i = 0; i < num; i++)
  262.             {
  263.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 2);
  264.             }
  265.             PS3.SetMemory(address, array);
  266.         }
  267.         public static void WriteInt32(uint address, int input)
  268.         {
  269.             byte[] array = new byte[4];
  270.             Lib.ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
  271.             PS3.SetMemory(address, array);
  272.         }
  273.         public static void WriteInt32(uint address, int[] input)
  274.         {
  275.             int num = input.Length;
  276.             byte[] array = new byte[num * 4];
  277.             for (int i = 0; i < num; i++)
  278.             {
  279.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 4);
  280.             }
  281.             PS3.SetMemory(address, array);
  282.         }
  283.         public static void WriteInt64(uint address, long input)
  284.         {
  285.             byte[] array = new byte[8];
  286.             Lib.ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
  287.             PS3.SetMemory(address, array);
  288.         }
  289.         public static void WriteInt64(uint address, long[] input)
  290.         {
  291.             int num = input.Length;
  292.             byte[] array = new byte[num * 8];
  293.             for (int i = 0; i < num; i++)
  294.             {
  295.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 8);
  296.             }
  297.             PS3.SetMemory(address, array);
  298.         }
  299.         public static void WriteSByte(uint address, sbyte input)
  300.         {
  301.             byte[] bytes = new byte[]
  302.             {
  303.                 (byte)input
  304.             };
  305.             PS3.SetMemory(address, bytes);
  306.         }
  307.         public static void WriteSBytes(uint address, sbyte[] input)
  308.         {
  309.             int num = input.Length;
  310.             byte[] array = new byte[num];
  311.             for (int i = 0; i < num; i++)
  312.             {
  313.                 array[i] = (byte)input[i];
  314.             }
  315.             PS3.SetMemory(address, array);
  316.         }
  317.         public static void WriteSingle(uint address, float input)
  318.         {
  319.             byte[] array = new byte[4];
  320.             BitConverter.GetBytes(input).CopyTo(array, 0);
  321.             Array.Reverse(array, 0, 4);
  322.             PS3.SetMemory(address, array);
  323.         }
  324.         public static void WriteSingle(uint address, float[] input)
  325.         {
  326.             int num = input.Length;
  327.             byte[] array = new byte[num * 4];
  328.             for (int i = 0; i < num; i++)
  329.             {
  330.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 4);
  331.             }
  332.             PS3.SetMemory(address, array);
  333.         }
  334.         public static void WriteString(uint address, string input)
  335.         {
  336.             byte[] bytes = Encoding.UTF8.GetBytes(input);
  337.             Array.Resize<byte>(ref bytes, bytes.Length + 1);
  338.             PS3.SetMemory(address, bytes);
  339.         }
  340.         public static void WriteUInt16(uint address, ushort input)
  341.         {
  342.             byte[] array = new byte[2];
  343.             BitConverter.GetBytes(input).CopyTo(array, 0);
  344.             Array.Reverse(array, 0, 2);
  345.             PS3.SetMemory(address, array);
  346.         }
  347.         public static void WriteUInt16(uint address, ushort[] input)
  348.         {
  349.             int num = input.Length;
  350.             byte[] array = new byte[num * 2];
  351.             for (int i = 0; i < num; i++)
  352.             {
  353.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 2);
  354.             }
  355.             PS3.SetMemory(address, array);
  356.         }
  357.         public static void WriteUInt32(uint address, uint input)
  358.         {
  359.             byte[] array = new byte[4];
  360.             BitConverter.GetBytes(input).CopyTo(array, 0);
  361.             Array.Reverse(array, 0, 4);
  362.             PS3.SetMemory(address, array);
  363.         }
  364.         public static void WriteUInt32(uint address, uint[] input)
  365.         {
  366.             int num = input.Length;
  367.             byte[] array = new byte[num * 4];
  368.             for (int i = 0; i < num; i++)
  369.             {
  370.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 4);
  371.             }
  372.             PS3.SetMemory(address, array);
  373.         }
  374.         public static void WriteUInt64(uint address, ulong input)
  375.         {
  376.             byte[] array = new byte[8];
  377.             BitConverter.GetBytes(input).CopyTo(array, 0);
  378.             Array.Reverse(array, 0, 8);
  379.             PS3.SetMemory(address, array);
  380.         }
  381.         public static void WriteUInt64(uint address, ulong[] input)
  382.         {
  383.             int num = input.Length;
  384.             byte[] array = new byte[num * 8];
  385.             for (int i = 0; i < num; i++)
  386.             {
  387.                 Lib.ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, i * 8);
  388.             }
  389.             PS3.SetMemory(address, array);
  390.         }
  391.         public static string char_to_wchar(string text)
  392.         {
  393.             string text2 = text;
  394.             for (int i = 0; i < text.Length; i++)
  395.             {
  396.                 text2 = text2.Insert(i * 2, "\0");
  397.             }
  398.             return text2;
  399.         }
  400.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement