From 702eb9fccdbed8ab747e74d004963a5de4cba55d Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Mon, 6 Apr 2026 01:39:46 +0300 Subject: [PATCH] Port to modern [Rpc] attribute Method ChooseTrackServerRpc should never have been an RPC. Server will invoke it when it's the right time. And only server was calling it anyway. --- MuzikaGromche/Plugin.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index 5cd1963..41a742e 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -2044,7 +2044,7 @@ namespace MuzikaGromche const string LoopAudioGameObjectName = "MuzikaGromcheAudio (Loop)"; // Number of times a selected track has been played. - // Increases by 1 with each ChooseTrackServerRpc call. + // Increases by 1 with each ChooseTrackOnServer call. // Resets on SettingChanged. private int SelectedTrackIndex = 0; @@ -2108,6 +2108,7 @@ namespace MuzikaGromche public override void OnNetworkSpawn() { + HostIsModded = IsServer; ChooseTrackDeferred(); foreach (var track in Plugin.Tracks) { @@ -2159,7 +2160,8 @@ namespace MuzikaGromche } // Once host has set a track via RPC, it is considered modded, and expected to always set tracks, so never reset this flag back to false. - bool HostIsModded = false; + // Initialized to `IsServer` on network spawn. If I am the host, then I am modded, otherwise we'll find out later. + bool HostIsModded; // Playing with modded host automatically disables vanilla compatability mode public bool VanillaCompatMode => IsServer ? Config.VanillaCompatMode : !HostIsModded; @@ -2173,12 +2175,12 @@ namespace MuzikaGromche if (Config.VanillaCompatMode) { - // In vanilla compat mode no, matter whether you are a host or a client, you should skip networking anyway + // In vanilla compat mode, no matter whether you are a host or a client, you should skip networking anyway ChooseTrackCompat(); } else if (IsServer) { - ChooseTrackServerRpc(); + ChooseTrackOnServer(); } else { @@ -2195,7 +2197,7 @@ namespace MuzikaGromche } } - [ClientRpc] + [Rpc(SendTo.Everyone)] void SetTrackClientRpc(string name) { Plugin.Log.LogDebug($"SetTrackClientRpc {name}"); @@ -2218,12 +2220,11 @@ namespace MuzikaGromche } } - [ServerRpc] - void ChooseTrackServerRpc() + void ChooseTrackOnServer() { var selectableTrack = Plugin.ChooseTrack(); var audioTrack = selectableTrack.SelectTrack(SelectedTrackIndex); - Plugin.Log.LogInfo($"ChooseTrackServerRpc {selectableTrack.Name} #{SelectedTrackIndex} {audioTrack.Name}"); + Plugin.Log.LogInfo($"ChooseTrackOnServer {selectableTrack.Name} #{SelectedTrackIndex} {audioTrack.Name}"); SetTrackClientRpc(audioTrack.Name); SelectedTrackIndex += 1; }