1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 02:03:32 +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:
SpoinkyNL 2017-01-01 01:07:22 +01:00
parent a0f6677964
commit c0918ebea6
22 changed files with 364 additions and 335 deletions

View File

@ -35,8 +35,8 @@ namespace Artemis.Managers
models.AddRange(overlayModels); models.AddRange(overlayModels);
// Add games, exclude WoW if needed // Add games, exclude WoW if needed
models.AddRange(_generalSettings.GamestatePort != 62575 models.AddRange(_generalSettings.GamestatePort != 62575
? gameModels.Where(e => e.Name != "WoW") ? gameModels.Where(e => e.Name != "WoW").Where(e => e.Name != "LightFX")
: gameModels); : gameModels.Where(e => e.Name != "LightFX"));
EffectModels = models; EffectModels = models;
_logger.Info("Intialized EffectManager"); _logger.Info("Intialized EffectManager");
@ -72,7 +72,7 @@ namespace Artemis.Managers
/// </summary> /// </summary>
public IEnumerable<GameModel> EnabledGames 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; public event EventHandler<EffectChangedEventArgs> OnEffectChangedEvent;
@ -138,14 +138,16 @@ namespace Artemis.Managers
{ {
if (!wasNull) if (!wasNull)
ActiveEffect.Dispose(); ActiveEffect.Dispose();
lock (effectModel)
ActiveEffect = effectModel;
ActiveEffect.Enable();
if (!ActiveEffect.Initialized)
{ {
_logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name); ActiveEffect = effectModel;
ActiveEffect = null; ActiveEffect.Enable();
return; if (!ActiveEffect.Initialized)
{
_logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name);
ActiveEffect = null;
return;
}
} }
} }

View File

@ -40,6 +40,7 @@ namespace Artemis.Managers
public void SetupLua(ProfileModel profileModel) public void SetupLua(ProfileModel profileModel)
{ {
_logger.Debug("Setting up LUA for {0}-{1}.", profileModel?.Name, profileModel?.GameName);
// Clear old state // Clear old state
ClearLua(); ClearLua();
@ -72,7 +73,6 @@ namespace Artemis.Managers
{ {
lock (_luaScript) lock (_luaScript)
{ {
UpdateLuaSource(ProfileModel);
_luaScript.DoString(ProfileModel.LuaScript); _luaScript.DoString(ProfileModel.LuaScript);
} }
} }
@ -179,20 +179,6 @@ namespace Artemis.Managers
#endregion #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 #region Editor
public void OpenEditor() public void OpenEditor()

View File

@ -23,17 +23,14 @@ namespace Artemis.Models
protected DateTime LastTrace; 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; DeviceManager = deviceManager;
LuaManager = luaManager; LuaManager = luaManager;
Settings = settings; Settings = settings;
DataModel = dataModel; 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; DeviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent;
} }
@ -45,6 +42,7 @@ namespace Artemis.Models
public int KeyboardScale { get; set; } = 4; public int KeyboardScale { get; set; } = 4;
// Used by profile system // Used by profile system
public IDataModel DataModel { get; set; } public IDataModel DataModel { get; set; }
public ProfileModel Profile { get; set; } public ProfileModel Profile { get; set; }
[Inject] [Inject]
@ -53,16 +51,26 @@ namespace Artemis.Models
public virtual void Dispose() public virtual void Dispose()
{ {
Profile?.Deactivate(LuaManager); Profile?.Deactivate(LuaManager);
Profile = null;
} }
private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs args) private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs args)
{ {
if (!string.IsNullOrEmpty(Settings?.LastProfile)) if (!string.IsNullOrEmpty(Settings?.LastProfile))
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile); Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile);
else
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default");
} }
// Called on creation // 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 // Called every frame
public abstract void Update(); public abstract void Update();
@ -75,9 +83,9 @@ namespace Artemis.Models
/// <param name="keyboardOnly"></param> /// <param name="keyboardOnly"></param>
public virtual void Render(RenderFrame frame, bool keyboardOnly) 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; return;
lock (DataModel) lock (DataModel)
{ {
lock (Profile) lock (Profile)

View File

@ -1,273 +1,275 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.DAL; using Artemis.DAL;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Utilities; using Artemis.Utilities;
using Newtonsoft.Json; using Newtonsoft.Json;
using SpotifyAPI.Local; using SpotifyAPI.Local;
namespace Artemis.Modules.Effects.WindowsProfile namespace Artemis.Modules.Effects.WindowsProfile
{ {
public class WindowsProfileModel : EffectModel public class WindowsProfileModel : EffectModel
{ {
private List<PerformanceCounter> _cores; private List<PerformanceCounter> _cores;
private int _cpuFrames; private int _cpuFrames;
private DateTime _lastMusicUpdate; private DateTime _lastMusicUpdate;
private PerformanceCounter _overallCpu; private PerformanceCounter _overallCpu;
private SpotifyLocalAPI _spotify; private SpotifyLocalAPI _spotify;
private bool _spotifySetupBusy; private bool _spotifySetupBusy;
public WindowsProfileModel(DeviceManager deviceManager, LuaManager luaManager) public WindowsProfileModel(DeviceManager deviceManager, LuaManager luaManager)
: base(deviceManager, luaManager, SettingsProvider.Load<WindowsProfileSettings>(), : base(deviceManager, luaManager, SettingsProvider.Load<WindowsProfileSettings>(),
new WindowsProfileDataModel()) new WindowsProfileDataModel())
{ {
_lastMusicUpdate = DateTime.Now; _lastMusicUpdate = DateTime.Now;
Name = "WindowsProfile"; Name = "WindowsProfile";
} }
public override void Dispose() public override void Dispose()
{ {
Initialized = false; Initialized = false;
base.Dispose(); base.Dispose();
} }
public override void Enable() public override void Enable()
{ {
SetupCpu(); base.Enable();
SetupSpotify();
SetupCpu();
Initialized = true; SetupSpotify();
}
Initialized = true;
public override void Update() }
{
var dataModel = (WindowsProfileDataModel) DataModel; public override void Update()
UpdateCpu(dataModel); {
UpdateMusicPlayers(dataModel); var dataModel = (WindowsProfileDataModel) DataModel;
UpdateDay(dataModel); UpdateCpu(dataModel);
UpdateKeyStates(dataModel); UpdateMusicPlayers(dataModel);
UpdateActiveWindow(dataModel); UpdateDay(dataModel);
} UpdateKeyStates(dataModel);
UpdateActiveWindow(dataModel);
#region Current Time }
private void UpdateDay(WindowsProfileDataModel dataModel) #region Current Time
{
var now = DateTime.Now; private void UpdateDay(WindowsProfileDataModel dataModel)
dataModel.CurrentTime.Hours24 = int.Parse(now.ToString("HH")); {
dataModel.CurrentTime.Hours12 = int.Parse(now.ToString("hh")); var now = DateTime.Now;
dataModel.CurrentTime.Minutes = int.Parse(now.ToString("mm")); dataModel.CurrentTime.Hours24 = int.Parse(now.ToString("HH"));
dataModel.CurrentTime.Seconds = int.Parse(now.ToString("ss")); 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 #endregion
private void SetupCpu() #region CPU
{
try private void SetupCpu()
{ {
_cores = GetPerformanceCounters(); try
var coreCount = _cores.Count; {
while (coreCount < 8) _cores = GetPerformanceCounters();
{ var coreCount = _cores.Count;
_cores.Add(null); while (coreCount < 8)
coreCount++; {
} _cores.Add(null);
_overallCpu = GetOverallPerformanceCounter(); coreCount++;
} }
catch (InvalidOperationException) _overallCpu = GetOverallPerformanceCounter();
{ }
Logger?.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator."); 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)) private void UpdateCpu(WindowsProfileDataModel dataModel)
return; {
if ((_cores == null) || (_overallCpu == null))
// CPU is only updated every 15 frames, the performance counter gives 0 if updated too often return;
_cpuFrames++;
if (_cpuFrames < 16) // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
return; _cpuFrames++;
if (_cpuFrames < 16)
_cpuFrames = 0; return;
// Update cores, not ideal but data models don't support lists. _cpuFrames = 0;
if (_cores[0] != null)
dataModel.Cpu.Core1Usage = (int) _cores[0].NextValue(); // Update cores, not ideal but data models don't support lists.
if (_cores[1] != null) if (_cores[0] != null)
dataModel.Cpu.Core2Usage = (int) _cores[1].NextValue(); dataModel.Cpu.Core1Usage = (int) _cores[0].NextValue();
if (_cores[2] != null) if (_cores[1] != null)
dataModel.Cpu.Core3Usage = (int) _cores[2].NextValue(); dataModel.Cpu.Core2Usage = (int) _cores[1].NextValue();
if (_cores[3] != null) if (_cores[2] != null)
dataModel.Cpu.Core4Usage = (int) _cores[3].NextValue(); dataModel.Cpu.Core3Usage = (int) _cores[2].NextValue();
if (_cores[4] != null) if (_cores[3] != null)
dataModel.Cpu.Core5Usage = (int) _cores[4].NextValue(); dataModel.Cpu.Core4Usage = (int) _cores[3].NextValue();
if (_cores[5] != null) if (_cores[4] != null)
dataModel.Cpu.Core6Usage = (int) _cores[5].NextValue(); dataModel.Cpu.Core5Usage = (int) _cores[4].NextValue();
if (_cores[6] != null) if (_cores[5] != null)
dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue(); dataModel.Cpu.Core6Usage = (int) _cores[5].NextValue();
if (_cores[7] != null) if (_cores[6] != null)
dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue(); dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue();
if (_cores[7] != null)
//From Ted - Let's get overall RAM and CPU usage here dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue();
dataModel.Cpu.TotalUsage = (int) _overallCpu.NextValue();
//From Ted - Let's get overall RAM and CPU usage here
var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB(); dataModel.Cpu.TotalUsage = (int) _overallCpu.NextValue();
var tot = PerformanceInfo.GetTotalMemoryInMiB();
var percentFree = phav / (decimal) tot * 100; var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
var percentOccupied = 100 - percentFree; var tot = PerformanceInfo.GetTotalMemoryInMiB();
var percentFree = phav / (decimal) tot * 100;
dataModel.Performance.RAMUsage = (int) percentOccupied; var percentOccupied = 100 - percentFree;
}
dataModel.Performance.RAMUsage = (int) percentOccupied;
public override List<LayerModel> GetRenderLayers(bool keyboardOnly) }
{
return Profile.GetRenderLayers(DataModel, keyboardOnly, false); public override List<LayerModel> GetRenderLayers(bool keyboardOnly)
} {
return Profile.GetRenderLayers(DataModel, keyboardOnly, false);
public static PerformanceCounter GetOverallPerformanceCounter() }
{
var cpuCounter = new PerformanceCounter public static PerformanceCounter GetOverallPerformanceCounter()
{ {
CategoryName = "Processor", var cpuCounter = new PerformanceCounter
CounterName = "% Processor Time", {
InstanceName = "_Total" CategoryName = "Processor",
}; CounterName = "% Processor Time",
InstanceName = "_Total"
return cpuCounter; };
}
return cpuCounter;
public static List<PerformanceCounter> GetPerformanceCounters() }
{
var performanceCounters = new List<PerformanceCounter>(); public static List<PerformanceCounter> GetPerformanceCounters()
var procCount = Environment.ProcessorCount; {
for (var i = 0; i < procCount; i++) var performanceCounters = new List<PerformanceCounter>();
{ var procCount = Environment.ProcessorCount;
var pc = new PerformanceCounter("Processor", "% Processor Time", i.ToString()); for (var i = 0; i < procCount; i++)
performanceCounters.Add(pc); {
} var pc = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
return performanceCounters; performanceCounters.Add(pc);
} }
return performanceCounters;
#endregion }
#region Music #endregion
public void SetupSpotify() #region Music
{
if (_spotifySetupBusy) public void SetupSpotify()
return; {
if (_spotifySetupBusy)
_spotifySetupBusy = true; return;
_spotify = new SpotifyLocalAPI();
_spotifySetupBusy = true;
// Connecting can sometimes use a little bit more conviction _spotify = new SpotifyLocalAPI();
Task.Factory.StartNew(() =>
{ // Connecting can sometimes use a little bit more conviction
var tryCount = 0; Task.Factory.StartNew(() =>
while (tryCount <= 10) {
{ var tryCount = 0;
// Causes WebException if not internet connection is available while (tryCount <= 10)
try {
{ // Causes WebException if not internet connection is available
tryCount++; try
{
tryCount++;
var connected = _spotify.Connect(); var connected = _spotify.Connect();
if (connected) if (connected)
break; break;
Thread.Sleep(1000); Thread.Sleep(1000);
} }
catch (WebException) catch (WebException)
{ {
break; break;
} }
} }
_spotifySetupBusy = false; _spotifySetupBusy = false;
}); });
} }
public void UpdateMusicPlayers(WindowsProfileDataModel dataModel) public void UpdateMusicPlayers(WindowsProfileDataModel dataModel)
{ {
// This is quite resource hungry so only update it once every two seconds // This is quite resource hungry so only update it once every two seconds
if (DateTime.Now - _lastMusicUpdate < TimeSpan.FromSeconds(2)) if (DateTime.Now - _lastMusicUpdate < TimeSpan.FromSeconds(2))
return; return;
_lastMusicUpdate = DateTime.Now; _lastMusicUpdate = DateTime.Now;
UpdateSpotify(dataModel); UpdateSpotify(dataModel);
UpdateGooglePlayMusic(dataModel); UpdateGooglePlayMusic(dataModel);
} }
private void UpdateSpotify(WindowsProfileDataModel dataModel) private void UpdateSpotify(WindowsProfileDataModel dataModel)
{ {
// Spotify // Spotify
if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning()) if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning())
SetupSpotify(); SetupSpotify();
var status = _spotify.GetStatus(); var status = _spotify.GetStatus();
if (status == null) if (status == null)
return; return;
dataModel.Spotify.Playing = status.Playing; dataModel.Spotify.Playing = status.Playing;
dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning(); dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning();
if (status.Track != null) if (status.Track != null)
{ {
dataModel.Spotify.Artist = status.Track.ArtistResource?.Name; dataModel.Spotify.Artist = status.Track.ArtistResource?.Name;
dataModel.Spotify.SongName = status.Track.TrackResource?.Name; dataModel.Spotify.SongName = status.Track.TrackResource?.Name;
dataModel.Spotify.Album = status.Track.AlbumResource?.Name; dataModel.Spotify.Album = status.Track.AlbumResource?.Name;
dataModel.Spotify.SongLength = status.Track.Length; dataModel.Spotify.SongLength = status.Track.Length;
} }
if (dataModel.Spotify.SongLength > 0) if (dataModel.Spotify.SongLength > 0)
dataModel.Spotify.SongPercentCompleted = dataModel.Spotify.SongPercentCompleted =
(int) (status.PlayingPosition / dataModel.Spotify.SongLength * 100.0); (int) (status.PlayingPosition / dataModel.Spotify.SongLength * 100.0);
} }
private void UpdateGooglePlayMusic(WindowsProfileDataModel dataModel) private void UpdateGooglePlayMusic(WindowsProfileDataModel dataModel)
{ {
// Google Play Music // Google Play Music
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var json = appData + @"\Google Play Music Desktop Player\json_store\playback.json"; var json = appData + @"\Google Play Music Desktop Player\json_store\playback.json";
if (!File.Exists(json)) if (!File.Exists(json))
return; return;
dataModel.GooglePlayMusic = JsonConvert.DeserializeObject<GooglePlayMusic>(File.ReadAllText(json)); dataModel.GooglePlayMusic = JsonConvert.DeserializeObject<GooglePlayMusic>(File.ReadAllText(json));
} }
#endregion #endregion
#region System #region System
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true,
CallingConvention = CallingConvention.Winapi)] CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode); public static extern short GetKeyState(int keyCode);
private void UpdateKeyStates(WindowsProfileDataModel dataModel) private void UpdateKeyStates(WindowsProfileDataModel dataModel)
{ {
dataModel.Keyboard.NumLock = ((ushort) GetKeyState(0x90) & 0xffff) != 0; dataModel.Keyboard.NumLock = ((ushort) GetKeyState(0x90) & 0xffff) != 0;
dataModel.Keyboard.CapsLock = ((ushort) GetKeyState(0x14) & 0xffff) != 0; dataModel.Keyboard.CapsLock = ((ushort) GetKeyState(0x14) & 0xffff) != 0;
dataModel.Keyboard.ScrollLock = ((ushort) GetKeyState(0x91) & 0xffff) != 0; dataModel.Keyboard.ScrollLock = ((ushort) GetKeyState(0x91) & 0xffff) != 0;
} }
private void UpdateActiveWindow(WindowsProfileDataModel dataModel) private void UpdateActiveWindow(WindowsProfileDataModel dataModel)
{ {
dataModel.ActiveWindow.ProcessName = ActiveWindowHelper.ActiveWindowProcessName; dataModel.ActiveWindow.ProcessName = ActiveWindowHelper.ActiveWindowProcessName;
dataModel.ActiveWindow.WindowTitle = ActiveWindowHelper.ActiveWindowWindowTitle; dataModel.ActiveWindow.WindowTitle = ActiveWindowHelper.ActiveWindowWindowTitle;
} }
#endregion #endregion
} }
} }

View File

@ -22,7 +22,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
IParameter[] args = IParameter[] args =
{ {
new ConstructorArgument("mainManager", main), new ConstructorArgument("mainManager", main),
new ConstructorArgument("gameModel", (WindowsProfileModel) EffectModel), new ConstructorArgument("effectModel", (WindowsProfileModel) EffectModel),
new ConstructorArgument("lastProfile", ((WindowsProfileSettings) EffectSettings).LastProfile) new ConstructorArgument("lastProfile", ((WindowsProfileSettings) EffectSettings).LastProfile)
}; };
ProfileEditor = kernel.Get<ProfileEditorViewModel>(args); ProfileEditor = kernel.Get<ProfileEditorViewModel>(args);

View File

@ -52,6 +52,8 @@ namespace Artemis.Modules.Games.CounterStrike
public override void Enable() public override void Enable()
{ {
base.Enable();
_gameStateWebServer.GameDataReceived += HandleGameData; _gameStateWebServer.GameDataReceived += HandleGameData;
Initialized = true; Initialized = true;
} }

View File

@ -45,6 +45,8 @@ namespace Artemis.Modules.Games.Dota2
public override void Enable() public override void Enable()
{ {
base.Enable();
_gameStateWebServer.GameDataReceived += HandleGameData; _gameStateWebServer.GameDataReceived += HandleGameData;
Initialized = true; Initialized = true;
} }

View File

@ -43,6 +43,8 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
public override void Enable() public override void Enable()
{ {
base.Enable();
Initialized = true; Initialized = true;
} }

View File

@ -27,6 +27,8 @@ namespace Artemis.Modules.Games.GtaV
public override void Enable() public override void Enable()
{ {
base.Enable();
DllManager.PlaceLogitechDll(); DllManager.PlaceLogitechDll();
_pipeServer.PipeMessage += PipeServerOnPipeMessage; _pipeServer.PipeMessage += PipeServerOnPipeMessage;
Initialized = true; Initialized = true;

View File

@ -56,6 +56,8 @@ namespace Artemis.Modules.Games.LightFx
public override void Enable() public override void Enable()
{ {
base.Enable();
Initialized = true; Initialized = true;
} }

View File

@ -82,6 +82,8 @@ namespace Artemis.Modules.Games.Overwatch
public override void Enable() public override void Enable()
{ {
base.Enable();
_stickyStatus = new StickyValue<OverwatchStatus>(300); _stickyStatus = new StickyValue<OverwatchStatus>(300);
_stickyUltimateReady = new StickyValue<bool>(350); _stickyUltimateReady = new StickyValue<bool>(350);
_stickyUltimateUsed = new StickyValue<bool>(350); _stickyUltimateUsed = new StickyValue<bool>(350);

View File

@ -33,6 +33,8 @@ namespace Artemis.Modules.Games.ProjectCars
public override void Enable() public override void Enable()
{ {
base.Enable();
Initialized = true; Initialized = true;
} }

View File

@ -29,14 +29,14 @@ namespace Artemis.Modules.Games.RocketLeague
//var offset = new GamePointersCollection //var offset = new GamePointersCollection
//{ //{
// Game = "RocketLeague", // Game = "RocketLeague",
// GameVersion = "1.24", // GameVersion = "1.26",
// GameAddresses = new List<GamePointer> // GameAddresses = new List<GamePointer>
// { // {
// new GamePointer // new GamePointer
// { // {
// Description = "Boost", // Description = "Boost",
// BasePointer = new IntPtr(0x016BBFB4), // BasePointer = new IntPtr(0x01666C38),
// Offsets = new[] { 0xc4, 0x210, 0x320, 0x734, 0x224} // Offsets = new[] { 0x58, 0x668, 0x73C, 0x224}
// } // }
// } // }
//}; //};
@ -54,8 +54,9 @@ namespace Artemis.Modules.Games.RocketLeague
public override void Enable() public override void Enable()
{ {
Initialized = false; base.Enable();
Initialized = false;
Updater.GetPointers(); Updater.GetPointers();
_pointer = SettingsProvider.Load<OffsetSettings>().RocketLeague; _pointer = SettingsProvider.Load<OffsetSettings>().RocketLeague;

View File

@ -49,8 +49,9 @@ namespace Artemis.Modules.Games.TheDivision
public override void Enable() public override void Enable()
{ {
Initialized = false; base.Enable();
Initialized = false;
_stickyAmmo = new StickyValue<bool>(200); _stickyAmmo = new StickyValue<bool>(200);
_stickyHp = new StickyValue<bool>(200); _stickyHp = new StickyValue<bool>(200);

View File

@ -126,6 +126,8 @@ namespace Artemis.Modules.Games.UnrealTournament
public override void Enable() public override void Enable()
{ {
base.Enable();
_pipeServer.PipeMessage += PipeServerOnPipeMessage; _pipeServer.PipeMessage += PipeServerOnPipeMessage;
_killTimer.Start(); _killTimer.Start();

View File

@ -43,8 +43,9 @@ namespace Artemis.Modules.Games.Witcher3
public override void Enable() public override void Enable()
{ {
Initialized = false; base.Enable();
Initialized = false;
// Ensure the config file is found // Ensure the config file is found
var witcherSettings = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + var witcherSettings = Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
@"\The Witcher 3\user.settings"; @"\The Witcher 3\user.settings";

View File

@ -77,6 +77,8 @@ namespace Artemis.Modules.Games.WoW
public override void Enable() public override void Enable()
{ {
base.Enable();
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName); var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
if (tempProcess == null) if (tempProcess == null)
return; return;

View File

@ -83,15 +83,15 @@ namespace Artemis.Profiles.Lua.Modules
} }
catch (InternalErrorException ex) 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) 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) catch (ScriptRuntimeException ex)
{ {
_logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage); _logger.Error("[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
} }
} }
} }

View File

@ -14,7 +14,7 @@
-- changes are applied to the profile and the script is restarted. -- changes are applied to the profile and the script is restarted.
-- This event is raised after every profile update, before drawing. -- 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 -- 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 -- updated. If you don't do this the updateHandler will trigger on every
-- device's update. -- device's update.
@ -26,7 +26,7 @@ function updateHandler(eventArgs)
end end
-- This event is raised after every profile draw, after updating. -- 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 -- In this example we only want to draw to the keyboard. Each device has it's
-- own drawing event -- own drawing event
if eventArgs.DeviceType != "keyboard" then if eventArgs.DeviceType != "keyboard" then

View File

@ -26,7 +26,7 @@ namespace Artemis.ViewModels.Abstract
IParameter[] args = IParameter[] args =
{ {
new ConstructorArgument("mainManager", mainManager), new ConstructorArgument("mainManager", mainManager),
new ConstructorArgument("gameModel", gameModel), new ConstructorArgument("effectModel", gameModel),
new ConstructorArgument("lastProfile", GameSettings.LastProfile) new ConstructorArgument("lastProfile", GameSettings.LastProfile)
}; };
ProfileEditor = kernel.Get<ProfileEditorViewModel>(args); 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() public void ToggleEffect()
{ {

View File

@ -35,7 +35,7 @@ namespace Artemis.ViewModels.Profiles
public sealed class ProfileEditorViewModel : Screen, IDropTarget public sealed class ProfileEditorViewModel : Screen, IDropTarget
{ {
private readonly DeviceManager _deviceManager; private readonly DeviceManager _deviceManager;
private readonly EffectModel _gameModel; private readonly EffectModel _effectModel;
private readonly LuaManager _luaManager; private readonly LuaManager _luaManager;
private readonly Timer _saveTimer; private readonly Timer _saveTimer;
private ImageSource _keyboardPreview; private ImageSource _keyboardPreview;
@ -44,13 +44,13 @@ namespace Artemis.ViewModels.Profiles
private bool _saving; private bool _saving;
private ProfileModel _selectedProfile; 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, ProfileViewModel profileViewModel, MetroDialogService dialogService, WindowService windowService,
string lastProfile) string lastProfile)
{ {
_deviceManager = deviceManager; _deviceManager = deviceManager;
_luaManager = luaManager; _luaManager = luaManager;
_gameModel = gameModel; _effectModel = effectModel;
ProfileNames = new ObservableCollection<string>(); ProfileNames = new ObservableCollection<string>();
Layers = new ObservableCollection<LayerModel>(); Layers = new ObservableCollection<LayerModel>();
@ -111,7 +111,7 @@ namespace Artemis.ViewModels.Profiles
if (value == SelectedProfile?.Name) if (value == SelectedProfile?.Name)
return; return;
SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _gameModel, value); SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel, value);
NotifyOfPropertyChange(() => SelectedProfileName); NotifyOfPropertyChange(() => SelectedProfileName);
} }
} }
@ -124,12 +124,21 @@ namespace Artemis.ViewModels.Profiles
if (Equals(value, _selectedProfile)) if (Equals(value, _selectedProfile))
return; return;
// Deactivate old profile if (IsActive)
_selectedProfile?.Deactivate(_luaManager); {
// Update the value // Deactivate old profile
_selectedProfile = value; _selectedProfile?.Deactivate(_luaManager);
// Activate new profile // Update the value
_selectedProfile?.Activate(_luaManager); _selectedProfile = value;
// Activate new profile
_selectedProfile?.Activate(_luaManager);
}
else
{
// Update the value
_selectedProfile = value;
}
NotifyOfPropertyChange(() => SelectedProfile); NotifyOfPropertyChange(() => SelectedProfile);
NotifyOfPropertyChange(() => SelectedProfileName); NotifyOfPropertyChange(() => SelectedProfileName);
} }
@ -230,6 +239,7 @@ namespace Artemis.ViewModels.Profiles
public void Activate() public void Activate()
{ {
_selectedProfile?.Activate(_luaManager);
ProfileViewModel.Activate(); ProfileViewModel.Activate();
_saveTimer.Start(); _saveTimer.Start();
} }
@ -247,20 +257,20 @@ namespace Artemis.ViewModels.Profiles
private void LoadProfiles() private void LoadProfiles()
{ {
ProfileNames.Clear(); ProfileNames.Clear();
if (_gameModel == null || _deviceManager.ActiveKeyboard == null) if (_effectModel == null || _deviceManager.ActiveKeyboard == null)
return; 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 // If a profile name was provided, try to load it
ProfileModel lastProfileModel = null; ProfileModel lastProfileModel = null;
if (!string.IsNullOrEmpty(LastProfile)) if (!string.IsNullOrEmpty(LastProfile))
lastProfileModel = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _gameModel, LastProfile); lastProfileModel = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel, LastProfile);
if (lastProfileModel != null) if (lastProfileModel != null)
SelectedProfile = lastProfileModel; SelectedProfile = lastProfileModel;
else else
SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _gameModel, SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel,
ProfileNames.FirstOrDefault()); ProfileNames.FirstOrDefault());
} }
@ -293,7 +303,7 @@ namespace Artemis.ViewModels.Profiles
IParameter[] args = IParameter[] args =
{ {
new ConstructorArgument("dataModel", _gameModel.DataModel), new ConstructorArgument("dataModel", _effectModel.DataModel),
new ConstructorArgument("layer", layer) new ConstructorArgument("layer", layer)
}; };
WindowService.ShowDialog<LayerEditorViewModel>(args); WindowService.ShowDialog<LayerEditorViewModel>(args);
@ -502,7 +512,7 @@ namespace Artemis.ViewModels.Profiles
KeyboardSlug = _deviceManager.ActiveKeyboard.Slug, KeyboardSlug = _deviceManager.ActiveKeyboard.Slug,
Width = _deviceManager.ActiveKeyboard.Width, Width = _deviceManager.ActiveKeyboard.Width,
Height = _deviceManager.ActiveKeyboard.Height, Height = _deviceManager.ActiveKeyboard.Height,
GameName = _gameModel.Name GameName = _effectModel.Name
}; };
if (!ProfileProvider.IsProfileUnique(profile)) if (!ProfileProvider.IsProfileUnique(profile))
@ -624,10 +634,10 @@ namespace Artemis.ViewModels.Profiles
} }
// Verify the game // Verify the game
if (profile.GameName != _gameModel.Name) if (profile.GameName != _effectModel.Name)
{ {
DialogService.ShowErrorMessageBox( 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; return;
} }
@ -690,7 +700,7 @@ namespace Artemis.ViewModels.Profiles
return; return;
try try
{ {
SelectedProfile?.Activate(_luaManager); _luaManager.SetupLua(SelectedProfile);
_luaManager.OpenEditor(); _luaManager.OpenEditor();
} }
catch (Exception e) catch (Exception e)