1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-02 02:33: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);
// 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;
}
}
}

View File

@ -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()

View File

@ -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,7 +83,7 @@ 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)

View File

@ -42,6 +42,8 @@ namespace Artemis.Modules.Effects.WindowsProfile
public override void Enable()
{
base.Enable();
SetupCpu();
SetupSpotify();

View File

@ -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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);

View File

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

View File

@ -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;

View File

@ -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);

View File

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

View File

@ -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";

View File

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

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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()
{

View File

@ -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)