62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
// ReSharper disable ALL
|
|
// Disable all the fucking warnings!
|
|
namespace FinalSolution
|
|
{
|
|
public static class NativeUtils
|
|
{
|
|
private const string WindowName = "Destiny 2";
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern short GetAsyncKeyState(Keys vKey);
|
|
|
|
public static IntPtr handle = FindWindow(null, WindowName);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
|
|
|
[DllImport("user32.dll")]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool GetWindowRect(IntPtr hwnd, out RECT IpRect);
|
|
|
|
public static RECT rect;
|
|
|
|
public struct RECT
|
|
{
|
|
public int left, top, right, bottom;
|
|
}
|
|
|
|
|
|
[DllImport("kernel32")]
|
|
public static extern bool QueryFullProcessImageName(
|
|
[In] IntPtr hProcess,
|
|
[In] uint dwFlags,
|
|
[Out] StringBuilder lpExeName,
|
|
[In, Out] ref uint lpdwSize
|
|
);
|
|
|
|
public static string GetMainModuleFileName(this Process process, int buffer = 1024)
|
|
{
|
|
var fileNameBuilder = new StringBuilder(buffer);
|
|
var bufferLength = (uint)fileNameBuilder.Capacity + 1;
|
|
return QueryFullProcessImageName(process.Handle, 0, fileNameBuilder, ref bufferLength)
|
|
? fileNameBuilder.ToString()
|
|
: null;
|
|
}
|
|
|
|
[DllImport("kernel32", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool AllocConsole();
|
|
}
|
|
} |