using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace ScreenConnect; public class WindowsCursorMessageProcessor : ICursorMessageProcessor, IMessageProcessor, IDisposable { private class WindowsCursor : ICursor, IBlittable, IDisposable { private Cursor cursor; public CorePoint HotSpot => cursor.HotSpot.ToCorePoint(); public object RawObject => cursor; public CoreSize Size => cursor.Size.ToCoreSize(); public WindowsCursor(Cursor cursor) { this.cursor = cursor; } public void Dispose() { cursor.Dispose(); } public IBitmapData AcquireBits(CoreRect bounds) { NativeBitmap nativeBitmap = NativeBitmap.CreateBitmap(bounds.Width, bounds.Height); Graphics val = Graphics.FromHdc(nativeBitmap.DeviceContextHandle); try { cursor.Draw(val, new Rectangle(new Point(-bounds.X, -bounds.Y), cursor.Size)); } finally { ((IDisposable)val)?.Dispose(); } Version trueOSVersion = WindowsExtensions.GetTrueOSVersion(); if (trueOSVersion.Major == 6 && trueOSVersion.Minor == 1) { RawBitmap rawBitmap = new RawBitmap(new BgrPixelModel24(32), bounds.Width, bounds.Height); nativeBitmap.CopyPixelsAndPaddingAlpha(rawBitmap); return rawBitmap; } return nativeBitmap; } public void ReleaseBits(IBitmapData bitmapData) { bitmapData.To().Dispose(); } } private SingleCaptureStreamManager> captureStreamManager; private WindowsCursor cursor; private CorePoint position; public ICursor Cursor => cursor; public ICursor DefaultCursor => new WindowsCursor(Cursors.Default); public CorePoint Position => position; public WindowsCursorMessageProcessor() { captureStreamManager = new SingleCaptureStreamManager>(); } public void Dispose() { captureStreamManager.Dispose(); } public bool ProcessMessage(CursorMessage cursorMessage) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Expected O, but got Unknown Dictionary streamState = captureStreamManager.GetStreamState(cursorMessage); CursorPositionMessage cursorPositionMessage = cursorMessage as CursorPositionMessage; if (streamState == null || cursorPositionMessage == null) { return false; } position = cursorPositionMessage.AssertArgumentNonNull("cursorPositionMessage").Position; if (!streamState.TryGetValue(cursorPositionMessage.CursorID, out cursor)) { StandardCursorPositionMessage standardCursorPositionMessage = cursorPositionMessage as StandardCursorPositionMessage; CustomCursorPositionMessage customCursorPositionMessage = cursorPositionMessage as CustomCursorPositionMessage; if (standardCursorPositionMessage != null) { IntPtr intPtr = WindowsNative.LoadCursor(IntPtr.Zero, (int)standardCursorPositionMessage.StandardCursor); if (intPtr != IntPtr.Zero) { cursor = new WindowsCursor(new Cursor(intPtr)); } } else if (customCursorPositionMessage != null) { WindowsNative.ICONINFO icon = new WindowsNative.ICONINFO { fIcon = false, xHotspot = customCursorPositionMessage.HotSpot.X, yHotspot = customCursorPositionMessage.HotSpot.Y }; try { if (customCursorPositionMessage.ColorImage.Count != 0) { icon.hbmColor = WindowsExtensions.GetHBitmap(customCursorPositionMessage.ColorImage); } if (customCursorPositionMessage.MaskImage.Count != 0) { icon.hbmMask = WindowsExtensions.GetHBitmap(customCursorPositionMessage.MaskImage); } IntPtr intPtr2 = WindowsNative.CreateIconIndirect(ref icon); if (intPtr2 != IntPtr.Zero) { cursor = new WindowsCursor(new Cursor(intPtr2)); } } finally { if (icon.hbmColor != IntPtr.Zero) { WindowsNative.DeleteObject(icon.hbmColor); } if (icon.hbmMask != IntPtr.Zero) { WindowsNative.DeleteObject(icon.hbmMask); } } } if (cursor == null) { cursor = new WindowsCursor(Cursors.Default); } streamState[cursorPositionMessage.CursorID] = cursor; } return true; } }