#Static Netcode Lib

242 messages · Page 1 of 1 (latest)

hearty niche
#

A basic library/patcher that allows you to use Rpcs in a static context. Network Variables are on the plate, but are not in the initial release.

Usage

Add the appropriate BepInDependency attribute to your plugin class, like so:

[BepInDependency(StaticNetcodeLib.Guid, DependencyFlags.HardDependency)]
public class ExampleMod : BaseUnityPlugin

Then add the StaticNetcode attribute to any classes that have static rpcs.

[StaticNetcode]
public class ExampleNetworkingClass

After that, you can simply use Server & Client Rpcs as you normally would (even outside NetworkBehaviours), but in a static context, like so:

[ClientRpc]
public static void ExampleClientRpc(string exampleString)
{
    ExampleMod.Logger.LogDebug(exampleString);
}

/* ... */

ExampleClientRpc("Hello, world!");

Note: The Rpc attribute params are not respected for this. For example, ServerRpcs are static and thus cannot have an owner, and are used as if it had the RequireOwnership = false parameter.

Links

GitHub: https://github.com/Xilophor/StaticNetcodeLib
NuGet: https://www.nuget.org/packages/Xilophor.StaticNetcodeLib
Thunderstore: https://thunderstore.io/c/lethal-company/p/xilophor/StaticNetcodeLib/

Example Project:https://github.com/Xilophor/Disintegration

This lib is not specific to Lethal Company, and should not break between updates.

whole hedge
#

this sound sgood but im too stupid to understand what it means

hearty niche
#

I'll have to put together an example project, but pretty much you don't have to use rpcs in a network behaviour anymore

whole hedge
#

well the reason is because im not a modder was just checking out and it souned good and it sounds even more good now

#

lol

hearty niche
#

@tender ether you happen to know where I can get a stubbed netcode.runtime for github?

tender ether
#

There's one in lethal company gamelibs

hearty niche
#

realized I don't use any of the gamelibs other than netcode.runtime so wanted to see if I can minimize it

tender ether
#

yeah so here's the thing

#

Uh actually

tender ether
#

that you can put in the repo

hearty niche
#

either works tbh

tender ether
#

basically it's not worth putting it on nuget

#

if you look at the patchers.zip for the latest version of netcode patcher

#

i have to have basically a matrix of assemblies

#

the dimensions are

#

netcode version x unity version x unity transport version x native collection support bool

#

but the patcher has to care about implementation

#

i think the netcode API is actually consistent (for each version)

#

hmm

hearty niche
#

other than the attributes for rpcs, I think so yeah

tender ether
#

uh no

#

ServerRpc and ClientRpc still exist in 1.8

hearty niche
tender ether
#

Rpc.SendTo is a convenience

hearty niche
#

okay yeah

tender ether
#

I might be chatting shit

#

but I'm almost certain

#

okay so they are deprecated but still exist

hearty niche
#

but yeah all that matters to me is patching the networkmanager start host/client/server, shutdown, the unnammed messaging shit, and INetworkSerializable

#

though I probably could add support for the updated rpc attributes

tender ether
#

I hope at some point Zeeks decides to update his dependencies

#

Transport >2 and Netcode 1.8 have lovely features

tender ether
#

ik it's different cause unity but still

hearty niche
#

I haven't looked into those, what is the gyst?

tender ether
hearty niche
#

well sorta, but not really

tender ether
#

the main thing is the Rpc.SendTo()

#

It eliminates the serverrpc into clientrpc pattern

#

because clients can Rpc.SendTo(everyoneelse)

hearty niche
#

hmm odd

tender ether
#

under the hood its the same as it was

#

sending to server, sending to everyone

hearty niche
#

yeye

tender ether
#

its syntactic sugar

hearty niche
#

sorta like my ClientMessage.SendOtherClients() or whatever it was in my network api

tender ether
#

Transport 2 is just general improves w/ a few new features that don't affect us too much but are nice-to-haves

hearty niche
#

just better than my implementation :)

tender ether
#

lmao sure, but you're working by yourself and this is a team of paid professionals

#

don't beat yourself up abt it

hearty niche
#

no yeah ik

#

why does my i key not always register sadcat

tender ether
hearty niche
#

tbh that's a lot of targets to support and I'm lazy

tender ether
#

Lmao I was not suggesting that you do 😂

#

Anyway

hearty niche
#

no I was considering it, but after seeing that list I'm no longer considering it kekw

tender ether
#

The easiest thing you can do is download the gamelibs package, rename it from .nupkg to .zip, and pull out the assembly from /lib/netstandard2.1/

hearty niche
#

ye

tender ether
#

that's a stripped netcode 1.5.2, I believe

#

if you want the other ones, you'll have to do some Unity project chicanery to get them

#

and use BepInEx.AssemblyPublicizer.Cli

hearty niche
#

that sounds like pain, and I only need the stripped version(s), and only v1.5.2 if they continue to have backwards compatibility

tender ether
#

Oh, I don't mean to publicize

#
assembly-publicizer ./Test.dll --strip-only
#

That's how GameLib Dehumidifer works

hearty niche
#

I do need to publicize tho xd

tender ether
#

read the screenshot bestie

hearty niche
#

no ik

tender ether
#
assembly-publicizer ./Test.dll --strip
#

oh i see

#

did you just realise? you previously thought you didn't need to ?

hearty niche
#

no I meant to reply to an earlier message

#

anyways

tender ether
#

Oh

#

i think i follow

hearty niche
#

I don't think I need to as long as ngo has backwards compatibility

tender ether
#

uhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

#

in terms of its API

tender ether
#

hmmmmmmmmm

#

Right

#

This is gonna sound a little batshit

#

but if you only need a subset of classes

#

you could make your own csharp project, define the types you need (in stub format) and compile that

#

and compile your API against that assembly

#

as long as you set the name to Unity.Netcode.Runtime

hearty niche
#

hmm

#

that sounds like more work than copying the stubbed version from the gamelibs package

tender ether
#

lmao

hearty niche
#

(which I've already done)

tender ether
#

I'll take a quick look at 1.8 and see whether there are any blaring issues with compiling against that

hearty niche
tender ether
#

okay from what I can see, comparing 1.8.1 to 1.2.0

#

I would be hard pressed to find a public member that has been renamed or removed

#

Plenty of implementation changes and internal/private refactoring

tender ether
hearty niche
#

really is just this

protected override void Read(ref NetworkBehaviourReference value, IDataReader reader)
{
    value.m_NetworkObjectReference = NetworkObjectReferenceSerializer.ReadValue(reader);
    value.m_NetworkBehaviourId = UInt16Serializer.ReadValue(reader);
}

protected override void Read(ref NetworkObjectReference value, IDataReader reader) =>
    value.NetworkObjectId = UInt64Serializer.ReadValue(reader);
#

those are internal/private iirc

tender ether
#

ah yeah

#

let me look

#

2 implementation changes

#

0 member renames/removals

hearty niche
#

as long as they're still used

tender ether
#

in fact

hearty niche
#

ah that's nothing

tender ether
#

i'm looking at network Object reference

#

there are 0 changes

#

to network behaviour reference

hearty niche
tender ether
#

from 1.2.0 through 1.8.1

hearty niche
#

wait it doesn't I think

tender ether
#

and I assume IsSpawned is either

#
  • a property that performs a lifetime check
  • a field where true implies 'this object is alive'
hearty niche
tender ether
hearty niche
tender ether
#

I don't see how that's relevant

hearty niche
#

I might be dumbo

tender ether
#

the default being null doesn't stop me from passing a dead unity object into that parameter

hearty niche
#

ah

#

yeah

tender ether
#

but it's a private

#

so they are sacrificing some developer experience for the sake of performance

#

Although

#

ah no

#

they will get a NRE on SpawnManager

#

it's assigned to null when the NetworkManager instance is Destroyed

hearty niche
clever salmon
#

I have taken my payment, thanks

hearty niche
hearty niche
#

rpcs can be found under Disintegration/RouletteWheel.cs

desert niche
#

this is based

#

thanks for making this 🥺

desert niche
#

@hearty niche is it safe to assume this isn't thread-safe like most other things in unity? or would be able to use static rpcs from a different thread, as long as the calls are from within the same thread?

hearty niche
#

uh, haven't tried it but I assume not, since it's using ngo shit behind the scenes

#

oh yeah, I touch a static field in it too so def. not

desert niche
#

sounds good, thanks for the confirmation

desert niche
#

@hearty niche this is probably game independent, but is there a simple way to know when is the earliest i'm able to run an rpc method using static netcode lib?

i'm having trouble finding where to hook to do this rn. here's what i've tried (all postfix patches):

  • StartOfRound.OnClientConnect (on the host, to try to do a client rpc)
  • StartOfRound.OnPlayerConnectedClientRpc (on a non-host, to try to do a server rpc)
  • PlayerControllerB.ConnectClientToPlayerObject (on either, to do a client/server rpc)

these always results in one of the sides not executing the rpc method, which clearly means it's not instantiated yet, but where can i simply hook to in order to, for example, run a server rpc at the earliest available moment for a non-host?

hearty niche
#

hmmmrmrmrmrmmmmmmmmm let me take a look at the lib's code to see at what point it can work

#

looks like messaging theoretically would work shortly after NetworkManager.Initialize; but idk if that's quite the point that it'd work with NGO

#

only thing is that I'm almost certain Initialize occurs before OnClientConnected

#

@tender ether you happen to know shit?

hearty niche
tender ether
tender ether
#

Prefix them both with a logline?

desert niche
hearty niche
#

writing this so I can remember to debug tomorrow

  • patch different applicable methods to check if UnnamedMessageHandler does have an instance
desert niche
#

ok so it turns out i was probably doing something wrong yesterday lmao

#

i just patched StartOfRound.OnClientConnect and it works just fine

#

whoops.... sorry for the false alarm

desert niche
#

Network Variables are on the plate, but are not in the initial release.
out of curiosity is this something that'll still get added at one point?

hearty niche
#

I've thought about it some, but it starts to get real fucky and confusing as to how it needs to work on the public side - eg all the (msnyll edge-cases) - that it becomes a much larger problem to tackle than one might think

#

that is to say it isn't a hard no, but if I do get around to it, it'd take a while to even come to a version that I'd be content with

#

this lib/patcher is essentially the higher quality "version" of LethalNetworkAPI, and so my expectations of quality for this lib/patcher is much higher

#

what'll likely happen is net vars are re-implemented in the LethalNetworkAPI rewrite in a way that I'm okay with, then I do a similar implementation in this but take quite a bit of time to better flesh-out the details

analog grove
#

I'm having a weird issue where Harmony eventually starts trying to use a version of my ServerRpc but with the parameters of the ClientRpc. This project is just starting out and I'm not mixing up the parameters in my code (ServerRpc is only being called in one patch and ClientRpc is only called by ServerRpc). Any ideas?

#
[Error  : Unity Log] ArgumentNullException: Value cannot be null.
Parameter name: key
Stack trace:
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <787acc3c9a4c471ba7d971300105af24>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (TKey key, TValue value) (at <787acc3c9a4c471ba7d971300105af24>:0)
StaticNetcodeLib.Messaging.UnnamedMessageHandler.ReceiveRpc (StaticNetcodeLib.Messaging.MessageData messageData) (at ./Messaging/UnnamedMessageHandler.cs:109)
StaticNetcodeLib.Messaging.UnnamedMessageHandler.ReceiveMessage (System.UInt64 clientId, Unity.Netcode.FastBufferReader message) (at ./Messaging/UnnamedMessageHandler.cs:91)
Unity.Netcode.CustomMessagingManager.InvokeUnnamedMessage (System.UInt64 clientId, Unity.Netcode.FastBufferReader reader, System.Int32 serializedHeaderSize) (at <895801699cfc4b4ab52267f31e2a4998>:0)
Unity.Netcode.UnnamedMessage.Handle (Unity.Netcode.NetworkContext& context) (at <895801699cfc4b4ab52267f31e2a4998>:0)
more crap...
#
[ServerRpc]
internal static void ChangePlayerTeamServerRpc(int suitId, ServerRpcParams rpcParams = default) { ... }

[ClientRpc]
private static void ChangePlayerTeamClientRpc(ulong clientId, int suitId) { ... }

and these are my rpcs

hearty niche
#

does this happen with the version before the latest release?

analog grove
hearty niche
#

hmm okay

#

I think I know the cause, which is a shame if I can't get around it somehow, since it allows anything to be serialized

#

I guess stick with v1.0.3 for now and I'll try and get a fixed version out somewhat soon, and if not it'll just be a revision

analog grove
hearty niche
#

no, those work

#

it's more like records and stuff

analog grove
#

Ah, ok

#

Well if you get a change out let me know and I'll test it

hearty niche
hearty niche
hearty niche
clever salmon
#

best change thus far

hearty niche
#

yeah.. github seems to be throwing a fit

#

idk if my internet was a bit wacky and github thinks I'm a sussy bakka, or if github is having issues themselves

#

like the actions are just in this limbo state, I can't even cancel the runs

#

at least the code's up so you can build it manually if you want

clever salmon
#

sorry xilo, u dont exist either

hearty niche
#

yeah I think github killed me

#

that sucks

hearty niche
storm marlin
raven patio
#

Ive been hearing multiple people say this mod causes hotbar locks

hearty niche
#

that's an odd one, you happen to have any logs or anything?

hearty niche
raven patio
raven patio
hearty niche
raven patio
hearty niche
#

like did all players have the same coroner version

#

might have been caused by a version mis-match

raven patio
#

So should be yeah

raven patio
raven patio
#

but some of the lag issues seem to be still present

raven patio
hearty niche
#

sorta expecting that to happen, if you can send me the log file (when you're done playing) I can take a closer look than before

hearty niche
#

hmm, seems like the bug you're seeing is unrelated, this log doesn't contain any errors related to static netcode lib

raven patio
#

weird

hearty niche
#

it may cause it, but at least in this case it doesn't seem like the error occurred

likely there are several network-related things that can cause that bug

hearty niche
#

I mean, the best way is to mark in the log where the bug occurs, but you'd have to be monitoring the console

there are a few things that catch my eye, but without knowing where the bug actually occurs, it's kinda hard to tell

#

starting at line 26531 19243 there's a grab invalidated log repeated, might have something to do with it

sour owl
#

does this require netcode patcher?

hearty niche
#

no, it patches static rpcs during runtime

sour owl
#

thanks

sour owl
#

also is it possible to make it so when a vanilla client tries to join it dosent get automatically get kicked for not having the mod

#

i dont know much abt netcode

hearty niche
#

this uses network messages, so the client won't be kicked unless the server or client has mods with additional NetworkObjects that the other doesn't have

#

e.g. any custom scrap or custom enemy mod

sour owl
#

I only added a client rpc and vanilla client cant join on lan

#

Maybe it was another mod

#

I will try again tmr

smoky blade
#

perhaps nobody has reported this problem to you before.

hearty niche
#

I've seen this before but haven't had enough info and couldn't replicate...

I sorta have a general idea of where this error is occurring, but not why

#

but since you mentioned how to replicate, I'll investigate and put out a fix

hearty niche
#

so seems like the serializer I use for this sometimes deserializes the string to an object array, causing this issue...

I just have to not be lazy in how I use it and explicitly define what to deserialize to, which sorta sucks but is whatever

smoky blade
#

Well, so has this problem been fixed?

hearty niche
#

got the bug fixed, will be releasing it later today after my flight

remote jetty
#

@hearty niche did you ever release the changes to fix the serialization issues? i see the branches 5 months ago but the last actual release was 2 years ago

hearty niche
#

did I not? whoops

#

I'll push that after work

remote jetty
#

thanksies