Exemplo n.º 1
0
        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 || !File.Exists( Path.Combine( Config.GetInstallDirectory(), "Updater.exe" ) ) )
                throw new InvalidOperationException( "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( 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();
        }
Exemplo n.º 2
0
        public static int OnUOAMessage( MainForm razor, int Msg, int wParam, int lParam )
        {
            switch ( (UOAMessage)Msg )
            {
                case UOAMessage.REGISTER:
                {
                    for(int i=0;i<m_WndReg.Count;i++)
                    {
                        if ( ((WndRegEnt)m_WndReg[i]).Handle == wParam )
                        {
                            m_WndReg.RemoveAt( i );
                            return 2;
                        }
                    }

                    m_WndReg.Add( new WndRegEnt( wParam, lParam == 1 ? 1 : 0 ) );

                    if ( lParam == 1 && World.Items != null )
                    {
                        foreach ( Item item in World.Items.Values )
                        {
                            if ( item.ItemID >= 0x4000 )
                                PostMessage( (IntPtr)wParam, (uint)UOAMessage.ADD_MULTI, (IntPtr)((int)((item.Position.X&0xFFFF)|((item.Position.Y&0xFFFF)<<16))), (IntPtr)item.ItemID.Value );
                        }
                    }

                    return 1;
                }
                case UOAMessage.COUNT_RESOURCES:
                {
                    Counter.FullRecount();
                    return 0;
                }
                case UOAMessage.GET_COORDS:
                {
                    if ( World.Player == null )
                        return 0;
                    return (World.Player.Position.X&0xFFFF)|((World.Player.Position.Y&0xFFFF)<<16);
                }
                case UOAMessage.GET_SKILL:
                {
                    if ( World.Player == null || lParam > 3 || wParam < 0 || World.Player.Skills == null || wParam > World.Player.Skills.Length || lParam < 0 )
                        return 0;

                    switch ( lParam )
                    {
                        case 3:
                        {
                            try
                            {
                                return GlobalAddAtom( ((SkillName)wParam).ToString() );
                            }
                            catch
                            {
                                return 0;
                            }
                        }
                        case 2: return (int)(World.Player.Skills[wParam].Lock);
                        case 1: return World.Player.Skills[wParam].FixedBase;
                        case 0: return World.Player.Skills[wParam].FixedValue;
                    }

                    return 0;
                }
                case UOAMessage.GET_STAT:
                {
                    if ( World.Player == null || wParam < 0 || wParam > 5 )
                        return 0;

                    switch ( wParam )
                    {
                        case 0: return World.Player.Str;
                        case 1: return World.Player.Int;
                        case 2: return World.Player.Dex;
                        case 3: return World.Player.Weight;
                        case 4: return World.Player.HitsMax;
                        case 5: return World.Player.Tithe;
                    }
                    return 0;
                }
                case UOAMessage.SET_MACRO:
                {
                    try
                    {
                        //if ( wParam >= 0 && wParam < Engine.MainWindow.macroList.Items.Count )
                        //	Engine.MainWindow.macroList.SelectedIndex = wParam;
                    }
                    catch
                    {
                    }
                    return 0;
                }
                case UOAMessage.PLAY_MACRO:
                {
                    if ( razor != null )
                        razor.playMacro_Click( razor, new EventArgs() );
                    return Macros.MacroManager.Playing ? 1 : 0;
                }
                case UOAMessage.DISPLAY_TEXT:
                {
                    if ( World.Player == null )
                        return 0;

                    int hue = wParam&0xFFFF;
                    StringBuilder sb = new StringBuilder( 256 );
                    if ( GlobalGetAtomName( (ushort)lParam, sb, 256 ) == 0 )
                        return 0;

                    if ( (wParam&0x00010000) != 0 )
                        ClientCommunication.SendToClient( new UnicodeMessage( 0xFFFFFFFF, -1, MessageType.Regular, hue, 3, Language.CliLocName, "System", sb.ToString() ) );
                    else
                        World.Player.OverheadMessage( hue, sb.ToString() );
                    GlobalDeleteAtom( (ushort)lParam );
                    return 1;
                }
                case UOAMessage.REQUEST_MULTIS:
                {
                    return World.Player != null ? 1 : 0;
                }
                case UOAMessage.ADD_CMD:
                {
                    StringBuilder sb = new StringBuilder( 256 );
                    if ( GlobalGetAtomName( (ushort)lParam, sb, 256 ) == 0 )
                        return 0;

                    if ( wParam == 0 )
                    {
                        Command.RemoveCommand( sb.ToString() );
                        return 0;
                    }
                    else
                    {
                        new WndCmd( m_NextCmdID, (IntPtr)wParam, sb.ToString() );
                        return (int)(m_NextCmdID++);
                    }
                }
                case UOAMessage.GET_UID:
                {
                    return World.Player != null ? (int)World.Player.Serial.Value : 0;
                }
                case UOAMessage.GET_SHARDNAME:
                {
                    if ( World.ShardName != null && World.ShardName.Length > 0 )
                        return GlobalAddAtom( World.ShardName );
                    else
                        return 0;
                }
                case UOAMessage.ADD_USER_2_PARTY:
                {
                    return 1; // not supported, return error
                }
                case UOAMessage.GET_UO_HWND:
                {
                    return FindUOWindow().ToInt32();
                }
                case UOAMessage.GET_POISON:
                {
                    return World.Player != null && World.Player.Poisoned ? 1 : 0;
                }
                case UOAMessage.SET_SKILL_LOCK:
                {
                    if ( World.Player == null || wParam < 0 || wParam > World.Player.Skills.Length || lParam < 0 || lParam >= 3 )
                        return 0;
                    SendToServer( new SetSkillLock( wParam, (LockType)lParam ) );
                    return 1;
                }
                case UOAMessage.GET_ACCT_ID:
                {
                    // free shards don't use account ids... so just return the player's serial number
                    return World.Player == null ? 0 : (int)World.Player.Serial.Value;
                }
                default:
                {
                    return 0;
                }
            }
        }
Exemplo n.º 3
0
        //private static DateTime m_LastActivate;
        internal static bool OnMessage( MainForm razor, uint wParam, int lParam )
        {
            bool retVal = true;

            switch ( (UONetMessage)(wParam&0xFFFF) )
            {
                case UONetMessage.OpenRPV:
                {
                    if ( Engine.MainWindow != null )
                    {
                        StringBuilder sb = new StringBuilder( 256 );
                        if ( GlobalGetAtomName( (ushort)lParam, sb, 256 ) == 0 )
                            return false;
                        BringToFront( FindUOWindow() );
                        PacketPlayer.Open( sb.ToString() );
                        Engine.MainWindow.ShowMe();
                        Engine.MainWindow.SwitchToVidTab();
                    }
                    break;
                }
                case UONetMessage.Ready: //Patch status
                    if ( lParam == (int)InitError.NO_MEMCOPY )
                    {
                        if ( MessageBox.Show( Engine.ActiveWindow, Language.GetString( LocString.NoMemCpy ), "No Client MemCopy", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ) == DialogResult.No )
                        {
                            m_Ready = false;
                            ClientProc = null;
                            Engine.MainWindow.CanClose = true;
                            Engine.MainWindow.Close();
                            break;
                        }
                    }

                    try
                    {
                        SetDataPath(Ultima.Files.Directory);
                    }
                    catch
                    {
                        SetDataPath( "" );
                    }

                    m_Ready = true;
                    break;

                case UONetMessage.NotReady:
                    m_Ready = false;
                    FatalInit( (InitError)lParam );
                    ClientProc = null;
                    Engine.MainWindow.CanClose = true;
                    Engine.MainWindow.Close();
                    break;

                    // Network events
                case UONetMessage.Recv:
                    OnRecv();
                    break;
                case UONetMessage.Send:
                    OnSend();
                    break;
                case UONetMessage.Connect:
                    m_ConnStart = DateTime.Now;
                    try
                    {
                        m_LastConnection = new IPAddress( (uint)lParam );
                    }
                    catch
                    {
                    }
                    break;
                case UONetMessage.Disconnect:
                    OnLogout( false );
                    break;
                case UONetMessage.Close:
                    OnLogout();
                    ClientProc = null;
                    try { PacketPlayer.Stop(); } catch {}
                    try { AVIRec.Stop(); } catch {}
                    Engine.MainWindow.CanClose = true;
                    Engine.MainWindow.Close();
                    break;

                    // Hot Keys
                case UONetMessage.Mouse:
                    HotKey.OnMouse( (ushort)(lParam&0xFFFF), (short)(lParam>>16) );
                    break;
                case UONetMessage.KeyDown:
                    retVal = HotKey.OnKeyDown( lParam );
                    break;

                    // Activation Tracking
                case UONetMessage.Activate:
                    /*if ( Config.GetBool( "AlwaysOnTop" ) )
                    {
                        if ( (lParam&0x0000FFFF) == 0 && (lParam&0xFFFF0000) != 0 && razor.WindowState != FormWindowState.Minimized && razor.Visible )
                        {// if uo is deactivating and minimized and we are not minimized
                            if ( !razor.ShowInTaskbar && razor.Visible )
                                razor.Hide();
                            razor.WindowState = FormWindowState.Minimized;
                            m_LastActivate = DateTime.Now;
                        }
                        else if ( (lParam&0x0000FFFF) != 0 && (lParam&0xFFFF0000) != 0 && razor.WindowState != FormWindowState.Normal )
                        { // is UO is activating and minimized and we are minimized
                            if ( m_LastActivate+TimeSpan.FromSeconds( 0.2 ) < DateTime.Now )
                            {
                                if ( !razor.ShowInTaskbar && !razor.Visible )
                                    razor.Show();
                                razor.WindowState = FormWindowState.Normal;
                                //SetForegroundWindow( FindUOWindow() );
                            }
                            m_LastActivate = DateTime.Now;
                        }
                    }*/
                    break;

                case UONetMessage.Focus:
                    if ( Config.GetBool( "AlwaysOnTop" ) )
                    {
                        if ( lParam != 0 && !razor.TopMost )
                        {
                            razor.TopMost = true;
                            SetForegroundWindow( FindUOWindow() );
                        }
                        else if ( lParam == 0 && razor.TopMost )
                        {
                            razor.TopMost = false;
                            razor.SendToBack();
                        }
                    }

                    // always use smartness for the map window
                    if ( razor.MapWindow != null && razor.MapWindow.Visible )
                    {
                        if ( lParam != 0 && !razor.MapWindow.TopMost )
                        {
                            razor.MapWindow.TopMost = true;
                            SetForegroundWindow( FindUOWindow() );
                        }
                        else if ( lParam == 0 && razor.MapWindow.TopMost )
                        {
                            razor.MapWindow.TopMost = false;
                            razor.MapWindow.SendToBack();
                        }
                    }

                    break;

                case UONetMessage.DLL_Error:
                {
                    string error = "Unknown";
                    switch ( (UONetMessage)lParam )
                    {
                        case UONetMessage.StatBar:
                            error = "Unable to patch status bar.";
                            break;
                    }

                    MessageBox.Show( Engine.ActiveWindow, "An Error has occured : \n" + error, "Error Reported", MessageBoxButtons.OK, MessageBoxIcon.Warning );
                    break;
                }

                case UONetMessage.FindData:
                    FindData.Message( (wParam&0xFFFF0000)>>16, lParam );
                    break;

                // ZIPPY REV 80
                /*case UONetMessage.SetFwdHWnd:
                    m_FwdWnd = lParam;
                    break;*/

                // Unknown
                default:
                    MessageBox.Show( Engine.ActiveWindow, "Unknown message from uo client\n" + ((int)wParam).ToString(), "Error?" );
                    break;
            }

            return retVal;
        }
Exemplo n.º 4
0
 public StatsTimer( MainForm form )
     : base(TimeSpan.FromSeconds( 0.5 ), TimeSpan.FromSeconds( 0.5 ))
 {
     m_Form = form;
 }