TorchAPI / Torch

An extensible modding framework and improved client/DS for Space Engineers. Still a work in progress!
Apache License 2.0
146 stars 76 forks source link

Added `__original` parameter for prefix/suffix patches #533

Closed ryo0ka closed 1 year ago

ryo0ka commented 1 year ago

Originally written by zznty; cherrypicked from his private repo. Tested with my own plugin in development.

static bool Prefix(MyShipConnector __instance, MethodInfo __original)
{
    ...
}

__original variable contains the patched method's MethodInfo instance.

This allows you to patch multiple arbitrary methods in one go while identifying them and giving them different behaviors on the fly. For example this feature will enable one of my plugins to optimize the game by patching the game's simulate/update methods specified in user config.

ryo0ka commented 1 year ago

Also this feature exists in Harmony (according to z).