Skip to content

Commit

Permalink
Splitted the function patcher into mutiple files and..
Browse files Browse the repository at this point in the history
changed the logging to UDP logging.
- updated to newest controller patcher (improves deadzone handling)
  • Loading branch information
Maschell committed Aug 9, 2016
1 parent 69fa0c0 commit 16c5045
Show file tree
Hide file tree
Showing 27 changed files with 2,317 additions and 2,035 deletions.
1 change: 0 additions & 1 deletion src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ extern "C" {
#define LIB_NN_ACP 11
#define LIB_SYSHID 12
#define LIB_VPADBASE 13
#define LIB_NN_AOC 14

// functions types
#define STATIC_FUNCTION 0
Expand Down
2 changes: 2 additions & 0 deletions src/common/retain_vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ u8 gPatchSDKDone __attribute__((section(".data"))) = 0;
u8 gHIDPADEnabled __attribute__((section(".data"))) = 0;
u8 gEnableDLC __attribute__((section(".data"))) = 0;
u32 gLoaderPhysicalBufferAddr __attribute__((section(".data"))) = 0;
u32 gLogUDP __attribute__((section(".data"))) = 0;
char gServerIP[16] __attribute__((section(".data")));
2 changes: 2 additions & 0 deletions src/common/retain_vars.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef RETAINS_VARS_H_
#define RETAINS_VARS_H_
#include <gctypes.h>

extern u8 gSettingLaunchPyGecko;
extern u8 gSettingUseUpdatepath;
Expand All @@ -9,5 +10,6 @@ extern u8 gPatchSDKDone;
extern u8 gHIDPADEnabled;
extern u8 gEnableDLC;
extern u32 gLoaderPhysicalBufferAddr;
extern char gServerIP[16];

#endif // RETAINS_VARS_H_
2 changes: 1 addition & 1 deletion src/controller_patcher
9 changes: 6 additions & 3 deletions src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "dynamic_libs/aoc_functions.h"
#include "dynamic_libs/gx2_functions.h"
#include "dynamic_libs/syshid_functions.h"
#include "patcher/function_hooks.h"
#include "utils/function_patcher.h"
#include "patcher/cpp_to_c_util.h"
#include "controller_patcher/controller_patcher.h"
#include "patcher/pygecko.h"
Expand All @@ -25,6 +25,9 @@ int __entry_menu(int argc, char **argv)
}
InitOSFunctionPointers();
InitSocketFunctionPointers();
InitAocFunctionPointers();
InitACPFunctionPointers();


log_init("192.168.0.181");

Expand All @@ -39,7 +42,7 @@ int __entry_menu(int argc, char **argv)
//!*******************************************************************

if(GAME_LAUNCHED){
PatchMethodHooks();
ApplyPatches();
}

//! *******************************************************************
Expand Down Expand Up @@ -132,7 +135,7 @@ int __entry_menu(int argc, char **argv)
return EXIT_RELAUNCH_ON_LOAD;
}

RestoreInstructions();
RestoreAllInstructions();

deinit_config_controller();

Expand Down
56 changes: 48 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#include "dynamic_libs/socket_functions.h"
#include "dynamic_libs/curl_functions.h"
#include "dynamic_libs/ax_functions.h"
#include "patcher/function_hooks.h"
#include "patcher/fs_patcher.h"
#include "patcher/fs_sd_patcher.h"
#include "patcher/rplrpx_patcher.h"
#include "patcher/extra_log_patcher.h"
#include "patcher/hid_controller_function_patcher.h"
#include "patcher/aoc_patcher.h"
#include "controller_patcher/cp_retain_vars.h"
#include "controller_patcher/config_reader.h"
#include "fs/fs_utils.h"
Expand All @@ -23,6 +28,7 @@
#include "utils/utils.h"
#include "utils/xml.h"
#include "common/common.h"
#include "main.h"

/* Entry point */
extern "C" int Menu_Main(void)
Expand All @@ -45,7 +51,12 @@ extern "C" int Menu_Main(void)
InitAXFunctionPointers();
InitCurlFunctionPointers();

log_print("Function exports loaded\n");
InitAocFunctionPointers();
InitACPFunctionPointers();



log_printf("Function exports loaded\n");

//!*******************************************************************
//! Initialize our kernel variables *
Expand All @@ -64,11 +75,6 @@ extern "C" int Menu_Main(void)
log_printf("Mount SD partition\n");
mount_sd_fat("sd");

//!*******************************************************************
//! Patch Functions *
//!*******************************************************************
log_printf("Patch FS and loader functions\n");

//!*******************************************************************
//! Read Configs for HID support *
//!*******************************************************************
Expand All @@ -80,7 +86,11 @@ extern "C" int Menu_Main(void)
gConfig_done = HID_SDCARD_READ;
}

PatchMethodHooks();
//!*******************************************************************
//! Patch Functions *
//!*******************************************************************
log_printf("Patch FS and loader functions\n");
ApplyPatches();
PatchSDK();

//!*******************************************************************
Expand All @@ -107,3 +117,33 @@ extern "C" int Menu_Main(void)

return 0;
}

void ApplyPatches(){
log_print("Patching FS functions\n");
PatchInvidualMethodHooks(method_hooks_fs, method_hooks_size_fs, method_calls_fs);
log_print("Patching functions for AOC support\n");
PatchInvidualMethodHooks(method_hooks_aoc, method_hooks_size_aoc, method_calls_aoc);
log_print("Patching more FS functions (SD)\n");
PatchInvidualMethodHooks(method_hooks_fs_sd, method_hooks_size_fs_sd, method_calls_fs_sd);
log_print("Patching functions for RPX/RPL loading\n");
PatchInvidualMethodHooks(method_hooks_rplrpx, method_hooks_size_rplrpx, method_calls_rplrpx);
log_print("Patching extra log functions\n");
PatchInvidualMethodHooks(method_hooks_extra_log, method_hooks_size_extra_log, method_calls_extra_log);
log_print("Patching controller_patcher (Hid to VPAD)\n");
PatchInvidualMethodHooks(method_hooks_hid_controller, method_hooks_size_hid_controller, method_calls_hid_controller);
}

void RestoreAllInstructions(){
log_print("Restoring FS functions\n");
RestoreInvidualInstructions(method_hooks_fs, method_hooks_size_fs);
log_print("Restoring functions for AOC support\n");
RestoreInvidualInstructions(method_hooks_aoc, method_hooks_size_aoc);
log_print("Restoring more FS functions (SD)\n");
RestoreInvidualInstructions(method_hooks_fs_sd, method_hooks_size_fs_sd);
log_print("Restoring functions for RPX/RPL loading\n");
RestoreInvidualInstructions(method_hooks_rplrpx, method_hooks_size_rplrpx);
log_print("Restoring extra log functions\n");
RestoreInvidualInstructions(method_hooks_extra_log, method_hooks_size_extra_log);
log_print("Restoring controller_patcher (Hid to VPAD)\n");
RestoreInvidualInstructions(method_hooks_hid_controller, method_hooks_size_hid_controller);
}
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern "C" {

//! C wrapper for out C++ functions
int Menu_Main(void);
void ApplyPatches(void);
void RestoreAllInstructions(void);

#ifdef __cplusplus
}
Expand Down
11 changes: 6 additions & 5 deletions src/menu/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,21 +489,22 @@ void MainWindow::OnGameLoadFinish(GameLauncher * launcher, const discHeader *hea
{
if(result == GameLauncher::SUCCESS)
{
// Set game launched
struct in_addr ip;
ip.s_addr = 0;

if(CSettings::getValueAsBool(CSettings::GameLogServer))
{
inet_aton(CSettings::getValueAsString(CSettings::GameLogServerIp).c_str(), &ip);
const char * ip = CSettings::getValueAsString(CSettings::GameLogServerIp).c_str();
if(strlen(ip) > 0 && strlen(ip) < 16){
memcpy(gServerIP,ip,strlen(ip)+1);
}
log_printf("FS log server on %s\n", CSettings::getValueAsString(CSettings::GameLogServerIp).c_str());
}
else
{
gServerIP[0] = '\0';
log_printf("FS log server is off\n");
}

SERVER_IP = ip.s_addr;

GAME_LAUNCHED = 1;
GAME_RPX_LOADED = 0;
LOADIINE_MODE = CSettings::getValueAsU8(CSettings::GameLaunchMethod);
Expand Down
44 changes: 44 additions & 0 deletions src/patcher/aoc_patcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include "aoc_patcher.h"
#include "common/retain_vars.h"
#include "controller_patcher/cp_retain_vars.h"

DECL(int, ACPGetAddOnUniqueId, unsigned int * id_buffer, int buffer_size)
{
int result = real_ACPGetAddOnUniqueId(id_buffer, buffer_size);

if(GAME_LAUNCHED && gEnableDLC)
{
id_buffer[0] = (cosAppXmlInfoStruct.title_id >> 8) & 0xffff;
result = 0;
}

return result;
}

DECL(int, AOC_OpenTitle, char * path, void * target, void * buffer, unsigned int buffer_size)
{
int result = real_AOC_OpenTitle(path, target, buffer, buffer_size);

if(GAME_LAUNCHED && gEnableDLC && (result != 0))
{
sprintf(path, "/vol/aoc0005000c%08x", (u32)(cosAppXmlInfoStruct.title_id & 0xffffffff));
result = 0;
}
return result;
}

/* *****************************************************************************
* Creates function pointer array
* ****************************************************************************/

hooks_magic_t method_hooks_aoc[] __attribute__((section(".data"))) = {
MAKE_MAGIC(AOC_OpenTitle, LIB_AOC,DYNAMIC_FUNCTION),
MAKE_MAGIC(ACPGetAddOnUniqueId, LIB_NN_ACP,DYNAMIC_FUNCTION),
};


u32 method_hooks_size_aoc __attribute__((section(".data"))) = sizeof(method_hooks_aoc) / sizeof(hooks_magic_t);

//! buffer to store our instructions needed for our replacements
volatile unsigned int method_calls_aoc[sizeof(method_hooks_aoc) / sizeof(hooks_magic_t) * FUNCTION_PATCHER_METHOD_STORE_SIZE] __attribute__((section(".data")));
21 changes: 21 additions & 0 deletions src/patcher/aoc_patcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _AOC_FUNCTION_PATCHER_H
#define _AOC_FUNCTION_PATCHER_H

#ifdef __cplusplus
extern "C" {
#endif

#include "utils/function_patcher.h"
#include "common/kernel_defs.h"

extern hooks_magic_t method_hooks_aoc[];
extern u32 method_hooks_size_aoc;
extern volatile unsigned int method_calls_aoc[];

extern ReducedCosAppXmlInfo cosAppXmlInfoStruct;

#ifdef __cplusplus
}
#endif

#endif /* _AOC_FUNCTION_PATCHER_H */
Loading

0 comments on commit 16c5045

Please sign in to comment.