I’ve updated the code here with the older below for some increased improvements. I may add OCR to the mix if I get some additional time this week. The improvements include launching PS4 and turning the machine on out of Rest mode and going back into Rest once completed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
using PS4RemotePlayInterceptor; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CSharpPS4RemotePlayInterceptor { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static void bringToFront(string title) { // Get a handle to the Calculator application. IntPtr handle = FindWindow(null, title); // Verify that Calculator is a running process. if (handle == IntPtr.Zero) { return; } // Make Calculator the foreground application SetForegroundWindow(handle); } [DllImport("USER32.DLL", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(String lpClassName, String lpWindowName); [DllImport("USER32.DLL")] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); [DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; static IntPtr FindWindowByIndex(IntPtr hWndParent, int index) { if (index == 0) return hWndParent; else { int ct = 0; IntPtr result = IntPtr.Zero; do { result = FindWindowEx(hWndParent, result, "Button", null); if (result != IntPtr.Zero) ++ct; } while (ct < index && result != IntPtr.Zero); return result; } } Process PlayStationProcess; private void Form1_Load(object sender, EventArgs e) { PlayStationProcess = Process.Start(@"C:\Program Files (x86)\Sony\PS4 Remote Play\RemotePlay.exe"); Debug.WriteLine(PlayStationProcess.Id); System.Threading.Thread t = new System.Threading.Thread(Start); t.IsBackground = true; t.Start(); } private void Inject() { // Setup callback to interceptor Interceptor.Callback = new InterceptionDelegate(OnReceiveData); // Emulate controller (BETA) Interceptor.EmulateController = true; // Start watchdog to automatically inject when possible Interceptor.Watchdog.Start(); // Notify watchdog events Interceptor.Watchdog.OnInjectionSuccess = () => Console.WriteLine("Watchdog OnInjectionSuccess"); Interceptor.Watchdog.OnInjectionFailure = () => Console.WriteLine("Watchdog OnInjectionFailure"); // Or inject manually and handle exceptions yourself Interceptor.InjectionMode = InjectionMode.Compatibility; //Interceptor.Inject(); } public System.Diagnostics.Stopwatch BootKeeper; public System.Diagnostics.Stopwatch TimeKeeper; private void Start() { Inject(); BootKeeper = new System.Diagnostics.Stopwatch(); TimeKeeper = new System.Diagnostics.Stopwatch(); PointerToMethodToCall = StartCOD; while (true) { if (Keyboard.IsKeyDown(Keys.Z)) { Debug.WriteLine("z"); } byte[] keys = new byte[256]; Keyboard.GetKeyboardState(keys); if ((keys[(int)Keys.Up] & keys[(int)Keys.Right] & 128) == 128) { Debug.WriteLine("Up Arrow key and Right Arrow key down."); } Application.DoEvents(); System.Threading.Thread.Sleep(50); } } private delegate void HumanForPS4(ref DualShockState state); HumanForPS4 PointerToMethodToCall; bool ActionDuringTime(Stopwatch Keeper, double StartTime, double Duration = 250) { if (Keeper.Elapsed.TotalMilliseconds > (StartTime * 1000) && (Keeper.Elapsed.TotalMilliseconds < Duration + (StartTime * 1000))) { //Debug.WriteLine("Returning true for Action"); return true; } else { return false; } } const uint WM_KEYDOWN = 0x100; const uint WM_KEYUP = 0x101; const uint Key_Down = 0x0001; const uint Key_Up = 0x0002; [DllImport("user32.dll", SetLastError = true)] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); [DllImport("user32.dll")] public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); bool step1 = false, step2 = false, step3 = false, step4 = false; private void StartCOD(ref DualShockState state) { if (ActionDuringTime(BootKeeper, 3)) { bringToFront(PlayStationProcess.MainWindowTitle); } if (ActionDuringTime(BootKeeper, 5)) { if (!step1) { if (false) //failed attenpt to send control send. { } IntPtr hWndAbout = FindWindow(null/* TODO Change to default(_) if this is not a reference type */, PlayStationProcess.MainWindowTitle); //keybd_event((byte)Keys.LControlKey, 0, Key_Down, 0); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYDOWN, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYUP, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); //keybd_event((byte)Keys.LControlKey, 0, Key_Up, 0); IntPtr hWndOkButton = FindWindowEx(hWndAbout, IntPtr.Zero, "WindowsForms10.STATIC.app.0.141b42a_r9_ad1", "Start"); step1 = true; Debug.WriteLine("Tab sent"); SendKeys.SendWait("{TAB}"); } } /* if (ActionDuringTime(BootKeeper, 6)) { if (!step1) { IntPtr hWndAbout = FindWindow(null, PlayStationProcess.MainWindowTitle); //keybd_event((byte)Keys.LControlKey, 0, Key_Down, 0); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYDOWN, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYUP, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); //keybd_event((byte)Keys.LControlKey, 0, Key_Up, 0); IntPtr hWndOkButton = FindWindowEx(hWndAbout, IntPtr.Zero, "WindowsForms10.STATIC.app.0.141b42a_r9_ad1", "Start"); step1 = true; Debug.WriteLine("Tab sent2"); //SendKeys.SendWait("{TAB}"); } } */ if (ActionDuringTime(BootKeeper, 7)) { if (!step2) { step2 = true; SendKeys.SendWait("{ENTER}"); } } if (BootKeeper.Elapsed.TotalSeconds > 70 && !TimeKeeper.IsRunning) { TimeKeeper.Start(); } if (ActionDuringTime(TimeKeeper, 1, 2000)) //Move alll the way to the left { state.LX = 0; return; } if (ActionDuringTime(TimeKeeper, 5)) //Move Right { state.LX = 255; return; } if (ActionDuringTime(TimeKeeper, 7)) //Move Right { state.LX = 255; return; } if (ActionDuringTime(TimeKeeper, 10)) //Hit X, start game { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 23)) //Hit X, Skip Intro { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 28)) //Hit X, Hit X to start game into main menu { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 30)) // Down one menu { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 33)) //Down to zombies { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 36)) //Hit X Enter Zombies { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 40)) //Hit X, Ack the rewards { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 42, 2000)) //Hold the button to quit { state.PS = true; return; } if (ActionDuringTime(TimeKeeper, 45, 2000)) //Move up to close application { state.LY = 0; return; } if (ActionDuringTime(TimeKeeper, 52)) //Confirm to close application { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 56)) //Confirm to close application { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 66)) //Move left { state.LX = 0; return; } if (ActionDuringTime(TimeKeeper, 70, 2000)) //Hold the button to quit { state.PS = true; return; } if (ActionDuringTime(TimeKeeper, 76)) //Move down (we assume we are already at sound/devices) { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 80)) //Move doown { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 83)) //Move right { state.LX = 255; return; } if (ActionDuringTime(TimeKeeper, 85)) //Select to enter rest mode { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 87)) //Kill our connection { if (!step3) { step3 = true; PlayStationProcess.Kill(); } return; } if (ActionDuringTime(TimeKeeper, 95)) //Kill our connection { if (!step4) { step4 = true; Application.Exit(); } return; } state.LX = 128; state.LY = 128; state.Cross = false; state.Square = false; state.Circle = false; state.Triangle = false; state.PS = false; } bool HookedAndSending = false; private void OnReceiveData(ref DualShockState state) { if (!HookedAndSending) { HookedAndSending = true; Debug.WriteLine("Hooked"); BootKeeper.Start(); } PointerToMethodToCall(ref state); return; state.Cross = Keyboard.IsKeyDown(Keys.X); state.Square = Keyboard.IsKeyDown(Keys.A); state.Circle = Keyboard.IsKeyDown(Keys.D); state.Triangle = Keyboard.IsKeyDown(Keys.W); if (state.Cross || state.Square || state.Triangle || state.Circle) { Debug.WriteLine(state.Cross + " " + state.Square + " " + state.Triangle + " " + state.Circle); } if (Keyboard.IsKeyDown(Keys.Up)) { state.LY = 0; } if (Keyboard.IsKeyDown(Keys.Down)) { state.LY = 255; } if (Keyboard.IsKeyDown(Keys.Left)) { state.LX = 0; } if (Keyboard.IsKeyDown(Keys.Right)) { state.LX = 255; } if (!Keyboard.IsKeyDown(Keys.Right) && !Keyboard.IsKeyDown(Keys.Left)) { state.LX = 128; } if (!Keyboard.IsKeyDown(Keys.Up) && !Keyboard.IsKeyDown(Keys.Down)) { state.LY = 128; } /* -- Modify the controller state here -- */ // Force press X // Force left analog upwards // Force left analog downwards // state.LY = 255; // Force left analog to center // state.LX = 128; // state.LY = 128; } public abstract class Keyboard { [Flags] private enum KeyStates { None = 0, Down = 1, Toggled = 2 } [DllImport("user32.dll")] public static extern int GetKeyboardState(byte[] keystate); [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] private static extern short GetKeyState(int keyCode); private static KeyStates GetKeyState(Keys key) { KeyStates state = KeyStates.None; short retVal = GetKeyState((int)key); //If the high-order bit is 1, the key is down //otherwise, it is up. if ((retVal & 0x8000) == 0x8000) state |= KeyStates.Down; //If the low-order bit is 1, the key is toggled. if ((retVal & 1) == 1) state |= KeyStates.Toggled; return state; } public static bool IsKeyDown(Keys key) { return KeyStates.Down == (GetKeyState(key) & KeyStates.Down); } public static bool IsKeyToggled(Keys key) { return KeyStates.Toggled == (GetKeyState(key) & KeyStates.Toggled); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Interceptor.StopInjection(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
using PS4RemotePlayInterceptor; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CSharpPS4RemotePlayInterceptor { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static void bringToFront(string title) { // Get a handle to the Calculator application. IntPtr handle = FindWindow(null, title); // Verify that Calculator is a running process. if (handle == IntPtr.Zero) { return; } // Make Calculator the foreground application SetForegroundWindow(handle); } [DllImport("USER32.DLL", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(String lpClassName, String lpWindowName); [DllImport("USER32.DLL")] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); [DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; static IntPtr FindWindowByIndex(IntPtr hWndParent, int index) { if (index == 0) return hWndParent; else { int ct = 0; IntPtr result = IntPtr.Zero; do { result = FindWindowEx(hWndParent, result, "Button", null); if (result != IntPtr.Zero) ++ct; } while (ct < index && result != IntPtr.Zero); return result; } } Process PlayStationProcess; private void Form1_Load(object sender, EventArgs e) { PlayStationProcess = Process.Start(@"C:\Program Files (x86)\Sony\PS4 Remote Play\RemotePlay.exe"); Debug.WriteLine(PlayStationProcess.Id); System.Threading.Thread t = new System.Threading.Thread(Start); t.IsBackground = true; t.Start(); } private void Inject() { // Setup callback to interceptor Interceptor.Callback = new InterceptionDelegate(OnReceiveData); // Emulate controller (BETA) Interceptor.EmulateController = true; // Start watchdog to automatically inject when possible Interceptor.Watchdog.Start(); // Notify watchdog events Interceptor.Watchdog.OnInjectionSuccess = () => Console.WriteLine("Watchdog OnInjectionSuccess"); Interceptor.Watchdog.OnInjectionFailure = () => Console.WriteLine("Watchdog OnInjectionFailure"); // Or inject manually and handle exceptions yourself Interceptor.InjectionMode = InjectionMode.Compatibility; //Interceptor.Inject(); } public System.Diagnostics.Stopwatch BootKeeper; public System.Diagnostics.Stopwatch TimeKeeper; private void Start() { Inject(); BootKeeper = new System.Diagnostics.Stopwatch(); TimeKeeper = new System.Diagnostics.Stopwatch(); PointerToMethodToCall = StartCOD; while (true) { if (Keyboard.IsKeyDown(Keys.Z)) { Debug.WriteLine("z"); } byte[] keys = new byte[256]; Keyboard.GetKeyboardState(keys); if ((keys[(int)Keys.Up] & keys[(int)Keys.Right] & 128) == 128) { Debug.WriteLine("Up Arrow key and Right Arrow key down."); } Application.DoEvents(); System.Threading.Thread.Sleep(50); } } private delegate void HumanForPS4(ref DualShockState state); HumanForPS4 PointerToMethodToCall; bool ActionDuringTime(Stopwatch Keeper, double StartTime, double Duration = 250) { if (Keeper.Elapsed.TotalMilliseconds > (StartTime * 1000) && (Keeper.Elapsed.TotalMilliseconds < Duration + (StartTime * 1000))) { //Debug.WriteLine("Returning true for Action"); return true; } else { return false; } } const uint WM_KEYDOWN = 0x100; const uint WM_KEYUP = 0x101; const uint Key_Down = 0x0001; const uint Key_Up = 0x0002; [DllImport("user32.dll", SetLastError = true)] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); [DllImport("user32.dll")] public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); bool step1 = false, step2 = false, step3 = false, step4 = false; private void StartCOD(ref DualShockState state) { if (ActionDuringTime(BootKeeper, 3)) { bringToFront(PlayStationProcess.MainWindowTitle); } if (ActionDuringTime(BootKeeper, 5)) { if (!step1) { if (false) //failed attenpt to send control send. { } IntPtr hWndAbout = FindWindow(null/* TODO Change to default(_) if this is not a reference type */, PlayStationProcess.MainWindowTitle); //keybd_event((byte)Keys.LControlKey, 0, Key_Down, 0); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYDOWN, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYUP, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); //keybd_event((byte)Keys.LControlKey, 0, Key_Up, 0); IntPtr hWndOkButton = FindWindowEx(hWndAbout, IntPtr.Zero, "WindowsForms10.STATIC.app.0.141b42a_r9_ad1", "Start"); step1 = true; Debug.WriteLine("Tab sent"); SendKeys.SendWait("{TAB}"); } } /* if (ActionDuringTime(BootKeeper, 6)) { if (!step1) { IntPtr hWndAbout = FindWindow(null, PlayStationProcess.MainWindowTitle); //keybd_event((byte)Keys.LControlKey, 0, Key_Down, 0); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYDOWN, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); PostMessage(PlayStationProcess.MainWindowHandle, WM_KEYUP, (IntPtr)Keys.Tab, (IntPtr)(0)); Thread.Sleep(50); //keybd_event((byte)Keys.LControlKey, 0, Key_Up, 0); IntPtr hWndOkButton = FindWindowEx(hWndAbout, IntPtr.Zero, "WindowsForms10.STATIC.app.0.141b42a_r9_ad1", "Start"); step1 = true; Debug.WriteLine("Tab sent2"); //SendKeys.SendWait("{TAB}"); } } */ if (ActionDuringTime(BootKeeper, 7)) { if (!step2) { step2 = true; SendKeys.SendWait("{ENTER}"); } } if (BootKeeper.Elapsed.TotalSeconds > 70 && !TimeKeeper.IsRunning) { TimeKeeper.Start(); } if (ActionDuringTime(TimeKeeper, 1, 2000)) //Move alll the way to the left { state.LX = 0; return; } if (ActionDuringTime(TimeKeeper, 5)) //Move Right { state.LX = 255; return; } if (ActionDuringTime(TimeKeeper, 7)) //Move Right { state.LX = 255; return; } if (ActionDuringTime(TimeKeeper, 10)) //Hit X, start game { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 23)) //Hit X, Skip Intro { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 28)) //Hit X, Hit X to start game into main menu { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 30)) // Down one menu { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 33)) //Down to zombies { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 36)) //Hit X Enter Zombies { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 40)) //Hit X, Ack the rewards { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 42, 2000)) //Hold the button to quit { state.PS = true; return; } if (ActionDuringTime(TimeKeeper, 45, 2000)) //Move up to close application { state.LY = 0; return; } if (ActionDuringTime(TimeKeeper, 52)) //Confirm to close application { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 56)) //Confirm to close application { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 66)) //Move left { state.LX = 0; return; } if (ActionDuringTime(TimeKeeper, 70, 2000)) //Hold the button to quit { state.PS = true; return; } if (ActionDuringTime(TimeKeeper, 76)) //Move down (we assume we are already at sound/devices) { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 80)) //Move doown { state.LY = 255; return; } if (ActionDuringTime(TimeKeeper, 83)) //Move right { state.LX = 255; return; } if (ActionDuringTime(TimeKeeper, 85)) //Select to enter rest mode { state.Cross = true; return; } if (ActionDuringTime(TimeKeeper, 87)) //Kill our connection { if (!step3) { step3 = true; PlayStationProcess.Kill(); } return; } if (ActionDuringTime(TimeKeeper, 87)) //Kill our connection { if (!step4) { step4 = true; Application.Exit(); } return; } state.LX = 128; state.LY = 128; state.Cross = false; state.Square = false; state.Circle = false; state.Triangle = false; state.PS = false; } bool HookedAndSending = false; private void OnReceiveData(ref DualShockState state) { if (!HookedAndSending) { HookedAndSending = true; Debug.WriteLine("Hooked"); BootKeeper.Start(); } PointerToMethodToCall(ref state); return; state.Cross = Keyboard.IsKeyDown(Keys.X); state.Square = Keyboard.IsKeyDown(Keys.A); state.Circle = Keyboard.IsKeyDown(Keys.D); state.Triangle = Keyboard.IsKeyDown(Keys.W); if (state.Cross || state.Square || state.Triangle || state.Circle) { Debug.WriteLine(state.Cross + " " + state.Square + " " + state.Triangle + " " + state.Circle); } if (Keyboard.IsKeyDown(Keys.Up)) { state.LY = 0; } if (Keyboard.IsKeyDown(Keys.Down)) { state.LY = 255; } if (Keyboard.IsKeyDown(Keys.Left)) { state.LX = 0; } if (Keyboard.IsKeyDown(Keys.Right)) { state.LX = 255; } if (!Keyboard.IsKeyDown(Keys.Right) && !Keyboard.IsKeyDown(Keys.Left)) { state.LX = 128; } if (!Keyboard.IsKeyDown(Keys.Up) && !Keyboard.IsKeyDown(Keys.Down)) { state.LY = 128; } /* -- Modify the controller state here -- */ // Force press X // Force left analog upwards // Force left analog downwards // state.LY = 255; // Force left analog to center // state.LX = 128; // state.LY = 128; } public abstract class Keyboard { [Flags] private enum KeyStates { None = 0, Down = 1, Toggled = 2 } [DllImport("user32.dll")] public static extern int GetKeyboardState(byte[] keystate); [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] private static extern short GetKeyState(int keyCode); private static KeyStates GetKeyState(Keys key) { KeyStates state = KeyStates.None; short retVal = GetKeyState((int)key); //If the high-order bit is 1, the key is down //otherwise, it is up. if ((retVal & 0x8000) == 0x8000) state |= KeyStates.Down; //If the low-order bit is 1, the key is toggled. if ((retVal & 1) == 1) state |= KeyStates.Toggled; return state; } public static bool IsKeyDown(Keys key) { return KeyStates.Down == (GetKeyState(key) & KeyStates.Down); } public static bool IsKeyToggled(Keys key) { return KeyStates.Toggled == (GetKeyState(key) & KeyStates.Toggled); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Interceptor.StopInjection(); } } } |