public static NetPacket PreparePacket(ushort powerId, int specificInfoBytesInPacketCount)
        {
            NetPacket result = NetModule.CreatePacket <NetCreativePowersModule>(specificInfoBytesInPacketCount + 2);

            result.Writer.Write(powerId);
            return(result);
        }
        /// <summary>
        /// Create a type defrinition for the given class file and all inner classes.
        /// </summary>
        public override void CreateType(NetTypeDefinition declaringType, NetModule module, TargetFramework target)
        {
            if (declaringType != null)
            {
                throw new ArgumentException("Declaring type should be null");
            }
            docClass = target.GetXmlClass(cf);

            var fullName = GetFullName();
            var dotIndex = fullName.LastIndexOf('.');
            var ns       = (dotIndex > 0) ? NameConverter.UpperCamelCase(fullName.Substring(0, dotIndex)) : String.Empty;
            var name     = (dotIndex > 0) ? NameConverter.UpperCamelCase(fullName.Substring(dotIndex + 1)) : fullName;

            name = CreateTypeName(null, cf, name, ns);

            typeDef                        = new NetTypeDefinition(cf, target, module.Scope);
            typeDef.Name                   = name;
            typeDef.Namespace              = ns;
            typeDef.OriginalJavaClassName  = cf.ClassName;
            typeDef.Attributes             = GetAttributes(cf, cf.Fields.Any());
            typeDef.IgnoreGenericArguments = !AddGenericParameters;
            typeDef.Description            = (docClass != null) ? docClass.Description : null;
            module.Types.Add(typeDef);

            // Prepare generics
            CreateGenericParameters(cf, typeDef);

            // Add mapping
            var finalFullName = string.IsNullOrEmpty(ns) ? name : ns + "." + name;

            RegisterType(target, cf, typeDef);
            CreateNestedTypes(cf, typeDef, finalFullName, module, target);
        }
Example #3
0
        /// <summary>
        /// Create a type defrinition for the given class file and all inner classes.
        /// </summary>
        public override void CreateType(NetTypeDefinition declaringType, NetModule module, TargetFramework target)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }
            docClass = target.GetXmlClass(cf);

            var name = NameConverter.UpperCamelCase(inner.IsAnonymous ? cf.Name : inner.Name);

            name = CreateTypeName(declaringType, cf, name, null);

            var finalFullName = parentFullName + "/" + name;

            var attributes = GetAttributes(cf);

            typeDef = new NetTypeDefinition(cf, target, module.Scope)
            {
                Name = name, Attributes = attributes
            };
            typeDef.OriginalJavaClassName = cf.ClassName;
            typeDef.Description           = (docClass != null) ? docClass.Description : null;
            parent.AddNestedType(typeDef, "", module, ref finalFullName);

            // Prepare generics
            CreateGenericParameters(cf, typeDef);

            // Add mapping
            RegisterType(target, cf, typeDef);
            CreateNestedTypes(cf, typeDef, finalFullName, module, target);
        }
Example #4
0
        void Start()
        {
            AppDomain.CurrentDomain.UnhandledException += this.OnUnhandledException;

            Application.runInBackground = true;
            Application.targetFrameRate = 60;
            DontDestroyOnLoad(this.gameObject);

            Env.isEditor   = Application.isEditor;
            Env.isRunning  = true;
            Env.platform   = ( int )Application.platform;
            Env.useNetwork = this.useNetwork;
            Env.StartTime();

            LoggerProxy.Init(Application.dataPath.Replace("\\", "/") + "/../Log/", this.logServerIp, this.logServerPort);
            LoggerProxy.logLevel = this.logLevel;

            Defs.Init(Resources.Load <TextAsset>("Defs/b_defs").text);

            UIManager.Init();

            if (Env.useNetwork)
            {
                NetworkManager.SetupKCP();
                Windows.CONNECTING_WIN.Open(NetworkConfig.CONNECTION_TIMEOUT / 1000f);
                NetModule.Initialize(this.useKCP ? NetworkManager.PType.Kcp : NetworkManager.PType.Tcp);
                NetModule.instance.OnSocketEvent += this.OnSocketEvent;
                NetModule.instance.Connect(this.ip, this.port);
            }
            else
            {
                Standalone.Init(this.cid, ( byte )this.image, this.map);
                Standalone.Load();
            }
        }
Example #5
0
        public static NetPacket Serialize(Vector2 position)
        {
            NetPacket packet = NetModule.CreatePacket <NetPingModule>(8);

            packet.Writer.WriteVector2(position);
            return(packet);
        }
Example #6
0
        /// <summary>
        /// Create a new instance of the game engine. A user
        /// is required to know how to run the engine.
        /// </summary>
        /// <param name="context">The executing context of the engine.</param>
        /// <param name="serviceLocator">The dependency locator.</param>
        protected GameEngine(IContext context, ServiceLocator serviceLocator)
        {
            if (instance != null)
            {
                throw new Exception("Two or more instances of the game engine exist!");
            }

            this.Context        = context;
            this.serviceLocator = serviceLocator;

            LogModule     = new LogModule(this);
            ConfigModule  = new ConfigModule(this);
            UserModule    = new UserModule(this);
            CommandModule = new CommandConsoleModule(this);
            UIModule      = new UIModule(this);
            NetModule     = new NetModule(this);
            InputModule   = new InputModule(this);

            this.Context.EngineTicker.OnInit   += OnTickerInit;
            this.Context.EngineTicker.OnStart  += OnTickerStart;
            this.Context.EngineTicker.OnUpdate += OnTickerUpdate;
            this.Context.EngineTicker.OnEnd    += OnTickerEnd;

            SceneManager.sceneLoaded += SceneManagerSceneLoaded;
            instance = this;
            Core.Context.SetContext(context);
        }
Example #7
0
        /// <summary>
        /// Create wrapper for given jar file
        /// </summary>
        private void CreateAssembly(JarFile jf, string folder)
        {
            // Create java type wrappers
            var module = new NetModule(jf.Scope);

            var classTypeBuilders = jf.ClassNames.SelectMany(n => StandardTypeBuilder.Create(jf.LoadClass(n), target));

            var typeBuilders = classTypeBuilders.OrderBy(x => x.Priority).ToList();

            typeBuilders.ForEach(x => x.CreateType(null, module, target));

            // Implement and finalize types
            Implement(typeBuilders, target);

            var assemblyAttributes = new List <NetCustomAttribute>();

            if (!importAsStubs)
            {
                // Import code
                var attrType = new NetTypeDefinition(ClassFile.Empty, target, AttributeConstants.Dot42Scope)
                {
                    Name      = AttributeConstants.JavaCodeAttributeName,
                    Namespace = AttributeConstants.Dot42AttributeNamespace
                };
                string hash = JarReferenceHash.ComputeJarReferenceHash(jarFilePath);
                var    attr = new NetCustomAttribute(attrType, hash, Path.GetFileName(jarFilePath));
                assemblyAttributes.Add(attr);
            }

            // Save
            CodeGenerator.Generate(folder, module.Types, assemblyAttributes, target, this, target);
        }
Example #8
0
        public static NetPacket SerializeClientMessage(ChatMessage message)
        {
            NetPacket packet = NetModule.CreatePacket <NetTextModule>(message.GetMaxSerializedSize());

            message.Serialize(packet.Writer);
            return(packet);
        }
Example #9
0
        public static NetPacket SerializeSight(int npcNetId)
        {
            NetPacket result = NetModule.CreatePacket <NetBestiaryModule>(3);

            result.Writer.Write((byte)1);
            result.Writer.Write((short)npcNetId);
            return(result);
        }
Example #10
0
        public static NetPacket Serialize(ParticleOrchestraType particleType, ParticleOrchestraSettings settings)
        {
            NetPacket result = NetModule.CreatePacket <NetParticlesModule>(22);

            result.Writer.Write((byte)particleType);
            settings.Serialize(result.Writer);
            return(result);
        }
Example #11
0
        public static NetPacket SerializeItemSacrifice(int itemId, int sacrificeCount)
        {
            NetPacket result = NetModule.CreatePacket <NetCreativeUnlocksModule>(3);

            result.Writer.Write((short)itemId);
            result.Writer.Write((ushort)sacrificeCount);
            return(result);
        }
Example #12
0
        public static NetPacket SerializeChat(int npcNetId)
        {
            NetPacket packet = NetModule.CreatePacket <NetBestiaryModule>(3);

            packet.Writer.Write((byte)2);
            packet.Writer.Write((short)npcNetId);
            return(packet);
        }
Example #13
0
        public void NetListeningSuccessTest()
        {
            Enode     enode     = new Enode(TestItem.PublicKeyA, IPAddress.Loopback, 30303);
            NetBridge netBridge = new NetBridge(enode, Substitute.For <ISyncServer>());
            NetModule module    = new NetModule(LimboLogs.Instance, netBridge);
            string    response  = RpcTest.TestSerializedRequest <INetModule>(module, "net_listening");

            Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":67}", response);
        }
Example #14
0
        public static NetPacket SerializeKillCount(int npcNetId, int killcount)
        {
            NetPacket packet = NetModule.CreatePacket <NetBestiaryModule>(5);

            packet.Writer.Write((byte)0);
            packet.Writer.Write((short)npcNetId);
            packet.Writer.Write((ushort)killcount);
            return(packet);
        }
Example #15
0
        public void NetVersionSuccessTest()
        {
            Enode     enode     = new Enode(TestItem.PublicKeyA, IPAddress.Loopback, 30303);
            NetBridge netBridge = new NetBridge(enode, Substitute.For <ISyncServer>(), Substitute.For <IPeerManager>());
            NetModule module    = new NetModule(NullLogManager.Instance, netBridge);
            string    response  = RpcTest.TestSerializedRequest <INetModule>(module, "net_version");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":\"0\"}", response);
        }
Example #16
0
        public static NetPacket SerializeCurrentPowerPermissionLevel(ushort powerId, int level)
        {
            NetPacket packet = NetModule.CreatePacket <NetCreativePowerPermissionsModule>(4);

            packet.Writer.Write((byte)0);
            packet.Writer.Write(powerId);
            packet.Writer.Write((byte)level);
            return(packet);
        }
Example #17
0
        public static NetPacket SerializeServerMessage(NetworkText text, Color color, byte authorId)
        {
            NetPacket result = NetModule.CreatePacket <NetTextModule>(1 + text.GetMaxSerializedSize() + 3);

            result.Writer.Write(authorId);
            text.Serialize(result.Writer);
            result.Writer.WriteRGB(color);
            return(result);
        }
        public static NetPacket SerializeSacrificeRequest(int itemId, int amount)
        {
            NetPacket packet = NetModule.CreatePacket <NetCreativeUnlocksPlayerReportModule>(5);

            packet.Writer.Write((byte)0);
            packet.Writer.Write((ushort)itemId);
            packet.Writer.Write((ushort)amount);
            return(packet);
        }
Example #19
0
        private void RegisterJsonRpcModules()
        {
            IJsonRpcConfig jsonRpcConfig = _configProvider.GetConfig <IJsonRpcConfig>();

            if (!jsonRpcConfig.Enabled)
            {
                return;
            }

            // the following line needs to be called in order to make sure that the CLI library is referenced from runner and built alongside
            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            EthModuleFactory ethModuleFactory = new EthModuleFactory(_dbProvider, _txPool, _wallet, _blockTree, _ethereumEcdsa, _blockProcessor, _receiptStorage, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <IEthModule>(8, ethModuleFactory));

            DebugModuleFactory debugModuleFactory = new DebugModuleFactory(_dbProvider, _blockTree, _blockValidator, _recoveryStep, _rewardCalculator, _receiptStorage, _configProvider, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <IDebugModule>(8, debugModuleFactory));

            TraceModuleFactory traceModuleFactory = new TraceModuleFactory(_dbProvider, _txPool, _blockTree, _blockValidator, _ethereumEcdsa, _recoveryStep, _rewardCalculator, _receiptStorage, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <ITraceModule>(8, traceModuleFactory));

            if (_sealValidator is CliqueSealValidator)
            {
                CliqueModule cliqueModule = new CliqueModule(_logManager, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register(new SingletonModulePool <ICliqueModule>(cliqueModule));
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_ethereumEcdsa, _wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _logManager);
                _rpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule));
            }

            AdminModule adminModule = new AdminModule(_logManager, _peerManager, _staticNodesManager);

            _rpcModuleProvider.Register(new SingletonModulePool <IAdminModule>(adminModule));

            TxPoolModule txPoolModule = new TxPoolModule(_logManager, _txPoolInfoProvider);

            _rpcModuleProvider.Register(new SingletonModulePool <ITxPoolModule>(txPoolModule));

            NetModule netModule = new NetModule(_logManager, new NetBridge(_enode, _syncServer, _peerManager));

            _rpcModuleProvider.Register(new SingletonModulePool <INetModule>(netModule));

            ParityModule parityModule = new ParityModule(_ethereumEcdsa, _txPool, _logManager);

            _rpcModuleProvider.Register(new SingletonModulePool <IParityModule>(parityModule));
        }
Example #20
0
        /// <summary>
        /// Create Dot42.dll
        /// </summary>
        private static void CreateFrameworkAssembly(JarFile jf, DocModel xmlModel, SourceProperties sourceProperties, string folder)
        {
            // Initialize all
            MappedTypeBuilder.Initialize(CompositionContainer);

            // Create java type wrappers
            var module      = new NetModule(AttributeConstants.Dot42Scope);
            var classLoader = new AssemblyClassLoader(null);
            var target      = new TargetFramework(null, classLoader, xmlModel, LogMissingParamNamesType, true, false, Enumerable.Empty <string>());

            List <TypeBuilder> typeBuilders;

            using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Create()", x.TotalMilliseconds)))
            {
                var classTypeBuilders = jf.ClassNames.SelectMany(n => StandardTypeBuilder.Create(jf.LoadClass(n), target));
                var customTypeBuilder = CompositionContainer.GetExportedValues <ICustomTypeBuilder>()
                                        .OrderBy(x => x.CustomTypeName)
                                        .Select(x => x.AsTypeBuilder());

                typeBuilders = classTypeBuilders.Concat(customTypeBuilder)
                               .OrderBy(x => x.Priority)
                               .ToList();



                typeBuilders.ForEach(x => x.CreateType(null, module, target));
            }

            // Create JavaRef attribute
            //JavaRefAttributeBuilder.Build(asm.MainModule);

            // Implement and finalize types
            using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Implement()", x.TotalMilliseconds)))
            {
                JarImporter.Implement(typeBuilders, target);
            }

            // Save
            using (Profiler.Profile(x => Console.WriteLine("{0:####} ms for Generate()", x.TotalMilliseconds)))
            {
                CodeGenerator.Generate(folder, module.Types, new List <NetCustomAttribute>(), target, new FrameworkCodeGeneratorContext(), target);
            }

            // Create layout.xml
            var doc = new XDocument(new XElement("layout"));

            typeBuilders.ForEach(x => x.FillLayoutXml(jf, doc.Root));
            doc.Save(Path.Combine(folder, "layout.xml"));

            // create dot42.typemap
            doc = new XDocument(new XElement("typemap"));
            typeBuilders.ForEach(x => x.FillTypemapXml(jf, doc.Root));
            doc.Save(Path.Combine(folder, "dot42.typemap"));
            //using (var s = new FileStream(Path.Combine(folder, "dot42.typemap"), FileMode.Create))
            //    CompressedXml.WriteTo(doc, s, Encoding.UTF8);
        }
Example #21
0
        public static NetPacket SerializeSkyEntitySpawn(Player player, SkyEntityType type)
        {
            int       value  = Main.rand.Next();
            NetPacket result = NetModule.CreatePacket <NetAmbienceModule>(6);

            result.Writer.Write((byte)player.whoAmI);
            result.Writer.Write(value);
            result.Writer.Write((byte)type);
            return(result);
        }
Example #22
0
 /// <summary>
 /// Create a type defrinition for the given class file and all inner classes.
 /// </summary>
 public override void CreateType(NetTypeDefinition declaringType, NetModule module, TargetFramework target)
 {
     // Create basic type
     typeDef = new NetTypeDefinition(ClassFile.Empty, target, Scope)
     {
         Name = name, Namespace = @namespace, Attributes = Attributes
     };
     module.Types.Add(typeDef);
     target.TypeNameMap.Add("custom/" + name, typeDef);
 }
Example #23
0
        public static NetPacket SerializeUseRequest(TeleportPylonInfo info)
        {
            NetPacket packet = NetModule.CreatePacket <NetTeleportPylonModule>(6);

            packet.Writer.Write((byte)2);
            packet.Writer.Write(info.PositionInTiles.X);
            packet.Writer.Write(info.PositionInTiles.Y);
            packet.Writer.Write((byte)info.TypeOfPylon);
            return(packet);
        }
Example #24
0
        public static NetPacket SerializePylonWasAddedOrRemoved(TeleportPylonInfo info, SubPacketType packetType)
        {
            NetPacket result = NetModule.CreatePacket <NetTeleportPylonModule>(6);

            result.Writer.Write((byte)packetType);
            result.Writer.Write(info.PositionInTiles.X);
            result.Writer.Write(info.PositionInTiles.Y);
            result.Writer.Write((byte)info.TypeOfPylon);
            return(result);
        }
Example #25
0
        public static NetPacket SerializeSkyEntitySpawn(Player player, SkyEntityType type)
        {
            int       num    = Main.rand.Next();
            NetPacket packet = NetModule.CreatePacket <NetAmbienceModule>(6);

            packet.Writer.Write((byte)player.whoAmI);
            packet.Writer.Write(num);
            packet.Writer.Write((byte)type);
            return(packet);
        }
Example #26
0
        public static NetPacket Serialize(HashSet <int> changes)
        {
            NetPacket netPacket = NetModule.CreatePacket <NetLiquidModule>(changes.Count * 6 + 2);

            netPacket.Writer.Write((ushort)changes.Count);
            foreach (int change in changes)
            {
                int num  = change >> 16 & 65535;
                int num1 = change & 65535;
                netPacket.Writer.Write(change);
                netPacket.Writer.Write(Main.tile[num, num1].liquid);
                netPacket.Writer.Write(Main.tile[num, num1].liquidType());
            }
            return(netPacket);
        }
Example #27
0
        public static NetPacket Serialize(HashSet <int> changes)
        {
            NetPacket result = NetModule.CreatePacket <NetLiquidModule>(changes.Count * 6 + 2);

            result.Writer.Write((ushort)changes.Count);
            foreach (int change in changes)
            {
                int num  = (change >> 16) & 0xFFFF;
                int num2 = change & 0xFFFF;
                result.Writer.Write(change);
                result.Writer.Write(Main.tile[num, num2].liquid);
                result.Writer.Write(Main.tile[num, num2].liquidType());
            }
            return(result);
        }
Example #28
0
        public static NetPacket Serialize(HashSet <int> changes)
        {
            NetPacket packet = NetModule.CreatePacket <NetLiquidModule>(changes.Count * 6 + 2);

            packet.Writer.Write((ushort)changes.Count);
            foreach (int change in changes)
            {
                int index1 = change >> 16 & (int)ushort.MaxValue;
                int index2 = change & (int)ushort.MaxValue;
                packet.Writer.Write(change);
                packet.Writer.Write(Main.tile[index1, index2].liquid);
                packet.Writer.Write(Main.tile[index1, index2].liquidType());
            }
            return(packet);
        }
Example #29
0
        public static NetPacket Serialize(HashSet <int> changes)
        {
            NetPacket packet = NetModule.CreatePacket <NetLiquidModule>(changes.Count * 6 + 2);

            packet.Writer.Write((ushort)changes.Count);
            foreach (int num in changes)
            {
                int index1 = num >> 16 & 65535;
                int index2 = num & 65535;
                packet.Writer.Write(num);
                packet.Writer.Write(Main.tile[index1, index2].liquid);
                packet.Writer.Write(Main.tile[index1, index2].liquidType());
            }

            return(packet);
        }
Example #30
0
        private void Init()
        {
            this._ready = true;

            Defs.Init(Resources.Load <TextAsset>("Defs/b_defs").text, Resources.Load <TextAsset>("Defs/lscript").text);

            UIManager.Init();

            NetworkManager.SetupKCP();
            NetworkManager.AddPacketTypes();
            Windows.CONNECTING_WIN.Open(NetworkConfig.CONNECTION_TIMEOUT / 1000f);
            NetModule.Initialize(this.useKCP ? NetworkManager.PType.Kcp : NetworkManager.PType.Tcp);
            NetModule.instance.OnSocketEvent += this.OnSocketEvent;
            NetModule.instance.Connect(this.ip, this.port);

            Windows.CONNECTING_WIN.Open(Core.Net.NetworkConfig.CONNECTION_TIMEOUT / 1000f);
        }