예제 #1
0
파일: Main.cs 프로젝트: mbnunes/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

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

            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;

            ClientCommunication.ClientEncrypted = false;

            // check if the new ServerEncryption option is in app.config
            dataDir = Config.GetAppSetting <string>("ServerEnc");
            if (dataDir == null)
            {
                // if not, add it (copied from UseOSIEnc)
                dataDir = Config.GetAppSetting <string>("UseOSIEnc");
                if (dataDir == "1")
                {
                    ClientCommunication.ServerEncrypted = true;
                    Config.SetAppSetting("ServerEnc", "1");
                }
                else
                {
                    Config.SetAppSetting("ServerEnc", "0");
                    ClientCommunication.ServerEncrypted = false;
                }

                Config.SetAppSetting("PatchEncy", "1");
                patch = true;
            }
            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.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)
            {
                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.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(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.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;
                }

                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();
        }
예제 #2
0
파일: Main.cs 프로젝트: mozkandemir/RE
        internal static void Start(RazorEnhanced.Shard selected)
        {
            ClientCommunication.ClientEncrypted = selected.PatchEnc;
            ClientCommunication.ServerEncrypted = selected.OSIEnc;
            string clientPath = selected.ClientPath;
            string dataDir    = selected.ClientFolder;
            string addr       = selected.Host;
            int    port       = selected.Port;

            Ultima.Files.Directory = selected.ClientFolder;

            if (!Language.Load("ENU"))
            {
                SplashScreen.End();
                MessageBox.Show("Unable to load required file Language/Razor_lang.enu", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                RazorEnhanced.Settings.General.WriteBool("NotShowLauncher", false);
                return;
            }

            if (dataDir != null && Directory.Exists(dataDir))
            {
                Ultima.Files.SetMulPath(dataDir);
            }
            else
            {
                MessageBox.Show("Unable to find the Data Folder " + dataDir, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                RazorEnhanced.Settings.General.WriteBool("NotShowLauncher", false);
                return;
            }

            Language.LoadCliLoc();
            Initialize(typeof(Assistant.Engine).Assembly);

            ClientCommunication.SetConnectionInfo(IPAddress.None, -1);
            ClientCommunication.Loader_Error result = ClientCommunication.Loader_Error.UNKNOWN_ERROR;

            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, "Unable to find the client " + clientPath, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(SplashScreen.Instance, "Unable to launch the client " + clientPath, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                SplashScreen.End();
                RazorEnhanced.Settings.General.WriteBool("NotShowLauncher", false);
                return;
            }

            // if these are null then the registry entry does not exist (old razor version)
            m_ip = Resolve(addr);
            if (m_ip == IPAddress.None || port == 0)
            {
                MessageBox.Show(Language.GetString(LocString.BadServerAddr), "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SplashScreen.End();
                RazorEnhanced.Settings.General.WriteBool("NotShowLauncher", false);
                return;
            }

            ClientBuild = FileVersionInfo.GetVersionInfo(clientPath).FileBuildPart;
            ClientMajor = FileVersionInfo.GetVersionInfo(clientPath).FileMajorPart;

            SplashScreen.Start();
            m_ActiveWnd = SplashScreen.Instance;

            ClientCommunication.SetConnectionInfo(m_ip, port);

            Ultima.Multis.PostHSFormat = UsePostHSChanges;

            MainWnd = new MainForm();
            Application.Run(MainWnd);

            m_Running = false;

            RazorEnhanced.Settings.General.SaveExitData();

            // Chiuto toolbar
            if (RazorEnhanced.ToolBar.ToolBarForm != null)
            {
                RazorEnhanced.ToolBar.ToolBarForm.Close();
            }

            // Chiuto Spellgrid
            if (RazorEnhanced.SpellGrid.SpellGridForm != null)
            {
                RazorEnhanced.SpellGrid.SpellGridForm.Close();
            }

            // Stoppo tick timer agent
            if (RazorEnhanced.Scripts.Timer != null)
            {
                RazorEnhanced.Scripts.Timer.Close();
            }

            // Stop forzato di tutti i thread agent
            RazorEnhanced.AutoLoot.AutoMode    = false;
            RazorEnhanced.Scavenger.AutoMode   = false;
            RazorEnhanced.BandageHeal.AutoMode = false;

            if (Assistant.Engine.MainWindow.OrganizerStop.Enabled == true)
            {
                Assistant.Engine.MainWindow.OrganizerStop.PerformClick();
            }

            if (Assistant.Engine.MainWindow.DressStopButton.Enabled == true)
            {
                Assistant.Engine.MainWindow.DressStopButton.PerformClick();
            }

            if (Assistant.Engine.MainWindow.RestockStop.Enabled == true)
            {
                Assistant.Engine.MainWindow.RestockStop.PerformClick();
            }

            RazorEnhanced.UI.EnhancedScriptEditor.End();

            ClientCommunication.Close();
        }