/trunk/X-Aim/Form1.Designer.cs |
@@ -1,4 +1,6 @@ |
namespace X_Aim |
using X_Aim.Controls; |
|
namespace X_Aim |
{ |
partial class Form1 |
{ |
@@ -32,8 +34,13 @@ |
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); |
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); |
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); |
this.enableToolStripMenuItem = new X_Aim.Controls.BindableToolStripMenuItem(); |
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); |
this.settingsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); |
this.startWithWindowsToolStripMenuItem = new X_Aim.Controls.BindableToolStripMenuItem(); |
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); |
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); |
this.quitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); |
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); |
this.contextMenuStrip1.SuspendLayout(); |
this.SuspendLayout(); |
// |
@@ -47,19 +54,54 @@ |
// contextMenuStrip1 |
// |
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { |
this.enableToolStripMenuItem, |
this.toolStripSeparator2, |
this.settingsToolStripMenuItem1, |
this.toolStripSeparator1, |
this.aboutToolStripMenuItem, |
this.quitToolStripMenuItem}); |
this.contextMenuStrip1.Name = "contextMenuStrip1"; |
this.contextMenuStrip1.Size = new System.Drawing.Size(144, 48); |
this.contextMenuStrip1.Size = new System.Drawing.Size(144, 104); |
// |
// quitToolStripMenuItem |
// enableToolStripMenuItem |
// |
this.quitToolStripMenuItem.Image = global::X_Aim.Properties.Resources.quit; |
this.quitToolStripMenuItem.Name = "quitToolStripMenuItem"; |
this.quitToolStripMenuItem.Size = new System.Drawing.Size(143, 22); |
this.quitToolStripMenuItem.Text = "Quit"; |
this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click); |
this.enableToolStripMenuItem.Checked = global::X_Aim.Properties.Settings.Default.Enable; |
this.enableToolStripMenuItem.CheckOnClick = true; |
this.enableToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; |
this.enableToolStripMenuItem.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::X_Aim.Properties.Settings.Default, "Enable", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); |
this.enableToolStripMenuItem.Name = "enableToolStripMenuItem"; |
this.enableToolStripMenuItem.Size = new System.Drawing.Size(143, 22); |
this.enableToolStripMenuItem.Text = "Enable"; |
this.enableToolStripMenuItem.CheckStateChanged += new System.EventHandler(this.Enable_OnCheckStateChanged); |
// |
// toolStripSeparator2 |
// |
this.toolStripSeparator2.Name = "toolStripSeparator2"; |
this.toolStripSeparator2.Size = new System.Drawing.Size(140, 6); |
// |
// settingsToolStripMenuItem1 |
// |
this.settingsToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { |
this.startWithWindowsToolStripMenuItem}); |
this.settingsToolStripMenuItem1.Name = "settingsToolStripMenuItem1"; |
this.settingsToolStripMenuItem1.Size = new System.Drawing.Size(143, 22); |
this.settingsToolStripMenuItem1.Text = "Settings"; |
// |
// startWithWindowsToolStripMenuItem |
// |
this.startWithWindowsToolStripMenuItem.Checked = global::X_Aim.Properties.Settings.Default.StartWithWindows; |
this.startWithWindowsToolStripMenuItem.CheckOnClick = true; |
this.startWithWindowsToolStripMenuItem.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::X_Aim.Properties.Settings.Default, "StartWithWindows", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); |
this.startWithWindowsToolStripMenuItem.Name = "startWithWindowsToolStripMenuItem"; |
this.startWithWindowsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); |
this.startWithWindowsToolStripMenuItem.Text = "Start with Windows"; |
this.startWithWindowsToolStripMenuItem.CheckStateChanged += new System.EventHandler(this.StartWithWindows_OnCheckStateChanged); |
// |
// toolStripSeparator1 |
// |
this.toolStripSeparator1.Name = "toolStripSeparator1"; |
this.toolStripSeparator1.Size = new System.Drawing.Size(140, 6); |
// |
// aboutToolStripMenuItem |
// |
this.aboutToolStripMenuItem.Image = global::X_Aim.Properties.Resources.help; |
@@ -68,6 +110,14 @@ |
this.aboutToolStripMenuItem.Text = "Help / About"; |
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); |
// |
// quitToolStripMenuItem |
// |
this.quitToolStripMenuItem.Image = global::X_Aim.Properties.Resources.quit; |
this.quitToolStripMenuItem.Name = "quitToolStripMenuItem"; |
this.quitToolStripMenuItem.Size = new System.Drawing.Size(143, 22); |
this.quitToolStripMenuItem.Text = "Quit"; |
this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click); |
// |
// Form1 |
// |
this.AllowDrop = true; |
@@ -88,6 +138,7 @@ |
this.Text = "Form1"; |
this.TopMost = true; |
this.TransparencyKey = System.Drawing.Color.White; |
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnFormClosing); |
this.Load += new System.EventHandler(this.OnLoad); |
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.OnDragDrop); |
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.OnDragEnter); |
@@ -105,6 +156,11 @@ |
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; |
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; |
private System.Windows.Forms.ToolStripMenuItem quitToolStripMenuItem; |
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; |
private BindableToolStripMenuItem enableToolStripMenuItem; |
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; |
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem1; |
private BindableToolStripMenuItem startWithWindowsToolStripMenuItem; |
} |
} |
|
/trunk/X-Aim/Form1.cs |
@@ -8,23 +8,47 @@ |
using System.Reflection; |
using System.Threading.Tasks; |
using System.Windows.Forms; |
using Microsoft.Win32; |
using X_Aim.Properties; |
|
namespace X_Aim |
{ |
public partial class Form1 : Form |
{ |
private readonly string ACTIVE_CROSSHAIR_FILE_PATH = |
private readonly string _activeCrosshairFilePath = |
$"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/img/activeCrosshair.png"; |
|
private Point firstPoint; |
private Point _firstPoint; |
|
private bool lockedPosition; |
private bool _lockedPosition; |
|
private bool mouseIsDown; |
private bool _mouseIsDown; |
|
public Form1() |
{ |
InitializeComponent(); |
|
// Show or hide the form. |
switch (Settings.Default["Enable"]) |
{ |
case true: |
Show(); |
break; |
default: |
Hide(); |
break; |
} |
|
// Set the application to start with windows. |
switch (Settings.Default["StartWithWindows"]) |
{ |
case true: |
AddApplicationToStartup(); |
break; |
default: |
RemoveApplicationFromStartup(); |
break; |
} |
} |
|
#region Event Handlers |
@@ -39,7 +63,7 @@ |
|
BackgroundImage = draggedImage; |
|
draggedImage.Save(ACTIVE_CROSSHAIR_FILE_PATH, ImageFormat.Png); |
draggedImage.Save(_activeCrosshairFilePath, ImageFormat.Png); |
} |
|
private void OnDragEnter(object sender, DragEventArgs e) |
@@ -49,27 +73,27 @@ |
|
private void OnMouseDown(object sender, MouseEventArgs e) |
{ |
firstPoint = e.Location; |
mouseIsDown = true; |
_firstPoint = e.Location; |
_mouseIsDown = true; |
} |
|
private void OnMouseUp(object sender, MouseEventArgs e) |
{ |
mouseIsDown = false; |
_mouseIsDown = false; |
|
if (e.Button == MouseButtons.Right) |
{ |
lockedPosition = !lockedPosition; |
_lockedPosition = !_lockedPosition; |
|
var resourceImage = lockedPosition ? "X_Aim.img.locked.png" : "X_Aim.img.unlocked.png"; |
var resourceImage = _lockedPosition ? "X_Aim.img.locked.png" : "X_Aim.img.unlocked.png"; |
|
#pragma warning disable 4014 |
#pragma warning disable 4014 |
Task.Run(() => |
#pragma warning restore 4014 |
{ |
Image originalImage = null; |
|
Invoke((MethodInvoker)delegate { originalImage = BackgroundImage; }); |
Invoke((MethodInvoker) delegate { originalImage = BackgroundImage; }); |
|
Image lockImage; |
using (var manifestResourceStream = |
@@ -80,15 +104,15 @@ |
|
foreach (var i in Enumerable.Range(0, 100).Reverse()) |
{ |
Invoke((MethodInvoker)delegate |
Invoke((MethodInvoker) delegate |
{ |
BackgroundImage = SetImageOpacity(lockImage, (float)i / 100); |
BackgroundImage = SetImageOpacity(lockImage, (float) i / 100); |
Invalidate(); |
Refresh(); |
}); |
} |
|
Invoke((MethodInvoker)delegate { BackgroundImage = originalImage; }); |
Invoke((MethodInvoker) delegate { BackgroundImage = originalImage; }); |
}); |
} |
} |
@@ -95,14 +119,14 @@ |
|
private void OnMouseMove(object sender, MouseEventArgs e) |
{ |
if (!mouseIsDown || lockedPosition) |
if (!_mouseIsDown || _lockedPosition) |
{ |
return; |
} |
|
// Get the difference between the two points |
var xDiff = firstPoint.X - e.Location.X; |
var yDiff = firstPoint.Y - e.Location.Y; |
var xDiff = _firstPoint.X - e.Location.X; |
var yDiff = _firstPoint.Y - e.Location.Y; |
|
// Set the new point |
var x = Location.X - xDiff; |
@@ -125,20 +149,22 @@ |
// Set window to top-most. |
Natives.AllowSetForegroundWindow((uint) Process.GetCurrentProcess().Id); |
Natives.SetForegroundWindow(Handle); |
Natives.ShowWindow(Handle, Natives.SW_SHOWNORMAL); |
Natives.ShowWindow(Handle, Natives.SwShownormal); |
|
// If the default crosshair cannot be found, unpack from resources and load the crosshair. |
if (!File.Exists(ACTIVE_CROSSHAIR_FILE_PATH)) |
if (!File.Exists(_activeCrosshairFilePath)) |
{ |
using (var manifestResourceStream = |
Assembly.GetExecutingAssembly().GetManifestResourceStream("X_Aim.img.defaultCrosshair.png")) |
{ |
FileInfo fileInfo = new FileInfo(ACTIVE_CROSSHAIR_FILE_PATH); |
var fileInfo = new FileInfo(_activeCrosshairFilePath); |
|
if (!fileInfo.Exists) |
{ |
Directory.CreateDirectory(fileInfo.Directory.FullName); |
} |
|
using (var fileStream = new FileStream(ACTIVE_CROSSHAIR_FILE_PATH, FileMode.Create)) |
using (var fileStream = new FileStream(_activeCrosshairFilePath, FileMode.Create)) |
{ |
await manifestResourceStream.CopyToAsync(fileStream); |
} |
@@ -145,9 +171,47 @@ |
} |
} |
|
BackgroundImage = LoadImageFromFile(ACTIVE_CROSSHAIR_FILE_PATH); |
using (var fileStream = new FileStream(_activeCrosshairFilePath, FileMode.Open)) |
{ |
BackgroundImage = Image.FromStream(fileStream); |
} |
} |
|
private void OnFormClosing(object sender, FormClosingEventArgs e) |
{ |
Settings.Default.Save(); |
} |
|
private void Enable_OnCheckStateChanged(object sender, EventArgs e) |
{ |
switch (Settings.Default["Enable"]) |
{ |
case true: |
Show(); |
break; |
default: |
Hide(); |
break; |
} |
|
Settings.Default.Save(); |
} |
|
private void StartWithWindows_OnCheckStateChanged(object sender, EventArgs e) |
{ |
switch (Settings.Default["StartWithWindows"]) |
{ |
case true: |
AddApplicationToStartup(); |
break; |
default: |
RemoveApplicationFromStartup(); |
break; |
} |
|
Settings.Default.Save(); |
} |
|
#endregion |
|
/// <summary> |
@@ -167,10 +231,9 @@ |
using (var gfx = Graphics.FromImage(bmp)) |
{ |
//create a color matrix object |
var matrix = new ColorMatrix(); |
var matrix = new ColorMatrix {Matrix33 = opacity}; |
|
//set the opacity |
matrix.Matrix33 = opacity; |
|
//create image attributes |
var attributes = new ImageAttributes(); |
@@ -192,14 +255,6 @@ |
} |
} |
|
private Image LoadImageFromFile(string file) |
{ |
using (var fileStream = new FileStream(file, FileMode.Open)) |
{ |
return Image.FromStream(fileStream); |
} |
} |
|
private bool TryGetDragDropImage(DragEventArgs e, out Image image) |
{ |
var file = ((IEnumerable<string>) e.Data.GetData(DataFormats.FileDrop)).FirstOrDefault(); |
@@ -211,7 +266,10 @@ |
|
try |
{ |
image = LoadImageFromFile(file); |
using (var fileStream = new FileStream(file, FileMode.Open)) |
{ |
image = Image.FromStream(fileStream); |
} |
|
return true; |
} |
@@ -221,5 +279,21 @@ |
return false; |
} |
} |
|
public static void AddApplicationToStartup() |
{ |
using (var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
{ |
key?.SetValue(Assembly.GetExecutingAssembly().FullName, "\"" + Application.ExecutablePath + "\""); |
} |
} |
|
public static void RemoveApplicationFromStartup() |
{ |
using (var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
{ |
key?.DeleteValue(Assembly.GetExecutingAssembly().FullName, false); |
} |
} |
} |
} |
/trunk/X-Aim/Properties/Settings.Designer.cs |
@@ -8,23 +8,43 @@ |
// </auto-generated> |
//------------------------------------------------------------------------------ |
|
namespace X_Aim.Properties |
{ |
|
|
namespace X_Aim.Properties { |
|
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] |
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase |
{ |
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] |
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { |
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); |
|
public static Settings Default |
{ |
get |
{ |
|
public static Settings Default { |
get { |
return defaultInstance; |
} |
} |
|
[global::System.Configuration.UserScopedSettingAttribute()] |
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
[global::System.Configuration.DefaultSettingValueAttribute("True")] |
public bool Enable { |
get { |
return ((bool)(this["Enable"])); |
} |
set { |
this["Enable"] = value; |
} |
} |
|
[global::System.Configuration.UserScopedSettingAttribute()] |
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
[global::System.Configuration.DefaultSettingValueAttribute("False")] |
public bool StartWithWindows { |
get { |
return ((bool)(this["StartWithWindows"])); |
} |
set { |
this["StartWithWindows"] = value; |
} |
} |
} |
} |
/trunk/X-Aim/app.manifest |
@@ -0,0 +1,77 @@ |
<?xml version="1.0" encoding="utf-8"?> |
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> |
<assemblyIdentity version="1.0.0.0" name="X-Aim.app" /> |
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> |
<security> |
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> |
<!-- UAC Manifest Options |
If you want to change the Windows User Account Control level replace the |
requestedExecutionLevel node with one of the following. |
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> |
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> |
<requestedExecutionLevel level="highestAvailable" uiAccess="false" /> |
|
Specifying requestedExecutionLevel element will disable file and registry virtualization. |
Remove this element if your application requires this virtualization for backwards |
compatibility. |
--> |
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> |
</requestedPrivileges> |
</security> |
</trustInfo> |
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> |
<application> |
<!-- A list of the Windows versions that this application has been tested on |
and is designed to work with. Uncomment the appropriate elements |
and Windows will automatically select the most compatible environment. --> |
|
<!-- Windows Vista --> |
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />--> |
|
<!-- Windows 7 --> |
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />--> |
|
<!-- Windows 8 --> |
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />--> |
|
<!-- Windows 8.1 --> |
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />--> |
|
<!-- Windows 10 --> |
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />--> |
|
</application> |
</compatibility> |
|
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher |
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need |
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should |
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. --> |
<!-- |
<application xmlns="urn:schemas-microsoft-com:asm.v3"> |
<windowsSettings> |
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware> |
</windowsSettings> |
</application> |
--> |
|
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) --> |
<!-- |
<dependency> |
<dependentAssembly> |
<assemblyIdentity |
type="win32" |
name="Microsoft.Windows.Common-Controls" |
version="6.0.0.0" |
processorArchitecture="*" |
publicKeyToken="6595b64144ccf1df" |
language="*" |
/> |
</dependentAssembly> |
</dependency> |
--> |
|
</assembly> |