#2
1st Jan 2020 at 8:08 PM
Posts: 156
Thanks: 24370 in 36 Posts
19 Achievements
Hey! Injecting is in fact wrapping, not modifying the actual function. Your function goes around the original function and then takes place of it so the game runs the modified wrapped function first (then you run the original function inside your injecting function). When you wrap ("inject") a function, each wrapping adds a layer that runs before the actual original function is reached. The layers are actually other mods potentially wrapping your injecting function or you wrapping some other mods injecting function. It's all perfectly safe if done properly.
What's not safe are insecure injections. Some mods might wrap functions without returning the original result, some might change passed arguments in such a way that might break your injection, some might cause errors that the game itself doesn't experience, and some might not even run the original function. It's not your fault, but it might completely break your mod and there's nothing you can do about it. And you might be doing it yourself without even thinking about it. Inject responsibly, kids.
EDIT: Just to add to this, there are "injections" of class methods, static methods, or functions (the above statement is actually about in-class methods). I assume you're speaking about the typical injection using an injector, since the other "injections" sometimes are done as overrides instead.