//Internal Event Handler //-> onTick is just a name, it's not really a timer and ticks are not necessarily well spaced //-> This is basically a function called from a hook of the client's "general-purpose" function //-> this is a function called by the client whenever it has no windows messages to handle. //-> from this function it does everything else it needs to do: send packets that are in the packet queue //-> receive/handle packets, perform pathfinding/following/.... etc. //-> In this hook we can do our own things at that time... completely synchronized with the client. //-> So onTick = synchronized stuff. //-> The invokation for the ISynchronizeInvoke of the client also goes here. private bool Client_onTick(UnmanagedContext ctx, UnmanagedStack stck) { if (m_HookProc == null) { //install message hook if not installed yet (must be done here as we need the correct threadid, and this tick event gets handled on the client's main thread) m_ClientThread = Thread.CurrentThread.ManagedThreadId; m_HookProc = new Imports.HookProc(MessageHook); Imports.SetWindowsHookEx(Imports.HookType.WH_GETMESSAGE, System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(m_HookProc), IntPtr.Zero, Imports.GetCurrentThreadId()); } if (!m_ShuttingDown) { while (DelegateQueue.Count > 0) { DelegateQueue.Dequeue().DoInvoke(); } } return(true); }
public bool m_Hook_Call(Assembler.UnmanagedContext ctx, UnmanagedStack stck) { lock (m_Delegates) { bool retval = true; if (m_Delegates.Count > 0) { object[] parameters = new object[parinfo.Length]; object[] attribs; uint stckpos = 0; uint i = 0; foreach (ParameterInfo pi in parinfo) { //marshal parameter here if ((attribs = pi.GetCustomAttributes(typeof(UThisParAttribute), true)).Length > 0) { if ((attribs = pi.GetCustomAttributes(typeof(UParAttribute), true)).Length > 0) { UParAttribute upa = (UParAttribute)attribs[0]; parameters[i] = UnmanagedProxy.MarshalFromUnmanaged(ctx.ECX, upa.ReturnType, upa.SizeConstant, upa.KnownType); } else { parameters[i] = null;//can't marshal } } else if ((attribs = pi.GetCustomAttributes(typeof(UParAttribute), true)).Length > 0) { UParAttribute upa = (UParAttribute)attribs[0]; parameters[i] = UnmanagedProxy.MarshalFromUnmanaged(stck[stckpos], upa.ReturnType, upa.SizeConstant, upa.KnownType); stckpos++; } else { parameters[i] = null;//can't marshal } i++; } foreach (Delegate del in m_Delegates) { try { if (Client.InvokationTarget != null) { if (Client.AsyncInvokation) { Client.InvokationTarget.BeginInvoke(del, parameters); } else { retval &= (bool)Client.InvokationTarget.Invoke(del, parameters); } } else { retval &= (bool)del.DynamicInvoke(parameters); } } catch { Remove(del); } } } return(retval); } }