Advertisement
Guest User

BOI Mp RPC 1.13

a guest
Mar 18th, 2014
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.70 KB | None | 0 0
  1. //Choco ghosts rpc port to bo1 mp by sc58
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace BOIMPRPC
  10. {
  11.     public class PS3
  12.     {
  13.         static uint processID;
  14.  
  15.         private static uint GetProcessID()
  16.         {
  17.             uint[] ProcessIDs;
  18.             PS3_TMAPI.GetProcessList(0, out ProcessIDs);
  19.             return ProcessIDs[0];
  20.         }
  21.  
  22.         public static void SetMemory(uint address, byte[] memory)
  23.         {
  24.             PS3_TMAPI.ProcessSetMemory(0, PS3_TMAPI.UnitType.PPU, processID, 0, address, memory);
  25.         }
  26.  
  27.         public static byte[] GetMemory(uint address, int length)
  28.         {
  29.             byte[] bytes = new byte[length];
  30.             PS3_TMAPI.ProcessGetMemory(0, PS3_TMAPI.UnitType.PPU, processID, 0, address, ref bytes);
  31.             return bytes;
  32.         }
  33.  
  34.         public static int Init()
  35.         {
  36.             processID = GetProcessID();
  37.             return RPC.Init();
  38.         }
  39.     }
  40.  
  41.     public class RPC
  42.     {
  43.         static uint function_address;
  44.  
  45.         public static int Init()
  46.         {
  47.             function_address = Get_func_address();
  48.             if (function_address == 0) return -1;
  49.             Enable_RPC();
  50.             return 0;
  51.         }
  52.  
  53.         public static uint Get_func_address()
  54.         {
  55.             for (uint i = 0x7A21D4; i < 0x1000000; i += 4)
  56.             {
  57.                 byte[] bytes = PS3.GetMemory(i, 8);
  58.                 if (((bytes[0] == 0x4B) && (bytes[1] == 0xFF) && (bytes[2] == 0xBE) && (bytes[3] == 0x05) && (bytes[4] == 0x4B) && (bytes[5] == 0xFF) && (bytes[6] == 0xFC) && (bytes[7] == 0x98)))
  59.                 {
  60.                     return i + 0xC;
  61.                 }
  62.             }
  63.             return 0;
  64.         }
  65.  
  66.         public static void Enable_RPC()
  67.         {
  68.             PS3.SetMemory(function_address, new byte[] { 0x4E, 0x80, 0x00, 0x20 });
  69.             System.Threading.Thread.Sleep(20);
  70.             byte[] func = new byte[] { 0x7C, 0x08, 0x02, 0xA6, 0xF8, 0x01, 0x00, 0x80, 0x3C, 0x60, 0x10, 0x05, 0x81, 0x83, 0x00, 0x4C, 0x2C, 0x0C, 0x00, 0x00, 0x41, 0x82, 0x00, 0x64, 0x80, 0x83, 0x00, 0x04, 0x80, 0xA3, 0x00, 0x08, 0x80, 0xC3, 0x00, 0x0C, 0x80, 0xE3, 0x00, 0x10, 0x81, 0x03, 0x00, 0x14, 0x81, 0x23, 0x00, 0x18, 0x81, 0x43, 0x00, 0x1C, 0x81, 0x63, 0x00, 0x20, 0xC0, 0x23, 0x00, 0x24, 0xC0, 0x43, 0x00, 0x28, 0xC0, 0x63, 0x00, 0x2C, 0xC0, 0x83, 0x00, 0x30, 0xC0, 0xA3, 0x00, 0x34, 0xC0, 0xC3, 0x00, 0x38, 0xC0, 0xE3, 0x00, 0x3C, 0xC1, 0x03, 0x00, 0x40, 0xC1, 0x23, 0x00, 0x48, 0x80, 0x63, 0x00, 0x00, 0x7D, 0x89, 0x03, 0xA6, 0x4E, 0x80, 0x04, 0x21, 0x3C, 0x80, 0x10, 0x05, 0x38, 0xA0, 0x00, 0x00, 0x90, 0xA4, 0x00, 0x4C, 0x80, 0x64, 0x00, 0x50, 0xE8, 0x01, 0x00, 0x80, 0x7C, 0x08, 0x03, 0xA6, 0x38, 0x21, 0x00, 0x70, 0x4E, 0x80, 0x00, 0x20, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00 };
  71.             PS3.SetMemory(function_address + 0x4, func);
  72.             PS3.SetMemory(0x10050000, new byte[0x2854]);
  73.             PS3.SetMemory(function_address, new byte[] { 0xF8, 0x21, 0xFF, 0x91 });
  74.         }
  75.  
  76.         public static int Call(uint func_address, params object[] parameters)
  77.         {
  78.             int num_params = parameters.Length;
  79.             uint num_floats = 0;
  80.             for (uint i = 0; i < num_params; i++)
  81.             {
  82.                 if (parameters[i] is int)
  83.                 {
  84.                     byte[] val = BitConverter.GetBytes((int)parameters[i]);
  85.                     Array.Reverse(val);
  86.                     PS3.SetMemory(0x10050000 + (i + num_floats) * 4, val);
  87.                 }
  88.                 else if (parameters[i] is uint)
  89.                 {
  90.                     byte[] val = BitConverter.GetBytes((uint)parameters[i]);
  91.                     Array.Reverse(val);
  92.                     PS3.SetMemory(0x10050000 + (i + num_floats) * 4, val);
  93.                 }
  94.                 else if (parameters[i] is string)
  95.                 {
  96.                     byte[] str = Encoding.UTF8.GetBytes(Convert.ToString(parameters[i]) + "\0");
  97.                     PS3.SetMemory(0x10050054 + i * 0x400, str);
  98.                     uint addr = 0x10050054 + i * 0x400;
  99.                     byte[] address = BitConverter.GetBytes(addr);
  100.                     Array.Reverse(address);
  101.                     PS3.SetMemory(0x10050000 + (i + num_floats) * 4, address);
  102.                 }
  103.                 else if (parameters[i] is float)
  104.                 {
  105.                     num_floats++;
  106.                     byte[] val = BitConverter.GetBytes((float)parameters[i]);
  107.                     Array.Reverse(val);
  108.                     PS3.SetMemory(0x10050024 + ((num_floats - 1) * 0x4), val);
  109.                 }
  110.             }
  111.             byte[] fadd = BitConverter.GetBytes(func_address);
  112.             Array.Reverse(fadd);
  113.             PS3.SetMemory(0x1005004C, fadd);
  114.             System.Threading.Thread.Sleep(20);
  115.             byte[] ret = PS3.GetMemory(0x10050050, 4);
  116.             Array.Reverse(ret);
  117.             return BitConverter.ToInt32(ret, 0);
  118.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement