//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); }
private void Tick() { Timer.Slice(); }