Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 1.88 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // cmlibCtrlHook_sample
  2.  
  3. // header
  4. #include <pspkernel.h>
  5. #include <pspctrl.h>
  6. #include "cmlibctrlhook.h"
  7.  
  8. // info
  9. PSP_MODULE_INFO("cmlibCtrlHook_sample", PSP_MODULE_KERNEL, 0, 1);
  10.  
  11. // global
  12. CTRL_HOOK_HANDLER previous;
  13.  
  14. // function
  15. void WaitButtons(u32 buttons)
  16. {
  17.         SceCtrlData pad_data;
  18.         pad_data.Buttons = buttons;
  19.  
  20.         while((pad_data.Buttons & buttons) != 0)
  21.         {
  22.                 libCtrlHookGetRawData(&pad_data);
  23.                 sceKernelDelayThread(1000);
  24.         }
  25.  
  26.         return;
  27. }
  28.  
  29. int CtrlHandler(SceCtrlData *pad_data)
  30. {
  31.         // swap Square / Select buttons
  32.         if(pad_data->Buttons & PSP_CTRL_SQUARE)
  33.         {
  34.                 pad_data->Buttons |= PSP_CTRL_SELECT;
  35.                 pad_data->Buttons &= ~PSP_CTRL_SQUARE;
  36.         }
  37.         else if(pad_data->Buttons & PSP_CTRL_SELECT)
  38.         {
  39.                 pad_data->Buttons |= PSP_CTRL_SQUARE;
  40.                 pad_data->Buttons &= ~PSP_CTRL_SELECT;
  41.         }
  42.  
  43.         return previous ? previous(pad_data) : 0;
  44. }
  45.  
  46. int MainThread(SceSize args, void *argp)
  47. {
  48.         int id;
  49.         SceCtrlData pad_data;
  50.  
  51.         // set handler
  52.         //previous = libCtrlHookSetHandler(CtrlHandler);
  53.  
  54.         // set Circle
  55.         //libCtrlHookSetInvalidButtons(PSP_CTRL_CIRCLE);
  56.  
  57.         // clear
  58.         id = 0;
  59.  
  60.         // loop
  61.         while(1)
  62.         {
  63.                 // get raw_pad_data
  64.                 libCtrlHookGetRawData(&pad_data);
  65.  
  66.                 // set / delete invalid_button
  67.                 if((pad_data.Buttons & PSP_CTRL_SQUARE) && (pad_data.Buttons & PSP_CTRL_LTRIGGER))
  68.                 {
  69.                         //WaitButtons(PSP_CTRL_SQUARE); <-- ????
  70.  
  71.                         if(id == 0)
  72.                         {
  73.                                 id = libCtrlHookSetInvalidButtons(PSP_CTRL_LEFT | PSP_CTRL_RIGHT | PSP_CTRL_UP | PSP_CTRL_DOWN);
  74.                         }
  75.                         else
  76.                         {
  77.                                 libCtrlHookDeleteInvalidButtons(id);
  78.                                 id = 0;
  79.                         }
  80.                 }
  81.  
  82.                 // delay
  83.                 sceKernelDelayThread(5000);
  84.         }
  85.  
  86.         return 0;
  87. }
  88.  
  89. int module_start(SceSize args, void *argp)
  90. {
  91.         SceUID thid = sceKernelCreateThread("MainThread", MainThread, 16, 0x1000, 0, NULL);
  92.  
  93.         if(thid > 0)
  94.                 sceKernelStartThread(thid, args, argp);
  95.  
  96.         return 0;
  97. }
  98.  
  99. int module_stop(SceSize args, void *argp)
  100. {
  101.         return 0;
  102. }