Advertisement
ScriptzMoDz

Lib.cs

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