Network Behaviour Event Injector

v1.0.0·Updated 2024-02-02

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

  1. The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
  2. 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.
  3. Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
  4. 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.

Dependencies

Install these first, or the mod will not work:

BepInEx-BepInExPack

File & checksum

Filename
Network_Behaviour_Event_Injector-1.0.0.zip
File size
80.0 KiB