disable buttons in XMB menu

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

disable buttons in XMB menu

Post by hotter »

I am making a prx plugin and I want to disable psp buttons in XMB menu (like the VSH menu), they would work just in my prx plugin. How to do that?
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

It calls vshCtrlReadBufferPositive. It can be hooked with a syscall patch. Or by patching the import call directly. Syscall patch is easier.

There are probably other methods but the advantage of hooking this function is that you can use the value it returns to detect key presses for your plugin. The XMB will call it continuously, so just use the pad data from the call, and make it zero after you're done so that the XMB will not respond to buttons. Your plugin will not have the overhead of its own button reading loop.
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

calling sceCtrlReadBufferPositive doesnt help when I call another function, for example delete file. Buttons works in XMB menu because delete file function take too long time... :(
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

hotter wrote:calling sceCtrlReadBufferPositive doesnt help when I call another function, for example delete file. Buttons works in XMB menu because delete file function take too long time... :(
Don't call the function! I mean that the XMB calls vshCtrlReadBufferPositive to read buttons. If you hook that function, and make the paddata parameter 0 it will not receive any button presses. And you can use the value before you make it zero in your own program to read the buttons instead of having a separate sceCtrlReadBufferPositive.

Learn how to hook functions with syscall patch. Look at iop.prx source.
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

Simply use sceCtrlReadBufferPositive in the main loop it will disable XMB entirely until you switch back to sceCtrlPeekBufferPositive. (I remember when I did this long back... but it should work)
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

void buttons_Set(void)
{
sceCtrlSetButtonMasks(0xFFFF, 1);
sceCtrlSetButtonMasks(0x10000, 2);
return;
}

void buttons_unSet(void)
{
sceCtrlSetButtonMasks(0x10000, 0);
sceCtrlSetButtonMasks(0xFFFF, 0);
return;
}


Set makes it so your proggy has access, unset sets it back.
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

NoEffex wrote:void buttons_Set(void)
{
sceCtrlSetButtonMasks(0xFFFF, 1);
sceCtrlSetButtonMasks(0x10000, 2);
return;
}

void buttons_unSet(void)
{
sceCtrlSetButtonMasks(0x10000, 0);
sceCtrlSetButtonMasks(0xFFFF, 0);
return;
}


Set makes it so your proggy has access, unset sets it back.
well I guess I need to include something like: #include <pspctrl_kernel.h>
but I get error:
main.c:(.text+0x4f8): undefined reference to `sceCtrl_driver_7CA723DC'
Do I need to add something in makefile?
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

Is your prx in user or kernel mode?
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

I guess it is in kernel mode
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

I mean, are you using kernel libs?

ex. in makefile

USE_KERNEL_LIBS=1
USE_KERNEL_LIBC=1

generally indicates kernel prx

I think the button mask is kernel-only, as I use it on several prx's, which are all kernel-mode.
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

no I dont use these because I cant printf after these...
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

pspDebugScreenKprintf

or

#define printf(...) { char buf[256]; sprintf(buf,__VA_ARGS__); pspDebugScreenPuts( buf ); }
Programming with:
Geany + Latest PSPSDK from svn
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

KickinAezz wrote:Simply use sceCtrlReadBufferPositive in the main loop it will disable XMB entirely until you switch back to sceCtrlPeekBufferPositive. (I remember when I did this long back... but it should work)
That doesn't work reliably for everyone. If your loop is not 60 calls per second it will still receive button presses. I use sceCtrlReadBufferPositive in some older plugins and XMB still works.
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

where could I find tutorials or something like that to make prx in XMB menu?
Would be cool to see VSHmenu source code :D
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

Not sure about the opacity but it looks like it uses the basic debug library, consisting of

pspDebugScreenSetXY(w/e, w/e);
pspDebugScreenSetBackColor(Whatever);
pspDebugScreenSetTextColor(Whatever);
pspDebugScreenPuts("M33 Vshmenu");

and so on.
Programming with:
Geany + Latest PSPSDK from svn
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

Torch wrote: Learn how to hook functions with syscall patch. Look at iop.prx source.
where could i find iop.prx source?
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Heres a modified version of the iop.prx that comes with DC, this one can be unloaded.
http://ifile.it/brjox3v/iop_unloadable.zip
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

well I tried my best and that is what I get:

Code: Select all

//...

int vshReadButtons&#40;SceCtrlData *pad_data, int count&#41;
&#123;
  int k1 = pspSdkSetK1&#40;0&#41;;
  int level = sctrlKernelSetUserLevel&#40;8&#41;;

  sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

  sctrlKernelSetUserLevel&#40;level&#41;;
  pspSdkSetK1&#40;k1&#41;;
  return 0;
&#125;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
  PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x826668E9&#41;;
	
  if &#40;!PatchSyscall&#41;
  &#123;
    PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x02BFCB5F&#41;;

    if &#40;!PatchSyscall&#41;
    &#123;
      asm&#40;"break\n"&#41;;
      return 1;
    &#125;
  &#125;

  orgaddr=sctrlHENFindFunction&#40;"vshCtrlReadBufferPositive", "Idontknowwhattowritehere", 0xC6395C03&#41;;
  PatchSyscall&#40;orgaddr, vshReadButtons&#41;;

  sceKernelDcacheWritebackAll&#40;&#41;;
  sceKernelIcacheClearAll&#40;&#41;;

  //...

  return 0;
&#125;

//...
But it doesnt work, could you help?
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Code: Select all

//...

int &#40;* vshCtrlReadBufferPositive&#41;&#40;SceCtrlData *pad_data, int count&#41;;

int vshReadButtons&#40;SceCtrlData *pad_data, int count&#41;
&#123;
  int ret, intc;
  
  ret = vshCtrlReadBufferPositive&#40;pad_data, count&#41;;
  if&#40;ret <= 0&#41;
  &#123;
    return ret;
  &#125;
  
  intc = pspSdkDisableInterrupts&#40;&#41;;

  //your program's button handling goes here. this function will be called automatically by the xmb.
  if &#40;pad_data.Buttons & PSP_CTRL_CIRCLE&#41; //etc
  &#123;
    //do your stuff for the buttons
  &#125;
  
  //zero it after use so xmb will not respond
  pad_data.Buttons = 0;
  
  pspSdkEnableInterrupts&#40;intc&#41;;
  return ret;
&#125;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
  PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x826668E9&#41;;
	
  if &#40;!PatchSyscall&#41;
  &#123;
    PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x02BFCB5F&#41;;

    if &#40;!PatchSyscall&#41;
    &#123;
      asm&#40;"break\n"&#41;;
      return 1;
    &#125;
  &#125;

  orgaddr=sctrlHENFindFunction&#40;"sceVshBridge_Driver", "sceVshBridge", 0xC6395C03&#41;;
  vshCtrlReadBufferPositive = &#40;void *&#41;orgaddr;
  PatchSyscall&#40;orgaddr, vshReadButtons&#41;;

  sceKernelDcacheWritebackAll&#40;&#41;;
  sceKernelIcacheClearAll&#40;&#41;;

  //...

  return 0;
&#125;

//...

This method will not increase CPU usage a lot because there needn't be a main loop to read the controls.

Also this method will not break the M33 VSHMenu. If VSHMenu is opened, your plugin will not receive input until the VSHMenu is closed.
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

well with some changes this code compiles but on psp it still dont work :(
It looks like function havent been patched because XMB still recave buttons ant my functions doesnt get buttons pressed.
It should disable XMB buttons from startup if I add prx to seplugins\vsh.txt and enable it, yes?
what could be wrong? :(
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

You should wait for vshbridge to load before hooking.

Code: Select all

//globals
int OnModuleStart&#40;SceModule2 *mod&#41;;
STMOD_HANDLER previous = NULL;

...
...

int OnModuleStart&#40;SceModule2 *mod&#41;
&#123;
	if &#40;strcmp&#40;mod->modname, "sceVshBridge_Driver"&#41; == 0&#41;
	&#123;
	 orgaddr=sctrlHENFindFunction&#40;"sceVshBridge_Driver", "sceVshBridge", 0xC6395C03&#41;;
	 vshCtrlReadBufferPositive = &#40;void *&#41;orgaddr;
	 PatchSyscall&#40;orgaddr, vshReadButtons&#41;;
	
	 sceKernelDcacheWritebackAll&#40;&#41;;
	 sceKernelIcacheClearAll&#40;&#41;; 
	&#125;
	
	if &#40;!previous&#41;
		return 0;
	
	return previous&#40;mod&#41;;
&#125;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
  PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x826668E9&#41;;
   
  if &#40;!PatchSyscall&#41;
  &#123;
    PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x02BFCB5F&#41;;

    if &#40;!PatchSyscall&#41;
    &#123;
      asm&#40;"break\n"&#41;;
      return 1;
    &#125;
  &#125;

  sceKernelDcacheWritebackAll&#40;&#41;;
  sceKernelIcacheClearAll&#40;&#41;;
  
  previous = sctrlHENSetStartModuleHandler&#40;OnModuleStart&#41;; //add this

  //...

  return 0;
&#125; 
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

well now it disables buttons on start up but my program dont get them but I still trying to make it work.
I guess I need to include something because I get error:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'previous'
on this line:
STMOD_HANDLER previous = NULL;
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

Look at the header...
There's something wrong...
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Its in one of these headers:
#include <pspsdk.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <systemctrl.h>

Extract the latest M33SDK into your includes and libs.
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

I searched but I didnt find M33SDK... What if I will remove that variable?
This is edited code:

Code: Select all

void &#40;* PatchSyscall&#41;&#40;u32 funcaddr, void *newfunc&#41;;
int &#40;* vshCtrlReadBufferPositive&#41;&#40;SceCtrlData *pad_data, int count&#41;;
int OnModuleStart&#40;SceModule2 *mod&#41;; 
u32 orgaddr;
SceCtrlData pad;


int vshReadButtons&#40;SceCtrlData *pad_data, int count&#41; 
&#123; 
  int ret, intc;
  
  ret = vshCtrlReadBufferPositive&#40;pad_data, count&#41;; 
  if&#40;ret <= 0&#41; 
  &#123; 
    return ret; 
  &#125; 
  intc = pspSdkDisableInterrupts&#40;&#41;; 
  pad = *pad_data;

  if &#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
  &#123; 
	//my menu on/off
    if&#40;a == 0&#41;&#123; a = 1; &#125;
	else&#123; a = 0; &#125;
  &#125; 
  //if my menu on block buttons
  if&#40;a == 1&#41;
  &#123;
	  pad.Buttons = 0;
  &#125;
  pad_data = &pad;
  
  pspSdkEnableInterrupts&#40;intc&#41;; 
  return ret; 
&#125;

int OnModuleStart&#40;SceModule2 *mod&#41; 
&#123; 
   if &#40;strcmp&#40;mod->modname, "sceVshBridge_Driver"&#41; == 0&#41; 
   &#123; 
    orgaddr=sctrlHENFindFunction&#40;"sceVshBridge_Driver", "sceVshBridge", 0xC6395C03&#41;; 
    vshCtrlReadBufferPositive = &#40;void *&#41;orgaddr; 
    PatchSyscall&#40;orgaddr, vshReadButtons&#41;; 
    
    sceKernelDcacheWritebackAll&#40;&#41;; 
    sceKernelIcacheClearAll&#40;&#41;; 
   &#125;
&#125; 


int module_start&#40;SceSize args, void *argp&#41; 
&#123; 
  PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x826668E9&#41;;
  if &#40;!PatchSyscall&#41; 
  &#123; 
    PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x02BFCB5F&#41;; 
    if &#40;!PatchSyscall&#41; 
    &#123; 
      asm&#40;"break\n"&#41;; 
      return 1; 
    &#125; 
  &#125; 
  sceKernelDcacheWritebackAll&#40;&#41;; 
  sceKernelIcacheClearAll&#40;&#41;; 

  sctrlHENSetStartModuleHandler&#40;OnModuleStart&#41;;

  //...

  return 0;
&#125;

int module_stop&#40;SceSize args, void *argp&#41;
&#123;
  PatchSyscall&#40;&#40;u32&#41;vshReadButtons, &#40;void *&#41;orgaddr&#41;;
	
  sceKernelDcacheWritebackAll&#40;&#41;;
  sceKernelIcacheClearAll&#40;&#41;;

  return 0;
&#125;
My program compiles. My functions gets buttons pushed but when I need to disable XMB menu buttons they are not disabled :( I guess I am doing something wrong in vshReadButtons function no?
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

You should directly use the value in pad_data. Since its a pointer, referencing it like the first element of an array pad_data[0] will give you the actual value.

You MUST include the previous pointer or it will break other plugins that hook module start, and possibly break M33 patches. The M33SDK comes in the 4.01M33 package.

Code: Select all

STMOD_HANDLER previous = NULL; 

...
...

int OnModuleStart&#40;SceModule2 *mod&#41;
&#123; 
...
...
   if &#40;!previous&#41;
      return 0;
   
   return previous&#40;mod&#41;; 
&#125;

Code: Select all

int vshReadButtons&#40;SceCtrlData *pad_data, int count&#41;
&#123;
  int ret, intc;
 
  ret = vshCtrlReadBufferPositive&#40;pad_data, count&#41;;
  if&#40;ret <= 0&#41;
  &#123;
    return ret;
  &#125;
  intc = pspSdkDisableInterrupts&#40;&#41;;

  if &#40;pad_data&#91;0&#93;.Buttons & PSP_CTRL_CIRCLE&#41;
  &#123;
   //my menu on/off
    if&#40;a == 0&#41;&#123; a = 1; &#125;
   else&#123; a = 0; &#125;
  &#125;
  //if my menu on block buttons
  if&#40;a == 1&#41;
  &#123;
     pad_data&#91;0&#93;.Buttons = 0;
  &#125;
 
  pspSdkEnableInterrupts&#40;intc&#41;;
  return ret;
&#125; 
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

It is working!!! almost :D
now the buttons are disabled in XMB when my menu is on so its good, but the same error with "previous" variable.
Last edited by hotter on Tue Mar 24, 2009 3:29 pm, edited 2 times in total.
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
User avatar
hotter
Posts: 53
Joined: Sun Dec 07, 2008 8:49 pm

Post by hotter »

I added this:

Code: Select all

typedef int &#40;* STMOD_HANDLER&#41;&#40;SceModule2 *&#41;;
and now I guess everything is working good!
Thx for help very much :)
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
SweetNSourOrc
Posts: 1
Joined: Thu Jun 11, 2009 8:31 am

I cant get this code to work

Post by SweetNSourOrc »

Code: Select all


int vshReadButtons&#40;SceCtrlData *pad_data, int count&#41;
&#123;
  int ret, intc;

  ret = vshCtrlReadBufferPositive&#40;pad_data, count&#41;;
  if&#40;ret <= 0&#41;
  &#123;
    return ret;
  &#125;
  intc = pspSdkDisableInterrupts&#40;&#41;;

  pad_data&#91;0&#93;.Buttons = 0; 

  pspSdkEnableInterrupts&#40;intc&#41;;
  return ret;
&#125;

int OnModuleStart&#40;SceModule2 *mod&#41;
&#123;
   if &#40;strcmp&#40;mod->modname, "sceVshBridge_Driver"&#41; == 0&#41;
   &#123;
    orgaddr=sctrlHENFindFunction&#40;"sceVshBridge_Driver", "sceVshBridge", 0xC6395C03&#41;;
    vshCtrlReadBufferPositive = &#40;void *&#41;orgaddr;
    PatchSyscall&#40;orgaddr, vshReadButtons&#41;;

    sceKernelDcacheWritebackAll&#40;&#41;;
    sceKernelIcacheClearAll&#40;&#41;;
   &#125;
   if &#40;!previous&#41;
      return 0;
   
   return previous&#40;mod&#41;; 
&#125;


int module_start&#40;SceSize args, void *argp&#41;
&#123;
  sceCtrlSetButtonMasks&#40;0x001000, 1&#41;; 
  PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x826668E9&#41;;
  if &#40;!PatchSyscall&#41;
  &#123;
    PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x02BFCB5F&#41;;
    if &#40;!PatchSyscall&#41;
    &#123;
      asm&#40;"break\n"&#41;;
      return 1;
    &#125;
  &#125;
  sceKernelDcacheWritebackAll&#40;&#41;;
  sceKernelIcacheClearAll&#40;&#41;;

  sctrlHENSetStartModuleHandler&#40;OnModuleStart&#41;;

  return 0;
&#125;

int module_stop&#40;SceSize args, void *argp&#41;
&#123;
  PatchSyscall&#40;&#40;u32&#41;vshReadButtons, &#40;void *&#41;orgaddr&#41;;

  sceKernelDcacheWritebackAll&#40;&#41;;
  sceKernelIcacheClearAll&#40;&#41;;

  return 0;
&#125;
For some reason, this code still doesnt disable the keys in VSH for me. Can you guys help?
hyeokje
Posts: 3
Joined: Tue Aug 04, 2009 11:01 pm

Re: I cant get this code to work

Post by hyeokje »

Code: Select all

#include <pspsdk.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <systemctrl.h>
#include <string.h>

PSP_MODULE_INFO&#40;"myHold", 0x1000, 1, 1&#41;;
STMOD_HANDLER previous = NULL;

void &#40;* PatchSyscall&#41;&#40;u32 funcaddr, void *newfunc&#41;;
int &#40;* vshCtrlReadBufferPositive&#41;&#40;SceCtrlData *pad_data, int count&#41;;
int OnModuleStart&#40;SceModule2 *mod&#41;;
u32 orgaddr;
SceCtrlData pad;
int a;
unsigned int paddata_old;

int vshReadButtons&#40;SceCtrlData *pad_data, int count&#41;
&#123;
	int ret, intc;

	ret = vshCtrlReadBufferPositive&#40;pad_data, count&#41;;
	if&#40;ret <= 0&#41;
	&#123;
		return ret;
	&#125;
	intc = pspSdkDisableInterrupts&#40;&#41;;

	if&#40;paddata_old != pad_data&#91;0&#93;.Buttons&#41;
	&#123;
		// simultaneously hotkey
		// if&#40; &#40;pad_data&#91;0&#93;.Buttons & PSP_CTRL_VOLUP&#41; && &#40;pad_data&#91;0&#93;.Buttons & PSP_CTRL_VOLDOWN&#41; &#41;
		if&#40;pad_data&#91;0&#93;.Buttons & PSP_CTRL_NOTE&#41;
		&#123;
			if&#40;a == 0&#41; &#123; a = 1; &#125;
			else &#123; a = 0; &#125;
		&#125;
	&#125;
	paddata_old = pad_data&#91;0&#93;.Buttons;

	if&#40;a == 1&#41;
	&#123;
		pad_data&#91;0&#93;.Buttons = 0;
	&#125;

	pspSdkEnableInterrupts&#40;intc&#41;;
	return ret;
&#125;

int OnModuleStart&#40;SceModule2 *mod&#41;
&#123;
	if &#40;strcmp&#40;mod->modname, "sceVshBridge_Driver"&#41; == 0&#41;
	&#123;
		orgaddr=sctrlHENFindFunction&#40;"sceVshBridge_Driver", "sceVshBridge", 0xC6395C03&#41;;
		vshCtrlReadBufferPositive = &#40;void *&#41;orgaddr;
		PatchSyscall&#40;orgaddr, vshReadButtons&#41;;

		sceKernelDcacheWritebackAll&#40;&#41;;
		sceKernelIcacheClearAll&#40;&#41;;
	&#125;
	if &#40;!previous&#41; return 0;

	return previous&#40;mod&#41;;
&#125;


int module_start&#40;SceSize args, void *argp&#41;
&#123;
	PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x826668E9&#41;;
	if &#40;!PatchSyscall&#41;
	&#123;
		PatchSyscall = &#40;void *&#41;sctrlHENFindFunction&#40;"SystemControl", "SystemCtrlForKernel", 0x02BFCB5F&#41;;
		if &#40;!PatchSyscall&#41;
		&#123;
			asm&#40;"break\n"&#41;;
			return 1;
		&#125;
	&#125;
	sceKernelDcacheWritebackAll&#40;&#41;;
	sceKernelIcacheClearAll&#40;&#41;;

	previous = sctrlHENSetStartModuleHandler&#40;OnModuleStart&#41;;

	return 0;
&#125;

int module_stop&#40;SceSize args, void *argp&#41;
&#123;
	PatchSyscall&#40;&#40;u32&#41;vshReadButtons, &#40;void *&#41;orgaddr&#41;;

	sceKernelDcacheWritebackAll&#40;&#41;;
	sceKernelIcacheClearAll&#40;&#41;;

	return 0;
&#125;

Code: Select all

#Makefile
TARGET = myHold
OBJS = myHold.o

BUILD_PRX = 1
PRX_EXPORTS =

USE_KERNEL_LIBC = 1
USE_KERNEL_LIBS = 1

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspkubridge -lpspsystemctrl_user -lpspsystemctrl_kernel

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
This is working, but launching homebrew causes error :(

I edited post, and this code is fully working. Thanks Torch.
Last edited by hyeokje on Sat Aug 08, 2009 2:01 pm, edited 4 times in total.
Post Reply