示例#1
0
        private async void Startup()
        {
            // Setup RPC handlers
            RpcManager.Configure(this.EventHandlers);

            var ticks  = new TickManager(c => this.Tick += c, c => this.Tick -= c);
            var events = new EventManager();
            var rpc    = new RpcHandler();
            var nui    = new NuiManager(this.EventHandlers);

            var user = await rpc.Event("clientInitialize").Request <User>("1.0.0");

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.GetCustomAttribute <ClientPluginAttribute>() == null)
                {
                    continue;
                }

                this.logger.Info(assembly.GetName().Name);

                foreach (var type in assembly.GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(Service))))
                {
                    this.logger.Info($"\t{type.FullName}");

                    var service = (Service)Activator.CreateInstance(type, new Logger($"Plugin|{type.Name}"), ticks, events, rpc, nui, user);
                    await service.Loaded();

                    this.services.Add(service);
                }
            }

            this.logger.Info("Plugins loaded");

#pragma warning disable 4014
            foreach (var service in this.services)
            {
                service.Started();
            }
#pragma warning restore 4014

            this.logger.Info("Plugins started");

            rpc.Event("clientInitialized").Trigger();
        }
示例#2
0
        private async void Startup()
        {
            this.logger.Info($"NFive {typeof(Program).Assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().First().InformationalVersion}");

            // Setup RPC handlers
            RpcManager.Configure(this.EventHandlers);
            var rpc = new RpcHandler();

            var ticks    = new TickManager(c => this.Tick += c, c => this.Tick -= c);
            var events   = new EventManager();
            var commands = new CommandManager(rpc);
            var nui      = new NuiManager(this.EventHandlers);

            // Initial connection
            //var configuration = await rpc.Event(SDK.Core.Rpc.RpcEvents.ClientInitialize).Request<ClientConfiguration>(typeof(Program).Assembly.GetName().Version);
            var config = await rpc.Event(SDK.Core.Rpc.RpcEvents.ClientInitialize).Request <User, LogLevel, LogLevel>(typeof(Program).Assembly.GetName().Version.ToString());

            ClientConfiguration.ConsoleLogLevel = config.Item2;
            ClientConfiguration.MirrorLogLevel  = config.Item3;

            var plugins = await rpc.Event(SDK.Core.Rpc.RpcEvents.ClientPlugins).Request <List <Plugin> >();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.GetCustomAttribute <ClientPluginAttribute>() == null)
                {
                    continue;
                }

                var plugin = plugins.FirstOrDefault(p => p.Client?.Main?.FirstOrDefault(m => m + ".net" == assembly.GetName().Name) != null);

                if (plugin == null)
                {
                    this.logger.Debug("Skipping " + assembly.GetName().Name);
                    continue;
                }

                this.logger.Info(plugin.FullName);
                this.logger.Info($"\t{assembly.GetName().Name}");

                foreach (var type in assembly.GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(Service))))
                {
                    this.logger.Info($"\t\t{type.FullName}");

                    var service = (Service)Activator.CreateInstance(type, new Logger($"Plugin|{type.Name}"), ticks, events, rpc, commands, new OverlayManager(plugin.Name, nui), config.Item1);
                    await service.Loaded();

                    this.services.Add(service);
                }
            }

            // Forward raw FiveM events
            this.EventHandlers.Add("gameEventTriggered", new Action <string, List <object> >((s, a) => events.Raise("gameEventTriggered", s, a)));
            this.EventHandlers.Add("populationPedCreating", new Action <float, float, float, uint, object>((x, y, z, model, setters) => events.Raise("populationPedCreating", new PedSpawnOptions(x, y, z, model, setters))));

            this.logger.Info("Plugins loaded");

#pragma warning disable 4014
            foreach (var service in this.services)
            {
                service.Started();
            }
#pragma warning restore 4014

            this.logger.Info("Plugins started");

            rpc.Event(SDK.Core.Rpc.RpcEvents.ClientInitialized).Trigger();

            foreach (var service in this.services)
            {
                await service.HoldFocus();
            }
        }
示例#3
0
        private async void Startup()
        {
            // Setup RPC handlers
            RpcManager.Configure(this.EventHandlers);

            var ticks    = new TickManager(c => this.Tick += c, c => this.Tick -= c);
            var events   = new EventManager();
            var rpc      = new RpcHandler();
            var commands = new CommandManager(rpc);
            var nui      = new NuiManager(this.EventHandlers);

            var user = await rpc.Event(SDK.Core.Rpc.RpcEvents.ClientInitialize).Request <User>("1.0.0");

            var plugins = await rpc.Event(SDK.Core.Rpc.RpcEvents.ClientPlugins).Request <List <Plugin> >();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.GetCustomAttribute <ClientPluginAttribute>() == null)
                {
                    continue;
                }

                var plugin = plugins.FirstOrDefault(p => p.Client?.Main?.FirstOrDefault(m => m + ".net" == assembly.GetName().Name) != null);

                if (plugin == null)
                {
                    this.logger.Debug("Skipping " + assembly.GetName().Name);
                    continue;
                }

                this.logger.Info(plugin.FullName);
                this.logger.Info($"\t{assembly.GetName().Name}");

                foreach (var type in assembly.GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(Service))))
                {
                    this.logger.Info($"\t\t{type.FullName}");

                    var service = (Service)Activator.CreateInstance(type, new Logger($"Plugin|{type.Name}"), ticks, events, rpc, commands, new OverlayManager(plugin.Name, nui), user);
                    await service.Loaded();

                    this.services.Add(service);
                }
            }

            this.logger.Info("Plugins loaded");

#pragma warning disable 4014
            foreach (var service in this.services)
            {
                service.Started();
            }
#pragma warning restore 4014

            this.logger.Info("Plugins started");

            foreach (var service in this.services)
            {
                await service.HoldFocus();
            }

            rpc.Event(SDK.Core.Rpc.RpcEvents.ClientInitialized).Trigger();
        }