Fixed accessing the friendlist while using HID to VPAD.

Updated used dynamic libs/controller patcher
This commit is contained in:
Maschell 2017-07-20 16:08:00 +02:00
parent cf54450cfd
commit f7ccd7d58d
8 changed files with 74 additions and 44 deletions

View File

@ -26,6 +26,8 @@ extern "C" {
#define LIB_NN_ACP 11
#define LIB_SYSHID 12
#define LIB_VPADBASE 13
#define LIB_AX_OLD 14
#define LIB_PROC_UI 15
// functions types
#define STATIC_FUNCTION 0

@ -1 +1 @@
Subproject commit 3559a18408126682d25ffe51ff6a43f99119e441
Subproject commit f8aa5558cdb6bf8a50da0cae0c340555994800a4

@ -1 +1 @@
Subproject commit a2f4abdbebedce82e36d10635d25d22038169795
Subproject commit 7a31349744a04df5390145c2ac00315967e4377e

View File

@ -10,6 +10,7 @@
#include "dynamic_libs/vpad_functions.h"
#include "dynamic_libs/socket_functions.h"
#include "dynamic_libs/sys_functions.h"
#include "dynamic_libs/proc_ui_functions.h"
#include "utils/logger.h"
#include "utils/utils.h"
@ -35,12 +36,17 @@
/* Entry point */
extern "C" s32 Menu_Main(void){
if(gAppStatus == 2){
//"No, we don't want to patch stuff again.");
return EXIT_RELAUNCH_ON_LOAD;
}
//!*******************************************************************
//! Initialize function pointers *
//!*******************************************************************
//! do OS (for acquire) and sockets first so we got logging
InitOSFunctionPointers();
InitVPadFunctionPointers();
InitProcUIFunctionPointers();
if(OSGetTitleID() == 0x00050000101a5f00L || // Shantae and the Pirate's Curse USA (reason: crashes when pressing HOME, Pro Controller not recognized)
OSGetTitleID() == 0x00050000101F7F00L || // Shantae and the Pirate's Curse JAP (シャンティ -海賊の呪い-) (reason: crashes when pressing HOME, Pro Controller not recognized)

View File

@ -242,6 +242,16 @@ DECL(void,WPADControlMotor,s32 chan, u32 status ){
real_WPADControlMotor(chan,status);
}
DECL(u32, ProcUIProcessMessages, u32 u){
u32 res = real_ProcUIProcessMessages(u);
if(res != gAppStatus){
log_printf("App status changed from %d to %d \n",gAppStatus,res);
gAppStatus = res;
}
return res;
}
hooks_magic_t method_hooks_hid_controller[] __attribute__((section(".data"))) = {
MAKE_MAGIC(VPADRead, LIB_VPAD, STATIC_FUNCTION),
MAKE_MAGIC(GX2CopyColorBufferToScanBuffer, LIB_GX2, STATIC_FUNCTION),
@ -255,6 +265,7 @@ hooks_magic_t method_hooks_hid_controller[] __attribute__((section(".data"))) =
MAKE_MAGIC(WPADSetDataFormat, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADControlMotor, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADProbe, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(ProcUIProcessMessages, LIB_PROC_UI, DYNAMIC_FUNCTION),
};
u32 method_hooks_size_hid_controller __attribute__((section(".data"))) = sizeof(method_hooks_hid_controller) / sizeof(hooks_magic_t);

View File

@ -74,7 +74,7 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
continue;
}
if(DEBUG_LOG_DYN){ log_printf("%s is located at %08X!\n", method_hooks[i].functionName,real_addr); }
if(DEBUG_LOG_DYN){log_printf("%s is located at %08X!\n", method_hooks[i].functionName,real_addr);}
physical = (u32)OSEffectiveToPhysical((void*)real_addr);
if(!physical){
@ -83,7 +83,7 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
continue;
}
if(DEBUG_LOG_DYN){ log_printf("%s physical is located at %08X!\n", method_hooks[i].functionName,physical); }
if(DEBUG_LOG_DYN){log_printf("%s physical is located at %08X!\n", method_hooks[i].functionName,physical);}
*(volatile u32 *)(call_addr) = (u32)(space) - CODE_RW_BASE_OFFSET;
@ -96,8 +96,8 @@ void PatchInvidualMethodHooks(hooks_magic_t method_hooks[],s32 hook_information_
// fill the restore instruction section
method_hooks[i].realAddr = real_addr;
method_hooks[i].restoreInstruction = *(space-1);
if(DEBUG_LOG_DYN){ log_printf("method_hooks[i].realAddr = %08X!\n", method_hooks[i].realAddr); }
if(DEBUG_LOG_DYN){ log_printf("method_hooks[i].restoreInstruction = %08X!\n",method_hooks[i].restoreInstruction) ; }
if(DEBUG_LOG_DYN){log_printf("method_hooks[i].realAddr = %08X!\n", method_hooks[i].realAddr);}
if(DEBUG_LOG_DYN){log_printf("method_hooks[i].restoreInstruction = %08X!\n",method_hooks[i].restoreInstruction) ;}
}
else{
log_printf("Error. Can't save %s for restoring!\n", method_hooks[i].functionName);
@ -175,14 +175,15 @@ void RestoreInvidualInstructions(hooks_magic_t method_hooks[],s32 hook_informati
else
{
physical = (u32)OSEffectiveToPhysical((void*)method_hooks[i].realAddr); //When its an static function, we need to use the old location
if(DEBUG_LOG_DYN){ log_printf("Restoring %08X to %08X\n",(u32)method_hooks[i].restoreInstruction,physical); }
if(DEBUG_LOG_DYN){log_printf("Restoring %08X to %08X\n",(u32)method_hooks[i].restoreInstruction,physical);}
SC0x25_KernelCopyData(physical,(u32)&method_hooks[i].restoreInstruction , 4);
if(DEBUG_LOG_DYN){ log_printf("ICInvalidateRange %08X\n",(void*)method_hooks[i].realAddr); }
if(DEBUG_LOG_DYN){log_printf("ICInvalidateRange %08X\n",(void*)method_hooks[i].realAddr);}
ICInvalidateRange((void*)method_hooks[i].realAddr, 4);
log_printf("done\n");
}
method_hooks[i].alreadyPatched = 0; // In case a
}
log_print("Done with restoring given functions!\n");
}
@ -219,75 +220,86 @@ u32 GetAddressOfFunction(const char * functionName,u32 library){
u32 rpl_handle = 0;
if(library == LIB_CORE_INIT){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_CORE_INIT\n", functionName); }
if(coreinit_handle == 0){log_print("LIB_CORE_INIT not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_CORE_INIT\n", functionName);}
if(coreinit_handle == 0){log_print("LIB_CORE_INIT not acquired\n"); return 0;}
rpl_handle = coreinit_handle;
}
else if(library == LIB_NSYSNET){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_NSYSNET\n", functionName); }
if(nsysnet_handle == 0){log_print("LIB_NSYSNET not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_NSYSNET\n", functionName);}
if(nsysnet_handle == 0){log_print("LIB_NSYSNET not acquired\n"); return 0;}
rpl_handle = nsysnet_handle;
}
else if(library == LIB_GX2){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_GX2\n", functionName); }
if(gx2_handle == 0){log_print("LIB_GX2 not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_GX2\n", functionName);}
if(gx2_handle == 0){log_print("LIB_GX2 not acquired\n"); return 0;}
rpl_handle = gx2_handle;
}
else if(library == LIB_AOC){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_AOC\n", functionName); }
if(aoc_handle == 0){log_print("LIB_AOC not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_AOC\n", functionName);}
if(aoc_handle == 0){log_print("LIB_AOC not acquired\n"); return 0;}
rpl_handle = aoc_handle;
}
else if(library == LIB_AX){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_AX\n", functionName); }
if(sound_handle == 0){log_print("LIB_AX not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_AX\n", functionName);}
if(sound_handle == 0){log_print("LIB_AX not acquired\n"); return 0;}
rpl_handle = sound_handle;
}
else if(library == LIB_AX_OLD){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_AX_OLD\n", functionName);}
if(sound_handle_old == 0){log_print("LIB_AX_OLD not acquired\n"); return 0;}
rpl_handle = sound_handle_old;
}
else if(library == LIB_FS){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_FS\n", functionName); }
if(coreinit_handle == 0){log_print("LIB_FS not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_FS\n", functionName);}
if(coreinit_handle == 0){log_print("LIB_FS not acquired\n"); return 0;}
rpl_handle = coreinit_handle;
}
else if(library == LIB_OS){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_OS\n", functionName); }
if(coreinit_handle == 0){log_print("LIB_OS not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_OS\n", functionName);}
if(coreinit_handle == 0){log_print("LIB_OS not acquired\n"); return 0;}
rpl_handle = coreinit_handle;
}
else if(library == LIB_PADSCORE){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_PADSCORE\n", functionName); }
if(padscore_handle == 0){log_print("LIB_PADSCORE not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_PADSCORE\n", functionName);}
if(padscore_handle == 0){log_print("LIB_PADSCORE not acquired\n"); return 0;}
rpl_handle = padscore_handle;
}
else if(library == LIB_SOCKET){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_SOCKET\n", functionName); }
if(nsysnet_handle == 0){log_print("LIB_SOCKET not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_SOCKET\n", functionName);}
if(nsysnet_handle == 0){log_print("LIB_SOCKET not acquired\n"); return 0;}
rpl_handle = nsysnet_handle;
}
else if(library == LIB_SYS){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_SYS\n", functionName); }
if(sysapp_handle == 0){log_print("LIB_SYS not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_SYS\n", functionName);}
if(sysapp_handle == 0){log_print("LIB_SYS not acquired\n"); return 0;}
rpl_handle = sysapp_handle;
}
else if(library == LIB_VPAD){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_VPAD\n", functionName); }
if(vpad_handle == 0){log_print("LIB_VPAD not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_VPAD\n", functionName);}
if(vpad_handle == 0){log_print("LIB_VPAD not acquired\n"); return 0;}
rpl_handle = vpad_handle;
}
else if(library == LIB_NN_ACP){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_NN_ACP\n", functionName); }
if(acp_handle == 0){log_print("LIB_NN_ACP not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_NN_ACP\n", functionName);}
if(acp_handle == 0){log_print("LIB_NN_ACP not acquired\n"); return 0;}
rpl_handle = acp_handle;
}
else if(library == LIB_SYSHID){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_SYSHID\n", functionName); }
if(syshid_handle == 0){log_print("LIB_SYSHID not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_SYSHID\n", functionName);}
if(syshid_handle == 0){log_print("LIB_SYSHID not acquired\n"); return 0;}
rpl_handle = syshid_handle;
}
else if(library == LIB_VPADBASE){
if(DEBUG_LOG_DYN){ log_printf("FindExport of %s! From LIB_VPADBASE\n", functionName); }
if(vpadbase_handle == 0){log_print("LIB_VPADBASE not aquired\n"); return 0;}
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_VPADBASE\n", functionName);}
if(vpadbase_handle == 0){log_print("LIB_VPADBASE not acquired\n"); return 0;}
rpl_handle = vpadbase_handle;
}
else if(library == LIB_PROC_UI){
if(DEBUG_LOG_DYN){log_printf("FindExport of %s! From LIB_PROC_UI\n", functionName);}
if(proc_ui_handle == 0){log_print("LIB_PROC_UI not acquired\n"); return 0;}
rpl_handle = proc_ui_handle;
}
if(!rpl_handle){
log_printf("Failed to find the RPL handle for %s\n", functionName);
@ -301,20 +313,17 @@ u32 GetAddressOfFunction(const char * functionName,u32 library){
return 0;
}
if((u32)(*(volatile u32*)(real_addr) & 0x48000002) == 0x48000000)
if((library == LIB_NN_ACP) && (u32)(*(volatile u32*)(real_addr) & 0x48000002) == 0x48000000)
{
u32 address_diff = (u32)(*(volatile u32*)(real_addr) & 0x03FFFFFC);
if((address_diff & 0x03000000) == 0x03000000) {
address_diff |= 0xFC000000;
}
real_addr += (int)address_diff;
real_addr += (s32)address_diff;
if((u32)(*(volatile u32*)(real_addr) & 0x48000002) == 0x48000000){
return 0;
}
}
return real_addr;
}

View File

@ -37,6 +37,7 @@ extern "C" {
#include "dynamic_libs/vpad_functions.h"
#include "dynamic_libs/acp_functions.h"
#include "dynamic_libs/syshid_functions.h"
#include "dynamic_libs/proc_ui_functions.h"
//Orignal code by Chadderz.
#define DECL(res, name, ...) \
@ -52,8 +53,8 @@ typedef struct {
const char functionName[50];
u32 realAddr;
u32 restoreInstruction;
unsigned char functionType;
unsigned char alreadyPatched;
u8 functionType;
u8 alreadyPatched;
} hooks_magic_t;
void PatchInvidualMethodHooks(hooks_magic_t hook_information[],s32 hook_information_size, volatile u32 dynamic_method_calls[]);
@ -63,6 +64,7 @@ s32 isDynamicFunction(u32 physicalAddress);
//Orignal code by Chadderz.
#define MAKE_MAGIC(x, lib,functionType) { (u32) my_ ## x, (u32) &real_ ## x, lib, # x,0,0,functionType,0}
#define MAKE_MAGIC_NAME(x,y, lib,functionType) { (u32) my_ ## x, (u32) &real_ ## x, lib, # y,0,0,functionType,0}
#ifdef __cplusplus
}

View File

@ -5,7 +5,7 @@
extern "C" {
#endif
//#define DEBUG_LOGGER 1
#define DEBUG_LOGGER 1
#ifdef DEBUG_LOGGER
void log_init(const char * ip);