|
2 | 2 | #define __RECOMPUTILS_H__ |
3 | 3 |
|
4 | 4 | #include "modding.h" |
| 5 | +#include "PR/ultratypes.h" |
5 | 6 |
|
6 | 7 | RECOMP_IMPORT("*", void* recomp_alloc(unsigned long size)); |
7 | 8 | RECOMP_IMPORT("*", void recomp_free(void* memory)); |
8 | 9 | RECOMP_IMPORT("*", int recomp_printf(const char* fmt, ...)); |
9 | 10 |
|
| 11 | +// These functions let you get the return value of a function from within a return hook for that function. |
| 12 | +// Calling these outside of a return hook will give an undefined result. |
| 13 | +// Calling the function for a return type that doesn't match the function's actual return type also gives an undefined result. |
| 14 | +RECOMP_IMPORT("*", s32 recomphook_get_return_s32()); |
| 15 | +RECOMP_IMPORT("*", u32 recomphook_get_return_u32()); |
| 16 | +RECOMP_IMPORT("*", void* recomphook_get_return_ptr()); |
| 17 | +RECOMP_IMPORT("*", s16 recomphook_get_return_s16()); |
| 18 | +RECOMP_IMPORT("*", u16 recomphook_get_return_u16()); |
| 19 | +RECOMP_IMPORT("*", s8 recomphook_get_return_s8()); |
| 20 | +RECOMP_IMPORT("*", u8 recomphook_get_return_u8()); |
| 21 | +RECOMP_IMPORT("*", s64 recomphook_get_return_s64()); |
| 22 | +RECOMP_IMPORT("*", u64 recomphook_get_return_u64()); |
| 23 | +RECOMP_IMPORT("*", float recomphook_get_return_float()); |
| 24 | +RECOMP_IMPORT("*", double recomphook_get_return_double()); |
| 25 | + |
| 26 | +typedef enum { |
| 27 | + // The dependency was found and the version requirement was met. |
| 28 | + DEPENDENCY_STATUS_FOUND = 0, |
| 29 | + // The ID given is not a dependency of the mod in question. |
| 30 | + DEPENDENCY_STATUS_INVALID_DEPENDENCY = 1, |
| 31 | + // The dependency was not found. |
| 32 | + DEPENDENCY_STATUS_NOT_FOUND = 2, |
| 33 | + // The dependency was found, but the version requirement was not met. |
| 34 | + DEPENDENCY_STATUS_WRONG_VERSION = 3 |
| 35 | +} DependencyStatus; |
| 36 | + |
| 37 | +// Checks the status of the provided dependency. This is only relevant for optional dependencies, |
| 38 | +// as the game wouldn't have started if a normal dependency wasn't met. |
| 39 | +// Use the return value of this to prevent calling imported functions from optional dependencies that are missing. |
| 40 | +// Try to avoid calling this function repeatedly, as it may incur some overhead. Instead, call it once at startup |
| 41 | +// and store the result into a variable for reading later on. |
| 42 | +RECOMP_IMPORT("*", DependencyStatus recomp_is_dependency_met(const char* dependency_id)); |
| 43 | + |
10 | 44 | #endif |
0 commit comments