private void WritePhysics(BitStream stream, MyEntity controlledEntity)
        {
            IMyReplicable controlledReplicable = MyExternalReplicable.FindByObject(controlledEntity);

            stream.WriteBool(controlledReplicable != null);

            if (controlledReplicable == null)
            {
                return;
            }

            IMyStateGroup stateGroup = null;

            bool             useCharacterOnServer = controlledEntity is MyCharacter && MyFakes.ENABLE_CHARACTER_CONTROL_ON_SERVER;
            bool             useGridOnServer      = controlledEntity is MyCubeGrid && MyFakes.ENABLE_SHIP_CONTROL_ON_SERVER;
            MyShipController controller           = MySession.Static.ControlledEntity as MyShipController;
            bool             hasWheels            = controller != null && controller.HasWheels;
            long?            supportId            = null;

            if (useCharacterOnServer || (useGridOnServer && hasWheels == false))
            {
                MyEntityPositionVerificationStateGroup group = controlledReplicable.FindStateGroup <MyEntityPositionVerificationStateGroup>();
                stateGroup = group;
                supportId  = group.GetSupportID();
            }
            else
            {
                stateGroup = controlledReplicable.FindStateGroup <MyEntityPhysicsStateGroup>();
            }


            stream.WriteBool(useCharacterOnServer || (useGridOnServer && hasWheels == false));
            stream.WriteBool(stateGroup != null);

            if (stateGroup == null)
            {
                return;
            }

            stream.WriteBool(supportId.HasValue);
            if (supportId.HasValue)
            {
                stream.WriteInt64(supportId.Value);
            }

            bool isResponsible = MyEntityPhysicsStateGroup.ResponsibleForUpdate(controlledEntity, new EndpointId(Sync.MyId));

            stream.WriteBool(isResponsible);
            if (isResponsible)
            {
                stateGroup.Serialize(stream, EndpointId, ClientTimeStamp, 0, 1024 * 1024);
            }
        }
        private void ReadPhysics(BitStream stream, MyNetworkClient sender, MyEntity controlledEntity, uint serverTimeStamp)
        {
            bool hasPhysics = stream.ReadBool();

            m_currentServerTimeStamp = serverTimeStamp;

            if (hasPhysics && MyEntityPhysicsStateGroup.ResponsibleForUpdate(controlledEntity, new EndpointId(sender.SteamUserId)))
            {
                IMyStateGroup stateGroup = null;
                SupportId = null;
                bool enableControlOnServer = stream.ReadBool();
                bool stateGroupFound       = stream.ReadBool();
                if (stateGroupFound == false)
                {
                    return;
                }


                if (stream.ReadBool())
                {
                    SupportId = stream.ReadInt64();
                }

                if (enableControlOnServer)
                {
                    stateGroup = MyExternalReplicable.FindByObject(controlledEntity).FindStateGroup <MyEntityPositionVerificationStateGroup>();
                }
                else
                {
                    stateGroup = MyExternalReplicable.FindByObject(controlledEntity).FindStateGroup <MyEntityPhysicsStateGroup>();
                }

                if (stream.ReadBool())
                {
                    stateGroup.Serialize(stream, new EndpointId(sender.SteamUserId), ClientTimeStamp, 0, 65535);
                }
            }
        }