From ddc63473a30616f6634788bb4ecc7004831c440a Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 21 Apr 2016 14:49:08 +0200 Subject: [PATCH] Updated Rocket League to use the profile editor --- .../Games/CounterStrike/CounterStrikeModel.cs | 5 - .../RocketLeague/RocketLeagueDataModel.cs | 7 +- .../Games/RocketLeague/RocketLeagueModel.cs | 95 +++---------------- .../Games/RocketLeague/RocketLeagueView.xaml | 42 +------- .../RocketLeague/RocketLeagueViewModel.cs | 17 +++- .../Games/TheDivision/TheDivisionView.xaml | 2 +- Artemis/Artemis/Utilities/LayerDrawer.cs | 1 + .../ViewModels/Abstract/GameViewModel.cs | 3 +- .../LayerDynamicPropertiesViewModel.cs | 51 +++++++++- .../LayerDynamicPropertiesView.xaml | 43 +++++---- 10 files changed, 106 insertions(+), 160 deletions(-) diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index 1ec23360d..4bf2f6d78 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -1,12 +1,9 @@ using System.Diagnostics; using System.Drawing; -using System.Windows.Media; using Artemis.Managers; using Artemis.Models; -using Artemis.Utilities; using Artemis.Utilities.GameState; using Newtonsoft.Json; -using Color = System.Windows.Media.Color; namespace Artemis.Modules.Games.CounterStrike { @@ -68,8 +65,6 @@ namespace Artemis.Modules.Games.CounterStrike if (!jsonString.Contains("Counter-Strike: Global Offensive")) return; - - Debug.WriteLine("Got data"); // Parse the JSON GameDataModel = JsonConvert.DeserializeObject(jsonString); } diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs index d85980ab8..9b2cf86b8 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs @@ -1,12 +1,9 @@ -using System.Collections.Generic; -using Artemis.Models.Interfaces; -using Artemis.Utilities; +using Artemis.Models.Interfaces; namespace Artemis.Modules.Games.RocketLeague { - internal class RocketLeagueDataModel : IGameDataModel + public class RocketLeagueDataModel : IGameDataModel { public int Boost { get; set; } - public List Properties { get; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs index ce2d997a0..089552d02 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; using System.Drawing; -using System.Drawing.Drawing2D; using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Artemis.Managers; using Artemis.Models; using Artemis.Settings; using Artemis.Utilities; -using Artemis.Utilities.Keyboard; using Artemis.Utilities.Memory; using Newtonsoft.Json; @@ -17,13 +12,8 @@ namespace Artemis.Modules.Games.RocketLeague { public class RocketLeagueModel : GameModel { - private int _boostAmount; - private bool _boostGrowing; - private KeyboardRectangle _boostRect; - private bool _contextualColor; private Memory _memory; private GamePointersCollection _pointer; - private int _previousBoost; public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager) { @@ -49,105 +39,44 @@ namespace Artemis.Modules.Games.RocketLeague { Initialized = false; - _contextualColor = Settings.ContextualColor; - - _boostRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List - { - ColorHelpers.ToDrawingColor(Settings.MainColor), - ColorHelpers.ToDrawingColor(Settings.SecondaryColor) - }, LinearGradientMode.Horizontal); - Updater.GetPointers(); _pointer = JsonConvert.DeserializeObject(Offsets.Default.RocketLeague); var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName); _memory = new Memory(tempProcess); + GameDataModel = new RocketLeagueDataModel(); Initialized = true; } public override void Update() { - if (_boostGrowing) - return; - if (_memory == null) + if (Profile == null || GameDataModel == null || _memory == null) return; var offsets = _pointer.GameAddresses.First(ga => ga.Description == "Boost").ToString(); var boostAddress = _memory.GetAddress("\"RocketLeague.exe\"" + offsets); var boostFloat = _memory.ReadFloat(boostAddress)*100/3; - _previousBoost = _boostAmount; - _boostAmount = (int) Math.Ceiling(boostFloat); + ((RocketLeagueDataModel) GameDataModel).Boost = (int) Math.Ceiling(boostFloat); // Take care of any reading errors resulting in an OutOfMemory on draw - if (_boostAmount < 0) - _boostAmount = 0; - if (_boostAmount > 100) - _boostAmount = 100; + if (((RocketLeagueDataModel) GameDataModel).Boost < 0) + ((RocketLeagueDataModel) GameDataModel).Boost = 0; + if (((RocketLeagueDataModel) GameDataModel).Boost > 100) + ((RocketLeagueDataModel) GameDataModel).Boost = 100; - _boostRect.Width = - (int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); - - if (_contextualColor) - { - if (_boostAmount < 33) - _boostRect.Colors = new List {Color.Red}; - else if (_boostAmount >= 33 && _boostAmount < 66) - _boostRect.Colors = new List {Color.Yellow}; - else if (_boostAmount >= 66) - _boostRect.Colors = new List {Color.Lime}; - } - - Task.Run(() => GrowIfHigher()); - } - - private void GrowIfHigher() - { - if (_boostAmount <= _previousBoost || _boostGrowing) - return; - - _boostGrowing = true; - const int amountOfSteps = 6; - - var difference = _boostAmount - _previousBoost; - var differenceStep = difference/amountOfSteps; - var differenceStepRest = difference%amountOfSteps; - _boostAmount = _previousBoost; - _boostRect.Width = - (int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); - - for (var i = 0; i < amountOfSteps; i++) - { - if (differenceStepRest > 0) - { - differenceStepRest -= 1; - _boostAmount += 1; - _boostRect.Width = - (int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); - } - _boostAmount += differenceStep; - _boostRect.Width = - (int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); - - Thread.Sleep(50); - } - - _boostGrowing = false; + foreach (var layerModel in Profile.Layers) + layerModel.Update(GameDataModel); } public override Bitmap GenerateBitmap() { - var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); - if (_boostRect == null) + if (Profile == null || GameDataModel == null) return null; - using (var g = Graphics.FromImage(bitmap)) - { - g.Clear(Color.Transparent); - _boostRect.Draw(g); - } - return bitmap; + var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale); + return Profile.GenerateBitmap(keyboardRect, GameDataModel); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml index a971d629d..f1ecb05bb 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueView.xaml @@ -40,46 +40,8 @@ - - - Main boost display color - - - - - - Secondary boost display color - - - - - - Color bar according to boost amount - - - - - - Tip: To find a color combination you like, start an exhibition match, pickup 100 boost and play around with the colors. - They'll appear on your keyboard immediately! Once you're satisfied don't forget to click save changes. - - + + diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs index 60785d2da..d91f9a4d3 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueViewModel.cs @@ -1,7 +1,9 @@ -using Artemis.Managers; +using System.ComponentModel; +using Artemis.Managers; using Artemis.Settings; using Artemis.Utilities; using Artemis.Utilities.Memory; +using Artemis.ViewModels; using Artemis.ViewModels.Abstract; using Newtonsoft.Json; @@ -21,10 +23,15 @@ namespace Artemis.Modules.Games.RocketLeague // Create effect model and add it to MainManager GameModel = new RocketLeagueModel(mainManager, (RocketLeagueSettings) GameSettings); MainManager.EffectManager.EffectModels.Add(GameModel); - SetVersionText(); + + ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel); + ProfileEditor.PropertyChanged += ProfileUpdater; + GameModel.Profile = ProfileEditor.SelectedProfile; } + public ProfileEditorViewModel ProfileEditor { get; set; } + public static string Name => "Rocket League"; public string VersionText @@ -40,6 +47,12 @@ namespace Artemis.Modules.Games.RocketLeague public RocketLeagueModel RocketLeagueModel { get; set; } + private void ProfileUpdater(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "SelectedProfile") + GameModel.Profile = ProfileEditor.SelectedProfile; + } + private void SetVersionText() { if (!General.Default.EnablePointersUpdate) diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionView.xaml b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionView.xaml index 48b9924bf..f1ece3e0d 100644 --- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionView.xaml +++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionView.xaml @@ -43,7 +43,7 @@ - + diff --git a/Artemis/Artemis/Utilities/LayerDrawer.cs b/Artemis/Artemis/Utilities/LayerDrawer.cs index f14079de8..bb5ff25aa 100644 --- a/Artemis/Artemis/Utilities/LayerDrawer.cs +++ b/Artemis/Artemis/Utilities/LayerDrawer.cs @@ -135,6 +135,7 @@ namespace Artemis.Utilities _layerModel.CalcProps.Animation == LayerAnimation.SlideRight || _layerModel.CalcProps.Animation == LayerAnimation.SlideUp) { + // TODO: if (_layerModel.CalcProps.ContainedBrush) c.PushClip(new RectangleGeometry(_rectangle)); c.DrawRectangle(brush, null, _firstRect); c.DrawRectangle(brush, null, _secondRect); diff --git a/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs b/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs index 317a23cfa..ba58d6dc6 100644 --- a/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs +++ b/Artemis/Artemis/ViewModels/Abstract/GameViewModel.cs @@ -1,4 +1,5 @@ -using Artemis.Managers; +using System.ComponentModel; +using Artemis.Managers; using Artemis.Models; using Caliburn.Micro; diff --git a/Artemis/Artemis/ViewModels/LayerEditor/LayerDynamicPropertiesViewModel.cs b/Artemis/Artemis/ViewModels/LayerEditor/LayerDynamicPropertiesViewModel.cs index af66f2da7..fd57df8e8 100644 --- a/Artemis/Artemis/ViewModels/LayerEditor/LayerDynamicPropertiesViewModel.cs +++ b/Artemis/Artemis/ViewModels/LayerEditor/LayerDynamicPropertiesViewModel.cs @@ -12,6 +12,9 @@ namespace Artemis.ViewModels.LayerEditor private string _name; private GeneralHelpers.PropertyCollection _selectedSource; private GeneralHelpers.PropertyCollection _selectedTarget; + private bool _sourcesIsVisible; + private bool _userSourceIsVisible; + private LayerPropertyType _layerPropertyType; public LayerDynamicPropertiesViewModel(string property, BindableCollection dataModelProps, LayerModel layer) @@ -37,6 +40,21 @@ namespace Artemis.ViewModels.LayerEditor Sources.AddRange(dataModelProps.Where(p => p.Type == "Int32")); PropertyChanged += OnPropertyChanged; + + SelectedTarget = dataModelProps.FirstOrDefault(p => p.Path == LayerDynamicPropertiesModel.GameProperty); + SelectedSource = dataModelProps.FirstOrDefault(p => p.Path == LayerDynamicPropertiesModel.PercentageSource); + LayerPropertyType = LayerDynamicPropertiesModel.LayerPropertyType; + } + + public LayerPropertyType LayerPropertyType + { + get { return _layerPropertyType; } + set + { + if (value == _layerPropertyType) return; + _layerPropertyType = value; + NotifyOfPropertyChange(() => LayerPropertyType); + } } public string Name @@ -87,17 +105,40 @@ namespace Artemis.ViewModels.LayerEditor } } - /// - /// Updates the underlying model - /// - /// - /// + public bool SourcesIsVisible + { + get { return _sourcesIsVisible; } + set + { + if (value == _sourcesIsVisible) return; + _sourcesIsVisible = value; + NotifyOfPropertyChange(() => SourcesIsVisible); + } + } + + public bool UserSourceIsVisible + { + get { return _userSourceIsVisible; } + set + { + if (value == _userSourceIsVisible) return; + _userSourceIsVisible = value; + NotifyOfPropertyChange(() => UserSourceIsVisible); + } + } + private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedTarget") LayerDynamicPropertiesModel.GameProperty = SelectedTarget.Path; if (e.PropertyName == "SelectedSource") LayerDynamicPropertiesModel.PercentageSource = SelectedSource.Path; + if (e.PropertyName == "LayerPropertyType") + { + LayerDynamicPropertiesModel.LayerPropertyType = LayerPropertyType; + UserSourceIsVisible = (LayerPropertyType == LayerPropertyType.PercentageOf); + SourcesIsVisible = (LayerPropertyType == LayerPropertyType.PercentageOfProperty); + } } } } \ No newline at end of file diff --git a/Artemis/Artemis/Views/LayerEditor/LayerDynamicPropertiesView.xaml b/Artemis/Artemis/Views/LayerEditor/LayerDynamicPropertiesView.xaml index bf4cc9107..e5de26968 100644 --- a/Artemis/Artemis/Views/LayerEditor/LayerDynamicPropertiesView.xaml +++ b/Artemis/Artemis/Views/LayerEditor/LayerDynamicPropertiesView.xaml @@ -7,6 +7,7 @@ xmlns:utilities="clr-namespace:Artemis.Utilities" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:profileEnumerations="clr-namespace:Artemis.Models.Profiles" + xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="500"> @@ -49,7 +50,7 @@ - @@ -59,22 +60,28 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file