예제 #1
0
 private void makeDef_Click(object sender, System.EventArgs e)
 {
     Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "DefClient", (clientList.SelectedIndex >= 0 ? clientList.SelectedIndex : 0).ToString());
     Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "PatchEncy", patchEncy.Checked ? "1" : "0");
     Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "ServerEnc", useEnc.Checked ? "1" : "0");
     MessageBox.Show(this, Language.GetString(LocString.SaveOK), "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
예제 #2
0
        private void langSel_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            string lang = langSel.SelectedItem as string;

            if (lang != null && lang != Language.Current)
            {
                if (!Language.Load(lang))
                {
                    MessageBox.Show("There was an error loading that language.", "Language Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    langSel.SelectedItem = Language.Current;
                }
                else
                {
                    Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "DefaultLanguage", Language.Current);
                    Language.LoadControlNames(this);

                    clientList.Items[0] = Language.GetString(LocString.Auto2D);
                    clientList.Items[1] = Language.GetString(LocString.Auto2D);
                    dataDir.Items[0]    = Language.GetString(LocString.AutoDetect);
                }
            }
        }
예제 #3
0
        /*private const string RazorLine = "; Razor Generated Entry";
         * private void WriteLoginCFG( string addr, int port )
         * {
         *      string fileName = Ultima.Client.GetFilePath( "Login.cfg" );
         *      if ( fileName == null || fileName == "" )
         *              return;
         *      ArrayList lines = new ArrayList();
         *
         *      if ( File.Exists( fileName ) )
         *      {
         *              using ( StreamReader cfg = new StreamReader( fileName ) )
         *              {
         *                      string line;
         *                      while ( (line = cfg.ReadLine()) != null )
         *                      {
         *                              line = line.Trim();
         *                              if ( line == RazorLine )
         *                              {
         *                                      cfg.ReadLine(); // skip the next line which is the razor server
         *                                      continue;
         *                              }
         *                              else if ( line != "" )
         *                              {
         *                                      lines.Add( line );
         *                              }
         *                      }
         *              }
         *      }
         *
         *      using ( StreamWriter cfg = new StreamWriter( fileName ) )
         *      {
         *              foreach ( string line in lines )
         *              {
         *                      if ( line.Length > 0 && line[0] != ';' )
         *                              cfg.Write( ';' );
         *                      cfg.WriteLine( line );
         *              }
         *              cfg.WriteLine( RazorLine );
         *              cfg.WriteLine( "LoginServer={0},{1}", addr.Trim(), port );
         *      }
         * }*/

        private void showAtStart_CheckedChanged(object sender, System.EventArgs e)
        {
            Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "ShowWelcome", (showAtStart.Checked ? 1 : 0).ToString());
        }
예제 #4
0
        private void SaveData()
        {
            for (int i = 0; i < serverList.Items.Count; i++)
            {
                for (int j = i + 1; j < serverList.Items.Count; j++)
                {
                    ServerEntry si = (ServerEntry)serverList.Items[i];
                    ServerEntry sj = (ServerEntry)serverList.Items[j];
                    if (si.Address == sj.Address && si.Port == sj.Port)
                    {
                        serverList.Items.RemoveAt(j);
                    }
                }
            }

            int num = 1;

            for (int i = 0; i < serverList.Items.Count; i++)
            {
                ServerEntry se = (ServerEntry)serverList.Items[i];
                if (se is Custom_SE || se is LoginCFG_SE)
                {
                    continue;
                }

                if (se.Address != "")
                {
                    Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, String.Format("Server{0}", num), se.Address);
                    Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, String.Format("Port{0}", num), se.Port.ToString());
                    num++;
                }
            }

            for (int i = 2; i < clientList.Items.Count; i++)
            {
                Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, String.Format("Client{0}", i - 1), ((PathElipsis)clientList.Items[i]).GetPath());
            }

            num = 1;
            if (dataDir.SelectedIndex == -1)
            {
                string dir = dataDir.Text;
                dir = dir.Trim();

                if (dir.Length > 0 && dir != "(Auto Detect)")
                {
                    Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "Dir1", dir);
                    Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "LastDir", "1");
                    m_DataDir = dir;
                    num       = 2;
                }
            }

            if (num == 1)
            {
                Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "LastDir", (dataDir.SelectedIndex != -1 ? dataDir.SelectedIndex : 0).ToString());
                try
                {
                    if (dataDir.SelectedIndex != 0)
                    {
                        m_DataDir = dataDir.SelectedItem as string;
                    }
                    else
                    {
                        m_DataDir = null;
                    }
                }
                catch
                {
                }
            }

            for (int i = 1; i < dataDir.Items.Count; i++)
            {
                Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, String.Format("Dir{0}", num++), (string)dataDir.Items[i]);
            }
        }
예제 #5
0
        private void okay_Click(object sender, System.EventArgs e)
        {
            m_PatchEncy = patchEncy.Checked;

            if (clientList.SelectedIndex < 2)
            {
                m_Launch = (ClientLaunch)clientList.SelectedIndex;
            }
            else
            {
                m_Launch     = ClientLaunch.Custom;
                m_ClientPath = ((PathElipsis)clientList.SelectedItem).GetPath();
            }

            ServerEntry se = null;

            if (serverList.SelectedItem != null)
            {
                if (serverList.SelectedItem is Custom_SE)
                {
                    int port = ((Custom_SE)serverList.SelectedItem).Port;

                    string addr = ((Custom_SE)serverList.SelectedItem).RealAddress;

                    if (addr == "login.ultimaonline.com")
                    {
                        ClientCommunication.ServerEncrypted = true;
                    }

                    if (port == 0)
                    {
                        port = 2593;                         // runuo default
                    }
                    se = new ServerEntry(addr, port);
                }
                else if (!(serverList.SelectedItem is LoginCFG_SE))
                {
                    se      = (ServerEntry)serverList.SelectedItem;
                    se.Port = Utility.ToInt32(port.Text.Trim(), 0);
                    if (se.Port <= 0 || se.Port > 65535)
                    {
                        MessageBox.Show(this, Language.GetString(LocString.NeedPort), "Need Port", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            else if (serverList.Text != "")
            {
                int thePort = Utility.ToInt32(port.Text.Trim(), 0);
                if (thePort <= 0 || thePort > 65535)
                {
                    MessageBox.Show(this, Language.GetString(LocString.NeedPort), "Need Port", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                se = new ServerEntry(serverList.Text.Trim(), thePort);
            }

            if (se != null && se.Address != null)
            {
                if (!(serverList.SelectedItem is Custom_SE))
                {
                    serverList.Items.Remove(se);
                    serverList.Items.Insert(1, se);
                }

                //if ( se.Address != "" )
                //	WriteLoginCFG( se.Address, se.Port );

                Config.SetRegString(Registry.CurrentUser, "LastServer", se.Address);
                Config.SetRegString(Registry.CurrentUser, "LastPort", se.Port.ToString());
            }

            SaveData();

            this.Close();
        }
예제 #6
0
        private void WelcomeForm_Load(object sender, System.EventArgs e)
        {
            Language.LoadControlNames(this);

            this.BringToFront();

            langSel.Items.AddRange(Language.GetPackNames());
            langSel.SelectedItem = Language.Current;

            showAtStart.Checked = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "ShowWindow"), 1) == 1;

            clientList.Items.Add(Language.GetString(LocString.Auto2D));
            clientList.Items.Add(Language.GetString(LocString.Auto3D));
            for (int i = 1; ; i++)
            {
                string val = String.Format("Client{0}", i);
                string cli = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, val);
                if (cli == null || cli == "")
                {
                    break;
                }
                if (File.Exists(cli))
                {
                    clientList.Items.Add(new PathElipsis(cli));
                }
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, val);
            }
            int sel = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "DefClient"), 0);

            if (sel >= clientList.Items.Count)
            {
                sel = 0;
                Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "DefClient", "0");
            }
            clientList.SelectedIndex = sel;

            dataDir.Items.Add(Language.GetString(LocString.AutoDetect));
            for (int i = 1; ; i++)
            {
                string val = String.Format("Dir{0}", i);
                string dir = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, val);
                if (dir == null || dir == "")
                {
                    break;
                }
                if (Directory.Exists(dir))
                {
                    dataDir.Items.Add(dir);
                }
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, val);
            }

            try
            {
                dataDir.SelectedIndex = Convert.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "LastDir"));
            }
            catch
            {
                dataDir.SelectedIndex = 0;
            }

            patchEncy.Checked = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "PatchEncy"), 1) != 0;
            useEnc.Checked    = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "ServerEnc"), 0) != 0;

            LoginCFG_SE lse = new LoginCFG_SE();
            Custom_SE   cse;

            ShardEntry[] entries = null;
            try { entries = JsonConvert.DeserializeObject <ShardEntry[]>(Engine.ShardList); }
            catch { }

            serverList.BeginUpdate();

            //serverList.Items.Add( lse=new LoginCFG_SE() );
            //serverList.SelectedItem = lse;

            for (int i = 1; ; i++)
            {
                ServerEntry se;
                string      sval = String.Format("Server{0}", i);
                string      serv = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, sval);
                if (serv == null)
                {
                    break;
                }
                string pval = String.Format("Port{0}", i);
                int    port = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, pval), 0);
                serverList.Items.Add(se = new ServerEntry(serv, port));
                if (serv == lse.RealAddress && port == lse.Port)
                {
                    serverList.SelectedItem = se;
                }
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, sval);
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, pval);
            }

            if (entries == null)
            {
                serverList.Items.Add(cse = new Custom_SE("Zenvera (UOR)", "login.zenvera.com"));
                if (serverList.SelectedItem == null || lse.RealAddress == cse.RealAddress && lse.Port == 2593)
                {
                    serverList.SelectedItem = cse;
                }
            }
            else
            {
                foreach (var entry in entries)
                {
                    if (String.IsNullOrEmpty(entry.name))
                    {
                        continue;
                    }

                    var ename = String.IsNullOrEmpty(entry.type) ? entry.name : String.Format("{0} ({1})", entry.name, entry.type);
                    serverList.Items.Add(cse = new Custom_SE(ename, entry.host, entry.port));
                    if (lse.RealAddress == cse.RealAddress && lse.Port == entry.port)
                    {
                        serverList.SelectedItem = cse;
                    }
                }
            }

            serverList.EndUpdate();

            serverList.Refresh();

            WindowState = FormWindowState.Normal;
            this.BringToFront();
            this.TopMost = true;

            _ShowTimer          = new System.Windows.Forms.Timer();
            _ShowTimer.Interval = 250;
            _ShowTimer.Enabled  = true;
            _ShowTimer.Tick    += new EventHandler(timer_Tick);
        }
예제 #7
0
        private void WelcomeForm_Load(object sender, System.EventArgs e)
        {
            Language.LoadControlNames(this);

            this.BringToFront();

            langSel.Items.AddRange(Language.GetPackNames());
            langSel.SelectedItem = Language.Current;

            showAtStart.Checked = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "ShowWindow"), 1) == 1;

            clientList.Items.Add(Language.GetString(LocString.Auto2D));
            clientList.Items.Add(Language.GetString(LocString.Auto3D));
            for (int i = 1; ; i++)
            {
                string val = String.Format("Client{0}", i);
                string cli = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, val);
                if (cli == null || cli == "")
                {
                    break;
                }
                if (File.Exists(cli))
                {
                    clientList.Items.Add(new PathElipsis(cli));
                }
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, val);
            }
            int sel = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "DefClient"), 0);

            if (sel >= clientList.Items.Count)
            {
                sel = 0;
                Config.SetRegString(Microsoft.Win32.Registry.CurrentUser, "DefClient", "0");
            }
            clientList.SelectedIndex = sel;

            dataDir.Items.Add(Language.GetString(LocString.AutoDetect));
            for (int i = 1; ; i++)
            {
                string val = String.Format("Dir{0}", i);
                string dir = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, val);
                if (dir == null || dir == "")
                {
                    break;
                }
                if (Directory.Exists(dir))
                {
                    dataDir.Items.Add(dir);
                }
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, val);
            }

            try
            {
                dataDir.SelectedIndex = Convert.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "LastDir"));
            }
            catch
            {
                dataDir.SelectedIndex = 0;
            }

            patchEncy.Checked = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "PatchEncy"), 1) != 0;
            useEnc.Checked    = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "ServerEnc"), 0) != 0;

            LoginCFG_SE lse = new LoginCFG_SE();
            UOGamers_SE uog;

            serverList.BeginUpdate();

            //serverList.Items.Add( lse=new LoginCFG_SE() );
            //serverList.SelectedItem = lse;

            for (int i = 1; ; i++)
            {
                ServerEntry se;
                string      sval = String.Format("Server{0}", i);
                string      serv = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, sval);
                if (serv == null)
                {
                    break;
                }
                string pval = String.Format("Port{0}", i);
                int    port = Utility.ToInt32(Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, pval), 0);
                serverList.Items.Add(se = new ServerEntry(serv, port));
                if (serv == lse.RealAddress && port == lse.Port)
                {
                    serverList.SelectedItem = se;
                }
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, sval);
                Config.DeleteRegValue(Microsoft.Win32.Registry.CurrentUser, pval);
            }

            serverList.Items.Add(uog = new UOGamers_SE("Zenvera (UOR)", "login.zenvera.com"));
            if (serverList.SelectedItem == null || lse.RealAddress == uog.RealAddress && lse.Port == 2593)
            {
                serverList.SelectedItem = uog;
            }

            serverList.Items.Add(uog = new UOGamers_SE("Second Age (T2A)", "login.uosecondage.com"));
            if (lse.RealAddress == uog.RealAddress && lse.Port == 2593)
            {
                serverList.SelectedItem = uog;
            }

            serverList.Items.Add(uog = new UOGamers_SE("An Corp (T2A)", "login.uoancorp.com"));
            if (lse.RealAddress == uog.RealAddress && lse.Port == 2593)
            {
                serverList.SelectedItem = uog;
            }

            serverList.Items.Add(uog = new UOGamers_SE("Forever (P16)", "login.uoforever.com", 2599));
            if (lse.RealAddress == uog.RealAddress && lse.Port == 2599)
            {
                serverList.SelectedItem = uog;
            }

            serverList.Items.Add(uog = new UOGamers_SE("Pandora (HS)", "play.pandorauo.com"));
            if (lse.RealAddress == uog.RealAddress && lse.Port == 2593)
            {
                serverList.SelectedItem = uog;
            }

            serverList.Items.Add(uog = new UOGamers_SE("Electronic Arts/Origin Servers", "login.ultimaonline.com", 7775));
            if (lse.RealAddress == uog.RealAddress && (lse.Port >= 7775 && lse.Port <= 7778))
            {
                serverList.SelectedItem = uog;
            }

            serverList.EndUpdate();

            serverList.Refresh();

            WindowState = FormWindowState.Normal;
            this.BringToFront();
            this.TopMost = true;

            _ShowTimer          = new System.Windows.Forms.Timer();
            _ShowTimer.Interval = 250;
            _ShowTimer.Enabled  = true;
            _ShowTimer.Tick    += new EventHandler(timer_Tick);
        }
예제 #8
0
파일: Main.cs 프로젝트: rolliff/razor
        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 { }
        }
예제 #9
0
파일: Main.cs 프로젝트: rolliff/razor
        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();

            if (ClientCommunication.InitializeLibrary(Engine.Version) == 0)
            {
                throw new InvalidOperationException("InitializeLibrary: This Razor installation is corrupted.");
            }

            if (!File.Exists(Path.Combine(Config.GetInstallDirectory(), "Updater.exe")))
            {
                throw new InvalidOperationException("UpdaterMissing: This Razor installation is corrupted.");
            }

            try { Engine.ShardList = Config.GetRegString(Microsoft.Win32.Registry.CurrentUser, "ShardList"); }
            catch { }

            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("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();
        }
예제 #10
0
        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 { }
        }