Skip to content

Commit

Permalink
add OpenSourceLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Feb 26, 2021
1 parent 29118b6 commit aacbf01
Show file tree
Hide file tree
Showing 24 changed files with 5,645 additions and 107 deletions.
11 changes: 11 additions & 0 deletions SteamToolsV2+.sln
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steam4NET", "references\Ste
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Titanium.Web.Proxy", "references\Titanium-Web-Proxy\src\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj", "{35D60129-6652-4B6E-A04A-9766C3CF1869}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Application.SteamTools.Tools.OpenSourceLibraryList", "System.Application.SteamTools.Tools.OpenSourceLibraryList\System.Application.SteamTools.Tools.OpenSourceLibraryList.csproj", "{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -283,6 +285,14 @@ Global
{35D60129-6652-4B6E-A04A-9766C3CF1869}.Release|Any CPU.Build.0 = Release|Any CPU
{35D60129-6652-4B6E-A04A-9766C3CF1869}.Release|x86.ActiveCfg = Release|Any CPU
{35D60129-6652-4B6E-A04A-9766C3CF1869}.Release|x86.Build.0 = Release|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Debug|x86.ActiveCfg = Debug|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Debug|x86.Build.0 = Debug|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Release|Any CPU.Build.0 = Release|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Release|x86.ActiveCfg = Release|Any CPU
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -320,6 +330,7 @@ Global
{6DD9644F-F005-4C19-8ADF-70C303EC5BB8} = {8EB91F53-1062-4E9B-8E4A-096F35EA688D}
{3C05CED6-7712-40F0-AF17-8DD3F4C0A224} = {8EB91F53-1062-4E9B-8E4A-096F35EA688D}
{35D60129-6652-4B6E-A04A-9766C3CF1869} = {8EB91F53-1062-4E9B-8E4A-096F35EA688D}
{CF7C2B80-D393-45EA-A67D-DF46FF17B0F8} = {CC6FF77A-6E6B-4D42-B12B-0177745E9D22}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3833E7C5-69BC-4CB3-92CE-A8854AA35D8A}
Expand Down
167 changes: 167 additions & 0 deletions System.Application.SteamTools.Client.Desktop.Windows/MouseHook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;

namespace System
{
internal static class MouseHook
{
delegate int HookProc(int nCode, int wParam, IntPtr lParam);

static int _mouseHookHandle;
static HookProc? _mouseDelegate;

static event MouseUpEventHandler? MouseUp;

public static event MouseUpEventHandler OnMouseUp
{
add
{
Subscribe();
MouseUp += value;
}
remove
{
MouseUp -= value;
Unsubscribe();
}
}

static void Unsubscribe()
{
if (_mouseHookHandle != 0)
{
int result = UnhookWindowsHookEx(_mouseHookHandle);
_mouseHookHandle = 0;
_mouseDelegate = null;
if (result == 0)
{
int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode);
}
}
}

static void Subscribe()
{
if (_mouseHookHandle == 0)
{
var currentProcessMainModuleName = Process.GetCurrentProcess().MainModule?.ModuleName;
if (string.IsNullOrWhiteSpace(currentProcessMainModuleName)) throw new ArgumentNullException(nameof(currentProcessMainModuleName));
_mouseDelegate = MouseHookProc;
_mouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL,
_mouseDelegate,
GetModuleHandle(currentProcessMainModuleName),
0);
if (_mouseHookHandle == 0)
{
int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode);
}
}
}

static int MouseHookProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode >= 0)
{
var mouseHookStructObj = Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
if (mouseHookStructObj == null) throw new ArgumentNullException(nameof(mouseHookStructObj));
var mouseHookStruct = (MSLLHOOKSTRUCT)mouseHookStructObj;
if (wParam == WM_LBUTTONUP)
{
if (MouseUp != null)
{
MouseUp.Invoke(null, new Point(mouseHookStruct.pt.X, mouseHookStruct.pt.Y));
}
}
}
return CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam);
}

const int WH_MOUSE_LL = 14;
const int WM_LBUTTONUP = 0x0202;

[StructLayout(LayoutKind.Sequential)]
struct MSLLHOOKSTRUCT
{
public PointInt32 pt;
public uint mouseData;
public uint flags;
public uint time;
public IntPtr dwExtraInfo;
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr GetModuleHandle(string name);

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
static extern int UnhookWindowsHookEx(int idHook);

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto)]
public static extern IntPtr LoadCursor(IntPtr hInstance, uint lpCursorName);

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto)]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);

public const uint OCR_NORMAL = 32512;
public const uint OCR_IBEAM = 32513;
public const uint OCR_CROSS = 32515;
public const uint OCR_HAND = 32649;

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto)]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam,
IntPtr pvParam, uint fWinIni);

public enum SystemParametersDesktopInfo : uint
{
SPIF_SENDWININICHANGE = 2,
SPI_SETDESKWALLPAPER = 20,
SPI_SETDESKPATTERN = 21,
SPI_SETWORKAREA = 47,
SPI_GETWORKAREA = 48,
SPI_GETFONTSMOOTHING = 74,
SPI_SETFONTSMOOTHING = 75,
SPI_SETCURSORS = 87,
SPI_GETDESKWALLPAPER = 115,
SPI_GETFLATMENU = 4130,
SPI_SETFLATMENU = 4131,
SPI_GETDROPSHADOW = 4132,
SPI_SETDROPSHADOW = 4133,
SPI_GETCLEARTYPE = 4168,
SPI_SETCLEARTYPE = 4169,
SPI_GETFONTSMOOTHINGTYPE = 8202,
SPI_SETFONTSMOOTHINGTYPE = 8203,
SPI_GETFONTSMOOTHINGCONTRAST = 8204,
SPI_SETFONTSMOOTHINGCONTRAST = 8205,
SPI_GETFONTSMOOTHINGORIENTATION = 8210,
SPI_SETFONTSMOOTHINGORIENTATION = 8211
}
[Flags]
public enum SystemParamtersInfoFlags : uint
{
None = 0,
SPIF_UPDATEINIFILE = 1,
SPIF_SENDCHANGE = 2,
SPIF_SENDWININICHANGE = 2
}

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto, EntryPoint = "GetCursorPos")]
public static extern bool GetCursorPos(out PointInt32 pt);

[DllImport(User32Window.LibraryName, CharSet = CharSet.Auto, EntryPoint = "WindowFromPoint")]
public static extern IntPtr WindowFromPoint(PointInt32 pt);
}

internal delegate void MouseUpEventHandler(object? sender, Point p);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.InteropServices;

namespace System
{
internal static class NativeMethods
{
[DllImport("Avrt.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr AvSetMmThreadCharacteristics(string taskName, ref uint taskIndex);
}
}
18 changes: 18 additions & 0 deletions System.Application.SteamTools.Client.Desktop.Windows/PointInt32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Runtime.InteropServices;

namespace System
{
[Serializable]
[StructLayout(LayoutKind.Sequential)]
internal struct PointInt32
{
public int X;
public int Y;

public PointInt32(int x, int y)
{
X = x;
Y = y;
}
}
}
13 changes: 13 additions & 0 deletions System.Application.SteamTools.Client.Desktop.Windows/RECT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;

namespace System
{
[StructLayout(LayoutKind.Sequential)]
internal class RECT
{
public int left;
public int top;
public int width;
public int height;
}
}
Loading

0 comments on commit aacbf01

Please sign in to comment.