Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// PS3TMAPI Simplified functions.
- /// </summary>
- public static class PS3
- {
- static uint[] ProcessIDs;
- static uint ProcessID;
- /// <summary>
- /// Connects the Ps3 to the PS3TMAPI.
- /// </summary>
- public static void Connect()
- {
- PS3TMAPI.InitTargetComms();
- PS3TMAPI.Connect(0, null);
- }
- /// <summary>
- /// Attach the process to the PS3TMAPI and continues the process automatically.
- /// </summary>
- public static void Attach()
- {
- PS3TMAPI.GetProcessList(0, out ProcessIDs);
- ulong uProcess = ProcessIDs[0];
- ProcessID = Convert.ToUInt32(uProcess);
- PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
- PS3TMAPI.ProcessContinue(0, ProcessID);
- }
- /// <summary>
- /// Continues the process
- /// </summary>
- public static void Continue()
- {
- PS3TMAPI.GetProcessList(0, out ProcessIDs);
- ulong uProcess = ProcessIDs[0];
- ProcessID = Convert.ToUInt32(uProcess);
- PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
- PS3TMAPI.ProcessContinue(0, ProcessID);
- }
- /// <summary>
- /// Pause the process.
- /// </summary>
- public static void Pause()
- {
- PS3TMAPI.GetProcessList(0, out ProcessIDs);
- ulong uProcess = ProcessIDs[0];
- ProcessID = Convert.ToUInt32(uProcess);
- PS3TMAPI.ProcessAttach(0, PS3TMAPI.UnitType.PPU, ProcessID);
- }
- /// <summary>
- /// Turns off the PS3.
- /// </summary>
- public static void TurnOFF()
- {
- PS3TMAPI.PowerOff(0, true);
- }
- /// <summary>
- /// Sets the bytes at a selected address.
- /// </summary>
- /// <param name="Address">Address to write at.</param>
- /// <param name="Bytes">Values to write at the address.</param>
- /// <param name="thread">Thread to execute the ps3 function on. (used in multi-threading)</param>
- /// <returns></returns>
- public static void SetMemory(uint Address, byte[] Bytes, uint thread = 0)
- {
- PS3TMAPI.ProcessSetMemory(0, PS3TMAPI.UnitType.PPU, ProcessID, thread, Address, Bytes);
- }
- /// <summary>
- /// Gets the bytes at a selected address.
- /// </summary>
- /// <param name="Address">Address to read at.</param>
- /// <param name="length">Length of the byte array</param>
- /// <param name="thread">Thread to execute the ps3 function on. (used in multi-threading)</param>
- /// <returns></returns>
- public static byte[] GetMemory(uint Address, int length, uint thread = 0)
- {
- byte[] x = new byte[length];
- PS3TMAPI.ProcessGetMemory(0, PS3TMAPI.UnitType.PPU, ProcessID, thread, Address, ref x);
- return x;
- }
- /// <summary>
- /// Gets the status of the PS3.
- /// </summary>
- /// <returns>Returns a result information as a string</returns>
- public static string GetStatus()
- {
- PS3TMAPI.ConnectStatus state = new PS3TMAPI.ConnectStatus();
- string use = "";
- PS3TMAPI.GetConnectStatus(0, out state, out use);
- return state.ToString();
- }
- /// <summary>
- /// Gets the IP Address of the PS3
- /// </summary>
- /// <returns>Returns the IP Address of the current PS3.</returns>
- public static string GetIP()
- {
- PS3TMAPI.TCPIPConnectProperties ip = new PS3TMAPI.TCPIPConnectProperties();
- PS3TMAPI.GetConnectionInfo(0, out ip);
- return ip.IPAddress.ToString();
- }
- /// <summary>
- /// Fetch the name of the current game.(Requires an internet connection.)
- /// </summary>
- /// <returns>Returns the name of the game</returns>
- public static string GetGame()
- {
- PS3TMAPI.ProcessInfo infos = new PS3TMAPI.ProcessInfo();
- PS3TMAPI.GetProcessInfo(0, ProcessID, out infos);
- string[] str = infos.Hdr.ELFPath.Split('/');
- string ID = str[3];
- try
- {
- System.Net.WebClient seeker = new System.Net.WebClient();
- System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
- string content = seeker.DownloadString("https://a0.ww.np.dl.playstation.net/tpl/np/" + ID + "/" + ID + "-ver.xml").Replace("<TITLE>", ";");
- string name = content.Split(';')[1].Replace("</TITLE>", ";");
- return name.Split(';')[0];
- }
- catch
- {
- return ID;
- }
- }
- public static byte[] Reverse(byte[] buff)
- {
- Array.Reverse(buff);
- return buff;
- }
- public static float ReadFloat(uint address)
- {
- byte[] buff = PS3.GetMemory(address, 4, 0);
- Array.Reverse(buff);
- float val = BitConverter.ToSingle(buff, 0);
- return val;
- }
- public static void WriteByte(uint address, byte val)
- {
- PS3.SetMemory(address, new byte[] {val});
- }
- public static void WriteFloat(uint address, float val)
- {
- PS3.SetMemory(address, Reverse(BitConverter.GetBytes(val)), 0);
- }
- public static void WriteInt(uint address, int val)
- {
- PS3.SetMemory(address, Reverse(BitConverter.GetBytes(val)), 0);
- }
- public static void WriteUInt(uint address, uint val)
- {
- PS3.SetMemory(address, Reverse(BitConverter.GetBytes(val)), 0);
- }
- public static int ReadInt(uint address)
- {
- byte[] buff = PS3.GetMemory(address, 4, 0);
- Array.Reverse(buff);
- int val = BitConverter.ToInt32(buff, 0);
- return val;
- }
- public static uint ReadUInt(uint address)
- {
- byte[] buff = PS3.GetMemory(address, 4, 0);
- Array.Reverse(buff);
- uint val = BitConverter.ToUInt32(buff, 0);
- return val;
- }
- public static short ReadShort(uint address)
- {
- byte[] buff = PS3.GetMemory(address, 2, 0);
- Array.Reverse(buff);
- short val = BitConverter.ToInt16(buff, 0);
- return val;
- }
- public static byte ReadByte(uint address)
- {
- byte[] buff = PS3.GetMemory(address, 1, 0);
- return buff[0];
- }
- public static string ReadString(uint address)
- {
- int length = 0;
- for (int i = 0; i < 5000; i++)
- {
- byte buffer = PS3.GetMemory(address + (uint)i, 1)[0];
- if (buffer == (byte)0x00) { length = i; break; }
- }
- byte[] buff = PS3.GetMemory(address, length, 0);
- return Encoding.ASCII.GetString(buff);
- }
- public static void WriteString(uint address, string txt)
- {
- PS3.SetMemory(address, Encoding.ASCII.GetBytes(txt + "\0"), 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement