mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Fixed LUA being initialized for every effect on UI open
Fixed editing a profile of a game that is running Updated default profiles for Overwatch Added default profiles for Project CARS
This commit is contained in:
parent
a0f6677964
commit
c0918ebea6
@ -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
|
||||
/// </summary>
|
||||
public IEnumerable<GameModel> EnabledGames
|
||||
{
|
||||
get { return EffectModels.OfType<GameModel>().Where(g => g.Enabled); }
|
||||
get { return EffectModels.OfType<GameModel>().Where(g => g.Enabled && g.Settings.Enabled); }
|
||||
}
|
||||
|
||||
public event EventHandler<EffectChangedEventArgs> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="profileModel"></param>
|
||||
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()
|
||||
|
||||
@ -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
|
||||
/// <param name="keyboardOnly"></param>
|
||||
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)
|
||||
|
||||
@ -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<PerformanceCounter> _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<WindowsProfileSettings>(),
|
||||
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<LayerModel> 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<PerformanceCounter> GetPerformanceCounters()
|
||||
{
|
||||
var performanceCounters = new List<PerformanceCounter>();
|
||||
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<PerformanceCounter> _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<WindowsProfileSettings>(),
|
||||
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<LayerModel> 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<PerformanceCounter> GetPerformanceCounters()
|
||||
{
|
||||
var performanceCounters = new List<PerformanceCounter>();
|
||||
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<GooglePlayMusic>(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<GooglePlayMusic>(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
|
||||
}
|
||||
}
|
||||
@ -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<ProfileEditorViewModel>(args);
|
||||
|
||||
@ -52,6 +52,8 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
_gameStateWebServer.GameDataReceived += HandleGameData;
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
@ -45,6 +45,8 @@ namespace Artemis.Modules.Games.Dota2
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
_gameStateWebServer.GameDataReceived += HandleGameData;
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
@ -43,6 +43,8 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,8 @@ namespace Artemis.Modules.Games.GtaV
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
DllManager.PlaceLogitechDll();
|
||||
_pipeServer.PipeMessage += PipeServerOnPipeMessage;
|
||||
Initialized = true;
|
||||
|
||||
@ -56,6 +56,8 @@ namespace Artemis.Modules.Games.LightFx
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@ -82,6 +82,8 @@ namespace Artemis.Modules.Games.Overwatch
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
_stickyStatus = new StickyValue<OverwatchStatus>(300);
|
||||
_stickyUltimateReady = new StickyValue<bool>(350);
|
||||
_stickyUltimateUsed = new StickyValue<bool>(350);
|
||||
|
||||
@ -33,6 +33,8 @@ namespace Artemis.Modules.Games.ProjectCars
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@ -29,14 +29,14 @@ namespace Artemis.Modules.Games.RocketLeague
|
||||
//var offset = new GamePointersCollection
|
||||
//{
|
||||
// Game = "RocketLeague",
|
||||
// GameVersion = "1.24",
|
||||
// GameVersion = "1.26",
|
||||
// GameAddresses = new List<GamePointer>
|
||||
// {
|
||||
// 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<OffsetSettings>().RocketLeague;
|
||||
|
||||
|
||||
@ -49,8 +49,9 @@ namespace Artemis.Modules.Games.TheDivision
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
Initialized = false;
|
||||
base.Enable();
|
||||
|
||||
Initialized = false;
|
||||
_stickyAmmo = new StickyValue<bool>(200);
|
||||
_stickyHp = new StickyValue<bool>(200);
|
||||
|
||||
|
||||
@ -126,6 +126,8 @@ namespace Artemis.Modules.Games.UnrealTournament
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
_pipeServer.PipeMessage += PipeServerOnPipeMessage;
|
||||
_killTimer.Start();
|
||||
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -77,6 +77,8 @@ namespace Artemis.Modules.Games.WoW
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
base.Enable();
|
||||
|
||||
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
|
||||
if (tempProcess == null)
|
||||
return;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -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
|
||||
|
||||
@ -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<ProfileEditorViewModel>(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()
|
||||
{
|
||||
|
||||
@ -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<string>();
|
||||
Layers = new ObservableCollection<LayerModel>();
|
||||
@ -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<LayerEditorViewModel>(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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user