Advertisement
BaSs_HaXoR

PS3TMAPI Class (C#)

Aug 15th, 2014
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.33 KB | None | 0 0
  1. /// <summary>
  2.     /// PS3TMAPI Simplified functions.
  3.     /// </summary>
  4.     public static class PS3
  5.     {
  6.         static uint[] ProcessIDs;
  7.         static uint ProcessID;
  8.  
  9.         /// <summary>
  10.         /// Connects the Ps3 to the PS3TMAPI.
  11.         /// </summary>
  12.         public static void Connect()
  13.         {
  14.             PS3TMAPI.InitTargetComms();
  15.             PS3TMAPI.Connect(0, null);
  16.         }
  17.         /// <summary>
  18.         /// Attach the process to the PS3TMAPI and continues the process automatically.
  19.         /// </summary>
  20.         public static void Attach()
  21.         {
  22.             PS3TMAPI.GetProcessList(0, out ProcessIDs);
  23.             ulong uProcess = ProcessIDs[0];
  24.             ProcessID = Convert.ToUInt32(uProcess);
  25.             PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
  26.             PS3TMAPI.ProcessContinue(0, ProcessID);
  27.  
  28.         }
  29.         /// <summary>
  30.         /// Continues the process
  31.         /// </summary>
  32.         public static void Continue()
  33.         {
  34.             PS3TMAPI.GetProcessList(0, out ProcessIDs);
  35.             ulong uProcess = ProcessIDs[0];
  36.             ProcessID = Convert.ToUInt32(uProcess);
  37.             PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
  38.             PS3TMAPI.ProcessContinue(0, ProcessID);
  39.         }
  40.         /// <summary>
  41.         /// Pause the process.
  42.         /// </summary>
  43.         public static void Pause()
  44.         {
  45.             PS3TMAPI.GetProcessList(0, out ProcessIDs);
  46.             ulong uProcess = ProcessIDs[0];
  47.             ProcessID = Convert.ToUInt32(uProcess);
  48.             PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
  49.         }
  50.         /// <summary>
  51.         /// Turns off the PS3.
  52.         /// </summary>
  53.         public static void TurnOFF()
  54.         {
  55.             PS3TMAPI.PowerOff(0, true);
  56.         }
  57.         /// <summary>
  58.         /// Sets the bytes at a selected address.
  59.         /// </summary>
  60.         /// <param name="Address">Address to write at.</param>
  61.         /// <param name="Bytes">Values to write at the address.</param>
  62.         /// <param name="thread">Thread to execute the ps3 function on. (used in multi-threading)</param>
  63.         /// <returns></returns>
  64.         public static void SetMemory(uint Address, byte[] Bytes, uint thread = 0)
  65.         {
  66.             PS3TMAPI.ProcessSetMemory(0, PS3TMAPI.UnitType.PPU, ProcessID, thread, Address, Bytes);
  67.         }
  68.         /// <summary>
  69.         /// Gets the bytes at a selected address.
  70.         /// </summary>
  71.         /// <param name="Address">Address to read at.</param>
  72.         /// <param name="length">Length of the byte array</param>
  73.         /// <param name="thread">Thread to execute the ps3 function on. (used in multi-threading)</param>
  74.         /// <returns></returns>
  75.         public static byte[] GetMemory(uint Address, int length, uint thread = 0)
  76.         {
  77.             byte[] x = new byte[length];
  78.             PS3TMAPI.ProcessGetMemory(0, PS3TMAPI.UnitType.PPU, ProcessID, thread, Address, ref x);
  79.             return x;
  80.         }
  81.         /// <summary>
  82.         /// Gets the status of the PS3.
  83.         /// </summary>
  84.         /// <returns>Returns a result information as a string</returns>
  85.         public static string GetStatus()
  86.         {
  87.             PS3TMAPI.ConnectStatus state = new PS3TMAPI.ConnectStatus();
  88.             string use = "";
  89.             PS3TMAPI.GetConnectStatus(0, out state, out use);
  90.             return state.ToString();
  91.         }
  92.         /// <summary>
  93.         /// Gets the IP Address of the PS3
  94.         /// </summary>
  95.         /// <returns>Returns the IP Address of the current PS3.</returns>
  96.         public static string GetIP()
  97.         {
  98.             PS3TMAPI.TCPIPConnectProperties ip = new PS3TMAPI.TCPIPConnectProperties();
  99.             PS3TMAPI.GetConnectionInfo(0, out ip);
  100.             return ip.IPAddress.ToString();
  101.         }
  102.    
  103.         /// <summary>
  104.         /// Fetch the name of the current game.(Requires an internet connection.)
  105.         /// </summary>
  106.         /// <returns>Returns the name of the game</returns>
  107.         public static string GetGame()
  108.         {
  109.             PS3TMAPI.ProcessInfo infos = new PS3TMAPI.ProcessInfo();
  110.             PS3TMAPI.GetProcessInfo(0, ProcessID, out infos);
  111.             string[] str = infos.Hdr.ELFPath.Split('/');
  112.             string ID = str[3];
  113.             try
  114.             {
  115.                 System.Net.WebClient seeker = new System.Net.WebClient();
  116.                 System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  117.                 string content = seeker.DownloadString("https://a0.ww.np.dl.playstation.net/tpl/np/" + ID + "/" + ID + "-ver.xml").Replace("<TITLE>", ";");
  118.                 string name = content.Split(';')[1].Replace("</TITLE>", ";");
  119.                 return name.Split(';')[0];
  120.             }
  121.             catch
  122.             {
  123.                 return ID;
  124.             }
  125.         }
  126.         public static byte[] Reverse(byte[] buff)
  127.         {
  128.             Array.Reverse(buff);
  129.             return buff;
  130.         }
  131.         public static float ReadFloat(uint address)
  132.         {
  133.  
  134.             byte[] buff = PS3.GetMemory(address, 4, 0);
  135.             Array.Reverse(buff);
  136.             float val = BitConverter.ToSingle(buff, 0);
  137.             return val;
  138.         }
  139.         public static void WriteByte(uint address, byte val)
  140.         {
  141.             PS3.SetMemory(address, new byte[] {val});
  142.         }
  143.         public static void WriteFloat(uint address, float val)
  144.         {
  145.             PS3.SetMemory(address, Reverse(BitConverter.GetBytes(val)), 0);
  146.         }
  147.         public static void WriteInt(uint address, int val)
  148.         {
  149.             PS3.SetMemory(address, Reverse(BitConverter.GetBytes(val)), 0);
  150.         }
  151.         public static void WriteUInt(uint address, uint val)
  152.         {
  153.             PS3.SetMemory(address, Reverse(BitConverter.GetBytes(val)), 0);
  154.         }
  155.         public static int ReadInt(uint address)
  156.         {
  157.  
  158.             byte[] buff = PS3.GetMemory(address, 4, 0);
  159.             Array.Reverse(buff);
  160.             int val = BitConverter.ToInt32(buff, 0);
  161.             return val;
  162.         }
  163.         public static uint ReadUInt(uint address)
  164.         {
  165.  
  166.             byte[] buff = PS3.GetMemory(address, 4, 0);
  167.             Array.Reverse(buff);
  168.             uint val = BitConverter.ToUInt32(buff, 0);
  169.             return val;
  170.         }
  171.         public static short ReadShort(uint address)
  172.         {
  173.  
  174.             byte[] buff = PS3.GetMemory(address, 2, 0);
  175.             Array.Reverse(buff);
  176.             short val = BitConverter.ToInt16(buff, 0);
  177.             return val;
  178.         }
  179.         public static byte ReadByte(uint address)
  180.         {
  181.             byte[] buff = PS3.GetMemory(address, 1, 0);
  182.             return buff[0];
  183.         }
  184.         public static string ReadString(uint address)
  185.         {
  186.             int length = 0;
  187.             for (int i = 0; i < 5000; i++)
  188.             {
  189.                 byte buffer = PS3.GetMemory(address + (uint)i, 1)[0];
  190.                 if (buffer == (byte)0x00) { length = i; break; }
  191.             }
  192.             byte[] buff = PS3.GetMemory(address, length, 0);
  193.             return Encoding.ASCII.GetString(buff);
  194.         }
  195.         public static void WriteString(uint address, string txt)
  196.         {
  197.             PS3.SetMemory(address, Encoding.ASCII.GetBytes(txt + "\0"), 0);
  198.         }
  199.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement