diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index ecad2e917..34e59e882 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -1,230 +1,233 @@ - - - - - -
-
-
-
-
-
-
-
-
-
-
-
- - - - - - - - - - True - - - #FFFF5000 - - - #FFFF0000 - - - - - {"Game":"RocketLeague","GameVersion":"1.10","GameAddresses":[{"Description":"Boost","BasePointer":{"value":21998084},"Offsets":[88,1452,1780,540]}]} - - - {"Game":"Witcher3","GameVersion":"1.11","GameAddresses":[{"Description":"Sign","BasePointer":{"value":42942304},"Offsets":[40,16,32,3008]}]} - - - - - True - - - - - 4 - - - 21 - - - True - - - 3 - - - #FFF90000 - - - #FFFF761E - - - #FF00DF00 - - - - - - - - True - - - #FFFF2900 - - - #FF26F600 - - - True - - - True - - - True - - - True - - - True - - - - - C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive - - - True - - - #FFFF2900 - - - #FF26F600 - - - True - - - True - - - True - - - True - - - - - #FFFF2900 - - - #FF26F600 - - - True - - - - - 4 - - - 21 - - - 1 - - - 3 - - - #FF0000FF - - - #FF1E90FF - - - - - False - - - #FFFF5000 - - - #FFFF0000 - - - - - TypeWave - - - - - True - - - #FFFF0000 - - - True - - - 20 - - - 500 - - - 4 - - - - - TypeWave - - - Corsair Gaming K95 RGB - - - True - - - 51364 - - - - - - - - - - - - - - - - - - - - - - - - + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + True + + + #FFFF5000 + + + #FFFF0000 + + + + + {"Game":"RocketLeague","GameVersion":"1.10","GameAddresses":[{"Description":"Boost","BasePointer":{"value":21998084},"Offsets":[88,1452,1780,540]}]} + + + {"Game":"Witcher3","GameVersion":"1.11","GameAddresses":[{"Description":"Sign","BasePointer":{"value":42942304},"Offsets":[40,16,32,3008]}]} + + + + + True + + + + + 4 + + + 21 + + + True + + + 3 + + + #FFF90000 + + + #FFFF761E + + + #FF00DF00 + + + + + + + + True + + + #FFFF2900 + + + #FF26F600 + + + True + + + True + + + True + + + True + + + True + + + + + C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Global Offensive + + + True + + + #FFFF2900 + + + #FF26F600 + + + True + + + True + + + True + + + True + + + + + #FFFF2900 + + + #FF26F600 + + + True + + + + + 4 + + + 21 + + + 1 + + + 3 + + + #FF0000FF + + + #FF1E90FF + + + + + False + + + #FFFF5000 + + + #FFFF0000 + + + + + TypeWave + + + + + True + + + #FFFF0000 + + + True + + + 20 + + + 500 + + + 4 + + + + + TypeWave + + + Corsair Gaming K95 RGB + + + True + + + 51364 + + + True + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index da42f7242..131a161a0 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -151,13 +151,10 @@ ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll True - - ..\packages\MahApps.Metro.1.3.0-ALPHA017\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.2.4.0\lib\net45\MahApps.Metro.dll True - - E:\Downloads\Chome Downloads\MemorySharp-master\MemorySharp-master\MemorySharp\bin\Release\MemorySharp.dll - False @@ -175,7 +172,10 @@ - + + ..\packages\MahApps.Metro.1.2.4.0\lib\net45\System.Windows.Interactivity.dll + True + @@ -227,6 +227,7 @@ Code + @@ -303,6 +304,7 @@ True General.settings + True True @@ -320,6 +322,7 @@ + @@ -417,14 +420,16 @@ + + + SettingsSingleFileGenerator Offsets.Designer.cs - SettingsSingleFileGenerator General.Designer.cs @@ -499,7 +504,6 @@ MSBuild:Compile - PreserveNewest @@ -511,8 +515,6 @@ PreserveNewest - - diff --git a/Artemis/Artemis/Events/ToggleEnabled.cs b/Artemis/Artemis/Events/ToggleEnabled.cs new file mode 100644 index 000000000..014575e6b --- /dev/null +++ b/Artemis/Artemis/Events/ToggleEnabled.cs @@ -0,0 +1,12 @@ +namespace Artemis.Events +{ + public class ToggleEnabled + { + public bool Enabled { get; set; } + + public ToggleEnabled(bool enabled) + { + Enabled = enabled; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs index a109c0ad6..9ed1be889 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs +++ b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs @@ -24,7 +24,12 @@ namespace Artemis.KeyboardProviders.Logitech // Initialize the SDK LogitechGSDK.LogiLedInit(); Thread.Sleep(200); + LogitechGSDK.LogiLedSaveCurrentLighting(); + LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB); + + // Disable keys we can't color + LogitechGSDK.LogiLedSetLighting(0, 0, 0); } public override void Disable() diff --git a/Artemis/Artemis/Models/MainModel.cs b/Artemis/Artemis/Models/MainModel.cs index e795e21b7..e5eaba72f 100644 --- a/Artemis/Artemis/Models/MainModel.cs +++ b/Artemis/Artemis/Models/MainModel.cs @@ -52,6 +52,14 @@ namespace Artemis.Models public void StartEffects() { + if (Enabled) + return; + if (_updateWorker.IsBusy || _processWorker.IsBusy) + { + Events.PublishOnUIThread(new ToggleEnabled(Enabled)); + return; + } + LoadLastKeyboard(); // If no keyboard was loaded, don't enable effects. if (ActiveKeyboard == null) @@ -66,10 +74,16 @@ namespace Artemis.Models // Start the Background Workers _updateWorker.RunWorkerAsync(); _processWorker.RunWorkerAsync(); + + Enabled = true; + Events.PublishOnUIThread(new ToggleEnabled(Enabled)); } public void ShutdownEffects() { + if (!Enabled) + return; + // Stop the Background Worker _updateWorker.CancelAsync(); _processWorker.CancelAsync(); @@ -80,6 +94,9 @@ namespace Artemis.Models ActiveKeyboard?.Disable(); ActiveKeyboard = null; + + Enabled = false; + Events.PublishOnUIThread(new ToggleEnabled(Enabled)); } private void LoadLastKeyboard() @@ -176,6 +193,12 @@ namespace Artemis.Models var sw = new Stopwatch(); while (!_updateWorker.CancellationPending) { + if (ActiveKeyboard == null) + { + Thread.Sleep(1000 / Fps); + continue; + } + sw.Start(); // Update the current effect @@ -186,7 +209,8 @@ namespace Artemis.Models // Draw enabled overlays on top foreach ( - var overlayModel in EffectModels.OfType().Where(overlayModel => overlayModel.Enabled)) + var overlayModel in + EffectModels.OfType().Where(overlayModel => overlayModel.Enabled)) { overlayModel.Update(); bitmap = bitmap != null ? overlayModel.GenerateBitmap(bitmap) : overlayModel.GenerateBitmap(); @@ -197,12 +221,12 @@ namespace Artemis.Models { ActiveKeyboard.DrawBitmap(bitmap); - // debugging + // debugging TODO: Disable when window isn't shown Events.PublishOnUIThread(new ChangeBitmap(bitmap)); } // Sleep according to time left this frame - var sleep = (int) (1000/Fps - sw.ElapsedMilliseconds); + var sleep = (int)(1000 / Fps - sw.ElapsedMilliseconds); if (sleep > 0) Thread.Sleep(sleep); sw.Reset(); diff --git a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs index 8b27d5be0..428cdcd91 100644 --- a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs +++ b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplayModel.cs @@ -74,9 +74,7 @@ namespace Artemis.Modules.Overlays.VolumeDisplay return bitmap; using (var g = Graphics.FromImage(bitmap)) - { VolumeDisplay.Draw(g); - } return bitmap; } diff --git a/Artemis/Artemis/Settings/General.Designer.cs b/Artemis/Artemis/Settings/General.Designer.cs index 702cf4be1..3fb4d979a 100644 --- a/Artemis/Artemis/Settings/General.Designer.cs +++ b/Artemis/Artemis/Settings/General.Designer.cs @@ -70,5 +70,17 @@ namespace Artemis.Settings { this["GamestatePort"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool Autorun { + get { + return ((bool)(this["Autorun"])); + } + set { + this["Autorun"] = value; + } + } } } diff --git a/Artemis/Artemis/Settings/General.settings b/Artemis/Artemis/Settings/General.settings index 647d5ca01..ab7c78638 100644 --- a/Artemis/Artemis/Settings/General.settings +++ b/Artemis/Artemis/Settings/General.settings @@ -1,7 +1,5 @@  - - + @@ -16,5 +14,8 @@ 51364 + + True + \ No newline at end of file diff --git a/Artemis/Artemis/Settings/GeneralSettings.cs b/Artemis/Artemis/Settings/GeneralSettings.cs new file mode 100644 index 000000000..c44be956c --- /dev/null +++ b/Artemis/Artemis/Settings/GeneralSettings.cs @@ -0,0 +1,66 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices.ComTypes; +using Artemis.Utilities; + +namespace Artemis.Settings +{ + public class GeneralSettings + { + public int GamestatePort + { + get { return General.Default.GamestatePort; } + set + { + if (General.Default.GamestatePort == value) return; + General.Default.GamestatePort = value; + ApplyGamestatePort(); + General.Default.Save(); + } + } + + public bool EnablePointersUpdate + { + get { return General.Default.EnablePointersUpdate; } + set + { + if (General.Default.EnablePointersUpdate == value) return; + General.Default.EnablePointersUpdate = value; + General.Default.Save(); + } + } + + public bool Autorun + { + get { return General.Default.Autorun; } + set + { + if (General.Default.Autorun == value) return; + General.Default.Autorun = value; + ApplyAutorun(); + General.Default.Save(); + } + } + + private void ApplyGamestatePort() + { + // TODO: Restart Gamestate server + } + + private void ApplyAutorun() + { + var startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup); + if (Autorun) + { + var link = (IShellLink) new ShellLink(); + link.SetPath(Assembly.GetExecutingAssembly().Location); + var file = (IPersistFile) link; + + file.Save(startupFolder + @"\Artemis.lnk", false); + } + else if (File.Exists(startupFolder + @"\Artemis.lnk")) + File.Delete(startupFolder + @"\Artemis.lnk"); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Utilities/ShellLink.cs b/Artemis/Artemis/Utilities/ShellLink.cs new file mode 100644 index 000000000..914bc33fe --- /dev/null +++ b/Artemis/Artemis/Utilities/ShellLink.cs @@ -0,0 +1,46 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace Artemis.Utilities +{ + /// + /// Creates a shortcut (.lnk) file. + /// Source: http://stackoverflow.com/a/14632782/5015269 + /// + [ComImport] + [Guid("00021401-0000-0000-C000-000000000046")] + internal class ShellLink + { + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214F9-0000-0000-C000-000000000046")] + internal interface IShellLink + { + void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd, + int fFlags); + + void GetIDList(out IntPtr ppidl); + void SetIDList(IntPtr pidl); + void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName); + void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); + void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); + void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); + void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); + void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); + void GetHotkey(out short pwHotkey); + void SetHotkey(short wHotkey); + void GetShowCmd(out int piShowCmd); + void SetShowCmd(int iShowCmd); + + void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, + out int piIcon); + + void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); + void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved); + void Resolve(IntPtr hwnd, int fFlags); + void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile); + } +} \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs index bee91c22c..c45110db4 100644 --- a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs +++ b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs @@ -1,24 +1,42 @@ using System.Diagnostics; using System.Linq; -using System.Windows.Forms; +using Artemis.Events; using Artemis.Models; +using Artemis.Settings; using Caliburn.Micro; using MahApps.Metro.Controls; namespace Artemis.ViewModels.Flyouts { - public class FlyoutSettingsViewModel : FlyoutBaseViewModel + public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle { + private bool _enabled; + private GeneralSettings _generalSettings; private string _selectedKeyboardProvider; - public MainModel MainModel { get; set; } public FlyoutSettingsViewModel(MainModel mainModel) { MainModel = mainModel; Header = "settings"; Position = Position.Right; + GeneralSettings = new GeneralSettings(); + + MainModel.Events.Subscribe(this); } + public GeneralSettings GeneralSettings + { + get { return _generalSettings; } + set + { + if (Equals(value, _generalSettings)) return; + _generalSettings = value; + NotifyOfPropertyChange(() => GeneralSettings); + } + } + + public MainModel MainModel { get; set; } + public BindableCollection KeyboardProviders => new BindableCollection(MainModel.KeyboardProviders.Select(k => k.Name)); @@ -30,11 +48,38 @@ namespace Artemis.ViewModels.Flyouts if (value == _selectedKeyboardProvider) return; _selectedKeyboardProvider = value; NotifyOfPropertyChange(() => SelectedKeyboardProvider); + if (value == null) + return; MainModel.ChangeKeyboard(MainModel.KeyboardProviders.First(k => k.Name == _selectedKeyboardProvider)); } } + public bool Enabled + { + get { return _enabled; } + set + { + if (value == _enabled) return; + _enabled = value; + + NotifyOfPropertyChange(() => Enabled); + } + } + + public void Handle(ToggleEnabled message) + { + Enabled = message.Enabled; + } + + public void ToggleEnabled() + { + if (Enabled) + MainModel.ShutdownEffects(); + else + MainModel.StartEffects(); + } + public void NavigateTo(string url) { Process.Start(new ProcessStartInfo(url)); diff --git a/Artemis/Artemis/ViewModels/ShellViewModel.cs b/Artemis/Artemis/ViewModels/ShellViewModel.cs index 9ca08e766..bbbc85191 100644 --- a/Artemis/Artemis/ViewModels/ShellViewModel.cs +++ b/Artemis/Artemis/ViewModels/ShellViewModel.cs @@ -24,24 +24,11 @@ namespace Artemis.ViewModels _overlaysVm = new OverlaysViewModel(MainModel) {DisplayName = "Overlays"}; Flyouts.Add(new FlyoutSettingsViewModel(MainModel)); - - // By now Effects are added to the MainModel so we can savely start one - ToggleEffects(); } public IObservableCollection Flyouts { get; set; } = new BindableCollection(); - public bool EffectsEnabled - { - get { return MainModel.Enabled; } - private set - { - MainModel.Enabled = value; - NotifyOfPropertyChange(() => EffectsEnabled); - } - } - public MainModel MainModel { get; set; } protected override void OnActivate() @@ -53,16 +40,6 @@ namespace Artemis.ViewModels ActivateItem(_overlaysVm); } - public void ToggleEffects() - { - if (EffectsEnabled) - MainModel.ShutdownEffects(); - else - MainModel.StartEffects(); - - EffectsEnabled = !EffectsEnabled; - } - public void OnClose(EventArgs e) { MainModel.ShutdownEffects(); diff --git a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs index a9015b07a..9cfa4635f 100644 --- a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs +++ b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs @@ -1,13 +1,16 @@ using System.Windows; +using Artemis.Events; using Caliburn.Micro; namespace Artemis.ViewModels { - public class SystemTrayViewModel : Screen + public class SystemTrayViewModel : Screen, IHandle { private readonly ShellViewModel _shellViewModel; private readonly IWindowManager _windowManager; + private bool _enabled; + private string _toggleText; /* * NOTE: In this sample the system tray view-model doesn't receive any notification * when the other window gets closed by pressing the top right 'x'. @@ -21,6 +24,14 @@ namespace Artemis.ViewModels { _windowManager = windowManager; _shellViewModel = shellViewModel; + _shellViewModel.MainModel.Events.Subscribe(this); + + /* + * By now Effects are added to the MainModel so we can savely start + * This is done from here to make sure all UI elements listening to + * events will receive the first ToggleEnabled event + * */ + _shellViewModel.MainModel.StartEffects(); // TODO: Check if show on startup is enabled, if so, show window. } @@ -29,6 +40,43 @@ namespace Artemis.ViewModels public bool CanHideWindow => _shellViewModel.IsActive; + public bool Enabled + { + get { return _enabled; } + set + { + if (value == _enabled) return; + _enabled = value; + + ToggleText = _enabled ? "Disable Artemis" : "Enable Artemis"; + NotifyOfPropertyChange(() => Enabled); + } + } + + public string ToggleText + { + get { return _toggleText; } + set + { + if (value == _toggleText) return; + _toggleText = value; + NotifyOfPropertyChange(() => ToggleText); + } + } + + public void Handle(ToggleEnabled message) + { + Enabled = message.Enabled; + } + + public void ToggleEnabled() + { + if (Enabled) + _shellViewModel.MainModel.ShutdownEffects(); + else + _shellViewModel.MainModel.StartEffects(); + } + protected override void OnActivate() { base.OnActivate(); diff --git a/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml b/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml index 7e3745fd9..5a2a4ce0c 100644 --- a/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml +++ b/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml @@ -31,12 +31,15 @@