public override Loader_Error LaunchClient(string client) { string dll = Path.Combine(Config.GetInstallDirectory(), "Crypt.dll"); uint pid = 0; Loader_Error err = (Loader_Error)Load(client, dll, "OnAttach", null, 0, out pid); if (err == Loader_Error.SUCCESS) { try { ClientProc = Process.GetProcessById((int)pid); } catch { // ignore } } if (ClientProc == null) { return(Loader_Error.UNKNOWN_ERROR); } else { return(err); } }
static Spell() { ArrayList list = new ArrayList(); string filename = Path.Combine(Config.GetInstallDirectory(), "spells.def"); m_SpellsByPower = new Hashtable(64 + 10 + 16); m_SpellsByID = new Hashtable(64 + 10 + 16); if (!File.Exists(filename)) { MessageBox.Show(Engine.ActiveWindow, Language.GetString(LocString.NoSpells), "Spells.def", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (StreamReader reader = new StreamReader(filename)) { string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line.Length <= 0 || line[0] == '#') { continue; } string[] split = line.Split('|'); try { if (split.Length >= 5) { string[] reags = new string[split.Length - 5]; for (int i = 5; i < split.Length; i++) { reags[i - 5] = split[i].ToLower().Trim(); } Spell s = new Spell(split[0].Trim()[0], Convert.ToInt32(split[1].Trim()), Convert.ToInt32(split[2].Trim()), /*split[3].Trim(),*/ split[4].Trim(), reags); m_SpellsByID[s.GetID()] = s; if (s.WordsOfPower != null && s.WordsOfPower.Trim().Length > 0) { m_SpellsByPower[s.WordsOfPower] = s; } } } catch { } } } HotKeyCallback = new HotKeyCallbackState(OnHotKey); foreach (Spell s in m_SpellsByID.Values) { HotKey.Add(HKCategory.Spells, HKSubCat.SpellOffset + s.Circle, s.Name, HotKeyCallback, (ushort)s.GetID()); } HotKey.Add(HKCategory.Spells, LocString.HealOrCureSelf, new HotKeyCallback(HealOrCureSelf)); HotKey.Add(HKCategory.Spells, LocString.MiniHealOrCureSelf, new HotKeyCallback(MiniHealOrCureSelf)); }
public static void Main(string[] Args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Directory.SetCurrentDirectory(Config.GetInstallDirectory()); #endif /* Load localization files */ string defLang = Config.GetAppSetting <string>("DefaultLanguage"); if (defLang == null) { defLang = "ENU"; } Client.Init(true); if (Client.IsOSI) { Ultima.Files.ReLoadDirectory(); Ultima.Files.LoadMulPath(); } if (!Language.Load(defLang)) { MessageBox.Show( String.Format( "WARNING: Razor was unable to load the file Language/Razor_lang.{0}\n.", defLang), "Language Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } /* Show welcome screen */ if (Config.GetAppSetting <int>("ShowWelcome") != 0) { SplashScreen.End(); WelcomeForm welcome = new WelcomeForm(); m_ActiveWnd = welcome; if (welcome.ShowDialog() == DialogResult.Cancel) { return; } SplashScreen.Start(); m_ActiveWnd = SplashScreen.Instance; } Load(); RunUI(); Close(); }
public static string[] GetPackNames() { string path = Config.GetInstallDirectory("Language"); string[] names = Directory.GetFiles(path, "Razor_lang.*"); for (int i = 0; i < names.Length; i++) { names[i] = Path.GetExtension(names[i]).ToUpper().Substring(1); } return(names); }
public override Loader_Error LaunchClient(string client) { /*string dir = Directory.GetCurrentDirectory(); * Directory.SetCurrentDirectory( Path.GetDirectoryName( client ) ); * Directory.SetCurrentDirectory( dir ); * * try * { * ProcessStartInfo psi = new ProcessStartInfo( client ); * psi.WorkingDirectory = Path.GetDirectoryName( client ); * * ClientProc = Process.Start( psi ); * * if ( ClientProc != null && !Config.GetBool( "SmartCPU" ) ) * ClientProc.PriorityClass = (ProcessPriorityClass)Enum.Parse( typeof(ProcessPriorityClass), Config.GetString( "ClientPrio" ), true ); * } * catch * { * }*/ string dll = Path.Combine(Config.GetInstallDirectory(), "Crypt.dll"); uint pid = 0; Loader_Error err = (Loader_Error)Load(client, dll, "OnAttach", null, 0, out pid); if (err == Loader_Error.SUCCESS) { try { ClientProc = Process.GetProcessById((int)pid); /*if ( ClientProc != null && !Config.GetBool( "SmartCPU" ) ) * ClientProc.PriorityClass = (ProcessPriorityClass)Enum.Parse( typeof(ProcessPriorityClass), Config.GetString( "ClientPrio" ), true );*/ } catch { } } if (ClientProc == null) { return(Loader_Error.UNKNOWN_ERROR); } else { return(err); } }
public static void Run(String clientPath) { m_Running = true; Thread.CurrentThread.Name = "Razor Main Thread"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Directory.SetCurrentDirectory(Config.GetInstallDirectory()); #endif Ultima.Files.SetMulPath(clientPath); if (!Language.Load("ENU")) { MessageBox.Show("Fatal Error: Unable to load required file Language/Razor_lang.enu\nRazor cannot continue.", "No Language Pack", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } Language.LoadCliLoc(); Initialize(typeof(Assistant.Engine).Assembly); Config.LoadCharList(); if (!Config.LoadLastProfile()) { MessageBox.Show("The selected profile could not be loaded, using default instead.", "Profile Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Ultima.Multis.PostHSFormat = UsePostHSChanges; m_MainWnd = new MainForm(); Application.Run(m_MainWnd); m_Running = false; ClientCommunication.Close(); Counter.Save(); Macros.MacroManager.Save(); Config.Save(); }
private static void CheckUpdaterFiles() { string instdir = Config.GetInstallDirectory(); string nUpdater = Path.Combine(instdir, "New_Updater.exe"); string nRar = Path.Combine(instdir, "New_unrar.dll"); if (File.Exists(nUpdater) || File.Exists(nRar)) { if (IsElevated) { if (File.Exists("New_unrar.dll")) { File.Copy("New_unrar.dll", "unrar.dll", true); File.Delete("New_unrar.dll"); } if (File.Exists("New_Updater.exe")) { File.Copy("New_Updater.exe", "Updater.exe", true); File.Delete("New_Updater.exe"); } ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.FileName = Path.Combine(instdir, "Razor.exe"); processInfo.UseShellExecute = false; processInfo.WorkingDirectory = instdir; Process.Start(processInfo); Process.GetCurrentProcess().Kill(); } else { ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.Verb = "runas"; // Administrator Rights processInfo.FileName = Path.Combine(instdir, "Razor.exe"); Process.Start(processInfo); Process.GetCurrentProcess().Kill(); } } }
public static bool Load(string lang) { lang = lang.ToUpper(); if (m_Current != null && m_Current == lang) { return(true); } m_CliLocName = "enu"; string filename = Path.Combine(Config.GetInstallDirectory("Language"), String.Format("Razor_lang.{0}", lang.ToLower())); if (!File.Exists(filename)) { return(false); } m_Current = lang; ArrayList errors = new ArrayList(); Encoding encoding = Encoding.ASCII; using (StreamReader reader = new StreamReader(filename)) { string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); string lower = line.ToLower(); if (line == "" || line[0] == '#' || line[0] == ';' || (line.Length >= 2 && line[0] == '/' && line[1] == '/')) { continue; } else if (lower == "[controls]" || lower == "[strings]") { break; } if (lower.StartsWith("::encoding")) { try { int idx = lower.IndexOf('=') + 1; if (idx > 0 && idx < lower.Length) { encoding = Encoding.GetEncoding(line.Substring(idx).Trim()); } } catch { encoding = null; } if (encoding == null) { MessageBox.Show( "Error: The encoding specified in the language file was not valid. Using ASCII.", "Invalid Encoding", MessageBoxButtons.OK, MessageBoxIcon.Error); encoding = Encoding.ASCII; } break; } } } using (StreamReader reader = new StreamReader(filename, encoding)) { //m_Dict.Clear(); // just overwrite the old lang, rather than erasing it (this way if this lang is missing something, it'll appear in the old one int lineNum = 0; string line; bool controls = true; int idx = 0; while ((line = reader.ReadLine()) != null) { try { line = line.Trim(); lineNum++; if (line == "" || line[0] == '#' || line[0] == ';' || (line.Length >= 2 && line[0] == '/' && line[1] == '/')) { continue; } string lower = line.ToLower(); if (lower == "[controls]") { controls = true; continue; } else if (lower == "[strings]") { controls = false; continue; } else if (lower.StartsWith("::cliloc")) { idx = lower.IndexOf('=') + 1; if (idx > 0 && idx < lower.Length) { m_CliLocName = lower.Substring(idx).Trim().ToUpper(); } continue; } else if (lower.StartsWith("::encoding")) { continue; } idx = line.IndexOf('='); if (idx < 0) { errors.Add(lineNum); continue; } string key = line.Substring(0, idx).Trim(); string value = line.Substring(idx + 1).Trim().Replace("\\n", "\n"); if (controls) { m_Controls[key] = value; } else { m_Strings[(LocString)Convert.ToInt32(key)] = value; } } catch { errors.Add(lineNum); } } //while } //using if (errors.Count > 0) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("Razor enountered errors on the following lines while loading the file '{0}'\r\n", filename); for (int i = 0; i < errors.Count; i++) { sb.AppendFormat("Line {0}\r\n", errors[i]); } new MessageDialog("Language Pack Load Errors", true, sb.ToString()).Show(); } LoadCliLoc(); m_Loaded = true; return(true); }
public static void Main(string[] Args) { Client.Init(true); Application.EnableVisualStyles(); m_Running = true; Thread.CurrentThread.Name = "Razor Main Thread"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Directory.SetCurrentDirectory(Config.GetInstallDirectory()); #endif try { Engine.ShardList = Config.GetAppSetting <string>("ShardList"); } catch { } bool patch = Config.GetAppSetting <int>("PatchEncy") != 0; bool showWelcome = Config.GetAppSetting <int>("ShowWelcome") != 0; ClientLaunch launch = ClientLaunch.TwoD; int attPID = -1; string dataDir; Client.Instance.ClientEncrypted = false; Client.Instance.ServerEncrypted = false; Config.SetAppSetting("PatchEncy", "1"); patch = true; dataDir = null; bool advCmdLine = false; for (int i = 0; i < Args.Length; i++) { string arg = Args[i].ToLower(); if (arg == "--nopatch") { patch = false; } else if (arg == "--clientenc") { Client.Instance.ClientEncrypted = true; advCmdLine = true; patch = false; } else if (arg == "--serverenc") { Client.Instance.ServerEncrypted = true; advCmdLine = true; } else if (arg == "--welcome") { showWelcome = true; } else if (arg == "--nowelcome") { showWelcome = false; } else if (arg == "--pid" && i + 1 < Args.Length) { i++; patch = false; attPID = Utility.ToInt32(Args[i], 0); } else if (arg.Substring(0, 5) == "--pid" && arg.Length > 5) //support for uog 1.8 (damn you fixit) { patch = false; attPID = Utility.ToInt32(arg.Substring(5), 0); } else if (arg == "--uodata" && i + 1 < Args.Length) { i++; dataDir = Args[i]; } else if (arg == "--server" && i + 1 < Args.Length) { i++; string[] split = Args[i].Split(',', ':', ';', ' '); if (split.Length >= 2) { Config.SetAppSetting("LastServer", split[0]); Config.SetAppSetting("LastPort", split[1]); showWelcome = false; } } else if (arg == "--debug") { ScavengerAgent.Debug = true; DragDropManager.Debug = true; } } if (attPID > 0 && !advCmdLine) { Client.Instance.ServerEncrypted = false; Client.Instance.ClientEncrypted = false; } if (!Language.Load("ENU")) { SplashScreen.End(); MessageBox.Show( "Fatal Error: Unable to load required file Language/Razor_lang.enu\nRazor cannot continue.", "No Language Pack", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } string defLang = Config.GetAppSetting <string>("DefaultLanguage"); if (defLang != null && !Language.Load(defLang)) { MessageBox.Show( String.Format( "WARNING: Razor was unable to load the file Language/Razor_lang.{0}\nENU will be used instead.", defLang), "Language Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } string clientPath = ""; // welcome only needed when not loaded by a launcher (ie uogateway) if (attPID == -1) { if (!showWelcome) { int cli = Config.GetAppSetting <int>("DefClient"); if (cli < 0 || cli > 1) { launch = ClientLaunch.Custom; clientPath = Config.GetAppSetting <string>($"Client{cli - 1}"); if (string.IsNullOrEmpty(clientPath)) { showWelcome = true; } } else { launch = (ClientLaunch)cli; } } if (showWelcome) { SplashScreen.End(); WelcomeForm welcome = new WelcomeForm(); m_ActiveWnd = welcome; if (welcome.ShowDialog() == DialogResult.Cancel) { return; } patch = welcome.PatchEncryption; launch = welcome.Client; dataDir = welcome.DataDirectory; if (launch == ClientLaunch.Custom) { clientPath = welcome.ClientPath; } SplashScreen.Start(); m_ActiveWnd = SplashScreen.Instance; } } if (dataDir != null && Directory.Exists(dataDir)) { Ultima.Files.SetMulPath(dataDir); } Language.LoadCliLoc(); SplashScreen.Message = LocString.Initializing; //m_TimerThread = new Thread( new ThreadStart( Timer.TimerThread.TimerMain ) ); //m_TimerThread.Name = "Razor Timers"; Initialize(typeof(Assistant.Engine).Assembly); //Assembly.GetExecutingAssembly() SplashScreen.Message = LocString.LoadingLastProfile; Config.LoadCharList(); if (!Config.LoadLastProfile()) { MessageBox.Show( "The selected profile could not be loaded, using default instead.", "Profile Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (attPID == -1) { Client.Instance.SetConnectionInfo(IPAddress.None, -1); Client.Loader_Error result = Client.Loader_Error.UNKNOWN_ERROR; SplashScreen.Message = LocString.LoadingClient; if (launch == ClientLaunch.TwoD) { clientPath = Ultima.Files.GetFilePath("client.exe"); } else if (launch == ClientLaunch.ThirdDawn) { clientPath = Ultima.Files.GetFilePath("uotd.exe"); } if (!advCmdLine) { Client.Instance.ClientEncrypted = patch; } if (clientPath != null && File.Exists(clientPath)) { result = Client.Instance.LaunchClient(clientPath); } if (result != Client.Loader_Error.SUCCESS) { if (clientPath == null && File.Exists(clientPath)) { MessageBox.Show(SplashScreen.Instance, String.Format("Unable to find the client specified.\n{0}: \"{1}\"", launch.ToString(), clientPath != null ? clientPath : "-null-"), "Could Not Start Client", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { MessageBox.Show(SplashScreen.Instance, String.Format("Unable to launch the client specified. (Error: {2})\n{0}: \"{1}\"", launch.ToString(), clientPath != null ? clientPath : "-null-", result), "Could Not Start Client", MessageBoxButtons.OK, MessageBoxIcon.Stop); } SplashScreen.End(); return; } string addr = Config.GetAppSetting <string>("LastServer"); int port = Config.GetAppSetting <int>("LastPort"); // if these are null then the registry entry does not exist (old razor version) IPAddress ip = Resolve(addr); if (ip == IPAddress.None || port == 0) { MessageBox.Show(SplashScreen.Instance, Language.GetString(LocString.BadServerAddr), "Bad Server Address", MessageBoxButtons.OK, MessageBoxIcon.Stop); SplashScreen.End(); return; } Client.Instance.SetConnectionInfo(ip, port); } else { string error = "Error attaching to the UO client."; bool result = false; try { result = Client.Instance.Attach(attPID); } catch (Exception e) { result = false; error = e.Message; } if (!result) { MessageBox.Show(SplashScreen.Instance, String.Format("{1}\nThe specified PID '{0}' may be invalid.", attPID, error), "Attach Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SplashScreen.End(); return; } Client.Instance.SetConnectionInfo(IPAddress.Any, 0); } if (Utility.Random(4) != 0) { SplashScreen.Message = LocString.WaitingForClient; } else { SplashScreen.Message = LocString.RememberDonate; } m_MainWnd = new MainForm(); Application.Run(m_MainWnd); m_Running = false; Client.Instance.Close(); Counter.Save(); Macros.MacroManager.Save(); Config.Save(); }
private static void CheckForUpdates() { try { SplashScreen.MessageStr = "Checking for Razor Updates..."; } catch { } int uid = 0; try { string str = Config.GetRegString(Microsoft.Win32.Registry.LocalMachine, "UId"); if (str == null || str.Length <= 0) { str = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "UId"); } if (str != null && str.Length > 0) { uid = Convert.ToInt32(str, 16); } } catch { uid = 0; } if (uid == 0) { try { uid = Utility.Random(int.MaxValue - 1); if (!Config.SetRegString(Microsoft.Win32.Registry.LocalMachine, "UId", String.Format("{0:x}", uid))) { if (!Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "UId", String.Format("{0:x}", uid))) { uid = 0; } } } catch { uid = 0; } } try { //ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; //WebRequest req = WebRequest.Create( String.Format( "https://zenvera.com/razor/version.php?id={0}", uid ) ); HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://razor.uo.cx/version.txt"); req.Timeout = 8000; req.UserAgent = "Razor Update Check"; using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) { Version newVer = new Version(reader.ReadToEnd().Trim()); Version v = Assembly.GetCallingAssembly().GetName().Version; if (v.CompareTo(newVer) < 0) // v < newVer { ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.Verb = "runas"; // Administrator Rights processInfo.FileName = Path.Combine(Config.GetInstallDirectory(), "Updater.exe"); processInfo.Arguments = v.ToString(); Process.Start(processInfo); Process.GetCurrentProcess().Kill(); } } } catch { } try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://uo.cx/razor/shards.php"); req.Timeout = 8000; req.UserAgent = "Razor Shard List Update"; using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) { string json = reader.ReadToEnd(); if (json != null && json.Length > 10) // Arbitrary, we just don't want to overwrite a valid shard list for empty Json { Engine.ShardList = json; try { Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "ShardList", json); } catch { } } } } catch { } try { SplashScreen.Message = LocString.Initializing; } catch { } }
public static void Main( string[] Args ) { m_Running = true; Thread.CurrentThread.Name = "Razor Main Thread"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); Directory.SetCurrentDirectory( Config.GetInstallDirectory() ); #endif CheckUpdaterFiles(); ClientCommunication.InitializeLibrary( Engine.Version ); //if ( ClientCommunication.InitializeLibrary( Engine.Version ) == 0 || !File.Exists( Path.Combine( Config.GetInstallDirectory(), "Updater.exe" ) ) ) // throw new InvalidOperationException( "This Razor installation is corrupted." ); DateTime lastCheck = DateTime.MinValue; try { lastCheck = DateTime.FromFileTime( Convert.ToInt64( Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "UpdateCheck" ), 16 ) ); } catch { } if ( lastCheck + TimeSpan.FromHours( 3.0 ) < DateTime.Now ) { SplashScreen.Start(); m_ActiveWnd = SplashScreen.Instance; CheckForUpdates(); Config.SetRegString( Microsoft.Win32.Registry.CurrentUser, "UpdateCheck", String.Format( "{0:X16}", DateTime.Now.ToFileTime() ) ); } bool patch = Utility.ToInt32( Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "PatchEncy" ), 1 ) != 0; bool showWelcome = Utility.ToInt32( Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "ShowWelcome" ), 1 ) != 0; ClientLaunch launch = ClientLaunch.TwoD; int attPID = -1; string dataDir; ClientCommunication.ClientEncrypted = false; // check if the new ServerEncryption option is in the registry yet dataDir = Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "ServerEnc" ); if ( dataDir == null ) { // if not, add it (copied from UseOSIEnc) dataDir = Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "UseOSIEnc" ); if ( dataDir == "1" ) { ClientCommunication.ServerEncrypted = true; Config.SetRegString( Microsoft.Win32.Registry.CurrentUser, "ServerEnc", "1" ); } else { Config.SetRegString( Microsoft.Win32.Registry.CurrentUser, "ServerEnc", "0" ); ClientCommunication.ServerEncrypted = false; } Config.SetRegString( Microsoft.Win32.Registry.CurrentUser, "PatchEncy", "1" ); // reset the patch encryption option to TRUE patch = true; Config.DeleteRegValue( Microsoft.Win32.Registry.CurrentUser, "UseOSIEnc" ); // delete the old value } else { ClientCommunication.ServerEncrypted = Utility.ToInt32( dataDir, 0 ) != 0; } dataDir = null; bool advCmdLine = false; for (int i=0;i<Args.Length;i++) { string arg = Args[i].ToLower(); if ( arg == "--nopatch" ) { patch = false; } else if ( arg == "--clientenc" ) { ClientCommunication.ClientEncrypted = true; advCmdLine = true; patch = false; } else if ( arg == "--serverenc" ) { ClientCommunication.ServerEncrypted = true; advCmdLine = true; } else if ( arg == "--welcome" ) { showWelcome = true; } else if ( arg == "--nowelcome" ) { showWelcome = false; } else if ( arg == "--pid" && i+1 < Args.Length ) { i++; patch = false; attPID = Utility.ToInt32( Args[i], 0 ); } else if ( arg.Substring( 0, 5 ) == "--pid" && arg.Length > 5 ) //support for uog 1.8 (damn you fixit) { patch = false; attPID = Utility.ToInt32( arg.Substring(5), 0 ); } else if ( arg == "--uodata" && i+1 < Args.Length ) { i++; dataDir = Args[i]; } else if ( arg == "--server" && i+1 < Args.Length ) { i++; string[] split = Args[i].Split( ',', ':', ';', ' ' ); if ( split.Length >= 2 ) { Config.SetRegString( Microsoft.Win32.Registry.CurrentUser, "LastServer", split[0] ); Config.SetRegString( Microsoft.Win32.Registry.CurrentUser, "LastPort", split[1] ); showWelcome = false; } } else if ( arg == "--debug" ) { ScavengerAgent.Debug = true; DragDropManager.Debug = true; } } if ( attPID > 0 && !advCmdLine ) { ClientCommunication.ServerEncrypted = false; ClientCommunication.ClientEncrypted = false; } if ( !Language.Load( "ENU" ) ) { SplashScreen.End(); MessageBox.Show( "Fatal Error: Unable to load required file Language/Razor_lang.enu\nRazor cannot continue.", "No Language Pack", MessageBoxButtons.OK, MessageBoxIcon.Stop ); return; } string defLang = Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "DefaultLanguage" ); if ( defLang != null && !Language.Load( defLang ) ) MessageBox.Show( String.Format( "WARNING: Razor was unable to load the file Language/Razor_lang.{0}\nENU will be used instead.", defLang ), "Language Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning ); string clientPath = ""; // welcome only needed when not loaded by a launcher (ie uogateway) if ( attPID == -1 ) { if ( !showWelcome ) { int cli = Utility.ToInt32( Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "DefClient" ), 0 ); if ( cli < 0 || cli > 1 ) { launch = ClientLaunch.Custom; clientPath = Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, String.Format( "Client{0}", cli - 1 ) ); if ( clientPath == null || clientPath == "" ) showWelcome = true; } else { launch = (ClientLaunch)cli; } } if ( showWelcome ) { SplashScreen.End(); WelcomeForm welcome = new WelcomeForm(); m_ActiveWnd = welcome; if ( welcome.ShowDialog() == DialogResult.Cancel ) return; patch = welcome.PatchEncryption; launch = welcome.Client; dataDir = welcome.DataDirectory; if ( launch == ClientLaunch.Custom ) clientPath = welcome.ClientPath; SplashScreen.Start(); m_ActiveWnd = SplashScreen.Instance; } } if (dataDir != null && Directory.Exists(dataDir)) { Ultima.Files.SetMulPath(dataDir); } Language.LoadCliLoc(); SplashScreen.Message = LocString.Initializing; //m_TimerThread = new Thread( new ThreadStart( Timer.TimerThread.TimerMain ) ); //m_TimerThread.Name = "Razor Timers"; Initialize( typeof( Assistant.Engine ).Assembly ); //Assembly.GetExecutingAssembly() SplashScreen.Message = LocString.LoadingLastProfile; Config.LoadCharList(); if ( !Config.LoadLastProfile() ) MessageBox.Show( SplashScreen.Instance, "The selected profile could not be loaded, using default instead.", "Profile Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning ); if ( attPID == -1 ) { ClientCommunication.SetConnectionInfo(IPAddress.None, -1); ClientCommunication.Loader_Error result = ClientCommunication.Loader_Error.UNKNOWN_ERROR; SplashScreen.Message = LocString.LoadingClient; if ( launch == ClientLaunch.TwoD ) clientPath = Ultima.Files.GetFilePath("client.exe"); else if ( launch == ClientLaunch.ThirdDawn ) clientPath = Ultima.Files.GetFilePath( "uotd.exe" ); if ( !advCmdLine ) ClientCommunication.ClientEncrypted = patch; if ( clientPath != null && File.Exists( clientPath ) ) result = ClientCommunication.LaunchClient( clientPath ); if ( result != ClientCommunication.Loader_Error.SUCCESS ) { if ( clientPath == null && File.Exists( clientPath ) ) MessageBox.Show( SplashScreen.Instance, String.Format( "Unable to find the client specified.\n{0}: \"{1}\"", launch.ToString(), clientPath != null ? clientPath : "-null-" ), "Could Not Start Client", MessageBoxButtons.OK, MessageBoxIcon.Stop ); else MessageBox.Show( SplashScreen.Instance, String.Format( "Unable to launch the client specified. (Error: {2})\n{0}: \"{1}\"", launch.ToString(), clientPath != null ? clientPath : "-null-", result ), "Could Not Start Client", MessageBoxButtons.OK, MessageBoxIcon.Stop ); SplashScreen.End(); return; } string addr = Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "LastServer" ); int port = Utility.ToInt32( Config.GetRegString( Microsoft.Win32.Registry.CurrentUser, "LastPort" ), 0 ); // if these are null then the registry entry does not exist (old razor version) IPAddress ip = Resolve( addr ); if ( ip == IPAddress.None || port == 0 ) { MessageBox.Show( SplashScreen.Instance, Language.GetString( LocString.BadServerAddr ), "Bad Server Address", MessageBoxButtons.OK, MessageBoxIcon.Stop ); SplashScreen.End(); return; } ClientCommunication.SetConnectionInfo( ip, port ); } else { string error = "Error attaching to the UO client."; bool result = false; try { result = ClientCommunication.Attach( attPID ); } catch ( Exception e ) { result = false; error = e.Message; } if ( !result ) { MessageBox.Show( SplashScreen.Instance, String.Format( "{1}\nThe specified PID '{0}' may be invalid.", attPID, error ), "Attach Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); SplashScreen.End(); return; } ClientCommunication.SetConnectionInfo(IPAddress.Any, 0); } Ultima.Multis.PostHSFormat = UsePostHSChanges; if ( Utility.Random(4) != 0 ) SplashScreen.Message = LocString.WaitingForClient; else SplashScreen.Message = LocString.RememberDonate; m_MainWnd = new MainForm(); Application.Run( m_MainWnd ); m_Running = false; try { PacketPlayer.Stop(); } catch {} try { AVIRec.Stop(); } catch {} ClientCommunication.Close(); Counter.Save(); Macros.MacroManager.Save(); Config.Save(); }
private static void CheckForUpdates() { try { SplashScreen.MessageStr = "Checking for Razor Updates..."; } catch { } int uid = 0; try { string str = Config.GetRegString(Microsoft.Win32.Registry.LocalMachine, "UId"); if (str == null || str.Length <= 0) { str = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "UId"); } if (str != null && str.Length > 0) { uid = Convert.ToInt32(str, 16); } } catch { uid = 0; } if (uid == 0) { try { uid = Utility.Random(int.MaxValue - 1); if (!Config.SetRegString(Microsoft.Win32.Registry.LocalMachine, "UId", String.Format("{0:x}", uid))) { if (!Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "UId", String.Format("{0:x}", uid))) { uid = 0; } } } catch { uid = 0; } } try { ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; WebRequest req = WebRequest.Create(String.Format("https://zenvera.com/razor/version.php?id={0}", uid)); using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) { Version newVer = new Version(reader.ReadToEnd().Trim()); Version v = Assembly.GetCallingAssembly().GetName().Version; if (v.CompareTo(newVer) < 0) // v < newVer { ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.Verb = "runas"; // Administrator Rights processInfo.FileName = Path.Combine(Config.GetInstallDirectory(), "Updater.exe"); Process.Start(processInfo); Process.GetCurrentProcess().Kill(); } } } catch { } try { SplashScreen.Message = LocString.Initializing; } catch { } }