2018-02-25 13:07:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2018 Maschell
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2018-02-25 13:07:49 +01:00
|
|
|
#ifndef WUPS_HOOKS_DEF_H_
|
|
|
|
#define WUPS_HOOKS_DEF_H_
|
|
|
|
|
2018-02-25 15:18:52 +01:00
|
|
|
#include "common.h"
|
2018-02-25 13:07:49 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WUPS_HOOK_EX(type_def,original_func) \
|
2018-02-25 15:18:52 +01:00
|
|
|
extern const wups_loader_hook_t wups_hooks_ ## original_func WUPS_SECTION("hooks"); \
|
2018-02-25 13:07:49 +01:00
|
|
|
const wups_loader_hook_t wups_hooks_ ## original_func = { \
|
|
|
|
.type = type_def, \
|
|
|
|
.target = (const void*)&(original_func) \
|
|
|
|
}
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2018-02-25 13:07:49 +01:00
|
|
|
typedef enum wups_loader_hook_type_t {
|
2019-11-18 11:50:03 +01:00
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_MALLOC,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_MALLOC,
|
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_NEWLIB,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_NEWLIB,
|
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_STDCPP,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_STDCPP,
|
2021-03-16 17:31:20 +01:00
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB,
|
2021-04-17 13:40:42 +02:00
|
|
|
WUPS_LOADER_HOOK_INIT_WUT_SOCKETS,
|
|
|
|
WUPS_LOADER_HOOK_FINI_WUT_SOCKETS,
|
2019-11-17 17:43:09 +01:00
|
|
|
|
|
|
|
WUPS_LOADER_HOOK_INIT_PLUGIN, /* Called when exiting the plugin loader */
|
|
|
|
WUPS_LOADER_HOOK_DEINIT_PLUGIN, /* Called when re-entering the plugin loader */
|
2021-03-16 17:31:20 +01:00
|
|
|
WUPS_LOADER_HOOK_APPLICATION_STARTS, /* Called when an application gets started */
|
2019-11-17 17:43:09 +01:00
|
|
|
WUPS_LOADER_HOOK_FUNCTIONS_PATCHED, /* Called when the functions where patched */
|
|
|
|
WUPS_LOADER_HOOK_RELEASE_FOREGROUND, /* Called when an foreground is going to be released */
|
|
|
|
WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND, /* Called when an foreground is acquired */
|
2021-03-16 17:31:20 +01:00
|
|
|
WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT, /* Called when an application wants to exit */
|
|
|
|
WUPS_LOADER_HOOK_APPLICATION_ENDS, /* Called when an application ends */
|
2019-11-17 17:43:09 +01:00
|
|
|
WUPS_LOADER_HOOK_VSYNC, /* Called when an application calls GX2WaitForVsync (most times each frame) */
|
2018-02-25 13:07:49 +01:00
|
|
|
} wups_loader_hook_type_t;
|
|
|
|
|
|
|
|
typedef struct wups_loader_hook_t {
|
|
|
|
wups_loader_hook_type_t type; /* Defines the type of the hook */
|
|
|
|
const void *target; /* Address of our own, new function */
|
|
|
|
} wups_loader_hook_t;
|
|
|
|
|
|
|
|
#define INITIALIZE_PLUGIN() \
|
2018-02-25 15:18:52 +01:00
|
|
|
void init_plugin(void);\
|
2018-02-25 13:07:49 +01:00
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_PLUGIN,init_plugin); \
|
2018-02-25 15:18:52 +01:00
|
|
|
void init_plugin()
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2018-02-25 13:07:49 +01:00
|
|
|
#define DEINITIALIZE_PLUGIN() \
|
|
|
|
void deinit_plugin(void);\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_DEINIT_PLUGIN,deinit_plugin); \
|
|
|
|
void deinit_plugin()
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2021-03-16 17:31:20 +01:00
|
|
|
#define ON_APPLICATION_START() \
|
|
|
|
void on_app_starting();\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_APPLICATION_STARTS,on_app_starting); \
|
|
|
|
void on_app_starting()
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2018-03-07 18:53:43 +01:00
|
|
|
#define ON_FUNCTIONS_PATCHED() \
|
|
|
|
void on_functions_patched();\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FUNCTIONS_PATCHED,on_functions_patched); \
|
|
|
|
void on_functions_patched()
|
2018-02-25 13:07:49 +01:00
|
|
|
|
2019-11-17 17:43:09 +01:00
|
|
|
#define ON_RELEASE_FOREGROUND() \
|
|
|
|
void on_release_foreground(void);\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_RELEASE_FOREGROUND,on_release_foreground); \
|
|
|
|
void on_release_foreground(void)
|
|
|
|
|
|
|
|
#define ON_ACQUIRED_FOREGROUND() \
|
|
|
|
void on_acquired_foreground(void);\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_ACQUIRED_FOREGROUND,on_acquired_foreground); \
|
|
|
|
void on_acquired_foreground(void)
|
2021-03-16 17:31:20 +01:00
|
|
|
|
|
|
|
#define ON_APPLICATION_REQUESTS_EXIT() \
|
|
|
|
void on_app_requests_exit(void);\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_APPLICATION_REQUESTS_EXIT,on_app_requests_exit); \
|
|
|
|
void on_app_requests_exit(void)
|
2019-11-17 17:43:09 +01:00
|
|
|
|
2021-03-16 17:31:20 +01:00
|
|
|
#define ON_APPLICATION_ENDS() \
|
2018-02-25 13:07:49 +01:00
|
|
|
void on_app_ending(void);\
|
2021-03-16 17:31:20 +01:00
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_APPLICATION_ENDS,on_app_ending); \
|
2018-02-25 13:07:49 +01:00
|
|
|
void on_app_ending(void)
|
|
|
|
|
|
|
|
#define ON_VYSNC() \
|
|
|
|
void on_vsync(void);\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_VSYNC,on_vsync); \
|
|
|
|
void on_vsync(void)
|
2018-03-11 17:12:46 +01:00
|
|
|
|
2021-04-06 20:33:19 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define __EXTERN_C_MACRO extern "C"
|
|
|
|
#else
|
|
|
|
#define __EXTERN_C_MACRO
|
|
|
|
#endif
|
|
|
|
|
2019-11-18 11:50:03 +01:00
|
|
|
#define WUPS_USE_WUT_MALLOC() \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __init_wut_malloc(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_init_wut_malloc(){ \
|
|
|
|
__init_wut_malloc(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_MALLOC,on_init_wut_malloc); \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __fini_wut_malloc(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_fini_wut_malloc(){ \
|
|
|
|
__fini_wut_malloc(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_MALLOC,on_fini_wut_malloc); \
|
2021-04-06 20:33:19 +02:00
|
|
|
|
2019-11-18 11:50:03 +01:00
|
|
|
#define WUPS_USE_WUT_DEVOPTAB() \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __init_wut_devoptab(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_init_wut_devoptab(){ \
|
|
|
|
__init_wut_devoptab(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_DEVOPTAB,on_init_wut_devoptab); \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __fini_wut_devoptab(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_fini_wut_devoptab(){ \
|
|
|
|
__fini_wut_devoptab(); \
|
|
|
|
}\
|
2021-03-16 17:31:20 +01:00
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_DEVOPTAB,on_fini_wut_devoptab);
|
|
|
|
|
2019-11-18 11:50:03 +01:00
|
|
|
#define WUPS_USE_WUT_NEWLIB() \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __init_wut_newlib(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_init_wut_newlib(){ \
|
|
|
|
__init_wut_newlib(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_NEWLIB,on_init_wut_newlib); \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __fini_wut_newlib(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_fini_wut_newlib(){ \
|
|
|
|
__fini_wut_newlib(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_NEWLIB,on_fini_wut_newlib);
|
|
|
|
|
|
|
|
#define WUPS_USE_WUT_STDCPP() \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __init_wut_stdcpp(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_init_wut_stdcpp(){ \
|
|
|
|
__init_wut_stdcpp(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_STDCPP,on_init_wut_stdcpp); \
|
2021-04-06 20:33:19 +02:00
|
|
|
__EXTERN_C_MACRO void __fini_wut_stdcpp(); \
|
2019-11-18 11:50:03 +01:00
|
|
|
void on_fini_wut_stdcpp(){ \
|
|
|
|
__fini_wut_stdcpp(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_STDCPP,on_fini_wut_stdcpp);
|
|
|
|
|
2021-04-17 13:40:42 +02:00
|
|
|
#define WUPS_USE_WUT_SOCKETS() \
|
|
|
|
__EXTERN_C_MACRO void __attribute__((weak)) __init_wut_socket(); \
|
|
|
|
void on_init_wut_sockets(){ \
|
|
|
|
if (&__init_wut_socket) __init_wut_socket(); \
|
|
|
|
} \
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_INIT_WUT_SOCKETS,on_init_wut_sockets); \
|
|
|
|
__EXTERN_C_MACRO void __attribute__((weak)) __fini_wut_socket(); \
|
|
|
|
void on_fini_wut_sockets(){ \
|
|
|
|
if (&__fini_wut_socket) __fini_wut_socket(); \
|
|
|
|
}\
|
|
|
|
WUPS_HOOK_EX(WUPS_LOADER_HOOK_FINI_WUT_SOCKETS,on_fini_wut_sockets);
|
|
|
|
|
2018-02-25 13:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-11 17:12:46 +01:00
|
|
|
#endif /* WUPS_WUPS_H_ */
|