1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Recommited contextual colors

This commit is contained in:
Logan Saso 2016-02-28 15:32:25 -08:00
parent 426ebac079
commit 2342308071

View File

@ -1,161 +1,161 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Settings; using Artemis.Settings;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.Utilities.Keyboard; using Artemis.Utilities.Keyboard;
using Artemis.Utilities.Memory; using Artemis.Utilities.Memory;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.Modules.Games.RocketLeague namespace Artemis.Modules.Games.RocketLeague
{ {
public class RocketLeagueModel : GameModel public class RocketLeagueModel : GameModel
{ {
private int _boostAmount; private int _boostAmount;
private bool _boostGrowing; private bool _boostGrowing;
private KeyboardRectangle _boostRect; private KeyboardRectangle _boostRect;
private Memory _memory; private Memory _memory;
private GamePointersCollectionModel _pointer; private GamePointersCollectionModel _pointer;
private int _previousBoost; private int _previousBoost;
public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager) public RocketLeagueModel(MainManager mainManager, RocketLeagueSettings settings) : base(mainManager)
{ {
Settings = settings; Settings = settings;
Name = "RocketLeague"; Name = "RocketLeague";
ProcessName = "RocketLeague"; ProcessName = "RocketLeague";
Scale = 4; Scale = 4;
Enabled = Settings.Enabled; Enabled = Settings.Enabled;
Initialized = false; Initialized = false;
ContextualColor = Settings.ContextualColor; ContextualColor = Settings.ContextualColor;
} }
public RocketLeagueSettings Settings { get; set; } public RocketLeagueSettings Settings { get; set; }
public int Scale { get; set; } public int Scale { get; set; }
public bool ContextualColor { get; set; } public bool ContextualColor { get; set; }
public override void Dispose() public override void Dispose()
{ {
Initialized = false; Initialized = false;
_memory = null; _memory = null;
} }
public override void Enable() public override void Enable()
{ {
Initialized = false; Initialized = false;
_boostRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color> _boostRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, 0, new List<Color>
{
ColorHelpers.ToDrawingColor(Settings.MainColor),
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
}, LinearGradientMode.Horizontal);
MemoryHelpers.GetPointers();
_pointer = JsonConvert.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague);
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
_memory = new Memory(tempProcess);
Initialized = true;
}
public override void Update()
{
if (_boostGrowing)
return;
if (_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);
// Take care of any reading errors resulting in an OutOfMemory on draw
if (_boostAmount < 0)
_boostAmount = 0;
if (_boostAmount > 100)
_boostAmount = 100;
_boostRect.Width =
(int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount);
if (ContextualColor)
{
if(_boostAmount < 33)
_boostRect.Colors = new List<Color>{ Color.Red };
else if(_boostAmount >= 33 && _boostAmount < 66)
_boostRect.Colors = new List<Color> { Color.Yellow };
else if(_boostAmount >= 66)
_boostRect.Colors = new List<Color> { Color.Lime };
}
else
{ {
_boostRect.Colors = new List<Color> ColorHelpers.ToDrawingColor(Settings.MainColor),
{ ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
ColorHelpers.ToDrawingColor(Settings.MainColor), }, LinearGradientMode.Horizontal);
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
}; MemoryHelpers.GetPointers();
} _pointer = JsonConvert.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague);
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
Task.Run(() => GrowIfHigher()); _memory = new Memory(tempProcess);
}
Initialized = true;
private void GrowIfHigher() }
{
if (_boostAmount <= _previousBoost || _boostGrowing) public override void Update()
return; {
if (_boostGrowing)
_boostGrowing = true; return;
const int amountOfSteps = 6; if (_memory == null)
return;
var difference = _boostAmount - _previousBoost;
var differenceStep = difference/amountOfSteps; var offsets = _pointer.GameAddresses.First(ga => ga.Description == "Boost").ToString();
var differenceStepRest = difference%amountOfSteps; var boostAddress = _memory.GetAddress("\"RocketLeague.exe\"" + offsets);
_boostAmount = _previousBoost; var boostFloat = _memory.ReadFloat(boostAddress)*100/3;
_boostRect.Width =
(int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); _previousBoost = _boostAmount;
_boostAmount = (int) Math.Ceiling(boostFloat);
for (var i = 0; i < amountOfSteps; i++)
{ // Take care of any reading errors resulting in an OutOfMemory on draw
if (differenceStepRest > 0) if (_boostAmount < 0)
{ _boostAmount = 0;
differenceStepRest -= 1; if (_boostAmount > 100)
_boostAmount += 1; _boostAmount = 100;
_boostRect.Width =
(int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); _boostRect.Width =
} (int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount);
_boostAmount += differenceStep;
_boostRect.Width = if (ContextualColor)
(int) Math.Ceiling(MainManager.KeyboardManager.ActiveKeyboard.Width*Scale/100.00*_boostAmount); {
if(_boostAmount < 33)
Thread.Sleep(50); _boostRect.Colors = new List<Color>{ Color.Red };
} else if(_boostAmount >= 33 && _boostAmount < 66)
_boostRect.Colors = new List<Color> { Color.Yellow };
_boostGrowing = false; else if(_boostAmount >= 66)
} _boostRect.Colors = new List<Color> { Color.Lime };
}
public override Bitmap GenerateBitmap() else
{ {
var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale); _boostRect.Colors = new List<Color>
if (_boostRect == null) {
return null; ColorHelpers.ToDrawingColor(Settings.MainColor),
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
using (var g = Graphics.FromImage(bitmap)) };
{ }
g.Clear(Color.Transparent);
_boostRect.Draw(g);
} Task.Run(() => GrowIfHigher());
return bitmap; }
}
} 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;
}
public override Bitmap GenerateBitmap()
{
var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale);
if (_boostRect == null)
return null;
using (var g = Graphics.FromImage(bitmap))
{
g.Clear(Color.Transparent);
_boostRect.Draw(g);
}
return bitmap;
}
}
} }