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(); }
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(); } }
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(); }
private async void Startup() { // Print exception messages in English // TODO: Test Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var asm = GetType().Assembly; // Setup RPC handlers RpcManager.Configure(this.EventHandlers); var ticks = new TickManager(c => this.Tick += c, c => this.Tick -= c); var events = new EventManager(); var comms = new CommunicationManager(events); var commands = new CommandManager(comms); var nui = new NuiManager(this.EventHandlers); // Initial connection var config = await comms.Event(CoreEvents.ClientInitialize).ToServer().Request <User, Tuple <LogLevel, LogLevel>, Tuple <List <string>, string> >(asm.GetName().Version.ToString()); ClientConfiguration.Log.ConsoleLogLevel = config.Item2.Item1; ClientConfiguration.Log.MirrorLogLevel = config.Item2.Item2; ClientConfiguration.Locale.Culture = config.Item3.Item1.Select(c => new CultureInfo(c)).ToList(); ClientConfiguration.Locale.TimeZone = TimeZoneInfo.Utc; // TODO: ??? + store IANA timezone // Use configured culture for output // TODO: Test Thread.CurrentThread.CurrentCulture = ClientConfiguration.Locale.Culture.First(); // Configure overlays nui.Emit(new { @event = "nfive:config", data = new { locale = ClientConfiguration.Locale.Culture.First().Name, currency = new RegionInfo(ClientConfiguration.Locale.Culture.First().Name).ISOCurrencySymbol, timezone = config.Item3.Item2 } }); // Forward raw FiveM events //this.EventHandlers.Add("gameEventTriggered", new Action<string, List<object>>((s, a) => events.Emit("gameEventTriggered", s, a))); //this.EventHandlers.Add("populationPedCreating", new Action<float, float, float, uint, object>((x, y, z, model, setters) => events.Emit("populationPedCreating", new PedSpawnOptions(x, y, z, model, setters)))); //RpcManager.OnRaw("onClientResourceStart", new Action<Player, string>(OnClientResourceStartRaw)); //RpcManager.OnRaw("onClientResourceStop", new Action<Player, string>(OnClientResourceStopRaw)); //RpcManager.OnRaw("gameEventTriggered", new Action<Player, string, List<dynamic>>(OnGameEventTriggeredRaw)); //RpcManager.OnRaw(FiveMClientEvents.PopulationPedCreating, new Action<float, float, float, uint, IPopulationPedCreatingSetter>(OnPopulationPedCreatingRaw)); // Provide raw BaseScript types to services Service.EventHandlers = this.EventHandlers; Service.Exports = this.Exports; Service.Players = this.Players; var plugins = await comms.Event(CoreEvents.ClientPlugins).ToServer().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.Warn($"Skipping {assembly.GetName().Name}, no client plugin"); continue; } this.logger.Info(plugin.FullName); foreach (var type in assembly.GetTypes().Where(t => !t.IsAbstract && t.IsSubclassOf(typeof(Service)))) { var service = (Service)Activator.CreateInstance(type, new Logger($"Plugin|{type.Name}"), ticks, comms, commands, new OverlayManager(plugin.Name, nui), config.Item1); await service.Loaded(); this.services.Add(service); } } this.logger.Info("Plugins loaded"); await Task.WhenAll(this.services.Select(s => s.Started())); this.logger.Info("Plugins started"); comms.Event(CoreEvents.ClientInitialized).ToServer().Emit(); this.logger.Info("Client ready"); foreach (var service in this.services) { await service.HoldFocus(); } }