• Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

[PS3][C#][CCAPI/TMAPI] Lib.cs

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PS3Lib;
using System.Threading;
using System.Diagnostics;
using System.IO;

namespace WindowsFormApplication
{
  class Lib
  {
  #region References
  private static SelectAPI CurrentAPI;
  private static PS3API PS3 = new PS3API(SelectAPI.ControlConsole);
  private static CCAPI PS3CCAPI = new CCAPI();
  private static TMAPI PS3TMAPI = new TMAPI();
  #endregion

  public static string char_to_wchar(string text)
  {
  string str = text;
  for (int i = 0; i < text.Length; i++)
  {
  str = str.Insert(i * 2, "\0");
  }
  return str;
  }

  public static bool CompareByteArray(byte[] byte_0, byte[] byte_1)
  {
  int num = 0;
  for (int i = 0; i < byte_0.Length; i++)
  {
  if (byte_0[i] == byte_1[i])
  {
  num++;
  }
  }
  return (num == byte_0.Length);
  }

  public static byte[] ReverseBytes(byte[] toReverse)
  {
  Array.Reverse(toReverse);
  return toReverse;
  }

  public static void WriteBool(uint address, bool input)
  {
  byte[] bytes = new byte[] { input ? ((byte)1) : ((byte)0) };
  PS3.SetMemory(address, bytes);
  }

  public static void WriteByte(uint address, byte input)
  {
  PS3.SetMemory(address, new byte[] { input });
  }

  public static void WriteBytes(uint address, byte[] input)
  {
  PS3.SetMemory(address, input);
  }

  public static void WriteDouble(uint 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(uint 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 WriteFloat(uint Offset, float Float)
  {
  byte[] buffer = new byte[4];
  BitConverter.GetBytes(Float).CopyTo(buffer, 0);
  Array.Reverse(buffer, 0, 4);
  PS3.SetMemory(Offset, buffer);
  }

  public static void WriteFloatArray(uint Offset, float[] Array)
  {
  byte[] buffer = new byte[Array.Length * 4];
  for (int Lenght = 0; Lenght < Array.Length; Lenght++)
  {
  ReverseBytes(BitConverter.GetBytes(Array[Lenght])).CopyTo(buffer, Lenght * 4);
  }
  PS3.SetMemory(Offset, buffer);
  }

  public static void WriteInt(uint Offset, int Value)
  {
  byte[] buffer = BitConverter.GetBytes(Value);
  Array.Reverse(buffer);
  PS3.SetMemory(Offset, buffer);
  }

  public static void WriteUInt(uint Offset, uint Value)
  {
  byte[] buffer = new byte[4];
  BitConverter.GetBytes(Value).CopyTo(buffer, 0);
  Array.Reverse(buffer, 0, 4);
  PS3.SetMemory(Offset, buffer);
  }

  public static void WriteInt16(uint address, short input)
  {
  byte[] array = new byte[2];
  ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
  PS3.SetMemory(address, array);
  }

  public static void WriteInt16(uint 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(uint address, int input)
  {
  byte[] array = new byte[4];
  ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
  PS3.SetMemory(address, array);
  }

  public static void WriteInt32(uint 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(uint address, long input)
  {
  byte[] array = new byte[8];
  ReverseBytes(BitConverter.GetBytes(input)).CopyTo(array, 0);
  PS3.SetMemory(address, array);
  }

  public static void WriteInt64(uint 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(uint address, sbyte input)
  {
  byte[] bytes = new byte[] { (byte)input };
  PS3.SetMemory(address, bytes);
  }

  public static void WriteSBytes(uint 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(uint 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(uint 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(uint 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(uint 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(uint 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(uint address, uint 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(uint address, uint[] 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(uint 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(uint 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 bool ReadBool(uint offset)
  {
  byte[] buffer = new byte[1];
  GetMem(offset, buffer, CurrentAPI);
  return (buffer[0] != 0);
  }

  public static float ReadFloat(uint Offset)
  {
  byte[] buffer = new byte[4];
  PS3.GetMemory(Offset, buffer);
  Array.Reverse(buffer, 0, 4);
  return BitConverter.ToSingle(buffer, 0);
  }

  public static int ReadInt(uint Offset)
  {
  byte[] buffer = new byte[4];
  PS3.GetMemory(Offset, buffer);
  Array.Reverse(buffer);
  int Value = BitConverter.ToInt32(buffer, 0);
  return Value;
  }

  public static byte ReadByte(uint offset)
  {
  return GetBytes(offset, 1, CurrentAPI)[0];
  }

  public static float[] ReadSingle(uint address, int length)
  {
  byte[] memory = PS3.Extension.ReadBytes(address, length * 4);
  ReverseBytes(memory);
  float[] numArray = new float[length];
  for (int index = 0; index < length; ++index)
  numArray[index] = BitConverter.ToSingle(memory, (length - 1 - index) * 4);
  return numArray;
  }

  public static byte[] ReadBytes(uint offset, int length)
  {
  return GetBytes(offset, length, CurrentAPI);
  }

  public static double ReadDouble(uint address)
  {
  byte[] memory = GetMemory(address, 8);
  Array.Reverse(memory, 0, 8);
  return BitConverter.ToDouble(memory, 0);
  }

  public static sbyte ReadSByte(uint address)
  {
  return (sbyte)GetMemory(address, 1)[0];
  }

  public static float[] ReadFloatLength(uint Offset, int Length)
  {
  byte[] buffer = new byte[Length * 4];
  PS3.GetMemory(Offset, buffer);
  Array.Reverse(buffer);
  float[] FArray = new float[Length];
  for (int i = 0; i < Length; i++)
  {
  FArray[i] = BitConverter.ToSingle(buffer, (Length - 1 - i) * 4);
  }
  return FArray;
  }

  public static sbyte[] ReadSBytes(uint address, int length)
  {
  byte[] memory = GetMemory(address, length);
  sbyte[] array = new sbyte[length];
  for (int i = 0; i < length; i++)
  {
  array[i] = (sbyte)memory[i];
  }
  return array;
  }

  public static double[] ReadDouble(uint address, int length)
  {
  byte[] memory = GetMemory(address, length * 8);
  ReverseBytes(memory);
  double[] array = new double[length];
  for (int i = 0; i < length; i++)
  {
  array[i] = (double)BitConverter.ToSingle(memory, (length - 1 - i) * 8);
  }
  return array;
  }

  public static short ReadInt16(uint offset)
  {
  byte[] array = GetBytes(offset, 2, CurrentAPI);
  Array.Reverse(array, 0, 2);
  return BitConverter.ToInt16(array, 0);
  }

  public static int ReadInt32(uint offset)
  {
  byte[] array = GetBytes(offset, 4, CurrentAPI);
  Array.Reverse(array, 0, 4);
  return BitConverter.ToInt32(array, 0);
  }

  public static ushort ReadUInt16(uint address)
  {
  byte[] memory = GetMemory(address, 2);
  Array.Reverse(memory, 0, 2);
  return BitConverter.ToUInt16(memory, 0);
  }

  public static ushort[] ReadUInt16(uint address, int length)
  {
  byte[] memory = GetMemory(address, length * 2);
  ReverseBytes(memory);
  ushort[] array = new ushort[length];
  for (int i = 0; i < length; i++)
  {
  array[i] = BitConverter.ToUInt16(memory, (length - 1 - i) * 2);
  }
  return array;
  }

  public static uint ReadUInt32(uint address)
  {
  byte[] memory = GetMemory(address, 4);
  Array.Reverse(memory, 0, 4);
  return BitConverter.ToUInt32(memory, 0);
  }

  public static uint[] ReadUInt32(uint address, int length)
  {
  byte[] memory = GetMemory(address, length * 4);
  ReverseBytes(memory);
  uint[] array = new uint[length];
  for (int i = 0; i < length; i++)
  {
  array[i] = BitConverter.ToUInt32(memory, (length - 1 - i) * 4);
  }
  return array;
  }

  public static ulong ReadUInt64(uint address)
  {
  byte[] memory = GetMemory(address, 8);
  Array.Reverse(memory, 0, 8);
  return BitConverter.ToUInt64(memory, 0);
  }

  public static ulong[] ReadUInt64(uint address, int length)
  {
  byte[] memory = GetMemory(address, length * 8);
  ReverseBytes(memory);
  ulong[] array = new ulong[length];
  for (int i = 0; i < length; i++)
  {
  array[i] = BitConverter.ToUInt64(memory, (length - 1 - i) * 8);
  }
  return array;
  }

  public static byte[] GetBytes(uint offset, int length, SelectAPI API)
  {
  byte[] bytes = new byte[length];
  if (API == SelectAPI.ControlConsole)
  {
  CurrentAPI = GetCurrentAPI();
  return PS3.GetBytes(offset, length);
  }
  if (API == SelectAPI.TargetManager)
  {
  CurrentAPI = GetCurrentAPI();
  bytes = PS3.GetBytes(offset, length);
  }
  return bytes;
  }

  public static byte[] GetMemory(uint offset, int length)
  {
  byte[] array = new byte[length];
  PS3.GetMemory(offset, array);
  return array;
  }

  public static byte[] ToHexFloat(float Axis)
  {
  byte[] bytes = BitConverter.GetBytes(Axis);
  Array.Reverse(bytes);
  return bytes;
  }

  public static void ChangeAPI(SelectAPI API)
  {
  PS3.ChangeAPI(API);
  }

  public static SelectAPI GetCurrentAPI()
  {
  return PS3.GetCurrentAPI();
  }

  public static void GetMem(uint offset, byte[] buffer, SelectAPI API)
  {
  if (API == SelectAPI.ControlConsole)
  {
  GetMemoryR(offset, buffer);
  }
  else if (API == SelectAPI.TargetManager)
  {
  GetMemoryR(offset, buffer);
  }
  }

  public static byte[] GetMemoryL(uint address, int length)
  {
  byte[] buffer = new byte[length];
  PS3.GetMemory(address, buffer);
  return buffer;
  }

  public static void SetMemory(uint Address, byte[] Bytes)
  {
  PS3.SetMemory(Address, Bytes);
  }

  public static void GetMemoryR(uint Address, byte[] Bytes)
  {
  PS3.GetMemory(Address, Bytes);
  }

  //Game Lib
  public static float[] GetOrigin(int Client)
  {
  float[] Position = ReadSingle(0x1780F50 + ((uint)Client * 0x5808), 3);
  return Position;
  }
  }
}
 
General chit-chat
Help Users
      Chat Bot: crc20100201 is our newest member. Welcome!
      Back
      Top