private void HookKeyboardCallback(HookData hookData) { KeyEventInformation info = KeyEventInformation.Get(hookData); Keys key = info.KeyCode | (info.Control ? Keys.Control : Keys.None) | (info.Shift ? Keys.Shift : Keys.None) | (info.Alt ? Keys.Alt : Keys.None); if (info.IsKeyDown) { m_KeyState[info.KeyCode] = true; OnKeyCombo?.Invoke(key); OnKeyDown?.Invoke(key); m_KeyboardDownHandlers.TryInvoke(key); } if (info.IsKeyUp) { m_KeyState[info.KeyCode] = false; OnKeyUp?.Invoke(key); m_KeyboardUpHandlers.TryInvoke(key); } }
public Injector Hook(MethodDefinition hookMethod, HookData hookData = null) { if (TargetMethod == null) { throw new NullReferenceException($"{nameof(TargetMethod)} was null, which must be populated if you want to modify the IL code."); } // TODO: dry coded // TODO: Fix 'PassInvokingInstance' to only execute on target instance types var flags = InjectFlags.PassInvokingInstance; if (TargetMethod.Parameters.Count > 0) { flags |= InjectFlags.PassParametersRef; } if (hookMethod.ReturnType.FullName != TargetAssembly.MainModule.TypeSystem.Void.FullName) { flags |= InjectFlags.ModifyReturn; } hookData ??= new HookData { Flags = flags }; var injector = new InjectionDefinition(TargetMethod, hookMethod, hookData.Flags); injector.Inject(hookData.StartCode, hookData.Token, hookData.Direction); return(this); }
static IntPtr CbHook(int nCode, uint wParam, ref HookData lParam) { if (EnableMouseInput && 0 <= nCode) { _cbHook?.Invoke(wParam, lParam); } return(Native.CallNextHookEx(_handle, nCode, wParam, ref lParam)); }
static IntPtr CbHook(int nCode, uint wParam, ref HookData lParam) { if (EnableKeyInput && 0 <= nCode) { //int vkCode = Marshal.ReadInt32(lParam); _cbHook?.Invoke(wParam, lParam); } return(Native.CallNextHookEx(_handle, nCode, wParam, ref lParam)); }
private MockedRequest MockHookRequest(MockHttpMessageHandler mockHttp, string url, KeyPathDiff[] expectedContent, Author author) { var hookData = new HookData(author, expectedContent); return(mockHttp .When(HttpMethod.Post, url) .WithHeaders("Content-Type", "application/json; charset=utf-8") .WithContent(JsonConvert.SerializeObject(hookData)) .Respond(HttpStatusCode.NoContent)); }
public static void RunSync(Func <Task> func) { var a = HookData.ToReadOnly(); AsyncHelper._myTaskFactory .StartNew <Task>((st) => { HookData.LoadFrom(a); ((State)st).Deconstruct(); return(func()); }, new State()) .Unwrap() .GetAwaiter() .GetResult(); }
private Dictionary <(string type, string url), string> GetHooksWithData( KeyPathsDictionary keyPathsByHookUrlAndType, Dictionary <string, KeyPathDiff> keyPathsDiffs, Author author ) { return(keyPathsByHookUrlAndType.ToDictionary( kvp => kvp.Key, kvp => { var hookKeyPathDiff = kvp.Value.Select(keyPath => keyPathsDiffs[keyPath]); var hookData = new HookData(author, hookKeyPathDiff); return JsonConvert.SerializeObject(hookData); } )); }
private void AddData(HookData data) { if (data is MouseData) { timelineView.Items.Add(new ListViewItem(new string[] { "Mouse", (data as MouseData).mouse.ToString(), "X: " + (data as MouseData).point.x + " Y: " + (data as MouseData).point.y })); } else if (data is KeyboardData) { timelineView.Items.Add(new ListViewItem(new string[] { "Keyboard", "Up", (data as KeyboardData).keyboard.ToString() })); } //Set items scroll to bottom timelineView.Items[timelineView.Items.Count - 1].EnsureVisible(); }
public static KeyEventInformation Get(HookData hookData) { WindowMessage message = (WindowMessage)hookData.wParam; KEYBDINPUT keyboardStruct = Marshal.PtrToStructure <KEYBDINPUT>(hookData.lParam); int scanCode = (int)keyboardStruct.wScan; int timestamp = (int)keyboardStruct.time; bool isKeyDown = message == WindowMessage.WM_KEYDOWN || message == WindowMessage.WM_KEYDOWN; bool isKeyUp = message == WindowMessage.WM_KEYUP || message == WindowMessage.WM_KEYUP; // If specified, the scan code was preceded by a prefix byte that has the value // 0xE0 (224). const uint maskExtendedKey = 0x1; bool isKeyExtended = ((uint)keyboardStruct.dwFlags & maskExtendedKey) > 0; Keys keyData = AppendModifierStates((Keys)keyboardStruct.wVk); return(new KeyEventInformation(keyData, scanCode, timestamp, isKeyDown, isKeyUp, isKeyExtended)); }
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, uint wParam, ref HookData lParam);
private void HookMouseCallback(HookData hookData) { MouseEventInformation info = MouseEventInformation.Get(hookData); int mx = info.X; int my = info.Y; MouseButtons button = info.Button; // 마우스 다운 if (info.IsMouseDown) { if (IsDoubleClick(info)) { info = info.ToDobuleClickMouseEventInformation(); } OnMouseDown?.Invoke(mx, my, button); if (info.Clicks == 2) { m_DoubleButton |= info.Button; } if (info.Clicks == 1) { m_SingleButton |= button; } } // 마우스 업 if (info.IsMouseUp) { OnMouseUp?.Invoke(mx, my, button); // 마우스 클릭 if ((m_SingleButton & button) != MouseButtons.None) { OnMouseClick?.Invoke(mx, my, button); m_SingleButton &= ~button; } // 마우스 더블 클릭 if ((m_DoubleButton & button) != MouseButtons.None) { OnMouseDoubleClick?.Invoke(mx, my, button); m_DoubleButton &= ~button; } if (info.Clicks == 2) { m_PreviousClickedButton = MouseButtons.None; m_PreviousClickedTime = 0; m_PreviousClickedX = m_DefaultPositionXY; m_PreviousClickedY = m_DefaultPositionXY; } if (info.Clicks == 1) { m_PreviousClickedButton = info.Button; m_PreviousClickedTime = info.Timestamp; m_PreviousClickedX = mx; m_PreviousClickedY = my; } } // 마우스 스크롤 if (info.IsMouseWheelScrolled) { OnMouseWheel?.Invoke(mx, my, button, info.Delta > 0 ? 1 : -1); } // 마우스 이동 if (IsMoved(mx, my)) { m_PreviousX = mx; m_PreviousY = my; OnMouseMove?.Invoke(mx, my, button); } // 마우스 드래그 if ((m_SingleButton & MouseButtons.Left) != MouseButtons.None) { if (m_DragStartPositionX == m_DefaultPositionXY && m_DragStartPositionY == m_DefaultPositionXY) { m_DragStartPositionX = mx; m_DragStartPositionY = my; } // 마우스 드래그 스타트 if (m_dragMode == false) { bool isXDragging = Math.Abs(mx - m_DragStartPositionX) > m_SystemDragX; bool isYDragging = Math.Abs(my - m_DragStartPositionY) > m_SystemDragY; m_dragMode = isXDragging || isYDragging; if (m_dragMode == true) { OnMouseDragStart?.Invoke(mx, my, button); } } } else { m_DragStartPositionX = m_DefaultPositionXY; m_DragStartPositionY = m_DefaultPositionXY; // 마우스 드래그 엔드 if (m_dragMode == true) { OnMouseDragEnd?.Invoke(mx, my, button); m_dragMode = false; } } }
private static void CreateConstraint(InternalRopeData ropeData, HookData hookA, HookData hookB, MyCubeBlock blockA, MyCubeBlock blockB) { if (ropeData.GridA == ropeData.GridB) return; var physicsA = blockA.CubeGrid.Physics; var physicsB = blockB.CubeGrid.Physics; if (physicsA == null || physicsB == null || !physicsA.RigidBody.IsAddedToWorld || !physicsB.RigidBody.IsAddedToWorld) return; Vector3D posA, posB; ComputeLocalPosition(blockA, hookA, out posA); ComputeLocalPosition(blockB, hookB, out posB); ropeData.ConstraintData = new HkRopeConstraintData(); { Vector3 posAf = (Vector3)posA; Vector3 posBf = (Vector3)posB; ropeData.ConstraintData.SetInBodySpace( posAf, posBf, physicsA, physicsB); } posA = Vector3D.Transform(posA, physicsA.GetWorldMatrix()); posB = Vector3D.Transform(posB, physicsB.GetWorldMatrix()); ropeData.ConstraintData.LinearLimit = ropeData.Public.CurrentRopeLength; ropeData.ConstraintData.Strength = 0.6f; ropeData.Constraint = new HkConstraint(physicsA.RigidBody, physicsB.RigidBody, ropeData.ConstraintData); physicsA.AddConstraint(ropeData.Constraint); ropeData.Constraint.Enabled = true; ropeData.ConstraintData.Update(ropeData.Constraint); MyCubeGrid.CreateGridGroupLink(GridLinkTypeEnum.Physical, ropeData.RopeId, blockA.CubeGrid, blockB.CubeGrid); physicsA.RigidBody.Activate(); physicsB.RigidBody.Activate(); }
public override unsafe void Hook() { this.DebugMessage("Hook: Begin"); this.DebugMessage("Hook: Before device creation"); using (var d3d = new Direct3D()) { this.DebugMessage("Hook: Direct3D created"); using ( var device = new Device( d3d, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters() { BackBufferWidth = 1, BackBufferHeight = 1 })) { this.id3dDeviceFunctionAddresses.AddRange(this.GetVTblAddresses(device.NativePointer, D3D9_DEVICE_METHOD_COUNT)); } } try { using (var d3dEx = new Direct3DEx()) { this.DebugMessage("Hook: Try Direct3DEx..."); using ( var deviceEx = new DeviceEx( d3dEx, 0, DeviceType.NullReference, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, new PresentParameters() { BackBufferWidth = 1, BackBufferHeight = 1 }, new DisplayModeEx() { Width = 800, Height = 600 })) { this.id3dDeviceFunctionAddresses.AddRange( this.GetVTblAddresses(deviceEx.NativePointer, D3D9_DEVICE_METHOD_COUNT, D3D9Ex_DEVICE_METHOD_COUNT)); this.supportsDirect3DEx = true; } } } catch (Exception) { throw; } this.DebugMessage("Setting up Direct3D hooks..."); this.Direct3DDevice_EndSceneHook = new HookData<Direct3D9Device_EndSceneDelegate>( this.id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.EndScene], new Direct3D9Device_EndSceneDelegate(this.EndSceneHook), this); this.Direct3DDevice_EndSceneHook.ReHook(); this.Hooks.Add(this.Direct3DDevice_EndSceneHook.Hook); this.Direct3DDevice_PresentHook = new HookData<Direct3D9Device_PresentDelegate>( this.id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.Present], new Direct3D9Device_PresentDelegate(this.PresentHook), this); this.Direct3DDevice_ResetHook = new HookData<Direct3D9Device_ResetDelegate>( this.id3dDeviceFunctionAddresses[(int)Direct3DDevice9FunctionOrdinals.Reset], new Direct3D9Device_ResetDelegate(this.ResetHook), this); if (this.supportsDirect3DEx) { this.DebugMessage("Setting up Direct3DEx hooks..."); this.Direct3DDeviceEx_PresentExHook = new HookData<Direct3D9DeviceEx_PresentExDelegate>( this.id3dDeviceFunctionAddresses[(int)Direct3DDevice9ExFunctionOrdinals.PresentEx], new Direct3D9DeviceEx_PresentExDelegate(this.PresentExHook), this); this.Direct3DDeviceEx_ResetExHook = new HookData<Direct3D9DeviceEx_ResetExDelegate>( this.id3dDeviceFunctionAddresses[(int)Direct3DDevice9ExFunctionOrdinals.ResetEx], new Direct3D9DeviceEx_ResetExDelegate(this.ResetExHook), this); } this.Direct3DDevice_ResetHook.ReHook(); this.Hooks.Add(this.Direct3DDevice_ResetHook.Hook); this.Direct3DDevice_PresentHook.ReHook(); this.Hooks.Add(this.Direct3DDevice_PresentHook.Hook); if (this.supportsDirect3DEx) { this.Direct3DDeviceEx_PresentExHook.ReHook(); this.Hooks.Add(this.Direct3DDeviceEx_PresentExHook.Hook); this.Direct3DDeviceEx_ResetExHook.ReHook(); this.Hooks.Add(this.Direct3DDeviceEx_ResetExHook.Hook); } this.DebugMessage("Hook: End"); }
public HookState(CharacterController controller, CharacterMotor motor, HookData data) : base(controller, motor) { this.data = data; hookLayer = 1 << 9; }
public static MouseEventInformation Get(HookData hookData) { WindowMessage message = (WindowMessage)hookData.wParam; MOUSEINPUT mouseStruct = Marshal.PtrToStructure <MOUSEINPUT>(hookData.lParam); int mx = mouseStruct.dx; int my = mouseStruct.dy; int timestamp = (int)mouseStruct.time; MouseButtons button = MouseButtons.None; int delta = 0; int clickCount = 0; bool isMouseDown = false; bool isMouseUp = false; switch (message) { // 마우스 왼쪽 case WindowMessage.WM_LBUTTONDOWN: isMouseDown = true; button = MouseButtons.Left; clickCount = 1; break; case WindowMessage.WM_LBUTTONUP: isMouseUp = true; button = MouseButtons.Left; clickCount = 1; break; case WindowMessage.WM_LBUTTONDBLCLK: isMouseDown = true; button = MouseButtons.Left; clickCount = 2; break; // 마우스 오른쪽 case WindowMessage.WM_RBUTTONDOWN: isMouseDown = true; button = MouseButtons.Right; clickCount = 1; break; case WindowMessage.WM_RBUTTONUP: isMouseUp = true; button = MouseButtons.Right; clickCount = 1; break; case WindowMessage.WM_RBUTTONDBLCLK: isMouseDown = true; button = MouseButtons.Right; clickCount = 2; break; // 마우스 가운데 case WindowMessage.WM_MBUTTONDOWN: isMouseDown = true; button = MouseButtons.Middle; clickCount = 1; break; case WindowMessage.WM_MBUTTONUP: isMouseUp = true; button = MouseButtons.Middle; clickCount = 1; break; case WindowMessage.WM_MBUTTONDBLCLK: isMouseDown = true; button = MouseButtons.Middle; clickCount = 2; break; // 마우스 휠 case WindowMessage.WM_MOUSEWHEEL: delta = (int)mouseStruct.mouseData; break; } return(new MouseEventInformation(button, clickCount, timestamp, mx, my, delta, isMouseDown, isMouseUp)); }
/// <summary> /// Replaces the method body with a call to the <paramref name="signature"/> delegate. NOTE: This overwrites existing IL code. /// </summary> /// <param name="signature">The delegate to call once the <see cref="TargetMethod"/> gets executed.</param> /// <returns>Returns same instance of <see cref="Injector"/> for chaining easability.</returns> public Injector Replace(MethodDefinition hookMethod, HookData hookData = null) { TargetMethod.Body.Instructions.Clear(); return(Hook(hookMethod, hookData)); }
private static void ComputeLocalPosition(MyCubeBlock block, HookData hook, out Vector3D localPosition) { Vector3 instanceLocalPivot = hook.LocalPivot; Vector3.TransformNormal(ref instanceLocalPivot, block.Orientation, out instanceLocalPivot); Vector3D instanceCenter = (Vector3D)(block.Min + block.Max) / 2.0; localPosition = instanceLocalPivot + instanceCenter * block.CubeGrid.GridSize; }
public Injector Hook(HookData hookData = null) { return(Hook(ExecutingMethod, hookData)); }
private static bool TryUpdateHook( GVFSContext context, HookData hook, out string errorMessage) { bool copyHook = false; string enlistmentHookPath = Path.Combine(context.Enlistment.WorkingDirectoryBackingRoot, hook.Path + GVFSPlatform.Instance.Constants.ExecutableExtension); string installedHookPath = Path.Combine(ExecutingDirectory, hook.ExecutableName); if (!context.FileSystem.FileExists(installedHookPath)) { errorMessage = hook.ExecutableName + " cannot be found at " + installedHookPath; return(false); } if (!context.FileSystem.FileExists(enlistmentHookPath)) { copyHook = true; EventMetadata metadata = new EventMetadata(); metadata.Add("Area", "Mount"); metadata.Add(nameof(enlistmentHookPath), enlistmentHookPath); metadata.Add(nameof(installedHookPath), installedHookPath); metadata.Add(TracingConstants.MessageKey.WarningMessage, hook.Name + " not found in enlistment, copying from installation folder"); context.Tracer.RelatedWarning(hook.Name + " MissingFromEnlistment", metadata); } else { try { FileVersionInfo enlistmentVersion = FileVersionInfo.GetVersionInfo(enlistmentHookPath); FileVersionInfo installedVersion = FileVersionInfo.GetVersionInfo(installedHookPath); copyHook = enlistmentVersion.FileVersion != installedVersion.FileVersion; } catch (Exception e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Area", "Mount"); metadata.Add(nameof(enlistmentHookPath), enlistmentHookPath); metadata.Add(nameof(installedHookPath), installedHookPath); metadata.Add("Exception", e.ToString()); context.Tracer.RelatedError(metadata, "Failed to compare " + hook.Name + " version"); errorMessage = "Error comparing " + hook.Name + " versions. " + ConsoleHelper.GetGVFSLogMessage(context.Enlistment.EnlistmentRoot); return(false); } } if (copyHook) { try { CopyHook(context, installedHookPath, enlistmentHookPath); } catch (Exception e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Area", "Mount"); metadata.Add(nameof(enlistmentHookPath), enlistmentHookPath); metadata.Add(nameof(installedHookPath), installedHookPath); metadata.Add("Exception", e.ToString()); context.Tracer.RelatedError(metadata, "Failed to copy " + hook.Name + " to enlistment"); errorMessage = "Error copying " + hook.Name + " to enlistment. " + ConsoleHelper.GetGVFSLogMessage(context.Enlistment.EnlistmentRoot); return(false); } } errorMessage = null; return(true); }
public Injector Replace(HookData hookData = null) { TargetMethod.Body.Instructions.Clear(); return(Hook(ExecutingMethod, hookData)); }