Exemplo n.º 1
0
        public void Initialize()
        {
            var types = _reflectionManager.FindTypesWithAttribute <NetSerializableAttribute>().ToList();

#if !FULL_RELEASE
            // confirm only shared types are marked for serialization, no client & server only types
            foreach (var type in types)
            {
                if (type.Assembly.FullName !.Contains("Server"))
                {
                    throw new InvalidOperationException($"Type {type} is server specific but has a NetSerializableAttribute!");
                }

                if (type.Assembly.FullName.Contains("Client"))
                {
                    throw new InvalidOperationException($"Type {type} is client specific but has a NetSerializableAttribute!");
                }
            }
#endif

            types.AddRange(AlwaysNetSerializable);

            _mappedStringSerializer.Initialize();

            var settings = new Settings
            {
                CustomTypeSerializers = new[] { _mappedStringSerializer.TypeSerializer }
            };
            _serializer        = new Serializer(types, settings);
            _serializableTypes = new HashSet <Type>(_serializer.GetTypeMap().Keys);
            LogSzr.Info($"Serializer Types Hash: {_serializer.GetSHA256()}");
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            IoCManager.RegisterInstance <IRobustMappedStringSerializer>(_mappedStringSerializer);

            var types = _reflectionManager.FindTypesWithAttribute <NetSerializableAttribute>().ToList();

#if !FULL_RELEASE
            // confirm only shared types are marked for serialization, no client & server only types
            foreach (var type in types)
            {
                if (type.Assembly.FullName !.Contains("Server"))
                {
                    throw new InvalidOperationException($"Type {type} is server specific but has a NetSerializableAttribute!");
                }

                if (type.Assembly.FullName.Contains("Client"))
                {
                    throw new InvalidOperationException($"Type {type} is client specific but has a NetSerializableAttribute!");
                }
            }
#endif

            var settings = new Settings
            {
                CustomTypeSerializers = new ITypeSerializer[] { _mappedStringSerializer }
            };
            _serializer        = new Serializer(types, settings);
            _serializableTypes = new HashSet <Type>(_serializer.GetTypeMap().Keys);
            LogSzr.Info($"Serializer Types Hash: {_serializer.GetSHA256()}");

            if (_netManager.IsClient)
            {
                _mappedStringSerializer.LockMappedStrings = true;
            }
            else
            {
                var defaultAssemblies = AssemblyLoadContext.Default.Assemblies;
                var gameAssemblies    = _reflectionManager.Assemblies;
                var robustShared      = defaultAssemblies
                                        .First(a => a.GetName().Name == "Robust.Shared");
                _mappedStringSerializer.AddStrings(robustShared);

                // TODO: Need to add a GetSharedAssemblies method to the reflection manager

                var contentShared = gameAssemblies
                                    .FirstOrDefault(a => a.GetName().Name == "Content.Shared");
                if (contentShared != null)
                {
                    _mappedStringSerializer.AddStrings(contentShared);
                }

                // TODO: Need to add a GetServerAssemblies method to the reflection manager

                var contentServer = gameAssemblies
                                    .FirstOrDefault(a => a.GetName().Name == "Content.Server");
                if (contentServer != null)
                {
                    _mappedStringSerializer.AddStrings(contentServer);
                }
            }

            _mappedStringSerializer.NetworkInitialize(_netManager);
        }