Utilities to inject custom functionality into functions.
This function is DEPRECATED. Use
inject_safely_into(mod_identity, target_object, target_function_name)¶
A decorator used to inject code into a function. It will catch and log exceptions, as well as run the original function should any problems occur.
Example of cls usage:
# cls usage @CommonInjectionUtils.inject_safely_into(SimSpawner, SimSpawner.spawn_sim._name__) def do_custom_spawn_sim(original, cls, *args, **kwargs): return original(*args, **kwargs)
Example of self usage:
# Self usage @CommonInjectionUtils.inject_safely_into(SimInfo, SimInfo.load_sim_info.__name__) def do_custom_load_sim_info(original, self, *args, **kwargs): return original(self, *args, **kwargs)
Injection WILL work on
- Functions decorated with ‘property’
- Functions decorated with ‘classmethod’
- Functions decorated with ‘staticmethod’
- Functions with ‘cls’ or ‘self’ as the first argument.
Injection WILL NOT work on
- Global functions, i.e. Functions not contained within a class.
- mod_identity (CommonModIdentity) – The identity of the Mod that is injecting custom code.
- target_object (Any) – The class that contains the target function.
- target_function_name (str) – The name of the function being injected to.
A wrapped function.