protected void ApplyColorToBinding(KeyboardCustom grid, string bindingName, Color color) { if (!Game.Bindings.TryGetValue(bindingName, out var binding)) { return; } foreach (var bps in new[] { binding.Primary, binding.Secondary }) { if (bps.Device != Device.Keyboard) { continue; } if (!KeyMappings.EliteKeys.TryGetValue(bps.Key, out var key)) { continue; } if (key == Key.Invalid) { continue; } if (!bps.Modifiers.Equals(Game.PressedModifiers)) { continue; } grid[key] = color; color = color.Transform(0.2); } }
protected void ApplyColorToBinding(KeyboardCustom grid, string bindingName, Color color) { if (!Game.BindingPreset.Bindings.TryGetValue(bindingName, out var binding)) { return; } foreach (var bps in new[] { binding.Primary, binding.Secondary }) { if (bps.Device != Device.Keyboard) { continue; } if (!KeyMappings.TryGetKey(bps.Key, Game.BindingPreset.KeyboardLayout, out var key, NativeMethods)) { continue; } if (key == 0) { continue; } if (!bps.Modifiers.Equals(Game.PressedModifiers)) { continue; } grid[key] = color; color = color.Transform(Colors.SecondaryBindingBrightness); } }
private void DrawStars(Stars stars, KeyboardCustom keyboard) { var t = (DateTimeOffset.UtcNow - Game.FsdJumpChange).TotalSeconds; stars.Clean(); foreach (var star in stars) { var r = Math.Pow((DateTimeOffset.UtcNow - star.Birth).TotalMilliseconds / star.Lifespan.TotalMilliseconds, 2); var x = (int)Math.Round(_x0 + (star.VX * r * _xScale)); var y = (int)Math.Round(_y0 + (star.Y * _yScale)); if (x < 0 || x >= KeyboardConstants.MaxColumns) { continue; } if (y < 0 || y >= KeyboardConstants.MaxRows) { continue; } var c = keyboard[y, x].Combine(star.Color.Transform(r * 1, 1.5)); if (Game.FsdJumpType == FsdJumpType.Hyperspace && t >= 4 && t <= 5) { c = c.Combine(Color.White, t - 4); } keyboard[y, x] = c; } }
private static void SetVolumeScale(ref KeyboardCustom keyboardGrid, List <Key> Keys, ColoreColor color) { for (var i = 0; i < (player.PlayerEngine.SoundVolume * Keys.Count) / 100; i++) //volume bar (D0-D9) { keyboardGrid[Keys[i]] = color; } }
public static KeyboardCustom MaxAt(this KeyboardCustom keyboard, int row, int column, Color c) { var key = GetKeyAt(row, column); keyboard[key] = keyboard[key].Max(c); return(keyboard); }
private void Render(KeyboardCustom keyboard, Color c, double lastZ) { // Particles are drawn as stretched lines, simulating movement. // Lines are antialiased at both ends. // x0 x1 // ┌───┐ ┌───┐ // ┌───┬───┬───┬───┬───┬───┐ // │ │▒▒▒│███│███│▒▒▒│ │ // └───┴───┴───┴───┴───┴───┘ // -1 0 1 2 3 4 const double xScale = KeyboardConstants.MaxColumns / 2.0; const double xCenter = (KeyboardConstants.MaxColumns - 1) / 2.0; Debug.Assert(lastZ >= Z, "Z always decreases"); var xPrev = (lastZ > 0 ? Math.Min(1 / lastZ, 2) : 2) * xScale; var xCurr = (Z > 0 ? Math.Min(1 / Z, 2) : 2) * xScale; double x0, x1; if (_angle >= 180) { x0 = xCenter + xPrev; x1 = xCenter + xCurr; } else { x1 = xCenter - xPrev; x0 = xCenter - xCurr; } var y = _angle % KeyboardConstants.MaxRows; // First pixel var xi = (int)Math.Floor(x0); if (xi >= 0 && xi < KeyboardConstants.MaxColumns) { var caa = c.Transform(1 - (x0 - xi)); keyboard[y, xi] = keyboard[y, xi].Max(caa); } // Last pixel var xj = (int)Math.Ceiling(x1); if (xj >= 0 && xj < KeyboardConstants.MaxColumns) { var caa = c.Transform(1 - (xj - x1)); keyboard[y, xj] = keyboard[y, xj].Max(caa); } // Middle pixels xi = Math.Max(0, xi + 1); xj = Math.Min(xj, KeyboardConstants.MaxColumns); for (; xi < xj; xi++) { keyboard[y, xi] = keyboard[y, xi].Max(c); } }
public void Send(KeyboardCustom colorGrid) { if (!Initialized) { return; } _chroma?.Keyboard.SetCustomAsync(colorGrid); }
private static void SetPlayingPosition(ref KeyboardCustom keyboardGrid, double position, List <Key> functionKeys, ColoreColor pos, ColoreColor background) { var currentPlayPosition = (int)Math.Round(position * 1.1, 0); //can replace 1.1 with ((double)(functionKeys.Count - 1) / 10) for safe calculation for (var i = 0; i < currentPlayPosition + 1; i++) { keyboardGrid[functionKeys[i]] = background; } keyboardGrid[functionKeys[currentPlayPosition]] = pos; }
public static KeyboardCustom Max(this KeyboardCustom keyboard, Color c) { for (var i = 0; i < _allKeys.Length; i++) { var key = _allKeys[i]; keyboard[key] = keyboard[key].Max(c); } return(keyboard); }
protected void ApplyColorToBinding(KeyboardCustom grid, IEnumerable <string> bindingNames, Color color) { if (bindingNames == null) { throw new ArgumentNullException(nameof(bindingNames)); } foreach (var bindingName in bindingNames) { ApplyColorToBinding(grid, bindingName, color); } }
private static void SetIndividualKeys(ref KeyboardCustom keyboardGrid) { keyboardGrid[Key.Up] = ColoreColor.Pink; keyboardGrid[Key.Down] = ColoreColor.Pink; keyboardGrid[Key.Left] = ColoreColor.Pink; keyboardGrid[Key.Right] = ColoreColor.Pink; keyboardGrid[Key.OemEquals] = ColoreColor.Purple; keyboardGrid[Key.OemMinus] = ColoreColor.Purple; keyboardGrid[Key.R] = ColoreColor.Blue; keyboardGrid[Key.O] = ColoreColor.Blue; keyboardGrid[Key.H] = ColoreColor.Blue; keyboardGrid[Key.S] = ColoreColor.Blue; }
private static void SetPlayingTime(ref KeyboardCustom keyboardGrid, TimeSpan currentTime, params ColoreColor[] colors) { if (colors.Length != 3 || currentTime == null) { return; } keyboardGrid[NumpadKeys[currentTime.Minutes]] = colors[0]; // ie. 47 - 7 = 40/10 = 4 //use a 'lossy' property of integer to round all floating point, best practice should be (currentTime.Seconds - (currentTime.Seconds % 10))/10 keyboardGrid[NumpadKeys[currentTime.Seconds / 10]] = colors[1]; keyboardGrid[NumpadKeys[currentTime.Seconds % 10]] = colors[2]; }
private static async void ChromaUpdateAsync() { AllKeys.Remove(Key.Invalid); // no idea why this key is inside the enum? var opacity = 0.5; var keyboardGrid = KeyboardCustom.Create(); var mouseGrid = MouseCustom.Create(); var chroma = await ColoreProvider.CreateNativeAsync(); var bg_playing = new ColoreColor((byte)Properties.Settings.Default.Background_Playing.R, (byte)Properties.Settings.Default.Background_Playing.G, (byte)Properties.Settings.Default.Background_Playing.B); var bg_pause = new ColoreColor((byte)Properties.Settings.Default.Background_Pause.R, (byte)Properties.Settings.Default.Background_Pause.G, (byte)Properties.Settings.Default.Background_Pause.B); var pos_fore = new ColoreColor((byte)Properties.Settings.Default.Position_Foreground.R, (byte)Properties.Settings.Default.Position_Foreground.G, (byte)Properties.Settings.Default.Position_Foreground.B); var pos_back = new ColoreColor((byte)Properties.Settings.Default.Position_Background.R, (byte)Properties.Settings.Default.Position_Background.G, (byte)Properties.Settings.Default.Position_Background.B); var vol = new ColoreColor((byte)Properties.Settings.Default.Volume.R, (byte)Properties.Settings.Default.Volume.G, (byte)Properties.Settings.Default.Volume.B); var backgroundColor = ColoreColor.Black; while (true) { var backgroundDetermine = player.PlayerEngine.PlayerState == ITPlayerState.ITPlayerStatePlaying ? bg_playing : bg_pause; backgroundColor = BackgroundColorDecision(ref opacity, Properties.Settings.Default.AdaptiveDensity ? ActiveDevice.AudioMeterInformation.MasterPeakValue : 1, backgroundDetermine);// (10 - Properties.Settings.Default.RefreshRate) + 1, backgroundDetermine); ColorsVariableDecision(ref bg_playing, ref bg_pause, ref pos_fore, ref pos_back, ref vol); try { var currentTime = TimeSpan.FromSeconds(player.PlayerEngine.PlayerPosition); var position = player.CalculatedPosition; keyboardGrid.Set(backgroundColor); mouseGrid.Set(backgroundColor); SetIndividualKeys(ref keyboardGrid); SetPlayingTime(ref keyboardGrid, currentTime, ColoreColor.Red, ThisIsWhatCalledOrange, ColoreColor.Yellow); SetPlayingPosition(ref keyboardGrid, position, FunctionKeys, pos_fore, pos_back); SetPlayingPosition(ref mouseGrid, position, Properties.Settings.Default.ReverseLEDRender ? RightStrip : LeftStrip, pos_fore, pos_back); SetVolumeScale(ref mouseGrid, Properties.Settings.Default.ReverseLEDRender ? LeftStrip : RightStrip, vol); SetVolumeScale(ref keyboardGrid, DPadKeys, vol); } catch { continue; //in case the music is not playing yet, the position is unobtainable. } finally { await chroma.Keyboard.SetCustomAsync(keyboardGrid); await chroma.Mouse.SetGridAsync(mouseGrid); await chroma.Headset.SetAllAsync(backgroundColor); await chroma.Mousepad.SetAllAsync(backgroundColor); Thread.Sleep(500 * (Properties.Settings.Default.AdaptiveDensity ? Properties.Settings.Default.RefreshRate / 10 : 1)); } } }
private void initChromaSkd() { var t = ColoreProvider.CreateNativeAsync(); t.Wait(); this.chroma = t.Result; this.muted = KeyboardCustom.Create(); this.muted.Set(Colore.Data.Color.Red); this.muted[Key.Macro4] = Colore.Data.Color.Green; this.unmuted = KeyboardCustom.Create(); this.unmuted.Set(Colore.Data.Color.Green); this.unmuted[Key.Macro4] = Colore.Data.Color.Red; }
public Task SetColors(IEnumerable <RGB> colors, CancellationToken token) { var nextColors = KeyboardCustom.Create(); var i = 0; foreach (var color in colors) { var position = keyboardPositions[i]; nextColors[position.Row, position.Column] = new Colore.Data.Color( (byte)color.R, (byte)color.G, (byte)color.B); i++; } return(keyboard.SetCustomAsync(nextColors)); }
private static void RenderKeyboard(ref KeyboardCustom keyboard, int[] characterHPPoint, int[] characterMPPoint) { //reset keyboard.Set(fadeRed); /* * var currentTime = DateTime.Now; * var am_pm = currentTime.ToString("tt", CultureInfo.InvariantCulture); * keyboard[FunctionKeys[currentTime.Hour % 12]] = am_pm == "AM" ? ColoreColor.White : ColoreColor.Blue; * var decMin = (currentTime.Minute - (currentTime.Minute % 10)) / 10; * keyboard[NumpadKeys[decMin]] = contrastOrange; * keyboard[NumpadKeys[currentTime.Minute % 10]] = ColoreColor.Yellow; */ for (var i = 0; i < charRenderGrid[0].Length; i++) { keyboard[charRenderGrid[0][i]] = fadeWhite; keyboard[charRenderGrid[1][i]] = fadeWhite; keyboard[charRenderGrid[2][i]] = fadeWhite; } for (var i = 0; i < charMPRows[0].Length; i++) { keyboard[charMPRows[0][i]] = fadeWhite; keyboard[charMPRows[1][i]] = fadeWhite; keyboard[charMPRows[2][i]] = fadeWhite; } for (var charIndex = 0; charIndex < characterHPPoint.Length; charIndex++) { ColoreColor hpColor = GetHPStateColor(characterHPPoint[charIndex]); ColoreColor mpColor = new ColoreColor((byte)0, (byte)0, (byte)(25.5 * characterMPPoint[charIndex])); var manaPercent = Math.Round(((double)characterMPPoint[charIndex] / 10) * charMPRows[charIndex].Length, 0); for (var i = 0; i < manaPercent; i++) { keyboard[charMPRows[charIndex][i]] = ColoreColor.Blue; } for (var i = 0; i < characterHPPoint[charIndex]; i++) { keyboard[charRenderGrid[charIndex][i]] = hpColor; } } blinking = !blinking; }
static async Task <bool> SwitchColour(AppCall args, IChroma chroma) { if (args.invalid) { return(false); } var grid = KeyboardCustom.Create(); if (args.addWeak || args.addStrong) { grid = currentKeyboard; } ColoreColor clr = ColoreColor.Black; foreach (string fline in File.ReadLines(args.filePath)) { string line = fline; if (line.Contains(";")) { line = line.Substring(0, line.IndexOf(";")); } line = line.Trim(); if (line == "") { continue; } if (line.ToLower().StartsWith("rgb")) { var b = line.Remove(0, 3).Trim(); try { clr = ColoreColor.FromRgb(uint.Parse(b, System.Globalization.NumberStyles.HexNumber)); } catch (Exception e) { Console.WriteLine("yo your color was invalid dude"); Console.WriteLine(e); return(false); } } if (line.ToLower().StartsWith("all")) { grid.Set(clr); } if (!Enum.TryParse(line, true, out Key currKey) && !line.ToLower().StartsWith("rgb") && !line.ToLower().StartsWith("all")) // horrible code hours { Console.WriteLine("thats not a valid key pls fix"); Console.WriteLine(currKey.ToString()); return(false); } if (args.addWeak) { if (grid[currKey] == ColoreColor.Black) { grid[currKey] = clr; } } else { grid[currKey] = clr; } } currentKeyboard = grid; Console.WriteLine("bro"); await chroma.Keyboard.SetCustomAsync(grid); return(true); }
static async Task MainAsync(string[] args) { string char1Name, char2Name, char3Name; int char1CurrentHP, char1MaxHP, char1CurrentMP, char1MaxMP, char2CurrentHP, char2MaxHP, char2CurrentMP, char2MaxMP, char3CurrentHP, char3MaxHP, char3CurrentMP, char3MaxMP; int familyLevel = 0; uint bufferSize = 255; var keyboard = KeyboardCustom.Create(); var chroma = await ColoreProvider.CreateNativeAsync(); await chroma.SetAllAsync(fadeRed); WaitGame: try { Process GameProcess = Process.GetProcessesByName("rGE").FirstOrDefault(); VAMemory vam = new VAMemory("rGE"); vam.ReadInt32(GameProcess.MainModule.BaseAddress); while (true) { Console.Clear(); //HP char1CurrentHP = vam.ReadInt32((IntPtr)(vam.getBaseAddress + CurrentHP[0])); char1MaxHP = vam.ReadInt32((IntPtr)(vam.getBaseAddress + MaxHP[0])); char2CurrentHP = vam.ReadInt32((IntPtr)(vam.getBaseAddress + CurrentHP[1])); char2MaxHP = vam.ReadInt32((IntPtr)(vam.getBaseAddress + MaxHP[1])); char3CurrentHP = vam.ReadInt32((IntPtr)(vam.getBaseAddress + CurrentHP[2])); char3MaxHP = vam.ReadInt32((IntPtr)(vam.getBaseAddress + MaxHP[2])); //MP char1CurrentMP = vam.ReadInt16((IntPtr)(vam.getBaseAddress + CurrentMP[0])); char1MaxMP = vam.ReadInt16((IntPtr)(vam.getBaseAddress + MaxMP[0])); char2CurrentMP = vam.ReadInt16((IntPtr)(vam.getBaseAddress + CurrentMP[1])); char2MaxMP = vam.ReadInt16((IntPtr)(vam.getBaseAddress + MaxMP[1])); char3CurrentMP = vam.ReadInt16((IntPtr)(vam.getBaseAddress + CurrentMP[2])); char3MaxMP = vam.ReadInt16((IntPtr)(vam.getBaseAddress + MaxMP[2])); var HP1Point = Math.Round((double)char1CurrentHP / char1MaxHP, 2); var HP2Point = Math.Round((double)char2CurrentHP / char2MaxHP, 2); var HP3Point = Math.Round((double)char3CurrentHP / char3MaxHP, 2); var MP1Point = Math.Round((double)char1CurrentMP / char1MaxMP, 2); var MP2Point = Math.Round((double)char2CurrentMP / char2MaxMP, 2); var MP3Point = Math.Round((double)char3CurrentMP / char3MaxMP, 2); RenderKeyboard(ref keyboard, new[] { (int)(HP1Point * 10), (int)(HP2Point * 10), (int)(HP3Point * 10) }, new[] { (int)(MP1Point * 10), (int)(MP2Point * 10), (int)(MP3Point * 10) }); await chroma.Keyboard.SetCustomAsync(keyboard); //char1Name = vam.ReadStringASCII((IntPtr)(vam.getBaseAddress + Name[0]), bufferSize); //char2Name = vam.ReadStringASCII((IntPtr)(vam.getBaseAddress + Name[1]), bufferSize); //char3Name = vam.ReadStringASCII((IntPtr)(vam.getBaseAddress + Name[2]), bufferSize); //char1Name = char1Name.Substring(0, char1Name.IndexOf("\0")); //char2Name = char2Name.Substring(0, char2Name.IndexOf("\0")); //char3Name = char3Name.Substring(0, char3Name.IndexOf("\0")); //Console.WriteLine($"\rName : {char1Name} {char1CurrentMP}/{char1MaxMP}[{HP1Point * 100}]% "); //Console.WriteLine($"\rName : {char2Name} {char2CurrentMP}/{char2MaxMP}[{HP2Point * 100}]% "); //Console.WriteLine($"\rName : {char3Name} {char3CurrentMP}/{char3MaxMP}[{HP3Point * 100}]% "); Thread.Sleep(500); } } catch { keyboard.Set(fadeRed); await chroma.Keyboard.SetCustomAsync(keyboard); Console.Write("\rWaiting for character info to allocate into memory..."); Thread.Sleep(500); goto WaitGame; } }
public SnakeGrid() { Chroma.Instance.Keyboard.Clear(); grid = KeyboardCustom.Create(); initGrid(); }