diff --git a/Artemis/Artemis/Managers/EffectManager.cs b/Artemis/Artemis/Managers/EffectManager.cs index e8ef40679..5936411dd 100644 --- a/Artemis/Artemis/Managers/EffectManager.cs +++ b/Artemis/Artemis/Managers/EffectManager.cs @@ -35,8 +35,8 @@ namespace Artemis.Managers models.AddRange(overlayModels); // Add games, exclude WoW if needed models.AddRange(_generalSettings.GamestatePort != 62575 - ? gameModels.Where(e => e.Name != "WoW") - : gameModels); + ? gameModels.Where(e => e.Name != "WoW").Where(e => e.Name != "LightFX") + : gameModels.Where(e => e.Name != "LightFX")); EffectModels = models; _logger.Info("Intialized EffectManager"); @@ -72,7 +72,7 @@ namespace Artemis.Managers /// public IEnumerable EnabledGames { - get { return EffectModels.OfType().Where(g => g.Enabled); } + get { return EffectModels.OfType().Where(g => g.Enabled && g.Settings.Enabled); } } public event EventHandler OnEffectChangedEvent; @@ -138,14 +138,16 @@ namespace Artemis.Managers { if (!wasNull) ActiveEffect.Dispose(); - - ActiveEffect = effectModel; - ActiveEffect.Enable(); - if (!ActiveEffect.Initialized) + lock (effectModel) { - _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name); - ActiveEffect = null; - return; + ActiveEffect = effectModel; + ActiveEffect.Enable(); + if (!ActiveEffect.Initialized) + { + _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name); + ActiveEffect = null; + return; + } } } diff --git a/Artemis/Artemis/Managers/LuaManager.cs b/Artemis/Artemis/Managers/LuaManager.cs index 3cf15a722..1aa9ea63d 100644 --- a/Artemis/Artemis/Managers/LuaManager.cs +++ b/Artemis/Artemis/Managers/LuaManager.cs @@ -40,6 +40,7 @@ namespace Artemis.Managers public void SetupLua(ProfileModel profileModel) { + _logger.Debug("Setting up LUA for {0}-{1}.", profileModel?.Name, profileModel?.GameName); // Clear old state ClearLua(); @@ -72,7 +73,6 @@ namespace Artemis.Managers { lock (_luaScript) { - UpdateLuaSource(ProfileModel); _luaScript.DoString(ProfileModel.LuaScript); } } @@ -179,20 +179,6 @@ namespace Artemis.Managers #endregion - /// - /// Updates a profile's LUA script to be compatible with the latest version of Artemis, if needed. - /// This function obviously won't fix completely custom profiles but it'll fix copied LUA. - /// - /// - private static void UpdateLuaSource(ProfileModel profileModel) - { - // 1.7.1.0 - Events cleanup - profileModel.LuaScript = profileModel.LuaScript.Replace("function updateHandler(profile, eventArgs)", - "function updateHandler(eventArgs)"); - profileModel.LuaScript = profileModel.LuaScript.Replace("function drawHandler(profile, eventArgs)", - "function drawHandler(eventArgs)"); - } - #region Editor public void OpenEditor() diff --git a/Artemis/Artemis/Models/EffectModel.cs b/Artemis/Artemis/Models/EffectModel.cs index 17a26a56c..600f7e1fd 100644 --- a/Artemis/Artemis/Models/EffectModel.cs +++ b/Artemis/Artemis/Models/EffectModel.cs @@ -23,17 +23,14 @@ namespace Artemis.Models protected DateTime LastTrace; - protected EffectModel(DeviceManager deviceManager, LuaManager luaManager, EffectSettings settings, IDataModel dataModel) + protected EffectModel(DeviceManager deviceManager, LuaManager luaManager, EffectSettings settings, + IDataModel dataModel) { DeviceManager = deviceManager; LuaManager = luaManager; Settings = settings; DataModel = dataModel; - // If set, load the last profile from settings - if (!string.IsNullOrEmpty(Settings?.LastProfile)) - Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile); - DeviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent; } @@ -45,6 +42,7 @@ namespace Artemis.Models public int KeyboardScale { get; set; } = 4; // Used by profile system public IDataModel DataModel { get; set; } + public ProfileModel Profile { get; set; } [Inject] @@ -53,16 +51,26 @@ namespace Artemis.Models public virtual void Dispose() { Profile?.Deactivate(LuaManager); + Profile = null; } private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs args) { if (!string.IsNullOrEmpty(Settings?.LastProfile)) Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile); + else + Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default"); } // Called on creation - public abstract void Enable(); + public virtual void Enable() + { + // If set, load the last profile from settings + if (!string.IsNullOrEmpty(Settings?.LastProfile)) + Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile); + else + Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default"); + } // Called every frame public abstract void Update(); @@ -75,9 +83,9 @@ namespace Artemis.Models /// public virtual void Render(RenderFrame frame, bool keyboardOnly) { - if ((Profile == null) || (DataModel == null) || (DeviceManager.ActiveKeyboard == null)) + if (Profile == null || DataModel == null || DeviceManager.ActiveKeyboard == null) return; - + lock (DataModel) { lock (Profile) diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs index 20d545bec..6fd367001 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs @@ -1,273 +1,275 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using Artemis.DAL; -using Artemis.Managers; -using Artemis.Models; -using Artemis.Profiles.Layers.Models; -using Artemis.Utilities; -using Newtonsoft.Json; -using SpotifyAPI.Local; - -namespace Artemis.Modules.Effects.WindowsProfile -{ - public class WindowsProfileModel : EffectModel - { - private List _cores; - private int _cpuFrames; - private DateTime _lastMusicUpdate; - private PerformanceCounter _overallCpu; - private SpotifyLocalAPI _spotify; - private bool _spotifySetupBusy; - - public WindowsProfileModel(DeviceManager deviceManager, LuaManager luaManager) - : base(deviceManager, luaManager, SettingsProvider.Load(), - new WindowsProfileDataModel()) - { - _lastMusicUpdate = DateTime.Now; - - Name = "WindowsProfile"; - } - - public override void Dispose() - { - Initialized = false; - base.Dispose(); - } - - public override void Enable() - { - SetupCpu(); - SetupSpotify(); - - Initialized = true; - } - - public override void Update() - { - var dataModel = (WindowsProfileDataModel) DataModel; - UpdateCpu(dataModel); - UpdateMusicPlayers(dataModel); - UpdateDay(dataModel); - UpdateKeyStates(dataModel); - UpdateActiveWindow(dataModel); - } - - #region Current Time - - private void UpdateDay(WindowsProfileDataModel dataModel) - { - var now = DateTime.Now; - dataModel.CurrentTime.Hours24 = int.Parse(now.ToString("HH")); - dataModel.CurrentTime.Hours12 = int.Parse(now.ToString("hh")); - dataModel.CurrentTime.Minutes = int.Parse(now.ToString("mm")); - dataModel.CurrentTime.Seconds = int.Parse(now.ToString("ss")); - } - - #endregion - - #region CPU - - private void SetupCpu() - { - try - { - _cores = GetPerformanceCounters(); - var coreCount = _cores.Count; - while (coreCount < 8) - { - _cores.Add(null); - coreCount++; - } - _overallCpu = GetOverallPerformanceCounter(); - } - catch (InvalidOperationException) - { - Logger?.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator."); - } - } - - private void UpdateCpu(WindowsProfileDataModel dataModel) - { - if ((_cores == null) || (_overallCpu == null)) - return; - - // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often - _cpuFrames++; - if (_cpuFrames < 16) - return; - - _cpuFrames = 0; - - // Update cores, not ideal but data models don't support lists. - if (_cores[0] != null) - dataModel.Cpu.Core1Usage = (int) _cores[0].NextValue(); - if (_cores[1] != null) - dataModel.Cpu.Core2Usage = (int) _cores[1].NextValue(); - if (_cores[2] != null) - dataModel.Cpu.Core3Usage = (int) _cores[2].NextValue(); - if (_cores[3] != null) - dataModel.Cpu.Core4Usage = (int) _cores[3].NextValue(); - if (_cores[4] != null) - dataModel.Cpu.Core5Usage = (int) _cores[4].NextValue(); - if (_cores[5] != null) - dataModel.Cpu.Core6Usage = (int) _cores[5].NextValue(); - if (_cores[6] != null) - dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue(); - if (_cores[7] != null) - dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue(); - - //From Ted - Let's get overall RAM and CPU usage here - dataModel.Cpu.TotalUsage = (int) _overallCpu.NextValue(); - - var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB(); - var tot = PerformanceInfo.GetTotalMemoryInMiB(); - var percentFree = phav / (decimal) tot * 100; - var percentOccupied = 100 - percentFree; - - dataModel.Performance.RAMUsage = (int) percentOccupied; - } - - public override List GetRenderLayers(bool keyboardOnly) - { - return Profile.GetRenderLayers(DataModel, keyboardOnly, false); - } - - public static PerformanceCounter GetOverallPerformanceCounter() - { - var cpuCounter = new PerformanceCounter - { - CategoryName = "Processor", - CounterName = "% Processor Time", - InstanceName = "_Total" - }; - - return cpuCounter; - } - - public static List GetPerformanceCounters() - { - var performanceCounters = new List(); - var procCount = Environment.ProcessorCount; - for (var i = 0; i < procCount; i++) - { - var pc = new PerformanceCounter("Processor", "% Processor Time", i.ToString()); - performanceCounters.Add(pc); - } - return performanceCounters; - } - - #endregion - - #region Music - - public void SetupSpotify() - { - if (_spotifySetupBusy) - return; - - _spotifySetupBusy = true; - _spotify = new SpotifyLocalAPI(); - - // Connecting can sometimes use a little bit more conviction - Task.Factory.StartNew(() => - { - var tryCount = 0; - while (tryCount <= 10) - { - // Causes WebException if not internet connection is available - try - { - tryCount++; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Net; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using Artemis.DAL; +using Artemis.Managers; +using Artemis.Models; +using Artemis.Profiles.Layers.Models; +using Artemis.Utilities; +using Newtonsoft.Json; +using SpotifyAPI.Local; + +namespace Artemis.Modules.Effects.WindowsProfile +{ + public class WindowsProfileModel : EffectModel + { + private List _cores; + private int _cpuFrames; + private DateTime _lastMusicUpdate; + private PerformanceCounter _overallCpu; + private SpotifyLocalAPI _spotify; + private bool _spotifySetupBusy; + + public WindowsProfileModel(DeviceManager deviceManager, LuaManager luaManager) + : base(deviceManager, luaManager, SettingsProvider.Load(), + new WindowsProfileDataModel()) + { + _lastMusicUpdate = DateTime.Now; + + Name = "WindowsProfile"; + } + + public override void Dispose() + { + Initialized = false; + base.Dispose(); + } + + public override void Enable() + { + base.Enable(); + + SetupCpu(); + SetupSpotify(); + + Initialized = true; + } + + public override void Update() + { + var dataModel = (WindowsProfileDataModel) DataModel; + UpdateCpu(dataModel); + UpdateMusicPlayers(dataModel); + UpdateDay(dataModel); + UpdateKeyStates(dataModel); + UpdateActiveWindow(dataModel); + } + + #region Current Time + + private void UpdateDay(WindowsProfileDataModel dataModel) + { + var now = DateTime.Now; + dataModel.CurrentTime.Hours24 = int.Parse(now.ToString("HH")); + dataModel.CurrentTime.Hours12 = int.Parse(now.ToString("hh")); + dataModel.CurrentTime.Minutes = int.Parse(now.ToString("mm")); + dataModel.CurrentTime.Seconds = int.Parse(now.ToString("ss")); + } + + #endregion + + #region CPU + + private void SetupCpu() + { + try + { + _cores = GetPerformanceCounters(); + var coreCount = _cores.Count; + while (coreCount < 8) + { + _cores.Add(null); + coreCount++; + } + _overallCpu = GetOverallPerformanceCounter(); + } + catch (InvalidOperationException) + { + Logger?.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator."); + } + } + + private void UpdateCpu(WindowsProfileDataModel dataModel) + { + if ((_cores == null) || (_overallCpu == null)) + return; + + // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often + _cpuFrames++; + if (_cpuFrames < 16) + return; + + _cpuFrames = 0; + + // Update cores, not ideal but data models don't support lists. + if (_cores[0] != null) + dataModel.Cpu.Core1Usage = (int) _cores[0].NextValue(); + if (_cores[1] != null) + dataModel.Cpu.Core2Usage = (int) _cores[1].NextValue(); + if (_cores[2] != null) + dataModel.Cpu.Core3Usage = (int) _cores[2].NextValue(); + if (_cores[3] != null) + dataModel.Cpu.Core4Usage = (int) _cores[3].NextValue(); + if (_cores[4] != null) + dataModel.Cpu.Core5Usage = (int) _cores[4].NextValue(); + if (_cores[5] != null) + dataModel.Cpu.Core6Usage = (int) _cores[5].NextValue(); + if (_cores[6] != null) + dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue(); + if (_cores[7] != null) + dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue(); + + //From Ted - Let's get overall RAM and CPU usage here + dataModel.Cpu.TotalUsage = (int) _overallCpu.NextValue(); + + var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB(); + var tot = PerformanceInfo.GetTotalMemoryInMiB(); + var percentFree = phav / (decimal) tot * 100; + var percentOccupied = 100 - percentFree; + + dataModel.Performance.RAMUsage = (int) percentOccupied; + } + + public override List GetRenderLayers(bool keyboardOnly) + { + return Profile.GetRenderLayers(DataModel, keyboardOnly, false); + } + + public static PerformanceCounter GetOverallPerformanceCounter() + { + var cpuCounter = new PerformanceCounter + { + CategoryName = "Processor", + CounterName = "% Processor Time", + InstanceName = "_Total" + }; + + return cpuCounter; + } + + public static List GetPerformanceCounters() + { + var performanceCounters = new List(); + var procCount = Environment.ProcessorCount; + for (var i = 0; i < procCount; i++) + { + var pc = new PerformanceCounter("Processor", "% Processor Time", i.ToString()); + performanceCounters.Add(pc); + } + return performanceCounters; + } + + #endregion + + #region Music + + public void SetupSpotify() + { + if (_spotifySetupBusy) + return; + + _spotifySetupBusy = true; + _spotify = new SpotifyLocalAPI(); + + // Connecting can sometimes use a little bit more conviction + Task.Factory.StartNew(() => + { + var tryCount = 0; + while (tryCount <= 10) + { + // Causes WebException if not internet connection is available + try + { + tryCount++; var connected = _spotify.Connect(); if (connected) break; - Thread.Sleep(1000); - } - catch (WebException) - { - break; - } - - } - _spotifySetupBusy = false; - }); - } - - public void UpdateMusicPlayers(WindowsProfileDataModel dataModel) - { - // This is quite resource hungry so only update it once every two seconds - if (DateTime.Now - _lastMusicUpdate < TimeSpan.FromSeconds(2)) - return; - _lastMusicUpdate = DateTime.Now; - - UpdateSpotify(dataModel); - UpdateGooglePlayMusic(dataModel); - } - - private void UpdateSpotify(WindowsProfileDataModel dataModel) - { - // Spotify - if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning()) - SetupSpotify(); - - var status = _spotify.GetStatus(); - if (status == null) - return; - - dataModel.Spotify.Playing = status.Playing; - dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning(); - - if (status.Track != null) - { - dataModel.Spotify.Artist = status.Track.ArtistResource?.Name; - dataModel.Spotify.SongName = status.Track.TrackResource?.Name; - dataModel.Spotify.Album = status.Track.AlbumResource?.Name; - dataModel.Spotify.SongLength = status.Track.Length; - } - - if (dataModel.Spotify.SongLength > 0) - dataModel.Spotify.SongPercentCompleted = - (int) (status.PlayingPosition / dataModel.Spotify.SongLength * 100.0); - } - - private void UpdateGooglePlayMusic(WindowsProfileDataModel dataModel) - { - // Google Play Music - var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - var json = appData + @"\Google Play Music Desktop Player\json_store\playback.json"; - if (!File.Exists(json)) - return; - - dataModel.GooglePlayMusic = JsonConvert.DeserializeObject(File.ReadAllText(json)); - } - - #endregion - - #region System - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, - CallingConvention = CallingConvention.Winapi)] - public static extern short GetKeyState(int keyCode); - - private void UpdateKeyStates(WindowsProfileDataModel dataModel) - { - dataModel.Keyboard.NumLock = ((ushort) GetKeyState(0x90) & 0xffff) != 0; - dataModel.Keyboard.CapsLock = ((ushort) GetKeyState(0x14) & 0xffff) != 0; - dataModel.Keyboard.ScrollLock = ((ushort) GetKeyState(0x91) & 0xffff) != 0; - } - - private void UpdateActiveWindow(WindowsProfileDataModel dataModel) - { - dataModel.ActiveWindow.ProcessName = ActiveWindowHelper.ActiveWindowProcessName; - dataModel.ActiveWindow.WindowTitle = ActiveWindowHelper.ActiveWindowWindowTitle; - } - - #endregion - } + Thread.Sleep(1000); + } + catch (WebException) + { + break; + } + + } + _spotifySetupBusy = false; + }); + } + + public void UpdateMusicPlayers(WindowsProfileDataModel dataModel) + { + // This is quite resource hungry so only update it once every two seconds + if (DateTime.Now - _lastMusicUpdate < TimeSpan.FromSeconds(2)) + return; + _lastMusicUpdate = DateTime.Now; + + UpdateSpotify(dataModel); + UpdateGooglePlayMusic(dataModel); + } + + private void UpdateSpotify(WindowsProfileDataModel dataModel) + { + // Spotify + if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning()) + SetupSpotify(); + + var status = _spotify.GetStatus(); + if (status == null) + return; + + dataModel.Spotify.Playing = status.Playing; + dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning(); + + if (status.Track != null) + { + dataModel.Spotify.Artist = status.Track.ArtistResource?.Name; + dataModel.Spotify.SongName = status.Track.TrackResource?.Name; + dataModel.Spotify.Album = status.Track.AlbumResource?.Name; + dataModel.Spotify.SongLength = status.Track.Length; + } + + if (dataModel.Spotify.SongLength > 0) + dataModel.Spotify.SongPercentCompleted = + (int) (status.PlayingPosition / dataModel.Spotify.SongLength * 100.0); + } + + private void UpdateGooglePlayMusic(WindowsProfileDataModel dataModel) + { + // Google Play Music + var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + var json = appData + @"\Google Play Music Desktop Player\json_store\playback.json"; + if (!File.Exists(json)) + return; + + dataModel.GooglePlayMusic = JsonConvert.DeserializeObject(File.ReadAllText(json)); + } + + #endregion + + #region System + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, + CallingConvention = CallingConvention.Winapi)] + public static extern short GetKeyState(int keyCode); + + private void UpdateKeyStates(WindowsProfileDataModel dataModel) + { + dataModel.Keyboard.NumLock = ((ushort) GetKeyState(0x90) & 0xffff) != 0; + dataModel.Keyboard.CapsLock = ((ushort) GetKeyState(0x14) & 0xffff) != 0; + dataModel.Keyboard.ScrollLock = ((ushort) GetKeyState(0x91) & 0xffff) != 0; + } + + private void UpdateActiveWindow(WindowsProfileDataModel dataModel) + { + dataModel.ActiveWindow.ProcessName = ActiveWindowHelper.ActiveWindowProcessName; + dataModel.ActiveWindow.WindowTitle = ActiveWindowHelper.ActiveWindowWindowTitle; + } + + #endregion + } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs index e39b96325..1f16bd4b4 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs @@ -22,7 +22,7 @@ namespace Artemis.Modules.Effects.WindowsProfile IParameter[] args = { new ConstructorArgument("mainManager", main), - new ConstructorArgument("gameModel", (WindowsProfileModel) EffectModel), + new ConstructorArgument("effectModel", (WindowsProfileModel) EffectModel), new ConstructorArgument("lastProfile", ((WindowsProfileSettings) EffectSettings).LastProfile) }; ProfileEditor = kernel.Get(args); diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index 321614b5b..cb4ffe5a4 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -52,6 +52,8 @@ namespace Artemis.Modules.Games.CounterStrike public override void Enable() { + base.Enable(); + _gameStateWebServer.GameDataReceived += HandleGameData; Initialized = true; } diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs index 2f1a61c23..f482bc71b 100644 --- a/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs +++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2Model.cs @@ -45,6 +45,8 @@ namespace Artemis.Modules.Games.Dota2 public override void Enable() { + base.Enable(); + _gameStateWebServer.GameDataReceived += HandleGameData; Initialized = true; } diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs index 5ff1873f6..1a9409b1a 100644 --- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs +++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2Model.cs @@ -43,6 +43,8 @@ namespace Artemis.Modules.Games.EurotruckSimulator2 public override void Enable() { + base.Enable(); + Initialized = true; } diff --git a/Artemis/Artemis/Modules/Games/GtaV/GtaVModel.cs b/Artemis/Artemis/Modules/Games/GtaV/GtaVModel.cs index b8e031572..1dd4293f2 100644 --- a/Artemis/Artemis/Modules/Games/GtaV/GtaVModel.cs +++ b/Artemis/Artemis/Modules/Games/GtaV/GtaVModel.cs @@ -27,6 +27,8 @@ namespace Artemis.Modules.Games.GtaV public override void Enable() { + base.Enable(); + DllManager.PlaceLogitechDll(); _pipeServer.PipeMessage += PipeServerOnPipeMessage; Initialized = true; diff --git a/Artemis/Artemis/Modules/Games/LightFx/LightFxModel.cs b/Artemis/Artemis/Modules/Games/LightFx/LightFxModel.cs index d0271d8f7..3d77bc907 100644 --- a/Artemis/Artemis/Modules/Games/LightFx/LightFxModel.cs +++ b/Artemis/Artemis/Modules/Games/LightFx/LightFxModel.cs @@ -56,6 +56,8 @@ namespace Artemis.Modules.Games.LightFx public override void Enable() { + base.Enable(); + Initialized = true; } diff --git a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs index 20a87d9b5..f2d860ca2 100644 --- a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs +++ b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs @@ -82,6 +82,8 @@ namespace Artemis.Modules.Games.Overwatch public override void Enable() { + base.Enable(); + _stickyStatus = new StickyValue(300); _stickyUltimateReady = new StickyValue(350); _stickyUltimateUsed = new StickyValue(350); diff --git a/Artemis/Artemis/Modules/Games/ProjectCars/ProjectCarsModel.cs b/Artemis/Artemis/Modules/Games/ProjectCars/ProjectCarsModel.cs index 145bb6591..c1bb99c98 100644 --- a/Artemis/Artemis/Modules/Games/ProjectCars/ProjectCarsModel.cs +++ b/Artemis/Artemis/Modules/Games/ProjectCars/ProjectCarsModel.cs @@ -33,6 +33,8 @@ namespace Artemis.Modules.Games.ProjectCars public override void Enable() { + base.Enable(); + Initialized = true; } diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs index 8e8673508..abe3193c4 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs @@ -29,14 +29,14 @@ namespace Artemis.Modules.Games.RocketLeague //var offset = new GamePointersCollection //{ // Game = "RocketLeague", - // GameVersion = "1.24", + // GameVersion = "1.26", // GameAddresses = new List // { // new GamePointer // { // Description = "Boost", - // BasePointer = new IntPtr(0x016BBFB4), - // Offsets = new[] { 0xc4, 0x210, 0x320, 0x734, 0x224} + // BasePointer = new IntPtr(0x01666C38), + // Offsets = new[] { 0x58, 0x668, 0x73C, 0x224} // } // } //}; @@ -54,8 +54,9 @@ namespace Artemis.Modules.Games.RocketLeague public override void Enable() { - Initialized = false; + base.Enable(); + Initialized = false; Updater.GetPointers(); _pointer = SettingsProvider.Load().RocketLeague; diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs index 5365aacd4..c80b08998 100644 --- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs +++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs @@ -49,8 +49,9 @@ namespace Artemis.Modules.Games.TheDivision public override void Enable() { - Initialized = false; + base.Enable(); + Initialized = false; _stickyAmmo = new StickyValue(200); _stickyHp = new StickyValue(200); diff --git a/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentModel.cs b/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentModel.cs index ee48801a8..142e852c4 100644 --- a/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentModel.cs +++ b/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentModel.cs @@ -126,6 +126,8 @@ namespace Artemis.Modules.Games.UnrealTournament public override void Enable() { + base.Enable(); + _pipeServer.PipeMessage += PipeServerOnPipeMessage; _killTimer.Start(); diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs index 76070e6eb..109d80155 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs @@ -43,8 +43,9 @@ namespace Artemis.Modules.Games.Witcher3 public override void Enable() { - Initialized = false; + base.Enable(); + Initialized = false; // Ensure the config file is found var witcherSettings = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\The Witcher 3\user.settings"; diff --git a/Artemis/Artemis/Modules/Games/WoW/WoWModel.cs b/Artemis/Artemis/Modules/Games/WoW/WoWModel.cs index 666aa5ca1..400901f17 100644 --- a/Artemis/Artemis/Modules/Games/WoW/WoWModel.cs +++ b/Artemis/Artemis/Modules/Games/WoW/WoWModel.cs @@ -77,6 +77,8 @@ namespace Artemis.Modules.Games.WoW public override void Enable() { + base.Enable(); + var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName); if (tempProcess == null) return; diff --git a/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs index 1e406b540..c023c3d4a 100644 --- a/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaEventsModule.cs @@ -83,15 +83,15 @@ namespace Artemis.Profiles.Lua.Modules } catch (InternalErrorException ex) { - _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); + _logger.Error("[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); } catch (SyntaxErrorException ex) { - _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); + _logger.Error("[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); } catch (ScriptRuntimeException ex) { - _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); + _logger.Error("[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); } } } diff --git a/Artemis/Artemis/Resources/Keyboards/default-profiles.zip b/Artemis/Artemis/Resources/Keyboards/default-profiles.zip index 5713033cc..8553f2868 100644 Binary files a/Artemis/Artemis/Resources/Keyboards/default-profiles.zip and b/Artemis/Artemis/Resources/Keyboards/default-profiles.zip differ diff --git a/Artemis/Artemis/Resources/lua-placeholder.lua b/Artemis/Artemis/Resources/lua-placeholder.lua index 68a963307..87b7a962a 100644 --- a/Artemis/Artemis/Resources/lua-placeholder.lua +++ b/Artemis/Artemis/Resources/lua-placeholder.lua @@ -14,7 +14,7 @@ -- changes are applied to the profile and the script is restarted. -- This event is raised after every profile update, before drawing. -function updateHandler(eventArgs) +function updateHandler(profile, eventArgs) -- In this example we only want to update once per frame when the keyboard is -- updated. If you don't do this the updateHandler will trigger on every -- device's update. @@ -26,7 +26,7 @@ function updateHandler(eventArgs) end -- This event is raised after every profile draw, after updating. -function drawHandler(eventArgs) +function drawHandler(profile, eventArgs) -- In this example we only want to draw to the keyboard. Each device has it's -- own drawing event if eventArgs.DeviceType != "keyboard" then diff --git a/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs b/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs index 295e45b6a..6c8a9703d 100644 --- a/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs +++ b/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs @@ -26,7 +26,7 @@ namespace Artemis.ViewModels.Abstract IParameter[] args = { new ConstructorArgument("mainManager", mainManager), - new ConstructorArgument("gameModel", gameModel), + new ConstructorArgument("effectModel", gameModel), new ConstructorArgument("lastProfile", GameSettings.LastProfile) }; ProfileEditor = kernel.Get(args); @@ -60,7 +60,7 @@ namespace Artemis.ViewModels.Abstract } } - public bool GameEnabled => MainManager.EffectManager.ActiveEffect == GameModel; + public bool GameEnabled => MainManager.EffectManager.ActiveEffect.Name == GameModel.Name; public void ToggleEffect() { diff --git a/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs index 88918413a..ff0385b73 100644 --- a/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/Profiles/ProfileEditorViewModel.cs @@ -35,7 +35,7 @@ namespace Artemis.ViewModels.Profiles public sealed class ProfileEditorViewModel : Screen, IDropTarget { private readonly DeviceManager _deviceManager; - private readonly EffectModel _gameModel; + private readonly EffectModel _effectModel; private readonly LuaManager _luaManager; private readonly Timer _saveTimer; private ImageSource _keyboardPreview; @@ -44,13 +44,13 @@ namespace Artemis.ViewModels.Profiles private bool _saving; private ProfileModel _selectedProfile; - public ProfileEditorViewModel(DeviceManager deviceManager, LuaManager luaManager, EffectModel gameModel, + public ProfileEditorViewModel(DeviceManager deviceManager, LuaManager luaManager, EffectModel effectModel, ProfileViewModel profileViewModel, MetroDialogService dialogService, WindowService windowService, string lastProfile) { _deviceManager = deviceManager; _luaManager = luaManager; - _gameModel = gameModel; + _effectModel = effectModel; ProfileNames = new ObservableCollection(); Layers = new ObservableCollection(); @@ -111,7 +111,7 @@ namespace Artemis.ViewModels.Profiles if (value == SelectedProfile?.Name) return; - SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _gameModel, value); + SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel, value); NotifyOfPropertyChange(() => SelectedProfileName); } } @@ -124,12 +124,21 @@ namespace Artemis.ViewModels.Profiles if (Equals(value, _selectedProfile)) return; - // Deactivate old profile - _selectedProfile?.Deactivate(_luaManager); - // Update the value - _selectedProfile = value; - // Activate new profile - _selectedProfile?.Activate(_luaManager); + if (IsActive) + { + // Deactivate old profile + _selectedProfile?.Deactivate(_luaManager); + // Update the value + _selectedProfile = value; + // Activate new profile + _selectedProfile?.Activate(_luaManager); + } + else + { + // Update the value + _selectedProfile = value; + } + NotifyOfPropertyChange(() => SelectedProfile); NotifyOfPropertyChange(() => SelectedProfileName); } @@ -230,6 +239,7 @@ namespace Artemis.ViewModels.Profiles public void Activate() { + _selectedProfile?.Activate(_luaManager); ProfileViewModel.Activate(); _saveTimer.Start(); } @@ -247,20 +257,20 @@ namespace Artemis.ViewModels.Profiles private void LoadProfiles() { ProfileNames.Clear(); - if (_gameModel == null || _deviceManager.ActiveKeyboard == null) + if (_effectModel == null || _deviceManager.ActiveKeyboard == null) return; - ProfileNames.AddRange(ProfileProvider.GetProfileNames(_deviceManager.ActiveKeyboard, _gameModel)); + ProfileNames.AddRange(ProfileProvider.GetProfileNames(_deviceManager.ActiveKeyboard, _effectModel)); // If a profile name was provided, try to load it ProfileModel lastProfileModel = null; if (!string.IsNullOrEmpty(LastProfile)) - lastProfileModel = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _gameModel, LastProfile); + lastProfileModel = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel, LastProfile); if (lastProfileModel != null) SelectedProfile = lastProfileModel; else - SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _gameModel, + SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel, ProfileNames.FirstOrDefault()); } @@ -293,7 +303,7 @@ namespace Artemis.ViewModels.Profiles IParameter[] args = { - new ConstructorArgument("dataModel", _gameModel.DataModel), + new ConstructorArgument("dataModel", _effectModel.DataModel), new ConstructorArgument("layer", layer) }; WindowService.ShowDialog(args); @@ -502,7 +512,7 @@ namespace Artemis.ViewModels.Profiles KeyboardSlug = _deviceManager.ActiveKeyboard.Slug, Width = _deviceManager.ActiveKeyboard.Width, Height = _deviceManager.ActiveKeyboard.Height, - GameName = _gameModel.Name + GameName = _effectModel.Name }; if (!ProfileProvider.IsProfileUnique(profile)) @@ -624,10 +634,10 @@ namespace Artemis.ViewModels.Profiles } // Verify the game - if (profile.GameName != _gameModel.Name) + if (profile.GameName != _effectModel.Name) { DialogService.ShowErrorMessageBox( - $"Oh oops! This profile is ment for {profile.GameName}, not {_gameModel.Name} :c"); + $"Oh oops! This profile is ment for {profile.GameName}, not {_effectModel.Name} :c"); return; } @@ -690,7 +700,7 @@ namespace Artemis.ViewModels.Profiles return; try { - SelectedProfile?.Activate(_luaManager); + _luaManager.SetupLua(SelectedProfile); _luaManager.OpenEditor(); } catch (Exception e)