Пример #1
0
        private async ValueTask InitGameDataAsync(ClientPlayer player)
        {
            if (Interlocked.Exchange(ref _gamedataInitialized, 1) != 0)
            {
                return;
            }

            /*
             * The Among Us client on 20.9.22i spawns some components on the host side and
             * only spawns these on other clients when someone else connects. This means that we can't
             * parse data until someone connects because we don't know which component belongs to the NetId.
             *
             * We solve this by spawning a fake player and removing the player when the spawn GameData
             * is received in HandleGameDataAsync.
             */
            using (var message = MessageWriter.Get(MessageType.Reliable))
            {
                // Spawn a fake player.
                Message01JoinGameS2C.SerializeJoin(message, false, Code, FakeClientId, HostId);

                message.StartMessage(MessageFlags.GameData);
                message.Write(Code);
                message.StartMessage(GameDataTag.SceneChangeFlag);
                message.WritePacked(FakeClientId);
                message.Write("OnlineGame");
                message.EndMessage();
                message.EndMessage();

                await player.Client.Connection.SendAsync(message);
            }
        }
Пример #2
0
        private ValueTask BroadcastJoinMessage(IMessageWriter message, bool clear, ClientPlayer player)
        {
            Message01JoinGameS2C.SerializeJoin(message, clear, Code, player.Client.Id, HostId);

            return(SendToAllExceptAsync(message, player.Client.Id));
        }