You are viewing a potentially older version of this package.
View all versions.
MirrorPlumber
Utility BepInEx Mod that allows modders to utilize various Mirror Networking functions at runtime
| Date uploaded | 2 weeks ago |
| Version | 0.3.1 |
| Download link | darmuh-MirrorPlumber-0.3.1.zip |
| Downloads | 1017 |
| Dependency string | darmuh-MirrorPlumber-0.3.1 |
README
Mirror Plumber
Utility BepInEx Mod that allows modders to utilize various Mirror Networking functions at runtime
This was built for YAPYAP, however, it should work in any other unity game that utilizes the same style of Mirror Networking.
Features:
-
Plumber class which facilitates all the internal plumbing Mirror requires to get a NetworkBehaviour working at runtime.
- Mirror does not recognize it's Attribute tags at runtime so you'll need to utilize this Plumber in order to get things working. (without a patcher or Mirror's weaver)*
- Currently supports Commands, ClientRpcs, TargetRpcs, and Psuedo-SyncVars (PlumbVars). See
ExampleNetBehaviour.cs
-
BehaviourAdder class handles adding custom classes that inherit NetworkBehaviour to existing Prefabs.
- Currently supports adding custom NetworkBehaviour classes to the Player Prefab and any prefab in NetworkManager's spawnPrefabs list.
- The classes are hooked into the prefabs during a NetworkManager Awake prefix patch.
- You will need to supply the assetId for any non-player prefab you wish to add a custom NetworkBehaviour class to.
- NOTE: Prefabs cannot contain more than 64 NetworkBehaviours
- NOTE 2: You will still need to have MirrorPlumber perform the plumbing of your NetworkBehaviour class for it to properly network.
- NOTE 3: When adding a NetworkBehaviour to the Player Prefab, keep in mind your NetworkBehaviour will be on every instance of the Player Prefab. Not just the local instance.
-
GameObjectExtensions class which holds useful gameobject extension methods that pertain to Mirror and MirrorPlumber.
TryRegisterPrefabAttempts to add a given gameobject to an internal MirrorPlumber list of game objects that will be registered at Mirror'sNetworkClient.Initialize- If the prefab is null or does not contain a NetworkIdentity this will return false
TryGetAssetIdAttempts to provide you with a given gameobject's NetworkIdentity assetId.- If the game object is null or does not have a NetworkIdentity, returns false
TryUntrackPrefabAttempts to remove a given gameobject (prefab) from the internal MirrorPlumber list of game objects that will be registered atNetworkClient.Initialize- If the gameobject is null, does not contain a NetworkIdentity, or is not already in the list it will return false.
TrySpawnOnServerAttempts to spawn a given gameobject (prefab) on the server- If the prefab is null or Mirror's
NetworkClientdoes not contain the prefab in it's prefabs list, this will return false.
- If the prefab is null or Mirror's
Examples:
- Network Behaviour using MirrorPlumber - ExampleNetBehaviour.cs
- Loading a Network Prefab with MirrorPlumber - ExampleCustomNetworkPrefab.cs
- Example Mod using MirrorPlumber - SkeletonCostume
Documentation:
- Documentation is WIP, for now you can view the old readme which had a lot of good but poorly organized information.
- It is HIGHLY recommended to reference Mirror's own documentation
CHANGELOG
MirrorPlumber Changelog
0.3.1
- Updated xml documentation for PlumbVars
- Added OnValueChanged event to PlumbVars that can be subscribed to similarly to Mirror's native SyncVar hooks attribute.
0.3.0
- Updated project to generate xml documentation file.
- Updated AutoPlugin version in project.
- Added PlumbVar which acts as a psuedo syncvar (using an internal command and clientrpc)
- Defined with the class name, value type, and initial value
- Get and set the value via the
Valueproperty. Setting the value will send your changes over the network.
- Found and provided fix for issue of NetworkEvent delegate listeners persisting past class destruction.
- In order to clear these delegates with destroyed (null) references, you can now use the
ClearListenersmethod in your NetworkBehaviour'sOnDestroymethod. - You can also swap to
SetListenerin place ofAddListenerthat will automatically clear existing listeners before adding your new listener. - To add additional listeners for one networkevent you can still utilize AddListener, just ensure it is after
ClearListenersorSetListener
- In order to clear these delegates with destroyed (null) references, you can now use the
- Found and provided fix for issue where NetworkPrefabs loaded from asset bundles will get cleared from the NetworkClient when they are no longer hosting.
- This is due to Mirror natively running
NetworkClient.ClearSpawnersduringNetworkClient.Shutdown(in yapyap this method is called when closing a hosted lobby) - The extension method
TryRegisterPrefabhas been updated to handle registration for you.- MirrorPlumber will keep a list of gameobjects that have been queued for registration and ensure they've been registered with NetworkClient at
NetworkClient.Initialize - An overload exists that does not provide the assetId as it's no longer necessary to keep track of.
- MirrorPlumber will keep a list of gameobjects that have been queued for registration and ensure they've been registered with NetworkClient at
- This is due to Mirror natively running
- New game object extension method can be used to remove a prefab from MirrorPlumber's prefab game object list via
TryUntrackPrefab- This will not remove the prefab from an active server, but will ensure it is not in the prefab list for the next time NetworkClient is initialized.
- New game object extension method for getting a prefab's assetId
- New game object extension method for spawning a prefab on the server.
- Examples updated with latest changes
- Readme updates for latest version.
0.2.1
- removed sample classes from compiler that I accidentally included in last build
0.2.0
- Moved Plumber registration from constructor to
Createmethod (breaking change from 0.1.1)- This was to solve an issue where Commands/Rpcs were trying to be re-added to Mirror after a lobby reload.
- Now rather than creating a new Plumber every awake, it should be defined only once and then
Createcan be ran multiple times without any issues.
- Added Examples folder to github.
- This should help the visual learners who learn strictly thru code.
- Added
BehaviourAdderclass for adding network behaviours to existing prefabs at runtime.- Handles both the PlayerPrefab and any spawnPrefab in the list that you can match to an assetId
- Added
GameObjectExtensionsclass for useful extension methods relating to Mirror/MirrorPlumberTryRegisterPrefabwill attempt to take your GameObject prefab and register it with MirrorClient- Returns true/false and provides you the NetworkIdentity assetId when successful.
- Some msbuild project changes to make building the release package a bit easier
0.1.1
- Fixed some typos in the readme
- Removed some old debugging logs for more accurate ones in Plumber.cs
0.1.0
- Initial release.