Esempio n. 1
0
        public override bool OnMessage(MainForm razor, uint wParam, int lParam)
        {
            bool retVal          = true;
            bool m_hidetoolbar   = false;
            bool m_hidespellgrid = false;

            switch ((UONetMessage)(wParam & 0xFFFF))
            {
            case UONetMessage.OpenRPV:
            {
                if (Engine.MainWindow != null)
                {
                    StringBuilder sb = new StringBuilder(256);
                    if (DLLImport.Win.GlobalGetAtomName((ushort)lParam, sb, 256) == 0)
                    {
                        return(false);
                    }

                    BringToFront(Assistant.Client.Instance.GetWindowHandle());
                    Engine.MainWindow.ShowMe();
                }
                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
                {
                    DLLImport.Razor.SetDataPath(Ultima.Files.Directory);
                }
                catch
                {
                    DLLImport.Razor.SetDataPath("");
                }
                UoMod.InjectUoMod();
                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_ConnectionStart = DateTime.UtcNow;
                try
                {
                    m_LastConnection = new IPAddress((uint)lParam);
                }
                catch
                {
                }
                break;

            case UONetMessage.Disconnect:
                OnLogout(false);
                break;

            case UONetMessage.Close:
                OnLogout();
                ClientProc = null;
                Engine.MainWindow.CanClose = true;
                Engine.MainWindow.Close();
                break;

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

            case UONetMessage.KeyDown:
                //retVal = HotKey.OnKeyDown(lParam);
                retVal = RazorEnhanced.HotKey.GameKeyDown((Keys)(lParam));
                break;

            // Activation Tracking
            case UONetMessage.Activate:
                if ((lParam & 0x0000FFFF) == 0 && (lParam & 0xFFFF0000) != 0)
                {
                    if (RazorEnhanced.ToolBar.ToolBarForm != null)
                    {
                        RazorEnhanced.ToolBar.ToolBarForm.Hide();
                    }

                    if (RazorEnhanced.SpellGrid.SpellGridForm != null)
                    {
                        RazorEnhanced.SpellGrid.SpellGridForm.Hide();
                    }
                }
                else
                {
                    if (lParam == 0 || lParam == 2097153)                             //2097153 riduzione a icona da win10 non perde il focus ma riduce
                    {
                        if (RazorEnhanced.ToolBar.ToolBarForm != null)
                        {
                            if (Cursor.Position.X >= RazorEnhanced.ToolBar.ToolBarForm.Location.X && Cursor.Position.X <= (RazorEnhanced.ToolBar.ToolBarForm.Location.X + RazorEnhanced.ToolBar.ToolBarForm.Width) && Cursor.Position.Y >= RazorEnhanced.ToolBar.ToolBarForm.Location.Y && Cursor.Position.Y <= (RazorEnhanced.ToolBar.ToolBarForm.Location.Y + RazorEnhanced.ToolBar.ToolBarForm.Height))
                            {
                                break;
                            }
                            m_hidetoolbar = true;
                        }
                        if (RazorEnhanced.SpellGrid.SpellGridForm != null)
                        {
                            if (Cursor.Position.X >= RazorEnhanced.SpellGrid.SpellGridForm.Location.X && Cursor.Position.X <= (RazorEnhanced.SpellGrid.SpellGridForm.Location.X + RazorEnhanced.SpellGrid.SpellGridForm.Width) && Cursor.Position.Y >= RazorEnhanced.SpellGrid.SpellGridForm.Location.Y && Cursor.Position.Y <= (RazorEnhanced.SpellGrid.SpellGridForm.Location.Y + RazorEnhanced.SpellGrid.SpellGridForm.Height))
                            {
                                break;
                            }
                            m_hidespellgrid = true;
                        }

                        if (m_hidetoolbar)
                        {
                            RazorEnhanced.ToolBar.ToolBarForm.Hide();
                        }
                        if (m_hidespellgrid)
                        {
                            RazorEnhanced.SpellGrid.SpellGridForm.Hide();
                        }
                    }
                    else
                    {
                        if (RazorEnhanced.ToolBar.ToolBarForm != null)
                        {
                            DLLImport.Win.ShowWindow(RazorEnhanced.ToolBar.ToolBarForm.Handle, 8);
                        }

                        if (RazorEnhanced.SpellGrid.SpellGridForm != null)
                        {
                            DLLImport.Win.ShowWindow(RazorEnhanced.SpellGrid.SpellGridForm.Handle, 8);
                        }

                        DLLImport.Win.SetForegroundWindow(Assistant.Client.Instance.GetWindowHandle());
                    }
                }

                /*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 (RazorEnhanced.Settings.General.ReadBool("AlwaysOnTop"))
                {
                    if (lParam != 0 && !razor.TopMost)
                    {
                        razor.TopMost = true;
                        DLLImport.Win.SetForegroundWindow(Assistant.Client.Instance.GetWindowHandle());
                    }
                    else if (lParam == 0 && razor.TopMost)
                    {
                        razor.TopMost = false;
                        razor.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;

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

            return(retVal);
        }
Esempio n. 2
0
        //private DateTime m_LastActivate;
        public override bool OnMessage(MainForm razor, uint wParam, int lParam)
        {
            bool retVal = true;

            switch ((UONetMessage)(wParam & 0xFFFF))
            {
            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;
                    }
                }

                byte *baseAddr = (byte *)GetSharedAddress().ToPointer();

                m_InRecv   = (Buffer *)baseAddr;
                m_OutRecv  = (Buffer *)(baseAddr + sizeof(Buffer));
                m_InSend   = (Buffer *)(baseAddr + sizeof(Buffer) * 2);
                m_OutSend  = (Buffer *)(baseAddr + sizeof(Buffer) * 3);
                m_TitleStr = (byte *)(baseAddr + sizeof(Buffer) * 4);

                SetServer(m_ServerIP, m_ServerPort);

                CommMutex = new Mutex();
#pragma warning disable 618
                CommMutex.Handle = GetCommMutex();
#pragma warning restore 618

                try
                {
                    string path = Ultima.Files.GetFilePath("art.mul");
                    if (path != null && path != string.Empty)
                    {
                        SetDataPath(Path.GetDirectoryName(path));
                    }
                    else
                    {
                        SetDataPath(Path.GetDirectoryName(Ultima.Files.Directory));
                    }
                }
                catch
                {
                    SetDataPath("");
                }

                if (Config.GetBool("OldStatBar"))
                {
                    RequestStatbarPatch(true);
                }

                m_Ready = true;
                Engine.MainWindow.MainForm_EndLoad();
                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.UtcNow;
                try
                {
                    m_LastConnection = new IPAddress((uint)lParam);
                }
                catch
                {
                }

                break;

            case UONetMessage.Disconnect:
                OnLogout(false);
                break;

            case UONetMessage.Close:
                OnLogout(true);
                ClientProc = null;
                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, ModKeys.None);
                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.UtcNow;
                 *  }
                 *  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.UtcNow )
                 *      {
                 *          if ( !razor.ShowInTaskbar && !razor.Visible )
                 *              razor.Show();
                 *          razor.WindowState = FormWindowState.Normal;
                 *          //SetForegroundWindow( FindUOWindow() );
                 *      }
                 *      m_LastActivate = DateTime.UtcNow;
                 *  }
                 * }*/
                break;

            case UONetMessage.Focus:
                if (Config.GetBool("AlwaysOnTop"))
                {
                    if (lParam != 0 && !razor.TopMost)
                    {
                        razor.TopMost = true;
                        Platform.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;
                        Platform.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.OnTick:
                // Game engine tick
                Timer.Slice();
                break;

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

            return(retVal);
        }
Esempio 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;
        }