Skip to content

Commit 68d8978

Browse files
authored
Expose new features from 1.2.1 (#12)
* Optional dependencies * Return getter export for return hooks * Mod folder/file path getter exports * Bump required recomp version to 1.2.1
1 parent 95c2d27 commit 68d8978

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

include/recompconfig.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ RECOMP_IMPORT("*", void recomp_change_save_file(const char* filename));
2525
// `recomp_free` (found in `recomputils.h`) MUST be called on the return value of this when the value is no longer in use to prevent a memory leak.
2626
RECOMP_IMPORT("*", unsigned char* recomp_get_save_file_path());
2727

28+
// Returns a UTF-8 encoded zero-terminated string containing the absolute path to the current game's mod folder.
29+
// The return type is an unsigned char pointer to indicate the UTF-8 encoding.
30+
// `recomp_free` (found in `recomputils.h`) MUST be called on the return value of this when the value is no longer in use to prevent a memory leak.
31+
RECOMP_IMPORT("*", unsigned char* recomp_get_mod_folder_path());
32+
33+
// Returns a UTF-8 encoded zero-terminated string containing the absolute path to the mod that called this function (i.e. the path to the .nrm file).
34+
// The return type is an unsigned char pointer to indicate the UTF-8 encoding.
35+
// `recomp_free` (found in `recomputils.h`) MUST be called on the return value of this when the value is no longer in use to prevent a memory leak.
36+
RECOMP_IMPORT("*", unsigned char* recomp_get_mod_file_path());
37+
2838
#endif

include/recomputils.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,43 @@
22
#define __RECOMPUTILS_H__
33

44
#include "modding.h"
5+
#include "PR/ultratypes.h"
56

67
RECOMP_IMPORT("*", void* recomp_alloc(unsigned long size));
78
RECOMP_IMPORT("*", void recomp_free(void* memory));
89
RECOMP_IMPORT("*", int recomp_printf(const char* fmt, ...));
910

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+
1044
#endif

mod.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ authors = [ "Your name here" ]
3131
game_id = "mm"
3232

3333
# Minimum version of the target recomp (e.g. Zelda 64: Recompiled) that this mod can run on.
34-
minimum_recomp_version = "1.2.0"
34+
minimum_recomp_version = "1.2.1"
3535

3636
# Dependency mods. Each entry is the mod's ID and then an optional minimum version of the dependency mod.
3737
dependencies = [
3838
# Example dependency:
3939
# "modname:1.0.0"
4040
]
4141

42+
# Optional dependency mods. This has the same format as `dependencies`, but the game will still start if dependencies in this
43+
# list aren't present. You can query the presence of a given dependency by using `recomp_is_dependency_met` in recomputils.h.
44+
# Calling a function imported from an optional dependency that isn't present will trigger an error.
45+
optional_dependencies = [
46+
47+
]
48+
4249
# Native libraries (e.g. DLLs) and the functions they export.
4350
native_libraries = [
4451
# Example native library:

0 commit comments

Comments
 (0)