Supported versions: GameMaker Studio 2.3.x, GameMaker 2022+
For older GameMaker versions, check out the 2019 edition.
This is an example of how to get pointers to GameMaker's built-in functions and pass them to native extensions.
This enables you to call built-in functions (or user-defined ones!) from native code, which can be used to create faster and more convenient extensions - see Apollo for an example.
ptr(method(undefined, a_built_in_function))
gives you a pointer to a method-struct,
which, among other things, contains a pointer to the function itself.
There is currently no way to get a function pointer from these using YYRunnerInterface
,
but we can figure out the offset ourselves by comparing layout of two method structs
pointing at the same built-in function.
- Import the extension
- Call
function_get_address_init()
- You can now call
function_get_address
(e.g.function_get_address(show_debug_message)
) and alike to get pointers to built-in functions.
For use in your own extensions, you can either bundle the function_get_address
extension with yours (it's 4KB!),
or borrow the initializer code.
This small example DLL shows how to call built-in functions, as well as calling user-defined scripts.
YYRunnerInterface
is currently (Feb 2024) only implemented on desktop platforms,
which means that using this on mobile/consoles requires additional legwork
even though the core trick remains functional.
Author: YellowAfterlife
License: MIT