Network Behaviour Event Injector
A preload patcher that injects virtual NetworkBehaviour methods on all sub-classes.
About this mod Author’s original text
Network Behaviour Event Preloader
A Preload Patcher that adds the methods OnNetworkSpawn, OnNetworkDespawn, OnGainedOwnership, OnLostOwnership, OnNetworkObjectParentChanged, and OnDestroy to all NetworkBehaviours in 'Assembly-CSharp.dll'.
How It's Implemented
Besides sanity checks, all methods are implemented with the following code snippet (TLDR it calls base.OnXYZ() and returns):
private static void CreateEventMethod(AssemblyDefinition assemblyDefinition, MethodReference methodReference,
TypeDefinition typeDef)
{
var newMethod = new MethodDefinition(
methodReference.Name,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual,
assemblyDefinition.MainModule.TypeSystem.Void);
typeDef.Methods.Add(newMethod);
newMethod.Body.InitLocals = true;
foreach (var paramRef in methodReference.Parameters)
newMethod.Parameters.Add(paramRef.Resolve());
var processor = newMethod.Body.GetILProcessor();
processor.Emit(OpCodes.Ldarg_0);
for (var i = 0; i < methodReference.Parameters.Count; i++)
processor.Emit(OpCodes.Ldarg, i + 1);
processor.Emit(OpCodes.Call, methodReference);
processor.Emit(OpCodes.Ret);
}
References to NetworkBehaviour are resolved from the 'Assembly-CSharp'.
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: