197 lines
6.0 KiB
C#
197 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Drawing.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using Gma.System.MouseKeyHook;
|
|
|
|
// ReSharper disable FunctionNeverReturns
|
|
// this is pretty normal when there is a daemon thing
|
|
namespace FinalSolution
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private readonly IKeyboardMouseEvents _globalHook;
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
_globalHook = Hook.GlobalEvents();
|
|
RegisterHotkeys();
|
|
}
|
|
|
|
private static Action ToggleCheckBox(CheckBox cb)
|
|
{
|
|
return cb.Toggle;
|
|
}
|
|
|
|
private void RegisterHotkeys()
|
|
{
|
|
var combinations = new Dictionary<Combination, Action>
|
|
{
|
|
{
|
|
Combination.FromString(NetLimiterBridge.F3074.Hotkey),
|
|
ToggleCheckBox(cb_3074DL)
|
|
},
|
|
{
|
|
Combination.FromString(NetLimiterBridge.F3074Ul.Hotkey),
|
|
ToggleCheckBox(cb_3074UL)
|
|
},
|
|
{
|
|
Combination.FromString(NetLimiterBridge.F7500.Hotkey),
|
|
ToggleCheckBox(cb_7500)
|
|
},
|
|
{
|
|
Combination.FromString(NetLimiterBridge.F27K.Hotkey),
|
|
ToggleCheckBox(cb_27k)
|
|
},
|
|
{
|
|
Combination.FromString(NetLimiterBridge.F30K.Hotkey),
|
|
ToggleCheckBox(cb_30k)
|
|
},
|
|
{
|
|
Combination.FromString(NetLimiterBridge.FFullGame.Hotkey),
|
|
ToggleCheckBox(cb_fullGame)
|
|
}
|
|
};
|
|
|
|
_globalHook.OnCombination(combinations);
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
CheckForIllegalCrossThreadCalls = false;
|
|
|
|
BackColor = Color.Wheat;
|
|
TransparencyKey = Color.Wheat;
|
|
FormBorderStyle = FormBorderStyle.None;
|
|
TopMost = true;
|
|
|
|
var initialStyle = NativeUtils.GetWindowLong(Handle, -20);
|
|
NativeUtils.SetWindowLong(Handle, -20, initialStyle | 0x8000 | 0x20);
|
|
|
|
Reposition();
|
|
positionWorker.RunWorkerAsync();
|
|
timerWorker.RunWorkerAsync();
|
|
}
|
|
|
|
private void MainForm_Closing(object sender, CancelEventArgs e)
|
|
{
|
|
_globalHook.Dispose();
|
|
}
|
|
|
|
private void Reposition()
|
|
{
|
|
NativeUtils.GetWindowRect(NativeUtils.handle, out var rect);
|
|
Size = new Size(rect.right - rect.left, rect.bottom - rect.top);
|
|
|
|
Left = rect.left;
|
|
Top = rect.top;
|
|
}
|
|
|
|
private void mainPanel_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void cb_3074DL_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
NetLimiterBridge.F3074.Set(cb_3074DL.Checked);
|
|
SetOrUnsetStartTime(NetLimiterBridge.F3074, out _timer3074Dl);
|
|
}
|
|
|
|
private void cb_3074UL_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
NetLimiterBridge.F3074Ul.Set(cb_3074UL.Checked);
|
|
SetOrUnsetStartTime(NetLimiterBridge.F3074Ul, out _timer3074Ul);
|
|
}
|
|
|
|
private void cb_7500_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
NetLimiterBridge.F7500.Set(cb_7500.Checked);
|
|
SetOrUnsetStartTime(NetLimiterBridge.F7500, out _timer7500);
|
|
}
|
|
|
|
private void cb_27k_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
NetLimiterBridge.F27K.Set(cb_27k.Checked);
|
|
SetOrUnsetStartTime(NetLimiterBridge.F27K, out _timer27K);
|
|
}
|
|
|
|
private void cb_30k_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
NetLimiterBridge.F30K.Set(cb_30k.Checked);
|
|
SetOrUnsetStartTime(NetLimiterBridge.F30K, out _timer30K);
|
|
}
|
|
|
|
private void cb_fullGame_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
NetLimiterBridge.FFullGame.Set(cb_fullGame.Checked);
|
|
SetOrUnsetStartTime(NetLimiterBridge.FFullGame, out _timerFullGame);
|
|
}
|
|
|
|
private void positionWorker_DoWork(object sender, DoWorkEventArgs e)
|
|
{
|
|
while (true)
|
|
{
|
|
Reposition();
|
|
Thread.Sleep(100);
|
|
}
|
|
}
|
|
|
|
private static DateTime? _timer3074Dl;
|
|
private static DateTime? _timer3074Ul;
|
|
private static DateTime? _timer7500;
|
|
private static DateTime? _timer27K;
|
|
private static DateTime? _timer30K;
|
|
private static DateTime? _timerFullGame;
|
|
|
|
private void timerWorker_DoWork(object sender, DoWorkEventArgs e)
|
|
{
|
|
while (true)
|
|
{
|
|
UpdateTimerLabel(timer_3074DL, _timer3074Dl);
|
|
UpdateTimerLabel(timer_3074UL, _timer3074Ul);
|
|
UpdateTimerLabel(timer_7500, _timer7500);
|
|
UpdateTimerLabel(timer_27k, _timer27K);
|
|
UpdateTimerLabel(timer_30k, _timer30K);
|
|
UpdateTimerLabel(timer_fullGame, _timerFullGame);
|
|
Thread.Sleep(10);
|
|
}
|
|
}
|
|
|
|
private static void UpdateTimerLabel(Control timerLabel, DateTime? startTime)
|
|
{
|
|
if (startTime is DateTime dt)
|
|
{
|
|
var elapsed = DateTime.Now - dt;
|
|
timerLabel.Text = $@"{elapsed.TotalSeconds:0.##}s";
|
|
}
|
|
else
|
|
{
|
|
timerLabel.Text = "";
|
|
}
|
|
}
|
|
|
|
private static void SetOrUnsetStartTime(FilterHandle f, out DateTime? dt)
|
|
{
|
|
if (f.IsEnabled())
|
|
{
|
|
dt = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
dt = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class Ext
|
|
{
|
|
public static void Toggle(this CheckBox cb)
|
|
{
|
|
cb.Checked = !cb.Checked;
|
|
}
|
|
}
|
|
} |