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; }