static void Main(string[] args) { Console.WriteLine($"sizeof(int): {sizeof(int)}"); Console.WriteLine($"sizeof(long): {sizeof(long)}"); Console.WriteLine($"{FakeADWrapper.ErrorToString(Error.Success)}"); #if I_FAILED int cursor = 0; var pinnedCursor = new PinnedObject(cursor); var pinnedCursorOpaqueHandle = pinnedCursor.ToIntPtr(); #endif var fakeAd = new FakeADWrapper( bytesPerSecond: CharsPerSecond, timeSliceInMilliseconds: 100, timeoutSliceCount: 3, port: 7373, callback: Typer.TypeIn, #if I_FAILED #if false context: pinnedCursor); #elif false context : pinnedCursor.ToIntPtr()); #else context : pinnedCursorOpaqueHandle); #endif #else context : IntPtr.Zero); #endif var buffer = new UnmanagedBuffer(sizeof(byte)); while (fakeAd.Read(buffer, sizeof(byte)) == sizeof(byte)) { Console.Write((char)buffer.Read <byte>()); } #if I_FAILED Console.WriteLine($"Cursor: {cursor}"); #endif Console.ReadKey(); }
public IMessage Invoke(IMessage message) { IMessage returnMessage; object[] attribs; uint addr; uint retval; IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)message); MethodBase method = methodMessage.MethodBase; object returnValue = null; if (method.MethodHandle == GetTypeMethodHandle) { returnValue = m_Interface; } else if (((attribs = method.GetCustomAttributes(typeof(SyncAttribute), true)).Length > 0) && (Client.Default.InvokeRequired)) { //m_Async value overrides Sync.Async if (m_Async.ContainsKey((int)method.MethodHandle.Value)) { if ((m_Async[(int)method.MethodHandle.Value]))//async override { Client.Default.BeginInvoke(new InvokeDelegate(Invoke), new object[] { message }); return(new ReturnMessage(null, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage)); } else//sync override { return((IMessage)Client.Default.Invoke(new InvokeDelegate(Invoke), new object[] { message })); } } else if (((SyncAttribute)attribs[0]).Async)//preconfigured async { Client.Default.BeginInvoke(new InvokeDelegate(Invoke), new object[] { message }); return(new ReturnMessage(null, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage)); } else//preconfigured sync { return((IMessage)Client.Default.Invoke(new InvokeDelegate(Invoke), new object[] { message })); } } else { if ((attribs = method.GetCustomAttributes(typeof(UMethodAttribute), true)).Length > 0) { UMethodAttribute mattrib = (UMethodAttribute)attribs[0]; addr = (uint)UOCallibration.Callibrations[(uint)mattrib.CallibratedOffsetFeature]; retval = PerformCall(addr, methodMessage); if (mattrib.HasReturnValue) { returnValue = MarshalFromUnmanaged(retval, mattrib.ReturnType, mattrib.SizeConstant, mattrib.KnownType); } else { returnValue = null; } } else if ((attribs = method.GetCustomAttributes(typeof(UFieldAttribute), true)).Length > 0) { UFieldAttribute fattrib = (UFieldAttribute)attribs[0]; UnmanagedBuffer buff = new UnmanagedBuffer((IntPtr)((uint)m_Address + (uint)UOCallibration.Callibrations[(uint)fattrib.CallibratedOffsetFeature])); retval = buff.Read <uint>(); returnValue = MarshalFromUnmanaged(retval, fattrib.ReturnType, fattrib.SizeConstant, fattrib.KnownType); } else if ((attribs = method.GetCustomAttributes(typeof(UGlobalAttribute), true)).Length > 0) { UGlobalAttribute gattrib = (UGlobalAttribute)attribs[0]; UnmanagedBuffer buff = new UnmanagedBuffer((IntPtr)UOCallibration.Callibrations[(uint)gattrib.CallibratedOffsetFeature]); retval = buff.Read <uint>(); returnValue = MarshalFromUnmanaged(retval, gattrib.ReturnType, gattrib.SizeConstant, gattrib.KnownType); } else if ((attribs = method.GetCustomAttributes(typeof(UVtblMethodAttribute), true)).Length > 0) { UVtblMethodAttribute mattrib = (UVtblMethodAttribute)attribs[0]; UnmanagedBuffer m_This = new UnmanagedBuffer(m_Address); addr = m_This.ReadAt <uint>(0); if (mattrib.hasidx) { addr += 4 * mattrib.index; } else { addr += (uint)UOCallibration.Callibrations[(uint)mattrib.CallibratedOffsetFeature]; } retval = PerformCall(addr, methodMessage); if (mattrib.HasReturnValue) { returnValue = MarshalFromUnmanaged(retval, mattrib.ReturnType, mattrib.SizeConstant, mattrib.KnownType); } else { returnValue = null; } } else if ((attribs = method.GetCustomAttributes(typeof(UForwardAttribute), true)).Length > 0) { UForwardAttribute fattrib = (UForwardAttribute)attribs[0]; /*if (fattrib.Target == null) * { * if (m_EventsByAddHandler.ContainsKey((int)method.MethodHandle.Value)) * returnValue = fattrib.onAdd.Invoke(null, methodMessage.Args); * else if (m_EventsByRemoveHandler.ContainsKey((int)method.MethodHandle.Value)) * returnValue = fattrib.onRemove.Invoke(null, methodMessage.Args); * else * returnValue = null; * } * else*/ returnValue = fattrib.Target.Invoke(null, methodMessage.Args); } else if ((methodMessage.ArgCount == 1) && (methodMessage.Args[0] is Delegate)) { returnValue = null; if (m_EventsByAddHandler.ContainsKey((int)method.MethodHandle.Value)) { m_EventsByAddHandler[(int)method.MethodHandle.Value].Add((Delegate)methodMessage.Args[0]); } else if (m_EventsByRemoveHandler.ContainsKey((int)method.MethodHandle.Value)) { m_EventsByRemoveHandler[(int)method.MethodHandle.Value].Remove((Delegate)methodMessage.Args[0]); } } } returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage); return(returnMessage); }
//Hooks for Windows Messages //-> currently for the WM_QUIT, WM_KEYDOWN, WM_KEYUP messages //-> i could add a general onMessage(MSG msg) hook //-> but that would have the potential of slowing the client down enormously private int MessageHook(int code, IntPtr wParam, IntPtr lParam) { UnmanagedBuffer msgbuff = new UnmanagedBuffer(lParam); Imports.MSG msg = msgbuff.Read <Imports.MSG>(); bool drop = false; lock (windowsmessage_handlers) { //invoke general message handlers (don't use these unless really necessary.. the WILL slow down the client) foreach (OnWindowsMessageDelegate del in Client.windowsmessage_handlers.ToArray())//toarray is needed to ensure we can remove handlers while enumerating (list can't change while enumerating it, so we enumerate a copy (the array) of it. { try { if (m_InvokationTarget != null) { if (m_AsyncInvokation) { m_InvokationTarget.BeginInvoke(del, new object[] { msg }); } else if (!(bool)m_InvokationTarget.Invoke(del, new object[] { msg })) { drop = true; } } else if (!del.Invoke(ref msg)) { drop = true; } } catch { windowsmessage_handlers.Remove(del); } } if (drop) { msg.message = drop_msg_message; } } if (msg.message == (uint)WindowHandler.Messages.WM_QUIT) { m_ShuttingDown = true; lock (quit_handlers) { //invoke on quit foreach (SimpleDelegate del in Client.quit_handlers.ToArray())//toarray is needed to ensure we can remove handlers while enumerating (list can't change while enumerating it, so we enumerate a copy (the array) of it. { try { if (m_InvokationTarget != null) { if (m_AsyncInvokation) { m_InvokationTarget.BeginInvoke(del, new object[] { }); } else { m_InvokationTarget.Invoke(del, new object[] { }); } } else { del.Invoke(); } } catch { quit_handlers.Remove(del); } } } foreach (LocalHook lh in m_Hooks) { lh.UnHook(); } } else if (msg.message == (uint)WindowHandler.Messages.WM_KEYDOWN) { bool dropkey = false; bool repeated = (msg.lParam & (2 ^ 30)) != 0; lock (keydown_handlers) { //invoke onkeydown foreach (OnKeyDownDelegate del in Client.keydown_handlers.ToArray())//toarray is needed to ensure we can remove handlers while enumerating (list can't change while enumerating it, so we enumerate a copy (the array) of it. { try { if (m_InvokationTarget != null) { if (m_AsyncInvokation) { m_InvokationTarget.BeginInvoke(del, new object[] { msg.wParam, repeated }); } else if (!(bool)m_InvokationTarget.Invoke(del, new object[] { msg.wParam, repeated })) { dropkey = true; break; } } else if (!del.Invoke(msg.wParam, repeated)) { dropkey = true; break; } } catch { keydown_handlers.Remove(del); } } } if (dropkey) { msg.message = drop_msg_message; } } else if (msg.message == (uint)WindowHandler.Messages.WM_KEYUP) { bool dropkey = false; lock (keyup_handlers) { //invoke onkeyup foreach (OnKeyUpDelegate del in Client.keyup_handlers.ToArray())//use of toarray is needed to be able to remove handlers while enumerating { try { if (m_InvokationTarget != null) { if (m_AsyncInvokation) { m_InvokationTarget.BeginInvoke(del, new object[] { msg.wParam }); } else if (!(bool)m_InvokationTarget.Invoke(del, new object[] { msg.wParam })) { dropkey = true; break; } } else if (!del.Invoke(msg.wParam)) { dropkey = true; break; } } catch { keyup_handlers.Remove(del); } } } if (dropkey) { msg.message = drop_msg_message; } } msgbuff.WriteAt <Imports.MSG>(msg, 0); return(Imports.CallNextHookEx(IntPtr.Zero, code, wParam, lParam)); }
public bool NetworkObject_onPacketRecieve(UnmanagedBuffer packet) { AddToListBox("received: " + ((byte)packet.Read(typeof(byte))).ToString("X")); return(true); }
public bool NetworkObject_onPacketSend(UnmanagedBuffer packet) { AddToListBox("sent: " + ((byte)packet.Read(typeof(byte))).ToString("X")); return(true); }