public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; OnRemoteDirectConnect = (a, b) => { }; delayedActions = new ActionQueue(); Ui.ResetAll(); if (worldRenderer != null) { worldRenderer.Dispose(); } worldRenderer = null; if (server != null) { server.Shutdown(); } if (OrderManager != null) { OrderManager.Dispose(); } if (ModData != null) { ModData.Dispose(); } ModData = null; // Fall back to default if the mod doesn't exist if (!ModMetadata.AllMods.ContainsKey(mod)) { mod = new GameSettings().Mod; } Console.WriteLine("Loading mod: {0}", mod); Settings.Game.Mod = mod; Sound.StopMusic(); Sound.StopVideo(); Sound.Initialize(); ModData = new ModData(mod, !Settings.Server.Dedicated); ModData.InitializeLoaders(); if (!Settings.Server.Dedicated) { Renderer.InitializeFonts(ModData.Manifest); } using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); if (Settings.Graphics.HardwareCursors) { try { Cursor = new HardwareCursor(ModData.CursorProvider); } catch (Exception e) { Log.Write("debug", "Failed to initialize hardware cursors. Falling back to software cursors."); Log.Write("debug", "Error was: " + e.Message); Console.WriteLine("Failed to initialize hardware cursors. Falling back to software cursors."); Console.WriteLine("Error was: " + e.Message); Cursor = new SoftwareCursor(ModData.CursorProvider); Settings.Graphics.HardwareCursors = false; } } else { Cursor = new SoftwareCursor(ModData.CursorProvider); } PerfHistory.Items["render"].HasNormalTick = false; PerfHistory.Items["batches"].HasNormalTick = false; PerfHistory.Items["render_widgets"].HasNormalTick = false; PerfHistory.Items["render_flip"].HasNormalTick = false; JoinLocal(); if (Settings.Server.Dedicated) { while (true) { Settings.Server.Map = WidgetUtils.ChooseInitialMap(Settings.Server.Map); Settings.Save(); CreateServer(new ServerSettings(Settings.Server)); while (true) { Thread.Sleep(100); if (server.State == Server.ServerState.GameStarted && server.Conns.Count < 1) { Console.WriteLine("No one is playing, shutting down..."); server.Shutdown(); break; } } if (Settings.Server.DedicatedLoop) { Console.WriteLine("Starting a new server instance..."); ModData.MapCache.LoadMaps(); continue; } break; } Environment.Exit(0); } else { ModData.LoadScreen.StartGame(args); } }
public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; OnRemoteDirectConnect = (a, b) => { }; delayedActions = new ActionQueue(); Ui.ResetAll(); if (worldRenderer != null) { worldRenderer.Dispose(); } worldRenderer = null; if (server != null) { server.Shutdown(); } if (OrderManager != null) { OrderManager.Dispose(); } if (ModData != null) { ModData.ModFiles.UnmountAll(); ModData.Dispose(); } ModData = null; if (mod == null) { throw new InvalidOperationException("Game.Mod argument missing."); } if (!Mods.ContainsKey(mod)) { throw new InvalidOperationException("Unknown or invalid mod '{0}'.".F(mod)); } Console.WriteLine("Loading mod: {0}", mod); Sound.StopVideo(); ModData = new ModData(Mods[mod], Mods, true); if (!ModData.LoadScreen.BeforeLoad()) { return; } using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); ModData.InitializeLoaders(ModData.DefaultFileSystem); Renderer.InitializeFonts(ModData); PerfHistory.Items["render"].HasNormalTick = false; PerfHistory.Items["batches"].HasNormalTick = false; PerfHistory.Items["render_widgets"].HasNormalTick = false; PerfHistory.Items["render_flip"].HasNormalTick = false; JoinLocal(); try { if (discoverNat != null) { discoverNat.Wait(); } } catch (Exception e) { Console.WriteLine("NAT discovery failed: {0}", e.Message); Log.Write("nat", e.ToString()); } ModData.LoadScreen.StartGame(args); }
public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; OnRemoteDirectConnect = (a, b) => { }; delayedActions = new ActionQueue(); Ui.ResetAll(); if (worldRenderer != null) { worldRenderer.Dispose(); } worldRenderer = null; if (server != null) { server.Shutdown(); } if (OrderManager != null) { OrderManager.Dispose(); } if (ModData != null) { ModData.ModFiles.UnmountAll(); ModData.Dispose(); } ModData = null; if (mod == null) { throw new InvalidOperationException("Game.Mod argument missing."); } if (!Mods.ContainsKey(mod)) { throw new InvalidOperationException("Unknown or invalid mod '{0}'.".F(mod)); } Console.WriteLine("Loading mod: {0}", mod); Sound.StopVideo(); ModData = new ModData(Mods[mod], Mods, true); LocalPlayerProfile = new LocalPlayerProfile(Platform.ResolvePath(Path.Combine("^", Settings.Game.AuthProfile)), ModData.Manifest.Get <PlayerDatabase>()); if (!ModData.LoadScreen.BeforeLoad()) { return; } using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); ModData.InitializeLoaders(ModData.DefaultFileSystem); Renderer.InitializeFonts(ModData); var grid = ModData.Manifest.Contains <MapGrid>() ? ModData.Manifest.Get <MapGrid>() : null; Renderer.InitializeDepthBuffer(grid); if (Cursor != null) { Cursor.Dispose(); } if (Settings.Graphics.HardwareCursors) { try { Cursor = new HardwareCursor(ModData.CursorProvider); } catch (Exception e) { Log.Write("debug", "Failed to initialize hardware cursors. Falling back to software cursors."); Log.Write("debug", "Error was: " + e.Message); Console.WriteLine("Failed to initialize hardware cursors. Falling back to software cursors."); Console.WriteLine("Error was: " + e.Message); Cursor = new SoftwareCursor(ModData.CursorProvider); } } else { Cursor = new SoftwareCursor(ModData.CursorProvider); } PerfHistory.Items["render"].HasNormalTick = false; PerfHistory.Items["batches"].HasNormalTick = false; PerfHistory.Items["render_widgets"].HasNormalTick = false; PerfHistory.Items["render_flip"].HasNormalTick = false; JoinLocal(); try { if (discoverNat != null) { discoverNat.Wait(); } } catch (Exception e) { Console.WriteLine("NAT discovery failed: {0}", e.Message); Log.Write("nat", e.ToString()); } ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor); ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor); ModData.LoadScreen.StartGame(args); }
public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; OnRemoteDirectConnect = endpoint => { }; delayedActions = new ActionQueue(); Ui.ResetAll(); worldRenderer?.Dispose(); worldRenderer = null; server?.Shutdown(); OrderManager?.Dispose(); if (ModData != null) { ModData.ModFiles.UnmountAll(); ModData.Dispose(); } ModData = null; if (mod == null) { throw new InvalidOperationException("Game.Mod argument missing."); } if (!Mods.ContainsKey(mod)) { throw new InvalidOperationException($"Unknown or invalid mod '{mod}'."); } Console.WriteLine("Loading mod: {0}", mod); Sound.StopVideo(); ModData = new ModData(Mods[mod], Mods, true); LocalPlayerProfile = new LocalPlayerProfile(Path.Combine(Platform.SupportDir, Settings.Game.AuthProfile), ModData.Manifest.Get <PlayerDatabase>()); if (!ModData.LoadScreen.BeforeLoad()) { return; } ModData.InitializeLoaders(ModData.DefaultFileSystem); Renderer.InitializeFonts(ModData); using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); var grid = ModData.Manifest.Contains <MapGrid>() ? ModData.Manifest.Get <MapGrid>() : null; Renderer.InitializeDepthBuffer(grid); Cursor?.Dispose(); Cursor = new CursorManager(ModData.CursorProvider); PerfHistory.Items["render"].HasNormalTick = false; PerfHistory.Items["batches"].HasNormalTick = false; PerfHistory.Items["render_world"].HasNormalTick = false; PerfHistory.Items["render_widgets"].HasNormalTick = false; PerfHistory.Items["render_flip"].HasNormalTick = false; PerfHistory.Items["terrain_lighting"].HasNormalTick = false; JoinLocal(); ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor); ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor); if (!ChromeMetrics.TryGet("SystemMessageLabel", out systemMessageLabel)) { systemMessageLabel = "Battlefield Control"; } ModData.LoadScreen.StartGame(args); }
public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; OnRemoteDirectConnect = (a, b) => { }; delayedActions = new ActionQueue(); Ui.ResetAll(); if (worldRenderer != null) { worldRenderer.Dispose(); } worldRenderer = null; if (server != null) { server.Shutdown(); } if (OrderManager != null) { OrderManager.Dispose(); } if (ModData != null) { ModData.ModFiles.UnmountAll(); ModData.Dispose(); } ModData = null; // Fall back to default if the mod doesn't exist or has missing prerequisites. if (!IsModInstalled(mod)) { mod = new GameSettings().Mod; } Console.WriteLine("Loading mod: {0}", mod); Settings.Game.Mod = mod; Sound.StopVideo(); ModData = new ModData(Mods[mod], Mods, true); using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); // Mod assets are missing! if (!ModData.LoadScreen.RequiredContentIsInstalled()) { InitializeMod("modchooser", new Arguments()); return; } ModData.InitializeLoaders(ModData.DefaultFileSystem); Renderer.InitializeFonts(ModData); var grid = ModData.Manifest.Contains <MapGrid>() ? ModData.Manifest.Get <MapGrid>() : null; Renderer.InitializeDepthBuffer(grid); if (Cursor != null) { Cursor.Dispose(); } if (Settings.Graphics.HardwareCursors) { try { Cursor = new HardwareCursor(ModData.CursorProvider); } catch (Exception e) { Log.Write("debug", "Failed to initialize hardware cursors. Falling back to software cursors."); Log.Write("debug", "Error was: " + e.Message); Console.WriteLine("Failed to initialize hardware cursors. Falling back to software cursors."); Console.WriteLine("Error was: " + e.Message); Cursor = new SoftwareCursor(ModData.CursorProvider); } } else { Cursor = new SoftwareCursor(ModData.CursorProvider); } PerfHistory.Items["render"].HasNormalTick = false; PerfHistory.Items["batches"].HasNormalTick = false; PerfHistory.Items["render_widgets"].HasNormalTick = false; PerfHistory.Items["render_flip"].HasNormalTick = false; JoinLocal(); try { if (discoverNat != null) { discoverNat.Wait(); } } catch (Exception e) { Console.WriteLine("NAT discovery failed: {0}", e.Message); Log.Write("nat", e.ToString()); Settings.Server.AllowPortForward = false; } ModData.LoadScreen.StartGame(args); }
public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; AddChatLine = (a, b, c) => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; Ui.ResetAll(); worldRenderer = null; if (server != null) { server.Shutdown(); } if (orderManager != null) { orderManager.Dispose(); } // Fall back to default if the mod doesn't exist if (!ModMetadata.AllMods.ContainsKey(mod)) { mod = new GameSettings().Mod; } Console.WriteLine("Loading mod: {0}", mod); Settings.Game.Mod = mod; Sound.StopMusic(); Sound.StopVideo(); Sound.Initialize(); modData = new ModData(mod); Renderer.InitializeFonts(modData.Manifest); modData.InitializeLoaders(); using (new PerfTimer("LoadMaps")) modData.MapCache.LoadMaps(); PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["render_widgets"].hasNormalTick = false; PerfHistory.items["render_flip"].hasNormalTick = false; JoinLocal(); if (Settings.Server.Dedicated) { while (true) { Settings.Server.Map = WidgetUtils.ChooseInitialMap(Settings.Server.Map); Settings.Save(); CreateServer(new ServerSettings(Settings.Server)); while (true) { System.Threading.Thread.Sleep(100); if (server.State == Server.ServerState.GameStarted && server.Conns.Count < 1) { Console.WriteLine("No one is playing, shutting down..."); server.Shutdown(); break; } } if (Settings.Server.DedicatedLoop) { Console.WriteLine("Starting a new server instance..."); modData.MapCache.LoadMaps(); continue; } break; } Environment.Exit(0); } else { var window = args != null?args.GetValue("Launch.Window", null) : null; if (!string.IsNullOrEmpty(window)) { var installData = modData.Manifest.ContentInstaller; if (installData.InstallerBackgroundWidget != null) { Ui.LoadWidget(installData.InstallerBackgroundWidget, Ui.Root, new WidgetArgs()); } Widgets.Ui.OpenWindow(window, new WidgetArgs()); } else { modData.LoadScreen.StartGame(); Settings.Save(); var replay = args != null?args.GetValue("Launch.Replay", null) : null; if (!string.IsNullOrEmpty(replay)) { Game.JoinReplay(replay); } } } }
public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; OnRemoteDirectConnect = (a, b) => { }; delayedActions = new ActionQueue(); Ui.ResetAll(); if (worldRenderer != null) { worldRenderer.Dispose(); } worldRenderer = null; if (server != null) { server.Shutdown(); } if (OrderManager != null) { OrderManager.Dispose(); } if (ModData != null) { ModData.Dispose(); } ModData = null; // Fall back to default if the mod doesn't exist if (!ModMetadata.AllMods.ContainsKey(mod)) { mod = new GameSettings().Mod; } Console.WriteLine("Loading mod: {0}", mod); Settings.Game.Mod = mod; Sound.StopVideo(); Sound.Initialize(); ModData = new ModData(mod, !Settings.Server.Dedicated); using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); if (Settings.Server.Dedicated) { RunDedicatedServer(); Environment.Exit(0); } var installData = ModData.Manifest.Get <ContentInstaller>(); var isModContentInstalled = installData.TestFiles.All(f => File.Exists(Platform.ResolvePath(f))); // Mod assets are missing! if (!isModContentInstalled) { InitializeMod("modchooser", new Arguments()); return; } ModData.MountFiles(); ModData.InitializeLoaders(); Renderer.InitializeFonts(ModData.Manifest); if (Cursor != null) { Cursor.Dispose(); } if (Settings.Graphics.HardwareCursors) { try { Cursor = new HardwareCursor(ModData.CursorProvider); } catch (Exception e) { Log.Write("debug", "Failed to initialize hardware cursors. Falling back to software cursors."); Log.Write("debug", "Error was: " + e.Message); Console.WriteLine("Failed to initialize hardware cursors. Falling back to software cursors."); Console.WriteLine("Error was: " + e.Message); Cursor = new SoftwareCursor(ModData.CursorProvider); } } else { Cursor = new SoftwareCursor(ModData.CursorProvider); } PerfHistory.Items["render"].HasNormalTick = false; PerfHistory.Items["batches"].HasNormalTick = false; PerfHistory.Items["render_widgets"].HasNormalTick = false; PerfHistory.Items["render_flip"].HasNormalTick = false; JoinLocal(); ModData.LoadScreen.StartGame(args); }
public static void InitializeWithMod(string mod) { // Clear static state if we have switched mods LobbyInfoChanged = () => { }; AddChatLine = (a, b, c) => { }; ConnectionStateChanged = om => { }; BeforeGameStart = () => { }; Ui.ResetAll(); worldRenderer = null; if (server != null) { server.Shutdown(); } if (orderManager != null) { orderManager.Dispose(); } // Fall back to RA if the mod doesn't exist if (!Mod.AllMods.ContainsKey(mod)) { mod = "ra"; } Console.WriteLine("Loading mod: {0}", mod); Settings.Game.Mod = mod; Sound.StopMusic(); Sound.StopVideo(); Sound.Initialize(); modData = new ModData(mod); Renderer.InitializeFonts(modData.Manifest); modData.InitializeLoaders(); PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["render_widgets"].hasNormalTick = false; PerfHistory.items["render_flip"].hasNormalTick = false; JoinLocal(); if (Settings.Server.Dedicated) { while (true) { Settings.Server.Map = WidgetUtils.ChooseInitialMap(Settings.Server.Map); Settings.Save(); CreateServer(new ServerSettings(Settings.Server)); while (true) { System.Threading.Thread.Sleep(100); if (server.State == Server.ServerState.GameStarted && server.Conns.Count <= 1) { Console.WriteLine("No one is playing, shutting down..."); server.Shutdown(); break; } } if (Settings.Server.DedicatedLoop) { Console.WriteLine("Starting a new server instance..."); continue; } break; } Environment.Exit(0); } else { modData.LoadScreen.StartGame(); Settings.Save(); } }
public static void InitializeWithMods(string[] mods) { // Clear static state if we have switched mods LobbyInfoChanged = () => {}; AddChatLine = (a, b, c) => {}; ConnectionStateChanged = om => {}; BeforeGameStart = () => {}; Ui.ResetAll(); worldRenderer = null; if (server != null) { server.Shutdown(); } if (orderManager != null) { orderManager.Dispose(); } // Discard any invalid mods, set RA as default var mm = mods.Where(m => Mod.AllMods.ContainsKey(m)).ToArray(); if (mm.Length == 0) { mm = new[] { "ra" } } ; Console.WriteLine("Loading mods: {0}", mm.JoinWith(",")); Settings.Game.Mods = mm; Sound.StopMusic(); Sound.StopVideo(); Sound.Initialize(); modData = new ModData(mm); Renderer.InitializeFonts(modData.Manifest); modData.InitializeLoaders(); PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["render_widgets"].hasNormalTick = false; PerfHistory.items["render_flip"].hasNormalTick = false; JoinLocal(); viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer); if (Game.Settings.Server.Dedicated) { while (true) { Game.Settings.Server.Map = WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map); Game.Settings.Save(); Game.CreateServer(new ServerSettings(Game.Settings.Server)); while (true) { System.Threading.Thread.Sleep(100); if ((server.State == Server.ServerState.GameStarted) && (server.conns.Count <= 1)) { Console.WriteLine("No one is playing, shutting down..."); server.Shutdown(); break; } } if (Game.Settings.Server.DedicatedLoop) { Console.WriteLine("Starting a new server instance..."); continue; } else { break; } } System.Environment.Exit(0); } else { modData.LoadScreen.StartGame(); Settings.Save(); } }