Source

Open PS2 Loader / loader / padhook.c

Full commit
  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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/*
  padhook.c Open PS2 Loader In Game Reset
 
  Copyright 2009-2010, Ifcaro, jimmikaelkael & Polo
  Copyright 2006-2008 Polo
  Licenced under Academic Free License version 3.0
  Review OpenUsbLd README & LICENSE files for further details.

  Reset SPU function taken from PS2SDK freesd.
  Copyright (c) 2004 TyRaNiD <tiraniddo@hotmail.com>
  Copyright (c) 2004,2007 Lukasz Bruun <mail@lukasz.dk>

  PadOpen Hooking function inspired from ps2rd.
  Hook scePadPortOpen/scePad2CreateSocket instead of scePadRead/scePad2Read
  Copyright (C) 2009 jimmikaelkael <jimmikaelkael@wanadoo.fr>
  Copyright (C) 2009 misfire <misfire@xploderfreax.de>
*/

#include "loader.h"
#include "padhook.h"

/* scePadPortOpen & scePad2CreateSocket prototypes */
static int (*scePadPortOpen)( int port, int slot, void *addr );
static int (*scePad2CreateSocket)( pad2socketparam_t *SocketParam, void *addr );

/* Monitored pad data */
static paddata_t Pad_Data;

/* Monitored power button data */
static powerbuttondata_t Power_Button;

/* IGR Thread ID */
static int IGR_Thread_ID = -1;

/* IGR thread stack & stack size */
#define IGR_STACK_SIZE (16 * 512)
static u8 IGR_Stack[IGR_STACK_SIZE] __attribute__ ((aligned(16)));

/* Extern symbol */
extern void *_gp;

// Reset SPU sound processor
static void ResetSPU()
{
	u32 core;
	volatile u16 *statx;

	DIntr();
	ee_kmode_enter();

	// Stop SPU Dma Core 0
	*SD_DMA_CHCR(0) &= ~SD_DMA_START;
	*U16_REGISTER(0x1B0) = 0;

	// Stop SPU Dma Core 1
	*SD_DMA_CHCR(1) &= ~SD_DMA_START;
	*U16_REGISTER(0x1B0 +  1024) = 0;

	// Initialize SPU2
	*U32_REGISTER(0x1404)  = 0xBF900000;
	*U32_REGISTER(0x140C)  = 0xBF900800;
	*U32_REGISTER(0x10F0) |= 0x80000;
	*U32_REGISTER(0x1570) |= 8;
	*U32_REGISTER(0x1014)  = 0x200B31E1;
	*U32_REGISTER(0x1414)  = 0x200B31E1;

	*SD_C_SPDIF_OUT = 0;
	delay(1);
	*SD_C_SPDIF_OUT = 0x8000;
	delay(1);

	*U32_REGISTER(0x10F0) |= 0xB0000;

	for(core=0; core < 2; core++)
	{
		*U16_REGISTER(0x1B0)	= 0;
		*SD_CORE_ATTR(core)		= 0;
		delay(1);
		*SD_CORE_ATTR(core)		= SD_SPU2_ON;

		*SD_P_MVOLL(core)		= 0;
		*SD_P_MVOLR(core)		= 0;
		
		statx = U16_REGISTER(0x344 + (core * 1024));

		while(*statx & 0x7FF);
		
		*SD_A_KOFF_HI(core)		= 0xFFFF;
		*SD_A_KOFF_LO(core)		= 0xFFFF; // Should probably only be 0xFF
	}

	*SD_S_PMON_HI(1)	= 0;
	*SD_S_PMON_LO(1)	= 0;
	*SD_S_NON_HI(1)		= 0;
	*SD_S_NON_LO(1)		= 0;

	ee_kmode_exit();
	EIntr();
}

// Shutdown Dev9 hardware
static void Shutdown_Dev9()
{
	u16 dev9_hw_type;
	
	DIntr();
	ee_kmode_enter();

	// Get dev9 hardware type
	dev9_hw_type = *DEV9_R_146E & 0xf0;
	
	// Shutdown Pcmcia
	if ( dev9_hw_type == 0x20 )
	{
		*DEV9_R_146C = 0;
		*DEV9_R_1474 = 0;
	}
	// Shutdown Expansion Bay
	else if ( dev9_hw_type == 0x30 )
	{
		*DEV9_R_1466 = 1;
		*DEV9_R_1464 = 0;
		*DEV9_R_1460 = *DEV9_R_1464;
		*DEV9_R_146C = *DEV9_R_146C & ~4;
		*DEV9_R_1460 = *DEV9_R_146C & ~1;
	}

	//Wait a sec
	delay(5);
	
	ee_kmode_exit();
	EIntr();
}

// Return to PS2 Browser
static void Go_Browser(void)
{
	// Shutdown Dev9 hardware
	Shutdown_Dev9();
	
	// FlushCache before exiting
	FlushCache(0);
	FlushCache(2);
		
	// Exit to PS2Browser
	__asm__ __volatile__(
		"	li $3, 0x04;"
		"	syscall;"
		"	nop;"
	);
}

// Load home ELF
static void t_loadElf(void)
{
	int ret;
	char *argv[2];
	t_ExecData elf;

	if(!DisableDebug)
		GS_BGCOLOUR = 0x80FF00; // Blue Green

	// Init RPC & CMD
	SifInitRpc(0);

	if(!DisableDebug)
		GS_BGCOLOUR = 0x000080; // Dark Red

	// Reset IO Processor
	while (!Reset_Iop("rom0:UDNL rom0:EELOADCNF", 0)) {;}
	while (!Sync_Iop()){;}

	if(!DisableDebug)
		GS_BGCOLOUR = 0xFF80FF; // Pink

	// Init RPC & CMD
	SifInitRpc(0);

	// Apply Sbv patches
	Sbv_Patch();
	
	if(!DisableDebug)
		GS_BGCOLOUR = 0xFF8000; // Blue sky

	// Load basic modules
	LoadModule("rom0:SIO2MAN", 0, NULL);
	LoadModule("rom0:MCMAN", 0, NULL);

	// Load BOOT.ELF
	if ( ExitMode == BOOT_MODE)
		argv[0] = "mc0:/BOOT/BOOT.ELF";
	else if ( ExitMode == APPS_MODE)
		argv[0] = "mc0:/APPS/BOOT.ELF";

	argv[1] = NULL;

	ret = LoadElf(argv[0], &elf);
	
	if (!ret && elf.epc) {

		// Exit services
		fioExit();
		LoadFileExit();
		SifExitIopHeap();
		SifExitRpc();

		FlushCache(0);
		FlushCache(2);

		if(!DisableDebug)
			GS_BGCOLOUR = 0x0080FF; // Orange

		// Execute BOOT.ELF
		ExecPS2((void*)elf.epc, (void*)elf.gp, 1, argv);
	}

	if(!DisableDebug)
	{
		GS_BGCOLOUR = 0x0000FF; // Red
		delay(5);
	}

	// Return to PS2 Browser
	Go_Browser();
}

// Poweroff PlayStation 2
static void PowerOff_PS2(void)
{
	// Shutdown Dev9 hardware
	Shutdown_Dev9();

	DIntr();
	ee_kmode_enter();

	// PowerOff PS2
	*CDVD_R_SDIN = 0x00;
	*CDVD_R_SCMD = 0x0F;

	ee_kmode_exit();
	EIntr();
}

// In Game Reset Thread
static void IGR_Thread(void *arg)
{
	u32 Cop0_Index, Cop0_Perf;

	// Place our IGR thread in WAIT state
	// It will be woken up by our IGR interrupt handler
	SleepThread();
	
	// If Pad Combo is Start + Select then Return to Home
	if(Pad_Data.combo_type == IGR_COMBO_START_SELECT)
	{
		if(!DisableDebug)
			GS_BGCOLOUR = 0xFFFFFF; // White

		// Re-Init RPC & CMD
		SifExitRpc();
		SifInitRpc(0);

		if(!DisableDebug)
			GS_BGCOLOUR = 0x800000; // Dark Blue

		// Remove kernel hook
		Remove_Kernel_Hooks();

		if(!DisableDebug)
			GS_BGCOLOUR = 0x008000; // Dark Green

		// Reset Data Decompression Vector Unit 0 & 1
		ResetEE(0x04);

		if(!DisableDebug)
			GS_BGCOLOUR = 0x800080; // Purple

		// Reset SPU Sound processor
		ResetSPU();

		if(!DisableDebug)
			GS_BGCOLOUR = 0x0000FF; // Red

		// Check Translation Look-Aside Buffer
		// Some game (GT4, GTA) modify memory map
		// A re-init is needed to properly access memory
		Cop0_Index = GetCop0(0);

		// Init TLB
		if(Cop0_Index != 0x26)
		{
			__asm__ __volatile__(
				"	li $3, 0x82;"
				"	syscall;"
				"	nop;"
			);
		}

		// Check Performance Counter
		// Some game (GT4) start performance counter
		// When counter overflow, an exception occur, so stop them
		Cop0_Perf = GetCop0(25);

		// Stop Performance Counter
		if(Cop0_Perf & 0x80000000)
		{
			__asm__ __volatile__(
				" mfc0 $3, $25;"
				" lui	 $2, 0x8000;"
				" or	 $3, $3, $2;"
				" xor	 $3, $3, $2;"
				" mtc0 $3, $25;"
				" sync.p;"
			);
		}

		if(!DisableDebug)
			GS_BGCOLOUR = 0x00FFFF; // Yellow

		// Exit services
		fioExit();
		LoadFileExit();
		SifExitIopHeap();
		SifExitRpc();

		FlushCache(0);
		FlushCache(2);

		// Execute home loader
		if ( ExitMode != OSDS_MODE)
			ExecPS2(t_loadElf, &_gp, 0, NULL);

		// Return to PS2 Browser
		Go_Browser();
	}

	// If combo is R3 + L3 or Reset failed, Poweroff PS2
	PowerOff_PS2();
}

// IGR VBLANK_END interrupt handler install to monitor combo trick in pad data aera
static int IGR_Intc_Handler(int cause)
{
	int i;

	// Write back the D-cache contents to update Pad Buffer
	iSyncDCache(Pad_Data.pad_buf, Pad_Data.pad_buf + 256);
	
	// First check pad state
	if ( ( (Pad_Data.libpad == IGR_LIBPAD_V1) && (Pad_Data.pad_buf[Pad_Data.pos_state] == IGR_PAD_STABLE_V1) ) ||
			 ( (Pad_Data.libpad == IGR_LIBPAD_V2) && (Pad_Data.pad_buf[Pad_Data.pos_state] == IGR_PAD_STABLE_V2) ) )
	{
		// Check if pad buffer is still alive with pad data frame counter
		// If pad frame change save it, otherwise tell to syshook to re-install padOpen hook
		if( Pad_Data.vb_count++ >= 10)
		{
			if(Pad_Data.pad_buf[Pad_Data.pos_frame] != Pad_Data.prev_frame)
			{
				padOpen_hooked = 1;
				Pad_Data.prev_frame = Pad_Data.pad_buf[Pad_Data.pos_frame];
			}
			else
			{
				padOpen_hooked = 0;
			}
			Pad_Data.vb_count = 0;
		}

		// Combo R1 + L1 + R2 + L2
		if ( Pad_Data.pad_buf[Pad_Data.pos_combo1] == IGR_COMBO_R1_L1_R2_L2 )
		{
			// Combo Start + Select OR R3 + L3
			if ( ( Pad_Data.pad_buf[Pad_Data.pos_combo2] == IGR_COMBO_START_SELECT ) || // Start + Select combo, so reset
				   ( Pad_Data.pad_buf[Pad_Data.pos_combo2] == IGR_COMBO_R3_L3 ) )         // R3 + L3 combo, so poweroff
				Pad_Data.combo_type = Pad_Data.pad_buf[Pad_Data.pos_combo2];
		}
	}

	ee_kmode_enter();
	
	// Check power button press
	if ( (*CDVD_R_NDIN & 0x20) && (*CDVD_R_POFF & 0x04) )
	{
		// Increment button press counter
		Power_Button.press++;

		// Cancel poweroff to catch the second button press
		*CDVD_R_SDIN = 0x00;
		*CDVD_R_SCMD = 0x1B;
	}

	// Start VBlank counter when power button is pressed
	if( Power_Button.press )
	{
		// Check number of power button press after 1 ~ sec
		if( Power_Button.vb_count++ >= 50 )
		{
			if( Power_Button.press == 1 )
				Pad_Data.combo_type = IGR_COMBO_R3_L3; // power button press 1 time, so poweroff
			else
				Pad_Data.combo_type = IGR_COMBO_START_SELECT; // power button press 2 time, so reset
		}
	}

	ee_kmode_exit();

	// If power button or combo is press
	// Disable all interrupts (not SBUS, TIMER2, TIMER3 use by kernel)
	// Suspend and Change priority of all threads other then our IGR thread
	// Wakeup and Change priority of our IGR thread
	if ( Pad_Data.combo_type != 0x00 )
	{
		// Disable Interrupts
		iDisableIntc(kINTC_GS          );
		iDisableIntc(kINTC_VBLANK_START); 
		iDisableIntc(kINTC_VBLANK_END  );
		iDisableIntc(kINTC_VIF0        );
		iDisableIntc(kINTC_VIF1        );
		iDisableIntc(kINTC_VU0         );
		iDisableIntc(kINTC_VU1         );
		iDisableIntc(kINTC_IPU         );
		iDisableIntc(kINTC_TIMER0      );
		iDisableIntc(kINTC_TIMER1      );

		// Loop for each threads
		for(i = 3; i < 256; i++)
		{
			if(i == IGR_Thread_ID )
			{
				// WakeUp IGR thread
				iWakeupThread(IGR_Thread_ID);
				iChangeThreadPriority( i, 0 );
			}
			else
			{
				// Suspend all threads
				iSuspendThread( i );
				iChangeThreadPriority( i, 127 );
			}
		}
	}

	// Exit handler
	__asm__ __volatile__(
		" sync.l;"
		" ei;"
	);

	return 0;
}

// Install IGR thread, and Pad interrupt handler
static void Install_IGR(void *addr, int libpad)
{
	ee_thread_t thread_param;

	// Reset power button data
	Power_Button.press    = 0;
	Power_Button.vb_count = 0;

	// Init Pad_Data informations
	Pad_Data.vb_count      = 0;
	Pad_Data.libpad        = libpad;
	Pad_Data.pad_buf       = addr;
	Pad_Data.combo_type    = 0x00;
	Pad_Data.prev_frame    = 0x00;

	// Set positions of pad data and pad state in buffer
	if(libpad == IGR_LIBPAD_V1)
	{
		Pad_Data.pos_combo1 = 3;
		Pad_Data.pos_combo2 = 2;
		Pad_Data.pos_state  = 112;
		Pad_Data.pos_frame  = 88;
	}
	else
	{
		Pad_Data.pos_combo1 = 29;
		Pad_Data.pos_combo2 = 28;
		Pad_Data.pos_state  = 4;
		Pad_Data.pos_frame  = 124;
	}

	// Create and start IGR thread
	thread_param.gp_reg           = &_gp;
	thread_param.func             = IGR_Thread;
	thread_param.stack            = (void*)IGR_Stack;
	thread_param.stack_size       = IGR_STACK_SIZE;
	thread_param.initial_priority = 127;
	IGR_Thread_ID                 = CreateThread(&thread_param);

	StartThread(IGR_Thread_ID, NULL);

	// Create IGR interrupt handler
	AddIntcHandler(kINTC_VBLANK_END, IGR_Intc_Handler, 0);
	EnableIntc(kINTC_VBLANK_END);
}

// Hook function for libpad scePadPortOpen
static int Hook_scePadPortOpen( int port, int slot, void* addr )
{
	int ret;
	
	// Make sure scePadPortOpen function is still available
	if(port == 0 && slot == 0)
		Install_PadOpen_Hook(0x00100000, 0x01ff0000, PADOPEN_CHECK);

	// Call original scePadPortOpen function
	ret = scePadPortOpen(port, slot, addr);

	// Install IGR with libpad1 parameters
	if(port == 0 && slot == 0)
		Install_IGR(addr, IGR_LIBPAD_V1);

	return ret;
}

// Hook function for libpad2 scePad2CreateSocket
static int Hook_scePad2CreateSocket( pad2socketparam_t *SocketParam, void *addr )
{
	int ret;

	// Make sure scePad2CreateSocket function is still available
	if(SocketParam->port == 0 && SocketParam->slot == 0)
		Install_PadOpen_Hook(0x00100000, 0x01ff0000, PADOPEN_CHECK);

	// Call original scePad2CreateSocket function
	ret = scePad2CreateSocket( SocketParam, addr );

	// Install IGR with libpad2 parameters
	if(SocketParam->port == 0 && SocketParam->slot == 0)
		Install_IGR(addr, IGR_LIBPAD_V2);

	return ret;
}

// This function patch the padOpen calls. (scePadPortOpen or scePad2CreateSocket)
int Install_PadOpen_Hook(u32 mem_start, u32 mem_end, int mode)
{
	u32 *ptr, *ptr2;
	u32 inst, fncall;
	u32 mem_size, mem_size2;
	u32 pattern[1], mask[1];
	int i, found, patched;

	pattern_t padopen_patterns[NB_PADOPEN_PATTERN] = {
		{ padPortOpenpattern0     , padPortOpenpattern0_mask     , sizeof(padPortOpenpattern0)     , 1 },
		{ pad2CreateSocketpattern0, pad2CreateSocketpattern0_mask, sizeof(pad2CreateSocketpattern0), 2 },
		{ pad2CreateSocketpattern1, pad2CreateSocketpattern1_mask, sizeof(pad2CreateSocketpattern1), 2 },
		{ pad2CreateSocketpattern2, pad2CreateSocketpattern2_mask, sizeof(pad2CreateSocketpattern2), 2 },
		{ padPortOpenpattern1     , padPortOpenpattern1_mask     , sizeof(padPortOpenpattern1)     , 1 },
		{ padPortOpenpattern2     , padPortOpenpattern2_mask     , sizeof(padPortOpenpattern2)     , 1 },
		{ padPortOpenpattern3     , padPortOpenpattern3_mask     , sizeof(padPortOpenpattern3)     , 1 }
	};

	found   = 0;
	patched = 0;

	// Loop for each libpad version
	for(i = 0; i < NB_PADOPEN_PATTERN; i++)
	{
		ptr = (u32 *)mem_start;
		while (ptr)
		{
			// Purple while PadOpen pattern search
			if(!DisableDebug)
				GS_BGCOLOUR = 0x800080;

			mem_size = mem_end - (u32)ptr;

			// First try to locate the orginal libpad's PadOpen function
			ptr = find_pattern_with_mask(ptr, mem_size, padopen_patterns[i].pattern, padopen_patterns[i].mask, padopen_patterns[i].size);
			if (ptr)
			{				
				found = 1;
				
				// Green while PadOpen patches
				if(!DisableDebug)
				 	GS_BGCOLOUR = 0x008000;

				// Save original PadOpen function
				if (padopen_patterns[i].version == IGR_LIBPAD_V1)
					scePadPortOpen = (void *)ptr;
				else
					scePad2CreateSocket = (void *)ptr;

				if(mode == PADOPEN_HOOK)
				{
					// Retrieve PadOpen call Instruction code
					inst = 0x00000000;
					inst |= 0x03ffffff & ((u32)ptr >> 2);

					// Make pattern with function call code saved above
					// Ignore bits 24-27 because Jump type can be J(8) or JAL(C)
					pattern[0] = inst;
					mask[0] = 0xf0ffffff;

					// Search & patch for calls to PadOpen
					ptr2 = (u32 *)0x00100000;
					while (ptr2)
					{
						mem_size2 = 0x01ff0000 - (u32)ptr2;

						ptr2 = find_pattern_with_mask(ptr2, mem_size2, pattern, mask, sizeof(pattern));
						if (ptr2)
						{
							patched = 1;

							fncall = (u32)ptr2;

							// Get PadOpen call Jump Instruction type. (JAL or J)
							inst = (ptr2[0] & 0x0f000000);

							// Get Hook_PadOpen call Instruction code
							if (padopen_patterns[i].version == IGR_LIBPAD_V1)
								inst |= 0x03ffffff & ((u32)Hook_scePadPortOpen >> 2);
							else
								inst |= 0x03ffffff & ((u32)Hook_scePad2CreateSocket >> 2);

							// Overwrite the original PadOpen function call with our function call
							_sw(inst, fncall);
						}
					}

					if(!patched)
					{
						// Make pattern with function address saved above
						pattern[0] = (u32)ptr;
						mask[0] = 0xffffffff;

						// Search & patch for PadOpen function address
						ptr2 = (u32 *)0x00100000;
						while (ptr2)
						{
							mem_size2 = 0x01ff0000 - (u32)ptr2;

							ptr2 = find_pattern_with_mask(ptr2, mem_size2, pattern, mask, sizeof(pattern));
							if (ptr2)
							{
								patched = 1;

								fncall = (u32)ptr2;

								// Get Hook_PadOpen function address
								if (padopen_patterns[i].version == IGR_LIBPAD_V1)
									inst = (u32)Hook_scePadPortOpen;
								else
									inst = (u32)Hook_scePad2CreateSocket;

								// Overwrite the original PadOpen function address with our function address
								_sw(inst, fncall);
							}
						}
					}
				}else
					// Hooking is not required and padOpen function was found, so stop searching
					break;

				// Increment search pointer
				ptr += padopen_patterns[i].size;
			}
		}

		// If a padOpen function call was patched or ( hooking is not required and a padOpen function was found ), so stop the libpad version search loop
		if( patched == 1 || (mode == PADOPEN_CHECK && found == 1) )
			break;
	}

	// Black, done
	if(!DisableDebug)
		GS_BGCOLOUR = 0x000000;

	return patched;
}