Advertisement
John

F# Menu Base

Sep 17th, 2015
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 4.47 KB | None | 0 0
  1. open System
  2. open System.Threading
  3. open PS3Lib
  4.  
  5. let PS3 = PS3Lib.PS3API(SelectAPI.TargetManager)
  6. let mutable AlreadyConnected = false
  7. let Connect() =
  8.     let mutable attached = false
  9.     if(PS3.ConnectTarget())
  10.      then (attached <- PS3.AttachProcess())
  11.     if(attached) then true
  12.     else false
  13.  
  14. let tryConnectAttach() =
  15.     if(Connect())
  16.      then
  17.       printfn "Connected and attached successfully"
  18.       AlreadyConnected <- true
  19.       true
  20.     else
  21.      printfn "Failed to Connect and/or Attach"
  22.      false
  23.  
  24. let NotificationText = 0x02056B04u
  25. let NotificationState = 0x02057214u + 0x03u
  26. let ButtonsMonitoring = 0x01FC7C88u + 0x08u
  27. type ModMenu =
  28.      struct
  29.       val mutable isOpen: bool
  30.       val mutable CurrentOption: int
  31.      end
  32.  
  33. let getButton() =
  34.     PS3.Extension.ReadUInt32(ButtonsMonitoring)
  35.  
  36. let ShowText(show) =
  37.     let mutable State = 0x02uy
  38.     if(show) then State <- 0x03uy
  39.     PS3.Extension.WriteByte(NotificationState, State)
  40.  
  41. let ChangeText(text) =
  42.     PS3.Extension.WriteString(NotificationText, text)
  43.  
  44. let AppendStringArray(text) =
  45.     let mutable Output = ""
  46.     for _string in text
  47.      do Output <- Output + _string + "\n"
  48.     Output
  49.  
  50. let DrawMenu(text, option) =
  51.     let mutable Output = ""
  52.     let SelectedColor = "~r~"
  53.     let White = "~w~"
  54.     let mutable Color = White
  55.     let mutable Index : int = 0
  56.     for _string in text
  57.      do
  58.       if(option = Index) then Color <- SelectedColor
  59.       else Color <- White
  60.       Output <- Output + Color + _string +  "~n~"
  61.       Index <- (Index + 1)
  62.     ChangeText(Output)
  63.     ShowText(true)
  64.  
  65. let doGodmode() =
  66.     let bytes = [| 0x38uy; 0x60uy; 0x7Fuy; 0xFFuy; 0xB0uy; 0x7Fuy; 0x00uy; 0xB4uy; |]
  67.     PS3.SetMemory(0x1185D08u, bytes)
  68.  
  69. let doSuperJump() =
  70.     let bytes = [| 0x60uy; 0x00uy; 0x00uy; 0x00uy; |]
  71.     PS3.SetMemory(0x5EE6A0u, bytes)
  72.  
  73. let doUnlimitedAmmo() =
  74.     let bytes1 = [| 0x3Buy; 0xA0uy; 0x03uy; 0xE7uy; |]
  75.     let bytes2 = [| 0x38uy; 0xE0uy; 0x00uy; 0x63uy; |]
  76.     PS3.SetMemory(0xFBF0A4u, bytes1)
  77.     PS3.SetMemory(0xFDA420u, bytes2)
  78.    
  79.  
  80. let selectOption(option) =
  81.     match option with
  82.      | 0 -> doGodmode(); printfn "Enabled Godmode"              //do something when option 0 is selected
  83.      | 1 -> doSuperJump(); printfn "Enabled Super Jump"         //do something when option 1 is selected
  84.      | 2 -> doUnlimitedAmmo(); printfn "Enabled Unlimited Ammo"  //do something when option 2 is selected
  85.      | 3 -> printfn "Option 3"                                  //do something when option 3 is selected
  86.      | 4 -> printfn "Option 4"                                  //do something when option 4 is selected, etc.
  87.      | _ -> ()                                                  //do nothing when no option is selected
  88.     printfn "Selected Option %i" option
  89.  
  90. let Monitor() =
  91.     PS3.ConnectTarget() |> ignore
  92.     printfn "Running Menu"
  93.     let mutable Menu : ModMenu = new ModMenu()
  94.     Menu.isOpen <- false
  95.     Menu.CurrentOption <- 0
  96.     ShowText(false)
  97.  
  98.     let MenuText = [| "God Mode"; "Super Jump"; "Unlimited Ammo"; "Option 3"; "Option 4"; "Option 5"; "Option 6" |]
  99.  
  100.     while true do
  101.      if (Menu.isOpen) then
  102.       DrawMenu(MenuText, Menu.CurrentOption)
  103.       match getButton() with
  104.        | 0x00100000u -> if(Menu.CurrentOption > 0) then Menu.CurrentOption <- Menu.CurrentOption - 1                    //Dpad_up
  105.        | 0x00400000u -> if(Menu.CurrentOption < MenuText.Length - 1) then Menu.CurrentOption <- Menu.CurrentOption + 1  //Dpad_down
  106.        | 0x00000040u -> selectOption(Menu.CurrentOption)                                                                //Button_A
  107.        | 0x00000080u -> Menu.isOpen <- false; ShowText(false)                                                           //Button_X
  108.        | _ -> ()
  109.  
  110.      else if (getButton() = 0x00100000u) then Menu.isOpen <- true
  111.      Thread.Sleep(100)
  112.  
  113. let main() =
  114.     printfn "type 'connect' to connect to PS3"
  115.     printfn "Type 'start' to run the menu"
  116.     printfn "Type 'clear' to clear the console"
  117.     printfn "Type 'exit' to exit the application"
  118.  
  119.     let mutable MonitorThread = new Thread(Monitor);
  120.     while true do
  121.      match Console.ReadLine() with
  122.       | "connect" -> tryConnectAttach() |> ignore
  123.       | "exit" -> Environment.Exit(0)
  124.       | "start" ->  if(AlreadyConnected) then MonitorThread.Start() else printfn "You must connect first!"
  125.       | "clear" -> Console.Clear()
  126.       | _ -> printfn "Unknown command!"
  127.  
  128. main()
  129. Console.ReadLine() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement