Example #1
0
        internal virtual void UpdateWrapperLights(IGameState new_game_state)
        {
            if (new_game_state is GameState_Wrapper)
            {
                _game_state = new_game_state;

                GameState_Wrapper ngw_state = (new_game_state as GameState_Wrapper);

                bitmap     = ngw_state.Sent_Bitmap;
                logo       = ngw_state.Extra_Keys.logo;
                g1         = ngw_state.Extra_Keys.G1;
                g2         = ngw_state.Extra_Keys.G2;
                g3         = ngw_state.Extra_Keys.G3;
                g4         = ngw_state.Extra_Keys.G4;
                g5         = ngw_state.Extra_Keys.G5;
                peripheral = ngw_state.Extra_Keys.peripheral;

                if (ngw_state.Command.Equals("SetLighting"))
                {
                    Color newfill = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);

                    if (!last_fill_color.Equals(newfill))
                    {
                        last_fill_color = newfill;

                        for (int i = 0; i < bitmap.Length; i += 4)
                        {
                            bitmap[i]     = (byte)ngw_state.Command_Data.blue_start;
                            bitmap[i + 1] = (byte)ngw_state.Command_Data.green_start;
                            bitmap[i + 2] = (byte)ngw_state.Command_Data.red_start;
                            bitmap[i + 3] = (byte)255;
                        }
                    }
                }
                else if (ngw_state.Command.Equals("SetLightingForKeyWithKeyName") || ngw_state.Command.Equals("SetLightingForKeyWithScanCode"))
                {
                    var bitmap_key = Devices.Logitech.LogitechDevice.ToLogitechBitmap((LedCSharp.keyboardNames)(ngw_state.Command_Data.key));

                    if (bitmap_key != Devices.Logitech.Logitech_keyboardBitmapKeys.UNKNOWN)
                    {
                        bitmap[(int)bitmap_key]     = (byte)ngw_state.Command_Data.blue_start;
                        bitmap[(int)bitmap_key + 1] = (byte)ngw_state.Command_Data.green_start;
                        bitmap[(int)bitmap_key + 2] = (byte)ngw_state.Command_Data.red_start;
                        bitmap[(int)bitmap_key + 3] = (byte)255;
                    }
                }
                else if (ngw_state.Command.Equals("FlashSingleKey"))
                {
                    Devices.DeviceKeys dev_key   = Devices.Logitech.LogitechDevice.ToDeviceKey((LedCSharp.keyboardNames)(ngw_state.Command_Data.key));
                    LogiFlashSingleKey neweffect = new LogiFlashSingleKey(dev_key, Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                                                                          ngw_state.Command_Data.duration,
                                                                          ngw_state.Command_Data.interval
                                                                          );

                    if (key_effects.ContainsKey(dev_key))
                    {
                        key_effects[dev_key] = neweffect;
                    }
                    else
                    {
                        key_effects.Add(dev_key, neweffect);
                    }
                }
                else if (ngw_state.Command.Equals("PulseSingleKey"))
                {
                    Devices.DeviceKeys dev_key = Devices.Logitech.LogitechDevice.ToDeviceKey((LedCSharp.keyboardNames)(ngw_state.Command_Data.key));
                    long duration = ngw_state.Command_Data.interval == 0 ? 0 : ngw_state.Command_Data.duration;

                    LogiPulseSingleKey neweffect = new LogiPulseSingleKey(dev_key, Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                                                                          Color.FromArgb(ngw_state.Command_Data.red_end, ngw_state.Command_Data.green_end, ngw_state.Command_Data.blue_end),
                                                                          duration
                                                                          );

                    if (key_effects.ContainsKey(dev_key))
                    {
                        key_effects[dev_key] = neweffect;
                    }
                    else
                    {
                        key_effects.Add(dev_key, neweffect);
                    }
                }
                else if (ngw_state.Command.Equals("PulseLighting"))
                {
                    current_effect = new LogiPulseLighting(
                        Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                        ngw_state.Command_Data.duration,
                        ngw_state.Command_Data.interval
                        );
                }
                else if (ngw_state.Command.Equals("FlashLighting"))
                {
                    current_effect = new LogiFlashLighting(
                        Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                        ngw_state.Command_Data.duration,
                        ngw_state.Command_Data.interval
                        );
                }
                else if (ngw_state.Command.Equals("StopEffects"))
                {
                    key_effects.Clear();
                    current_effect = null;
                }
                else if (ngw_state.Command.Equals("SetLightingFromBitmap"))
                {
                }
                //LightFX
                else if (ngw_state.Command.Equals("LFX_GetNumDevices"))
                {
                }
                else if (ngw_state.Command.Equals("LFX_Light"))
                {
                }
                else if (ngw_state.Command.Equals("LFX_SetLightColor"))
                {
                }
                else if (ngw_state.Command.Equals("LFX_Update"))
                {
                    Color newfill = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);

                    if (!last_fill_color.Equals(newfill))
                    {
                        last_fill_color = newfill;

                        for (int i = 0; i < bitmap.Length; i++)
                        {
                            bitmap[i] = (int)(((int)ngw_state.Command_Data.red_start << 16) | ((int)ngw_state.Command_Data.green_start << 8) | ((int)ngw_state.Command_Data.blue_start));
                        }

                        logo       = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);
                        peripheral = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);
                    }
                }
                else if (ngw_state.Command.Equals("LFX_SetLightActionColor") || ngw_state.Command.Equals("LFX_ActionColor"))
                {
                    Color primary   = Color.Transparent;
                    Color secondary = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);

                    if (current_effect != null)
                    {
                        primary = current_effect.GetCurrentColor(Utils.Time.GetMillisecondsSinceEpoch() - current_effect.timeStarted);
                    }

                    switch (ngw_state.Command_Data.effect_type)
                    {
                    case "LFX_ACTION_COLOR":
                        current_effect = new LFX_Color(primary);
                        break;

                    case "LFX_ACTION_PULSE":
                        current_effect = new LFX_Pulse(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    case "LFX_ACTION_MORPH":
                        current_effect = new LFX_Morph(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    default:
                        current_effect = null;
                        break;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_SetLightActionColorEx") || ngw_state.Command.Equals("LFX_ActionColorEx"))
                {
                    Color primary   = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);
                    Color secondary = Color.FromArgb(ngw_state.Command_Data.red_end, ngw_state.Command_Data.green_end, ngw_state.Command_Data.blue_end);

                    switch (ngw_state.Command_Data.effect_type)
                    {
                    case "LFX_ACTION_COLOR":
                        current_effect = new LFX_Color(primary);
                        break;

                    case "LFX_ACTION_PULSE":
                        current_effect = new LFX_Pulse(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    case "LFX_ACTION_MORPH":
                        current_effect = new LFX_Morph(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    default:
                        current_effect = null;
                        break;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_Reset"))
                {
                    current_effect = null;
                }
                //Razer
                else if (ngw_state.Command.Equals("CreateMouseEffect"))
                {
                }
                else if (ngw_state.Command.Equals("CreateKeyboardEffect"))
                {
                    Color primary   = Color.Red;
                    Color secondary = Color.Blue;

                    if (ngw_state.Command_Data.red_start >= 0 &&
                        ngw_state.Command_Data.green_start >= 0 &&
                        ngw_state.Command_Data.blue_start >= 0
                        )
                    {
                        primary = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);
                    }

                    if (ngw_state.Command_Data.red_end >= 0 &&
                        ngw_state.Command_Data.green_end >= 0 &&
                        ngw_state.Command_Data.blue_end >= 0
                        )
                    {
                        secondary = Color.FromArgb(ngw_state.Command_Data.red_end, ngw_state.Command_Data.green_end, ngw_state.Command_Data.blue_end);
                    }

                    switch (ngw_state.Command_Data.effect_type)
                    {
                    case "CHROMA_BREATHING":
                        current_effect = new CHROMA_BREATHING(primary, secondary, ngw_state.Command_Data.effect_config);
                        break;

                    default:
                        current_effect = null;
                        break;
                    }
                }
                else
                {
                    Global.logger.LogLine("Unknown Wrapper Command: " + ngw_state.Command, Logging_Level.Info, false);
                }
            }
        }
        internal virtual void UpdateWrapperLights(IGameState new_game_state)
        {
            if (new_game_state is GameState_Wrapper)
            {
                _game_state = new_game_state;

                GameState_Wrapper ngw_state = (new_game_state as GameState_Wrapper);

                if (ngw_state.Sent_Bitmap.Length != 0)
                {
                    bitmap = ngw_state.Sent_Bitmap;
                }

                SetExtraKey(Devices.DeviceKeys.LOGO, ngw_state.Extra_Keys.logo);
                SetExtraKey(Devices.DeviceKeys.LOGO2, ngw_state.Extra_Keys.badge);
                SetExtraKey(Devices.DeviceKeys.Peripheral, ngw_state.Extra_Keys.peripheral);
                SetExtraKey(Devices.DeviceKeys.G1, ngw_state.Extra_Keys.G1);
                SetExtraKey(Devices.DeviceKeys.G2, ngw_state.Extra_Keys.G2);
                SetExtraKey(Devices.DeviceKeys.G3, ngw_state.Extra_Keys.G3);
                SetExtraKey(Devices.DeviceKeys.G4, ngw_state.Extra_Keys.G4);
                SetExtraKey(Devices.DeviceKeys.G5, ngw_state.Extra_Keys.G5);
                SetExtraKey(Devices.DeviceKeys.G6, ngw_state.Extra_Keys.G6);
                SetExtraKey(Devices.DeviceKeys.G7, ngw_state.Extra_Keys.G7);
                SetExtraKey(Devices.DeviceKeys.G8, ngw_state.Extra_Keys.G8);
                SetExtraKey(Devices.DeviceKeys.G9, ngw_state.Extra_Keys.G9);
                SetExtraKey(Devices.DeviceKeys.G10, ngw_state.Extra_Keys.G10);
                SetExtraKey(Devices.DeviceKeys.G11, ngw_state.Extra_Keys.G11);
                SetExtraKey(Devices.DeviceKeys.G12, ngw_state.Extra_Keys.G12);
                SetExtraKey(Devices.DeviceKeys.G13, ngw_state.Extra_Keys.G13);
                SetExtraKey(Devices.DeviceKeys.G14, ngw_state.Extra_Keys.G14);
                SetExtraKey(Devices.DeviceKeys.G15, ngw_state.Extra_Keys.G15);
                SetExtraKey(Devices.DeviceKeys.G16, ngw_state.Extra_Keys.G16);
                SetExtraKey(Devices.DeviceKeys.G17, ngw_state.Extra_Keys.G17);
                SetExtraKey(Devices.DeviceKeys.G18, ngw_state.Extra_Keys.G18);
                SetExtraKey(Devices.DeviceKeys.G19, ngw_state.Extra_Keys.G19);
                SetExtraKey(Devices.DeviceKeys.G20, ngw_state.Extra_Keys.G20);

                if (ngw_state.Command.Equals("SetLighting"))
                {
                    Color newfill = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);

                    if (!last_fill_color.Equals(newfill))
                    {
                        last_fill_color = newfill;

                        for (int i = 0; i < bitmap.Length; i++)
                        {
                            bitmap[i] = (int)(((int)ngw_state.Command_Data.red_start << 16) | ((int)ngw_state.Command_Data.green_start << 8) | ((int)ngw_state.Command_Data.blue_start));
                        }
                    }
                }
                else if (ngw_state.Command.Equals("SetLightingForKeyWithKeyName") || ngw_state.Command.Equals("SetLightingForKeyWithScanCode"))
                {
                    var bitmap_key = Devices.Logitech.LogitechDevice.ToLogitechBitmap((LedCSharp.keyboardNames)(ngw_state.Command_Data.key));

                    if (bitmap_key != Devices.Logitech.Logitech_keyboardBitmapKeys.UNKNOWN)
                    {
                        bitmap[(int)bitmap_key / 4] = (int)(((int)ngw_state.Command_Data.red_start << 16) | ((int)ngw_state.Command_Data.green_start << 8) | ((int)ngw_state.Command_Data.blue_start));
                    }
                }
                else if (ngw_state.Command.Equals("FlashSingleKey"))
                {
                    Devices.DeviceKeys dev_key   = Devices.Logitech.LogitechDevice.ToDeviceKey((LedCSharp.keyboardNames)(ngw_state.Command_Data.key));
                    LogiFlashSingleKey neweffect = new LogiFlashSingleKey(dev_key, Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                                                                          ngw_state.Command_Data.duration,
                                                                          ngw_state.Command_Data.interval
                                                                          );

                    if (key_effects.ContainsKey(dev_key))
                    {
                        key_effects[dev_key] = neweffect;
                    }
                    else
                    {
                        key_effects.Add(dev_key, neweffect);
                    }
                }
                else if (ngw_state.Command.Equals("PulseSingleKey"))
                {
                    Devices.DeviceKeys dev_key = Devices.Logitech.LogitechDevice.ToDeviceKey((LedCSharp.keyboardNames)(ngw_state.Command_Data.key));
                    long duration = ngw_state.Command_Data.interval == 0 ? 0 : ngw_state.Command_Data.duration;

                    LogiPulseSingleKey neweffect = new LogiPulseSingleKey(dev_key, Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                                                                          Color.FromArgb(ngw_state.Command_Data.red_end, ngw_state.Command_Data.green_end, ngw_state.Command_Data.blue_end),
                                                                          duration
                                                                          );

                    if (key_effects.ContainsKey(dev_key))
                    {
                        key_effects[dev_key] = neweffect;
                    }
                    else
                    {
                        key_effects.Add(dev_key, neweffect);
                    }
                }
                else if (ngw_state.Command.Equals("PulseLighting"))
                {
                    current_effect = new LogiPulseLighting(
                        Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                        ngw_state.Command_Data.duration,
                        ngw_state.Command_Data.interval
                        );
                }
                else if (ngw_state.Command.Equals("FlashLighting"))
                {
                    current_effect = new LogiFlashLighting(
                        Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start),
                        ngw_state.Command_Data.duration,
                        ngw_state.Command_Data.interval
                        );
                }
                else if (ngw_state.Command.Equals("StopEffects"))
                {
                    key_effects.Clear();
                    current_effect = null;
                }
                else if (ngw_state.Command.Equals("SetLightingFromBitmap"))
                {
                }
                //LightFX
                else if (ngw_state.Command.Equals("LFX_GetNumDevices"))
                {
                    //Retain previous lighting
                    int fill_color_int = Utils.ColorUtils.GetIntFromColor(last_fill_color);

                    for (int i = 0; i < bitmap.Length; i++)
                    {
                        bitmap[i] = fill_color_int;
                    }

                    foreach (var extra_key in extra_keys.Keys.ToArray())
                    {
                        extra_keys[extra_key] = last_fill_color;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_Light"))
                {
                    //Retain previous lighting
                    int fill_color_int = Utils.ColorUtils.GetIntFromColor(last_fill_color);

                    for (int i = 0; i < bitmap.Length; i++)
                    {
                        bitmap[i] = fill_color_int;
                    }

                    foreach (var extra_key in extra_keys.Keys.ToArray())
                    {
                        extra_keys[extra_key] = last_fill_color;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_SetLightColor"))
                {
                    //Retain previous lighting
                    int fill_color_int = Utils.ColorUtils.GetIntFromColor(last_fill_color);

                    for (int i = 0; i < bitmap.Length; i++)
                    {
                        bitmap[i] = fill_color_int;
                    }

                    foreach (var extra_key in extra_keys.Keys.ToArray())
                    {
                        extra_keys[extra_key] = last_fill_color;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_Update"))
                {
                    Color newfill = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);

                    if (!last_fill_color.Equals(newfill))
                    {
                        last_fill_color = newfill;

                        for (int i = 0; i < bitmap.Length; i++)
                        {
                            bitmap[i] = (int)(((int)ngw_state.Command_Data.red_start << 16) | ((int)ngw_state.Command_Data.green_start << 8) | ((int)ngw_state.Command_Data.blue_start));
                        }
                    }

                    foreach (var extra_key in extra_keys.Keys.ToArray())
                    {
                        extra_keys[extra_key] = newfill;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_SetLightActionColor") || ngw_state.Command.Equals("LFX_ActionColor"))
                {
                    Color primary   = Color.Transparent;
                    Color secondary = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);

                    if (current_effect != null)
                    {
                        primary = current_effect.GetCurrentColor(Utils.Time.GetMillisecondsSinceEpoch() - current_effect.timeStarted);
                    }

                    switch (ngw_state.Command_Data.effect_type)
                    {
                    case "LFX_ACTION_COLOR":
                        current_effect = new LFX_Color(primary);
                        break;

                    case "LFX_ACTION_PULSE":
                        current_effect = new LFX_Pulse(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    case "LFX_ACTION_MORPH":
                        current_effect = new LFX_Morph(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    default:
                        current_effect = null;
                        break;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_SetLightActionColorEx") || ngw_state.Command.Equals("LFX_ActionColorEx"))
                {
                    Color primary   = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);
                    Color secondary = Color.FromArgb(ngw_state.Command_Data.red_end, ngw_state.Command_Data.green_end, ngw_state.Command_Data.blue_end);

                    switch (ngw_state.Command_Data.effect_type)
                    {
                    case "LFX_ACTION_COLOR":
                        current_effect = new LFX_Color(primary);
                        break;

                    case "LFX_ACTION_PULSE":
                        current_effect = new LFX_Pulse(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    case "LFX_ACTION_MORPH":
                        current_effect = new LFX_Morph(primary, secondary, ngw_state.Command_Data.duration);
                        break;

                    default:
                        current_effect = null;
                        break;
                    }
                }
                else if (ngw_state.Command.Equals("LFX_Reset"))
                {
                    current_effect = null;
                }
                //Razer
                else if (ngw_state.Command.Equals("CreateMouseEffect"))
                {
                }
                else if (ngw_state.Command.Equals("CreateKeyboardEffect"))
                {
                    Color primary   = Color.Red;
                    Color secondary = Color.Blue;

                    if (ngw_state.Command_Data.red_start >= 0 &&
                        ngw_state.Command_Data.green_start >= 0 &&
                        ngw_state.Command_Data.blue_start >= 0
                        )
                    {
                        primary = Color.FromArgb(ngw_state.Command_Data.red_start, ngw_state.Command_Data.green_start, ngw_state.Command_Data.blue_start);
                    }

                    if (ngw_state.Command_Data.red_end >= 0 &&
                        ngw_state.Command_Data.green_end >= 0 &&
                        ngw_state.Command_Data.blue_end >= 0
                        )
                    {
                        secondary = Color.FromArgb(ngw_state.Command_Data.red_end, ngw_state.Command_Data.green_end, ngw_state.Command_Data.blue_end);
                    }

                    switch (ngw_state.Command_Data.effect_type)
                    {
                    case "CHROMA_BREATHING":
                        current_effect = new CHROMA_BREATHING(primary, secondary, ngw_state.Command_Data.effect_config);
                        break;

                    default:
                        current_effect = null;
                        break;
                    }
                }
                else
                {
                    Global.logger.LogLine("Unknown Wrapper Command: " + ngw_state.Command, Logging_Level.Info, false);
                }
            }
        }