public unsafe int SetCooperativeLevel(DirectInput8.IDirectInputDevice8 *This, IntPtr hWnd, UInt32 dwFlags) { DSetCooperativeLevel del = (DSetCooperativeLevel)Marshal.GetDelegateForFunctionPointer(oldSetCooperativeLevel, typeof(DSetCooperativeLevel)); /* Ask for non-exclusive, foreground-only access. Might need to revisit this for gamepads... */ dwFlags = DirectInput8.DISCL_NONEXCLUSIVE | DirectInput8.DISCL_FOREGROUND; return(del(This, hWnd, dwFlags)); }
public unsafe IDirectInputDevice8(DirectInput8.IDirectInputDevice8 *InDevice, YggdrasillInterface iface) { Device = InDevice; Interface = iface; /* Hook up any functions we care about */ OverrideFunctions(); }
public unsafe int GetDeviceState(DirectInput8.IDirectInputDevice8 *This, UInt32 cbData, IntPtr lpData) { DGetDeviceState del = (DGetDeviceState)Marshal.GetDelegateForFunctionPointer(oldGetDeviceState, typeof(DGetDeviceState)); int rv = del(This, cbData, lpData); /* XXXX: HACK!! 20 is the size of mouse data... Hopefully it isn't the size of anything else we care about. */ if (cbData == 20) { DirectInput8.DIMOUSESTATE2 *ms = (DirectInput8.DIMOUSESTATE2 *)lpData; Process p = Process.GetCurrentProcess(); /* We only care when we go from not clicked to clicked... */ if (buttonState == 0 && ms->rgbButtons_0 != 0) { User32.RECT wndRect = new User32.RECT(); User32.POINT point = new User32.POINT(); User32.GetWindowRect(p.MainWindowHandle, ref wndRect); User32.GetCursorPos(out point); /* Check bounds. */ if (point.X < wndRect.Left || point.X > wndRect.Right || point.Y < wndRect.Top || point.Y > wndRect.Bottom) { ms->rgbButtons_0 = 0; ms->rgbButtons_1 = 0; } } buttonState = ms->rgbButtons_0; } /* La de dah... Imma collect some garbage now. */ GC.Collect(); return(rv); }