Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace BO2_Menu_Base
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class Lib
- {
- public static void And_Int32(UInt32 address, int input)
- {
- int num = ReadInt32(address) & input;
- WriteInt32(address, num);
- }
- public static bool CompareByteArray(byte[] a, byte[] b)
- {
- int num = 0;
- for (int i = 0; i < a.Length; i++)
- {
- if (a[i] == b[i])
- {
- num++;
- }
- }
- return (num == a.Length);
- }
- public static void Or_Int32(UInt32 address, int input)
- {
- int num = ReadInt32(address) | input;
- WriteInt32(address, num);
- }
- public static bool ReadBool(UInt32 address)
- {
- return (PS3.GetMemory(address, 1)[0] != 0);
- }
- public static byte ReadByte(UInt32 address)
- {
- return PS3.GetMemory(address, 1)[0];
- }
- public static byte[] ReadBytes(UInt32 address, int length)
- {
- return PS3.GetMemory(address, length);
- }
- public static double ReadDouble(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 8);
- Array.Reverse(memory, 0, 8);
- return BitConverter.ToDouble(memory, 0);
- }
- public static double[] ReadDouble(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 8);
- ReverseBytes(memory);
- double[] numArray = new double[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToSingle(memory, ((length - 1) - i) * 8);
- }
- return numArray;
- }
- public static short ReadInt16(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 2);
- Array.Reverse(memory, 0, 2);
- return BitConverter.ToInt16(memory, 0);
- }
- public static short[] ReadInt16(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 2);
- ReverseBytes(memory);
- short[] numArray = new short[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToInt16(memory, ((length - 1) - i) * 2);
- }
- return numArray;
- }
- public static int ReadInt32(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 4);
- Array.Reverse(memory, 0, 4);
- return BitConverter.ToInt32(memory, 0);
- }
- public static int[] ReadInt32(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 4);
- ReverseBytes(memory);
- int[] numArray = new int[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToInt32(memory, ((length - 1) - i) * 4);
- }
- return numArray;
- }
- public static long ReadInt64(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 8);
- Array.Reverse(memory, 0, 8);
- return BitConverter.ToInt64(memory, 0);
- }
- public static long[] ReadInt64(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 8);
- ReverseBytes(memory);
- long[] numArray = new long[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToInt64(memory, ((length - 1) - i) * 8);
- }
- return numArray;
- }
- public static sbyte ReadSByte(UInt32 address)
- {
- return (sbyte) PS3.GetMemory(address, 1)[0];
- }
- public static sbyte[] ReadSBytes(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length);
- sbyte[] numArray = new sbyte[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = (sbyte) memory[i];
- }
- return numArray;
- }
- public static float ReadSingle(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 4);
- Array.Reverse(memory, 0, 4);
- return BitConverter.ToSingle(memory, 0);
- }
- public static float[] ReadSingle(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 4);
- ReverseBytes(memory);
- float[] numArray = new float[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToSingle(memory, ((length - 1) - i) * 4);
- }
- return numArray;
- }
- public static string ReadString(UInt32 address)
- {
- int length = 40;
- int num2 = 0;
- string source = "";
- do
- {
- byte[] memory = PS3.GetMemory(address + ((UInt32) num2), length);
- source = source + Encoding.UTF8.GetString(memory);
- num2 += length;
- }
- while (!source.Contains<char>('\0'));
- int index = source.IndexOf('\0');
- string str2 = source.Substring(0, index);
- source = string.Empty;
- return str2;
- }
- public static ushort ReadUInt16(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 2);
- Array.Reverse(memory, 0, 2);
- return BitConverter.ToUInt16(memory, 0);
- }
- public static ushort[] ReadUInt16(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 2);
- ReverseBytes(memory);
- ushort[] numArray = new ushort[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToUInt16(memory, ((length - 1) - i) * 2);
- }
- return numArray;
- }
- public static UInt32 ReadUInt32(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 4);
- Array.Reverse(memory, 0, 4);
- return BitConverter.ToUInt32(memory, 0);
- }
- public static UInt32[] ReadUInt32(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 4);
- ReverseBytes(memory);
- UInt32[] numArray = new UInt32[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToUInt32(memory, ((length - 1) - i) * 4);
- }
- return numArray;
- }
- public static ulong ReadUInt64(UInt32 address)
- {
- byte[] memory = PS3.GetMemory(address, 8);
- Array.Reverse(memory, 0, 8);
- return BitConverter.ToUInt64(memory, 0);
- }
- public static ulong[] ReadUInt64(UInt32 address, int length)
- {
- byte[] memory = PS3.GetMemory(address, length * 8);
- ReverseBytes(memory);
- ulong[] numArray = new ulong[length];
- for (int i = 0; i < length; i++)
- {
- numArray[i] = BitConverter.ToUInt64(memory, ((length - 1) - i) * 8);
- }
- return numArray;
- }
- public static byte[] ReverseBytes(byte[] toReverse)
- {
- Array.Reverse(toReverse);
- return toReverse;
- }
- public static void WriteBool(UInt32 address, bool input)
- {
- byte[] bytes = new byte[] { input ? ((byte) 1) : ((byte) 0) };
- PS3.SetMemory(address, bytes);
- }
- public static void WriteByte(UInt32 address, byte input)
- {
- PS3.SetMemory(address, new byte[] { input });
- }
- public static void WriteBytes(UInt32 address, byte[] input)
- {
- PS3.SetMemory(address, input);
- }
- public static bool WriteBytesToggle(UInt32 Offset, byte[] On, byte[] Off)
- {
- bool flag = ReadByte(Offset) == On[0];
- WriteBytes(Offset, !flag ? On : Off);
- return flag;
- }
- public static void WriteDouble(UInt32 address, double input)
- {
- byte[] array = new byte[8];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 8);
- PS3.SetMemory(address, array);
- }
- public static void WriteDouble(UInt32 address, double[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 8];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 8));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteInt16(UInt32 address, short input)
- {
- byte[] array = new byte[2];
- ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
- PS3.SetMemory(address, array);
- }
- public static void WriteInt16(UInt32 address, short[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 2];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 2));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteInt32(UInt32 address, int input)
- {
- byte[] array = new byte[4];
- ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
- PS3.SetMemory(address, array);
- }
- public static void WriteInt32(UInt32 address, int[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 4];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 4));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteInt64(UInt32 address, long input)
- {
- byte[] array = new byte[8];
- ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
- PS3.SetMemory(address, array);
- }
- public static void WriteInt64(UInt32 address, long[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 8];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 8));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteSByte(UInt32 address, sbyte input)
- {
- byte[] bytes = new byte[] { (byte) input };
- PS3.SetMemory(address, bytes);
- }
- public static void WriteSBytes(UInt32 address, sbyte[] input)
- {
- int length = input.Length;
- byte[] bytes = new byte[length];
- for (int i = 0; i < length; i++)
- {
- bytes[i] = (byte) input[i];
- }
- PS3.SetMemory(address, bytes);
- }
- public static void WriteSingle(UInt32 address, float input)
- {
- byte[] array = new byte[4];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 4);
- PS3.SetMemory(address, array);
- }
- public static void WriteSingle(UInt32 address, float[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 4];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 4));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteString(UInt32 address, string input)
- {
- byte[] bytes = Encoding.UTF8.GetBytes(input);
- Array.Resize<byte>(ref bytes, bytes.Length + 1);
- PS3.SetMemory(address, bytes);
- }
- public static void WriteUInt16(UInt32 address, ushort input)
- {
- byte[] array = new byte[2];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 2);
- PS3.SetMemory(address, array);
- }
- public static void WriteUInt16(UInt32 address, ushort[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 2];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 2));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteUInt32(UInt32 address, UInt32 input)
- {
- byte[] array = new byte[4];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 4);
- PS3.SetMemory(address, array);
- }
- public static void WriteUInt32(UInt32 address, UInt32[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 4];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 4));
- }
- PS3.SetMemory(address, array);
- }
- public static void WriteUInt64(UInt32 address, ulong input)
- {
- byte[] array = new byte[8];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 8);
- PS3.SetMemory(address, array);
- }
- public static void WriteUInt64(UInt32 address, ulong[] input)
- {
- int length = input.Length;
- byte[] array = new byte[length * 8];
- for (int i = 0; i < length; i++)
- {
- ReverseBytes(BitConverter.GetBytes(input[i])).CopyTo(array, (int) (i * 8));
- }
- PS3.SetMemory(address, array);
- }
- public static String char_to_wchar(String text)
- {
- String wchar = text;
- for (Int32 i = 0; i < text.Length; i++)
- {
- wchar = wchar.Insert(i * 2, "\0");
- }
- return wchar;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement