Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PS3AP
- {
- #region Functions
- private static PS3API DEX = new PS3API();
- public static void Connect()
- {
- DEX.ConnectTarget();
- DEX.AttachProcess();
- }
- public static void Reconnect()
- {
- DEX.ConnectTarget();
- }
- public static byte[] GetMemory(UInt32 offset, int length)
- {
- byte[] array = new byte[length];
- DEX.GetMemory(offset, array);
- return array;
- }
- public static void ChangeAPI(SelectAPI API)
- {
- DEX.ChangeAPI(API);
- }
- public static SelectAPI GetCurrentAPI()
- {
- return DEX.GetCurrentAPI();
- }
- public static byte[] GetMemoryL(UInt32 address, int length)
- {
- byte[] buffer = new byte[length];
- DEX.GetMemory(address, buffer);
- return buffer;
- }
- public static void GetMemor(UInt32 Address, byte[] Bytes)
- {
- DEX.SetMemory(Address, Bytes);
- }
- public static void GetMemoryR(UInt32 Address, ref byte[] Bytes)
- {
- DEX.GetMemory(Address, Bytes);
- }
- public class Extension
- {
- private static SelectAPI CurrentAPI;
- private static byte[] GetBytes(UInt32 offset, int length, SelectAPI API)
- {
- byte[] bytes = new byte[length];
- if (API == SelectAPI.ControlConsole)
- {
- CurrentAPI = GetCurrentAPI();
- return DEX.GetBytes(offset, length);
- }
- if (API == SelectAPI.TargetManager)
- {
- CurrentAPI = GetCurrentAPI();
- bytes = DEX.GetBytes(offset, length);
- }
- return bytes;
- }
- private static void GetMem(UInt32 offset, byte[] buffer, SelectAPI API)
- {
- if (API == SelectAPI.ControlConsole)
- {
- GetMemoryR(offset, ref buffer);
- }
- else if (API == SelectAPI.TargetManager)
- {
- GetMemoryR(offset, ref buffer);
- }
- }
- public static bool ReadBool(UInt32 offset)
- {
- byte[] buffer = new byte[1];
- GetMem(offset, buffer, CurrentAPI);
- return (buffer[0] != 0);
- }
- public static byte ReadByte(UInt32 offset)
- {
- return GetBytes(offset, 1, CurrentAPI)[0];
- }
- public static byte[] ReadBytes(UInt32 offset, int length)
- {
- return GetBytes(offset, length, CurrentAPI);
- }
- public static float ReadFloat(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 4, CurrentAPI);
- Array.Reverse(array, 0, 4);
- return BitConverter.ToSingle(array, 0);
- }
- public static short ReadInt16(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 2, CurrentAPI);
- Array.Reverse(array, 0, 2);
- return BitConverter.ToInt16(array, 0);
- }
- public static int ReadInt32(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 4, CurrentAPI);
- Array.Reverse(array, 0, 4);
- return BitConverter.ToInt32(array, 0);
- }
- public static void WriteSingle(UInt32 address, float input)
- {
- byte[] array = new byte[4];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 4);
- PS3AP.GetMemor(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));
- }
- PS3AP.GetMemor(address, array);
- }
- public static long ReadInt64(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 8, CurrentAPI);
- Array.Reverse(array, 0, 8);
- return BitConverter.ToInt64(array, 0);
- }
- public static sbyte ReadSByte(UInt32 offset)
- {
- byte[] buffer = new byte[1];
- GetMem(offset, buffer, CurrentAPI);
- return (sbyte)buffer[0];
- }
- public static string ReadString(UInt32 offset)
- {
- int length = 40;
- int num2 = 0;
- string source = "";
- do
- {
- byte[] bytes = ReadBytes(offset + ((UInt32)num2), length);
- source = source + Encoding.UTF8.GetString(bytes);
- 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 byte[] ReverseArray(float float_0)
- {
- byte[] bytes = BitConverter.GetBytes(float_0);
- Array.Reverse(bytes);
- return bytes;
- }
- public static byte[] uintBytes(UInt32 input)
- {
- byte[] data = BitConverter.GetBytes(input);
- Array.Reverse(data);
- return data;
- }
- public static byte[] ReverseBytes(byte[] inArray)
- {
- Array.Reverse(inArray);
- return inArray;
- }
- public static byte[] ToHexFloat(float Axis)
- {
- byte[] bytes = BitConverter.GetBytes(Axis);
- Array.Reverse(bytes);
- return bytes;
- }
- public static ushort ReadUInt16(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 2, CurrentAPI);
- Array.Reverse(array, 0, 2);
- return BitConverter.ToUInt16(array, 0);
- }
- public static UInt32 ReadUInt32(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 4, CurrentAPI);
- Array.Reverse(array, 0, 4);
- return BitConverter.ToUInt32(array, 0);
- }
- public static ulong ReadUInt64(UInt32 offset)
- {
- byte[] array = GetBytes(offset, 8, CurrentAPI);
- Array.Reverse(array, 0, 8);
- return BitConverter.ToUInt64(array, 0);
- }
- private static void SetMem(UInt32 Address, byte[] buffer, SelectAPI API)
- {
- DEX.SetMemory(Address, buffer);
- }
- public static void WriteBool(UInt32 offset, bool input)
- {
- byte[] buffer = new byte[] { input ? ((byte)1) : ((byte)0) };
- SetMem(offset, buffer, CurrentAPI);
- }
- public static void WriteByte(UInt32 offset, byte input)
- {
- byte[] buffer = new byte[] { input };
- SetMem(offset, buffer, CurrentAPI);
- }
- public static void WriteBytes(UInt32 offset, byte[] input)
- {
- byte[] buffer = input;
- SetMem(offset, buffer, CurrentAPI);
- }
- public static void WriteFloat(UInt32 offset, float input)
- {
- byte[] array = new byte[4];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 4);
- SetMem(offset, array, CurrentAPI);
- }
- public static void WriteInt16(UInt32 offset, short input)
- {
- byte[] array = new byte[2];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 2);
- SetMem(offset, array, CurrentAPI);
- }
- public static void WriteInt32(UInt32 offset, int input)
- {
- byte[] array = new byte[4];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 4);
- SetMem(offset, array, CurrentAPI);
- }
- public static void WriteInt64(UInt32 offset, long input)
- {
- byte[] array = new byte[8];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 8);
- SetMem(offset, array, CurrentAPI);
- }
- public static void WriteSByte(UInt32 offset, sbyte input)
- {
- byte[] buffer = new byte[] { (byte)input };
- SetMem(offset, buffer, CurrentAPI);
- }
- public static void WriteString(UInt32 offset, string input)
- {
- byte[] bytes = Encoding.UTF8.GetBytes(input);
- Array.Resize<byte>(ref bytes, bytes.Length + 1);
- SetMem(offset, bytes, CurrentAPI);
- }
- public static void WriteUInt16(UInt32 offset, ushort input)
- {
- byte[] array = new byte[2];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 2);
- SetMem(offset, array, CurrentAPI);
- }
- public static void WriteUInt32(UInt32 offset, UInt32 input)
- {
- byte[] array = new byte[4];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 4);
- SetMem(offset, array, CurrentAPI);
- }
- public static void WriteUInt64(UInt32 offset, ulong input)
- {
- byte[] array = new byte[8];
- BitConverter.GetBytes(input).CopyTo(array, 0);
- Array.Reverse(array, 0, 8);
- SetMem(offset, array, CurrentAPI);
- }
- }
- public class Func
- {
- public static byte GetByte(uint offset)
- {
- return PS3AP.GetMemory(offset, 1)[0];
- }
- public static ushort GetUInt16(uint offset, bool Reverse = false)
- {
- if (Reverse)
- {
- return BitConverter.ToUInt16(PS3AP.GetMemory(offset, 2), 0);
- }
- return BitConverter.ToUInt16(PS3AP.GetMemory(offset, 2).Reverse<byte>().ToArray<byte>(), 0);
- }
- public static uint GetUInt32(uint offset, bool Reverse = false)
- {
- if (Reverse)
- {
- return BitConverter.ToUInt32(PS3AP.GetMemory(offset, 4), 0);
- }
- return BitConverter.ToUInt32(PS3AP.GetMemory(offset, 4).Reverse<byte>().ToArray<byte>(), 0);
- }
- public static ulong GetUInt64(uint offset, bool Reverse = false)
- {
- if (Reverse)
- {
- return BitConverter.ToUInt64(PS3AP.GetMemory(offset, 8), 0);
- }
- return BitConverter.ToUInt64(PS3AP.GetMemory(offset, 8).Reverse<byte>().ToArray<byte>(), 0);
- }
- public static void SetByte(uint offset, byte Value)
- {
- PS3AP.GetMemor(offset, new byte[] { Value });
- }
- public static void SetString(uint offset, string text)
- {
- byte[] bytes = Encoding.ASCII.GetBytes(text);
- Array.Resize<byte>(ref bytes, bytes.Length + 1);
- PS3AP.GetMemor(offset, bytes);
- }
- public static void SetUInt16(uint offset, ushort Value, bool Reverse = false)
- {
- if (Reverse)
- {
- PS3AP.GetMemor(offset, BitConverter.GetBytes(Value));
- }
- else
- {
- PS3AP.GetMemor(offset, BitConverter.GetBytes(Value).Reverse<byte>().ToArray<byte>());
- }
- }
- public static void SetUInt32(uint offset, uint Value, bool Reverse = false)
- {
- if (Reverse)
- {
- PS3AP.GetMemor(offset, BitConverter.GetBytes(Value));
- }
- else
- {
- PS3AP.GetMemor(offset, BitConverter.GetBytes(Value).Reverse<byte>().ToArray<byte>());
- }
- }
- public static void SetUInt64(uint offset, ulong Value, bool Reverse = false)
- {
- if (Reverse)
- {
- PS3AP.GetMemor(offset, BitConverter.GetBytes(Value));
- }
- else
- {
- PS3AP.GetMemor(offset, BitConverter.GetBytes(Value).Reverse<byte>().ToArray<byte>());
- }
- }
- class Conversions
- {
- public static byte[] ReverseBytes(byte[] input)
- {
- Array.Reverse(input);
- return input;
- }
- public static byte[] RandomizeRGBA()
- {
- byte[] RGBA = new byte[4];
- Random randomize = new Random();
- RGBA[0] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
- RGBA[1] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
- RGBA[2] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
- RGBA[3] = BitConverter.GetBytes(randomize.Next(0, 255))[0];
- return RGBA;
- }
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement