Further explanation into net methods. #4176
-
Made a few of these discussions lately 🤦♂️ Recently I had the idea of making a totally new gamemode within the game by having the client and the server install the same module. I figured it would be best to stick with the current net system that the game uses, so after looking at some decompiled examples I went ahead and made this: public class TestManager : SteamCaller
{
private static readonly ClientStaticMethod<string> SendTestNet = ClientStaticMethod<string>.Get(ReceiveTestNet);
public static void ServerTestNet(ITransportConnection connection, string str)
{
SendTestNet.Invoke(ENetReliability.Reliable, connection, str);
}
[SteamCall(ESteamCallValidation.ONLY_FROM_SERVER)]
public static void ReceiveTestNet(string str)
{
PlayerUI.message(EPlayerMessage.NPC_CUSTOM, str, 2);
}
}
[NetInvokableGeneratedClass(typeof(TestManager))]
public class TestManager_NetMethods
{
[NetInvokableGeneratedMethod("ReceiveTestNet", ENetInvokableGeneratedMethodPurpose.Read)]
public static void ReceiveTestNet_Read(in ClientInvocationContext context)
{
NetPakReader reader = context.reader;
reader.ReadString(out var value);
TestManager.ReceiveTestNet(value);
}
[NetInvokableGeneratedMethod("ReceiveTestNet", ENetInvokableGeneratedMethodPurpose.Write)]
public static void ReceiveTestNet_Write(NetPakWriter writer, string str)
{
writer.WriteString(str);
}
} After attempting to use ServerTestNet server-side, I received a NullReferenceException, likely relating to this log message:
I'm clueless as to how the all of it works, but I do suspect that the problem might be caused by using Assembly.GetExecutingAssembly instead of GetCallingAssembly in the ctor for NetReflection. Was this intended to prevent modules from using the net method stuff? If not, is there something I'm doing wrong on my end or does the constructor for NetReflection need to be modified? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I believe those attributes generate read/write methods at compile time, so they won't be of much use to you (which could be changed to be done at runtime using Dynamic Methods). As someone who has also done this, I had success with making my own knockoff of his RPCs that use dynamic methods. If you want you can check out how I was able to update the read/write methods to add a few extra enum values to EServerMessage and EClientMessage and add my own listeners for it:
(Note this method is not compatible with clients/servers that do not have your module) |
Beta Was this translation helpful? Give feedback.
-
Hi bro, did you manage to realize the communication between client and server)? |
Beta Was this translation helpful? Give feedback.
-
Hi, @SDGNelson do you think you could simply make it so NetReflection does not use a type initializer and instead make it so it is activated/registers methods after modules are loaded? I, with the assistance of a few others, have tried to use a transpiler to add my own types to the search and recall the initializer. I've been trying to do this for close to a year now. We have concluded that we are likely limited by the fact that you are using a static constructor and readonly fields. |
Beta Was this translation helpful? Give feedback.
I believe those attributes generate read/write methods at compile time, so they won't be of much use to you (which could be changed to be done at runtime using Dynamic Methods).
As someone who has also done this, I had success with making my own knockoff of his RPCs that use dynamic methods.
If you want you can check out how I was able to update the read/write methods to add a few extra enum values to EServerMessage and EClientMessage and add my own listeners for it:
https://github.com/DanielWillett/DevkitServer/blob/master/Multiplayer/Networking/NetFactory.cs#L100