private Engine(Settings settings) { Instance = this; _settings = settings ?? ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, "settings.json")); if (_settings == null) { SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No `setting.json`", "A `settings.json` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow()); Log.Message(LogTypes.Trace, "settings.json file not found"); _settings = new Settings(); _settings.Save(); IsQuitted = true; return; } TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS); IsFixedTimeStep = _settings.FixedTimeStep; _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; _window = Window; Window.ClientSizeChanged += (sender, e) => { int width = Window.ClientBounds.Width; int height = Window.ClientBounds.Height; if (_isHighDPI) { width *= 2; height *= 2; } _graphicDeviceManager.PreferredBackBufferWidth = width; _graphicDeviceManager.PreferredBackBufferHeight = height; _graphicDeviceManager.ApplyChanges(); WorldViewportGump gump = _uiManager.GetByLocalSerial <WorldViewportGump>(); if (gump != null && _profileManager.Current.GameWindowFullSize) { gump.ResizeWindow(new Point(WindowWidth, WindowHeight)); } }; Window.AllowUserResizing = true; IsMouseVisible = true; }
public static void Load() { LastCharacters = new List <LastCharacterInfo>(); if (!File.Exists(_lastCharacterFile)) { ConfigurationResolver.Save(LastCharacters, _lastCharacterFile); } LastCharacters = ConfigurationResolver.Load <List <LastCharacterInfo> >(_lastCharacterFile); // safety check if (LastCharacters == null) { LastCharacters = new List <LastCharacterInfo>(); } }
private Engine() { _settings = ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, "settings.json")); if (_settings == null) { SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "No `setting.json`", "A `settings.json` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow()); Log.Message(LogTypes.Trace, "settings.json file was not found creating default"); _settings = new Settings(); _settings.Save(); Quit(); return; } if (_settings.FixedTimeStep) { TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS); } else { IsFixedTimeStep = false; } _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); Window.ClientSizeChanged += (sender, e) => { _graphicDeviceManager.PreferredBackBufferWidth = Window.ClientBounds.Width; _graphicDeviceManager.PreferredBackBufferHeight = Window.ClientBounds.Height; _graphicDeviceManager.ApplyChanges(); }; Window.AllowUserResizing = true; IsMouseVisible = true; }
static void Main(string[] args) { // - check for update // - launcher & user setup // - game setup // - game launch // - enjoy CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; Log.Start(LogTypes.All); CUOEnviroment.GameThread = Thread.CurrentThread; CUOEnviroment.GameThread.Name = "CUO_MAIN_THREAD"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (s, e) => { StringBuilder sb = new StringBuilder(); sb.AppendLine("######################## [START LOG] ########################"); #if DEV_BUILD sb.AppendLine($"ClassicUO [DEV_BUILD] - {CUOEnviroment.Version}"); #else sb.AppendLine($"ClassicUO [STANDARD_BUILD] - {CUOEnviroment.Version}"); #endif sb.AppendLine($"OS: {Environment.OSVersion.Platform} x{(Environment.Is64BitOperatingSystem ? "64" : "86")}"); sb.AppendLine($"Thread: {Thread.CurrentThread.Name}"); sb.AppendLine(); sb.AppendLine($"Protocol: {Client.Protocol}"); sb.AppendLine($"ClientFeatures: {World.ClientFeatures.Flags}"); sb.AppendLine($"ClientLockedFeatures: {World.ClientLockedFeatures.Flags}"); sb.AppendLine($"ClientVersion: {Client.Version}"); sb.AppendLine(); sb.AppendFormat("Exception:\n{0}\n", e.ExceptionObject); sb.AppendLine("######################## [END LOG] ########################"); sb.AppendLine(); sb.AppendLine(); Log.Panic(e.ExceptionObject.ToString()); string path = Path.Combine(CUOEnviroment.ExecutablePath, "Logs"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (LogFile crashfile = new LogFile(path, "crash.txt")) { crashfile.WriteAsync(sb.ToString()).RunSynchronously(); } }; #endif ReadSettingsFromArgs(args); #if DEV_BUILD if (!_skipUpdates) { Updater updater = new Updater(); if (updater.Check()) { return; } } #endif if (!_skipUpdates) { if (CheckUpdate(args)) { return; } } if (CUOEnviroment.IsHighDPI) { Log.Trace("HIGH DPI - ENABLED"); Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "1"); } Environment.SetEnvironmentVariable("FNA3D_BACKBUFFER_SCALE_NEAREST", "1"); Environment.SetEnvironmentVariable("FNA3D_OPENGL_FORCE_COMPATIBILITY_PROFILE", "1"); Environment.SetEnvironmentVariable(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Plugins")); string globalSettingsPath = Settings.GetSettingsFilepath(); if ((!Directory.Exists(Path.GetDirectoryName(globalSettingsPath)) || !File.Exists(globalSettingsPath))) { // settings specified in path does not exists, make new one { // TODO: Settings.GlobalSettings.Save(); } } Settings.GlobalSettings = ConfigurationResolver.Load <Settings>(globalSettingsPath); CUOEnviroment.IsOutlands = Settings.GlobalSettings.ShardType == 2; ReadSettingsFromArgs(args); // still invalid, cannot load settings if (Settings.GlobalSettings == null) { Settings.GlobalSettings = new Settings(); Settings.GlobalSettings.Save(); } if (!CUOEnviroment.IsUnix) { string libsPath = Path.Combine(CUOEnviroment.ExecutablePath, Environment.Is64BitProcess ? "x64" : "x86"); SetDllDirectory(libsPath); } // FIXME: force to use OpenGL in osx and linux contexts. Metal wants texture converted in .Color instead of BGRA5551. // Check the branch "fna3d-macos-fix" /*if (CUOEnviroment.IsUnix) * { * Environment.SetEnvironmentVariable("FNA3D_FORCE_DRIVER", "OpenGL"); * } */ if (string.IsNullOrWhiteSpace(Settings.GlobalSettings.UltimaOnlineDirectory)) { Settings.GlobalSettings.UltimaOnlineDirectory = CUOEnviroment.ExecutablePath; } const uint INVALID_UO_DIRECTORY = 0x100; const uint INVALID_UO_VERSION = 0x200; uint flags = 0; if (!Directory.Exists(Settings.GlobalSettings.UltimaOnlineDirectory) || !File.Exists(UOFileManager.GetUOFilePath("tiledata.mul"))) { flags |= INVALID_UO_DIRECTORY; } string clientVersionText = Settings.GlobalSettings.ClientVersion; if (!ClientVersionHelper.IsClientVersionValid(Settings.GlobalSettings.ClientVersion, out var clientVersion)) { Log.Warn($"Client version [{clientVersionText}] is invalid, let's try to read the client.exe"); // mmm something bad happened, try to load from client.exe [windows only] if (!ClientVersionHelper.TryParseFromFile(Path.Combine(Settings.GlobalSettings.UltimaOnlineDirectory, "client.exe"), out clientVersionText) || !ClientVersionHelper.IsClientVersionValid(clientVersionText, out clientVersion)) { Log.Error("Invalid client version: " + clientVersionText); flags |= INVALID_UO_VERSION; } else { Log.Trace($"Found a valid client.exe [{clientVersionText} - {clientVersion}]"); // update the wrong/missing client version in settings.json Settings.GlobalSettings.ClientVersion = clientVersionText; } } if (flags != 0) { if ((flags & INVALID_UO_DIRECTORY) != 0) { Client.ShowErrorMessage("Your Ultima Online directory seems to be invalid.\nDownload the official Launcher to setup and run your game.\n\nLink: classicuo.eu"); } else if ((flags & INVALID_UO_VERSION) != 0) { Client.ShowErrorMessage("Your Ultima Online client version seems to be invalid.\nDownload the official Launcher to setup and run your game.\n\nLink: classicuo.eu"); } try { Process.Start("https://classicuo.eu"); } catch { } } else { switch (Settings.GlobalSettings.ForceDriver) { case 1: // OpenGL Environment.SetEnvironmentVariable("FNA3D_FORCE_DRIVER", "OpenGL"); break; case 2: // Vulkan Environment.SetEnvironmentVariable("FNA3D_FORCE_DRIVER", "Vulkan"); break; } Client.Run(); } Log.Trace("Closing..."); }
static void Main(string[] args) { // - check for update // - launcher & user setup // - game setup // - game launch // - enjoy Log.Start(LogTypes.All); CUOEnviroment.GameThread = Thread.CurrentThread; CUOEnviroment.GameThread.Name = "CUO_MAIN_THREAD"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (s, e) => { StringBuilder sb = new StringBuilder(); sb.AppendLine("######################## [START LOG] ########################"); #if DEV_BUILD sb.AppendLine($"ClassicUO [DEV_BUILD] - {CUOEnviroment.Version}"); #else sb.AppendLine($"ClassicUO [STANDARD_BUILD] - {CUOEnviroment.Version}"); #endif sb.AppendLine($"OS: {Environment.OSVersion.Platform} x{(Environment.Is64BitOperatingSystem ? "64" : "86")}"); sb.AppendLine($"Thread: {Thread.CurrentThread.Name}"); sb.AppendLine(); sb.AppendLine($"Protocol: {Client.Protocol}"); sb.AppendLine($"ClientFeatures: {World.ClientFeatures.Flags}"); sb.AppendLine($"ClientLockedFeatures: {World.ClientLockedFeatures.Flags}"); sb.AppendLine($"ClientVersion: {Client.Version}"); sb.AppendLine(); sb.AppendFormat("Exception:\n{0}\n", e.ExceptionObject); sb.AppendLine("######################## [END LOG] ########################"); sb.AppendLine(); sb.AppendLine(); Log.Panic(e.ExceptionObject.ToString()); string path = Path.Combine(CUOEnviroment.ExecutablePath, "Logs"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (LogFile crashfile = new LogFile(path, "crash.txt")) { crashfile.WriteAsync(sb.ToString()).RunSynchronously(); } }; #endif #if DEV_BUILD Updater updater = new Updater(); if (updater.Check()) { return; } #endif ReadSettingsFromArgs(args); if (!_skipUpdates) { if (CheckUpdate(args)) { return; } } //Environment.SetEnvironmentVariable("FNA_GRAPHICS_FORCE_GLDEVICE", "ModernGLDevice"); Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", CUOEnviroment.IsHighDPI ? "1" : "0"); Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); Environment.SetEnvironmentVariable("FNA_OPENGL_FORCE_COMPATIBILITY_PROFILE", "1"); Environment.SetEnvironmentVariable(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Plugins")); string globalSettingsPath = Settings.GetSettingsFilepath(); if ((!Directory.Exists(Path.GetDirectoryName(globalSettingsPath)) || !File.Exists(globalSettingsPath))) { // settings specified in path does not exists, make new one { // TODO: Settings.GlobalSettings.Save(); return; } } Settings.GlobalSettings = ConfigurationResolver.Load <Settings>(globalSettingsPath); ReadSettingsFromArgs(args); // still invalid, cannot load settings if (Settings.GlobalSettings == null) { Settings.GlobalSettings = new Settings(); Settings.GlobalSettings.Save(); } if (!CUOEnviroment.IsUnix) { string libsPath = Path.Combine(CUOEnviroment.ExecutablePath, "libs", Environment.Is64BitProcess ? "x64" : "x86"); SetDllDirectory(libsPath); } if (string.IsNullOrWhiteSpace(Settings.GlobalSettings.UltimaOnlineDirectory)) { Settings.GlobalSettings.UltimaOnlineDirectory = CUOEnviroment.ExecutablePath; } Client.Run(); Log.Trace("Closing..."); }
protected override void Initialize() { Settings settings = ConfigurationResolver.Load <Settings>(Path.Combine(Bootstrap.ExeDirectory, "settings.json")); if (settings == null) { Log.Message(LogTypes.Trace, "settings.json file was not found creating default"); settings = new Settings(); ConfigurationResolver.Save(settings, "settings.json"); Process.Start("notepad.exe", "settings.json"); Exit(); return; } Service.Register(settings); Log.Message(LogTypes.Trace, "Checking for Ultima Online installation..."); try { FileManager.UoFolderPath = settings.UltimaOnlineDirectory; } catch (FileNotFoundException e) { Log.Message(LogTypes.Error, "Wrong Ultima Online installation folder."); throw e; } Log.Message(LogTypes.Trace, "Done!"); Log.Message(LogTypes.Trace, $"Ultima Online installation folder: {FileManager.UoFolderPath}"); Log.Message(LogTypes.Trace, "Loading files..."); Stopwatch stopwatch = Stopwatch.StartNew(); FileManager.LoadFiles(); uint[] hues = Hues.CreateShaderColors(); Texture2D texture0 = new Texture2D(GraphicsDevice, 32, Hues.HuesCount); texture0.SetData(hues, 0, 32 * Hues.HuesCount); Texture2D texture1 = new Texture2D(GraphicsDevice, 32, Hues.HuesCount); texture1.SetData(hues, 32 * Hues.HuesCount, 32 * Hues.HuesCount); GraphicsDevice.Textures[1] = texture0; GraphicsDevice.Textures[2] = texture1; Log.Message(LogTypes.Trace, $"Files loaded in: {stopwatch.ElapsedMilliseconds} ms!"); stopwatch.Stop(); InputManager.Initialize(); //Register Service Stack Service.Register(this); Service.Register(_sb3D = new SpriteBatch3D(GraphicsDevice)); Service.Register(_sbUI = new SpriteBatchUI(GraphicsDevice)); Service.Register(_uiManager = new UIManager()); //Register Command Stack Commands.Initialize(); Log.Message(LogTypes.Trace, "Network calibration..."); PacketHandlers.Load(); PacketsTable.AdjustPacketSizeByVersion(FileManager.ClientVersion); Log.Message(LogTypes.Trace, "Done!"); MaxFPS = settings.MaxFPS; _infoText = new RenderedText { IsUnicode = true, Font = 3, FontStyle = FontStyle.BlackBorder, Align = TEXT_ALIGN_TYPE.TS_LEFT, MaxWidth = 150 }; base.Initialize(); }
static void Main(string[] args) { // - check for update // - launcher & user setup // - game setup // - game launch // - enjoy Log.Start(LogTypes.All); CUOEnviroment.GameThread = Thread.CurrentThread; CUOEnviroment.GameThread.Name = "CUO_MAIN_THREAD"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (s, e) => { StringBuilder sb = new StringBuilder(); #if DEV_BUILD sb.AppendFormat("ClassicUO [dev] - v{0}\nOS: {1} {2}\nThread: {3}\n\n", CUOEnviroment.Version, Environment.OSVersion.Platform, Environment.Is64BitOperatingSystem ? "x64" : "x86", Thread.CurrentThread.Name); #else sb.AppendFormat("ClassicUO - v{0}\nOS: {1} {2}\nThread: {3}\n\n", CUOEnviroment.Version, Environment.OSVersion.Platform, Environment.Is64BitOperatingSystem ? "x64" : "x86", Thread.CurrentThread.Name); #endif sb.AppendFormat("Exception:\n{0}", e.ExceptionObject); Log.Panic(e.ExceptionObject.ToString()); string path = Path.Combine(CUOEnviroment.ExecutablePath, "Logs"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (LogFile crashfile = new LogFile(path, "crash.txt")) { crashfile.WriteAsync(sb.ToString()).RunSynchronously(); //SDL.SDL_ShowSimpleMessageBox( // SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, // "An error occurred", // $"{crashfile}\ncreated in /Logs.", // SDL.SDL_GL_GetCurrentWindow() // ); } }; #endif #if DEV_BUILD Updater updater = new Updater(); if (updater.Check()) { return; } #endif ReadSettingsFromArgs(args); if (!SkipUpdate) { if (CheckUpdate(args)) { return; } } Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", CUOEnviroment.IsHighDPI ? "1" : "0"); Environment.SetEnvironmentVariable("FNA_OPENGL_BACKBUFFER_SCALE_NEAREST", "1"); Environment.SetEnvironmentVariable("FNA_OPENGL_FORCE_COMPATIBILITY_PROFILE", "1"); Environment.SetEnvironmentVariable(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Plugins")); string globalSettingsPath = Settings.GetSettingsFilepath(); if ((!Directory.Exists(Path.GetDirectoryName(globalSettingsPath)) || !File.Exists(globalSettingsPath))) { // settings specified in path does not exists, make new one { // TODO: Settings.GlobalSettings.Save(); return; } } Settings.GlobalSettings = ConfigurationResolver.Load <Settings>(globalSettingsPath); ReadSettingsFromArgs(args); // still invalid, cannot load settings if (Settings.GlobalSettings == null || !Settings.GlobalSettings.IsValid()) { // TODO: Settings.GlobalSettings?.Save(); return; } if (!CUOEnviroment.IsUnix) { string libsPath = Path.Combine(CUOEnviroment.ExecutablePath, "libs", Environment.Is64BitProcess ? "x64" : "x86"); SetDllDirectory(libsPath); } CUOEnviroment.Client = new GameController(); CUOEnviroment.Client.Run(); CUOEnviroment.Client.Dispose(); Log.Trace("Closing..."); }
private Engine(string[] args) { Instance = this; // By default try to load settings from main settings file _settings = ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, SettingsFile)); // Try to apply any settings passed from the command-line/shortcut to what we loaded from file // NOTE: If nothing was loaded from settings file (file doesn't exist), then it will create // a new settings object and populate it with the passed settings ArgsParser(args, _settings); // If no still no settings after loading a file and parsing command-line settings, // then show an error, generate default settings file and exit if (_settings == null) { SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No `" + SettingsFile + "`", "A `" + SettingsFile + "` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow()); Log.Message(LogTypes.Trace, SettingsFile + " file not found"); _settings = new Settings(); _settings.Save(); IsQuitted = true; return; } // If settings are invalid, then show an error and exit if (!_settings.IsValid()) { SDL.SDL_ShowSimpleMessageBox( SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "Invalid settings", "Please, check your settings.\nYou should at least set `ultimaonlinedirectory` and `clientversion`.", SDL.SDL_GL_GetCurrentWindow() ); Log.Message(LogTypes.Trace, "Invalid settings"); IsQuitted = true; return; } TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS); IsFixedTimeStep = _settings.FixedTimeStep; _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; _window = Window; Window.ClientSizeChanged += (sender, e) => { int width = Window.ClientBounds.Width; int height = Window.ClientBounds.Height; if (_isHighDPI) { width *= 2; height *= 2; } if (!IsMaximized) { _engine._profileManager.Current.WindowClientBounds = new Point(width, height); } SetPreferredBackBufferSize(width, height); WorldViewportGump gump = _uiManager.GetControl <WorldViewportGump>(); if (gump != null && _profileManager.Current.GameWindowFullSize) { gump.ResizeWindow(new Point(WindowWidth, WindowHeight)); gump.X = -5; gump.Y = -5; } }; Window.AllowUserResizing = true; IsMouseVisible = true; Window.Title = $"ClassicUO - {Version}"; }
public static void Main(string[] args) { CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; Log.Start(LogTypes.All); CUOEnviroment.GameThread = Thread.CurrentThread; CUOEnviroment.GameThread.Name = "CUO_MAIN_THREAD"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (s, e) => { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("######################## [START LOG] ########################"); #if DEV_BUILD sb.AppendLine($"ClassicUO [DEV_BUILD] - {CUOEnviroment.Version} - {DateTime.Now}"); #else sb.AppendLine($"ClassicUO [STANDARD_BUILD] - {CUOEnviroment.Version} - {DateTime.Now}"); #endif sb.AppendLine ($"OS: {Environment.OSVersion.Platform} {(Environment.Is64BitOperatingSystem ? "x64" : "x86")}"); sb.AppendLine($"Thread: {Thread.CurrentThread.Name}"); sb.AppendLine(); if (Settings.GlobalSettings != null) { sb.AppendLine($"Shard: {Settings.GlobalSettings.IP}"); sb.AppendLine($"ClientVersion: {Settings.GlobalSettings.ClientVersion}"); sb.AppendLine(); } sb.AppendFormat("Exception:\n{0}\n", e.ExceptionObject); sb.AppendLine("######################## [END LOG] ########################"); sb.AppendLine(); sb.AppendLine(); Log.Panic(e.ExceptionObject.ToString()); string path = Path.Combine(CUOEnviroment.ExecutablePath, "Logs"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (LogFile crashfile = new LogFile(path, "crash.txt")) { crashfile.WriteAsync(sb.ToString()).RunSynchronously(); } }; #endif ReadSettingsFromArgs(args); #if DEV_BUILD if (!_skipUpdates) { Network.Updater updater = new Network.Updater(); if (updater.Check()) { return; } } #endif if (!_skipUpdates) { if (CheckUpdate(args)) { return; } } if (CUOEnviroment.IsHighDPI) { Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "1"); } Environment.SetEnvironmentVariable("FNA3D_BACKBUFFER_SCALE_NEAREST", "1"); Environment.SetEnvironmentVariable("FNA3D_OPENGL_FORCE_COMPATIBILITY_PROFILE", "1"); Environment.SetEnvironmentVariable(SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Plugins")); string globalSettingsPath = Settings.GetSettingsFilepath(); if (!Directory.Exists(Path.GetDirectoryName(globalSettingsPath)) || !File.Exists(globalSettingsPath)) { // settings specified in path does not exists, make new one { // TODO: Settings.GlobalSettings.Save(); } } Settings.GlobalSettings = ConfigurationResolver.Load <Settings>(globalSettingsPath); CUOEnviroment.IsOutlands = Settings.GlobalSettings.ShardType == 2; ReadSettingsFromArgs(args); // still invalid, cannot load settings if (Settings.GlobalSettings == null) { Settings.GlobalSettings = new Settings(); Settings.GlobalSettings.Save(); } if (!CUOEnviroment.IsUnix) { string libsPath = Path.Combine(CUOEnviroment.ExecutablePath, Environment.Is64BitProcess ? "x64" : "x86"); SetDllDirectory(libsPath); } if (string.IsNullOrWhiteSpace(Settings.GlobalSettings.UltimaOnlineDirectory)) { Settings.GlobalSettings.UltimaOnlineDirectory = CUOEnviroment.ExecutablePath; } const uint INVALID_UO_DIRECTORY = 0x100; const uint INVALID_UO_VERSION = 0x200; uint flags = 0; if (!Directory.Exists(Settings.GlobalSettings.UltimaOnlineDirectory) || !File.Exists(UOFileManager.GetUOFilePath("tiledata.mul"))) { flags |= INVALID_UO_DIRECTORY; } string clientVersionText = Settings.GlobalSettings.ClientVersion; if (!ClientVersionHelper.IsClientVersionValid(Settings.GlobalSettings.ClientVersion, out ClientVersion clientVersion)) { Log.Warn($"Client version [{clientVersionText}] is invalid, let's try to read the client.exe"); // mmm something bad happened, try to load from client.exe [windows only] if (!ClientVersionHelper.TryParseFromFile(Path.Combine(Settings.GlobalSettings.UltimaOnlineDirectory, "client.exe"), out clientVersionText) || !ClientVersionHelper.IsClientVersionValid(clientVersionText, out clientVersion)) { Log.Error("Invalid client version: " + clientVersionText); flags |= INVALID_UO_VERSION; } else { Log.Trace($"Found a valid client.exe [{clientVersionText} - {clientVersion}]"); // update the wrong/missing client version in settings.json Settings.GlobalSettings.ClientVersion = clientVersionText; } } if (flags != 0) { if ((flags & INVALID_UO_DIRECTORY) != 0) { Client.ShowErrorMessage(ResGeneral.YourUODirectoryIsInvalid); } else if ((flags & INVALID_UO_VERSION) != 0) { Client.ShowErrorMessage(ResGeneral.YourUOClientVersionIsInvalid); } PlatformHelper.LaunchBrowser(ResGeneral.ClassicUOLink); } else { switch (Settings.GlobalSettings.ForceDriver) { case 1: // OpenGL Environment.SetEnvironmentVariable("FNA3D_FORCE_DRIVER", "OpenGL"); break; case 2: // Vulkan Environment.SetEnvironmentVariable("FNA3D_FORCE_DRIVER", "Vulkan"); break; } Client.Run(); } Log.Trace("Closing..."); }
protected override void Initialize() { //uncomment it and fill it to save your first settings //Settings settings1 = new Settings() //{ //}; //ConfigurationResolver.Save(settings1, "settings.json"); Settings settings = ConfigurationResolver.Load <Settings>(Path.Combine(Bootstrap.ExeDirectory, "settings.json")); Service.Register(settings); Log.Message(LogTypes.Trace, "Checking for Ultima Online installation..."); try { FileManager.UoFolderPath = settings.UltimaOnlineDirectory; } catch (FileNotFoundException e) { Log.Message(LogTypes.Error, "Wrong Ultima Online installation folder."); throw e; } Log.Message(LogTypes.Trace, "Done!"); Log.Message(LogTypes.Trace, $"Ultima Online installation folder: {FileManager.UoFolderPath}"); Log.Message(LogTypes.Trace, "Loading files..."); Stopwatch stopwatch = Stopwatch.StartNew(); FileManager.LoadFiles(); uint[] hues = Hues.CreateShaderColors(); Texture2D texture0 = new Texture2D(GraphicsDevice, 32, 3000); texture0.SetData(hues, 0, 32 * 3000); Texture2D texture1 = new Texture2D(GraphicsDevice, 32, 3000); texture1.SetData(hues, 32 * 3000, 32 * 3000); GraphicsDevice.Textures[1] = texture0; GraphicsDevice.Textures[2] = texture1; Log.Message(LogTypes.Trace, $"Files loaded in: {stopwatch.ElapsedMilliseconds} ms!"); stopwatch.Stop(); //Register Service Stack Service.Register(this); Service.Register(new SpriteBatch3D(GraphicsDevice)); Service.Register(new SpriteBatchUI(GraphicsDevice)); Service.Register(new InputManager()); Service.Register(_uiManager = new UIManager()); Service.Register(_sceneManager = new SceneManager()); Service.Register(_journalManager = new JournalData()); //Register Command Stack PartySystem.RegisterCommands(); _inputManager = Service.Get <InputManager>(); _sb3D = Service.Get <SpriteBatch3D>(); _sbUI = Service.Get <SpriteBatchUI>(); Log.Message(LogTypes.Trace, "Network calibration..."); PacketHandlers.Load(); PacketsTable.AdjustPacketSizeByVersion(FileManager.ClientVersion); Log.Message(LogTypes.Trace, "Done!"); MaxFPS = settings.MaxFPS; _sceneManager.ChangeScene(ScenesType.Login); _infoText = new RenderedText { IsUnicode = true, Font = 3, FontStyle = FontStyle.BlackBorder, Align = TEXT_ALIGN_TYPE.TS_LEFT, MaxWidth = 150 }; base.Initialize(); }
private Engine(string[] args) { Instance = this; string settingsFilepath = Settings.GetSettingsFilepath(); Console.WriteLine($"SETTINGS FILE: {settingsFilepath}"); // Check settings file for existence if (!Directory.Exists(Path.GetDirectoryName(settingsFilepath)) || !File.Exists(settingsFilepath)) { Log.Message(LogTypes.Trace, "Settings file not found"); Directory.CreateDirectory(Path.GetDirectoryName(settingsFilepath)); // Make sure we have full path in place _settings = new Settings(); _settings.Save(); SDL.SDL_ShowSimpleMessageBox( SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No settings", $"A new settings file has been created: {settingsFilepath}\n\n" + "Please, open it with a text editor and at least set `ultimaonlinedirectory` and `clientversion` options.", SDL.SDL_GL_GetCurrentWindow() ); IsQuitted = true; return; } // Firstly, try to load settings from either main or custom settings file // TODO: Wrap it in the `try..catch` block to catch potential JSON parsing errors _settings = ConfigurationResolver.Load <Settings>(settingsFilepath); // Secondly, Try to apply any settings passed from the command-line/shortcut options over those // we loaded from the settings file // NOTE: If nothing was loaded from settings file (file doesn't exist), then it will create // a new settings object and populate it with the passed settings ArgsParser(args, _settings); // If no settings loaded from file, no settings parsed from command-line options, // or if settings are invalid, then show an error and exit if (_settings == null || !_settings.IsValid()) { Log.Message(LogTypes.Trace, "Invalid settings"); SDL.SDL_ShowSimpleMessageBox( SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "Invalid settings", "Please, check your settings.\n\n" + "You should at least set `ultimaonlinedirectory` and `clientversion`.", SDL.SDL_GL_GetCurrentWindow() ); IsQuitted = true; return; } TargetElapsedTime = TimeSpan.FromSeconds(1.0f / Constants.MAX_FPS); IsFixedTimeStep = _settings.FixedTimeStep; _graphicDeviceManager = new GraphicsDeviceManager(this); _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef)) { _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef; } _graphicDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8; _graphicDeviceManager.SynchronizeWithVerticalRetrace = false; _graphicDeviceManager.ApplyChanges(); _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; _window = Window; Window.ClientSizeChanged += (sender, e) => { int width = Window.ClientBounds.Width; int height = Window.ClientBounds.Height; if (_isHighDPI) { width *= 2; height *= 2; } if (!IsMaximized) { _engine._profileManager.Current.WindowClientBounds = new Point(width, height); } SetPreferredBackBufferSize(width, height); WorldViewportGump gump = _uiManager.GetGump <WorldViewportGump>(); if (gump != null && _profileManager.Current.GameWindowFullSize) { gump.ResizeWindow(new Point(WindowWidth, WindowHeight)); gump.X = -5; gump.Y = -5; } }; Window.AllowUserResizing = true; IsMouseVisible = _settings.RunMouseInASeparateThread; Window.Title = $"ClassicUO - {Version}"; if (Bootstrap.StartMinimized) { SDL.SDL_MinimizeWindow(Window.Handle); } }